diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-10 01:44:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-10 01:44:26 +0300 |
commit | 3535be3f6f35af5a766c7bc523c68054584a3ad4 (patch) | |
tree | b36d1b65adf9e10cd5e0033dd8c9cf68ca75068a | |
parent | 30fd13387dc5b9733a0402f1a58dbbddd162d918 (diff) |
patch from Cessen, tweaks and fixes to metarig elements
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 28 | ||||
-rw-r--r-- | release/scripts/modules/rigify/arm.py | 19 | ||||
-rw-r--r-- | release/scripts/modules/rigify/finger.py | 7 | ||||
-rw-r--r-- | release/scripts/modules/rigify/leg.py | 39 | ||||
-rw-r--r-- | release/scripts/modules/rigify/neck.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rigify/palm.py | 7 | ||||
-rw-r--r-- | release/scripts/modules/rigify/spine.py | 1 |
7 files changed, 74 insertions, 29 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index af345b5e546..2f099474990 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -294,6 +294,28 @@ def blend_bone_list(obj, apply_bones, from_bones, to_bones, target_bone=None, ta 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 @@ def add_stretch_to(obj, from_name, to_name, name): 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 @@ def add_pole_target_bone(obj, base_name, name, mode='CROSS'): 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 diff --git a/release/scripts/modules/rigify/arm.py b/release/scripts/modules/rigify/arm.py index 6ed564ac070..35be7f34e4b 100644 --- a/release/scripts/modules/rigify/arm.py +++ b/release/scripts/modules/rigify/arm.py @@ -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 @@ def metarig_definition(obj, orig_bone_name): 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 @@ def metarig_definition(obj, orig_bone_name): 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 @@ def ik(obj, definitions, base_names): # 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 @@ def fk(obj, definitions, base_names): 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 diff --git a/release/scripts/modules/rigify/finger.py b/release/scripts/modules/rigify/finger.py index baa9ed49041..ad4206cc432 100644 --- a/release/scripts/modules/rigify/finger.py +++ b/release/scripts/modules/rigify/finger.py @@ -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 @@ def main(obj, bone_definition, base_names): 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 diff --git a/release/scripts/modules/rigify/leg.py b/release/scripts/modules/rigify/leg.py index ed28c21fd32..aaed335f6c7 100644 --- a/release/scripts/modules/rigify/leg.py +++ b/release/scripts/modules/rigify/leg.py @@ -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 @@ def ik(obj, bone_definition, base_names): 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 @@ def ik(obj, bone_definition, base_names): # 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 @@ def ik(obj, bone_definition, base_names): 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 @@ def ik(obj, bone_definition, base_names): 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 @@ def fk(obj, bone_definition, base_names): 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 @@ def fk(obj, bone_definition, base_names): 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 --git a/release/scripts/modules/rigify/neck.py b/release/scripts/modules/rigify/neck.py index 887b0b091fc..0aeee59225e 100644 --- a/release/scripts/modules/rigify/neck.py +++ b/release/scripts/modules/rigify/neck.py @@ -135,7 +135,7 @@ def main(obj, bone_definition, base_names): ex.head_e.tail.y += head_length / 2.0 # Yes, use the body bone but call it a head hinge - ex.head_hinge_e = copy_bone_simple(arm, mt.body, "MCH_%s_hinge" % base_names[mt.head], parent=True) + ex.head_hinge_e = copy_bone_simple(arm, mt.body, "MCH_%s_hinge" % base_names[mt.head], parent=False) ex.head_hinge_e.connected = False ex.head_hinge = ex.head_hinge_e.name ex.head_hinge_e.head.y += head_length / 4.0 diff --git a/release/scripts/modules/rigify/palm.py b/release/scripts/modules/rigify/palm.py index 5f4ada6128d..078e3125b00 100644 --- a/release/scripts/modules/rigify/palm.py +++ b/release/scripts/modules/rigify/palm.py @@ -19,7 +19,7 @@ # <pep8 compliant> import bpy -from rigify import get_bone_data, copy_bone_simple +from rigify import get_bone_data, copy_bone_simple, get_side_name from rna_prop_ui import rna_idprop_ui_prop_get # not used, defined for completeness @@ -105,7 +105,10 @@ def main(obj, bone_definition, base_names): pinky_ebone = arm.edit_bones[children[0]] ring_ebone = arm.edit_bones[children[1]] - control_ebone = copy_bone_simple(arm, pinky_ebone.name, "palm_control", parent=True) + # FIXME, why split the second one? + base_name = base_names[pinky_ebone.name].rsplit('.', 2)[0] + + control_ebone = copy_bone_simple(arm, pinky_ebone.name, base_name + get_side_name(base_names[pinky_ebone.name]), parent=True) control_name = control_ebone.name offset = (pinky_ebone.head - ring_ebone.head) diff --git a/release/scripts/modules/rigify/spine.py b/release/scripts/modules/rigify/spine.py index 2ccc10350b1..ed42d6a2e46 100644 --- a/release/scripts/modules/rigify/spine.py +++ b/release/scripts/modules/rigify/spine.py @@ -148,6 +148,7 @@ def main(obj, bone_definition, base_names): ex.pelvis_copy_e = copy_bone_simple(arm, mt.pelvis, base_names[mt.pelvis]) # no parent ex.pelvis_copy = ex.pelvis_copy_e.name + ex.pelvis_copy_e.local_location = False # copy the pelvis, offset to make MCH-spine_rotate and MCH-ribcage_hinge ex.ribcage_hinge_e = copy_bone_simple(arm, mt.pelvis, "MCH-%s_hinge" % base_names[mt.ribcage]) |