[Bf-extensions-cvs] [8b1df843] master: Rigify: replace rigs with new implementations using the new base rig.

Alexander Gavrilov noreply at git.blender.org
Sat Sep 14 08:34:18 CEST 2019


Commit: 8b1df843703fdb51ffa5758625c117c4f10bc6dd
Author: Alexander Gavrilov
Date:   Sat Sep 14 09:17:30 2019 +0300
Branches: master
https://developer.blender.org/rBA8b1df843703fdb51ffa5758625c117c4f10bc6dd

Rigify: replace rigs with new implementations using the new base rig.

Spine is split into parts. Limbs and tentacles simply converted.

Differential Revision: https://developer.blender.org/D4624

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

M	rigify/rigs/limbs/arm.py
M	rigify/rigs/limbs/leg.py
A	rigify/rigs/limbs/limb_rigs.py
M	rigify/rigs/limbs/paw.py
M	rigify/rigs/limbs/rear_paw.py
M	rigify/rigs/limbs/simple_tentacle.py
M	rigify/rigs/limbs/super_finger.py
M	rigify/rigs/limbs/super_limb.py
D	rigify/rigs/limbs/ui.py
A	rigify/rigs/spines/basic_spine.py
A	rigify/rigs/spines/basic_tail.py
A	rigify/rigs/spines/spine_rigs.py
A	rigify/rigs/spines/super_head.py
M	rigify/rigs/spines/super_spine.py
M	rigify/rigs/utils.py

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

diff --git a/rigify/rigs/limbs/arm.py b/rigify/rigs/limbs/arm.py
index aacc1e86..4e9cf299 100644
--- a/rigify/rigs/limbs/arm.py
+++ b/rigify/rigs/limbs/arm.py
@@ -1,1014 +1,115 @@
-import bpy, re
-from ..widgets import create_hand_widget, create_gear_widget
-from .ui             import create_script
-from .limb_utils     import *
-from mathutils       import Vector
-from ...utils       import copy_bone, put_bone
-from ...utils       import strip_org, strip_mch
-from ...utils       import create_circle_widget, create_sphere_widget, create_line_widget
-from ...utils       import make_mechanism_name
-from ...utils       import create_limb_widget, connected_children_names
-from ...utils       import align_bone_x_axis, align_bone_z_axis
-from ...rig_ui_template import UTILITIES_RIG_ARM, REGISTER_RIG_ARM
-from ...utils       import ControlLayersOption
-from ...utils.mechanism import make_property, make_driver
-from ..widgets import create_ikarrow_widget
-from math import trunc, pi
+#====================== 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 ========================
 
-from ...utils.switch_parent import SwitchParentBuilder
+# <pep8 compliant>
 
+import bpy
 
-IMPLEMENTATION = True   # Include and set True if Rig is just an implementation for a wrapper class
-                        # add_parameters and parameters_ui are unused for implementation classes
+from itertools import count
 
+from ...utils.bones import BoneDict, compute_chain_x_axis, align_bone_x_axis, align_bone_z_axis
+from ...utils.naming import make_derived_name
+from ...utils.misc import map_list
 
-class Rig:
+from ..widgets import create_hand_widget
 
-    def __init__(self, obj, bone_name, params):
-        """ Initialize arm rig and key rig properties """
-        self.obj = obj
-        self.params = params
+from ...base_rig import stage
 
-        self.org_bones = list(
-            [bone_name] + connected_children_names(obj, bone_name)
-            )[:3]  # The basic limb is the first 3 bones
+from .limb_rigs import BaseLimbRig
 
-        self.segments = params.segments
-        self.bbones = params.bbones
-        self.limb_type = params.limb_type
-        self.rot_axis = params.rotation_axis
-        self.auto_align_extremity = params.auto_align_extremity
 
+class Rig(BaseLimbRig):
+    """Human arm rig."""
 
-    def orient_org_bones(self):
+    def initialize(self):
+        if len(self.bones.org.main) != 3:
+            self.raise_error("Input to rig type must be a chain of 3 bones.")
 
-        bpy.ops.object.mode_set(mode='EDIT')
-        eb = self.obj.data.edit_bones
+        super().initialize()
 
-        thigh = self.org_bones[0]
-        org_bones = list(
-            [thigh] + connected_children_names(self.obj, thigh)
-        )  # All the provided orgs
+    def prepare_bones(self):
+        orgs = self.bones.org.main
 
-        org_uarm = eb[org_bones[0]]
-        org_farm = eb[org_bones[1]]
-        org_hand = eb[org_bones[2]]
+        if self.params.rotation_axis == 'automatic':
+            axis = compute_chain_x_axis(self.obj, orgs[0:2])
 
-        if self.rot_axis != 'automatic':
-            if self.auto_align_extremity:
-                z_ground_projection = Vector((org_hand.z_axis[0], org_hand.z_axis[1], 0))
-                align_bone_z_axis(self.obj, org_hand.name, z_ground_projection.normalized())
-            return
+            for bone in orgs:
+                align_bone_x_axis(self.obj, bone, axis)
 
-        # Orient uarm farm bones
-        chain_y_axis = org_uarm.y_axis + org_farm.y_axis
-        chain_rot_axis = org_uarm.y_axis.cross(chain_y_axis).normalized()  # ik-plane normal axis (rotation)
+        elif self.params.auto_align_extremity:
+            axis = self.vector_without_z(self.get_bone(orgs[2]).z_axis)
 
-        align_bone_x_axis(self.obj, org_uarm.name, chain_rot_axis)
-        align_bone_x_axis(self.obj, org_farm.name, chain_rot_axis)
+            align_bone_z_axis(self.obj, orgs[2], axis)
 
