[Bf-extensions-cvs] [e5e67819] master: Rigify: experimental super chain cleanup

Lucio Rossi noreply at git.blender.org
Thu Mar 7 20:33:54 CET 2019


Commit: e5e678198854d3ba62744120d10babf2592a5565
Author: Lucio Rossi
Date:   Thu Mar 7 20:33:29 2019 +0100
Branches: master
https://developer.blender.org/rBAe5e678198854d3ba62744120d10babf2592a5565

Rigify: experimental super chain cleanup

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

M	rigify/rigs/experimental/super_chain.py

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

diff --git a/rigify/rigs/experimental/super_chain.py b/rigify/rigs/experimental/super_chain.py
index 42b37682..565e5bdc 100644
--- a/rigify/rigs/experimental/super_chain.py
+++ b/rigify/rigs/experimental/super_chain.py
@@ -1,27 +1,17 @@
 import bpy
 from mathutils import Vector
-from math import pi
-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, put_bone, org, align_bone_y_axis, align_bone_x_axis, align_bone_z_axis
 from ...utils import strip_org, make_deformer_name, connected_children_names
-from ...utils import create_circle_widget, create_sphere_widget, create_widget, create_chain_widget
-from ...utils import MetarigError, make_mechanism_name, create_cube_widget
+from ...utils import create_chain_widget
+from ...utils import make_mechanism_name, create_cube_widget
 from rna_prop_ui import rna_idprop_ui_prop_get
 from ..limbs.limb_utils import get_bone_name
 
-script = """
-controls = [%s]
-torso    = '%s'
-
-if is_selected( controls ):
-    layout.prop( pose_bones[ torso ], '["%s"]', slider = True )
-    layout.prop( pose_bones[ torso ], '["%s"]', slider = True )
-"""
-
 
 class Rig:
 
     def __init__(self, obj, bone_name, params):
-        """ A simplified version of the torso rig. Basically a connected-DEF chain of bones """
+        """ Chain with pivot Rig """
 
         eb = obj.data.edit_bones
 
@@ -30,40 +20,7 @@ class Rig:
         self.params = params
         self.spine_length = sum([eb[b].length for b in self.org_bones])
         self.bbones = params.bbones
-
-        # Check if user provided the positions of the neck and pivot
-        # if params.neck_pos and params.pivot_pos:
-        #     self.neck_pos  = params.neck_pos
-        #     self.pivot_pos = params.pivot_pos
-        # else:
-        #     raise MetarigError(
-        #         "RIGIFY ERROR: please specify neck and pivot bone positions"
-        #     )
-        #
-        # # Check if neck is lower than pivot
-        # if params.neck_pos <= params.pivot_pos:
-        #     raise MetarigError(
-        #         "RIGIFY ERROR: Neck cannot be below or the same as pivot"
-        #     )
-
-        # if params.control_num:
-        #     self.control_num = params.control_num
-        # else:
-        #     raise MetarigError(
-        #         "RIGIFY ERROR: please specify number of controls"
-        #     )
-        #
-        # if params.control_num > round(len(eb)/2):
-        #     raise MetarigError(
-        #         "RIGIFY ERROR: Number of controls must be <= number of bones/2"
-        #     )
-
-        # TODO:
-        # Limit neck_pos prop  to 1 --> num of bones - 1 (last is head)
-        # Limit pivot_pos prop to 2 --> num of bones (must leave place for lower torso)
-
-        # if params.tail_pos:
-        #     self.tail_pos = params.tail_pos
+        self.SINGLE_BONE = (len(self.org_bones) == 1)
 
         # Assign values to tweak layers props if opted by user
         if params.tweak_extra_layers:
@@ -71,61 +28,23 @@ class Rig:
         else:
             self.tweak_layers = None
 
