Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-11-20 09:07:04 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-11-20 09:15:18 +0300
commit1501c3adad13c3b0ae4f02a84f1be2c84f6f1db2 (patch)
treea259123829ce56c09996901b09fc9ddd4bce284a /source/blender/editors/space_view3d/view3d_project.c
parenta8f4affb2ead7f49996f54a8e6a14be5a48db785 (diff)
Add Object Tool: support placing objects in orthographic axis views
When an projecting onto a plane that is orthogonal to the views Z axis, project onto a view aligned axis then map it back to the original plane. see: ED_view3d_win_to_3d_on_plane_with_fallback Since the depth can't be properly visualized in 3D, display a 2D so it's possible to to tell the depth from the cursor motion.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_project.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_project.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 0afa44b6f4f..58538fc3ecb 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -633,6 +633,48 @@ bool ED_view3d_win_to_3d_on_plane_int(const ARegion *region,
}
/**
+ * A wrapper for #ED_view3d_win_to_3d_on_plane that projects onto \a plane_fallback
+ * then maps this back to \a plane.
+ *
+ * This is intended to be used when \a plane is orthogonal to the views Z axis where
+ * projecting the \a mval doesn't work well (or fail completely when exactly aligned).
+ */
+bool ED_view3d_win_to_3d_on_plane_with_fallback(const ARegion *region,
+ const float plane[4],
+ const float mval[2],
+ const bool do_clip,
+ const float plane_fallback[4],
+ float r_out[3])
+{
+ float isect_co[3], isect_no[3];
+ if (!isect_plane_plane_v3(plane, plane_fallback, isect_co, isect_no)) {
+ return false;
+ }
+ normalize_v3(isect_no);
+
+ /* Construct matrix to transform `plane_fallback` onto `plane`. */
+ float mat4[4][4];
+ {
+ float mat3[3][3];
+ rotation_between_vecs_to_mat3(mat3, plane, plane_fallback);
+ copy_m4_m3(mat4, mat3);
+ transform_pivot_set_m4(mat4, isect_co);
+ }
+
+ float co[3];
+ if (!ED_view3d_win_to_3d_on_plane(region, plane_fallback, mval, do_clip, co)) {
+ return false;
+ }
+ mul_m4_v3(mat4, co);
+
+ /* While the point is already on the plane, there may be some small in-precision
+ * so ensure the point is exactly on the plane. */
+ closest_to_plane_v3(r_out, plane, co);
+
+ return true;
+}
+
+/**
* Calculate a 3d difference vector from 2d window offset.
* note that #ED_view3d_calc_zfac() must be called first to determine
* the depth used to calculate the delta.