diff options
author | Sergej Reich <sergej.reich@googlemail.com> | 2013-01-23 09:56:56 +0400 |
---|---|---|
committer | Sergej Reich <sergej.reich@googlemail.com> | 2013-01-23 09:56:56 +0400 |
commit | 47c96081d00f2edfb1148d5d7c276489f03a8581 (patch) | |
tree | 51f1b93916d4042313dad5bc3907dcc6e0b33503 /release/scripts/startup/bl_operators/rigidbody.py | |
parent | cdc8ed24bfc771e8fcf729ce23db9ab060ade87d (diff) |
rigidbody: Add rigid body constraints
Constraints connect two rigid bodies.
Depending on which constraint is used different degrees of freedom
are limited, e.g. a hinge constraint only allows the objects to rotate
around a common axis.
Constraints are implemented as individual objects and bahave similar to
rigid bodies in terms of adding/removing/validating.
The position and orientation of the constraint object is the pivot point
of the constraint.
Constraints have their own group in the rigid body world.
To make connecting rigid bodies easier, there is a "Connect" operator that
creates an empty objects with a rigid body constraint connecting the selected
objects to active.
Currently the following constraints are implemented:
* Fixed
* Point
* Hinge
* Slider
* Piston
* Generic
Note: constraint limits aren't animatable yet).
Diffstat (limited to 'release/scripts/startup/bl_operators/rigidbody.py')
-rw-r--r-- | release/scripts/startup/bl_operators/rigidbody.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_operators/rigidbody.py b/release/scripts/startup/bl_operators/rigidbody.py index 55a2cef4535..5363eba6420 100644 --- a/release/scripts/startup/bl_operators/rigidbody.py +++ b/release/scripts/startup/bl_operators/rigidbody.py @@ -188,3 +188,63 @@ class BakeToKeyframes(Operator): wm = context.window_manager return wm.invoke_props_dialog(self) + +class ConnectRigidBodies(Operator): + + + '''Connect selected rigid bodies to active''' + bl_idname = "rigidbody.connect" + bl_label = "ConnectRigidBodies" + bl_options = {'REGISTER', 'UNDO'} + + con_type = EnumProperty( + name="Type", + description="Type of generated contraint", + items=(('FIXED', "Fixed", "Glues ridig bodies together"), + ('POINT', "Point", "Constrains rigid bodies to move aound common pivot point"), + ('HINGE', "Hinge", "Restricts rigid body rotation to one axis"), + ('SLIDER', "Slider", "Restricts rigid boddy translation to one axis"), + ('PISTON', "Piston", "Restricts rigid boddy translation and rotation to one axis"), + ('GENERIC', "Generic", "Restricts translation and rotation to specified axes"), + default='FIXED',) + + pivot_type = EnumProperty( + name="Location", + description="Constraint pivot location", + items=(('CENTER', "Center", "Pivot location is between the constrained rigid bodies"), + ('ACTIVE', "Active", "Pivot location is at the active object position"), + ('SELECTED', "Selected", "Pivot location is at the slected object position")), + default='CENTER',) + + @classmethod + def poll(cls, context): + obj = bpy.context.object + objs = bpy.context.selected_objects + return (obj and obj.rigid_body and (len(objs) > 1)) + + def execute(self, context): + + objs = bpy.context.selected_objects + ob_act = bpy.context.active_object + + for ob in objs: + if ob == ob_act: + continue + if self.pivot_type == 'ACTIVE': + loc = ob_act.location + elif self.pivot_type == 'SELECTED': + loc = ob.location + else: + loc = (ob_act.location + ob.location) / 2 + bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=loc) + bpy.ops.rigidbody.constraint_group_add() + con = bpy.context.active_object.rigid_body_constraint + con.type = self.con_type + con.object1 = ob_act + con.object2 = ob + + return {'FINISHED'} + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) |