[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25283] trunk/blender: - rigify context changes & example for delta

Campbell Barton ideasman42 at gmail.com
Thu Dec 10 12:56:31 CET 2009


Revision: 25283
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25283
Author:   campbellbarton
Date:     2009-12-10 12:56:31 +0100 (Thu, 10 Dec 2009)

Log Message:
-----------
- rigify context changes & example for delta
- sequencer transform had 0.0 for rotation minimum
- missed icon rename in last commit

Modified Paths:
--------------
    trunk/blender/release/scripts/io/export_mdd.py
    trunk/blender/release/scripts/modules/graphviz_export.py
    trunk/blender/release/scripts/modules/rigify/__init__.py
    trunk/blender/release/scripts/modules/rigify/arm.py
    trunk/blender/release/scripts/modules/rigify/delta.py
    trunk/blender/release/scripts/modules/rigify/finger.py
    trunk/blender/release/scripts/modules/rigify/leg.py
    trunk/blender/release/scripts/modules/rigify/neck.py
    trunk/blender/release/scripts/modules/rigify/palm.py
    trunk/blender/release/scripts/modules/rigify/spine.py
    trunk/blender/release/scripts/modules/rna_prop_ui.py
    trunk/blender/source/blender/makesrna/intern/rna_sequence.c

Modified: trunk/blender/release/scripts/io/export_mdd.py
===================================================================
--- trunk/blender/release/scripts/io/export_mdd.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/io/export_mdd.py	2009-12-10 11:56:31 UTC (rev 25283)
@@ -163,7 +163,7 @@
 
     # List of operator properties, the attributes will be assigned
     # to the class instance from the operator settings before calling.
-    path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "tmp.mdd")
+    path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen= 1024, default= "")
     fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default= 25)
     start_frame = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe,max=maxframe,default=1)
     end_frame = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default= 250)

Modified: trunk/blender/release/scripts/modules/graphviz_export.py
===================================================================
--- trunk/blender/release/scripts/modules/graphviz_export.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/modules/graphviz_export.py	2009-12-10 11:56:31 UTC (rev 25283)
@@ -48,7 +48,7 @@
     #text = text.replace(']', ']\n')
     text = text.replace("\n", "\\n")
     text = text.replace('"', '\\"')
-    return "* " + text
+    return text
 
 
 def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True, XTRA_INFO=True):

Modified: trunk/blender/release/scripts/modules/rigify/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-10 11:56:31 UTC (rev 25283)
@@ -25,8 +25,8 @@
 from rna_prop_ui import rna_idprop_ui_prop_get
 
 empty_layer = [False] * 32
+DELIMITER = '-._'
 
-
 def auto_class(slots, name="ContainerClass", class_dict=None):
 
     if class_dict:
@@ -300,7 +300,7 @@
     whether it is a a left or right (or center, or whatever) bone.
     Returns an empty string if nothing is found.
     '''
-    if name[-2] in "-._":
+    if name[-2] in DELIMITER:
         return name[-2:]
     else:
         return ""
@@ -310,7 +310,7 @@
     Returns the part of a string (typically a bone's name) corresponding to it's
     base name (no sidedness, no ORG prefix).
     '''
-    if name[-2] in "-._":
+    if name[-2] in DELIMITER:
         return name[:-2]
     else:
         return name
@@ -408,12 +408,34 @@
 
     return poll_name
 
+def validate_rig(context, obj):
+    for pbone in obj.pose.bones:
+        bone_name = pbone.name
+        bone_type = pbone.get("type", "")
 
+        if bone_type:
+            bone_type_list = [bt for bt in bone_type.replace(",", " ").split()]
+        else:
+            bone_type_list = []
+
+        for bone_type in bone_type_list:            
+            type_pair = bone_type.split(".")
+            submod_name = type_pair[0]
+            
+            submod = __import__(name="%s.%s" % (__package__, submod_name), fromlist=[submod_name])
+            reload(submod)
+
+            submod.metarig_definition(obj, bone_name)
+        
+        # missing, - check for duplicate root bone.
+
+
 def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
     from collections import OrderedDict
 
     global_undo = context.user_preferences.edit.global_undo
     context.user_preferences.edit.global_undo = False
+    mode_orig = context.mode
 
     bpy.ops.object.mode_set(mode='OBJECT')
 
@@ -495,8 +517,7 @@
 
             # Only calculate bone definitions once
             if submod_name not in bone_def_dict:
-                metarig_definition_func = getattr(submod, "metarig_definition")
-                bone_def_dict[submod_name] = metarig_definition_func(obj, bone_name)
+                bone_def_dict[submod_name] = submod.metarig_definition(obj, bone_name)
 
 
             bone_typeinfo = bone_typeinfos.setdefault(bone_name, [])
@@ -579,8 +600,10 @@
     # obj.restrict_view = True
     obj.data.draw_axes = False
 
+    bpy.ops.object.mode_set(mode=mode_orig)
+
     context.user_preferences.edit.global_undo = global_undo
-
+    
     return obj
 
 
@@ -594,7 +617,7 @@
     bpy.ops.object.mode_set(mode='EDIT')
     code.append("    bpy.ops.object.mode_set(mode='EDIT')")
 
-    code.append("    obj = bpy.context.object")
+    code.append("    obj = bpy.context.active_object")
     code.append("    arm = obj.data")
 
     arm = obj.data
@@ -642,7 +665,7 @@
     return "\n".join(code)
 
 
-def generate_test(context):
+def generate_test(context, metarig_type="", GENERATE_FINAL=True):
     import os
     new_objects = []
 
