diff --git a/object_fracture_cell/__init__.py b/object_fracture_cell/__init__.py index 0fcf794097ce04f1e9ffa15d8b8edb54be5729a7..01216409f8f58238c657a6af93c165240b934806 100644 --- a/object_fracture_cell/__init__.py +++ b/object_fracture_cell/__init__.py @@ -40,6 +40,7 @@ from bpy.props import (StringProperty, BoolProperty, IntProperty, FloatProperty, + FloatVectorProperty, EnumProperty) from bpy.types import Operator @@ -192,6 +193,14 @@ class FractureCell(Operator): default=0.0, ) + cell_scale = FloatVectorProperty( + name="Scale", + description="Scale Cell Shape", + size=3, + min=0.0, max=1.0, + default=(1.0, 1.0, 1.0), + ) + # ------------------------------------------------------------------------- # Recursion @@ -330,6 +339,7 @@ class FractureCell(Operator): rowsub.prop(self, "source_limit") rowsub.prop(self, "source_noise") rowsub = col.row() + rowsub.prop(self, "cell_scale") box = layout.box() col = box.column() diff --git a/object_fracture_cell/fracture_cell_calc.py b/object_fracture_cell/fracture_cell_calc.py index d75f6994ca11629a22a51fca9bdc7e83a868db3e..884fec1109fc1b6e281d386ae07efa774302ab37 100644 --- a/object_fracture_cell/fracture_cell_calc.py +++ b/object_fracture_cell/fracture_cell_calc.py @@ -21,7 +21,9 @@ # Script copyright (C) Blender Foundation 2012 -def points_as_bmesh_cells(verts, points, +def points_as_bmesh_cells(verts, + points, + points_scale=None, margin_bounds=0.05, margin_cell=0.0): from math import sqrt @@ -29,6 +31,14 @@ def points_as_bmesh_cells(verts, points, from mathutils import Vector cells = [] + + ''' + if points_scale: + points_scale = (1.0 / points_scale[0], + 1.0 / points_scale[1], + 1.0 / points_scale[2], + ) + ''' points_sorted_current = [p for p in points] plane_indices = [] @@ -65,6 +75,20 @@ def points_as_bmesh_cells(verts, points, for j in range(1, len(points)): normal = points_sorted_current[j] - point_cell_current nlength = normal.length + + if points_scale is not None: + normal_alt = normal.copy() + normal_alt.x *= points_scale[0] + normal_alt.y *= points_scale[1] + normal_alt.z *= points_scale[2] + + # rotate plane to new distance + # should always be positive!! - but abs incase + scalar = normal_alt.normalized().dot(normal.normalized()) + # assert(scalar >= 0.0) + nlength *= scalar + normal = normal_alt + if nlength > distance_max: break diff --git a/object_fracture_cell/fracture_cell_setup.py b/object_fracture_cell/fracture_cell_setup.py index a33658284a22c802d3d3975c8c0269beafdc322a..19a5086a2a56488fb69ce503fad9f2b749f69871 100644 --- a/object_fracture_cell/fracture_cell_setup.py +++ b/object_fracture_cell/fracture_cell_setup.py @@ -125,6 +125,7 @@ def cell_fracture_objects(scene, obj, margin=0.0, material_index=0, use_debug_redraw=False, + cell_scale=(1.0, 1.0, 1.0), ): from . import fracture_cell_calc @@ -136,7 +137,7 @@ def cell_fracture_objects(scene, obj, if not points: # print using fallback - points = _points_from_object(obj, source | {'VERT_OWN'}) + points = _points_from_object(obj, {'VERT_OWN'}) if not points: print("no points found") @@ -187,7 +188,9 @@ 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, + cell_scale, margin_cell=margin) # some hacks here :S