[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1651] trunk/py/scripts/addons/rigify: The leg/foot rig can now rock from side to side.

Nathan Vegdahl cessen at cessen.com
Thu Feb 24 03:16:40 CET 2011


Revision: 1651
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1651
Author:   cessen
Date:     2011-02-24 02:16:38 +0000 (Thu, 24 Feb 2011)
Log Message:
-----------
The leg/foot rig can now rock from side to side.  Requires a special metarig
setup (not yet added to the default human metarig).

Modified Paths:
--------------
    trunk/py/scripts/addons/rigify/rigs/biped/leg/__init__.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py
    trunk/py/scripts/addons/rigify/utils.py

Modified: trunk/py/scripts/addons/rigify/rigs/biped/leg/__init__.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/biped/leg/__init__.py	2011-02-24 00:12:36 UTC (rev 1650)
+++ trunk/py/scripts/addons/rigify/rigs/biped/leg/__init__.py	2011-02-24 02:16:38 UTC (rev 1651)
@@ -177,6 +177,13 @@
         bone.use_connect = True
         bone.parent = arm.edit_bones[bones['shin']]
         bones['heel'] = bone.name
+        bone = arm.edit_bones.new('heel.02')
+        bone.head[:] = -0.0500, -0.0200, 0.0000
+        bone.tail[:] = 0.0500, -0.0200, 0.0000
+        bone.roll = 0.0000
+        bone.use_connect = False
+        bone.parent = arm.edit_bones[bones['heel']]
+        bones['heel.02'] = bone.name
         bone = arm.edit_bones.new('toe')
         bone.head[:] = 0.0000, -0.1200, 0.0300
         bone.tail[:] = 0.0000, -0.2000, 0.0300

Modified: trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py	2011-02-24 00:12:36 UTC (rev 1650)
+++ trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py	2011-02-24 02:16:38 UTC (rev 1651)
@@ -21,7 +21,7 @@
 from mathutils import Vector, Matrix
 from rigify.utils import MetarigError
 from rigify.utils import copy_bone, flip_bone, put_bone
-from rigify.utils import connected_children_names
+from rigify.utils import connected_children_names, has_connected_children
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
 
 
@@ -94,10 +94,10 @@
         heel = None
         for b in self.obj.data.bones[leg_bones[1]].children:
             if b.use_connect == True:
-                if len(b.children) == 0:
+                if len(b.children) >= 1 and has_connected_children(b):
+                    foot = b.name
+                else:
                     heel = b.name
-                else:
-                    foot = b.name
 
         if foot == None or heel == None:
             raise MetarigError("RIGIFY ERROR: Bone '%s': incorrect bone configuration for rig type." % (strip_org(bone)))

Modified: trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py	2011-02-24 00:12:36 UTC (rev 1650)
+++ trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py	2011-02-24 02:16:38 UTC (rev 1651)
@@ -21,7 +21,7 @@
 from mathutils import Vector
 from rigify.utils import MetarigError
 from rigify.utils import copy_bone, flip_bone, put_bone
-from rigify.utils import connected_children_names
+from rigify.utils import connected_children_names, has_connected_children
 from rigify.utils import strip_org, make_mechanism_name, make_deformer_name
 from rigify.utils import get_layers
 from rigify.utils import create_widget, create_limb_widget
@@ -54,10 +54,10 @@
         heel = None
         for b in self.obj.data.bones[leg_bones[1]].children:
             if b.use_connect == True:
-                if len(b.children) == 0:
+                if len(b.children) >= 1 and has_connected_children(b):
+                    foot = b.name
+                else:
                     heel = b.name
-                else:
-                    foot = b.name
 
         if foot == None or heel == None:
             raise MetarigError("RIGIFY ERROR: Bone '%s': incorrect bone configuration for rig type." % (strip_org(bone)))

Modified: trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py
===================================================================
--- trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py	2011-02-24 00:12:36 UTC (rev 1650)
+++ trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py	2011-02-24 02:16:38 UTC (rev 1651)
@@ -21,7 +21,7 @@
 from math import pi, acos
 from rigify.utils import MetarigError
 from rigify.utils import copy_bone, flip_bone, put_bone
-from rigify.utils import connected_children_names
+from rigify.utils import connected_children_names, has_connected_children
 from rigify.utils import strip_org, make_mechanism_name, insert_before_lr
 from rigify.utils import get_layers
 from rigify.utils import create_widget, create_line_widget, create_sphere_widget, create_circle_widget
@@ -102,14 +102,19 @@
         # Get the foot and heel
         foot = None
         heel = None
+        rocker = None
         for b in self.obj.data.bones[leg_bones[1]].children:
             if b.use_connect == True:
-                if len(b.children) == 0:
+                if len(b.children) >= 1 and has_connected_children(b):
+                    foot = b.name
+                else:
                     heel = b.name
-                else:
-                    foot = b.name
+                    if len(b.children) > 0:
+                        rocker = b.children[0].name
+                    
 
         if foot == None or heel == None:
+            print("blah")
             raise MetarigError("RIGIFY ERROR: Bone '%s': incorrect bone configuration for rig type." % (strip_org(bone)))
 
         # Get the toe
@@ -122,7 +127,7 @@
         if toe == None:
             raise MetarigError("RIGIFY ERROR: Bone '%s': incorrect bone configuration for rig type." % (strip_org(bone)))
 
-        self.org_bones = leg_bones + [foot, toe, heel]
+        self.org_bones = leg_bones + [foot, toe, heel, rocker]
 
         # Get rig parameters
         if params.separate_ik_layers:
