diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-06-28 00:40:58 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-06-28 01:00:24 +0300 |
commit | 317dfc17358fd4ee0c7f19be62112d7037b6c6f2 (patch) | |
tree | c7c542d5164ae23d77cad96963c462ad08b8bfe1 /source/blender/editors/space_view3d/view3d_cursor_snap.c | |
parent | 17a773cdcee9ea413d5be72a95fe1567743c269b (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.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_cursor_snap.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_cursor_snap.c | 30 |
1 files changed, 23 insertions, 7 deletions
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) && |