diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-11 19:30:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-11 19:30:27 +0300 |
commit | 026364dcca6539c4e3ad6a5010cba81e61638ef2 (patch) | |
tree | 54488973264d95add2fd491735076d82b4427a1e /release/scripts/modules/rigify | |
parent | ab18fe02c458a88b4a010c23f0703ab999b5a9f8 (diff) |
rigify
* optional default blend argument, use for better leg & arm defaults
* way to define arbitrary options for bones that can then be passed to the generator function, only used to set elbow target parent at the moment.
Diffstat (limited to 'release/scripts/modules/rigify')
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 56 | ||||
-rw-r--r-- | release/scripts/modules/rigify/arm_biped_generic.py | 26 | ||||
-rw-r--r-- | release/scripts/modules/rigify/copy.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rigify/delta.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rigify/finger_curl.py | 20 | ||||
-rw-r--r-- | release/scripts/modules/rigify/leg_biped_generic.py | 12 | ||||
-rw-r--r-- | release/scripts/modules/rigify/neck_flex.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rigify/palm_curl.py | 36 | ||||
-rw-r--r-- | release/scripts/modules/rigify/spine_pivot_flex.py | 6 |
9 files changed, 92 insertions, 70 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 33a2f4c007e..6ec90015d61 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -41,19 +41,19 @@ def submodule_func_from_type(bone_type): if len(type_pair) == 1: type_pair = type_pair[0], "main" - submod_name, func_name = type_pair + type_name, func_name = type_pair # from rigify import leg try: - submod = __import__(name="%s.%s" % (__package__, submod_name), fromlist=[submod_name]) + submod = __import__(name="%s.%s" % (__package__, type_name), fromlist=[type_name]) except ImportError: - raise RigifyError("python module for type '%s' not found" % submod_name) + raise RigifyError("python module for type '%s' not found" % type_name) reload(submod) - return submod, getattr(submod, func_name) + return type_name, submod, getattr(submod, func_name) -def submodule_types(): +def get_submodule_types(): import os submodules = [] files = os.listdir(os.path.dirname(__file__)) @@ -63,6 +63,17 @@ def submodule_types(): return sorted(submodules) +def get_bone_type_options(pbone, type_name): + options = {} + bone_name = pbone.name + for key, value in pbone.items(): + key_pair = key.split(".") + if key_pair[0] == type_name: + if len(key_pair) != 2: + raise RigifyError("option error for bone '%s', property name was not a pair '%s'" % (bone_name, key_pair)) + options[key_pair[1]] = value + + return options def validate_rig(context, obj): ''' @@ -84,11 +95,13 @@ def validate_rig(context, obj): if bone_type.split(".")[0] in SPECIAL_TYPES: continue - submod, type_func = submodule_func_from_type(bone_type) + type_name, submod, type_func = submodule_func_from_type(bone_type) reload(submod) submod.metarig_definition(obj, bone_name) type_found = True - + + get_bone_type_options(pbone, bone_type) + # missing, - check for duplicate root bone. if not type_found: @@ -162,6 +175,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): # ...needed so we can override the root parent bone_genesis = {} + # inspect all bones and assign their definitions before modifying for pbone in obj.pose.bones: bone_name = pbone.name @@ -181,18 +195,17 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): bone_type_list[:] = [] for bone_type in bone_type_list: - submod, type_func = submodule_func_from_type(bone_type) + type_name, submod, type_func = submodule_func_from_type(bone_type) reload(submod) - submod_name = submod.__name__ bone_def_dict = bone_definitions.setdefault(bone_name, {}) # Only calculate bone definitions once - if submod_name not in bone_def_dict: - bone_def_dict[submod_name] = submod.metarig_definition(obj, bone_name) + if type_name not in bone_def_dict: + bone_def_dict[type_name] = submod.metarig_definition(obj, bone_name) bone_typeinfo = bone_typeinfos.setdefault(bone_name, []) - bone_typeinfo.append((submod_name, type_func)) + bone_typeinfo.append((type_name, type_func)) # sort bones, not needed but gives more pradictable execution which may be useful in rare cases @@ -216,16 +229,17 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): bone_names_pre = set([bone.name for bone in arm.bones]) - for submod_name, type_func in bone_typeinfos[bone_name]: + for type_name, type_func in bone_typeinfos[bone_name]: # this bones definition of the current typeinfo - definition = bone_def_dict[submod_name] + definition = bone_def_dict[type_name] + options = get_bone_type_options(pbone, type_name) bpy.ops.object.mode_set(mode='EDIT') - ret = type_func(obj, definition, base_names) + ret = type_func(obj, definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') if ret: - result_submod = results.setdefault(submod_name, []) + result_submod = results.setdefault(type_name, []) if result_submod and len(result_submod[-1]) != len(ret): raise Exception("bone lists not compatible: %s, %s" % (result_submod[-1], ret)) @@ -234,7 +248,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): for result_submod in results.values(): # blend 2 chains - definition = bone_def_dict[submod_name] + definition = bone_def_dict[type_name] if len(result_submod) == 2: blend_bone_list(obj, definition, result_submod[0], result_submod[1], target_bone=bone_name) @@ -325,11 +339,15 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True): obj.selected = False obj_new.selected = True - for module_name in submodule_types(): + for module_name in get_submodule_types(): if (metarig_type and module_name != metarig_type): continue + + # XXX workaround!, problem with updating the pose matrix. + if module_name=="delta": + continue - submodule, func = submodule_func_from_type(module_name) + type_name, submodule, func = submodule_func_from_type(module_name) metarig_template = getattr(submodule, "metarig_template", None) diff --git a/release/scripts/modules/rigify/arm_biped_generic.py b/release/scripts/modules/rigify/arm_biped_generic.py index e22857852ee..a9b5e62775e 100644 --- a/release/scripts/modules/rigify/arm_biped_generic.py +++ b/release/scripts/modules/rigify/arm_biped_generic.py @@ -93,7 +93,10 @@ def metarig_definition(obj, orig_bone_name): return mt.names() -def ik(obj, definitions, base_names): +def ik(obj, definitions, base_names, options): + print(options) + arm = obj.data + mt = bone_class_instance(obj, METARIG_NAMES) mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions mt.update() @@ -117,6 +120,17 @@ def ik(obj, definitions, base_names): ik.update() ik.pole_e.local_location = False + # option: elbow_parent + elbow_parent_name = options.get("elbow_parent", "") + + if elbow_parent_name: + try: + elbow_parent_e = arm.edit_bones[elbow_parent_name] + except: + # TODO, old/new parent mapping + raise RigifyError("parent bone from property 'arm_biped_generic.elbow_parent' not found '%s'" % elbow_parent_name) + ik.pole_e.parent = elbow_parent_e + # update bones after this! ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand]) ik.pole_vis = add_stretch_to(obj, mt.forearm, ik.pole, "VIS-%s_ik" % base_names[mt.forearm]) @@ -162,7 +176,7 @@ def ik(obj, definitions, base_names): return [None] + ik_chain.names() -def fk(obj, definitions, base_names): +def fk(obj, definitions, base_names, options): arm = obj.data @@ -254,9 +268,9 @@ def fk(obj, definitions, base_names): return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand -def main(obj, bone_definition, base_names): - bones_ik = ik(obj, bone_definition, base_names) - bones_fk = fk(obj, bone_definition, base_names) +def main(obj, bone_definition, base_names, options): + bones_ik = ik(obj, bone_definition, base_names, options) + bones_fk = fk(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') - blend_bone_list(obj, bone_definition, bones_ik, bones_fk, target_bone=bone_definition[1]) + blend_bone_list(obj, bone_definition, bones_ik, bones_fk, target_bone=bone_definition[1], blend_default=1.0) diff --git a/release/scripts/modules/rigify/copy.py b/release/scripts/modules/rigify/copy.py index 21d0970234b..70086b70907 100644 --- a/release/scripts/modules/rigify/copy.py +++ b/release/scripts/modules/rigify/copy.py @@ -44,7 +44,7 @@ def metarig_definition(obj, orig_bone_name): return [orig_bone_name] -def main(obj, bone_definition, base_names): +def main(obj, bone_definition, base_names, options): arm = obj.data mt = bone_class_instance(obj, METARIG_NAMES) mt.cpy = bone_definition[0] diff --git a/release/scripts/modules/rigify/delta.py b/release/scripts/modules/rigify/delta.py index 261e2b22479..4e1d8ce4571 100644 --- a/release/scripts/modules/rigify/delta.py +++ b/release/scripts/modules/rigify/delta.py @@ -75,7 +75,7 @@ def metarig_definition(obj, orig_bone_name): return bone_definition -def main(obj, bone_definition, base_names): +def main(obj, bone_definition, base_names, options): ''' Use this bone to define a delta thats applied to its child in pose mode. ''' diff --git a/release/scripts/modules/rigify/finger_curl.py b/release/scripts/modules/rigify/finger_curl.py index 7f21eecd7d3..d260bb1a67a 100644 --- a/release/scripts/modules/rigify/finger_curl.py +++ b/release/scripts/modules/rigify/finger_curl.py @@ -20,7 +20,7 @@ import bpy from rigify import RigifyError -from rigify_utils import copy_bone_simple, get_side_name, get_base_name, EMPTY_LAYER +from rigify_utils import copy_bone_simple, get_side_name, get_base_name from rna_prop_ui import rna_idprop_ui_prop_get from functools import reduce @@ -85,21 +85,17 @@ def metarig_definition(obj, orig_bone_name): return bone_definition -def main(obj, bone_definition, base_names): - +def main(obj, bone_definition, base_names, options): # *** EDITMODE # get assosiated data arm = obj.data - orig_pbone = obj.pose.bones[bone_definition[0]] orig_ebone = arm.edit_bones[bone_definition[0]] obj.animation_data_create() # needed if its a new armature with no keys - arm.layer[0] = arm.layer[8] = True - - children = orig_pbone.children_recursive - tot_len = reduce(lambda f, pbone: f + pbone.bone.length, children, orig_pbone.bone.length) + children = orig_ebone.children_recursive + tot_len = reduce(lambda f, ebone: f + ebone.length, children, orig_ebone.length) # FIXME, the line below is far too arbitrary base_name = base_names[bone_definition[0]].rsplit(".", 2)[0] @@ -116,12 +112,7 @@ def main(obj, bone_definition, base_names): # now add bones inbetween this and its children recursively # switching modes so store names only! - children = [pbone.name for pbone in children] - - # set an alternate layer for driver bones - other_layer = EMPTY_LAYER[:] - other_layer[8] = True - + children = [ebone.name for ebone in children] driver_bone_pairs = [] @@ -134,7 +125,6 @@ def main(obj, bone_definition, base_names): driver_ebone = copy_bone_simple(arm, child_ebone.name, driver_bone_name) driver_ebone.length *= 0.5 - driver_ebone.layer = other_layer # Insert driver_ebone in the chain without connected parents driver_ebone.connected = False diff --git a/release/scripts/modules/rigify/leg_biped_generic.py b/release/scripts/modules/rigify/leg_biped_generic.py index 65fde79da6e..4ce7352539a 100644 --- a/release/scripts/modules/rigify/leg_biped_generic.py +++ b/release/scripts/modules/rigify/leg_biped_generic.py @@ -125,7 +125,7 @@ def metarig_definition(obj, orig_bone_name): return bone_definition -def ik(obj, bone_definition, base_names): +def ik(obj, bone_definition, base_names, options): arm = obj.data # setup the existing bones @@ -274,7 +274,7 @@ def ik(obj, bone_definition, base_names): return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None -def fk(obj, bone_definition, base_names): +def fk(obj, bone_definition, base_names, options): from Mathutils import Vector arm = obj.data @@ -354,9 +354,9 @@ def fk(obj, bone_definition, base_names): return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None -def main(obj, bone_definition, base_names): - bones_ik = ik(obj, bone_definition, base_names) - bones_fk = fk(obj, bone_definition, base_names) +def main(obj, bone_definition, base_names, options): + bones_ik = ik(obj, bone_definition, base_names, options) + bones_fk = fk(obj, bone_definition, base_names, options) bpy.ops.object.mode_set(mode='OBJECT') - blend_bone_list(obj, bone_definition, bones_ik, bones_fk, target_bone=bone_definition[1]) + blend_bone_list(obj, bone_definition, bones_ik, bones_fk, target_bone=bone_definition[1], blend_default=0.0) diff --git a/release/scripts/modules/rigify/neck_flex.py b/release/scripts/modules/rigify/neck_flex.py index 9bb852b25b5..15efc2a6985 100644 --- a/release/scripts/modules/rigify/neck_flex.py +++ b/release/scripts/modules/rigify/neck_flex.py @@ -100,7 +100,7 @@ def metarig_definition(obj, orig_bone_name): return bone_definition -def main(obj, bone_definition, base_names): +def main(obj, bone_definition, base_names, options): from Mathutils import Vector arm = obj.data diff --git a/release/scripts/modules/rigify/palm_curl.py b/release/scripts/modules/rigify/palm_curl.py index 867889b0084..4ad0cfe3675 100644 --- a/release/scripts/modules/rigify/palm_curl.py +++ b/release/scripts/modules/rigify/palm_curl.py @@ -96,7 +96,7 @@ def metarig_definition(obj, orig_bone_name): return [palm_parent.name] + bone_definition -def main(obj, bone_definition, base_names): +def main(obj, bone_definition, base_names, options): arm = obj.data children = bone_definition[1:] @@ -163,22 +163,6 @@ def main(obj, bone_definition, base_names): driver = driver_fcurves[2].driver driver.expression = "(1.0-cos(x))-s" - def x_direction(): - # NOTE: the direction of the Z rotation depends on which side the palm is on. - # we could do a simple side-of-x test but better to work out the direction - # the hand is facing. - from Mathutils import Vector, AngleBetweenVecs - from math import degrees - child_pbone_01 = obj.pose.bones[children[0]] - child_pbone_02 = obj.pose.bones[children[1]] - - rel_vec = child_pbone_01.head - child_pbone_02.head - x_vec = child_pbone_01.matrix.rotationPart() * Vector(1.0, 0.0, 0.0) - return degrees(AngleBetweenVecs(rel_vec, x_vec)) > 90.0 - - if x_direction(): # flip - driver.expression = "-(%s)" % driver.expression - for fcurve in driver_fcurves: fcurve.modifiers.remove(0) # grr dont need a modifier @@ -229,5 +213,23 @@ def main(obj, bone_definition, base_names): child_pbone = obj.pose.bones[children[-1]] child_pbone.rotation_mode = 'QUATERNION' + # fix at the end since there is some trouble with tx info not being updated otherwise + def x_direction(): + # NOTE: the direction of the Z rotation depends on which side the palm is on. + # we could do a simple side-of-x test but better to work out the direction + # the hand is facing. + from Mathutils import Vector, AngleBetweenVecs + from math import degrees + child_pbone_01 = obj.pose.bones[children[0]].bone + child_pbone_02 = obj.pose.bones[children[1]].bone + + rel_vec = child_pbone_01.head - child_pbone_02.head + x_vec = child_pbone_01.matrix.rotationPart() * Vector(1.0, 0.0, 0.0) + print(rel_vec, x_vec) + return degrees(AngleBetweenVecs(rel_vec, x_vec)) > 90.0 + + if x_direction(): # flip + driver.expression = "-(%s)" % driver.expression + # no blending the result of this return None diff --git a/release/scripts/modules/rigify/spine_pivot_flex.py b/release/scripts/modules/rigify/spine_pivot_flex.py index beeb5c68b7c..f2608732c37 100644 --- a/release/scripts/modules/rigify/spine_pivot_flex.py +++ b/release/scripts/modules/rigify/spine_pivot_flex.py @@ -121,7 +121,7 @@ def fk(*args): main(*args) -def main(obj, bone_definition, base_names): +def main(obj, bone_definition, base_names, options): from Mathutils import Vector, RotationMatrix from math import radians, pi @@ -155,11 +155,9 @@ def main(obj, bone_definition, base_names): ex.ribcage_hinge = ex.ribcage_hinge_e.name ex.ribcage_hinge_e.translate(Vector(0.0, spine_chain_segment_length / 4.0, 0.0)) - ex.spine_rotate_e = copy_bone_simple(arm, mt.pelvis, "MCH-%s_rotate" % spine_chain_basename) + ex.spine_rotate_e = copy_bone_simple(arm, mt.ribcage, "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.connected = False ex.spine_rotate_e.parent = ex.pelvis_copy_e |