[Bf-extensions-cvs] [1f9e3bf] blender-v2.78-release: Pitchipoy: added super_arm and super_leg w root/parent switch

Lucio Rossi noreply at git.blender.org
Mon Sep 26 14:33:51 CEST 2016


Commit: 1f9e3bfa3b8bc5fe082d7182b422c788691653a1
Author: Lucio Rossi
Date:   Mon Sep 12 16:14:15 2016 +0200
Branches: blender-v2.78-release
https://developer.blender.org/rBA1f9e3bfa3b8bc5fe082d7182b422c788691653a1

Pitchipoy: added super_arm and super_leg w root/parent switch

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

A	rigify/rigs/pitchipoy/limbs/super_arm.py
A	rigify/rigs/pitchipoy/limbs/super_leg.py

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

diff --git a/rigify/rigs/pitchipoy/limbs/super_arm.py b/rigify/rigs/pitchipoy/limbs/super_arm.py
new file mode 100644
index 0000000..cddf59c
--- /dev/null
+++ b/rigify/rigs/pitchipoy/limbs/super_arm.py
@@ -0,0 +1,1294 @@
+import bpy, re
+from ..super_widgets import create_hand_widget
+from   .ui             import create_script
+from   .limb_utils     import *
+from   mathutils       import Vector
+from   ....utils       import copy_bone, flip_bone, put_bone, create_cube_widget
+from   ....utils       import strip_org, make_deformer_name, create_widget
+from   ....utils       import create_circle_widget, create_sphere_widget
+from   ....utils       import MetarigError, make_mechanism_name, org
+from   ....utils       import create_limb_widget, connected_children_names
+from   rna_prop_ui     import rna_idprop_ui_prop_get
+from   ..super_widgets import create_ikarrow_widget
+from   math            import trunc
+
+extra_script = """
+controls = [%s]
+ctrl    = '%s'
+
+if is_selected( controls ):
+    layout.prop( pose_bones[ ctrl ], '["%s"]')
+    layout.prop( pose_bones[ ctrl ], '["%s"]', slider = True )
+"""
+
+class Rig:
+    def __init__(self, obj, bone_name, params):
+        """ Initialize arm rig and key rig properties """
+        self.obj       = obj
+        self.params    = params
+
+        self.org_bones = list(
+            [bone_name] + connected_children_names(obj, bone_name)
+            )[:3]  # The basic limb is the first 3 bones
+
+        self.segments  = params.segments
+        self.bbones    = params.bbones
+        self.limb_type = params.limb_type
+        self.rot_axis  = params.rotation_axis
+
+        # Assign values to tweak/FK layers props if opted by user
+        if params.tweak_extra_layers:
+            self.tweak_layers = list(params.tweak_layers)
+        else:
+            self.tweak_layers = None
+
+        if params.fk_extra_layers:
+            self.fk_layers = list(params.fk_layers)
+        else:
+            self.fk_layers = None
+
+
+    def create_parent( self ):
+
+        org_bones = self.org_bones
+
+        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
+
+        # 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 )
+
+        prop["min"]         = 0.0
+        prop["max"]         = 1.0
+        prop["soft_min"]    = 0.0
+        prop["soft_max"]    = 1.0
+        prop["description"] = name
+
+        drv = pb[ mch ].constraints[ 0 ].driver_add("influence").driver
+
+        drv.type = 'AVERAGE'
+        var = drv.variables.new()
+        var.name = name
+        var.type = "SINGLE_PROP"
+        var.targets[0].id = self.obj
+        var.targets[0].data_path = pb[ mch ].path_from_id() + \
+                                   '[' + '"' + name + '"' + ']'
+
+        return mch
+
+
+    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 (self.limb_type == 'paw'):
+            #    idx_stop = len(org_bones)
+            #else:
+            #    idx_stop = len(org_bones) - 1
+
+            if i < len(org_bones) - 1:
+            # if i < idx_stop:
+                # 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
+
+        # Contraints
+
+        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 index (between
+                # the two edges)
+                make_constraint( self, b, {
+                    'constraint'  : 'COPY_TRANSFORMS',
+                    'subtarget'   : tweaks['ctrl'][targets[0]]
+                })
+                make_constraint( self, b, {
+                    'constraint'  : 'COPY_TRANSFORMS',
+                    'subtarget'   : tweaks['ctrl'][targets[1]],
+                    'influence'   : (i - factor) / self.segments
+                })
+                make_constraint( self, b, {
+                    'constraint'  : 'DAMPED_TRACK',
+                    'subtarget'   : tweaks['ctrl'][ dt_target_idx ],
+                })
+
+        # Ctrl bones Locks and Widgets
+        pb = self.obj.pose.bones
+        for t in tweaks['ctrl']:
+            pb[t].lock_rotation = True, False, True
+            pb[t].lock_scale    = False, True, False
+
+            create_sphere_widget(self.obj, t, bone_transform_name=None)
+
+            if self.tweak_layers:
+                pb[t].bone.layers = self.tweak_layers
+
+        return tweaks
+
+
+    def create_def( self, tweaks ):
+        org_bones = self.org_bones
+
+        bpy.ops.object.mode_set(mode ='EDIT')
+        eb = self.obj.data.edit_bones
+
+        def_bones = []
+        for i,org in enumerate(org_bones):
+
+            if i < len(org_bones) - 1:
+                # Create segments if specified
+                for j in range( self.segments ):
+                    name = get_bone_name( strip_org(org), 'def' )
+                    def_name = copy_bone( self.obj, org, name )
+
+                    eb[ def_name ].length /= self.segments
+
+                    # If we have more than one segments, place the 2nd and
+                    # onwards on the tail of the previous bone
+                    if j > 0:
+                         put_bone(self.obj, def_name, eb[ def_bones[-1] ].tail)
+
+                    def_bones += [ def_name ]
+            else:
+                name     = get_bone_name( strip_org(org), 'def' )
+                def_name = copy_bone( self.obj, org, name )
+                def_bones.append( def_name )
+
+        # Parent deform bones
+        for i,b in enumerate( def_bones ):
+            if i > 0: # For all bones but the first (which has no parent)
+                eb[b].parent      = eb[ def_bones[i-1] ] # to previous
+                eb[b].use_connect = True
+
+        # Constraint def to tweaks
+        for d,t in zip(def_bones, tweaks):
+            tidx = tweaks.index(t)
+
+            make_constraint( self, d, {
+                'constraint'  : 'COPY_TRANSFORMS',
+                'subtarget'   : t
+            })
+
+            if tidx != len(tweaks) - 1:
+                make_constraint( self, d, {
+                    'constraint'  : 'DAMPED_TRACK',
+                    'subtarget'   : tweaks[ tidx + 1 ],
+                })
+
+                make_constraint( self, d, {
+                    'constraint'  : 'STRETCH_TO',
+           

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list