Public Access
2
0
Files
stocker_helper/scripts/phase3_operator.py
T
2026-04-10 12:22:21 -04:00

60 lines
2.2 KiB
Python

import bpy
def setup_stocker_operator(logic_module):
"""
Wraps the phase 1 & 2 logic into a Blender Operator.
"""
class STOCKER_OT_setup(bpy.types.Operator):
bl_idname = "object.stocker_setup"
bl_label = "Stocker Helper"
bl_description = "Generate a boundary cube for the selected objects"
bl_options = {'REGISTER', 'UNDO'}
mode: bpy.props.EnumProperty(
name="Packing Mode",
description="Select the geometry nodes template to apply",
items=[
('GRID', "Grid Pack", "Use the Grid Pack template"),
('CIRCLE', "Circle Pack", "Use the Circle Pack template"),
# Placeholder for future modes
],
default='GRID'
)
def execute(self, context):
# 1. Get selected objects
selected_objs = context.selected_objects
# 2. Run logic from previous phases
bounds = logic_module.calculate_global_bounds(selected_objs)
if not bounds:
self.report({'ERROR'}, "No valid mesh objects selected.")
return {'CANCELLED'}
# 3. Create the cube
new_obj = logic_module.create_aligned_boundary_cube(bounds)
if not new_obj:
self.report({'ERROR'}, "Failed to create boundary cube.")
return {'CANCELLED'}
# 4. Modifier Injection
# Search for the node group
group_name = "grid_pack" if self.mode == 'GRID' else "Stocker_Circle"
node_group = bpy.data.node_groups.get(group_name)
if not node_group:
self.report({'WARNING'}, f"Node Group '{group_name}' not found. Boundary created without modifier.")
return {'FINISHED'}
# Add Geometry Nodes modifier
mod = new_obj.modifiers.new(name="circle_pack", type='NODES')
mod.node_group = node_group
self.report({'INFO'}, f"Stocker setup complete using {self.mode} mode.")
return {'FINISHED'}
return STOCKER_OT_setup
if __name__ == "__main__":
print("Phase 3: Integration (The Operator) logic loaded.")