Skip to content

Commit

Permalink
Add rigid body operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Weisl committed Jan 30, 2024
1 parent fb1ce3c commit 1ceb312
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
importlib.reload(collider_conversion)
importlib.reload(auto_Convex)
importlib.reload(pyshics_materials)
importlib.reload(rigid_body)
importlib.reload(preferences)


Expand All @@ -33,6 +34,7 @@
from . import collider_conversion
from . import auto_Convex
from . import pyshics_materials
from . import rigid_body
from . import preferences


Expand All @@ -45,6 +47,7 @@ def register():
collider_conversion.register()
auto_Convex.register()
pyshics_materials.register()
rigid_body.register()

# keymap and preferences should be last
preferences.register()
Expand All @@ -56,6 +59,7 @@ def unregister():
# call unregister function of the sub-modules
preferences.unregister()

rigid_body.unregister()
pyshics_materials.unregister()
auto_Convex.unregister()
collider_conversion.unregister()
Expand Down
19 changes: 19 additions & 0 deletions rigid_body/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from . import rigid_body


classes = (
rigid_body.OBJECT_OT_make_rigid_body,
)


def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)


def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)

28 changes: 28 additions & 0 deletions rigid_body/rigid_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import bpy

class OBJECT_OT_make_rigid_body(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.set_rigid_body"
bl_label = "Make_rigid_body"
bl_description = 'Convert object to be a rigid body'

@classmethod
def poll(cls, context):
return len(context.selected_objects) > 0

def execute(self, context):
prefs = context.preferences.addons[__package__.split('.')[0]].preferences

for obj in bpy.context.selected_objects.copy():
new_name = obj.name

if prefs.rigid_body_naming_position == 'SUFFIX':
if not obj.name.endswith(prefs.rigid_body_extension):
new_name = obj.name + prefs.rigid_body_separator + prefs.rigid_body_extension
else:
if not obj.name.startswith(prefs.rigid_body_extension):
new_name = prefs.rigid_body_extension + prefs.rigid_body_separator + obj.name

obj.name = new_name
return {'FINISHED'}

11 changes: 5 additions & 6 deletions ui/properties_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,11 @@ def draw_creation_menu(context, layout, settings=False):

layout.separator()

# row = layout.row(align=True)
# row.label(text='Display')
#
# row = layout.row(align=True)
# row.operator('view.collider_view_object', icon='HIDE_OFF', text='Groups')
# row.operator('view.collider_view_material', icon='HIDE_OFF', text='Materials')
row = layout.row(align=True)
row.label(text='Rigid Body')

row = layout.row(align=True)
row.operator('object.set_rigid_body', icon='NONE')


row = layout.row(align=True)
Expand Down

0 comments on commit 1ceb312

Please sign in to comment.