[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25384] trunk/blender: * new metarig type for the durian dragon leg (original rig by Cessen)

Campbell Barton ideasman42 at gmail.com
Mon Dec 14 21:56:19 CET 2009


Revision: 25384
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25384
Author:   campbellbarton
Date:     2009-12-14 21:56:19 +0100 (Mon, 14 Dec 2009)

Log Message:
-----------
* new metarig type for the durian dragon leg (original rig by Cessen)
* option to roll the delta of the arm rig.
* fix to copy metarig type
* renamed EditBone.align() --> EditBone.align_roll()
* Added EditBone.align_orientation(other)
* Added bone.vector: same as (bone.tail - bone.head)

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_types.py
    trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py
    trunk/blender/release/scripts/modules/rigify/copy.py
    trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py
    trunk/blender/release/scripts/modules/rigify/neck_flex.py
    trunk/blender/release/scripts/modules/rigify/spine_pivot_flex.py
    trunk/blender/release/scripts/modules/rigify_utils.py
    trunk/blender/release/scripts/ui/properties_data_bone.py
    trunk/blender/release/scripts/ui/properties_object_constraint.py
    trunk/blender/release/test/pep8.py
    trunk/blender/source/blender/makesrna/intern/rna_armature_api.c

Added Paths:
-----------
    trunk/blender/release/scripts/modules/rigify/leg_quadruped_generic.py

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2009-12-14 20:47:02 UTC (rev 25383)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2009-12-14 20:56:19 UTC (rev 25384)
@@ -94,7 +94,7 @@
 
     @property
     def length(self):
-        return (self.head - self.tail).length
+        return self.vector.length
 
     @length.setter
     def length(self, value):
@@ -102,6 +102,10 @@
         self.tail = self.head + ((self.tail - self.head).normalize() * value)
 
     @property
+    def vector(self):
+        return (self.tail - self.head)
+
+    @property
     def children(self):
         return [child for child in self._other_bones if child.parent == self]
 
@@ -172,7 +176,16 @@
 class EditBone(StructRNA, _GenericBone):
     __slots__ = ()
 
+    def align_orientation(self, other):
+        '''
+        Align this bone to another by moving its tail and settings its roll
+        the length of the other bone is not used.
+        '''
+        vec = other.vector.normalize() * self.length
+        self.tail = self.head + vec
+        self.roll = other.roll
 
+
 def ord_ind(i1, i2):
     if i1 < i2:
         return i1, i2

Modified: trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py	2009-12-14 20:47:02 UTC (rev 25383)
+++ trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py	2009-12-14 20:56:19 UTC (rev 25384)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from math import radians
 from rigify import RigifyError, get_layer_dict
 from rigify_utils import bone_class_instance, copy_bone_simple, add_pole_target_bone, add_stretch_to, blend_bone_list, get_side_name, get_base_name
 from rna_prop_ui import rna_idprop_ui_prop_get
@@ -213,6 +214,8 @@
     ex.hand_delta = ex.hand_delta_e.name
     ex.hand_delta_e.length *= 0.5
     ex.hand_delta_e.connected = False
+    if "hand_roll" in options:
+        ex.hand_delta_e.roll += radians(options["hand_roll"])
 
     fk_chain.hand_e.connected = False
     fk_chain.hand_e.parent = ex.hand_delta_e

Modified: trunk/blender/release/scripts/modules/rigify/copy.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/copy.py	2009-12-14 20:47:02 UTC (rev 25383)
+++ trunk/blender/release/scripts/modules/rigify/copy.py	2009-12-14 20:56:19 UTC (rev 25384)
@@ -53,25 +53,25 @@
     cp = bone_class_instance(obj, ["cpy"])
     cp.cpy_e = copy_bone_simple(arm, mt.cpy, base_names[mt.cpy], parent=True)
     cp.cpy = cp.cpy_e.name
-    
+
     bpy.ops.object.mode_set(mode='OBJECT')
 
     cp.update()
     mt.update()
 
     if not cp.cpy_b.connected:
-        con = cp.cpy_p.constraints.new('COPY_LOCATION')
+        con = mt.cpy_p.constraints.new('COPY_LOCATION')
         con.target = obj
-        con.subtarget = mt.cpy
+        con.subtarget = cp.cpy
 
-    con = cp.cpy_p.constraints.new('COPY_ROTATION')
+    con = mt.cpy_p.constraints.new('COPY_ROTATION')
     con.target = obj
     con.subtarget = cp.cpy
 
     con = mt.cpy_p.constraints.new('COPY_SCALE')
     con.target = obj
     con.subtarget = cp.cpy
-    
+
     # Rotation mode and axis locks
     cp.cpy_p.rotation_mode = mt.cpy_p.rotation_mode
     cp.cpy_p.lock_location = tuple(mt.cpy_p.lock_location)

Modified: trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py	2009-12-14 20:47:02 UTC (rev 25383)
+++ trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py	2009-12-14 20:56:19 UTC (rev 25384)
@@ -128,22 +128,16 @@
 def ik(obj, bone_definition, base_names, options):
     arm = obj.data
 
-    # setup the existing bones
+    # setup the existing bones, use names from METARIG_NAMES
     mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
     mt = bone_class_instance(obj, ["hips", "heel"])
+
+    mt.attr_initialize(METARIG_NAMES, bone_definition)
+    mt_chain.attr_initialize(METARIG_NAMES, bone_definition)
+
     # children of ik_foot
     ik = bone_class_instance(obj, ["foot", "foot_roll", "foot_roll_01", "foot_roll_02", "knee_target"])
 
-    # XXX - duplicate below
-    for bone_class in (mt, mt_chain):
-        for attr in bone_class.attr_names:
-            i = METARIG_NAMES.index(attr)
-            ebone = arm.edit_bones[bone_definition[i]]
-            setattr(bone_class, attr, ebone.name)
-        bone_class.update()
-    # XXX - end dupe
-
-
     # Make a new chain
     ik_chain = mt_chain.copy(to_fmt="MCH-%s", base_names=base_names)
 
@@ -165,7 +159,7 @@
     # foot roll: heel pointing backwards, half length
     ik.foot_roll_e = copy_bone_simple(arm, mt.heel, base_foot_name + "_roll" + get_side_name(base_names[mt_chain.foot]))
     ik.foot_roll = ik.foot_roll_e.name
-    ik.foot_roll_e.tail = ik.foot_roll_e.head + (ik.foot_roll_e.head - ik.foot_roll_e.tail) / 2.0
+    ik.foot_roll_e.tail = ik.foot_roll_e.head + ik.foot_roll_e.vector / 2.0
     ik.foot_roll_e.parent = ik.foot_e # heel is disconnected
 
     # heel pointing forwards to the toe base, parent of the following 2 bones
@@ -208,7 +202,7 @@
 
     # roll the bone to point up... could also point in the same direction as ik.foot_roll
     # ik.foot_roll_02_e.matrix * Vector(0.0, 0.0, 1.0) # ACK!, no rest matrix in editmode
-    ik.foot_roll_01_e.align((0.0, 0.0, -1.0))
+    ik.foot_roll_01_e.align_roll((0.0, 0.0, -1.0))
 
     bpy.ops.object.mode_set(mode='OBJECT')
 
@@ -355,7 +349,6 @@
     mod.coefficients[1] = -1.0
 
 
-
     # last step setup layers
     layers = get_layer_dict(options)
     lay = layers["fk"]

