adds option for different selection modes

This commit is contained in:
Michel Fedde 2024-01-30 20:19:58 +01:00
parent 53366cc71d
commit 060612d789
7 changed files with 95 additions and 15 deletions

View file

@ -13,4 +13,19 @@ class BakeToIDMapPanel(bpy.types.Panel):
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
self.layout.operator("object.bake_to_id_map", text="Bake")
props = context.scene.bake_to_id_props
operator_row = layout.row()
operator_row.operator("object.bake_to_id_map", text="Bake")
operator_row.enabled = self.check_if_props_valid(context, props)
layout.prop(props, "selection_mode")
def check_if_props_valid(self, context, props):
if (props.selection_mode == "SINGLE" and context.active_object is None):
return False
if (props.selection_mode != "SINGLE" and len(context.selected_objects) < 1):
return False
return True

View file

@ -19,5 +19,28 @@ class BakeToIDInfoPanel(bpy.types.Panel):
source = get_source(props.source)
layout.label(text="Selected Object-Count: " + str(len(context.selected_objects)))
layout.label(text="Estimated ID-Count: " + str(source.estimate_ids(context, props)))
if props.selection_mode != 'SINGLE':
layout.label(text="Selected Object-Count: " + str(len(context.selected_objects)))
layout.separator()
if props.selection_mode == 'SINGLE':
layout.label(text="ID-Total: " + str(source.estimate_ids([context.active_object])))
if props.selection_mode == 'MULTIPLE_SEPARATE':
total = 0
count = 0
for obj in context.selected_objects:
if (obj.type != 'MESH'):
continue
total += source.estimate_ids([obj])
count += 1
layout.label(text="Estimated ID-Total: " + str(total))
try:
layout.label(text="Estimated ID-Average: " + str(total / count))
except ZeroDivisionError:
layout.label(text="Estimated ID-Average: 0")
if props.selection_mode == 'MULTIPLE_COMBINED':
layout.label(text="ID-Total: " + str(source.estimate_ids(context.selected_objects)))

View file

@ -15,6 +15,8 @@ class BakeToIDOptionsPanel(bpy.types.Panel):
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
props = context.scene.bake_to_id_props