[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54025] trunk/blender: rigidbody: Add rigid body constraints

Sergej Reich sergej.reich at googlemail.com
Wed Jan 23 06:56:57 CET 2013


Revision: 54025
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54025
Author:   sergof
Date:     2013-01-23 05:56:56 +0000 (Wed, 23 Jan 2013)
Log Message:
-----------
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).

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
    trunk/blender/release/scripts/startup/bl_ui/__init__.py
    trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py
    trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenkernel/intern/rigidbody.c
    trunk/blender/source/blender/blenkernel/intern/scene.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/editors/include/ED_physics.h
    trunk/blender/source/blender/editors/object/object_add.c
    trunk/blender/source/blender/editors/physics/CMakeLists.txt
    trunk/blender/source/blender/editors/physics/physics_intern.h
    trunk/blender/source/blender/editors/physics/physics_ops.c
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/makesdna/DNA_rigidbody_types.h
    trunk/blender/source/blender/makesrna/RNA_enum_types.h
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_rigidbody.c

Added Paths:
-----------
    trunk/blender/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
    trunk/blender/source/blender/editors/physics/rigidbody_constraint.c

Modified: trunk/blender/release/scripts/startup/bl_operators/rigidbody.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 05:56:49 UTC (rev 54024)
+++ trunk/blender/release/scripts/startup/bl_operators/rigidbody.py	2013-01-23 05:56:56 UTC (rev 54025)
@@ -188,3 +188,63 @@
         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)

Modified: trunk/blender/release/scripts/startup/bl_ui/__init__.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/__init__.py	2013-01-23 05:56:49 UTC (rev 54024)
+++ trunk/blender/release/scripts/startup/bl_ui/__init__.py	2013-01-23 05:56:56 UTC (rev 54025)
@@ -49,6 +49,7 @@
     "properties_physics_field",
     "properties_physics_fluid",
     "properties_physics_rigidbody",
+    "properties_physics_rigidbody_constraint",
     "properties_physics_smoke",
     "properties_physics_softbody",
     "properties_render",

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py	2013-01-23 05:56:49 UTC (rev 54024)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py	2013-01-23 05:56:56 UTC (rev 54025)
@@ -88,7 +88,12 @@
                                 "rigidbody.object_remove",
                                 'MESH_ICOSPHERE') # XXX: need dedicated icon
 
+            physics_add_special(self, col, ob.rigid_body_constraint, "Rigid Body Constraint",
+                                "rigidbody.constraint_add",
+                                "rigidbody.constraint_remove",
+                                'CONSTRAINT') # RB_TODO needs better icon
 
+
 # cache-type can be 'PSYS' 'HAIR' 'SMOKE' etc
 
 def point_cache_ui(self, context, cache, enabled, cachetype):

Added: trunk/blender/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py	                        (rev 0)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py	2013-01-23 05:56:56 UTC (rev 54025)
@@ -0,0 +1,215 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+import bpy
+from bpy.types import Panel
+
+
+class PHYSICS_PT_rigidbody_constraint_panel():
+    bl_space_type = 'PROPERTIES'
+    bl_region_type = 'WINDOW'
+    bl_context = "physics"
+
+
+class PHYSICS_PT_rigid_body_constraint(PHYSICS_PT_rigidbody_constraint_panel, Panel):
+    bl_label = "Rigid Body Constraint"
+
+    @classmethod
+    def poll(cls, context):
+        ob = context.object
+        rd = context.scene.render
+        return (ob and ob.rigid_body_constraint and (not rd.use_game_engine))
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        rbc = ob.rigid_body_constraint
+
+        if rbc:
+            layout.prop(rbc, "type")
+
+            split = layout.split()
+
+            row = split.row()
+            row.prop(rbc, "enabled")
+            row.prop(rbc, "disable_collisions")
+
+            split = layout.split()
+            split.prop(rbc, "object1")
+            split = layout.split()
+            split.prop(rbc, "object2")
+
+            split = layout.split()
+            col = split.row()
+            col.prop(rbc, "use_breaking")
+            sub = col.column()
+            sub.active = rbc.use_breaking
+            sub.prop(rbc, "breaking_threshold", text="Threshold")
+
+            split = layout.split()
+            col = split.row()
+            col.prop(rbc, "override_solver_iterations", text="Override Iterations")
+            sub = col.split()
+            sub.active = rbc.override_solver_iterations
+            sub.prop(rbc, "num_solver_iterations", text="Iterations")
+
+            if rbc.type == 'HINGE':
+                col = layout.column(align=True)
+                col.label("Limits:")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_ang_z", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_ang_z
+                sub.prop(rbc, "limit_ang_z_lower", text="Lower")
+                sub.prop(rbc, "limit_ang_z_upper", text="Upper")
+
+            elif rbc.type == 'SLIDER':
+                col = layout.column(align=True)
+                col.label("Limits:")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_lin_x", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_lin_x
+                sub.prop(rbc, "limit_lin_x_lower", text="Lower")
+                sub.prop(rbc, "limit_lin_x_upper", text="Upper")
+
+            elif rbc.type == 'PISTON':
+                col = layout.column(align=True)
+                col.label("Limits:")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_lin_x", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_lin_x
+                sub.prop(rbc, "limit_lin_x_lower", text="Lower")
+                sub.prop(rbc, "limit_lin_x_upper", text="Upper")
+
+                col = layout.column(align=True)
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_ang_x", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_ang_x
+                sub.prop(rbc, "limit_ang_x_lower", text="Lower")
+                sub.prop(rbc, "limit_ang_x_upper", text="Upper")
+
+            elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
+                col = layout.column(align=True)
+                col.label("Limits:")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_lin_x", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_lin_x
+                sub.prop(rbc, "limit_lin_x_lower", text="Lower")
+                sub.prop(rbc, "limit_lin_x_upper", text="Upper")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_lin_y", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_lin_y
+                sub.prop(rbc, "limit_lin_y_lower", text="Lower")
+                sub.prop(rbc, "limit_lin_y_upper", text="Upper")
+
+                row = col.row()
+                sub = row.row()
+                sub.scale_x = 0.5
+                sub.prop(rbc, "use_limit_lin_z", toggle=True)
+                sub = row.row()
+                sub.active = rbc.use_limit_lin_z
+                sub.prop(rbc, "limit_lin_z_lower", text="Lower")
+                sub.prop(rbc, "limit_lin_z_upper", text="Upper")
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list