diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-19 06:06:45 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-19 06:06:45 +0300 |
commit | 76b674198123eb0c5d77270ae037ad9c6c32c321 (patch) | |
tree | 2d5456125445b0d290ecc3081469f69f45ac9818 | |
parent | 214e61fc2ca17affc971d7f7838a748ea8e93b4a (diff) |
Fix View Roll failure to align the quaternion to the view-axis
View roll checked if the resulting roll was close to a view axis
but didn't write the aligned quaternion back to the final result.
Add ED_view3d_quat_to_axis_view_and_reset_quat since most callers
to ED_view3d_quat_to_axis_view will reset the quaternion when a view
aligned axis is found.
4 files changed, 27 insertions, 9 deletions
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 1e9b68c0920..51fd8e6c533 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -1064,6 +1064,16 @@ bool ED_view3d_quat_to_axis_view(const float viewquat[4], float epsilon, char *r_view, char *r_view_axis_rotation); +/** + * A version of #ED_view3d_quat_to_axis_view that updates `viewquat` + * if it's within `epsilon` to an axis-view. + * + * \note Include the special case function since most callers need to perform these operations. + */ +bool ED_view3d_quat_to_axis_view_and_reset_quat(float viewquat[4], + float epsilon, + char *r_view, + char *r_view_axis_rotation); char ED_view3d_lock_view_from_index(int index); char ED_view3d_axis_view_opposite(char view); diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c index ea21eed6445..087ca72211e 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_roll.c +++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c @@ -48,11 +48,7 @@ static void view_roll_angle(ARegion *region, normalize_qt(quat); if (use_axis_view && RV3D_VIEW_IS_AXIS(rv3d->view) && (fabsf(angle) == (float)M_PI_2)) { - if (ED_view3d_quat_to_axis_view(quat, 0.01f, &rv3d->view, &rv3d->view_axis_roll)) { - if (rv3d->view != RV3D_VIEW_USER) { - ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_mul); - } - } + ED_view3d_quat_to_axis_view_and_reset_quat(quat, 0.01f, &rv3d->view, &rv3d->view_axis_roll); } else { rv3d->view = RV3D_VIEW_USER; diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c index c9ef6422982..989fa152acc 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c +++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c @@ -162,10 +162,8 @@ static void viewrotate_apply_snap(ViewOpsData *vod) if (found) { /* lock 'quat_best' to an axis view if we can */ - ED_view3d_quat_to_axis_view(quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll); - if (rv3d->view != RV3D_VIEW_USER) { - ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_best); - } + ED_view3d_quat_to_axis_view_and_reset_quat( + quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll); } else { copy_qt_qt(quat_best, viewquat_align); diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index e6895c0f4a3..dd0d5966a76 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -1333,6 +1333,20 @@ bool ED_view3d_quat_to_axis_view(const float quat[4], return false; } +bool ED_view3d_quat_to_axis_view_and_reset_quat(float quat[4], + const float epsilon, + char *r_view, + char *r_view_axis_roll) +{ + const bool is_axis_view = ED_view3d_quat_to_axis_view(quat, epsilon, r_view, r_view_axis_roll); + if (is_axis_view) { + /* Reset `quat` to it's view axis, so axis-aligned views are always *exactly* aligned. */ + BLI_assert(*r_view != RV3D_VIEW_USER); + ED_view3d_quat_from_axis_view(*r_view, *r_view_axis_roll, quat); + } + return is_axis_view; +} + char ED_view3d_lock_view_from_index(int index) { switch (index) { |