diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-06-28 00:40:58 +0300 |
---|---|---|
committer | Thomas Dinges <blender@dingto.org> | 2022-06-28 16:08:45 +0300 |
commit | 6edc9438a461ff8fbf7cd49d74104342af33ee05 (patch) | |
tree | a9a973e2816b8a7ede9ed1bd78839607eea97c42 | |
parent | e0dd51fc14763b85ddb55d32cc5858f8338c79b5 (diff) |
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.
-rw-r--r-- | source/blender/editors/space_view3d/view3d_cursor_snap.c | 30 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.cc | 4 |
2 files changed, 23 insertions, 11 deletions
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; } |