[Bf-blender-cvs] [4475c49e2f9] master: Fix T81591: Align view to active is not working in sculpt mode

Campbell Barton noreply at git.blender.org
Fri Oct 16 13:17:50 CEST 2020


Commit: 4475c49e2f901ba034b086ca856848ee2071af34
Author: Campbell Barton
Date:   Fri Oct 16 21:48:35 2020 +1100
Branches: master
https://developer.blender.org/rB4475c49e2f901ba034b086ca856848ee2071af34

Fix T81591: Align view to active is not working in sculpt mode

Remove sculpt/paint checks in getTransformOrientation_ex
This code goes back a long time (early 2.5x). I couldn't find any
reason why sculpt/paint checks were being made.

This makes the following changes:

- When in object mode, the object must be selected.
  Since this function typically operates on the selected items.

- When in paint/particle modes, the objects matrix is always
  used regardless of selection, since object selection can't be
  controlled in these modes.

- When there is no active object, the first selected object is no
  longer used as it's quite an arbitrary decision & not something
  done elsewhere with objects in Blender.

===================================================================

M	source/blender/editors/transform/transform_orientations.c

===================================================================

diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 3cd4c12980c..8ad61288461 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -744,7 +744,6 @@ int getTransformOrientation_ex(const bContext *C,
 {
   ViewLayer *view_layer = CTX_data_view_layer(C);
   View3D *v3d = CTX_wm_view3d(C);
-  Base *base;
   int result = ORIENTATION_NONE;
   const bool activeOnly = (around == V3D_AROUND_ACTIVE);
 
@@ -1236,30 +1235,30 @@ int getTransformOrientation_ex(const bContext *C,
       result = ORIENTATION_EDGE;
     }
   }
-  else if (ob && (ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) {
-    /* pass */
-  }
   else {
     /* we need the one selected object, if its not active */
-    base = BASACT(view_layer);
-    ob = OBACT(view_layer);
-    if (base && ((base->flag & BASE_SELECTED) != 0)) {
-      /* pass */
-    }
-    else {
-      /* first selected */
-      ob = NULL;
-      for (base = view_layer->object_bases.first; base; base = base->next) {
-        if (BASE_SELECTED_EDITABLE(v3d, base)) {
-          ob = base->object;
-          break;
+    if (ob != NULL) {
+      bool ok = false;
+      if (activeOnly || (ob->mode & (OB_MODE_ALL_PAINT | OB_MODE_PARTICLE_EDIT))) {
+        /* Ignore selection state. */
+        ok = true;
+      }
+      else {
+        Base *base = BKE_view_layer_base_find(view_layer, ob);
+        if (UNLIKELY(base == NULL)) {
+          /* This is very unlikely, if it happens allow the value to be set since the caller
+           * may have taken the object from outside this view-layer. */
+          ok = true;
+        }
+        else if (BASE_SELECTED(v3d, base)) {
+          ok = true;
         }
       }
-    }
 
-    if (ob) {
-      copy_v3_v3(normal, ob->obmat[2]);
-      copy_v3_v3(plane, ob->obmat[1]);
+      if (ok) {
+        copy_v3_v3(normal, ob->obmat[2]);
+        copy_v3_v3(plane, ob->obmat[1]);
+      }
     }
     result = ORIENTATION_NORMAL;
   }



More information about the Bf-blender-cvs mailing list