@@ -654,6 +677,9 @@
         obj_new.data = armature
         scene.objects.link(obj_new)
         scene.objects.active = obj_new
+        for obj in scene.objects:
+            obj.selected = False
+        obj_new.selected = True
 
     files = os.listdir(os.path.dirname(__file__))
     for f in files:
@@ -664,6 +690,10 @@
             continue
 
         module_name = f[:-3]
+        
+        if (module_name and module_name != metarig_type):
+            continue
+        
         submodule = __import__(name="%s.%s" % (__package__, module_name), fromlist=[module_name])
 
         metarig_template = getattr(submodule, "metarig_template", None)
@@ -671,17 +701,21 @@
         if metarig_template:
             create_empty_armature("meta_" + module_name) # sets active
             metarig_template()
-            obj = context.object
-            obj_new = generate_rig(context, obj)
-
-            new_objects.append((obj, obj_new))
+            obj = context.active_object
+            obj.location = scene.cursor_location
+            
+            if GENERATE_FINAL:
+                obj_new = generate_rig(context, obj)
+                new_objects.append((obj, obj_new))
+            else:
+                new_objects.append((obj, None))
         else:
             print("note: rig type '%s' has no metarig_template(), can't test this", module_name)
 
     return new_objects
 
 
-def generate_test_all(context):
+def generate_test_all(context, GRAPH=False):
     import rigify
     import graphviz_export
     import os
@@ -689,19 +723,20 @@
     reload(graphviz_export)
 
     new_objects = rigify.generate_test(context)
+    
+    if GRAPH:
+        base_name = os.path.splitext(bpy.data.filename)[0]
+        for obj, obj_new in new_objects:
+            for obj in (obj, obj_new):
+                fn = base_name + "-" + bpy.utils.clean_name(obj.name)
 
-    base_name = os.path.splitext(bpy.data.filename)[0]
-    for obj, obj_new in new_objects:
-        for obj in (obj, obj_new):
-            fn = base_name + "-" + bpy.utils.clean_name(obj.name)
+                path_dot = fn + ".dot"
+                path_png = fn + ".png"
+                saved = graphviz_export.graph_armature(obj, path_dot, CONSTRAINTS=True, DRIVERS=True)
 
-            path_dot = fn + ".dot"
-            path_png = fn + ".png"
-            saved = graphviz_export.graph_armature(obj, path_dot, CONSTRAINTS=True, DRIVERS=True)
+                #if saved:
+                #    os.system("dot -Tpng %s > %s; eog %s" % (path_dot, path_png, path_png))
 
-            #if saved:
-            #    os.system("dot -Tpng %s > %s; eog %s" % (path_dot, path_png, path_png))
-
     i = 0
     for obj, obj_new in new_objects:
         obj.data.drawtype = 'STICK'
@@ -713,4 +748,4 @@
 
 
 if __name__ == "__main__":
-    generate_rig(bpy.context, bpy.context.object)
+    generate_rig(bpy.context, bpy.context.active_object)

Modified: trunk/blender/release/scripts/modules/rigify/arm.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/arm.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/modules/rigify/arm.py	2009-12-10 11:56:31 UTC (rev 25283)
@@ -29,7 +29,7 @@
 def metarig_template():
     # generated by rigify.write_meta_rig
     bpy.ops.object.mode_set(mode='EDIT')
-    obj = bpy.context.object
+    obj = bpy.context.active_object
     arm = obj.data
     bone = arm.edit_bones.new('shoulder')
     bone.head[:] = 0.0000, -0.4515, 0.0000

Modified: trunk/blender/release/scripts/modules/rigify/delta.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/delta.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/modules/rigify/delta.py	2009-12-10 11:56:31 UTC (rev 25283)
@@ -25,6 +25,34 @@
 METARIG_NAMES = tuple()
 
 
+def metarig_template():
+    # 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('bonesker')
+    bone.head[:] = 0.0000, 0.0000, 0.0000
+    bone.tail[:] = -0.0000, 0.7382, 0.1895
+    bone.roll = -0.0000
+    bone.connected = False
+    bone = arm.edit_bones.new('delta')
+    bone.head[:] = -0.0497, 0.8414, 0.3530
+    bone.tail[:] = -0.2511, 1.1588, 0.9653
+    bone.roll = 2.6044
+    bone.connected = False
+    bone.parent = arm.edit_bones['bonesker']
+    bone = arm.edit_bones.new('boney')
+    bone.head[:] = 0.7940, 2.5592, 0.4134
+    bone.tail[:] = 0.7940, 3.3975, 0.4890
+    bone.roll = 3.1416
+    bone.connected = False
+    bone.parent = arm.edit_bones['delta']
+
+    bpy.ops.object.mode_set(mode='OBJECT')
+    pbone = obj.pose.bones['delta']
+    pbone['type'] = 'delta'
+
+
 def metarig_definition(obj, orig_bone_name):
     '''
     The bone given is the head, its parent is the body,
@@ -37,7 +65,7 @@
     children = delta.children
 
     if len(children) != 1:
-        print("only 1 child supported for delta")
+        raise Exception("only 1 child supported for delta on bone '%s'" % delta.name)
 
     bone_definition = [delta.name, children[0].name]
 

Modified: trunk/blender/release/scripts/modules/rigify/finger.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/finger.py	2009-12-10 11:20:43 UTC (rev 25282)
+++ trunk/blender/release/scripts/modules/rigify/finger.py	2009-12-10 11:56:31 UTC (rev 25283)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list