Skip to content

Commit

Permalink
Merge pull request #388 from Weisl/#342-convert-SELECTION-to-collider
Browse files Browse the repository at this point in the history
#342 Add SELECTION INDIVIDUAL to "Convert to Collider"
  • Loading branch information
Weisl authored Jun 4, 2023
2 parents b3f9a80 + da31015 commit ae60393
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions collider_conversion/conversion_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self):
self.use_shape_change = True
self.use_decimation = True
self.is_mesh_to_collider = True
self.use_creation_mode = False
# self.use_creation_mode = False
self.shape = 'mesh_shape'
self.use_keep_original_materials = True

Expand Down Expand Up @@ -120,6 +120,8 @@ def execute(self, context):
super().execute(context)

self.original_obj_data = []
collider_data = []
user_collections = []

# Create the bounding geometry, depending on edit or object mode.
for obj in self.selected_objects:
Expand All @@ -130,16 +132,15 @@ def execute(self, context):

new_collider = obj.copy()
new_collider.data = obj.data.copy()
bpy.context.collection.objects.link(new_collider)

user_collections = obj.users_collection

self.new_colliders_list.append(new_collider)
self.original_obj_data.append(self.store_initial_obj_state(obj, user_collections))

for collection in obj.users_collection:
collection.objects.unlink(obj)

self.primitive_postprocessing(context, new_collider, user_collections)

prefs = context.preferences.addons[__package__.split('.')[0]].preferences

if prefs.replace_name:
Expand All @@ -149,8 +150,36 @@ def execute(self, context):
else:
basename = obj.name

mesh_collider_data = {}
mesh_collider_data['basename'] = basename
mesh_collider_data['new_collider'] = new_collider
collider_data.append(mesh_collider_data)

if self.creation_mode[self.creation_mode_idx] == 'INDIVIDUAL':
for mesh_collider_data in collider_data:
basename = mesh_collider_data['basename']
new_collider = mesh_collider_data['new_collider']

self.primitive_postprocessing(context, new_collider, user_collections)
self.new_colliders_list.append(new_collider)
super().set_collider_name(new_collider, basename)

else: # self.creation_mode[self.creation_mode_idx] == 'SELECTION':
bpy.ops.object.select_all(action='DESELECT')
last_selected = None
for mesh_collider_data in collider_data:
basename = mesh_collider_data['basename']
new_collider = mesh_collider_data['new_collider']
new_collider.select_set(True)

context.view_layer.objects.active = new_collider
bpy.ops.object.join()

self.primitive_postprocessing(context, new_collider, user_collections)
self.new_colliders_list.append(new_collider)
super().set_collider_name(new_collider, basename)


elapsed_time = self.get_time_elapsed()
super().print_generation_time("Convert to Collider", elapsed_time)
self.report({'INFO'}, f"Convert to Collider: {float(elapsed_time)}")
Expand Down

0 comments on commit ae60393

Please sign in to comment.