@@ -140,6 +145,10 @@
         """
         bpy.ops.object.mode_set(mode='EDIT')
 
+        make_rocker = False
+        if self.org_bones[5] is not None:
+            make_rocker = True
+
         # Create the bones
         thigh = copy_bone(self.obj, self.org_bones[0], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[0], "_ik"))))
         shin = copy_bone(self.obj, self.org_bones[1], make_mechanism_name(strip_org(insert_before_lr(self.org_bones[1], "_ik"))))
@@ -154,9 +163,13 @@
         toe_parent_socket2 = copy_bone(self.obj, self.org_bones[2], make_mechanism_name(strip_org(self.org_bones[3] + ".socket2")))
 
         foot_roll = copy_bone(self.obj, self.org_bones[4], strip_org(insert_before_lr(self.org_bones[2], "_roll")))
-        roll1 = copy_bone(self.obj, self.org_bones[4], make_mechanism_name(strip_org(self.org_bones[2] + ".roll")))
-        roll2 = copy_bone(self.obj, self.org_bones[4], make_mechanism_name(strip_org(self.org_bones[2] + ".roll")))
+        roll1 = copy_bone(self.obj, self.org_bones[4], make_mechanism_name(strip_org(self.org_bones[2] + ".roll.01")))
+        roll2 = copy_bone(self.obj, self.org_bones[4], make_mechanism_name(strip_org(self.org_bones[2] + ".roll.02")))
 
+        if make_rocker:
+            rocker1 = copy_bone(self.obj, self.org_bones[5], make_mechanism_name(strip_org(self.org_bones[2] + ".rocker.01")))
+            rocker2 = copy_bone(self.obj, self.org_bones[5], make_mechanism_name(strip_org(self.org_bones[2] + ".rocker.02")))
+
         visfoot = copy_bone(self.obj, self.org_bones[2], "VIS-" + strip_org(insert_before_lr(self.org_bones[2], "_ik")))
         vispole = copy_bone(self.obj, self.org_bones[1], "VIS-" + strip_org(insert_before_lr(self.org_bones[0], "_pole")))
 
@@ -176,6 +189,9 @@
         foot_roll_e = eb[foot_roll]
         roll1_e = eb[roll1]
         roll2_e = eb[roll2]
+        if make_rocker:
+            rocker1_e = eb[rocker1]
+            rocker2_e = eb[rocker2]
         visfoot_e = eb[visfoot]
         vispole_e = eb[vispole]
 
@@ -213,6 +229,14 @@
         vispole_e.use_connect = False
         vispole_e.parent = None
 
+        if make_rocker:
+            rocker1_e.use_connect = False
+            rocker2_e.use_connect = False
+
+            roll1_e.parent = rocker2_e
+            rocker2_e.parent = rocker1_e
+            rocker1_e.parent = foot_e
+
         # Misc
         foot_e.use_local_location = False
 
@@ -270,6 +294,14 @@
         visfoot_e.tail = visfoot_e.head + Vector((0, 0, v1.length / 32))
         vispole_e.tail = vispole_e.head + Vector((0, 0, v1.length / 32))
 
+        if make_rocker:
+            d = toe_e.y_axis.dot(rocker1_e.x_axis)
+            if d >= 0.0:
+                flip_bone(self.obj, rocker2)
+            else:
+                flip_bone(self.obj, rocker1)
+            
+
         # Weird alignment issues.  Fix.
         toe_parent_e.head = Vector(org_foot_e.head)
         toe_parent_e.tail = Vector(org_foot_e.tail)
@@ -297,6 +329,9 @@
         foot_roll_p = pb[foot_roll]
         roll1_p = pb[roll1]
         roll2_p = pb[roll2]
+        if make_rocker:
+            rocker1_p = pb[rocker1]
+            rocker2_p = pb[rocker2]
         toe_p = pb[toe]
         toe_parent_p = pb[toe_parent]
         toe_parent_socket1_p = pb[toe_parent_socket1]
@@ -314,12 +349,22 @@
             shin_p.lock_ik_x = True
             shin_p.lock_ik_y = True
 
-        # Foot roll control only rotates on x-axis.
+        # Foot roll control only rotates on x-axis, or x and y if rocker.
         foot_roll_p.rotation_mode = 'XYZ'
-        foot_roll_p.lock_rotation = False, True, True
+        if make_rocker:
+            foot_roll_p.lock_rotation = False, False, True
+        else:
+            foot_roll_p.lock_rotation = False, True, True
         foot_roll_p.lock_location = True, True, True
         foot_roll_p.lock_scale = True, True, True
 
+        # roll and rocker bones set to euler rotation
+        roll1_p.rotation_mode = 'XYZ'
+        roll2_p.rotation_mode = 'XYZ'
+        if make_rocker:
+            rocker1_p.rotation_mode = 'XYZ'
+            rocker2_p.rotation_mode = 'XYZ'
+
         # Pole target only translates
         pole_p.lock_location = False, False, False
         pole_p.lock_rotation = True, True, True
@@ -372,34 +417,47 @@
         mod.coefficients[0] = 1.0
         mod.coefficients[1] = -1.0
 
-        # Foot roll constraints
-        con = roll1_p.constraints.new('COPY_ROTATION')
-        con.name = "roll"
-        con.target = self.obj
-        con.subtarget = foot_roll
-        con.target_space = 'LOCAL'
-        con.owner_space = 'LOCAL'
+        # Foot roll drivers
+        fcurve = roll1_p.driver_add("rotation_euler", 0)
+        driver = fcurve.driver
+        var = driver.variables.new()
+        driver.type = 'SCRIPTED'
+        driver.expression = "min(0,var)"
+        var.name = "var"
+        var.targets[0].id_type = 'OBJECT'
+        var.targets[0].id = self.obj

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list