diff options
Diffstat (limited to 'object_fracture_cell/operator.py')
-rw-r--r-- | object_fracture_cell/operator.py | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/object_fracture_cell/operator.py b/object_fracture_cell/operator.py index cd8dca00..7bc35a46 100644 --- a/object_fracture_cell/operator.py +++ b/object_fracture_cell/operator.py @@ -24,27 +24,32 @@ class FRACTURE_OT_Cell(Operator): bl_description = "Make fractured cells from selected object." bl_options = {'REGISTER', 'UNDO'} - def execute(self, context): + @classmethod + def poll(cls, context): + obj = context.active_object + return obj and obj.type == "MESH" + + def execute(self, context): #keywords = self.as_keywords() # ignore=("blah",) - + fracture_cell_props = context.window_manager.fracture_cell_props cell_keywords = utilities._cell_props_to_dict(fracture_cell_props) - - originals = context.selected_editable_objects + + originals = context.selected_editable_objects for original in originals: cell_main.main(context, original, **cell_keywords) - + return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager - return wm.invoke_props_dialog(self, width=600) - - def draw(self, context): + return wm.invoke_props_dialog(self, width=350) + + def draw(self, context): cell_props = context.window_manager.fracture_cell_props - + layout = self.layout - + box = layout.box() col = box.column() col.label(text="Fracture From") @@ -52,23 +57,24 @@ class FRACTURE_OT_Cell(Operator): #row.prop(cell_props, "source") row.prop(cell_props, "source_vert_own") row.prop(cell_props, "source_particle_own") - row.prop(cell_props, "source_random") row = col.row() + row.prop(cell_props, "source_random") row.prop(cell_props, "source_vert_child") + row = col.row() row.prop(cell_props, "source_particle_child") row.prop(cell_props, "source_pencil") - + box = layout.box() col = box.column() col.label(text="Transform") row = col.row() row.prop(cell_props, "pre_simplify") row.prop(cell_props, "source_noise") + row = col.row(align=True) row.prop(cell_props, "margin") + row.prop(cell_props, "use_recenter") row = col.row(align=True) - row.prop(cell_props, "cell_scale") - row.prop(cell_props, "use_recenter") # could be own section, control how we subdiv #row.prop(cell_props, "use_island_split") @@ -76,38 +82,37 @@ class FRACTURE_OT_Cell(Operator): col = box.column() col.label(text="Recursive Shatter") row = col.row(align=True) - row.alignment = 'LEFT' row.prop(cell_props, "recursion") + row.prop(cell_props, "recursion_chance") row = col.row(align=True) - row.alignment = 'LEFT' if cell_props.recursion > 0: row.enabled = True else: row.enabled = False row.prop(cell_props, "recursion_source_limit") row.prop(cell_props, "recursion_clamp") - row.prop(cell_props, "recursion_chance") + row = col.row() row.prop(cell_props, "recursion_chance_select")#, expand=True) box = layout.box() col = box.column() col.label(text="Interior Meshes") row = col.row(align=True) - row.alignment = 'LEFT' - row.prop(cell_props, "use_data_match") + row.prop(cell_props, "use_data_match") row.prop(cell_props, "use_interior_vgroup") - row.prop(cell_props, "use_smooth_faces") + row = col.row(align=True) + row.prop(cell_props, "use_smooth_faces") row.prop(cell_props, "use_sharp_edges") if cell_props.use_sharp_edges == True: row.prop(cell_props, "use_sharp_edges_apply") - + row = col.row() if cell_props.use_data_match == True: row.enabled = True else: row.enabled = False row.alignment = 'LEFT' - # on same row for even layout but infact are not all that related + # on same row for even layout but infact are not all that related row.prop(cell_props, "material_index") box = layout.box() @@ -121,28 +126,31 @@ class FRACTURE_OT_Cell(Operator): row = col.row(align=True) row.prop(cell_props, "mass_mode") row.prop(cell_props, "mass") - + box = layout.box() col = box.column() - col.label(text="Scene Management") + col.label(text="Object Management") row = col.row(align=True) - row.alignment = 'LEFT' row.prop(cell_props, "original_hide") row.prop(cell_props, "cell_relocate") + + box = layout.box() + col = box.column() + col.label(text="Collections:") row = col.row(align=True) row.prop(cell_props, "use_collection") if cell_props.use_collection: row.prop(cell_props, "new_collection") row.prop(cell_props, "collection_name") - + box = layout.box() col = box.column() col.label(text="Debug") row = col.row(align=True) - row.prop(cell_props, "use_debug_redraw") row.prop(cell_props, "use_debug_points") row.prop(cell_props, "use_debug_bool") - + row = col.row(align=True) + row.prop(cell_props, "use_debug_redraw") class FRACTURE_OT_Crack(Operator): bl_idname = "object.add_fracture_crack" @@ -150,36 +158,41 @@ class FRACTURE_OT_Crack(Operator): bl_description = "Make a cracked object from cell objects" bl_options = {'REGISTER', 'UNDO'} + @classmethod + def poll(cls, context): + obj = context.active_object + return obj and obj.type == "MESH" + def invoke(self, context, event): wm = context.window_manager - return wm.invoke_props_dialog(self, width=600) - - def execute(self, context): + return wm.invoke_props_dialog(self, width=350) + + def execute(self, context): crack_props = context.window_manager.fracture_crack_props - + cells = context.selected_editable_objects object = None - - if cells: + + if cells: # clear sharp edges for correct crack surface. bpy.context.view_layer.objects.active = cells[0] bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.reveal() - + bpy.ops.mesh.mark_sharp(clear=True, use_verts=True) - bpy.ops.object.mode_set(mode='OBJECT') - + bpy.ops.object.mode_set(mode='OBJECT') + for cell in cells: bpy.context.view_layer.objects.active = cell bpy.ops.object.modifier_remove(modifier="EDGE_SPLIT_cell") bpy.context.object.vertex_groups.clear() - + bpy.context.view_layer.objects.active = cells[0] object = crack_functions.make_join(cells) - + if object: bpy.context.view_layer.objects.active = object - + crack_functions.add_modifiers() bpy.context.object.modifiers['DECIMATE_crackit'].ratio = crack_props.modifier_decimate bpy.context.object.modifiers['SMOOTH_crackit'].factor = crack_props.modifier_smooth @@ -193,19 +206,19 @@ class FRACTURE_OT_Crack(Operator): ) bpy.ops.object.modifier_apply(apply_as='DATA', modifier='DECIMATE_crackit') bpy.ops.object.shade_smooth() - + if crack_props.modifier_wireframe == True: bpy.ops.object.modifier_add(type='WIREFRAME') wireframe = bpy.context.object.modifiers[-1] wireframe.name = 'WIREFRAME_crackit' wireframe.use_even_offset = False - wireframe.thickness = 0.01 + wireframe.thickness = 0.01 else: assert("Joining into One object had been failed. Mesh object can only be joined.") - + return {'FINISHED'} - def draw(self, context): + def draw(self, context): cell_props = context.window_manager.fracture_cell_props crack_props = context.window_manager.fracture_crack_props layout = self.layout @@ -213,7 +226,7 @@ class FRACTURE_OT_Crack(Operator): box = layout.box() col = box.column() col.label(text='* Execute After "1. Cell Fracture"') - + box = layout.box() col = box.column() col.label(text="Surface:") @@ -221,20 +234,20 @@ class FRACTURE_OT_Crack(Operator): row.alignment = 'LEFT' row.prop(crack_props, "modifier_decimate") row.prop(crack_props, "modifier_smooth") - + col = box.column() - col.label(text="Extrude:") - row = col.row(align=True) + col.label(text="Extrude:") + row = col.row(align=True) row.prop(crack_props, "extrude_scale") row.prop(crack_props, "extrude_var") row.prop(crack_props, "extrude_num") - - col = box.column() + + col = box.column() col.label(text="Post Processing") row = col.row(align=True) row.prop(crack_props, "modifier_wireframe") - - + + class FRACTURE_OT_Material(Operator): bl_idname = "object.add_fracture_material" bl_label = "Material Preset" @@ -248,9 +261,9 @@ class FRACTURE_OT_Material(Operator): included = ['MESH', 'CURVE', 'SURFACE', 'FONT', 'META'] return (obj is not None and obj.type in included) - def execute(self, context): + def execute(self, context): material_props = context.window_manager.fracture_material_props - + mat_name = material_props.material_preset mat_lib_name = material_props.material_lib_name mat_ui_name = material_props.get_ui_mat_name(mat_name) if not mat_lib_name else mat_name |