From 8a56a6082b6f70571ba39f9bd739734a19710c45 Mon Sep 17 00:00:00 2001 From: Campbell Barton <ideasman42@gmail.com> Date: Tue, 3 Jul 2012 12:16:10 +0000 Subject: [PATCH] fracture updates - added options to fracture into a new group and to use the next layer then the active object. - noise option wasnt working right, was always adding a lot of noise. --- object_fracture_voroni/__init__.py | 117 +++++++++++++----- object_fracture_voroni/fracture_cell_setup.py | 19 ++- 2 files changed, 104 insertions(+), 32 deletions(-) diff --git a/object_fracture_voroni/__init__.py b/object_fracture_voroni/__init__.py index c904777af..38bbd7871 100644 --- a/object_fracture_voroni/__init__.py +++ b/object_fracture_voroni/__init__.py @@ -54,6 +54,9 @@ def main_object(scene, obj, level, **kw): recursion = kw_copy.pop("recursion") recursion_chance = kw_copy.pop("recursion_chance") recursion_chance_select = kw_copy.pop("recursion_chance_select") + use_layer_next = kw_copy.pop("use_layer_next") + group_name = kw_copy.pop("group_name") + from . import fracture_cell_setup @@ -107,10 +110,26 @@ def main_object(scene, obj, level, **kw): scene.objects.unlink(obj_cell) del objects[i] objects.extend(objects_recursive) - + + #-------------- + # Scene Options + + # layer + if use_layer_next: + layers_new = [False] * 20 + layers_new[(obj.layers[:].index(True) + 1) % 20] = True + for obj_cell in objects: + obj_cell.layers = layers_new + # group + if group_name: + group = bpy.data.groups.get(group_name) + if group is None: + group = bpy.data.groups.new(group_name) + for obj_cell in objects: + group.objects.link(obj_cell) # testing only! - obj.hide = True + # obj.hide = True return objects @@ -165,6 +184,34 @@ class FractureCell(Operator): default=0.0, ) + # ------------------------------------------------------------------------- + # Recursion + + recursion = IntProperty( + name="Recursion", + description="Break shards resursively", + min=0, max=5000, + default=0, + ) + + recursion_chance = FloatProperty( + name="Random Factor", + description="Likelyhood of recursion", + min=0.0, max=1.0, + default=1.0, + ) + + recursion_chance_select = EnumProperty( + name="Recurse Over", + items=(('RANDOM', "Random", ""), + ('SIZE_MIN', "Small", "Recursively subdivide smaller objects"), + ('SIZE_MAX', "Big", "Recursively subdivide smaller objects"), + ('CURSOR_MIN', "Cursor Close", "Recursively subdivide objects closer to the cursor"), + ('CURSOR_MAX', "Cursor Far", "Recursively subdivide objects closer to the cursor"), + ), + default='SIZE_MIN', + ) + # ------------------------------------------------------------------------- # Mesh Data Options @@ -214,31 +261,29 @@ class FractureCell(Operator): ) # ------------------------------------------------------------------------- - # Recursion - - recursion = IntProperty( - name="Recursion", - description="Break shards resursively", - min=0, max=5000, - default=0, + # Scene Options + # + # .. dirreferent from object options in that this controls how the objects + # are setup in the scene. + + use_layer_next = BoolProperty( + name="Next Layer", + description="At the object into the next layer", + default=True, ) - recursion_chance = FloatProperty( - name="Random Factor", - description="Likelyhood of recursion", - min=0.0, max=1.0, - default=1.0, + group_name = StringProperty( + name="Group", + description="Create objects int a group " + "(use existing or create new)", ) - recursion_chance_select = EnumProperty( - name="Recurse Over", - items=(('RANDOM', "Random", ""), - ('SIZE_MIN', "Small", "Recursively subdivide smaller objects"), - ('SIZE_MAX', "Big", "Recursively subdivide smaller objects"), - ('CURSOR_MIN', "Cursor Close", "Recursively subdivide objects closer to the cursor"), - ('CURSOR_MAX', "Cursor Far", "Recursively subdivide objects closer to the cursor"), - ), - default='SIZE_MIN', + # ------------------------------------------------------------------------- + # Debug + use_debug_points = BoolProperty( + name="Debug Points", + description="Create mesh data showing the points used for fracture", + default=False, ) def execute(self, context): @@ -252,7 +297,7 @@ class FractureCell(Operator): def invoke(self, context, event): print(self.recursion_chance_select) wm = context.window_manager - return wm.invoke_props_dialog(self, width=1000) + return wm.invoke_props_dialog(self, width=600) def draw(self, context): layout = self.layout @@ -266,6 +311,15 @@ class FractureCell(Operator): rowsub.prop(self, "source_noise") rowsub = col.row() + box = layout.box() + col = box.column() + col.label("Recursive Shatter") + rowsub = col.row(align=True) + rowsub.prop(self, "recursion") + rowsub = col.row() + rowsub.prop(self, "recursion_chance") + rowsub.prop(self, "recursion_chance_select", expand=True) + box = layout.box() col = box.column() col.label("Mesh Data") @@ -282,14 +336,19 @@ class FractureCell(Operator): rowsub = col.row(align=True) rowsub.prop(self, "use_recenter") + box = layout.box() col = box.column() - col.label("Recursive Shatter") + col.label("Scene") rowsub = col.row(align=True) - rowsub.prop(self, "recursion") - rowsub = col.row() - rowsub.prop(self, "recursion_chance") - rowsub.prop(self, "recursion_chance_select", expand=True) + rowsub.prop(self, "use_layer_next") + rowsub.prop(self, "group_name") + + box = layout.box() + col = box.column() + col.label("Debug") + rowsub = col.row(align=True) + rowsub.prop(self, "use_debug_points") #def menu_func(self, context): # self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN") diff --git a/object_fracture_voroni/fracture_cell_setup.py b/object_fracture_voroni/fracture_cell_setup.py index 3f1e08fbf..5c6efc12c 100644 --- a/object_fracture_voroni/fracture_cell_setup.py +++ b/object_fracture_voroni/fracture_cell_setup.py @@ -123,6 +123,7 @@ def cell_fracture_objects(scene, obj, use_smooth_edges=True, use_data_match=False, use_island_split=False, + use_debug_points=False, margin=0.0, ): @@ -157,19 +158,31 @@ def cell_fracture_objects(scene, obj, if source_noise > 0.0: + from random import random # boundbox approx of overall scale from mathutils import Vector matrix = obj.matrix_world.copy() bb_world = [matrix * Vector(v) for v in obj.bound_box] - scalar = (bb_world[0] - bb_world[6]).length / 2.0 + scalar = source_noise * ((bb_world[0] - bb_world[6]).length / 2.0) - from mathutils.noise import noise_vector + from mathutils.noise import random_unit_vector - points[:] = [p + (noise_vector(p) * scalar) for p in points] + points[:] = [p + (random_unit_vector() * (scalar * random())) for p in points] # end remove doubles # ------------------ + if use_debug_points: + bm = bmesh.new() + for p in points: + bm.verts.new(p) + mesh_tmp = bpy.data.meshes.new(name="DebugPoints") + bm.to_mesh(mesh_tmp) + bm.free() + obj_tmp = bpy.data.objects.new(name=mesh_tmp.name, object_data=mesh_tmp) + scene.objects.link(obj_tmp) + del obj_tmp, mesh_tmp + mesh = obj.data matrix = obj.matrix_world.copy() verts = [matrix * v.co for v in mesh.vertices] -- GitLab