Skip to content

Commit

Permalink
Implements #25
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanmunawar committed Jul 13, 2023
1 parent 37eaaa6 commit a0da096
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion ambf_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,40 @@ def execute(self, context):
return {'FINISHED'}


class AMBF_OT_ambf_move_collision_mesh_to_body_origin(Operator):
bl_idname = "ambf.ambf_move_collision_mesh_to_body_origin"
bl_label = "Move collision mesh to body origin"
bl_description = "Move the collision mesh to the correct location (i.e. body's origin, this is where AMBF will consider this mesh)"

def execute(self, context):
collision_mesh_obj = context.object.ambf_collision_mesh
mesh_obj = get_active_object()
if collision_mesh_obj is not None:
collision_mesh_obj.matrix_world = mesh_obj.matrix_world.copy()
make_obj1_parent_of_obj2(collision_mesh_obj, mesh_obj)
select_object(collision_mesh_obj, False)
select_object(mesh_obj)
set_active_object(mesh_obj)
return {'FINISHED'}


class AMBF_OT_ambf_collision_mesh_use_current_location(Operator):
bl_idname = "ambf.ambf_collision_mesh_use_current_location"
bl_label = "Use current location of collision mesh"
bl_description = "Use the current location of the collision mesh (i.e. set its origin to be at the origin of the AMBF object without moving it)"

def execute(self, context):
collision_mesh_obj = context.object.ambf_collision_mesh
mesh_obj = get_active_object()
if collision_mesh_obj is not None:
T_rb_w = mesh_obj.matrix_world.copy()
T_c_w = collision_mesh_obj.matrix_world.copy()
T_c_rb = T_rb_w.inverted() @ T_c_w
collision_mesh_obj.matrix_world = T_rb_w
collision_mesh_obj.data.vertices.data.transform(T_c_rb)
return {'FINISHED'}


class AMBF_PT_main_panel(Panel):
"""Creates a Panel in the Tool Shelf"""
bl_label = "LOAD, CREATE AND SAVE ADFs"
Expand Down Expand Up @@ -3398,6 +3432,14 @@ def draw(self, context):
col.prop(context.object, 'ambf_collision_mesh')
col.enabled = context.object.ambf_use_separate_collision_mesh

col = box.column()
col.operator('ambf.ambf_move_collision_mesh_to_body_origin')
col.enabled = context.object.ambf_use_separate_collision_mesh

col = box.column()
col.operator('ambf.ambf_collision_mesh_use_current_location')
col.enabled = context.object.ambf_use_separate_collision_mesh

elif context.object.ambf_collision_type == 'SINGULAR_SHAPE':

col = box.column()
Expand Down Expand Up @@ -3940,7 +3982,9 @@ class AMBF_PG_CollisionShapePropGroup(PropertyGroup):
AMBF_PT_main_panel,
AMBF_PT_ambf_rigid_body,
AMBF_PT_ambf_ghost_object,
AMBF_PT_ambf_constraint)
AMBF_PT_ambf_constraint,
AMBF_OT_ambf_move_collision_mesh_to_body_origin,
AMBF_OT_ambf_collision_mesh_use_current_location)


def register():
Expand Down

0 comments on commit a0da096

Please sign in to comment.