diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-06-27 14:30:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-06-27 14:30:25 +0400 |
commit | d77e9af67c85afc247771bce2c020d50c785f43d (patch) | |
tree | 5611bc33031f9f60bd63eaf76b4c448af4bd1ac2 /object_fracture_voroni | |
parent | b297ad7f3f9fc617d7d75b84bd08deb3113cf8e5 (diff) |
remove example code and add a margin setting.
Diffstat (limited to 'object_fracture_voroni')
-rw-r--r-- | object_fracture_voroni/cell_fracture.py | 63 |
1 files changed, 4 insertions, 59 deletions
diff --git a/object_fracture_voroni/cell_fracture.py b/object_fracture_voroni/cell_fracture.py index f8fe64ca..3b5d6da8 100644 --- a/object_fracture_voroni/cell_fracture.py +++ b/object_fracture_voroni/cell_fracture.py @@ -21,7 +21,7 @@ # Script copyright (C) Blender Foundation 2012 -def points_as_bmesh_cells(verts, points): +def points_as_bmesh_cells(verts, points, margin=0.01): import mathutils from mathutils import Vector @@ -38,9 +38,9 @@ def points_as_bmesh_cells(verts, points): ya = [v[1] for v in verts] za = [v[2] for v in verts] - xmin, xmax = min(xa), max(xa) - ymin, ymax = min(ya), max(ya) - zmin, zmax = min(za), max(za) + xmin, xmax = min(xa) - margin, max(xa) + margin + ymin, ymax = min(ya) - margin, max(ya) + margin + zmin, zmax = min(za) - margin, max(za) + margin convexPlanes = [ Vector((+1.0, 0.0, 0.0, -abs(xmax))), Vector((-1.0, 0.0, 0.0, -abs(xmin))), @@ -91,58 +91,3 @@ def points_as_bmesh_cells(verts, points): vertices[:] = [] return cells - - -# --- run --- -# b ~/phys.blend -b --python cell_test.py - -def main(): - import bpy - import sys - #points = [v.co.copy() for v in bpy.data.objects["points"].data.vertices] - - sys.path.append("/media/data/blender-svn/blender-phymec/phymec_tools") - - import phymec_tools as pt - pt.voro_add_points(100) - #pt.physics_voronoi_shatter(pt.voro_points(particles=True),True) - #return - - points = [] - points.extend([p.location for p in bpy.data.objects["verts"].particle_systems[0].particles]) - - verts = [v.co.copy() for v in bpy.data.objects["verts"].data.vertices] - - cells = points_as_bmesh_cells(verts, points) - for cent, cell in cells: - me = bpy.data.meshes.new(name="Blah") - ob = bpy.data.objects.new(name="Blah", object_data=me) - bpy.context.scene.objects.link(ob) - bpy.context.scene.objects.active = ob - ob.location = cent - - # create the convex hulls - import bmesh - bm = bmesh.new() - for i, v in enumerate(cell): - bm_vert = bm.verts.new(v) - bm_vert.tag = True - - import mathutils - bm.transform(mathutils.Matrix.Translation((+100.0, +100.0, +100.0))) # BUG IN BLENDER - 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) - bm.free() - - print(len(cells)) - - -if __name__ == "__main__": - import time - t = time.time() - main() - - print("%.5f sec" % (time.time() - t)) |