[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1162] trunk/py/scripts/addons: Adding the Rigify addon to svn.

Nathan Vegdahl cessen at cessen.com
Wed Nov 17 07:05:43 CET 2010


Revision: 1162
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=1162
Author:   cessen
Date:     2010-11-17 07:05:16 +0100 (Wed, 17 Nov 2010)

Log Message:
-----------
Adding the Rigify addon to svn.

Added Paths:
-----------
    trunk/py/scripts/addons/rigify/
    trunk/py/scripts/addons/rigify/__init__.py
    trunk/py/scripts/addons/rigify/generate.py
    trunk/py/scripts/addons/rigify/metarig_menu.py
    trunk/py/scripts/addons/rigify/metarigs/
    trunk/py/scripts/addons/rigify/metarigs/__init__.py
    trunk/py/scripts/addons/rigify/metarigs/human.py
    trunk/py/scripts/addons/rigify/rig_ui_template.py
    trunk/py/scripts/addons/rigify/rigs/
    trunk/py/scripts/addons/rigify/rigs/__init__.py
    trunk/py/scripts/addons/rigify/rigs/biped/
    trunk/py/scripts/addons/rigify/rigs/biped/__init__.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/
    trunk/py/scripts/addons/rigify/rigs/biped/arm/__init__.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/deform.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/fk.py
    trunk/py/scripts/addons/rigify/rigs/biped/arm/ik.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/
    trunk/py/scripts/addons/rigify/rigs/biped/leg/__init__.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/deform.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/fk.py
    trunk/py/scripts/addons/rigify/rigs/biped/leg/ik.py
    trunk/py/scripts/addons/rigify/rigs/copy.py
    trunk/py/scripts/addons/rigify/rigs/finger.py
    trunk/py/scripts/addons/rigify/rigs/misc/
    trunk/py/scripts/addons/rigify/rigs/misc/__init__.py
    trunk/py/scripts/addons/rigify/rigs/misc/delta.py
    trunk/py/scripts/addons/rigify/rigs/neck_short.py
    trunk/py/scripts/addons/rigify/rigs/palm.py
    trunk/py/scripts/addons/rigify/rigs/spine.py
    trunk/py/scripts/addons/rigify/ui.py
    trunk/py/scripts/addons/rigify/utils.py

