Welcome to mirror list, hosted at ThFree Co, Russian Federation.

__init__.py « object_fracture_cell - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7adc80f348b5fa1efa5510586e9cc0ea5ebe647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
    "name": "Cell Fracture",
    "author": "ideasman42, phymec, Sergey Sharybin, Nobuyuki Hirakata",
    "version": (1, 0, 1),
    "blender": (2, 80, 0),
    "location": "View3D > Sidebar > Transform tab",
    "description": "Fractured Object, or Cracked Surface",
    "warning": "Work in Progress",
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
                "Scripts/Object/CellFracture",
    "category": "Object"}


if "bpy" in locals():
    import importlib
    importlib.reload(operator)

else:
    from . import operator

import bpy
from bpy.props import (
        StringProperty,
        BoolProperty,
        IntProperty,
        FloatProperty,
        FloatVectorProperty,
        EnumProperty,
        BoolVectorProperty,
        PointerProperty,
        )

from bpy.types import (
        Panel,
        PropertyGroup,
        )        


class FRACTURE_PT_Menu(Panel):
    bl_idname = 'FRACTURE_PT_Menu'
    bl_label = "Fracture Cell"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Transform"
    bl_context = 'objectmode'
    bl_options = {"DEFAULT_CLOSED"}
    
    def draw(self, context):
        # Show pop-upped menu when the button is hit.
        layout = self.layout
        #layout.label(text="Cell Fracture:")
        layout.operator(operator.FRACTURE_OT_Cell.bl_idname,
                    text="1. Cell Fracture")       
        layout.operator(operator.FRACTURE_OT_Crack.bl_idname,
                    text="2. Cell to Crack")
        
        material_props = context.window_manager.fracture_material_props
        layout.separator()
        box = layout.box()
        col = box.column()
        row = col.row(align=True)
        row.label(text="Material Preset:")
        '''
        row_sub = row.row()
        row_sub.prop(material_props, "material_lib_name", text="",
                     toggle=True, icon="LONGDISPLAY")
        '''
        row = box.row()
        row.prop(material_props, "material_preset", text="")

        row = box.row()
        row.operator(operator.FRACTURE_OT_Material.bl_idname, icon="MATERIAL_DATA",
                    text="Append Material")       


