diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-11 17:16:59 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-11 17:16:59 +0300 |
commit | fb28896cf78c6c7444fc959fce56cea23b7de4f5 (patch) | |
tree | 40d890e7f84b1eb2353523d71cb4f19ff9ab838b /release/scripts/modules/rigify | |
parent | fba99b627b001177590e73471f0b0f29a832bc14 (diff) |
* added an armature submenu where python defined armatures can go.
* bpy.utils.display_name(), which makes filenames and module names look nicer in menus eg... /home/me/foo_bar.py --> "Foo Bar"
* missing rna_path --> data_path renaming
Diffstat (limited to 'release/scripts/modules/rigify')
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 31 | ||||
-rw-r--r-- | release/scripts/modules/rigify/copy.py | 15 | ||||
-rw-r--r-- | release/scripts/modules/rigify/palm_curl.py | 20 |
3 files changed, 54 insertions, 12 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 5d1ec2e1e5a..33a2f4c007e 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -51,9 +51,24 @@ def submodule_func_from_type(bone_type): reload(submod) return submod, getattr(submod, func_name) + + +def submodule_types(): + import os + submodules = [] + files = os.listdir(os.path.dirname(__file__)) + for f in files: + if not f.startswith("_") and f.endswith(".py"): + submodules.append(f[:-3]) + return sorted(submodules) + def validate_rig(context, obj): + ''' + Makes no changes + only runs the metarig definitions and reports errors + ''' type_found = False for pbone in obj.pose.bones: @@ -81,6 +96,9 @@ def validate_rig(context, obj): def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True): + ''' + Main function for generating + ''' from collections import OrderedDict import rigify_utils reload(rigify_utils) @@ -307,20 +325,11 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True): obj.selected = False obj_new.selected = True - files = os.listdir(os.path.dirname(__file__)) - for f in files: - if f.startswith("_"): - continue - - if not f.endswith(".py"): - continue - - module_name = f[:-3] - + for module_name in submodule_types(): if (metarig_type and module_name != metarig_type): continue - submodule = __import__(name="%s.%s" % (__package__, module_name), fromlist=[module_name]) + submodule, func = submodule_func_from_type(module_name) metarig_template = getattr(submodule, "metarig_template", None) diff --git a/release/scripts/modules/rigify/copy.py b/release/scripts/modules/rigify/copy.py index 2be5669e5a6..21d0970234b 100644 --- a/release/scripts/modules/rigify/copy.py +++ b/release/scripts/modules/rigify/copy.py @@ -24,8 +24,21 @@ from rna_prop_ui import rna_idprop_ui_prop_get METARIG_NAMES = ("cpy",) +# note, this example is just a bone with copy property. def metarig_template(): - pass + # generated by rigify.write_meta_rig + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.active_object + arm = obj.data + bone = arm.edit_bones.new('Bone') + bone.head[:] = 0.0000, 0.0000, 0.0000 + bone.tail[:] = 0.0000, 0.0000, 1.0000 + bone.roll = 0.0000 + bone.connected = False + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['Bone'] + pbone['type'] = 'copy' def metarig_definition(obj, orig_bone_name): return [orig_bone_name] diff --git a/release/scripts/modules/rigify/palm_curl.py b/release/scripts/modules/rigify/palm_curl.py index 6c9ff516c49..867889b0084 100644 --- a/release/scripts/modules/rigify/palm_curl.py +++ b/release/scripts/modules/rigify/palm_curl.py @@ -162,6 +162,26 @@ 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 + tar = driver.targets.new() tar.name = "x" tar.id_type = 'OBJECT' |