[Bf-extensions-cvs] [120645a7] master: Rigify 0.5: basic and animals metarigs. metarig custom multi-menu. minor wgt reposition and shapes

Lucio Rossi noreply at git.blender.org
Fri Jun 2 19:11:25 CEST 2017


Commit: 120645a7ffb6a4ce3593180395eaf43c7a7144a0
Author: Lucio Rossi
Date:   Fri Jun 2 19:09:56 2017 +0200
Branches: master
https://developer.blender.org/rBA120645a7ffb6a4ce3593180395eaf43c7a7144a0

Rigify 0.5: basic and animals metarigs. metarig custom multi-menu. minor wgt reposition and shapes

===================================================================

M	rigify/metarig_menu.py
M	rigify/rigs/limbs/paw.py
M	rigify/rigs/spines/super_spine.py
M	rigify/utils.py

===================================================================

diff --git a/rigify/metarig_menu.py b/rigify/metarig_menu.py
index 4bdf2701..0c917c40 100644
--- a/rigify/metarig_menu.py
+++ b/rigify/metarig_menu.py
@@ -26,11 +26,23 @@ import bpy
 from . import utils
 
 
-def get_metarig_list(path):
+class ArmatureSubMenu(bpy.types.Menu):
+    # bl_idname = 'ARMATURE_MT_armature_class'
+
+    def draw(self, context):
+        layout = self.layout
+        layout.label(self.bl_label)
+        for op, name in self.operators:
+            text = capwords(name.replace("_", " ")) + " (Meta-Rig)"
+            layout.operator(op, icon='OUTLINER_OB_ARMATURE', text=text)
+
+
+def get_metarig_list(path, depth=0):
     """ Searches for metarig modules, and returns a list of the
         imported modules.
     """
     metarigs = []
+    metarigs_dict = dict()
     MODULE_DIR = os.path.dirname(__file__)
     METARIG_DIR_ABS = os.path.join(MODULE_DIR, utils.METARIG_DIR)
     SEARCH_DIR_ABS = os.path.join(METARIG_DIR_ABS, path)
@@ -39,8 +51,12 @@ def get_metarig_list(path):
 
     for f in files:
         # Is it a directory?
-        if os.path.isdir(os.path.join(SEARCH_DIR_ABS, f)):
-            continue
+        complete_path = os.path.join(SEARCH_DIR_ABS, f)
+        if os.path.isdir(complete_path) and depth == 0:
+            if f[0] != '_':
+                metarigs_dict[f] = get_metarig_list(f, depth=1)
+            else:
+                continue
         elif not f.endswith(".py"):
             continue
         elif f == "__init__.py":
@@ -48,10 +64,18 @@ def get_metarig_list(path):
         else:
             module_name = f[:-3]
             try:
-                metarigs += [utils.get_metarig_module(module_name)]
+                if depth == 1:
+                    metarigs += [utils.get_metarig_module(module_name, utils.METARIG_DIR + '.' + path)]
+                else:
+                    metarigs += [utils.get_metarig_module(module_name, utils.METARIG_DIR)]
             except (ImportError):
                 pass
-    return metarigs
+
+    if depth == 1:
+        return metarigs
+
+    metarigs_dict[utils.METARIG_DIR] = metarigs
+    return metarigs_dict
 
 
 def make_metarig_add_execute(m):
@@ -85,41 +109,72 @@ def make_metarig_menu_func(bl_idname, text):
     return metarig_menu
 
 
+def make_submenu_func(bl_idname, text):
+    def metarig_menu(self, context):
+        self.layout.menu(bl_idname, icon='OUTLINER_OB_ARMATURE', text=text)
+    return metarig_menu
+
+
 # Get the metarig modules
-metarigs = get_metarig_list("")
+metarigs_dict = get_metarig_list("")
+print(metarigs_dict)
+armature_submenus = []
 
 # Create metarig add Operators
-metarig_ops = []
-for m in metarigs:
-    name = m.__name__.rsplit('.', 1)[1]
+metarig_ops = {}
+for metarig_class in metarigs_dict:
+    metarig_ops[metarig_class] = []
+    for m in metarigs_dict[metarig_class]:
+        name = m.__name__.rsplit('.', 1)[1]
 
