diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-03 02:43:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-03 02:43:46 +0300 |
commit | d8d11c55d9ebdedb72ea2c2bfb5038e612529157 (patch) | |
tree | a7a94e3b635aa8e7afe279f6364266f4c94fceec | |
parent | 04d0261c37ccd28e8466312f5a2d8260c5a4c9e9 (diff) |
patch from Cessen
Adds a new set of bones to rig types which are to be used for weight paint vgroups, in some these have some more segments to account for twist. also use Aligoriths new copy transform constraint.
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 16 | ||||
-rw-r--r-- | release/scripts/modules/rigify/arm_biped_generic.py | 10 | ||||
-rw-r--r-- | release/scripts/modules/rigify/copy.py | 23 | ||||
-rw-r--r-- | release/scripts/modules/rigify/finger_curl.py | 63 | ||||
-rw-r--r-- | release/scripts/modules/rigify/leg_biped_generic.py | 11 | ||||
-rw-r--r-- | release/scripts/modules/rigify/leg_quadruped_generic.py | 14 | ||||
-rw-r--r-- | release/scripts/modules/rigify/neck_flex.py | 25 | ||||
-rw-r--r-- | release/scripts/modules/rigify/palm_curl.py | 26 | ||||
-rw-r--r-- | release/scripts/modules/rigify/spine_pivot_flex.py | 25 |
9 files changed, 175 insertions, 38 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 95ae2fed76c..6163ffbe950 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -26,6 +26,12 @@ from rna_prop_ui import rna_idprop_ui_prop_get SPECIAL_TYPES = "root", LAYER_TYPES = "main", "extra", "ik", "fk" +ORG_LAYERS = [n==31 for n in range(0,32)] +MCH_LAYERS = [n==30 for n in range(0,32)] +DEF_LAYERS = [n==29 for n in range(0,32)] + + + class RigifyError(Exception): """Exception raised for errors in the metarig. @@ -341,10 +347,14 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): layer_second_last[30] = True for bone_name, bone in arm.bones.items(): + bone.deform = False # Non DEF bones shouldn't deform if bone_name.startswith(prefix): - bone.layer = layer_last - elif bone_name.startswith("MCH"): # XXX fixme - bone.layer = layer_second_last + bone.layer = ORG_LAYERS + elif bone_name.startswith("MCH-"): # XXX fixme + bone.layer = MCH_LAYERS + elif bone_name.startswith("DEF-"): # XXX fixme + bone.layer = DEF_LAYERS + bone.deform = True layer_tot[:] = [max(lay) for lay in zip(layer_tot, bone.layer)] diff --git a/release/scripts/modules/rigify/arm_biped_generic.py b/release/scripts/modules/rigify/arm_biped_generic.py index 3acd812cf4a..092a047f0da 100644 --- a/release/scripts/modules/rigify/arm_biped_generic.py +++ b/release/scripts/modules/rigify/arm_biped_generic.py @@ -306,6 +306,12 @@ def deform(obj, definitions, base_names, options): farm1.tail = center farm2.head = center + # Create twist bone + twist = copy_bone_simple(obj.data, definitions[2], "MCH-arm_twist") + twist.connected = False + twist.parent = obj.data.edit_bones[definitions[3]] + twist.length /= 2 + # Create hand bone hand = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True) @@ -314,6 +320,7 @@ def deform(obj, definitions, base_names, options): uarm2_name = uarm2.name farm1_name = farm1.name farm2_name = farm2.name + twist_name = twist.name hand_name = hand.name # Leave edit mode @@ -324,6 +331,7 @@ def deform(obj, definitions, base_names, options): uarm2 = obj.pose.bones[uarm2_name] farm1 = obj.pose.bones[farm1_name] farm2 = obj.pose.bones[farm2_name] + twist = obj.pose.bones[twist_name] hand = obj.pose.bones[hand_name] # Upper arm constraints @@ -346,7 +354,7 @@ def deform(obj, definitions, base_names, options): con = farm2.constraints.new('COPY_ROTATION') con.name = "copy_rot" con.target = obj - con.subtarget = definitions[3] + con.subtarget = twist.name con = farm2.constraints.new('DAMPED_TRACK') con.name = "trackto" diff --git a/release/scripts/modules/rigify/copy.py b/release/scripts/modules/rigify/copy.py index 7184f49d48d..a84487e8e21 100644 --- a/release/scripts/modules/rigify/copy.py +++ b/release/scripts/modules/rigify/copy.py @@ -61,22 +61,11 @@ def deform(obj, definitions, base_names, options): bone = obj.pose.bones[bone_name] # Constrain to the original bone - # XXX. Todo, is this needed if the bone is connected to its parent? - con = bone.constraints.new('COPY_LOCATION') + con = bone.constraints.new('COPY_TRANSFORMS') con.name = "copy_loc" con.target = obj con.subtarget = definitions[0] - con = bone.constraints.new('COPY_ROTATION') - con.name = "copy_rot" - con.target = obj - con.subtarget = definitions[0] - - con = bone.constraints.new('COPY_SCALE') - con.name = "copy_scale" - con.target = obj - con.subtarget = definitions[0] - return (bone_name,) @@ -94,18 +83,10 @@ def main(obj, bone_definition, base_names, options): cp.update() mt.update() - if not cp.cpy_b.connected: - con = mt.cpy_p.constraints.new('COPY_LOCATION') - con.target = obj - con.subtarget = cp.cpy - - con = mt.cpy_p.constraints.new('COPY_ROTATION') + con = mt.cpy_p.constraints.new('COPY_TRANSFORMS') 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 diff --git a/release/scripts/modules/rigify/finger_curl.py b/release/scripts/modules/rigify/finger_curl.py index a4688ee8b5b..7eb1588efd6 100644 --- a/release/scripts/modules/rigify/finger_curl.py +++ b/release/scripts/modules/rigify/finger_curl.py @@ -86,6 +86,68 @@ def metarig_definition(obj, orig_bone_name): return bone_definition +def deform(obj, definitions, base_names, options): + """ Creates the deform rig. + """ + bpy.ops.object.mode_set(mode='EDIT') + + # Create base digit bones: two bones, each half of the base digit. + f1a = copy_bone_simple(obj.data, definitions[0], "DEF-%s.01" % base_names[definitions[0]], parent=True) + f1b = copy_bone_simple(obj.data, definitions[0], "DEF-%s.02" % base_names[definitions[0]], parent=True) + f1a.connected = False + f1b.connected = False + f1b.parent = f1a + center = f1a.center + f1a.tail = center + f1b.head = center + + # Create the other deform bones. + f2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s" % base_names[definitions[1]], parent=True) + f3 = copy_bone_simple(obj.data, definitions[2], "DEF-%s" % base_names[definitions[2]], parent=True) + + # Store names before leaving edit mode + f1a_name = f1a.name + f1b_name = f1b.name + f2_name = f2.name + f3_name = f3.name + + # Leave edit mode + bpy.ops.object.mode_set(mode='OBJECT') + + # Get the pose bones + f1a = obj.pose.bones[f1a_name] + f1b = obj.pose.bones[f1b_name] + f2 = obj.pose.bones[f2_name] + f3 = obj.pose.bones[f3_name] + + # Constrain the base digit's bones + con = f1a.constraints.new('DAMPED_TRACK') + con.name = "trackto" + con.target = obj + con.subtarget = definitions[1] + + con = f1a.constraints.new('COPY_SCALE') + con.name = "copy_scale" + con.target = obj + con.subtarget = definitions[0] + + con = f1b.constraints.new('COPY_ROTATION') + con.name = "copy_rot" + con.target = obj + con.subtarget = definitions[0] + + # Constrain the other digit's bones + con = f2.constraints.new('COPY_TRANSFORMS') + con.name = "copy_transforms" + con.target = obj + con.subtarget = definitions[1] + + con = f3.constraints.new('COPY_TRANSFORMS') + con.name = "copy_transforms" + con.target = obj + con.subtarget = definitions[2] + + def main(obj, bone_definition, base_names, options): # *** EDITMODE @@ -139,6 +201,7 @@ def main(obj, bone_definition, base_names, options): del control_ebone + deform(obj, bone_definition, base_names, options) # *** POSEMODE bpy.ops.object.mode_set(mode='OBJECT') diff --git a/release/scripts/modules/rigify/leg_biped_generic.py b/release/scripts/modules/rigify/leg_biped_generic.py index f7501d4ad6f..f2d59a96032 100644 --- a/release/scripts/modules/rigify/leg_biped_generic.py +++ b/release/scripts/modules/rigify/leg_biped_generic.py @@ -271,8 +271,7 @@ def ik(obj, bone_definition, base_names, options): bpy.ops.object.mode_set(mode='EDIT') - #return ((None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None), (ik.foot, ik.knee_target)) # Cessen ??? - return (None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None) + return (None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None, ik.foot) def fk(obj, bone_definition, base_names, options): @@ -364,7 +363,7 @@ def fk(obj, bone_definition, base_names, options): bpy.ops.object.mode_set(mode='EDIT') # dont blend the hips or heel - return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None + return (None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None, None) def deform(obj, definitions, base_names, options): @@ -462,7 +461,7 @@ def deform(obj, definitions, base_names, options): con.subtarget = definitions[4] bpy.ops.object.mode_set(mode='EDIT') - return (uleg1_name, uleg2_name, lleg1_name, lleg2_name, foot_name, toe_name) + return (uleg1_name, uleg2_name, lleg1_name, lleg2_name, foot_name, toe_name, None) def main(obj, bone_definition, base_names, options): @@ -471,5 +470,5 @@ def main(obj, bone_definition, base_names, options): deform(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') - #blend_bone_list(obj, bone_definition, bones_fk, bones_ik[0], target_bone=bones_ik[1][0], target_prop="ik", blend_default=0.0) # Cessen ??? - blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_prop="ik", blend_default=0.0) + blend_bone_list(obj, bone_definition + [None], bones_fk, bones_ik, target_bone=bones_ik[6], target_prop="ik", blend_default=0.0) + diff --git a/release/scripts/modules/rigify/leg_quadruped_generic.py b/release/scripts/modules/rigify/leg_quadruped_generic.py index 5f8f274c963..f63c7c4ddd5 100644 --- a/release/scripts/modules/rigify/leg_quadruped_generic.py +++ b/release/scripts/modules/rigify/leg_quadruped_generic.py @@ -119,7 +119,7 @@ def ik(obj, bone_definition, base_names, options): ik_chain.thigh_e.parent = mt.hips_e ik_chain.foot_e.parent = None - ik_chain.rename("foot", ik_chain.foot + "_ik") + ik_chain.rename("foot", get_base_name(ik_chain.foot) + "_ik" + get_side_name(ik_chain.foot)) # keep the foot_ik as the parent ik_chain.toe_e.connected = False @@ -130,14 +130,14 @@ def ik(obj, bone_definition, base_names, options): # children of ik_foot ik = bone_class_instance(obj, ["foot", "foot_roll", "foot_roll_01", "foot_roll_02", "knee_target", "foot_target"]) - ik.knee_target = add_pole_target_bone(obj, mt_chain.shin, "knee_target") #XXX - pick a better name + ik.knee_target = add_pole_target_bone(obj, mt_chain.shin, "knee_target" + get_side_name(base_names[mt_chain.foot])) #XXX - pick a better name ik.update() ik.knee_target_e.parent = mt.hips_e # foot roll is an interesting one! # plot a vector from the toe bones head, bactwards to the length of the foot # then align it with the foot but reverse direction. - ik.foot_roll_e = copy_bone_simple(arm, mt_chain.toe, base_names[mt_chain.foot] + "_roll") + ik.foot_roll_e = copy_bone_simple(arm, mt_chain.toe, get_base_name(base_names[mt_chain.foot]) + "_roll" + get_side_name(base_names[mt_chain.foot])) ik.foot_roll = ik.foot_roll_e.name ik.foot_roll_e.parent = ik_chain.foot_e ik.foot_roll_e.translate(- (mt_chain.toe_e.vector.normalize() * mt_chain.foot_e.length)) @@ -174,19 +174,19 @@ def ik(obj, bone_definition, base_names, options): ik_chain.update() # simple constraining of orig bones - con = mt_chain.thigh_p.constraints.new('COPY_ROTATION') + con = mt_chain.thigh_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = ik_chain.thigh - con = mt_chain.shin_p.constraints.new('COPY_ROTATION') + con = mt_chain.shin_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = ik_chain.shin - con = mt_chain.foot_p.constraints.new('COPY_ROTATION') + con = mt_chain.foot_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = ik.foot_roll_02 - con = mt_chain.toe_p.constraints.new('COPY_ROTATION') + con = mt_chain.toe_p.constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = ik_chain.toe diff --git a/release/scripts/modules/rigify/neck_flex.py b/release/scripts/modules/rigify/neck_flex.py index c52230ed30a..7b5b8c6bacb 100644 --- a/release/scripts/modules/rigify/neck_flex.py +++ b/release/scripts/modules/rigify/neck_flex.py @@ -100,6 +100,30 @@ def metarig_definition(obj, orig_bone_name): return bone_definition +def deform(obj, definitions, base_names, options): + for org_bone_name in definitions[2:]: + bpy.ops.object.mode_set(mode='EDIT') + + # Create deform bone. + bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) + + # Store name before leaving edit mode + bone_name = bone.name + + # Leave edit mode + bpy.ops.object.mode_set(mode='OBJECT') + + # Get the pose bone + bone = obj.pose.bones[bone_name] + + # Constrain to the original bone + # XXX. Todo, is this needed if the bone is connected to its parent? + con = bone.constraints.new('COPY_TRANSFORMS') + con.name = "copy_loc" + con.target = obj + con.subtarget = org_bone_name + + def main(obj, bone_definition, base_names, options): from Mathutils import Vector @@ -180,6 +204,7 @@ def main(obj, bone_definition, base_names, options): else: neck_e_parent.parent = orig_parent + deform(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') diff --git a/release/scripts/modules/rigify/palm_curl.py b/release/scripts/modules/rigify/palm_curl.py index f2ddcca6d59..48931079816 100644 --- a/release/scripts/modules/rigify/palm_curl.py +++ b/release/scripts/modules/rigify/palm_curl.py @@ -98,6 +98,30 @@ def metarig_definition(obj, orig_bone_name): return [palm_parent.name] + bone_definition +def deform(obj, definitions, base_names, options): + for org_bone_name in definitions[1:]: + bpy.ops.object.mode_set(mode='EDIT') + + # Create deform bone. + bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) + + # Store name before leaving edit mode + bone_name = bone.name + + # Leave edit mode + bpy.ops.object.mode_set(mode='OBJECT') + + # Get the pose bone + bone = obj.pose.bones[bone_name] + + # Constrain to the original bone + # XXX. Todo, is this needed if the bone is connected to its parent? + con = bone.constraints.new('COPY_TRANSFORMS') + con.name = "copy_loc" + con.target = obj + con.subtarget = org_bone_name + + def main(obj, bone_definition, base_names, options): arm = obj.data @@ -117,6 +141,8 @@ def main(obj, bone_definition, base_names, options): offset = (pinky_ebone.head - ring_ebone.head) control_ebone.translate(offset) + + deform(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') diff --git a/release/scripts/modules/rigify/spine_pivot_flex.py b/release/scripts/modules/rigify/spine_pivot_flex.py index 895a5d854c0..a8ba71d1fe6 100644 --- a/release/scripts/modules/rigify/spine_pivot_flex.py +++ b/release/scripts/modules/rigify/spine_pivot_flex.py @@ -122,6 +122,30 @@ def fk(*args): main(*args) +def deform(obj, definitions, base_names, options): + for org_bone_name in definitions[2:]: + bpy.ops.object.mode_set(mode='EDIT') + + # Create deform bone. + bone = copy_bone_simple(obj.data, org_bone_name, "DEF-%s" % base_names[org_bone_name], parent=True) + + # Store name before leaving edit mode + bone_name = bone.name + + # Leave edit mode + bpy.ops.object.mode_set(mode='OBJECT') + + # Get the pose bone + bone = obj.pose.bones[bone_name] + + # Constrain to the original bone + # XXX. Todo, is this needed if the bone is connected to its parent? + con = bone.constraints.new('COPY_TRANSFORMS') + con.name = "copy_loc" + con.target = obj + con.subtarget = org_bone_name + + def main(obj, bone_definition, base_names, options): from Mathutils import Vector, RotationMatrix from math import radians, pi @@ -269,6 +293,7 @@ def main(obj, bone_definition, base_names, options): spine_e.roll += pi # 180d roll del spine_e + deform(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') |