Added: trunk/py/scripts/addons/rigify/__init__.py
===================================================================
--- trunk/py/scripts/addons/rigify/__init__.py	                        (rev 0)
+++ trunk/py/scripts/addons/rigify/__init__.py	2010-11-17 06:05:16 UTC (rev 1162)
@@ -0,0 +1,138 @@
+#====================== 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#======================= END GPL LICENSE BLOCK ========================
+
+bl_addon_info = {
+    "name": "Rigify",
+    "author": "Nathan Vegdahl",
+    "version": (0, 5),
+    "blender": (2, 5, 5),
+    "api": 33110,
+    "location": "Armature properties",
+    "wiki_url": "",
+    "tracker_url": "",
+    "category": "Rigging"}
+
+import bpy
+import bpy_types
+import os
+from imp import reload
+
+
+try:
+    reload(generate)
+    reload(ui)
+    reload(utils)
+    reload(metarig_menu)
+except NameError:
+    from rigify import generate, ui, utils, metarig_menu
+
+
+def get_rig_list(path):
+    """ Recursively searches for rig types, and returns a list.
+    """
+    rigs = []
+    files = os.listdir(os.path.dirname(__file__) + "/" + utils.RIG_DIR + "/" + path)
+    files = sorted(files)
+
+    for f in files:
+        if not f.startswith("_"):
+            if os.path.isdir(os.path.dirname(__file__) + "/" + utils.RIG_DIR + "/" + path + f):
+                # Check directories
+                try:
+                    rig = utils.get_rig_type((path + f).replace("/", "."))
+                except ImportError as e:
+                    print("Rigify: " + str(e))
+                else:
+                    # Check if it's a rig itself
+                    try:
+                        rig.Rig
+                    except AttributeError:
+                        # Check for sub-rigs
+                        ls = get_rig_list(path + f + "/")
+                        for l in ls:
+                            rigs += [f + '.' + l]
+                    else:
+                        rigs += [f]
+
+            elif f.endswith(".py"):
+                # Check straight-up python files
+                t = f[:-3]
+                try:
+                    utils.get_rig_type((path + t).replace("/", ".")).Rig
+                except (ImportError, AttributeError):
+                    pass
+                else:
+                    rigs += [t]
+    rigs.sort()
+    return rigs
+
+
+rig_list = get_rig_list("")
+
+
+collection_list = []
+for r in rig_list:
+    a = r.split(".")
+    if len(a) >= 2 and a[0] not in collection_list:
+        collection_list += [a[0]]
+
+
+col_enum_list = [("All", "All", ""), ("None", "None", "")]
+for c in collection_list:
+    col_enum_list += [(c, c, "")]
+
+
+class RigifyName(bpy.types.IDPropertyGroup):
+    name = bpy.props.StringProperty()
+
+
+class RigifyParameters(bpy.types.IDPropertyGroup):
+    name = bpy.props.StringProperty()
+
+
+for rig in rig_list:
+    r = utils.get_rig_type(rig).Rig
+    try:
+        r.add_parameters(RigifyParameters)
+    except AttributeError:
+        pass
+
+
+##### REGISTER #####
+
+def register():
+    bpy.types.PoseBone.rigify_type = bpy.props.StringProperty(name="Rigify Type", description="Rig type for this bone.")
+    bpy.types.PoseBone.rigify_parameters = bpy.props.CollectionProperty(type=RigifyParameters)
+
+    bpy.types.Scene.rigify_collection = bpy.props.EnumProperty(items=col_enum_list, default="All", name="Rigify Active Collection", description="The selected rig collection")
+    bpy.types.Scene.rigify_types = bpy.props.CollectionProperty(type=RigifyName)
+    bpy.types.Scene.rigify_active_type = bpy.props.IntProperty(name="Rigify Active Type", description="The selected rig type.")
+
+    metarig_menu.register()
+
+
+def unregister():
+    del bpy.types.PoseBone.rigify_type
+    del bpy.types.PoseBone.rigify_parameters
+
+    del bpy.types.Scene.rigify_collection
+    del bpy.types.Scene.rigify_types
+    del bpy.types.Scene.rigify_active_type
+
+    metarig_menu.unregister()
+

