[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3547] trunk/py/scripts/addons/ object_fracture_voroni: cell fracture operator is now functional.
Campbell Barton
ideasman42 at gmail.com
Wed Jun 27 16:12:07 CEST 2012
Revision: 3547
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3547
Author: campbellbarton
Date: 2012-06-27 14:12:06 +0000 (Wed, 27 Jun 2012)
Log Message:
-----------
cell fracture operator is now functional.
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-27 12:39:17 UTC (rev 3546)
+++ trunk/py/scripts/addons/object_fracture_voroni/__init__.py 2012-06-27 14:12:06 UTC (rev 3547)
@@ -33,13 +33,31 @@
if "bpy" in locals():
import imp
- imp.reload(cell_fracture)
-else:
- from . import cell_fracture
+ imp.reload(fracture_cell_setup)
import bpy
+from bpy.types import Operator
+def main(context):
+ from . import fracture_cell_setup
+ obj = context.active_object
+ objects = fracture_cell_setup.cell_fracture_objects(context, obj)
+ objects = fracture_cell_setup.cell_fracture_boolean(context, obj, objects)
+ bpy.ops.object.select_all(action='DESELECT')
+ for obj_cell in objects:
+ obj_cell.select = True
+
+
+class FractureCell(Operator):
+ bl_idname = "object.add_fracture_cell_objects"
+ bl_label = "Cell Fracture Helper Objects"
+
+ def execute(self, context):
+ main(context)
+ return {'FINISHED'}
+
+'''
class INFO_MT_add_fracture_objects(bpy.types.Menu):
bl_idname = "INFO_MT_add_fracture_objects"
bl_label = "Fracture Helper Objects"
@@ -54,24 +72,24 @@
text="Projectile")
layout.operator("object.import_fracture_recorder",
text="Rigidbody Recorder")
+'''
+#def menu_func(self, context):
+# self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN")
-def menu_func(self, context):
- self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN")
-
def register():
- bpy.utils.register_module(__name__)
+ bpy.utils.register_class(FractureCell)
# Add the "add fracture objects" menu to the "Add" menu
- bpy.types.INFO_MT_add.append(menu_func)
+ # bpy.types.INFO_MT_add.append(menu_func)
def unregister():
- bpy.utils.unregister_module(__name__)
+ bpy.utils.unregister_class(FractureCell)
# Remove "add fracture objects" menu from the "Add" menu.
- bpy.types.INFO_MT_add.remove(menu_func)
+ # bpy.types.INFO_MT_add.remove(menu_func)
if __name__ == "__main__":
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-27 12:39:17 UTC (rev 3546)
+++ trunk/py/scripts/addons/object_fracture_voroni/fracture_cell_setup.py 2012-06-27 14:12:06 UTC (rev 3547)
@@ -20,8 +20,12 @@
# Script copyright (C) Blender Foundation 2012
-def cell_fracture_objects(context, obj, method={'OTHER'}):
+import bpy
+import bmesh
+
+def cell_fracture_objects(context, obj, method={'PARTICLES'}, clean=True):
+
#assert(method in {'OTHER', 'PARTICLES'})
from . import fracture_cell_calc
@@ -40,6 +44,8 @@
matrix = obj_other.matrix_world.copy()
points.extend([matrix * v.co for v in mesh.vertices])
+ if not points:
+ return []
mesh = obj.data
matrix = obj.matrix_world.copy()
@@ -48,8 +54,6 @@
cells = fracture_cell_calc.points_as_bmesh_cells(verts, points)
# some hacks here :S
- import bmesh
-
scene = context.scene
cell_name = obj.name + "_cell"
@@ -73,36 +77,62 @@
bmesh.ops.remove_doubles(bm, {'TAG'}, 0.0001)
bmesh.ops.convex_hull(bm, {'TAG'})
bm.transform(mathutils.Matrix.Translation((-100.0, -100.0, -100.0))) # BUG IN BLENDER
-
- bm.to_mesh(me)
+
+ if clean:
+ for bm_vert in bm.verts:
+ bm_vert.tag = True
+ for bm_edge in bm.edges:
+ bm_edge.tag = True
+ bm.normal_update()
+ bmesh.ops.dissolve_limit(bm, {'TAG'}, {'TAG'}, 0.001)
+
+ bm.to_mesh(mesh)
bm.free()
objects.append(obj_cell)
- return obj_cell
+ scene.update()
+ return objects
+def cell_fracture_boolean(context, obj, objects, apply=True, clean=True):
+ scene = context.scene
-def cell_fracture_boolean(context, obj, objects):
- scene = context.scene
+ objects_boolean = []
+
for obj_cell in objects:
- mod = obj_cell.modifiers.new(type='BOOLEAN')
- mod.object = boolobj
+ mod = obj_cell.modifiers.new(name="Boolean", type='BOOLEAN')
+ mod.object = obj
mod.operation = 'INTERSECT'
-
- mesh_new = obj_cell.to_mesh(scene, apply_modifiers=True)
- mesh_old = obj_cell.data
- obj_cell.data = mesh_new
- # remove if not valid
- if not mesh_old.users:
- bpy.data.meshes.remove(mesh_old)
- if not mesh_new.verts:
- scene.objects.unlink(obj_cell)
- if not obj_cell.users:
- bpy.data.objects.remove(obj_cell)
- if not mesh_new.users:
- bpy.data.meshes.remove(mesh_old)
- obj_cell.select = True
+ if apply:
+ mesh_new = obj_cell.to_mesh(scene, apply_modifiers=True, settings='PREVIEW')
+ mesh_old = obj_cell.data
+ obj_cell.data = mesh_new
+ obj_cell.modifiers.remove(mod)
+ # remove if not valid
+ if not mesh_old.users:
+ bpy.data.meshes.remove(mesh_old)
+ if not mesh_new.vertices:
+ scene.objects.unlink(obj_cell)
+ if not obj_cell.users:
+ bpy.data.objects.remove(obj_cell)
+ if not mesh_new.users:
+ bpy.data.meshes.remove(mesh_new)
+
+ if clean:
+ bm = bmesh.new()
+ bm.from_mesh(mesh_new)
+ for bm_vert in bm.verts:
+ bm_vert.tag = True
+ for bm_edge in bm.edges:
+ bm_edge.tag = True
+ bm.normal_update()
+ bmesh.ops.dissolve_limit(bm, {'TAG'}, {'TAG'}, 0.01)
+ bm.to_mesh(mesh_new)
+ bm.free()
+
+ objects_boolean.append(obj_cell)
+ return objects_boolean
More information about the Bf-extensions-cvs
mailing list