[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3552] trunk/py/scripts/addons/ object_fracture_voroni: add option to favor which parts to re-fracture
Campbell Barton
ideasman42 at gmail.com
Fri Jun 29 14:43:48 CEST 2012
Revision: 3552
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3552
Author: campbellbarton
Date: 2012-06-29 12:43:47 +0000 (Fri, 29 Jun 2012)
Log Message:
-----------
add option to favor which parts to re-fracture
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-06-29 09:58:32 UTC (rev 3551)
+++ trunk/py/scripts/addons/object_fracture_voroni/__init__.py 2012-06-29 12:43:47 UTC (rev 3552)
@@ -53,7 +53,10 @@
use_remove_original = kw_copy.pop("use_remove_original")
recursion = kw_copy.pop("recursion")
recursion_chance = kw_copy.pop("recursion_chance")
+ recursion_chance_select = kw_copy.pop("recursion_chance_select")
+ print("AAAA", recursion_chance_select * 10)
+
from . import fracture_cell_setup
objects = fracture_cell_setup.cell_fracture_objects(scene, obj, **kw_copy)
@@ -67,15 +70,44 @@
type='ORIGIN_GEOMETRY', center='MEDIAN')
if level < recursion:
+
+ objects_recurse_input = [(i, o) for i, o in enumerate(objects)]
+
+ if recursion_chance != 1.0:
+
+ if 0:
+ random.shuffle(objects_recurse_input)
+ else:
+ from mathutils import Vector
+ if recursion_chance_select == 'RANDOM':
+ pass
+ elif recursion_chance_select == {'SIZE_MIN', 'SIZE_MAX'}:
+ objects_recurse_input.sort(key=lambda ob_pair:
+ (Vector(ob_pair[1].bound_box[0]) -
+ Vector(ob_pair[1].bound_box[6])).length_squared)
+ if recursion_chance_select == 'SIZE_MAX':
+ objects_recurse_input.reverse()
+ elif recursion_chance_select == {'CURSOR_MIN', 'CURSOR_MAX'}:
+ print(recursion_chance_select)
+ c = scene.cursor_location.copy()
+ objects_recurse_input.sort(key=lambda ob_pair:
+ (ob_pair[1].matrix_world.translation - c).length_squared)
+ if recursion_chance_select == 'SIZE_MAX':
+ objects_recurse_input.reverse()
+
+ objects_recurse_input[int(recursion_chance * len(objects_recurse_input)):] = []
+ objects_recurse_input.sort()
+
+ # reverse index values so we can remove from original list.
+ objects_recurse_input.reverse()
+
objects_recursive = []
- for i in range(len(objects) - 1, -1, -1): # reverse loop
-
- if recursion_chance == 1.0 or recursion_chance < random.random():
- obj_cell = objects[i]
- objects_recursive += main_object(scene, obj_cell, level + 1, **kw)
- if use_remove_original:
- scene.objects.unlink(obj_cell)
- del objects[i]
+ for i, obj_cell in objects_recurse_input:
+ assert(objects[i] is obj_cell)
+ objects_recursive += main_object(scene, obj_cell, level + 1, **kw)
+ if use_remove_original:
+ scene.objects.unlink(obj_cell)
+ del objects[i]
objects.extend(objects_recursive)
@@ -193,6 +225,17 @@
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 Min", "Recursively subdivide objects closer to the cursor"),
+ ('CURSOR_MAX', "Cursor Max", "Recursively subdivide objects closer to the cursor"),
+ ),
+ default='SIZE_MIN',
+ )
+
def execute(self, context):
keywords = self.as_keywords() # ignore=("blah",)
@@ -202,6 +245,7 @@
def invoke(self, context, event):
+ print(self.recursion_chance_select)
wm = context.window_manager
return wm.invoke_props_dialog(self, width=600)
@@ -237,7 +281,9 @@
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)
#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-06-29 09:58:32 UTC (rev 3551)
+++ trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py 2012-06-29 12:43:47 UTC (rev 3552)
@@ -234,7 +234,7 @@
# currently only materials + data layers, could do others...
mesh_src = obj.data
for mat in mesh_src.materials:
- mesh.materials.append(mat)
+ mesh_dst.materials.append(mat)
for lay_attr in ("vertex_colors", "uv_layers"):
lay_src = getattr(mesh_src, lay_attr)
lay_dst = getattr(mesh_dst, lay_attr)
More information about the Bf-extensions-cvs
mailing list