-        # Orient hand
-        align_bone_x_axis(self.obj, org_hand.name, chain_rot_axis)
+    ####################################################
+    # Overrides
 
-    def create_parent(self):
+    def register_switch_parents(self, pbuilder):
+        super().register_switch_parents(pbuilder)
 
-        org_bones = self.org_bones
+        pbuilder.register_parent(self, self.bones.org.main[2], exclude_self=True)
 
-        bpy.ops.object.mode_set(mode='EDIT')
-        eb = self.obj.data.edit_bones
-
-        name = get_bone_name( strip_org( org_bones[0] ), 'mch', 'parent' )
-
-        mch = copy_bone( self.obj, org_bones[0], name )
-        orient_bone( self, eb[mch], 'y' )
-        eb[ mch ].length = eb[ org_bones[0] ].length / 4
-
-        eb[ mch ].parent = eb[ org_bones[0] ].parent
-
-        eb[ mch ].roll = 0.0
-
-        # Add non-MCH main limb control
-        name = get_bone_name(strip_org(org_bones[0]), 'ctrl', 'parent')
-        main_parent = copy_bone(self.obj, org_bones[0], name)
-        eb[main_parent].length = eb[org_bones[0]].length / 4
-        eb[main_parent].parent = None
-        eb[main_parent].roll = 0.0
-
-        # Constraints
-        make_constraint( self, mch, {
-            'constraint'  : 'COPY_ROTATION',
-            'subtarget'   : 'root'
-        })
-
-        make_constraint( self, mch, {
-            'constraint'  : 'COPY_SCALE',
-            'subtarget'   : 'root'
-        })
-
-        # Limb Follow Driver
-        pb = self.obj.pose.bones
-
-        name = 'FK_limb_follow'
-
-        # pb[ mch ][ name ] = 0.0
-        # prop = rna_idprop_ui_prop_get( pb[ mch ], name, create = True )
-        make_property(pb[main_parent], name, 0.0)
-
-        make_driver(pb[mch].constraints[0], "influence", variables=[(self.obj, main_parent, name)])
-
-        size = pb[main_parent].bone.y_axis.length * 10
-        create_gear_widget(self.obj, main_parent, size=size, bone_transform_name=None)
-
-        return [mch, main_parent]
-
-    def create_tweak(self):
-        org_bones = self.org_bones
-
-        bpy.ops.object.mode_set(mode ='EDIT')
-        eb = self.obj.data.edit_bones
-
-        tweaks         = {}
-        tweaks['ctrl'] = []
-        tweaks['mch' ] = []
-
-        # Create and parent mch and ctrl tweaks
-        for i,org in enumerate(org_bones):
-            if i < len(org_bones) - 1:
-                # Create segments if specified
-                for j in range( self.segments ):
-                    # MCH
-                    name = get_bone_name( strip_org(org), 'mch', 'tweak' )
-                    mch = copy_bone( self.obj, org, name )
-
-                    # CTRL
-                    name = get_bone_name( strip_org(org), 'ctrl', 'tweak' )
-                    ctrl = copy_bone( self.obj, org, name )
-
-                    eb[ mch  ].length /= self.segments
-                    eb[ ctrl ].length /= self.segments
-
-                    # If we have more than one segments, place the head of the
-                    # 2nd and onwards at the correct position
-                    if j > 0:
-                        put_bone(self.obj, mch,  eb[ tweaks['mch' ][-1] ].tail)
-                        put_bone(self.obj, ctrl, eb[ tweaks['ctrl'][-1] ].tail)
-
-                    tweaks['ctrl'] += [ ctrl ]
-                    tweaks['mch' ] += [ mch  ]
-
-                    # Parenting the tweak ctrls to mchs
-                    eb[ mch  ].parent = eb[ org ]
-                    eb[ ctrl ].parent = eb[ mch ]
-
-            else: # Last limb bone - is not subdivided
-                name = get_bone_name( strip_org(org), 'mch', 'tweak' )
-                mch = copy_bone( self.obj, org_bones[i-1], name )
-                eb[ mch ].length = eb[org].length / 4
-                put_bone(
-                    self.obj,
-                    mch,
-                    eb[org_bones[i-1]].tail
-                )
-
-                ctrl = get_bone_name( strip_org(org), 'ctrl', 'tweak' )
-                ctrl = copy_bone( self.obj, org, ctrl )
-                eb[ ctrl ].length = eb[org].length / 2
-
-                tweaks['mch']  += [ mch  ]
-                tweaks['ctrl'] += [ ctrl ]
-
-                # Parenting the tweak ctrls to mchs
-                eb[ mch  ].parent = eb[ org ]
-                eb[ ctrl ].parent = eb[ mch ]
-
-        # Scale to reduce widget size and maintain conventions!
-        for mch, ctrl in zip( tweaks['mch'], tweaks['ctrl'] ):
-            eb[ mch  ].length /= 4
-            eb[ ctrl ].length /= 2
-
-        # Constraints
-
-        for i,b in enumerate( tweaks['mch'] ):
-            first  = 0
-            middle = trunc( len( tweaks['mch'] ) / 2 )
-            last   = len( tweaks['mch'] ) - 1
-
-            if i == first or i == middle:
-                make_constraint( self, b, {
-                    'constraint'  : 'COPY_SCALE',
-                    'subtarget'   : 'root'
-                })
-            elif i != last:
-                targets       = []
-                dt_target_idx = middle
-                factor        = 0
-                if i < middle:
-                    targets = [first,middle]
-                else:
-                    targets       = [middle,last]
-                    factor        = self.segments
-                    dt_target_idx = last
-
-                # Use copy transforms constraints to position each bone
-                # exactly in the location respective to its inde

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list