[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25054] trunk/blender/release/scripts/ modules: - rig spine type WIP, editmode done, still needs pose constraints and drivers.

Campbell Barton ideasman42 at gmail.com
Tue Dec 1 23:46:50 CET 2009


Revision: 25054
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25054
Author:   campbellbarton
Date:     2009-12-01 23:45:56 +0100 (Tue, 01 Dec 2009)

Log Message:
-----------
- rig spine type WIP, editmode done, still needs pose constraints and drivers.
- bone.translate(vec) utility function

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy_types.py
    trunk/blender/release/scripts/modules/graphviz_export.py

Added Paths:
-----------
    trunk/blender/release/scripts/modules/rigify/spine.py

Modified: trunk/blender/release/scripts/modules/bpy_types.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_types.py	2009-12-01 20:37:26 UTC (rev 25053)
+++ trunk/blender/release/scripts/modules/bpy_types.py	2009-12-01 22:45:56 UTC (rev 25054)
@@ -46,7 +46,11 @@
     functions for bones, common between Armature/Pose/Edit bones.
     internal subclassing use only.
     '''
-    
+
+    def translate(self, vec):
+        self.head += vec
+        self.tail += vec
+
     def parent_index(self, parent_test):
         '''
         The same as 'bone in other_bone.parent_recursive' but saved generating a list.

