[Bf-blender-cvs] [6edc9438a46] blender-v3.2-release: Fix T96776: Assets dropped upside down when looking through camera

Germano Cavalcante noreply at git.blender.org
Tue Jun 28 15:08:57 CEST 2022


Commit: 6edc9438a461ff8fbf7cd49d74104342af33ee05
Author: Germano Cavalcante
Date:   Mon Jun 27 18:40:58 2022 -0300
Branches: blender-v3.2-release
https://developer.blender.org/rB6edc9438a461ff8fbf7cd49d74104342af33ee05

Fix T96776: Assets dropped upside down when looking through camera

In perspective mode the snap point direction needs to be taken into
account to define which side of the face is being looked at.

If there is no face under the mouse cursor, there is no direction
adjustment and the element normal will be used.

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

M	source/blender/editors/space_view3d/view3d_cursor_snap.c
M	source/blender/editors/transform/transform_snap_object.cc

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

diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 96a193cc10d..c0555574026 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -663,10 +663,6 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
         face_nor);
   }
 
-  if (is_zero_v3(face_nor)) {
-    face_nor[state->plane_axis] = 1.0f;
-  }
-
   if (calc_plane_omat) {
     RegionView3D *rv3d = region->regiondata;
     bool orient_surface = snap_elem && (state->plane_orient == V3D_PLACE_ORIENT_SURFACE);
@@ -693,8 +689,28 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
     orthogonalize_m3(omat, state->plane_axis);
 
     if (orient_surface) {
-      if (dot_v3v3(rv3d->viewinv[2], face_nor) < 0.0f) {
-        negate_v3(face_nor);
+      if (!is_zero_v3(face_nor)) {
+        /* Negate the face normal according to the view. */
+        float ray_dir[3];
+        if (rv3d->is_persp) {
+          BLI_assert_msg(snap_elem != SCE_SNAP_MODE_NONE,
+                         "Use of variable `co` without it being computed");
+
+          sub_v3_v3v3(ray_dir, co, rv3d->viewinv[3]); /* No need to normalize. */
+        }
+        else {
+          negate_v3_v3(ray_dir, rv3d->viewinv[2]);
+        }
+
+        if (dot_v3v3(ray_dir, face_nor) >= 0.0f) {
+          negate_v3(face_nor);
+        }
+      }
+      else if (!is_zero_v3(no)) {
+        copy_v3_v3(face_nor, no);
+      }
+      else {
+        face_nor[state->plane_axis] = 1.0f;
       }
       v3d_cursor_poject_surface_normal(face_nor, obmat, omat);
     }
@@ -702,7 +718,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
 
   float *co_depth = snap_elem ? co : scene->cursor.location;
   snap_elem &= ~data_intern->snap_elem_hidden;
-  if (snap_elem == 0) {
+  if (snap_elem == SCE_SNAP_MODE_NONE) {
     RegionView3D *rv3d = region->regiondata;
     const float *plane_normal = omat[state->plane_axis];
     bool do_plane_isect = (state->plane_depth != V3D_PLACE_DEPTH_CURSOR_VIEW) &&
diff --git a/source/blender/editors/transform/transform_snap_object.cc b/source/blender/editors/transform/transform_snap_object.cc
index 6beae690b12..bbe64c995fd 100644
--- a/source/blender/editors/transform/transform_snap_object.cc
+++ b/source/blender/editors/transform/transform_snap_object.cc
@@ -3180,10 +3180,6 @@ static short transform_snap_context_project_view3d_mixed_impl(SnapObjectContext
       if (r_index) {
         *r_index = index;
       }
-      if (r_face_nor && !has_hit) {
-        /* Fallback. */
-        copy_v3_v3(r_face_nor, no);
-      }
 
       *dist_px = dist_px_tmp;
     }



More information about the Bf-blender-cvs mailing list