Added: trunk/py/scripts/addons/rigify/generate.py
===================================================================
--- trunk/py/scripts/addons/rigify/generate.py	                        (rev 0)
+++ trunk/py/scripts/addons/rigify/generate.py	2010-11-17 06:05:16 UTC (rev 1162)
@@ -0,0 +1,351 @@
+#====================== 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+#======================= END GPL LICENSE BLOCK ========================
+
+import bpy
+import time
+import traceback
+import sys
+from rna_prop_ui import rna_idprop_ui_prop_get
+from rigify.utils import MetarigError, new_bone, get_rig_type
+from rigify.utils import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, WGT_PREFIX, ROOT_NAME, make_original_name
+from rigify.utils import RIG_DIR
+from rigify.utils import create_root_widget
+from rigify.utils import random_string
+from rigify.rig_ui_template import UI_SLIDERS, layers_ui
+from rigify import rigs
+
+RIG_MODULE = "rigs"
+ORG_LAYER = [n == 31 for n in range(0, 32)]  # Armature layer that original bones should be moved to.
+MCH_LAYER = [n == 30 for n in range(0, 32)]  # Armature layer that mechanism bones should be moved to.
+DEF_LAYER = [n == 29 for n in range(0, 32)]  # Armature layer that deformation bones should be moved to.
+ROOT_LAYER = [n == 28 for n in range(0, 32)]  # Armature layer that root bone should be moved to.
+
+
+class Timer:
+    def __init__(self):
+        self.timez = time.time()
+
+    def tick(self, string):
+        t = time.time()
+        print(string + "%.3f" % (t - self.timez))
+        self.timez = t
+
+
+# TODO: generalize to take a group as input instead of an armature.
+def generate_rig(context, metarig):
+    """ Generates a rig from a metarig.
+
+    """
+    t = Timer()
+    rig_id = random_string(12)  # Random so that different rigs don't collide id's
+
+    # Initial configuration
+    use_global_undo = context.user_preferences.edit.use_global_undo
+    context.user_preferences.edit.use_global_undo = False
+    mode_orig = context.mode
+    rest_backup = metarig.data.pose_position
+    metarig.data.pose_position = 'REST'
+
+    bpy.ops.object.mode_set(mode='OBJECT')
+
+    scene = context.scene
+
+    #------------------------------------------
+    # Create/find the rig object and set it up
+
+    # Check if the generated rig already exists, so we can
+    # regenerate in the same object.  If not, create a new
+    # object to generate the rig in.
+    print("Fetch rig.")
+    try:
+        name = metarig["rig_object_name"]
+    except KeyError:
+        name = "rig"
+
+    try:
+        obj = scene.objects[name]
+    except KeyError:
+        obj = bpy.data.objects.new(name, bpy.data.armatures.new(name))
+        obj.draw_type = 'WIRE'
+        scene.objects.link(obj)
+
+    obj.data.pose_position = 'POSE'
+
+    # Get rid of anim data in case the rig already existed
+    print("Clear rig animation data.")
+    obj.animation_data_clear()
+
+    # Select generated rig object
+    metarig.select = False
+    obj.select = True
+    scene.objects.active = obj
+
+    # Remove all bones from the generated rig armature.
+    bpy.ops.object.mode_set(mode='EDIT')
+    for bone in obj.data.edit_bones:
+        obj.data.edit_bones.remove(bone)
+    bpy.ops.object.mode_set(mode='OBJECT')
+
+    # Create temporary duplicates for merging
+    temp_rig_1 = metarig.copy()
+    temp_rig_1.data = metarig.data.copy()
+    scene.objects.link(temp_rig_1)
+
+    temp_rig_2 = metarig.copy()
+    temp_rig_2.data = obj.data
+    scene.objects.link(temp_rig_2)
+
+    # Select the temp rigs for merging
+    for objt in scene.objects:
+        objt.select = False  # deselect all objects
+    temp_rig_1.select = True
+    temp_rig_2.select = True
+    scene.objects.active = temp_rig_2
+
+    # Merge the temporary rigs
+    bpy.ops.object.join()
+
+    # Delete the second temp rig
+    bpy.ops.object.delete()
+
+    # Select the generated rig
+    for objt in scene.objects:
+        objt.select = False  # deselect all objects
+    obj.select = True
+    scene.objects.active = obj
+
+    # Copy over the pose_bone properties
+    for bone in metarig.pose.bones:
+        bone_gen = obj.pose.bones[bone.name]
+
+        # Rotation mode and transform locks
+        bone_gen.rotation_mode = bone.rotation_mode
+        bone_gen.lock_rotation = tuple(bone.lock_rotation)
+        bone_gen.lock_rotation_w = bone.lock_rotation_w
+        bone_gen.lock_rotations_4d = bone.lock_rotations_4d
+        bone_gen.lock_location = tuple(bone.lock_location)
+        bone_gen.lock_scale = tuple(bone.lock_scale)
+
+        # Custom properties
+        for prop in bone.keys():
+            bone_gen[prop] = bone[prop]
+
+    # Copy over bone properties
+    for bone in metarig.data.bones:
+        bone_gen = obj.data.bones[bone.name]
+
+        # B-bone stuff
+        bone_gen.bbone_segments = bone.bbone_segments
+        bone_gen.bbone_in = bone.bbone_in
+        bone_gen.bbone_out = bone.bbone_out
+
+    t.tick("Duplicate rig: ")
+    #----------------------------------

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list