[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25260] trunk/blender/release/scripts/ modules/rigify: patch from Cessen, tweaks and fixes to metarig elements
Campbell Barton
ideasman42 at gmail.com
Wed Dec 9 23:44:28 CET 2009
Revision: 25260
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25260
Author: campbellbarton
Date: 2009-12-09 23:44:26 +0100 (Wed, 09 Dec 2009)
Log Message:
-----------
patch from Cessen, tweaks and fixes to metarig elements
Modified Paths:
--------------
trunk/blender/release/scripts/modules/rigify/__init__.py
trunk/blender/release/scripts/modules/rigify/arm.py
trunk/blender/release/scripts/modules/rigify/finger.py
trunk/blender/release/scripts/modules/rigify/leg.py
trunk/blender/release/scripts/modules/rigify/neck.py
trunk/blender/release/scripts/modules/rigify/palm.py
trunk/blender/release/scripts/modules/rigify/spine.py
Modified: trunk/blender/release/scripts/modules/rigify/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/__init__.py 2009-12-09 22:37:02 UTC (rev 25259)
+++ trunk/blender/release/scripts/modules/rigify/__init__.py 2009-12-09 22:44:26 UTC (rev 25260)
@@ -294,6 +294,28 @@
blend_rotation(new_pbone, from_bone_name, to_bone_name)
+def get_side_name(name):
+ '''
+ Returns the last part of a string (typically a bone's name) indicating
+ whether it is a a left or right (or center, or whatever) bone.
+ Returns an empty string if nothing is found.
+ '''
+ if name[-2] in "-._":
+ return name[-2:]
+ else:
+ return ""
+
+def get_base_name(name):
+ '''
+ Returns the part of a string (typically a bone's name) corresponding to it's
+ base name (no sidedness, no ORG prefix).
+ '''
+ if name[-2] in "-._":
+ return name[:-2]
+ else:
+ return name
+
+
def add_stretch_to(obj, from_name, to_name, name):
'''
Adds a bone that stretches from one to another
@@ -336,7 +358,7 @@
return stretch_name
-def add_pole_target_bone(obj, base_name, name, mode='CROSS'):
+def add_pole_target_bone(obj, base_bone_name, name, mode='CROSS'):
'''
Does not actually create a poll target, just the bone to use as a poll target
'''
@@ -345,8 +367,8 @@
arm = obj.data
- poll_ebone = arm.edit_bones.new(base_name + "_poll")
- base_ebone = arm.edit_bones[base_name]
+ poll_ebone = arm.edit_bones.new(name)
+ base_ebone = arm.edit_bones[base_bone_name]
poll_name = poll_ebone.name
parent_ebone = base_ebone.parent
Modified: trunk/blender/release/scripts/modules/rigify/arm.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/arm.py 2009-12-09 22:37:02 UTC (rev 25259)
+++ trunk/blender/release/scripts/modules/rigify/arm.py 2009-12-09 22:44:26 UTC (rev 25260)
@@ -19,7 +19,7 @@
# <pep8 compliant>
import bpy
-from rigify import bone_class_instance, copy_bone_simple, add_pole_target_bone, add_stretch_to, blend_bone_list
+from rigify 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
from Mathutils import Vector
@@ -69,9 +69,6 @@
if not mt.shoulder_p:
raise Exception("could not find '%s' parent, skipping:" % orig_bone_name)
-
- if mt.arm_p.parent.bone.connected:
- raise Exception("expected '%s' to be disconnected from its parent" % orig_bone_name)
mt.shoulder = mt.shoulder_p.name
@@ -79,11 +76,11 @@
hands = []
for pbone in obj.pose.bones:
index = pbone.parent_index(mt.arm_p)
- if index == 2:
+ if index == 2 and pbone.bone.connected and pbone.bone.parent.connected:
hands.append(pbone)
if len(hands) != 1:
- raise Exception("Expected more then 1 hand found on:", orig_bone_name)
+ raise Exception("Found %s possible hands attached to this arm, expected 1 from bone: %s" % ([pbone.name for pbone in hands], orig_bone_name))
# first add the 2 new bones
mt.hand_p = hands[0]
@@ -106,12 +103,18 @@
# IK needs no parent_index
ik_chain.hand_e.connected = False
ik_chain.hand_e.parent = None
+ ik_chain.hand_e.local_location = False
+ ik_chain.rename("hand", get_base_name(base_names[mt.hand]) + "_ik" + get_side_name(mt.hand))
ik_chain.arm_e.connected = False
ik_chain.arm_e.parent = mt.shoulder_e
# Add the bone used for the arms poll target
- ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_poll", mode='ZAVERAGE')
+ #ik.pole = add_pole_target_bone(obj, mt.forearm, get_base_name(base_names[mt.forearm]) + "_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
+ ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
+
+ ik.update()
+ ik.pole_e.local_location = False
# update bones after this!
ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand])
@@ -178,7 +181,7 @@
ex.socket = ex.socket_e.name
ex.socket_e.connected = False
ex.socket_e.parent = mt.shoulder_e
- ex.socket_e.tail = mt.shoulder_e.tail
+ ex.socket_e.length *= 0.5
# insert the 'DLT-hand', between the forearm and the hand
# copies forarm rotation
Modified: trunk/blender/release/scripts/modules/rigify/finger.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/finger.py 2009-12-09 22:37:02 UTC (rev 25259)
+++ trunk/blender/release/scripts/modules/rigify/finger.py 2009-12-09 22:44:26 UTC (rev 25260)
@@ -19,7 +19,7 @@
# <pep8 compliant>
import bpy
-from rigify import get_bone_data, empty_layer, copy_bone_simple
+from rigify import get_bone_data, empty_layer, copy_bone_simple, get_side_name, get_base_name
from rna_prop_ui import rna_idprop_ui_prop_get
from functools import reduce
@@ -98,11 +98,12 @@
children = orig_pbone.children_recursive
tot_len = reduce(lambda f, pbone: f + pbone.bone.length, children, orig_pbone.bone.length)
- base_name = base_names[bone_definition[0]].rsplit(".", 1)[0]
+ # FIXME, the line below is far too arbitrary
+ base_name = base_names[bone_definition[0]].rsplit(".", 2)[0]
# first make a new bone at the location of the finger
#control_ebone = arm.edit_bones.new(base_name)
- control_ebone = copy_bone_simple(arm, bone_definition[0], base_name)
+ control_ebone = copy_bone_simple(arm, bone_definition[0], base_name + get_side_name(base_names[bone_definition[0]]), parent=True)
control_bone_name = control_ebone.name # we dont know if we get the name requested
control_ebone.connected = orig_ebone.connected
Modified: trunk/blender/release/scripts/modules/rigify/leg.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/leg.py 2009-12-09 22:37:02 UTC (rev 25259)
+++ trunk/blender/release/scripts/modules/rigify/leg.py 2009-12-09 22:44:26 UTC (rev 25260)
@@ -19,7 +19,7 @@
# <pep8 compliant>
import bpy
-from rigify import bone_class_instance, copy_bone_simple, blend_bone_list
+from rigify import bone_class_instance, copy_bone_simple, blend_bone_list, get_side_name, get_base_name
from rna_prop_ui import rna_idprop_ui_prop_get
METARIG_NAMES = "hips", "thigh", "shin", "foot", "toe", "heel"
@@ -152,15 +152,19 @@
ik_chain.rename("thigh", ik_chain.thigh + "_ik")
ik_chain.rename("shin", ik_chain.shin + "_ik")
- # ik foot, no parents
- base_foot_name = base_names[mt_chain.foot] # whatever the foot is called, use that!, XXX - ORG!
- ik.foot_e = copy_bone_simple(arm, mt_chain.foot, "%s_ik" % base_foot_name)
+ # make sure leg is child of hips
+ ik_chain.thigh_e.parent = mt.hips_e
+
+ # ik foot: no parents
+ base_foot_name = get_base_name(base_names[mt_chain.foot])
+ ik.foot_e = copy_bone_simple(arm, mt_chain.foot, base_foot_name + "_ik" + get_side_name(base_names[mt_chain.foot]))
ik.foot = ik.foot_e.name
ik.foot_e.tail.z = ik.foot_e.head.z
ik.foot_e.roll = 0.0
+ ik.foot_e.local_location = False
- # heel pointing backwards, half length
- ik.foot_roll_e = copy_bone_simple(arm, mt.heel, "%s_roll" % base_foot_name)
+ # 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.parent = ik.foot_e # heel is disconnected
@@ -182,7 +186,7 @@
# rename 'MCH-toe' --> to 'toe_ik' and make the child of ik.foot_roll_01
# ------------------ FK or IK?
- ik_chain.rename("toe", base_names[mt_chain.toe] + "_ik")
+ ik_chain.rename("toe", get_base_name(base_names[mt_chain.toe]) + "_ik" + get_side_name(base_names[mt_chain.toe]))
ik_chain.toe_e.connected = False
ik_chain.toe_e.parent = ik.foot_roll_01_e
@@ -201,6 +205,7 @@
ik.knee_target_e.translate(offset)
ik.knee_target_e.length *= 0.5
ik.knee_target_e.parent = ik.foot_e
+ ik.knee_target_e.local_location = False
# 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
@@ -218,6 +223,12 @@
ik_chain.shin_p.ik_dof_y = False
ik_chain.shin_p.ik_dof_z = False
+ # Set rotation modes and axis locks
+ ik.foot_roll_p.rotation_mode = 'XYZ'
+ ik.foot_roll_p.lock_rotation = False, True, True
+ ik_chain.toe_p.rotation_mode = 'YXZ'
+ ik_chain.toe_p.lock_rotation = False, True, True
+
# IK
con = ik_chain.shin_p.constraints.new('IK')
con.chain_length = 2
@@ -284,13 +295,10 @@
ex.thigh_socket = ex.thigh_socket_e.name
ex.thigh_socket_e.tail = ex.thigh_socket_e.head + Vector(0.0, 0.0, ex.thigh_socket_e.length / 4.0)
- ex.thigh_hinge_e = copy_bone_simple(arm, mt_chain.thigh, "MCH-%s_hinge" % base_names[mt_chain.thigh])
+ ex.thigh_hinge_e = copy_bone_simple(arm, mt.hips, "MCH-%s_hinge" % base_names[mt_chain.thigh], parent=False)
ex.thigh_hinge = ex.thigh_hinge_e.name
- ex.thigh_hinge_e.tail = ex.thigh_hinge_e.head + Vector(0.0, 0.0, mt_chain.thigh_e.head.length)
- ex.thigh_hinge_e.translate(Vector( - (mt.hips_e.head.x - mt_chain.thigh_e.head.x), 0.0, 0.0))
- ex.thigh_hinge_e.length = mt.hips_e.length
- fk_chain = mt_chain.copy() # fk has no prefix!
+ fk_chain = mt_chain.copy(base_names=base_names) # fk has no prefix!
fk_chain.thigh_e.connected = False
fk_chain.thigh_e.parent = ex.thigh_hinge_e
@@ -301,6 +309,13 @@
mt_chain.update()
fk_chain.update()
+ # Set rotation modes and axis locks
+ fk_chain.shin_p.rotation_mode = 'XYZ'
+ fk_chain.shin_p.lock_rotation = False, True, True
+ fk_chain.foot_p.rotation_mode = 'YXZ'
+ fk_chain.toe_p.rotation_mode = 'YXZ'
+ fk_chain.toe_p.lock_rotation = False, True, True
+
con = fk_chain.thigh_p.constraints.new('COPY_LOCATION')
con.target = obj
con.subtarget = ex.thigh_socket
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list