[Bf-blender-cvs] [317dfc17358] master: Fix T96776: Assets dropped upside down when looking through camera

Germano Cavalcante noreply at git.blender.org
Tue Jun 28 00:06:33 CEST 2022


Commit: 317dfc17358fd4ee0c7f19be62112d7037b6c6f2
Author: Germano Cavalcante
Date:   Mon Jun 27 18:40:58 2022 -0300
Branches: master
https://developer.blender.org/rB317dfc17358fd4ee0c7f19be62112d7037b6c6f2

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 395df42b2cb..a879a05d41a 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -660,10 +660,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 != SCE_SNAP_MODE_NONE) &&
@@ -691,8 +687,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);
     }
@@ -700,7 +716,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
 
   float *co_depth = (snap_elem != SCE_SNAP_MODE_NONE) ? 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 cf99d4b2ef3..bd3d29fac8a 100644
--- a/source/blender/editors/transform/transform_snap_object.cc
+++ b/source/blender/editors/transform/transform_snap_object.cc
@@ -3179,10 +3179,6 @@ static eSnapMode transform_snap_context_project_view3d_mixed_impl(SnapObjectCont
       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