[Bf-blender-cvs] [b4c9f8da885] blender-v3.0-release: Fix T93869: snap cursor may fail in orthographic view

Germano Cavalcante noreply at git.blender.org
Tue Jan 11 09:00:05 CET 2022


Commit: b4c9f8da885a0cd2b9df874c42de45a8b7e5827b
Author: Germano Cavalcante
Date:   Wed Dec 8 23:47:26 2021 -0300
Branches: blender-v3.0-release
https://developer.blender.org/rBb4c9f8da885a0cd2b9df874c42de45a8b7e5827b

Fix T93869: snap cursor may fail in orthographic view

Float precision issues cause the `ED_view3d_win_to_3d_on_plane` to return
a value even when the view ray is parallel to the plane.

A more general solution might be desired in this case, as other areas that
use `ED_view3d_win_to_3d_on_plane` might have the same problem.

For now, just work around the problem for the snap cursor.

===================================================================

M	source/blender/editors/space_view3d/view3d_cursor_snap.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 569aa542487..747d5248056 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -105,6 +105,12 @@ static SnapCursorDataIntern g_data_intern = {
                       .box_dimensions = {1.0f, 1.0f, 1.0f},
                       .draw_point = true}};
 
+/**
+ * Dot products below this will be considered view aligned.
+ * In this case we can't usefully project the mouse cursor onto the plane.
+ */
+static const float eps_view_align = 1e-2f;
+
 /**
  * Calculate a 3x3 orientation matrix from the surface under the cursor.
  */
@@ -717,14 +723,18 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
   snap_elem &= ~data_intern->snap_elem_hidden;
   if (snap_elem == 0) {
     RegionView3D *rv3d = region->regiondata;
-    float plane[4];
-    if (state->plane_depth != V3D_PLACE_DEPTH_CURSOR_VIEW) {
-      const float *plane_normal = omat[state->plane_axis];
+    const float *plane_normal = omat[state->plane_axis];
+    bool do_plane_isect = (state->plane_depth != V3D_PLACE_DEPTH_CURSOR_VIEW) &&
+                          (rv3d->is_persp ||
+                           (fabsf(dot_v3v3(plane_normal, rv3d->viewinv[2])) > eps_view_align));
+
+    if (do_plane_isect) {
+      float plane[4];
       plane_from_point_normal_v3(plane, co_depth, plane_normal);
+      do_plane_isect = ED_view3d_win_to_3d_on_plane(region, plane, mval_fl, rv3d->is_persp, co);
     }
 
-    if ((state->plane_depth == V3D_PLACE_DEPTH_CURSOR_VIEW) ||
-        !ED_view3d_win_to_3d_on_plane(region, plane, mval_fl, rv3d->is_persp, co)) {
+    if (!do_plane_isect) {
       ED_view3d_win_to_3d(v3d, region, co_depth, mval_fl, co);
     }



More information about the Bf-blender-cvs mailing list