-        # Report error of user created less than the minimum of 4 bones for rig
-        # if len(self.org_bones) <= 4:
-        #     raise MetarigError(
-        #         "RIGIFY ERROR: invalid rig structure" % (strip_org(bone_name))
-        #     )
-
-
-    # def build_bone_structure( self ):
-    #     """ Divide meta-rig into lists of bones according to torso rig anatomy:
-    #         Neck --> Upper torso --> Lower torso --> Tail (optional) """
-    #
-    #     if self.pivot_pos and self.neck_pos:
-    #
-    #         neck_index  = self.neck_pos  - 1
-    #         pivot_index = self.pivot_pos - 1
-    #
-    #         tail_index = 0
-    #         if 'tail_pos' in dir(self):
-    #             tail_index  = self.tail_pos  - 1
-    #
-    #         neck_bones        = self.org_bones[neck_index::]
-    #         upper_torso_bones = self.org_bones[pivot_index:neck_index]
-    #         lower_torso_bones = self.org_bones[tail_index:pivot_index]
-    #
-    #         tail_bones        = []
-    #         if tail_index:
-    #             tail_bones = self.org_bones[::tail_index+1]
-    #
-    #         return {
-    #             'neck'  : neck_bones,
-    #             'upper' : upper_torso_bones,
-    #             'lower' : lower_torso_bones,
-    #             'tail'  : tail_bones
-    #         }
-    #
-    #     else:
-    #         return 'ERROR'
-
     def orient_bone(self, eb, axis, scale, reverse=False):
         v = Vector((0, 0, 0))
 
         setattr(v, axis, scale)
 
         if reverse:
-            tail_vec = v @ self.obj.matrix_world
+            tail_vec = v * self.obj.matrix_world
             eb.head[:] = eb.tail
             eb.tail[:] = eb.head + tail_vec
         else:
-            tail_vec = v @ self.obj.matrix_world
+            tail_vec = v * self.obj.matrix_world
             eb.tail[:] = eb.head + tail_vec
 
-    def create_pivot(self, bones=None, pivot=None):
+    def create_pivot(self, pivot=None):
         """ Create the pivot control and mechanism bones """
 
-        org_bones  = self.org_bones
+        org_bones = self.org_bones
 
         bpy.ops.object.mode_set(mode='EDIT')
         eb = self.obj.data.edit_bones
@@ -143,78 +62,43 @@ class Rig:
 
         ctrl_name = get_bone_name(prefix, 'ctrl', 'pivot')
         ctrl_name = copy_bone(self.obj, pivot_name, ctrl_name)
-        ctrl_eb = eb[ ctrl_name ]
+        ctrl_eb = eb[ctrl_name]
 
-        self.orient_bone( ctrl_eb, 'y', self.spine_length / 2.5 )
+        self.orient_bone(ctrl_eb, 'y', self.spine_length / 2.5)
 
-        pivot_loc = eb[pivot_name].head + ((eb[pivot_name].tail - eb[pivot_name].head)/2)*(len(org_bones)%2)
+        pivot_loc = eb[pivot_name].head + ((eb[pivot_name].tail - eb[pivot_name].head)/2)*(len(org_bones) % 2)
 
-        put_bone( self.obj, ctrl_name, pivot_loc)
+        put_bone(self.obj, ctrl_name, pivot_loc)
 
         v = eb[org_bones[-1]].tail - eb[org_bones[0]].head  # Create a vector from head of first ORG to tail of last
         v.normalize()
         v_proj = eb[org_bones[0]].y_axis.dot(v)*v   # projection of first ORG to v
         v_point = eb[org_bones[0]].y_axis - v_proj  # a vector co-planar to first ORG and v directed out of the chain
 
-        if v_point.magnitude < eb[org_bones[0]].y_axis.magnitude*1e-03: #if v_point is too small it's not usable
+        if v_point.magnitude < eb[org_bones[0]].y_axis.magnitude*1e-03:     # if v_point is too small it's not usable
             v_point = eb[org_bones[0]].x_axis
 
         if self.params.tweak_axis == 'auto':
             align_bone_y_axis(self.obj, ctrl_name, v)
             align_bone_z_axis(self.obj, ctrl_name, -v_point)
         elif self.params.tweak_axis == 'x':
