Skip to content

Commit

Permalink
#61 Works in global mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Weisl committed Jun 27, 2022
1 parent 698f422 commit e672e3d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions operators/__init__.py
Expand Up @@ -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')
Expand Down
30 changes: 25 additions & 5 deletions operators/add_bounding_box.py
Expand Up @@ -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
Expand All @@ -143,24 +146,39 @@ 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']
verts_loc = bounding_box_data['verts_loc']

global face_order
new_collider = verts_faces_to_bbox_collider(self, context, verts_loc, face_order)

scene = context.scene

if scene.my_space == 'LOCAL':
Expand All @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions operators/add_bounding_primitive.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e672e3d

Please sign in to comment.