diff --git a/object_fracture_voroni/__init__.py b/object_fracture_voroni/__init__.py index 3b573ced0437488170532fbc6904c751a03ed071..c904777af69437d204047545a9dd91f5cc55b725 100644 --- a/object_fracture_voroni/__init__.py +++ b/object_fracture_voroni/__init__.py @@ -54,9 +54,7 @@ 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") - - print("AAAA", recursion_chance_select * 10) - + from . import fracture_cell_setup objects = fracture_cell_setup.cell_fracture_objects(scene, obj, **kw_copy) @@ -92,7 +90,7 @@ def main_object(scene, obj, level, **kw): 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': + if recursion_chance_select == 'CURSOR_MAX': objects_recurse_input.reverse() objects_recurse_input[int(recursion_chance * len(objects_recurse_input)):] = [] @@ -193,6 +191,13 @@ class FractureCell(Operator): default=True, ) + margin = FloatProperty( + name="Margin", + description="Gaps for the fracture (gives more stable physics)", + min=0.0, max=1.0, + default=0.001, + ) + # ------------------------------------------------------------------------- # Object Options @@ -230,8 +235,8 @@ class FractureCell(Operator): 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"), + ('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', ) @@ -247,7 +252,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=600) + return wm.invoke_props_dialog(self, width=1000) def draw(self, context): layout = self.layout @@ -268,6 +273,7 @@ class FractureCell(Operator): rowsub.prop(self, "use_smooth_faces") rowsub.prop(self, "use_smooth_edges") rowsub.prop(self, "use_data_match") + rowsub.prop(self, "margin") # rowsub.prop(self, "use_island_split") # TODO box = layout.box() diff --git a/object_fracture_voroni/fracture_cell_calc.py b/object_fracture_voroni/fracture_cell_calc.py index e25a0ee3951c2c3b823005ec93770f99a00cb89c..b7416dd88cb000a5834984a56a8e2a15ad1eec07 100644 --- a/object_fracture_voroni/fracture_cell_calc.py +++ b/object_fracture_voroni/fracture_cell_calc.py @@ -21,7 +21,9 @@ # Script copyright (C) Blender Foundation 2012 -def points_as_bmesh_cells(verts, points, margin=0.01): +def points_as_bmesh_cells(verts, points, + margin_bounds=0.01, + margin_cell=0.0): import mathutils from mathutils import Vector @@ -38,9 +40,9 @@ def points_as_bmesh_cells(verts, points, margin=0.01): ya = [v[1] for v in verts] za = [v[2] for v in verts] - xmin, xmax = min(xa) - margin, max(xa) + margin - ymin, ymax = min(ya) - margin, max(ya) + margin - zmin, zmax = min(za) - margin, max(za) + margin + xmin, xmax = min(xa) - margin_bounds, max(xa) + margin_bounds + ymin, ymax = min(ya) - margin_bounds, max(ya) + margin_bounds + zmin, zmax = min(za) - margin_bounds, max(za) + margin_bounds convexPlanes = [ Vector((+1.0, 0.0, 0.0, -abs(xmax))), Vector((-1.0, 0.0, 0.0, -abs(xmin))), @@ -67,7 +69,7 @@ def points_as_bmesh_cells(verts, points, margin=0.01): plane = normal.normalized() plane.resize_4d() - plane[3] = -nlength / 2.0 + plane[3] = (-nlength / 2.0) + margin_cell planes.append(plane) vertices[:], plane_indices[:] = mathutils.geometry.points_in_planes(planes) diff --git a/object_fracture_voroni/fracture_cell_setup.py b/object_fracture_voroni/fracture_cell_setup.py index 8bbf7db57613204351a9228695c06226c7c0ab4d..cc440a530648811768643cd2b571a8faa470b0c2 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, + margin=0.0, ): from . import fracture_cell_calc @@ -173,7 +174,8 @@ def cell_fracture_objects(scene, obj, matrix = obj.matrix_world.copy() verts = [matrix * v.co for v in mesh.vertices] - cells = fracture_cell_calc.points_as_bmesh_cells(verts, points) + cells = fracture_cell_calc.points_as_bmesh_cells(verts, points, + margin_cell=margin) # some hacks here :S cell_name = obj.name + "_cell" @@ -259,7 +261,7 @@ def cell_fracture_objects(scene, obj, game = obj_cell.game game.physics_type = 'RIGID_BODY' game.use_collision_bounds = True - game.collision_bounds_type = 'TRIANGLE_MESH' + game.collision_bounds_type = 'CONVEX_HULL' return objects