Skip to content

Commit

Permalink
non uniform cell shape, currently only xyz scale.
Browse files Browse the repository at this point in the history
  • Loading branch information
ideasman42 committed Jul 5, 2012
1 parent 1b0bdd0 commit 8c02109
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
10 changes: 10 additions & 0 deletions object_fracture_cell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty)

from bpy.types import Operator
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -330,6 +339,7 @@ def draw(self, context):
rowsub.prop(self, "source_limit")
rowsub.prop(self, "source_noise")
rowsub = col.row()
rowsub.prop(self, "cell_scale")

box = layout.box()
col = box.column()
Expand Down
26 changes: 25 additions & 1 deletion object_fracture_cell/fracture_cell_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@
# 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
import mathutils
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 = []
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions object_fracture_cell/fracture_cell_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8c02109

Please sign in to comment.