Skip to content
Snippets Groups Projects
Commit 8a56a608 authored by Campbell Barton's avatar Campbell Barton
Browse files

fracture updates

- added options to fracture into a new group and to use the next layer then the active object.
- noise option wasnt working right, was always adding a lot of noise.
parent 2dc06f6d
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,9 @@ def main_object(scene, obj, level, **kw): ...@@ -54,6 +54,9 @@ def main_object(scene, obj, level, **kw):
recursion = kw_copy.pop("recursion") recursion = kw_copy.pop("recursion")
recursion_chance = kw_copy.pop("recursion_chance") recursion_chance = kw_copy.pop("recursion_chance")
recursion_chance_select = kw_copy.pop("recursion_chance_select") recursion_chance_select = kw_copy.pop("recursion_chance_select")
use_layer_next = kw_copy.pop("use_layer_next")
group_name = kw_copy.pop("group_name")
from . import fracture_cell_setup from . import fracture_cell_setup
...@@ -107,10 +110,26 @@ def main_object(scene, obj, level, **kw): ...@@ -107,10 +110,26 @@ def main_object(scene, obj, level, **kw):
scene.objects.unlink(obj_cell) scene.objects.unlink(obj_cell)
del objects[i] del objects[i]
objects.extend(objects_recursive) objects.extend(objects_recursive)
#--------------
# Scene Options
# layer
if use_layer_next:
layers_new = [False] * 20
layers_new[(obj.layers[:].index(True) + 1) % 20] = True
for obj_cell in objects:
obj_cell.layers = layers_new
# group
if group_name:
group = bpy.data.groups.get(group_name)
if group is None:
group = bpy.data.groups.new(group_name)
for obj_cell in objects:
group.objects.link(obj_cell)
# testing only! # testing only!
obj.hide = True # obj.hide = True
return objects return objects
...@@ -165,6 +184,34 @@ class FractureCell(Operator): ...@@ -165,6 +184,34 @@ class FractureCell(Operator):
default=0.0, default=0.0,
) )
# -------------------------------------------------------------------------
# Recursion
recursion = IntProperty(
name="Recursion",
description="Break shards resursively",
min=0, max=5000,
default=0,
)
recursion_chance = FloatProperty(
name="Random Factor",
description="Likelyhood of recursion",
min=0.0, max=1.0,
default=1.0,
)
recursion_chance_select = EnumProperty(
name="Recurse Over",
items=(('RANDOM', "Random", ""),
('SIZE_MIN', "Small", "Recursively subdivide smaller objects"),
('SIZE_MAX', "Big", "Recursively subdivide smaller objects"),
('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',
)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Mesh Data Options # Mesh Data Options
...@@ -214,31 +261,29 @@ class FractureCell(Operator): ...@@ -214,31 +261,29 @@ class FractureCell(Operator):
) )
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Recursion # Scene Options
#
recursion = IntProperty( # .. dirreferent from object options in that this controls how the objects
name="Recursion", # are setup in the scene.
description="Break shards resursively",
min=0, max=5000, use_layer_next = BoolProperty(
default=0, name="Next Layer",
description="At the object into the next layer",
default=True,
) )
recursion_chance = FloatProperty( group_name = StringProperty(
name="Random Factor", name="Group",
description="Likelyhood of recursion", description="Create objects int a group "
min=0.0, max=1.0, "(use existing or create new)",
default=1.0,
) )
recursion_chance_select = EnumProperty( # -------------------------------------------------------------------------
name="Recurse Over", # Debug
items=(('RANDOM', "Random", ""), use_debug_points = BoolProperty(
('SIZE_MIN', "Small", "Recursively subdivide smaller objects"), name="Debug Points",
('SIZE_MAX', "Big", "Recursively subdivide smaller objects"), description="Create mesh data showing the points used for fracture",
('CURSOR_MIN', "Cursor Close", "Recursively subdivide objects closer to the cursor"), default=False,
('CURSOR_MAX', "Cursor Far", "Recursively subdivide objects closer to the cursor"),
),
default='SIZE_MIN',
) )
def execute(self, context): def execute(self, context):
...@@ -252,7 +297,7 @@ class FractureCell(Operator): ...@@ -252,7 +297,7 @@ class FractureCell(Operator):
def invoke(self, context, event): def invoke(self, context, event):
print(self.recursion_chance_select) print(self.recursion_chance_select)
wm = context.window_manager wm = context.window_manager
return wm.invoke_props_dialog(self, width=1000) return wm.invoke_props_dialog(self, width=600)
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
...@@ -266,6 +311,15 @@ class FractureCell(Operator): ...@@ -266,6 +311,15 @@ class FractureCell(Operator):
rowsub.prop(self, "source_noise") rowsub.prop(self, "source_noise")
rowsub = col.row() rowsub = col.row()
box = layout.box()
col = box.column()
col.label("Recursive Shatter")
rowsub = col.row(align=True)
rowsub.prop(self, "recursion")
rowsub = col.row()
rowsub.prop(self, "recursion_chance")
rowsub.prop(self, "recursion_chance_select", expand=True)
box = layout.box() box = layout.box()
col = box.column() col = box.column()
col.label("Mesh Data") col.label("Mesh Data")
...@@ -282,14 +336,19 @@ class FractureCell(Operator): ...@@ -282,14 +336,19 @@ class FractureCell(Operator):
rowsub = col.row(align=True) rowsub = col.row(align=True)
rowsub.prop(self, "use_recenter") rowsub.prop(self, "use_recenter")
box = layout.box() box = layout.box()
col = box.column() col = box.column()
col.label("Recursive Shatter") col.label("Scene")
rowsub = col.row(align=True) rowsub = col.row(align=True)
rowsub.prop(self, "recursion") rowsub.prop(self, "use_layer_next")
rowsub = col.row() rowsub.prop(self, "group_name")
rowsub.prop(self, "recursion_chance")
rowsub.prop(self, "recursion_chance_select", expand=True) box = layout.box()
col = box.column()
col.label("Debug")
rowsub = col.row(align=True)
rowsub.prop(self, "use_debug_points")
#def menu_func(self, context): #def menu_func(self, context):
# self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN") # self.layout.menu("INFO_MT_add_fracture_objects", icon="PLUGIN")
......
...@@ -123,6 +123,7 @@ def cell_fracture_objects(scene, obj, ...@@ -123,6 +123,7 @@ def cell_fracture_objects(scene, obj,
use_smooth_edges=True, use_smooth_edges=True,
use_data_match=False, use_data_match=False,
use_island_split=False, use_island_split=False,
use_debug_points=False,
margin=0.0, margin=0.0,
): ):
...@@ -157,19 +158,31 @@ def cell_fracture_objects(scene, obj, ...@@ -157,19 +158,31 @@ def cell_fracture_objects(scene, obj,
if source_noise > 0.0: if source_noise > 0.0:
from random import random
# boundbox approx of overall scale # boundbox approx of overall scale
from mathutils import Vector from mathutils import Vector
matrix = obj.matrix_world.copy() matrix = obj.matrix_world.copy()
bb_world = [matrix * Vector(v) for v in obj.bound_box] bb_world = [matrix * Vector(v) for v in obj.bound_box]
scalar = (bb_world[0] - bb_world[6]).length / 2.0 scalar = source_noise * ((bb_world[0] - bb_world[6]).length / 2.0)
from mathutils.noise import noise_vector from mathutils.noise import random_unit_vector
points[:] = [p + (noise_vector(p) * scalar) for p in points] points[:] = [p + (random_unit_vector() * (scalar * random())) for p in points]
# end remove doubles # end remove doubles
# ------------------ # ------------------
if use_debug_points:
bm = bmesh.new()
for p in points:
bm.verts.new(p)
mesh_tmp = bpy.data.meshes.new(name="DebugPoints")
bm.to_mesh(mesh_tmp)
bm.free()
obj_tmp = bpy.data.objects.new(name=mesh_tmp.name, object_data=mesh_tmp)
scene.objects.link(obj_tmp)
del obj_tmp, mesh_tmp
mesh = obj.data mesh = obj.data
matrix = obj.matrix_world.copy() matrix = obj.matrix_world.copy()
verts = [matrix * v.co for v in mesh.vertices] verts = [matrix * v.co for v in mesh.vertices]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment