diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-02 14:55:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-02 14:55:47 +0300 |
commit | 2bf618368a2181319e5d47b97c60417223f84893 (patch) | |
tree | 689d4af865d687f3eb662faa087353ac7d880c58 /release | |
parent | 927b976a88a836c94651b07210f0d635d33500ef (diff) |
- include example input rigs for each autorig type, running metarig_template() in each submodule generates the armature and pose bone ID properties.
- rigify.write_meta_rig() exports rigs as python scripts
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 60 | ||||
-rw-r--r-- | release/scripts/modules/rigify/arm.py | 33 | ||||
-rw-r--r-- | release/scripts/modules/rigify/finger.py | 28 | ||||
-rw-r--r-- | release/scripts/modules/rigify/neck.py | 51 | ||||
-rw-r--r-- | release/scripts/modules/rigify/palm.py | 52 | ||||
-rw-r--r-- | release/scripts/modules/rigify/spine.py | 64 |
6 files changed, 288 insertions, 0 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index a0b5c721b2a..8c0643769c3 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -231,5 +231,65 @@ def generate_rig(context, ob): context.user_preferences.edit.global_undo = global_undo + +def write_meta_rig(obj, func_name="metarig_template"): + ''' Must be in editmode + ''' + code = [] + + code.append("def %s():" % func_name) + + bpy.ops.object.mode_set(mode='EDIT') + code.append(" bpy.ops.object.mode_set(mode='EDIT')") + + code.append(" obj = bpy.context.object") + code.append(" arm = obj.data") + + arm = obj.data + # write parents first + bones = [(len(bone.parent_recursive), bone.name) for bone in arm.edit_bones] + bones.sort(key=lambda item: item[0]) + bones = [item[1] for item in bones] + + + + for bone_name in bones: + bone = arm.edit_bones[bone_name] + code.append(" bone = arm.edit_bones.new('%s')" % bone.name) + code.append(" bone.head[:] = %.4f, %.4f, %.4f" % bone.head.toTuple(4)) + code.append(" bone.tail[:] = %.4f, %.4f, %.4f" % bone.tail.toTuple(4)) + code.append(" bone.roll = %.4f" % bone.roll) + code.append(" bone.connected = %s" % str(bone.connected)) + if bone.parent: + code.append(" bone.parent = arm.edit_bones['%s']" % bone.parent.name) + + bpy.ops.object.mode_set(mode='OBJECT') + code.append("") + code.append(" bpy.ops.object.mode_set(mode='OBJECT')") + + for bone_name in bones: + pbone = obj.pose.bones[bone_name] + pbone_written = False + + # Only 1 level of props, simple types supported + for key, value in pbone.items(): + if key.startswith("_"): + continue + + if type(value) not in (float, str, int): + print("Unsupported ID Prop:", str((key, value))) + continue + + if type(value) == str: + value = "'" + value + "'" + + if not pbone_written: # only write bones we need + code.append(" pbone = obj.pose.bones['%s']" % bone_name) + + code.append(" pbone['%s'] = %s" % (key, value)) + + return "\n".join(code) + + if __name__ == "__main__": generate_rig(bpy.context, bpy.context.object) diff --git a/release/scripts/modules/rigify/arm.py b/release/scripts/modules/rigify/arm.py index d2c9208d4ff..36217ed5247 100644 --- a/release/scripts/modules/rigify/arm.py +++ b/release/scripts/modules/rigify/arm.py @@ -21,6 +21,39 @@ from rigify import bone_class_instance, copy_bone_simple, add_pole_target_bone, from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get +def metarig_template(): + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.object + arm = obj.data + bone = arm.edit_bones.new('shoulder') + bone.head[:] = 0.0000, -0.4515, 0.0000 + bone.tail[:] = 1.0000, -0.0794, 0.3540 + bone.roll = -0.2227 + bone.connected = False + bone = arm.edit_bones.new('upper_arm') + bone.head[:] = 1.1319, -0.0808, -0.0101 + bone.tail[:] = 3.0319, 0.2191, -0.1101 + bone.roll = 1.6152 + bone.connected = False + bone.parent = arm.edit_bones['shoulder'] + bone = arm.edit_bones.new('forearm') + bone.head[:] = 3.0319, 0.2191, -0.1101 + bone.tail[:] = 4.8319, -0.0809, -0.0242 + bone.roll = 1.5153 + bone.connected = True + bone.parent = arm.edit_bones['upper_arm'] + bone = arm.edit_bones.new('hand') + bone.head[:] = 4.8319, -0.0809, -0.0242 + bone.tail[:] = 5.7590, -0.1553, -0.1392 + bone.roll = -3.0083 + bone.connected = True + bone.parent = arm.edit_bones['forearm'] + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['upper_arm'] + pbone['type'] = 'arm' + + def main(obj, orig_bone_name): """ the bone with the 'arm' property is the upper arm, this assumes a chain as follows. diff --git a/release/scripts/modules/rigify/finger.py b/release/scripts/modules/rigify/finger.py index c71473dca8e..a9040830e4e 100644 --- a/release/scripts/modules/rigify/finger.py +++ b/release/scripts/modules/rigify/finger.py @@ -21,6 +21,34 @@ from rigify import get_bone_data, empty_layer from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get from functools import reduce + +def metarig_template(): + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.object + arm = obj.data + bone = arm.edit_bones.new('finger.01') + bone.head[:] = 0.0000, 0.0000, 0.0000 + bone.tail[:] = 0.8788, -0.4584, -0.1327 + bone.roll = -2.8722 + bone.connected = False + bone = arm.edit_bones.new('finger.02') + bone.head[:] = 0.8788, -0.4584, -0.1327 + bone.tail[:] = 1.7483, -0.9059, -0.3643 + bone.roll = -2.7099 + bone.connected = True + bone.parent = arm.edit_bones['finger.01'] + bone = arm.edit_bones.new('finger.03') + bone.head[:] = 1.7483, -0.9059, -0.3643 + bone.tail[:] = 2.2478, -1.1483, -0.7408 + bone.roll = -2.1709 + bone.connected = True + bone.parent = arm.edit_bones['finger.02'] + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['finger.01'] + pbone['type'] = 'finger' + + def main(obj, orig_bone_name): # *** EDITMODE diff --git a/release/scripts/modules/rigify/neck.py b/release/scripts/modules/rigify/neck.py index c9c732b5df6..524de6e2f3d 100644 --- a/release/scripts/modules/rigify/neck.py +++ b/release/scripts/modules/rigify/neck.py @@ -21,6 +21,57 @@ from rigify import bone_class_instance, copy_bone_simple from rna_prop_ui import rna_idprop_ui_prop_get +def metarig_template(): + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.object + arm = obj.data + bone = arm.edit_bones.new('body') + bone.head[:] = -0.0000, -0.2771, -1.3345 + bone.tail[:] = -0.0000, -0.1708, -0.3984 + bone.roll = 0.0000 + bone.connected = False + bone = arm.edit_bones.new('head') + bone.head[:] = -0.0000, -0.1708, -0.1984 + bone.tail[:] = 0.0000, -0.1708, 1.6016 + bone.roll = -0.0000 + bone.connected = False + bone.parent = arm.edit_bones['body'] + bone = arm.edit_bones.new('neck.01') + bone.head[:] = 0.0000, -0.1708, -0.1984 + bone.tail[:] = -0.0000, -0.0994, 0.1470 + bone.roll = -0.0000 + bone.connected = False + bone.parent = arm.edit_bones['head'] + bone = arm.edit_bones.new('neck.02') + bone.head[:] = -0.0000, -0.0994, 0.1470 + bone.tail[:] = 0.0000, -0.2428, 0.5162 + bone.roll = -0.0000 + bone.connected = True + bone.parent = arm.edit_bones['neck.01'] + bone = arm.edit_bones.new('neck.03') + bone.head[:] = 0.0000, -0.2428, 0.5162 + bone.tail[:] = 0.0000, -0.4190, 0.8722 + bone.roll = -0.0000 + bone.connected = True + bone.parent = arm.edit_bones['neck.02'] + bone = arm.edit_bones.new('neck.04') + bone.head[:] = 0.0000, -0.4190, 0.8722 + bone.tail[:] = 0.0000, -0.5111, 1.1956 + bone.roll = 0.0000 + bone.connected = True + bone.parent = arm.edit_bones['neck.03'] + bone = arm.edit_bones.new('neck.05') + bone.head[:] = 0.0000, -0.5111, 1.1956 + bone.tail[:] = 0.0000, -0.5391, 1.6081 + bone.roll = 0.0000 + bone.connected = True + bone.parent = arm.edit_bones['neck.04'] + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['head'] + pbone['type'] = 'neck' + + def main(obj, orig_bone_name): from Mathutils import Vector diff --git a/release/scripts/modules/rigify/palm.py b/release/scripts/modules/rigify/palm.py index f6f55541c64..b9df113167c 100644 --- a/release/scripts/modules/rigify/palm.py +++ b/release/scripts/modules/rigify/palm.py @@ -20,6 +20,58 @@ import bpy from rigify import get_bone_data, copy_bone_simple from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get + +def metarig_template(): + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.object + arm = obj.data + bone = arm.edit_bones.new('hand') + bone.head[:] = 0.0082, -1.2492, 0.0000 + bone.tail[:] = 0.0423, -0.4150, 0.0000 + bone.roll = 0.0000 + bone.connected = False + bone = arm.edit_bones.new('palm.03') + bone.head[:] = 0.0000, 0.0000, -0.0000 + bone.tail[:] = 0.0506, 1.2781, -0.1299 + bone.roll = -3.1396 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + bone = arm.edit_bones.new('palm.04') + bone.head[:] = 0.5000, -0.0000, 0.0000 + bone.tail[:] = 0.6433, 1.2444, -0.1299 + bone.roll = -3.1357 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + bone = arm.edit_bones.new('palm.05') + bone.head[:] = 1.0000, 0.0000, 0.0000 + bone.tail[:] = 1.3961, 1.0084, -0.1299 + bone.roll = -3.1190 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + bone = arm.edit_bones.new('palm.02') + bone.head[:] = -0.5000, 0.0000, -0.0000 + bone.tail[:] = -0.5674, 1.2022, -0.1299 + bone.roll = 3.1386 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + bone = arm.edit_bones.new('palm.01') + bone.head[:] = -1.0000, 0.0000, -0.0000 + bone.tail[:] = -1.3286, 1.0590, -0.1299 + bone.roll = 3.1239 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + bone = arm.edit_bones.new('palm.06') + bone.head[:] = 1.3536, -0.2941, 0.0000 + bone.tail[:] = 2.1109, 0.4807, -0.1299 + bone.roll = -3.0929 + bone.connected = False + bone.parent = arm.edit_bones['hand'] + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['hand'] + pbone['type'] = 'palm' + + def main(obj, orig_bone_name): arm, palm_pbone, palm_ebone = get_bone_data(obj, orig_bone_name) children = [ebone.name for ebone in palm_ebone.children] diff --git a/release/scripts/modules/rigify/spine.py b/release/scripts/modules/rigify/spine.py index d507d6fe1bc..f75575daacb 100644 --- a/release/scripts/modules/rigify/spine.py +++ b/release/scripts/modules/rigify/spine.py @@ -20,6 +20,70 @@ import bpy from rigify import bone_class_instance, copy_bone_simple from rna_prop_ui import rna_idprop_ui_prop_get + +def metarig_template(): + bpy.ops.object.mode_set(mode='EDIT') + obj = bpy.context.object + arm = obj.data + bone = arm.edit_bones.new('pelvis') + bone.head[:] = -0.0000, -0.2559, 0.8673 + bone.tail[:] = -0.0000, -0.2559, -0.1327 + bone.roll = 0.0000 + bone.connected = False + bone = arm.edit_bones.new('rib_cage') + bone.head[:] = -0.0000, -0.2559, 0.8673 + bone.tail[:] = -0.0000, -0.2559, 1.8673 + bone.roll = -0.0000 + bone.connected = False + bone.parent = arm.edit_bones['pelvis'] + bone = arm.edit_bones.new('spine.01') + bone.head[:] = -0.0000, -0.0000, 0.0000 + bone.tail[:] = -0.0000, -0.2559, 0.8673 + bone.roll = -0.0000 + bone.connected = False + bone.parent = arm.edit_bones['rib_cage'] + bone = arm.edit_bones.new('spine.02') + bone.head[:] = -0.0000, -0.2559, 0.8673 + bone.tail[:] = -0.0000, -0.3321, 1.7080 + bone.roll = -0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.01'] + bone = arm.edit_bones.new('spine.03') + bone.head[:] = -0.0000, -0.3321, 1.7080 + bone.tail[:] = -0.0000, -0.0787, 2.4160 + bone.roll = 0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.02'] + bone = arm.edit_bones.new('spine.04') + bone.head[:] = -0.0000, -0.0787, 2.4160 + bone.tail[:] = -0.0000, 0.2797, 3.0016 + bone.roll = 0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.03'] + bone = arm.edit_bones.new('spine.05') + bone.head[:] = -0.0000, 0.2797, 3.0016 + bone.tail[:] = -0.0000, 0.4633, 3.6135 + bone.roll = 0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.04'] + bone = arm.edit_bones.new('spine.06') + bone.head[:] = -0.0000, 0.4633, 3.6135 + bone.tail[:] = -0.0000, 0.3671, 4.3477 + bone.roll = -0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.05'] + bone = arm.edit_bones.new('spine.07') + bone.head[:] = -0.0000, 0.3671, 4.3477 + bone.tail[:] = -0.0000, 0.0175, 5.0033 + bone.roll = -0.0000 + bone.connected = True + bone.parent = arm.edit_bones['spine.06'] + + bpy.ops.object.mode_set(mode='OBJECT') + pbone = obj.pose.bones['rib_cage'] + pbone['type'] = 'spine' + + def validate(obj, orig_bone_name): ''' The bone given is the second in a chain. |