[Bf-blender-cvs] [5058c4b1446] master: Cleanup: localize finding the nearest non-active object on selection

Campbell Barton noreply at git.blender.org
Thu Mar 24 06:32:20 CET 2022


Commit: 5058c4b1446f58bb9a5ddcb65f7353d9df3a594a
Author: Campbell Barton
Date:   Thu Mar 24 15:42:38 2022 +1100
Branches: master
https://developer.blender.org/rB5058c4b1446f58bb9a5ddcb65f7353d9df3a594a

Cleanup: localize finding the nearest non-active object on selection

Move this into it's own block since it only needs to run if the
nearest object is currently selected & active.

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

M	source/blender/editors/space_view3d/view3d_select.c

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

diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 3dbd2edb8e6..28d86f457ee 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2119,10 +2119,13 @@ static Base *mouse_select_eval_buffer(ViewContext *vc,
       }
     }
     else {
-      int select_id_exclude = 0;
-      /* Only exclude active object when it is selected. */
-      if (BASACT(view_layer) && (BASACT(view_layer)->flag & BASE_SELECTED) && hits > 1) {
-        select_id_exclude = BASACT(view_layer)->object->runtime.select_id;
+
+      for (a = 0; a < hits; a++) {
+        /* Any object. */
+        if (min > buffer[a].depth) {
+          min = buffer[a].depth;
+          hit_index = a;
+        }
       }
 
       /* Find the best active & non-active hits.
@@ -2134,38 +2137,37 @@ static Base *mouse_select_eval_buffer(ViewContext *vc,
        *
        * For this reason, keep track of the best hit as well as the best hit that
        * excludes the selected & active object, using this value when it's valid. */
+      if ((hit_index != -1) &&
+          /* Special case, cycling away from the active object should only be done when it
+           * doesn't have a bone selection, otherwise selecting sub-elements is difficult. */
+          ((buffer[hit_index].id & 0xFFFF0000) == 0) &&
+          /* Only exclude active object when it is selected. */
+          (BASACT(view_layer) && (BASACT(view_layer)->flag & BASE_SELECTED))) {
 
-      uint min_not_active = min;
-      int hit_index_not_active = -1;
+        const int select_id_active = BASACT(view_layer)->object->runtime.select_id;
 
-      for (a = 0; a < hits; a++) {
-        /* Any object. */
-        if (min > buffer[a].depth) {
-          min = buffer[a].depth;
-          hit_index = a;
-        }
-        /* Any object other than the active-selected. */
-        if (select_id_exclude != 0) {
-          if (min_not_active > buffer[a].depth && select_id_exclude != (buffer[a].id & 0xFFFF)) {
-            min_not_active = buffer[a].depth;
-            hit_index_not_active = a;
+        /* Check if `hit_index` is the current active object. */
+        if ((buffer[hit_index].id & 0xFFFF) == select_id_active) {
+          uint min_not_active = 0xFFFFFFFF;
+          int hit_index_not_active = -1;
+          for (a = 0; a < hits; a++) {
+            /* Any object other than the active-selected. */
+            if (select_id_active == (buffer[a].id & 0xFFFF)) {
+              continue;
+            }
+            if (min_not_active > buffer[a].depth) {
+              min_not_active = buffer[a].depth;
+              hit_index_not_active = a;
+            }
           }
-        }
-      }
 
-      /* Special case, cycling away from the active object should only be done if the active
-       * object doesn't have a bone selection, otherwise selecting sub-elements is difficult. */
-      if (has_bones && (hit_index != -1)) {
-        if (buffer[hit_index].id & 0xFFFF0000) {
-          hit_index_not_active = -1;
+          /* When the active was selected, first try to use the index
+           * for the best non-active hit that was found. */
+          if (hit_index_not_active != -1) {
+            hit_index = hit_index_not_active;
+          }
         }
       }
-
-      /* When the active was selected, first try to use the index
-       * for the best non-active hit that was found. */
-      if (hit_index_not_active != -1) {
-        hit_index = hit_index_not_active;
-      }
     }
 
     if (hit_index != -1) {



More information about the Bf-blender-cvs mailing list