diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-10-22 06:48:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-10-22 06:48:22 +0300 |
commit | be8893ce16a6841fe723bd4b504ec5f039719d25 (patch) | |
tree | fa53e31a18bfcafcf1e6c0bfa6488cf38fb53f86 | |
parent | 0941b635cc762eeca9383dbb3c10ea580c5aa547 (diff) |
Fix T81940: Cell Fracture fails with recursion & target collection
-rw-r--r-- | object_fracture_cell/__init__.py | 37 | ||||
-rw-r--r-- | object_fracture_cell/fracture_cell_setup.py | 6 |
2 files changed, 17 insertions, 26 deletions
diff --git a/object_fracture_cell/__init__.py b/object_fracture_cell/__init__.py index cb8cc561..ea4f0d2b 100644 --- a/object_fracture_cell/__init__.py +++ b/object_fracture_cell/__init__.py @@ -45,7 +45,7 @@ from bpy.props import ( from bpy.types import Operator -def main_object(context, obj, level, **kw): +def main_object(context, collection, obj, level, **kw): import random # pull out some args @@ -57,7 +57,6 @@ def main_object(context, obj, level, **kw): recursion_clamp = kw_copy.pop("recursion_clamp") recursion_chance = kw_copy.pop("recursion_chance") recursion_chance_select = kw_copy.pop("recursion_chance_select") - collection_name = kw_copy.pop("collection_name") 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") @@ -65,7 +64,6 @@ def main_object(context, obj, level, **kw): use_sharp_edges_apply = kw_copy.pop("use_sharp_edges_apply") scene = context.scene - collection = context.collection if level != 0: kw_copy["source_limit"] = recursion_source_limit @@ -79,9 +77,9 @@ def main_object(context, obj, level, **kw): obj_display_type_prev = obj.display_type obj.display_type = 'WIRE' - objects = fracture_cell_setup.cell_fracture_objects(context, obj, **kw_copy) + objects = fracture_cell_setup.cell_fracture_objects(context, collection, obj, **kw_copy) objects = fracture_cell_setup.cell_fracture_boolean( - context, obj, objects, + context, collection, obj, objects, use_island_split=use_island_split, use_interior_hide=(use_interior_vgroup or use_sharp_edges), use_debug_bool=use_debug_bool, @@ -131,7 +129,7 @@ def main_object(context, obj, level, **kw): objects_recursive = [] for i, obj_cell in objects_recurse_input: assert(objects[i] is obj_cell) - objects_recursive += main_object(context, obj_cell, level_sub, **kw) + objects_recursive += main_object(context, collection, obj_cell, level_sub, **kw) if use_remove_original: collection.objects.unlink(obj_cell) del objects[i] @@ -154,21 +152,6 @@ def main_object(context, obj, level, **kw): use_sharp_edges_apply=use_sharp_edges_apply, ) - #-------------- - # Scene Options - - # group - if collection_name: - group = bpy.data.collections.get(collection_name) - if group is None: - group = bpy.data.collections.new(collection_name) - collection.children.link(group) - group_objects = group.objects[:] - for obj_cell in objects: - if obj_cell not in group_objects: - collection.objects.unlink(obj_cell) - group.objects.link(obj_cell) - if kw_copy["use_debug_redraw"]: obj.display_type = obj_display_type_prev @@ -187,11 +170,21 @@ def main(context, **kw): # mass mass_mode = kw_copy.pop("mass_mode") mass = kw_copy.pop("mass") + collection_name = kw_copy.pop("collection_name") + + collection = context.collection + if collection_name: + collection_current = collection + collection = bpy.data.collections.get(collection_name) + if collection is None: + collection = bpy.data.collections.new(collection_name) + collection_current.children.link(collection) + del collection_current objects = [] for obj in objects_context: if obj.type == 'MESH': - objects += main_object(context, obj, 0, **kw_copy) + objects += main_object(context, collection, obj, 0, **kw_copy) bpy.ops.object.select_all(action='DESELECT') for obj_cell in objects: diff --git a/object_fracture_cell/fracture_cell_setup.py b/object_fracture_cell/fracture_cell_setup.py index cb72aa1f..f083af2f 100644 --- a/object_fracture_cell/fracture_cell_setup.py +++ b/object_fracture_cell/fracture_cell_setup.py @@ -122,7 +122,7 @@ def _points_from_object(depsgraph, scene, obj, source): return points -def cell_fracture_objects(context, obj, +def cell_fracture_objects(context, collection, obj, source={'PARTICLE_OWN'}, source_limit=0, source_noise=0.0, @@ -140,7 +140,6 @@ def cell_fracture_objects(context, obj, from . import fracture_cell_calc depsgraph = context.evaluated_depsgraph_get() scene = context.scene - collection = context.collection view_layer = context.view_layer # ------------------------------------------------------------------------- @@ -307,7 +306,7 @@ def cell_fracture_objects(context, obj, return objects -def cell_fracture_boolean(context, obj, objects, +def cell_fracture_boolean(context, collection, obj, objects, use_debug_bool=False, clean=True, use_island_split=False, @@ -318,7 +317,6 @@ def cell_fracture_boolean(context, obj, objects, ): objects_boolean = [] - collection = context.collection scene = context.scene view_layer = context.view_layer |