From 526bfd81e21f68e96b890761c20525b72ac40793 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 17 Jul 2012 08:30:15 +0000 Subject: recursive option now works with interior verts and split edges --- object_fracture_cell/__init__.py | 36 +++++---- object_fracture_cell/fracture_cell_setup.py | 117 ++++++++++++++-------------- 2 files changed, 81 insertions(+), 72 deletions(-) (limited to 'object_fracture_cell') diff --git a/object_fracture_cell/__init__.py b/object_fracture_cell/__init__.py index f05e745c..15bc1886 100644 --- a/object_fracture_cell/__init__.py +++ b/object_fracture_cell/__init__.py @@ -60,8 +60,8 @@ def main_object(scene, obj, level, **kw): use_island_split = kw_copy.pop("use_island_split") use_debug_bool = kw_copy.pop("use_debug_bool") use_interior_vgroup = kw_copy.pop("use_interior_vgroup") - use_smooth_edges = kw_copy.pop("use_smooth_edges") - use_smooth_edges_apply = kw_copy.pop("use_smooth_edges_apply") + use_sharp_edges = kw_copy.pop("use_sharp_edges") + use_sharp_edges_apply = kw_copy.pop("use_sharp_edges_apply") if level != 0: kw_copy["source_limit"] = recursion_source_limit @@ -78,15 +78,12 @@ def main_object(scene, obj, level, **kw): objects = fracture_cell_setup.cell_fracture_objects(scene, obj, **kw_copy) objects = fracture_cell_setup.cell_fracture_boolean(scene, obj, objects, use_island_split=use_island_split, - use_interior_vgroup=use_interior_vgroup, + use_interior_hide=(use_interior_vgroup or use_sharp_edges), use_debug_bool=use_debug_bool, use_debug_redraw=kw_copy["use_debug_redraw"], - use_smooth_edges=use_smooth_edges, - use_smooth_edges_apply=use_smooth_edges_apply, + level=level, ) - # todo, split islands. - # must apply after boolean. if use_recenter: bpy.ops.object.origin_set({"selected_editable_objects": objects}, @@ -128,6 +125,17 @@ def main_object(scene, obj, level, **kw): del objects[i] objects.extend(objects_recursive) + #-------------- + # Level Options + if level == 0: + # import pdb; pdb.set_trace() + if use_interior_vgroup or use_sharp_edges: + fracture_cell_setup.cell_fracture_interior_handle(objects, + use_interior_vgroup=use_interior_vgroup, + use_sharp_edges=use_sharp_edges, + use_sharp_edges_apply=use_sharp_edges_apply, + ) + #-------------- # Scene Options @@ -182,7 +190,7 @@ def main(context, **kw): bpy.ops.object.select_all(action='DESELECT') for obj_cell in objects: obj_cell.select = True - + if mass_mode == 'UNIFORM': for obj_cell in objects: obj_cell.game.mass = mass @@ -311,16 +319,16 @@ class FractureCell(Operator): default=False, ) - use_smooth_edges = BoolProperty( - name="Smooth Edges", + use_sharp_edges = BoolProperty( + name="Sharp Edges", description="Set sharp edges when disabled", default=True, ) - use_smooth_edges_apply = BoolProperty( + use_sharp_edges_apply = BoolProperty( name="Apply Split Edge", description="Split sharp hard edges", - default=False, + default=True, ) use_data_match = BoolProperty( @@ -474,8 +482,8 @@ class FractureCell(Operator): col.label("Mesh Data") rowsub = col.row() rowsub.prop(self, "use_smooth_faces") - rowsub.prop(self, "use_smooth_edges") - rowsub.prop(self, "use_smooth_edges_apply") + rowsub.prop(self, "use_sharp_edges") + rowsub.prop(self, "use_sharp_edges_apply") rowsub.prop(self, "use_data_match") rowsub = col.row() diff --git a/object_fracture_cell/fracture_cell_setup.py b/object_fracture_cell/fracture_cell_setup.py index c5d60d8e..5a57fbb3 100644 --- a/object_fracture_cell/fracture_cell_setup.py +++ b/object_fracture_cell/fracture_cell_setup.py @@ -80,8 +80,8 @@ def _points_from_object(obj, source): def points_from_particles(obj): points.extend([p.location.copy() - for psys in obj.particle_systems - for p in psys.particles]) + for psys in obj.particle_systems + for p in psys.particles]) # geom own @@ -130,7 +130,6 @@ def cell_fracture_objects(scene, obj, clean=True, # operator options use_smooth_faces=False, - use_smooth_edges=True, use_data_match=False, use_debug_points=False, margin=0.0, @@ -253,8 +252,6 @@ def cell_fracture_objects(scene, obj, for bm_face in bm.faces: bm_face.smooth = True - # use_smooth_edges is handled after boolean - if material_index != 0: for bm_face in bm.faces: bm_face.material_index = material_index @@ -312,17 +309,15 @@ def cell_fracture_boolean(scene, obj, objects, use_debug_bool=False, clean=True, use_island_split=False, - use_interior_vgroup=False, + use_interior_hide=False, use_debug_redraw=False, - use_smooth_edges=True, - use_smooth_edges_apply=True, + level=0, ): objects_boolean = [] - do_hide_hack = use_interior_vgroup or (use_smooth_edges is False) - - if do_hide_hack: + if use_interior_hide and level == 0: + # only set for level 0 obj.data.polygons.foreach_set("hide", [False] * len(obj.data.polygons)) for obj_cell in objects: @@ -332,7 +327,7 @@ def cell_fracture_boolean(scene, obj, objects, if not use_debug_bool: - if do_hide_hack: + if use_interior_hide: obj_cell.data.polygons.foreach_set("hide", [True] * len(obj_cell.data.polygons)) mesh_new = obj_cell.to_mesh(scene, @@ -368,42 +363,10 @@ def cell_fracture_boolean(scene, obj, objects, import traceback traceback.print_exc() - if do_hide_hack and mesh_new: - # use_interior_vgroup or (use_smooth_edges == False) - if bm is None: - bm = bmesh.new() - bm.from_mesh(mesh_new) - - if use_interior_vgroup: - for bm_vert in bm.verts: - bm_vert.tag = True - for bm_face in bm.faces: - if not bm_face.hide: - for bm_vert in bm_face.verts: - bm_vert.tag = False - - # now add all vgroups - defvert_lay = bm.verts.layers.deform.verify() - for bm_vert in bm.verts: - if bm_vert.tag: - bm_vert[defvert_lay][0] = 1.0 - - if use_smooth_edges is False: - mesh_new.show_edge_sharp = True - for bm_edge in bm.edges: - if len({bm_face.hide for bm_face in bm_edge.link_faces}) == 2: - bm_edge.smooth = False - - for bm_face in bm.faces: - bm_face.hide = False - if bm is not None: bm.to_mesh(mesh_new) bm.free() - if use_interior_vgroup: - # add a vgroup - obj_cell.vertex_groups.new(name="Interior") del mesh_new del mesh_old @@ -436,20 +399,58 @@ def cell_fracture_boolean(scene, obj, objects, objects_boolean = objects_islands - # _must_ be done after split islands - if use_smooth_edges is False and use_smooth_edges_apply is True: - for obj_cell in objects_boolean: - mesh = obj_cell.data - bm = bmesh.new() - bm.from_mesh(mesh) - bm.normal_update() - bmesh.ops.split_edges(bm, - edges=[edge for edge in bm.edges - if not edge.smooth] - ) - bm.to_mesh(mesh) - bm.free() - scene.update() return objects_boolean + + +def cell_fracture_interior_handle(objects, + use_interior_vgroup=False, + use_sharp_edges=False, + use_sharp_edges_apply=False, + ): + """Run after doing _all_ booleans""" + + assert(use_interior_vgroup or use_sharp_edges or use_sharp_edges_apply) + + for obj_cell in objects: + mesh = obj_cell.data + bm = bmesh.new() + bm.from_mesh(mesh) + + if use_interior_vgroup: + for bm_vert in bm.verts: + bm_vert.tag = True + for bm_face in bm.faces: + if not bm_face.hide: + for bm_vert in bm_face.verts: + bm_vert.tag = False + + # now add all vgroups + defvert_lay = bm.verts.layers.deform.verify() + for bm_vert in bm.verts: + if bm_vert.tag: + bm_vert[defvert_lay][0] = 1.0 + + # add a vgroup + obj_cell.vertex_groups.new(name="Interior") + + if use_sharp_edges: + mesh.show_edge_sharp = True + for bm_edge in bm.edges: + if len({bm_face.hide for bm_face in bm_edge.link_faces}) == 2: + bm_edge.smooth = False + + + if use_sharp_edges_apply: + edges = [edge for edge in bm.edges if edge.smooth is False] + if edges: + bm.normal_update() + bmesh.ops.split_edges(bm, edges=edges) + + for bm_face in bm.faces: + bm_face.hide = False + + + bm.to_mesh(mesh) + bm.free() -- cgit v1.2.3