-    # Dynamically construct an Operator
-    T = type("Add_" + name + "_Metarig", (bpy.types.Operator,), {})
-    T.bl_idname = "object.armature_" + name + "_metarig_add"
-    T.bl_label = "Add " + name.replace("_", " ").capitalize() + " (metarig)"
-    T.bl_options = {'REGISTER', 'UNDO'}
-    T.execute = make_metarig_add_execute(m)
+        # Dynamically construct an Operator
+        T = type("Add_" + name + "_Metarig", (bpy.types.Operator,), {})
+        T.bl_idname = "object.armature_" + name + "_metarig_add"
+        T.bl_label = "Add " + name.replace("_", " ").capitalize() + " (metarig)"
+        T.bl_options = {'REGISTER', 'UNDO'}
+        T.execute = make_metarig_add_execute(m)
 
-    metarig_ops.append((T, name))
+        metarig_ops[metarig_class].append((T, name))
 
-# Create menu functions
 menu_funcs = []
-for mop, name in metarig_ops:
-    text = capwords(name.replace("_", " ")) + " (Meta-Rig)"
-    menu_funcs += [make_metarig_menu_func(mop.bl_idname, text)]
-
+for metarig_class in metarigs_dict:
+    # Create menu functions
+    if metarig_class != utils.METARIG_DIR:
+        armature_submenus.append(type('Class_' + metarig_class + '_submenu', (ArmatureSubMenu,), {}))
+        armature_submenus[-1].bl_label = metarig_class + ' (submenu)'
+        armature_submenus[-1].bl_idname = 'ARMATURE_MT_%s_class' % metarig_class
+        armature_submenus[-1].operators = []
+        menu_funcs += [make_submenu_func(armature_submenus[-1].bl_idname, metarig_class)]
+
+    for mop, name in metarig_ops[metarig_class]:
+        print(metarig_class)
+        print(metarig_ops[metarig_class])
+        if metarig_class != utils.METARIG_DIR:
+            arm_sub = next((e for e in armature_submenus if e.bl_label == metarig_class + ' (submenu)'), '')
+            arm_sub.operators.append((mop.bl_idname, name,))
+        else:
+            text = capwords(name.replace("_", " ")) + " (Meta-Rig)"
+            menu_funcs += [make_metarig_menu_func(mop.bl_idname, text)]
 
 def register():
-    for mop, name in metarig_ops:
-        bpy.utils.register_class(mop)
+    for cl in metarig_ops:
+        for mop, name in metarig_ops[cl]:
+            bpy.utils.register_class(mop)
+
+    for arm_sub in armature_submenus:
+        bpy.utils.register_class(arm_sub)
 
     for mf in menu_funcs:
         bpy.types.INFO_MT_armature_add.append(mf)
 
 
 def unregister():
-    for mop, name in metarig_ops:
-        bpy.utils.unregister_class(mop)
+    for cl in metarig_ops:
+        for mop, name in metarig_ops[cl]:
+            bpy.utils.unregister_class(mop)
+
+    for arm_sub in armature_submenus:
+        bpy.utils.unregister_class(arm_sub)
 
     for mf in menu_funcs:
         bpy.types.INFO_MT_armature_add.remove(mf)
diff --git a/rigify/rigs/limbs/paw.py b/rigify/rigs/limbs/paw.py
index 8c79503e..720dea1c 100644
--- a/rigify/rigs/limbs/paw.py
+++ b/rigify/rigs/limbs/paw.py
@@ -421,9 +421,9 @@ class Rig:
         eb[ mch_str ].tail = eb[ org_bones[-2] ].head
 
         # Parenting
-        eb[ ctrl    ].parent = eb[ parent ]
-        eb[ mch_str ].parent = eb[ parent ]
-        eb[ mch_ik  ].parent = eb[ ctrl   ]
+        eb[ctrl].parent = eb[parent]
+        eb[mch_str].parent = eb[parent]
+        eb[mch_ik].parent = eb[ctrl]
 
         # Make standard pole target bone
         pole_name = get_bone_name(org_bones[0], 'ctrl', 'ik_target')
