Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-05-19 06:44:36 +0300
committerCampbell Barton <campbell@blender.org>2022-05-19 07:31:22 +0300
commit3ecc03c3d6b7baeee900a7ffd97fc0c2701adbc5 (patch)
treea1e24b86780eb540814427d7aa5480754a558ebe /source/blender/editors
parent76b674198123eb0c5d77270ae037ad9c6c32c321 (diff)
Fix T93779: Python is unable to set axis aligned views
It wasn't possible to temporarily orbit the view, then set back to an axis-aligned view. Details: - It was possible to change RegionView3D.view_rotation while the view kept the axis alignment value (Top, Left, Front .. etc) which displayed in the viewport overlay. Now changing the view rotation directly or via "view_matrix" resets the axis-alignment - clearing when the view is no longer axis-aligned or assigning the newly aligned axis. - RegionView3D.is_orthographic_side_view added in [0] could be assigned but wasn't useful as it treated an enum as a boolean only setting the RegionView3D.view to RV3D_VIEW_USER or RV3D_VIEW_FRONT. Now enabling this aligns the viewport rotation to it's closest axis-aligned orientation setting RegionView3D.view & view_axis_roll accordingly. Note that the "orthographic" term is misleading as the property only relates to axis-alignment, not to the perspective/orthographic setting. We could consider deprecating the current naming. [0]: 63bae864f40302b0a303498d26f230caf4f24339
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index dd0d5966a76..51f50633468 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -1317,17 +1317,40 @@ bool ED_view3d_quat_to_axis_view(const float quat[4],
*r_view = RV3D_VIEW_USER;
*r_view_axis_roll = RV3D_VIEW_AXIS_ROLL_0;
- /* quat values are all unit length */
- for (int view = RV3D_VIEW_FRONT; view <= RV3D_VIEW_BOTTOM; view++) {
- for (int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270;
- view_axis_roll++) {
- if (fabsf(angle_signed_qtqt(
- quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll])) < epsilon) {
- *r_view = view;
- *r_view_axis_roll = view_axis_roll;
- return true;
+ /* Quaternion values are all unit length. */
+
+ if (epsilon < M_PI_4) {
+ /* Under 45 degrees, just pick the closest value. */
+ for (int view = RV3D_VIEW_FRONT; view <= RV3D_VIEW_BOTTOM; view++) {
+ for (int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270;
+ view_axis_roll++) {
+ if (fabsf(angle_signed_qtqt(
+ quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll])) < epsilon) {
+ *r_view = view;
+ *r_view_axis_roll = view_axis_roll;
+ return true;
+ }
+ }
+ }
+ }
+ else {
+ /* Epsilon over 45 degrees, check all & find use the closest. */
+ float delta_best = FLT_MAX;
+ for (int view = RV3D_VIEW_FRONT; view <= RV3D_VIEW_BOTTOM; view++) {
+ for (int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270;
+ view_axis_roll++) {
+ const float delta_test = fabsf(
+ angle_signed_qtqt(quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll]));
+ if (delta_best > delta_test) {
+ delta_best = delta_test;
+ *r_view = view;
+ *r_view_axis_roll = view_axis_roll;
+ }
}
}
+ if (*r_view != RV3D_VIEW_USER) {
+ return true;
+ }
}
return false;