[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3565] trunk/py/scripts/addons/ object_fracture_voroni: fracture updates

Campbell Barton ideasman42 at gmail.com
Tue Jul 3 14:16:20 CEST 2012


Revision: 3565
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3565
Author:   campbellbarton
Date:     2012-07-03 12:16:10 +0000 (Tue, 03 Jul 2012)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/py/scripts/addons/object_fracture_voroni/__init__.py
    trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py

Modified: trunk/py/scripts/addons/object_fracture_voroni/__init__.py
===================================================================
--- trunk/py/scripts/addons/object_fracture_voroni/__init__.py	2012-07-03 09:01:43 UTC (rev 3564)
+++ trunk/py/scripts/addons/object_fracture_voroni/__init__.py	2012-07-03 12:16:10 UTC (rev 3565)
@@ -54,6 +54,9 @@
     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 @@
                 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
 
 
@@ -166,6 +185,34 @@
             )
 
     # -------------------------------------------------------------------------
+    # 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
 
     use_smooth_faces = BoolProperty(
@@ -214,31 +261,29 @@
             )
 
     # -------------------------------------------------------------------------
-    # Recursion
+    # Scene Options
+    #
+    # .. dirreferent from object options in that this controls how the objects
+    #    are setup in the scene.  
 
-    recursion = IntProperty(
-            name="Recursion",
-            description="Break shards resursively",
-            min=0, max=5000,
-            default=0,
+    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 @@
     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
@@ -268,6 +313,15 @@
 
         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")
         rowsub = col.row(align=True)
         rowsub.prop(self, "use_smooth_faces")
@@ -282,14 +336,19 @@
         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")

Modified: trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py
===================================================================
--- trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py	2012-07-03 09:01:43 UTC (rev 3564)
+++ trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py	2012-07-03 12:16:10 UTC (rev 3565)
@@ -123,6 +123,7 @@
                           use_smooth_edges=True,
                           use_data_match=False,
                           use_island_split=False,
+                          use_debug_points=False,
                           margin=0.0,
                           ):
     
@@ -157,19 +158,31 @@
 
 
     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]



More information about the Bf-extensions-cvs mailing list