class FractureCellProperties(PropertyGroup):              
    # -------------------------------------------------------------------------
    # Source Options
    source_vert_own: IntProperty(
            name="Own Verts",
            description="Use own vertices",
            min=0, max=2000,
            default=100,
            )
    source_vert_child: IntProperty(
            name="Child Verts",
            description="Use child object vertices",
            min=0, max=2000,
            default=0,
            )
    source_particle_own: IntProperty(
            name="Own Particles",
            description="All particle systems of the source object",
            min=0, max=2000,
            default=0,
            )
    source_particle_child: IntProperty(
            name="Child Particles",
            description="All particle systems of the child objects",
            min=0, max=2000,
            default=0,
            )
    source_pencil: IntProperty(
            name="Annotation Pencil",
            description="Annotation Grease Pencil",
            min=0, max=2000,
            default=0,
            )
    source_random: IntProperty(
            name="Random",
            description="Random seed position",
            min=0, max=2000,
            default=0,
            )
    '''        
    source_limit: IntProperty(
            name="Source Limit",
            description="Limit the number of input points, 0 for unlimited",
            min=0, max=5000,
            default=100,
            )
    '''    
    # -------------------------------------------------------------------------
    # Transform 
    source_noise: FloatProperty(
            name="Noise",
            description="Randomize point distribution",
            min=0.0, max=1.0,
            default=0.0,
            )
    margin: FloatProperty(
            name="Margin",
            description="Gaps for the fracture (gives more stable physics)",
            min=0.0, max=1.0,
            default=0.001,
            )
    cell_scale: FloatVectorProperty(
            name="Scale",
            description="Scale Cell Shape",
            size=3,
            min=0.0, max=1.0,
            default=(1.0, 1.0, 1.0),
            )
    pre_simplify : FloatProperty(
            name="Simplify Base Mesh",
            description="Simplify base mesh before making cell. Lower face size, faster calculation",
            default=0.00,
            min=0.00,
            max=1.00
            )
    use_recenter: BoolProperty(
            name="Recenter",
            description="Recalculate the center points after splitting",
            default=True,
            )
    use_island_split: BoolProperty(
            name="Split Islands",
            description="Split disconnected meshes",
            default=True,
            )
    # -------------------------------------------------------------------------
    # Recursion
    recursion: IntProperty(
            name="Recursion",
            description="Break shards recursively",
            min=0, max=2000,
            default=0,
            )
    recursion_source_limit: IntProperty(
            name="Fracture Each",
            description="Limit the number of input points, 0 for unlimited (applies to recursion only)",
            min=2, max=2000, # Oviously, dividing in more than two objects is needed, to avoid no fracture object. 
            default=8,
            )
    recursion_clamp: IntProperty(
            name="Max Fracture",
            description="Finish recursion when this number of objects is reached (prevents recursing for extended periods of time), zero disables",
            min=0, max=10000,
            default=250,
            )
    recursion_chance: FloatProperty(
            name="Recursion Chance",
            description="Likelihood of recursion",
            min=0.0, max=1.0,
            default=1.00,
            )
    recursion_chance_select: EnumProperty(
            name="Target",
            items=(('RANDOM', "Random", ""),
                   ('SIZE_MIN', "Small", "Recursively subdivide smaller objects"),
                   ('SIZE_MAX', "Big", "Recursively subdivide bigger objects"),
                   ('CURSOR_MIN', "Cursor Close", "Recursively subdivide objects closer to the cursor"),
                   ('CURSOR_MAX', "Cursor Far", "Recursively subdivide objects farther from the cursor"),
                   ),
            default='SIZE_MIN',
            )
    # -------------------------------------------------------------------------
    # Interior Meshes Options
    use_smooth_faces: BoolProperty(
            name="Smooth Faces",
            description="Smooth Faces of inner side",
            default=False,
            )
    use_sharp_edges: BoolProperty(
            name="Mark Sharp Edges",
            description="Set sharp edges when disabled",
            default=False,
            )
    use_sharp_edges_apply: BoolProperty(
            name="Edge Split Modifier",
            description="Add edge split modofier for sharp edges",
            default=False,
            )
    use_data_match: BoolProperty(
            name="Copy Original Data",
            description="Match original mesh materials and data layers",
            default=True,
            )
    material_index: IntProperty(
            name="Interior Material Slot",
            description="Material index for interior faces",
            default=0,
            )
    use_interior_vgroup: BoolProperty(
            name="Vertex Group",
            description="Create a vertex group for interior verts",
            default=False,
            )
    # -------------------------------------------------------------------------
    # Scene Options    
    use_collection: BoolProperty(
            name="Use Collection",
            description="Use collection to organize fracture objects",
            default=True,
            )    
    new_collection: BoolProperty(
            name="New Collection",
            description="Make new collection for fracture objects",
            default=True,
            )  
    collection_name: StringProperty(
            name="Name",
            description="Collection name.",
            default="Fracture",
            )
    original_hide: BoolProperty(
            name="Hide Original",
            description="Hide original object after cell fracture.",
            default=False,
            )
    cell_relocate : BoolProperty(
            name="Move Beside Original",
            description="Move cells beside the original object.",
            default=False,
            )
    # -------------------------------------------------------------------------
    # Custom Property Options    
    use_mass: BoolProperty(
        name="Mass",
        description="Append mass data on custom properties of cell objects.",
        default=False,
        )   
    mass_name: StringProperty(
        name="Property Name",
        description="Name for custome properties.",
        default="mass",
        )
    mass_mode: EnumProperty(
            name="Mass Mode",
            items=(('VOLUME', "Volume", "Objects get part of specified mass based on their volume"),
                   ('UNIFORM', "Uniform", "All objects get the specified mass"),
                   ),
            default='VOLUME',
            )
    mass: FloatProperty(
            name="Mass Factor",
            description="Mass to give created objects",
            min=0.001, max=1000.0,
            default=1.0,
            )
    # -------------------------------------------------------------------------
    # Debug
    use_debug_points: BoolProperty(
            name="Debug Points",
            description="Create mesh data showing the points used for fracture",
            default=False,
            )

    use_debug_redraw: BoolProperty(
            name="Show Progress Realtime",
            description="Redraw as fracture is done",
            default=False,
            )

    use_debug_bool: BoolProperty(
            name="Debug Boolean",
            description="Skip applying the boolean modifier",
            default=False,
            )

            
