- include example input rigs for each autorig type, running metarig_template() in...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 2 Dec 2009 11:55:47 +0000 (11:55 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 2 Dec 2009 11:55:47 +0000 (11:55 +0000)
- rigify.write_meta_rig() exports rigs as python scripts

release/scripts/modules/rigify/__init__.py
release/scripts/modules/rigify/arm.py
release/scripts/modules/rigify/finger.py
release/scripts/modules/rigify/neck.py
release/scripts/modules/rigify/palm.py
release/scripts/modules/rigify/spine.py

index a0b5c721b2aa2d5b24e7475950d21a1e410e0450..8c0643769c333adb5e42e5b9eb0abfc59bbd7bb6 100644 (file)
@@ -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)
index d2c9208d4ffbff894140f48466d1f7ea598fa582..36217ed5247206aa247cebda63d8b0757b2b9393 100644 (file)
@@ -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.
index c71473dca8efcd4de89e8dfc080693bd4acf2017..a9040830e4e587d76ed682a2f87dd245291243fb 100644 (file)
@@ -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
index c9c732b5df6ced8e2d8a84ae81e2a2460fbc562d..524de6e2f3df428d8abb55fce7a3b38a264b0132 100644 (file)
@@ -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
     
index f6f55541c6493ac4e1024b12c484903663ae07c0..b9df113167c2cf69861c5453c0b451d490c28a24 100644 (file)
@@ -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]
index d507d6fe1bc914a0a7f8c4edb93819ee1ed6caa0..f75575daacb7ba1276263e296546d7c74be91d64 100644 (file)
@@ -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.