-            align_bone_y_axis(self.obj, ctrl_name, Vector((1,0,0)))
-            align_bone_x_axis(self.obj, ctrl_name, Vector((0,0,1)))
+            align_bone_y_axis(self.obj, ctrl_name, Vector((1, 0, 0)))
+            align_bone_x_axis(self.obj, ctrl_name, Vector((0, 0, 1)))
         elif self.params.tweak_axis == 'y':
-            align_bone_y_axis(self.obj, ctrl_name, Vector((0,1,0)))
-            align_bone_x_axis(self.obj, ctrl_name, Vector((1,0,0)))
+            align_bone_y_axis(self.obj, ctrl_name, Vector((0, 1, 0)))
+            align_bone_x_axis(self.obj, ctrl_name, Vector((1, 0, 0)))
         elif self.params.tweak_axis == 'z':
-            align_bone_y_axis(self.obj, ctrl_name, Vector((0,0,1)))
-            align_bone_x_axis(self.obj, ctrl_name, Vector((1,0,0)))
+            align_bone_y_axis(self.obj, ctrl_name, Vector((0, 0, 1)))
+            align_bone_x_axis(self.obj, ctrl_name, Vector((1, 0, 0)))
 
         return {
-            'ctrl' : ctrl_name
-        }#Todo modify following
-
-
-        org_bones  = self.org_bones
-        pivot_name = org_bones[pivot-1]
-
-        bpy.ops.object.mode_set(mode ='EDIT')
-        eb = self.obj.data.edit_bones
-
-        # Create torso control bone
-        torso_name = 'torso'
-        ctrl_name = copy_bone(self.obj, pivot_name, torso_name)
-        ctrl_eb = eb[ctrl_name]
-
-        self.orient_bone( ctrl_eb, 'y', self.spine_length / 2.5 )
-
-        # Create mch_pivot
-        mch_name = make_mechanism_name( 'pivot' )
-        mch_name = copy_bone(self.obj, ctrl_name, mch_name)
-        mch_eb = eb[mch_name]
-
-        mch_eb.length /= 4
-
-        # Positioning pivot in a more usable location for animators
-        if hasattr(self, 'tail_pos') and self.tail_pos > 0:
-            pivot_loc = eb[org_bones[pivot-1]].head
-        else:
-            pivot_loc = (eb[org_bones[0]].head + eb[org_bones[0]].tail) / 2
-
-        put_bone(self.obj, ctrl_name, pivot_loc)
-
-        return {
-            'ctrl': ctrl_name,
-            'mch': mch_name
+            'ctrl': ctrl_name
         }
 
     def create_deform(self):
         org_bones = self.org_bones
 
         bpy.ops.object.mode_set(mode='EDIT')
-        eb = self.obj.data.edit_bones
 
         def_bones = []
         for o in org_bones:
@@ -237,155 +121,7 @@ class Rig:
 
         return def_bones
 
-    def create_neck( self, neck_bones ):
-        org_bones = self.org_bones
-
-        bpy.ops.object.mode_set(mode ='EDIT')
-        eb = self.obj.data.edit_bones
-
-        # Create neck control
-        neck    = copy_bone( self.obj, org(neck_bones[0]), 'neck' )
-        neck_eb = eb[ neck ]
-
-        # Neck spans all neck bones (except head)
-        neck_eb.tail[:] = eb[ org(neck_bones[-1]) ].head
-
-        # Create head control
-        head = copy_bone( self.obj, org(neck_bones[-1]), 'head' )
-
-        # MCH bones
-        # Neck MCH stretch
-        mch_str = copy_bone( self.obj, neck, make_mechanism_name('STR-neck') )
-
-        # Neck MCH rotation
-        mch_neck = copy_bone(
-            self.obj, neck, make_mechanism_name('ROT-neck')
-        )
-
-        self.orient_bone( eb[mch_neck], 'y', self.spine_length / 10 )
-
-        # Head MCH rotation
-        mch_head = copy_bone(
-            self.obj, head, make_mechanism_name('ROT-head')
-        )
-
-        self.orient_bone( eb[mch_head], 'y', sel

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list