class FractureCrackProperties(PropertyGroup):
    modifier_decimate : FloatProperty(
        name="Reduce Faces",
        description="Apply Decimate Modifier to reduce face number",
        default=0.40,
        min=0.00,
        max=1.00
        )
    modifier_smooth : FloatProperty(
            name="Loose | Tight",
            description="Smooth Modifier",
            default=-0.50,
            min=-3.00,
            max=3.00
            )
    extrude_scale : FloatProperty(
            name="Extrude Blob",
            description="Extrude Scale",
            default=0.00,
            min=0.00,
            max=5.00
            )
    extrude_var : FloatProperty(
            name="Extrude Random ",
            description="Extrude Varriant",
            default=0.01,
            min=-4.00,
            max=4.00
            )
    extrude_num : IntProperty(
            name="Extrude Num",
            description="Extrude Number",
            default=1,
            min=0,
            max=10
            )
    modifier_wireframe : BoolProperty(
            name="Wireframe Modifier",
            description="Wireframe Modifier",
            default=False
            )  


class FractureMaterialProperties(PropertyGroup):  
    # Note: you can choose the original name in the library blend
    # or the prop name
    material_preset : EnumProperty(
            name="Preset",
            description="Material Preset",
            items=[
                ('crackit_organic_mud', "Organic Mud", "Mud material"),
                ('crackit_mud', "Mud", "Mud material"),
                ('crackit_tree_moss', "Tree Moss", "Tree Material"),
                ('crackit_tree_dry', "Tree Dry", "Tree Material"),
                ('crackit_tree_red', "Tree Red", "Tree Material"),
                ('crackit_rock', "Rock", "Rock Material"),
                ('crackit_lava', "Lava", "Lava Material"),
                ('crackit_wet-paint', "Wet Paint", "Paint Material"),
                ('crackit_soap', "Soap", "Soap Material"),
                ]
            )
    material_lib_name : BoolProperty(
            name="Library Name",
            description="Use the original Material name from the .blend library\n"
                        "instead of the one defined in the Preset",
            default=True
            )
    
classes = (
    FractureCellProperties,
    FractureCrackProperties,
    FractureMaterialProperties,
    operator.FRACTURE_OT_Cell,
    operator.FRACTURE_OT_Crack,
    operator.FRACTURE_OT_Material,
    FRACTURE_PT_Menu,
    )

def register():
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)

    bpy.types.WindowManager.fracture_cell_props = PointerProperty(
        type=FractureCellProperties
    )
    bpy.types.WindowManager.fracture_crack_props = PointerProperty(
        type=FractureCrackProperties
    )
    bpy.types.WindowManager.fracture_material_props = PointerProperty(
        type=FractureMaterialProperties
    )    
    
def unregister():
    del bpy.types.WindowManager.fracture_material_props
    del bpy.types.WindowManager.fracture_crack_props
    del bpy.types.WindowManager.fracture_cell_props
    
    from bpy.utils import unregister_class
    for cls in reversed(classes):
        unregister_class(cls)