Added: trunk/blender/release/scripts/modules/rigify/leg_quadruped_generic.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/leg_quadruped_generic.py	                        (rev 0)
+++ trunk/blender/release/scripts/modules/rigify/leg_quadruped_generic.py	2009-12-14 20:56:19 UTC (rev 25384)
@@ -0,0 +1,225 @@
+# ##### 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import bpy
+from rigify import RigifyError, get_layer_dict
+from rigify_utils import bone_class_instance, copy_bone_simple, blend_bone_list, get_side_name, get_base_name, add_pole_target_bone
+from rna_prop_ui import rna_idprop_ui_prop_get
+from Mathutils import Vector
+
+METARIG_NAMES = "hips", "thigh", "shin", "foot", "toe"
+
+
+def metarig_template():
+    # generated by rigify.write_meta_rig
+    bpy.ops.object.mode_set(mode='EDIT')
+    obj = bpy.context.active_object
+    arm = obj.data
+    bone = arm.edit_bones.new('body')
+    bone.head[:] = -0.3000, -1.0000, 0.0000
+    bone.tail[:] = -0.3000, -1.0000, 1.0000
+    bone.roll = 0.0000
+    bone.connected = False
+    bone = arm.edit_bones.new('thigh')
+    bone.head[:] = 0.0000, 0.0000, -0.0000
+    bone.tail[:] = 0.3351, -0.8690, -1.3903
+    bone.roll = -0.4656
+    bone.connected = False
+    bone.parent = arm.edit_bones['body']
+    bone = arm.edit_bones.new('shin')
+    bone.head[:] = 0.3351, -0.8690, -1.3903
+    bone.tail[:] = 0.2943, -0.0179, -2.4026
+    bone.roll = -0.2024
+    bone.connected = True
+    bone.parent = arm.edit_bones['thigh']
+    bone = arm.edit_bones.new('foot')
+    bone.head[:] = 0.2943, -0.0179, -2.4026
+    bone.tail[:] = 0.3830, -0.1995, -3.1531
+    bone.roll = -0.3766
+    bone.connected = True
+    bone.parent = arm.edit_bones['shin']
+    bone = arm.edit_bones.new('toe')
+    bone.head[:] = 0.3830, -0.1995, -3.1531
+    bone.tail[:] = 0.4724, -0.5126, -3.1531
+    bone.roll = 0.0000
+    bone.connected = True
+    bone.parent = arm.edit_bones['foot']
+
+    bpy.ops.object.mode_set(mode='OBJECT')
+    pbone = obj.pose.bones['thigh']
+    pbone['type'] = 'leg_quadruped_generic'
+
+
+def metarig_definition(obj, orig_bone_name):
+    '''
+    The bone given is the first in a chain
+    Expects a chain of at least 3 children.
+    eg.
+        thigh -> shin -> foot -> [toe, heel]
+    '''
+
+    bone_definition = []
+
+    orig_bone = obj.data.bones[orig_bone_name]
+    orig_bone_parent = orig_bone.parent
+
+    if orig_bone_parent is None:
+        raise RigifyError("expected the thigh bone to have a parent hip bone")
+
+    bone_definition.append(orig_bone_parent.name)
+    bone_definition.append(orig_bone.name)
+
+
+    bone = orig_bone
+    chain = 0
+    while chain < 3: # first 2 bones only have 1 child
+        children = bone.children
+
+        if len(children) != 1:
+            raise RigifyError("expected the thigh bone to have 3 children without a fork")
+        bone = children[0]
+        bone_definition.append(bone.name) # shin, foot
+        chain += 1
+
+    if len(bone_definition) != len(METARIG_NAMES):
+        raise RigifyError("internal problem, expected %d bones" % len(METARIG_NAMES))
+
+    return bone_definition
+
+
+def ik(obj, bone_definition, base_names, options):
+    arm = obj.data
+
+    # setup the existing bones, use names from METARIG_NAMES
+    mt = bone_class_instance(obj, ["hips"])
+    mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
+
+    mt.attr_initialize(METARIG_NAMES, bone_definition)
+    mt_chain.attr_initialize(METARIG_NAMES, bone_definition)
+
+    ik_chain = mt_chain.copy(to_fmt="%s", base_names=base_names)
+
+    ik_chain.thigh_e.connected = False
+    ik_chain.thigh_e.parent = mt.hips_e
+
+    ik_chain.foot_e.parent = None
+    ik_chain.rename("foot", ik_chain.foot + "_ik")
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list