diff options
Diffstat (limited to 'release/scripts/modules/rigify/spine.py')
-rw-r--r-- | release/scripts/modules/rigify/spine.py | 126 |
1 files changed, 77 insertions, 49 deletions
diff --git a/release/scripts/modules/rigify/spine.py b/release/scripts/modules/rigify/spine.py index 39ba4baee61..2ccc10350b1 100644 --- a/release/scripts/modules/rigify/spine.py +++ b/release/scripts/modules/rigify/spine.py @@ -27,6 +27,7 @@ METARIG_NAMES = ("pelvis", "ribcage") def metarig_template(): + # generated by rigify.write_meta_rig bpy.ops.object.mode_set(mode='EDIT') obj = bpy.context.object arm = obj.data @@ -86,7 +87,7 @@ def metarig_template(): bpy.ops.object.mode_set(mode='OBJECT') pbone = obj.pose.bones['rib_cage'] - pbone['type'] = 'spine' + pbone['type'] = 'spine.fk' def metarig_definition(obj, orig_bone_name): @@ -110,7 +111,7 @@ def metarig_definition(obj, orig_bone_name): raise Exception("expected the ribcage to have only 1 child.") child = children[0] - + bone_definition = [pelvis.name, ribcage.name, child.name] bone_definition.extend([child.name for child in child.children_recursive_basename]) return bone_definition @@ -139,46 +140,54 @@ def main(obj, bone_definition, base_names): child = spine_chain[0] spine_chain_segment_length = child.length - child.parent = mt.pelvis_e # was mt.ribcage + #child.parent = mt.pelvis_e # was mt.ribcage # The first bone in the chain happens to be the basis of others, create them now - ex = bone_class_instance(obj, ["pelvis", "ribcage", "ribcage_hinge", "spine_rotate"]) + ex = bone_class_instance(obj, ["pelvis", "pelvis_copy", "ribcage", "ribcage_hinge", "ribcage_copy", "spine_rotate"]) df = bone_class_instance(obj, ["pelvis", "ribcage"]) # DEF-wgt_pelvis, DEF-wgt_rib_cage + ex.pelvis_copy_e = copy_bone_simple(arm, mt.pelvis, base_names[mt.pelvis]) # no parent + ex.pelvis_copy = ex.pelvis_copy_e.name # 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" % mt.ribcage) + ex.ribcage_hinge_e = copy_bone_simple(arm, mt.pelvis, "MCH-%s_hinge" % base_names[mt.ribcage]) ex.ribcage_hinge = ex.ribcage_hinge_e.name ex.ribcage_hinge_e.translate(Vector(0.0, spine_chain_segment_length / 4.0, 0.0)) - mt.ribcage_e.parent = ex.ribcage_hinge_e ex.spine_rotate_e = copy_bone_simple(arm, mt.pelvis, "MCH-%s_rotate" % spine_chain_basename) ex.spine_rotate = ex.spine_rotate_e.name ex.spine_rotate_e.translate(Vector(0.0, spine_chain_segment_length / 2.0, 0.0)) # swap head/tail ex.spine_rotate_e.head, ex.spine_rotate_e.tail = ex.spine_rotate_e.tail.copy(), ex.spine_rotate_e.head.copy() - ex.spine_rotate_e.parent = mt.pelvis_e + ex.spine_rotate_e.connected = False + ex.spine_rotate_e.parent = ex.pelvis_copy_e - df.pelvis_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % mt.pelvis) + df.pelvis_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % base_names[mt.pelvis]) df.pelvis = df.pelvis_e.name df.pelvis_e.translate(Vector(spine_chain_segment_length * 2.0, - spine_chain_segment_length, 0.0)) - ex.pelvis_e = copy_bone_simple(arm, child.name, "MCH-wgt_%s" % mt.pelvis) + ex.pelvis_e = copy_bone_simple(arm, child.name, "MCH-wgt_%s" % base_names[mt.pelvis]) ex.pelvis = ex.pelvis_e.name ex.pelvis_e.translate(Vector(0.0, - spine_chain_segment_length, 0.0)) - ex.pelvis_e.parent = mt.pelvis_e + ex.pelvis_e.connected = False + ex.pelvis_e.parent = ex.pelvis_copy_e # Copy the last bone now child = spine_chain[-1] - df.ribcage_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % mt.ribcage) + df.ribcage_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % base_names[mt.ribcage]) df.ribcage = df.ribcage_e.name df.ribcage_e.translate(Vector(spine_chain_segment_length * 2.0, - df.ribcage_e.length / 2.0, 0.0)) + + ex.ribcage_copy_e = copy_bone_simple(arm, mt.ribcage, base_names[mt.ribcage]) + ex.ribcage_copy = ex.ribcage_copy_e.name + ex.ribcage_copy_e.connected = False + ex.ribcage_copy_e.parent = ex.ribcage_hinge_e - ex.ribcage_e = copy_bone_simple(arm, child.name, "MCH-wgt_%s" % mt.ribcage) + ex.ribcage_e = copy_bone_simple(arm, child.name, "MCH-wgt_%s" % base_names[mt.ribcage]) ex.ribcage = ex.ribcage_e.name ex.ribcage_e.translate(Vector(0.0, - ex.ribcage_e.length / 2.0, 0.0)) - ex.ribcage_e.parent = mt.ribcage_e + ex.ribcage_e.parent = ex.ribcage_copy_e spine_chain = [child.name for child in spine_chain] @@ -214,21 +223,22 @@ def main(obj, bone_definition, base_names): # Now we need to re-parent these chains for i, child_name in enumerate(spine_chain_orig): attr = ex_chain.attr_names[i] + "_e" - + ebone = getattr(ex_chain, attr) if i == 0: - getattr(ex_chain, attr).parent = mt.pelvis_e + ebone.connected = False + ebone.parent = ex.pelvis_copy_e else: - attr_parent = ex_chain.attr_names[i-1] + "_e" - getattr(ex_chain, attr).parent = getattr(ex_chain, attr_parent) + attr_parent = ex_chain.attr_names[i - 1] + "_e" + ebone.parent = getattr(ex_chain, attr_parent) # intentional! get the parent from the other paralelle chain member - getattr(rv_chain, attr).parent = getattr(ex_chain, attr) + getattr(rv_chain, attr).parent = ebone # ex_chain needs to interlace bones! # Note, skip the first bone for i in range(1, spine_chain_len): # similar to neck - child_name_orig = spine_chain_orig[i] + child_name_orig = base_names[spine_chain_orig[i]] spine_e = getattr(mt_chain, mt_chain.attr_names[i] + "_e") # dont store parent names, re-reference as each chain bones parent. @@ -284,6 +294,8 @@ def main(obj, bone_definition, base_names): con.target_space = 'LOCAL' # df.ribcage_p / DEF-wgt_rib_cage + df.ribcage_p.lock_location = True, True, True + con = df.ribcage_p.constraints.new('COPY_ROTATION') con.target = obj con.subtarget = ex.ribcage @@ -299,11 +311,9 @@ def main(obj, bone_definition, base_names): con = ex.ribcage_hinge_p.constraints.new('COPY_ROTATION') con.name = "hinge" con.target = obj - con.subtarget = mt.pelvis + con.subtarget = ex.pelvis_copy # add driver - hinge_driver_path = mt.ribcage_p.path_to_id() + '["hinge"]' - fcurve = con.driver_add("influence", 0) driver = fcurve.driver tar = driver.targets.new() @@ -311,7 +321,7 @@ def main(obj, bone_definition, base_names): tar.name = "var" tar.id_type = 'OBJECT' tar.id = obj - tar.rna_path = hinge_driver_path + tar.rna_path = ex.ribcage_copy_p.path_to_id() + '["hinge"]' mod = fcurve.modifiers[0] mod.poly_order = 1 @@ -321,7 +331,7 @@ def main(obj, bone_definition, base_names): con = ex.spine_rotate_p.constraints.new('COPY_ROTATION') con.target = obj - con.subtarget = mt.ribcage + con.subtarget = ex.ribcage_copy # ex.pelvis_p / MCH-wgt_pelvis @@ -347,29 +357,23 @@ def main(obj, bone_definition, base_names): con.target = obj con.subtarget = getattr(mt_chain, mt_chain.attr_names[-1]) - # mt.pelvis_p / rib_cage - con = mt.ribcage_p.constraints.new('COPY_LOCATION') + # ex.pelvis_copy_p / rib_cage + con = ex.ribcage_copy_p.constraints.new('COPY_LOCATION') con.target = obj - con.subtarget = mt.pelvis + con.subtarget = ex.pelvis_copy con.head_tail = 0.0 # This stores all important ID props - prop = rna_idprop_ui_prop_get(mt.ribcage_p, "hinge", create=True) - mt.ribcage_p["hinge"] = 1.0 + prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, "hinge", create=True) + ex.ribcage_copy_p["hinge"] = 1.0 prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 - prop = rna_idprop_ui_prop_get(mt.ribcage_p, "pivot_slide", create=True) - mt.ribcage_p["pivot_slide"] = 0.5 + prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, "pivot_slide", create=True) + ex.ribcage_copy_p["pivot_slide"] = 1.0 / spine_chain_len prop["soft_min"] = 1.0 / spine_chain_len prop["soft_max"] = 1.0 - for i in range(spine_chain_len - 1): - prop_name = "bend_%.2d" % (i + 1) - prop = rna_idprop_ui_prop_get(mt.ribcage_p, prop_name, create=True) - mt.ribcage_p[prop_name] = 1.0 - prop["soft_min"] = 0.0 - prop["soft_max"] = 1.0 # Create a fake connected parent/child relationship with bone location constraints # positioned at the tip. @@ -387,15 +391,31 @@ def main(obj, bone_definition, base_names): # Constrain 'inbetween' bones - - # b01/max(0.001,b01+b02+b03+b04+b05) target_names = [("b%.2d" % (i + 1)) for i in range(spine_chain_len - 1)] - expression_suffix = "/max(0.001,%s)" % "+".join(target_names) + rib_driver_path = ex.ribcage_copy_p.path_to_id() - rib_driver_path = mt.ribcage_p.path_to_id() + ex.ribcage_copy_p["bend_tot"] = 0.0 + fcurve = ex.ribcage_copy_p.driver_add('["bend_tot"]', 0) + driver = fcurve.driver + driver.type = 'SUM' + fcurve.modifiers.remove(0) # grr dont need a modifier + + for i in range(spine_chain_len - 1): + tar = driver.targets.new() + tar.name = target_names[i] + tar.id_type = 'OBJECT' + tar.id = obj + tar.rna_path = rib_driver_path + ('["bend_%.2d"]' % (i + 1)) for i in range(1, spine_chain_len): + # Add bend prop + prop_name = "bend_%.2d" % i + prop = rna_idprop_ui_prop_get(ex.ribcage_copy_p, prop_name, create=True) + ex.ribcage_copy_p[prop_name] = 1.0 + prop["soft_min"] = 0.0 + prop["soft_max"] = 1.0 + spine_p = getattr(ex_chain, ex_chain.attr_names[i] + "_p") spine_p_parent = spine_p.parent # interlaced bone @@ -410,16 +430,24 @@ def main(obj, bone_definition, base_names): fcurve = con.driver_add("influence", 0) driver = fcurve.driver driver.type = 'SCRIPTED' - # b01/max(0.001,b01+b02+b03+b04+b05) - driver.expression = target_names[i - 1] + expression_suffix + driver.expression = "bend/bend_tot" + fcurve.modifiers.remove(0) # grr dont need a modifier - for j in range(spine_chain_len - 1): - tar = driver.targets.new() - tar.name = target_names[j] - tar.id_type = 'OBJECT' - tar.id = obj - tar.rna_path = rib_driver_path + ('["bend_%.2d"]' % (j + 1)) + + # add target + tar = driver.targets.new() + tar.name = "bend_tot" + tar.id_type = 'OBJECT' + tar.id = obj + tar.rna_path = rib_driver_path + ('["bend_tot"]') + + tar = driver.targets.new() + tar.name = "bend" + tar.id_type = 'OBJECT' + tar.id = obj + tar.rna_path = rib_driver_path + ('["%s"]' % prop_name) + # original bone drivers |