diff --git a/rigify/rigs/spines/super_spine.py b/rigify/rigs/spines/super_spine.py
index a79a3e89..0ec9e1c9 100644
--- a/rigify/rigs/spines/super_spine.py
+++ b/rigify/rigs/spines/super_spine.py
@@ -1,8 +1,8 @@
 import bpy
 from mathutils import Vector
-from ...utils import copy_bone, flip_bone, put_bone, org, align_bone_y_axis, align_bone_x_axis, align_bone_z_axis
+from ...utils import copy_bone, flip_bone, put_bone, org, align_bone_y_axis, align_bone_x_axis
 from ...utils import strip_org, make_deformer_name, connected_children_names 
-from ...utils import create_circle_widget, create_sphere_widget, create_widget
+from ...utils import create_circle_widget, create_sphere_widget, create_neck_bend_widget, create_neck_tweak_widget
 from ..widgets import create_ballsocket_widget
 from ...utils import MetarigError, make_mechanism_name, create_cube_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
@@ -811,7 +811,6 @@ class Rig:
             self.obj.data.bones[bone].bbone_segments = 8
 
         self.obj.data.bones[bones['def'][0]].bbone_in = 0.0
-        # self.obj.data.bones[bones['def'][-2]].bbone_out = 0.0
         self.obj.data.bones[bones['def'][-2]].bbone_out = 1.0
 
         # Locks
@@ -862,11 +861,17 @@ class Rig:
             else:
                 radius = 1.0
 
+            # place chest on neck-base for very long necks
+            if bone == bones['chest']['ctrl'] and len(bones['neck']['original_names']) > 3:
+                head_tail = 0.0
+            else:
+                head_tail = 0.75
+
             create_circle_widget(
                 self.obj,
                 bone,
                 radius=radius,
-                head_tail=0.75,
+                head_tail=head_tail,
                 with_line=False,
                 bone_transform_name=None
             )
@@ -881,8 +886,7 @@ class Rig:
                 self.obj,
                 bones['neck']['ctrl_neck'],
                 radius=radius,
-                head_tail=0.75,
-                with_line=False,
+                head_tail=0.5,
                 bone_transform_name=None
             )
 
@@ -892,22 +896,26 @@ class Rig:
                 radius = 0.5
             else:
                 radius = 1/(2*len(bones['neck']['mch']))
-            create_circle_widget(
+            create_neck_bend_widget(
                 self.obj,
                 bones['neck']['neck_bend'],
                 radius=radius,
                 head_tail=0.0,
-                with_line=False,
                 bone_transform_name=None
             )
 
         # Head widget
+        # place wgt @ middle of head bone for long necks
+        if len(bones['neck']['original_names']) > 3:
+            head_tail = 0.5
+        else:
+            head_tail = 1.0
         if self.use_head:
             create_circle_widget(
                 self.obj,
                 bones['neck']['ctrl'],
                 radius              = 0.5,
-                head_tail           = 1.0,
+                head_tail           = head_tail,
                 with_line           = False,
                 bone_transform_name = None
             )
@@ -926,6 +934,11 @@ class Rig:
 
         # Assigning widgets to tweak bones and layers
         for bone in tweaks:
+
+            if bones['neck']['tweak'] and bone == bones['neck']['tweak'][0] \
+                    and len(bones['neck']['original_names']) > 3:
+                create_neck_tweak_widget(self.obj, bone, size=1.0, bone_transform_name=None)
+                continue
             create_sphere_widget(self.obj, bone, bone_transform_name=None)
 
             if self.tweak_layers:
@@ -1013,10 +1026,10 @@ def add_parameters(params):
     )
 
     params.pivot_pos = bpy.props.IntProperty(
-        name         = 'pivot_position',
-        default      = 3,
-        min          = 0,
-        description  = 'Position of the torso control and pivot point'
+        name='pivot_position',
+        default=2,
+        min=0

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list