diff --git a/operators/__init__.py b/operators/__init__.py index db4eef0..0fd6b9b 100644 --- a/operators/__init__.py +++ b/operators/__init__.py @@ -63,6 +63,11 @@ def register(): ('ALWAYS', "Always","The wireframes remain visible afterwards.")), description="Hide Bounding Object After Creation.", default='PREVIEW') + scene.creation_mode = bpy.props.EnumProperty(name="Creation Mode", + items=(('INDIVIDUAL', "Individual",""), + ('SELECTION', "Selection","")), + description="", default='INDIVIDUAL') + obj.basename = bpy.props.StringProperty(default='geo', name='Basename', description='Default naming used for collisions when the name is not inherited from a parent (Name from parent is disabled).') obj.collider_type = bpy.props.EnumProperty(name="Shading", items=[('BOX', "Box", "Used to descibe boxed shape collision shapes."),('SHERE', "Sphere", "Used to descibe spherical collision shapes."),('CONVEX', "CONVEX", "Used to descibe convex shaped collision shapes."),('MESH', "Triangle Mesh", "Used to descibe complex triangle mesh collisions.")], default='BOX') diff --git a/operators/add_bounding_box.py b/operators/add_bounding_box.py index b12a80d..d5791af 100644 --- a/operators/add_bounding_box.py +++ b/operators/add_bounding_box.py @@ -118,10 +118,13 @@ def execute(self, context): #List for storing dictionaries of data used to generate the collision meshes collider_data = [] + vert_positions_x = [] + vert_positions_y = [] + vert_positions_z = [] + # Create the bounding geometry, depending on edit or object mode. for obj in self.selected_objects: - # skip if invalid object if obj is None: continue @@ -143,16 +146,32 @@ def execute(self, context): continue positionsX, positionsY, positionsZ = self.get_point_positions(obj, scene.my_space, used_vertices) - verts_loc = self.generate_bounding_box(positionsX, positionsY, positionsZ) + vert_positions_x = vert_positions_x + positionsX + vert_positions_y = vert_positions_y + positionsY + vert_positions_z = vert_positions_z + positionsZ + + if scene.creation_mode == 'INDIVIDUAL': + verts_loc = self.generate_bounding_box(positionsX, positionsY, positionsZ) + + #store data needed to generate a bounding box in a dictionary + bounding_box_data['parent'] = obj + bounding_box_data['verts_loc'] = verts_loc - #store data needed to generate a bounding box in a dictionary + collider_data.append(bounding_box_data) + + if scene.creation_mode == 'SELECTION': + print(str(vert_positions_x)) + verts_loc = self.generate_bounding_box(vert_positions_x,vert_positions_y,vert_positions_z) + + bounding_box_data = {} bounding_box_data['parent'] = obj bounding_box_data['verts_loc'] = verts_loc - collider_data.append(bounding_box_data) + bpy.ops.object.mode_set(mode='OBJECT') + for bounding_box_data in collider_data: # get data from dictionary parent = bounding_box_data['parent'] @@ -160,7 +179,6 @@ def execute(self, context): global face_order new_collider = verts_faces_to_bbox_collider(self, context, verts_loc, face_order) - scene = context.scene if scene.my_space == 'LOCAL': @@ -180,6 +198,8 @@ def execute(self, context): parent_name = parent.name new_collider.name = super().collider_name(basename=parent_name) + + # Initial state has to be restored for the modal operator to work. If not, the result will break once changing the parameters super().reset_to_initial_state(context) super().print_generation_time("Box Collider") diff --git a/operators/add_bounding_primitive.py b/operators/add_bounding_primitive.py index 393ea44..2198deb 100644 --- a/operators/add_bounding_primitive.py +++ b/operators/add_bounding_primitive.py @@ -100,6 +100,10 @@ def draw_viewport_overlay(self, context): value = str(scene.wireframe_mode) i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value = value, key='(W)', type='enum') + label = "Creation Mode " + value = str(scene.creation_mode) + i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value = value, key='(M)', type='bool') + label = "Hide After Creation " value = str(scene.my_hide) i = draw_modal_item(self, font_id, i, vertical_px_offset, left_margin, label, value = value, key='(H)', type='bool') @@ -663,6 +667,7 @@ def invoke(self, context, event): self.shading_idx = 0 self.shading_modes = ['OBJECT','MATERIAL','SINGLE'] self.wireframe_idx = 1 + self.creation_mode_idx = 0 # self.wireframe_mode = ['OFF', 'PREVIEW', 'ALWAYS'] self.collision_type_idx = 0 self.collision_type = collider_types @@ -819,6 +824,11 @@ def modal(self, context, event): scene.wireframe_mode = bpy.types.Scene.bl_rna.properties['wireframe_mode'].enum_items[self.wireframe_idx].identifier self.set_collisions_wire_preview(scene.wireframe_mode) + elif event.type == 'M' and event.value == 'RELEASE': + self.creation_mode_idx = (self.creation_mode_idx + 1) % len(bpy.types.Scene.bl_rna.properties['creation_mode'].enum_items) + scene.creation_mode = bpy.types.Scene.bl_rna.properties['creation_mode'].enum_items[self.creation_mode_idx].identifier + self.execute(context) + elif event.type == 'S' and event.value == 'RELEASE': self.displace_active = not self.displace_active self.opacity_active = False