1 # gpl: author Nobuyuki Hirakata
4 from bpy
.types
import (
11 def check_object_cell_fracture():
12 if "object_fracture_cell" in bpy
.context
.user_preferences
.addons
.keys():
17 # Access by bpy.ops.mesh.crackit_fracture
18 class FractureOperation(Operator
):
19 bl_idname
= "mesh.crackit_fracture"
20 bl_label
= "Crack it!"
21 bl_description
= ("Make cracks using the cell fracture add-on\n"
22 "Needs only one Selected Mesh Object")
23 bl_options
= {'REGISTER', 'UNDO'}
26 def poll(cls
, context
):
27 obj
= context
.active_object
28 sel_obj
= len(context
.selected_objects
) == 1
30 return (obj
is not None and obj
.type == "MESH" and sel_obj
)
32 def execute(self
, context
):
33 if check_object_cell_fracture():
34 crackit
= context
.scene
.crackit
36 crack_it
.makeFracture(
37 child_verts
=crackit
.fracture_childverts
,
38 division
=crackit
.fracture_div
, scaleX
=crackit
.fracture_scalex
,
39 scaleY
=crackit
.fracture_scaley
, scaleZ
=crackit
.fracture_scalez
,
40 margin
=crackit
.fracture_margin
42 crack_it
.addModifiers()
43 crack_it
.multiExtrude(
44 off
=crackit
.extrude_offset
,
45 var2
=crackit
.extrude_random
, var3
=crackit
.extrude_random
47 bpy
.ops
.object.shade_smooth()
49 except Exception as e
:
50 crack_it
.error_handlers(
51 self
, "mesh.crackit_fracture", e
, "Crack It! could not be completed."
55 self
.report({'WARNING'},
56 "Depends on Object: Cell Fracture addon. Please enable it first. "
64 # Apply material preset
65 # Access by bpy.ops.mesh.crackit_material
66 class MaterialOperation(Operator
):
67 bl_idname
= "mesh.crackit_material"
68 bl_label
= "Apply Material"
69 bl_description
= ("Apply a preset material\n"
70 "The Material will be applied to the Active Object\n"
71 "from the type of Mesh, Curve, Surface, Font, Meta")
72 bl_options
= {'REGISTER', 'UNDO'}
75 def poll(cls
, context
):
76 obj
= context
.active_object
77 # included - type that can have materials
78 included
= ['MESH', 'CURVE', 'SURFACE', 'FONT', 'META']
79 return (obj
is not None and obj
.type in included
)
81 def execute(self
, context
):
82 crackit
= context
.scene
.crackit
83 mat_name
= crackit
.material_preset
84 mat_lib_name
= crackit
.material_lib_name
85 mat_ui_name
= crack_it
.get_ui_mat_name(mat_name
) if not mat_lib_name
else mat_name
88 crack_it
.appendMaterial(
89 addon_path
=crackit
.material_addonpath
,
90 material_name
=mat_name
,
91 mat_ui_names
=mat_ui_name
93 except Exception as e
:
94 crack_it
.error_handlers(
95 self
, "mesh.crackit_material", e
,
96 "The active Object could not have the Material {} applied".format(mat_ui_name
)
104 class crackitPanel(Panel
):
105 bl_label
= "Crack it!"
106 bl_idname
= 'crack_it'
107 bl_space_type
= "VIEW_3D"
108 bl_region_type
= "TOOLS"
109 bl_category
= "Create"
110 bl_context
= 'objectmode'
111 bl_options
= {"DEFAULT_CLOSED"}
113 def draw(self
, context
):
114 crackit
= context
.scene
.crackit
121 # Warning if the fracture cell addon is not enabled
122 if not check_object_cell_fracture():
124 col
.label(text
="Please enable Object: Cell Fracture addon", icon
="INFO")
126 col
.operator("wm.addon_userpref_show",
127 text
="Go to Cell Fracture addon",
128 icon
="PREFERENCES").module
= "object_fracture_cell"
133 row
.operator(FractureOperation
.bl_idname
, icon
="SPLITSCREEN")
136 row
.prop(crackit
, "fracture_childverts")
138 col
= box
.column(align
=True)
139 col
.prop(crackit
, "fracture_scalex")
140 col
.prop(crackit
, "fracture_scaley")
141 col
.prop(crackit
, "fracture_scalez")
143 col
= box
.column(align
=True)
144 col
.label("Settings:")
145 col
.prop(crackit
, "fracture_div")
146 col
.prop(crackit
, "fracture_margin")
148 col
= box
.column(align
=True)
149 col
.label("Extrude:")
150 col
.prop(crackit
, "extrude_offset")
151 col
.prop(crackit
, "extrude_random")
156 row
.label("Material Preset:")
158 row_sub
.prop(crackit
, "material_lib_name", text
="",
159 toggle
=True, icon
="LONGDISPLAY")
161 row
.prop(crackit
, "material_preset")
164 row
.operator(MaterialOperation
.bl_idname
)