Modified: trunk/blender/release/scripts/modules/graphviz_export.py
===================================================================
--- trunk/blender/release/scripts/modules/graphviz_export.py	2009-12-01 20:37:26 UTC (rev 25053)
+++ trunk/blender/release/scripts/modules/graphviz_export.py	2009-12-01 22:45:56 UTC (rev 25054)
@@ -26,12 +26,26 @@
 }
 '''
 
-def compat_str(text):
+def compat_str(text, line_length=22):
+
+    if line_length:
+        text_ls = []
+        while len(text) > line_length:
+            text_ls.append(text[:line_length])
+            text = text[line_length:]
+        
+        if text:
+            text_ls.append(text)
+        text = '\n  '.join(text_ls)
+    
+    
+    #text = text.replace('.', '.\n')
+    #text = text.replace(']', ']\n')
     text = text.replace("\n", "\\n")
     text = text.replace('"', '\\"')
-    return text
+    return "* " + text
 
-def graph_armature(obj, path, FAKE_PARENT=True):
+def graph_armature(obj, path, FAKE_PARENT=True, CONSTRAINTS=True, DRIVERS=True):
     
     file = open(path, "w")
     fw = file.write
@@ -40,8 +54,15 @@
     
     arm = obj.data
     
-    for bone in arm.bones:
-        label = [bone.name]
+    bones = [bone.name for bone in arm.bones]
+    bones.sort()
+    print("")
+    for bone in bones:
+        b = arm.bones[bone]
+        print(">>", bone, ["*>", "->"][b.connected], getattr(getattr(b, "parent", ""), "name", ""))
+        label = [bone]
+        bone = arm.bones[bone]
+        
         for key, value in obj.pose.bones[bone.name].items():
             if key.startswith("_"):
                 continue
@@ -53,8 +74,14 @@
             
             label.append("%s = %s" % (key, value))
         
-        opts = ["shape=box", "regular=1", "style=filled", "fillcolor=white", 'width="2.33"', 'height="0.35"', "fixedsize=false", 'label="%s"' % compat_str('\n'.join(label))]
+        opts = ["shape=box", "regular=1", "style=filled", 'width="2.33"', 'height="0.35"', "fixedsize=false", 'label="%s"' % compat_str('\n'.join(label))]
         
+        if bone.name.startswith('ORG'):
+            opts.append("fillcolor=yellow")
+        else:
+            opts.append("fillcolor=white")
+        
+        
         fw('"%s" [%s];\n' % (bone.name, ','.join(opts)))
     
     # Root node.
@@ -80,44 +107,46 @@
     del bone    
     
     # constraints
-    for pbone in obj.pose.bones:
-        for constraint in pbone.constraints:
-            subtarget = constraint.subtarget
-            if subtarget:
-                # TODO, not internal links
-                opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="red"', 'labelfontsize=8']
-                label = "%s\n%s" % (constraint.type, constraint.name)
-                opts.append('label="%s"' % compat_str(label))
-                fw('"%s" -> "%s" [%s] ;\n' % (subtarget, pbone.name, ','.join(opts)))
+    if CONSTRAINTS:
+        for pbone in obj.pose.bones:
+            for constraint in pbone.constraints:
+                subtarget = constraint.subtarget
+                if subtarget:
+                    # TODO, not internal links
+                    opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="red"', 'labelfontsize=4']
+                    label = "%s\n%s" % (constraint.type, constraint.name)
+                    opts.append('label="%s"' % compat_str(label))
+                    fw('"%s" -> "%s" [%s] ;\n' % (subtarget, pbone.name, ','.join(opts)))
     
     # Drivers
-    def rna_path_as_pbone(rna_path):
-        if not rna_path.startswith("pose.bones["):
-            return None
+    if DRIVERS:
+        def rna_path_as_pbone(rna_path):
+            if not rna_path.startswith("pose.bones["):
+                return None
 
-        #rna_path_bone = rna_path[:rna_path.index("]") + 1]
-        #return obj.path_resolve(rna_path_bone)
-        bone_name = rna_path.split("[")[1].split("]")[0]
-        return obj.pose.bones[bone_name[1:-1]]
+            #rna_path_bone = rna_path[:rna_path.index("]") + 1]
+            #return obj.path_resolve(rna_path_bone)
+            bone_name = rna_path.split("[")[1].split("]")[0]
+            return obj.pose.bones[bone_name[1:-1]]
+        
+        animation_data = obj.animation_data
+        if animation_data:
+            for fcurve_driver in animation_data.drivers:
+                rna_path = fcurve_driver.rna_path
+                pbone = rna_path_as_pbone(rna_path)
+                    
+                if pbone:
+                    for target in fcurve_driver.driver.targets:
+                        pbone_target = rna_path_as_pbone(target.rna_path)
+                        rna_path_target = target.rna_path
+                        if pbone_target:
+                            opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="blue"', "labelfontsize=4"] # , 
+                            display_source = rna_path.replace("pose.bones", "")
+                            display_target = rna_path_target.replace("pose.bones", "")
+                            label = "%s\\n%s" % (display_source, display_target)
+                            opts.append('label="%s"' % compat_str(label))
+                            fw('"%s" -> "%s" [%s] ;\n' % (pbone_target.name, pbone.name, ','.join(opts)))
     
-    animation_data = obj.animation_data
-    if animation_data:
-        for fcurve_driver in animation_data.drivers:
-            rna_path = fcurve_driver.rna_path
-            pbone = rna_path_as_pbone(rna_path)
-                
-            if pbone:
-                for target in fcurve_driver.driver.targets:
-                    pbone_target = rna_path_as_pbone(target.rna_path)
-                    rna_path_target = target.rna_path
-                    if pbone_target:
-                        opts = ['dir=forward', "weight=1", "arrowhead=normal", "arrowtail=none", "constraint=false", 'color="blue"', "labelfontsize=8"] # , 
-                        display_source = rna_path.replace("pose.bones", "")
-                        display_target = rna_path_target.replace("pose.bones", "")
-                        label = "%s\\n%s" % (display_source, display_target)
-                        opts.append('label="%s"' % compat_str(label))
-                        fw('"%s" -> "%s" [%s] ;\n' % (pbone_target.name, pbone.name, ','.join(opts)))
-    
     fw(footer)
     file.close()
     
@@ -129,5 +158,5 @@
     import bpy
     import os
     path ="/tmp/test.dot"
-    graph_armature(bpy.context.object, path)
+    graph_armature(bpy.context.object, path, CONSTRAINTS=False, DRIVERS=False)
     os.system("dot -Tpng %s > %s; eog %s &" % (path, path + '.png', path + '.png'))

Added: trunk/blender/release/scripts/modules/rigify/spine.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/spine.py	                        (rev 0)
+++ trunk/blender/release/scripts/modules/rigify/spine.py	2009-12-01 22:45:56 UTC (rev 25054)
@@ -0,0 +1,187 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+from rigify import bone_class_instance, copy_bone_simple
+from rna_prop_ui import rna_idprop_ui_prop_get
+
+def validate(obj, orig_bone_name):
+    '''
+    The bone given is the second in a chain.
+    Expects at least 1 parent and a chain of children withe the same basename
+    eg.
+        pelvis -> rib_cage -> spine.01 -> spine.02 -> spine.03
+    '''
+    orig_bone = obj.data.bones[orig_bone_name]
+    if not orig_bone.parent:
+        return "expected spine bone '%s' to have a parent" % orig_bone_name
+    
+    children = orig_bone.children
+
+    if len(children) != 1:
+        return "expected spine bone '%s' to have only 1 child for the sine chain" % orig_bone_name
+    
+    children_spine = children[0].children_recursive_basename
+
+    if len(children_spine) == 0:
+        return "expected '%s' to define a chain of children with its basename (2 or more)" % children[0]
+
+    return ''
+
+def main(obj, orig_bone_name):
+    from Mathutils import Vector, Matrix, RotationMatrix
+    from math import radians, pi
+    
+    arm = obj.data
+
+    # Initialize container classes for convenience
+    mt = bone_class_instance(obj, ["pelvis", "ribcage"]) # meta
+    mt.ribcage = orig_bone_name
+    mt.update()
+    mt.pelvis = mt.ribcage_e.parent.name
+    mt.update()
+
+    children = mt.ribcage_e.children
+    child = children[0] # validate checks for 1 only.
+    spine_chain_basename = child.basename # probably 'spine'
+    spine_chain_segment_length = child.length
+    spine_chain = [child] + child.children_recursive_basename
+    spine_chain_orig = [child.name for child in spine_chain]
+    child.parent = mt.pelvis_e # was mt.ribcage
+    
+    # The first bone in the chain happens to be the basis of others, create them now
+    ex = bone_class_instance(obj, ["pelvis", "ribcage", "ribcage_hinge", "spine_rotate"])

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list