Collection Manager: Fix T78985. Task: T69577

Refactored the functions get_move_selection and get_move_active
to be faster by using sets and looping through all the objects
instead of looping through the selected objects and using direct
object lookups, except for special cases where direct lookups are
actually faster.

Removed unneeded calls to get_move_selection and get_move_active.
This commit is contained in:
Ryan Inch 2020-08-01 23:16:39 -04:00
parent 7da2a313f9
commit adac42a463
Notes: blender-bot 2023-02-14 18:51:13 +01:00
Referenced by commit 7084d19e: Collection Manager: Fix regression. Task: T69577
Referenced by commit 497e97cf: Collection Manager: Fix regression. Task: T69577
Referenced by commit 7084d19e, Collection Manager: Fix regression. Task: T69577
Referenced by commit 497e97cf, Collection Manager: Fix regression. Task: T69577
Referenced by issue #78985, Collection Manager: Performance impact when selecting a large number of objects
4 changed files with 32 additions and 15 deletions

View File

@ -22,7 +22,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (2, 12, 2),
"version": (2, 12, 3),
"blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel

View File

@ -597,13 +597,21 @@ def generate_state():
return state
def get_move_selection():
def get_move_selection(*, names_only=False):
global move_selection
if not move_selection:
move_selection = [obj.name for obj in bpy.context.selected_objects]
move_selection = {obj.name for obj in bpy.context.selected_objects}
return [bpy.data.objects[name] for name in move_selection]
if names_only:
return move_selection
else:
if len(move_selection) <= 5:
return {bpy.data.objects[name] for name in move_selection}
else:
return {obj for obj in bpy.data.objects if obj.name in move_selection}
def get_move_active():
@ -613,7 +621,7 @@ def get_move_active():
if not move_active:
move_active = getattr(bpy.context.view_layer.objects.active, "name", None)
if move_active not in [obj.name for obj in get_move_selection()]:
if move_active not in get_move_selection(names_only=True):
move_active = None
return bpy.data.objects[move_active] if move_active else None

View File

@ -655,6 +655,10 @@ def allocate_main_ui(self, context):
self.areas["Button Row 2 B"] = button_row_2_b
selected_objects = qcd_operators.get_move_selection()
active_object = qcd_operators.get_move_active()
# BUTTONS
def get_buttons(button_row, row_num):
cur_width_pos = button_row["vert"][0]
@ -667,8 +671,6 @@ def allocate_main_ui(self, context):
if qcd_slot_name:
qcd_laycol = layer_collections[qcd_slot_name]["ptr"]
collection_objects = qcd_laycol.collection.objects
selected_objects = qcd_operators.get_move_selection()
active_object = qcd_operators.get_move_active()
# BUTTON
x = cur_width_pos

View File

@ -178,8 +178,12 @@ class CollectionManager(Operator):
row_setcol = global_rto_row.row()
row_setcol.alignment = 'LEFT'
row_setcol.operator_context = 'INVOKE_DEFAULT'
selected_objects = get_move_selection()
active_object = get_move_active()
CM_UL_items.selected_objects = selected_objects
CM_UL_items.active_object = active_object
collection = context.view_layer.layer_collection.collection
icon = 'MESH_CUBE'
@ -188,7 +192,7 @@ class CollectionManager(Operator):
if active_object and active_object.name in collection.objects:
icon = 'SNAP_VOLUME'
elif not set(selected_objects).isdisjoint(collection.objects):
elif not selected_objects.isdisjoint(collection.objects):
icon = 'STICKY_UVS_LOC'
else:
@ -437,6 +441,9 @@ class CollectionManager(Operator):
class CM_UL_items(UIList):
last_filter_value = ""
selected_objects = set()
active_object = None
filter_by_selected: BoolProperty(
name="Filter By Selected",
default=False,
@ -456,8 +463,8 @@ class CM_UL_items(UIList):
view_layer = context.view_layer
laycol = layer_collections[item.name]
collection = laycol["ptr"].collection
selected_objects = get_move_selection()
active_object = get_move_active()
selected_objects = CM_UL_items.selected_objects
active_object = CM_UL_items.active_object
column = layout.column(align=True)
@ -545,7 +552,7 @@ class CM_UL_items(UIList):
if active_object and active_object.name in collection.objects:
icon = 'SNAP_VOLUME'
elif not set(selected_objects).isdisjoint(collection.objects):
elif not selected_objects.isdisjoint(collection.objects):
icon = 'STICKY_UVS_LOC'
else:
@ -781,14 +788,15 @@ def view3d_header_qcd_slots(self, context):
update_collection_tree(context)
selected_objects = get_move_selection()
active_object = get_move_active()
for x in range(20):
qcd_slot_name = qcd_slots.get_name(str(x+1))
if qcd_slot_name:
qcd_laycol = layer_collections[qcd_slot_name]["ptr"]
collection_objects = qcd_laycol.collection.objects
selected_objects = get_move_selection()
active_object = get_move_active()
icon_value = 0
@ -797,9 +805,8 @@ def view3d_header_qcd_slots(self, context):
active_object.name in collection_objects):
icon = 'LAYER_ACTIVE'
# if there are selected objects use LAYER_ACTIVE
elif not set(selected_objects).isdisjoint(collection_objects):
elif not selected_objects.isdisjoint(collection_objects):
icon = 'LAYER_USED'
# If there are objects use LAYER_USED