Ejemplo n.º 1
0
def create_neck ():

    if mc.objExists( Controllers.HEAD ):
        print 'HEAD ALREADY EXISTS'
        return

    if mc.objExists ( Controllers.NECK ):
        print 'NECK ROOT DRV exists'

    else:
        create_spine ()
    
    distance_x = mc.getAttr ( SpineJoint.HEAD + '.translateX' ) / 4

    _, __, ___, ik_crv, neck_group = rd.create_ikspline( 5, distance_x, 'neck', SpineJoint.NECK, Controllers.GLOBAL )

    mc.parent ( neck_group, Controllers.GLOBAL )

    # Create head
    mc.select ( clear = True )
    head_drv = mc.joint ( name = 'head_DRV' )
    rd.get_position ( head_drv, SpineJoint.HEAD, 0, 1, 1 )

    head_ctl = rd.create_ctrl( 'circle', Controllers.HEAD, 10, Colors.BLUE, option_attr = True, obj_pos = head_drv )

    orient_gp = rd.parent_group( head_ctl, Controllers.HEAD + '_orient_GRP' )
    head_gp = rd.parent_group ( orient_gp, head_ctl + '_GRP' )
    mc.parent ( head_gp, Controllers.GLOBAL )
    mc.parent ( head_drv, head_ctl )

    orient_loc = mc.spaceLocator( name = 'head_orient_pos_LOC' )
    rd.get_position ( orient_loc, 'root_JNT', position = False )

    mc.parent ( orient_loc, Controllers.GLOBAL )

    mc.pointConstraint ( 'neck_CTL_pos_LOC', head_gp )
    mc.orientConstraint ( 'neck_CTL', 'chest_CTL', orient_loc, orient_gp )

    # Skin spline curve
    mc.skinCluster ( DriveJoints.NECK, head_drv, ik_crv, toSelectedBones = True )[0]
Ejemplo n.º 2
0
def create_arm_sys ( side = '_l_' ):
    
    if side == '_l_':
        ik_ctl = Controllers.ARM_LEFT
        clav_ctl = Controllers.CLAVICLE_LEFT
        clavicle_jnt = ArmLeftJoint.CLAVICLE
        clavicle_end = ArmLeftJoint.CLAVICLE_END
        shoulder_jnt = ArmLeftJoint.SHOULDER
        pv_ctl = Controllers.ARM_PV_LEFT
            
    else:
        ik_ctl = Controllers.ARM_RIGHT
        clav_ctl = Controllers.CLAVICLE_RIGHT
        clavicle_jnt = ArmRightJoint.CLAVICLE
        shoulder_jnt = ArmRightJoint.SHOULDER
        clavicle_end = ArmRightJoint.CLAVICLE_END
        pv_ctl = Controllers.ARM_PV_RIGHT
    
    name = 'arm' + side

    ##########################
    #
    # Clavicle Rig

    chest_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_chest_LOC' )[0]
    mc.delete ( mc.pointConstraint ( DriveJoints.CHEST, chest_loc ) )
    mc.move ( 0, 5, 0, relative = True, objectSpace = True, worldSpaceDistance = True )
    mc.parent ( chest_loc, 'arm' + side + 'holder_GRP' )
    
    mc.parent ( 'arm' + side + 'origin_LOC', chest_loc )
    
    colliar_ctl = rd.create_ctrl( 'sphere', clav_ctl, Scales.CLAVICLE, Colors.BLUE, obj_pos = clavicle_jnt )

    colliar_group = rd.parent_group ( colliar_ctl, colliar_ctl.replace ( '_CTL', '_parent_to_chest_GRP' ) )
    rd.parent_group ( colliar_ctl, colliar_ctl.replace ( '_CTL', '_CTL_GRP' ) )
    mc.parent ( colliar_group, chest_loc )

    fk_clavicle = rd.duplicate_bones ( clavicle_jnt, 'JNT1', 'DRV' )

    colliar_jnt = fk_clavicle[0]

    name = name.replace ( 'start', 'end' )

    mc.parent ( colliar_jnt, colliar_group )

    ##########################
    #
    # Wrist Rig
    
    if side == '_l_':
        wrist_ctl = Controllers.WRIST_LEFT
        wrist_jnt = HandLeftJoint.WRIST
    else:
        wrist_ctl = Controllers.WRIST_RIGHT    
        wrist_jnt = HandRightJoint.WRIST
    
    wrist_ctl = rd.create_ctrl( 'fist', wrist_ctl, Scales.HAND, Colors.BLUE, option_attr = 1, obj_pos = wrist_jnt )

    rd.add_attr( wrist_ctl, 'ik', min_max = 'both', min_val = 0, max_val = 1 )
    rd.add_attr( wrist_ctl, 'fk', min_max = 'both', min_val = 0, max_val = 1 )

    node = mc.createNode ( 'reverse', name = wrist_ctl + '_RVS' )
    mc.connectAttr ( wrist_ctl + '.ik', node + '.inputX' )
    mc.connectAttr ( node + '.outputX', wrist_ctl + '.fk' )

    mc.connectAttr ( wrist_ctl + '.ik', 'arm' + side + 'ik_fk_blend_LOC.ik' )

    mc.setAttr ( wrist_ctl + '.fk', lock = True )

    rd.add_attr( wrist_ctl, 'ik_vis', attr_type = 'bool' )
    rd.add_attr( wrist_ctl, 'fk_vis', attr_type = 'bool' )
    rd.add_attr( wrist_ctl, 'ribbon_vis', attr_type = 'bool' )
    
    wrist_follow_gp = rd.parent_group ( wrist_ctl, wrist_ctl.replace ( '_CTL', '_follow_GRP' ) )
    
    mc.orientConstraint( ik_ctl, wrist_follow_gp )
    
    wrist_gp = rd.parent_group ( wrist_follow_gp, wrist_ctl.replace ( '_CTL', '_CTL_GRP' ) )
    wrist_global_gp = rd.parent_group ( wrist_gp, wrist_gp.replace ( '_CTL_GRP', '_GRP' ) )
    mc.parent ( wrist_global_gp, 'arm' + side + 'holder_GRP' )

    mc.select ( shoulder_jnt.replace ( 'JNT', 'BLD'), replace = True )
    child = mc.listRelatives ( children = True )[0]
    child = mc.listRelatives ( child, children = True )[0]

    mc.pointConstraint ( child, wrist_gp )
    
    # pinky_ctl = rd.create_ctrl ( 'circle', pinky_ctl )
    # rd.get_position ( pinky_jnt, 0, 1, 1 )

    # mc.parent ( pinky_ctl, wrist_ctl )
    # rd.parent_group ( pinky_ctl.replace ( '_CTL', '_CTL_GRP' ) )

    ##########################
    #
    # Hand Rig   -------------------> A REPRENDRE ET MODIFIER LA CA NE VA PAS ! REVOIR LE RIG DE BASE

    hand_bones = rd.duplicate_bones ( wrist_jnt, 'JNT1', 'DRV' )

    mc.parent ( hand_bones[0], 'arm' + side + 'holder_GRP'  )
    mc.pointConstraint ( child, hand_bones[0] )
    mc.orientConstraint ( wrist_ctl, hand_bones[0] )

    for bone in hand_bones:
        mc.rename ( bone, bone.replace ( 'END1', 'DRV_END' ) )

    if side == '_l_':
        fingers_list = [ HandLeftJoint.INDEX, HandLeftJoint.MIDDLE, HandLeftJoint.ANNULAR, HandLeftJoint.PINKY ]
    else:
        fingers_list = [ HandRightJoint.INDEX, HandRightJoint.MIDDLE, HandRightJoint.ANNULAR, HandRightJoint.PINKY ]

    for finger in fingers_list :

        finger_bones_list = mc.listRelatives ( finger.replace ( 'JNT', 'DRV' ), allDescendents = True )
        finger_bones_list.append ( finger.replace ( 'JNT', 'DRV' ) )
        finger_bones_list = list ( reversed ( finger_bones_list ) )

        for finger_bone in finger_bones_list:
            mc.select ( finger_bone )
            rd.parent_group ( finger_bone, finger_bone.replace ( 'DRV', 'up_GRP' ) )
            rd.parent_group ( finger_bone, finger_bone.replace ( 'DRV', 'GRP' ) )

        finger_ctl_list = []

        for finger_bone in finger_bones_list:
            finger_ctl = rd.create_ctrl( 'diamond', finger_bone.replace ( '_DRV', '_CTL' ), Scales.FINGER, Colors.SOFT_BLUE, option_attr = True, obj_pos = finger_bone )

            father = mc.listRelatives ( finger_bone, parent = True )
            mc.parent ( finger_ctl, father )
            mc.parent ( finger_bone, finger_ctl )
            
            rd.add_attr( finger_ctl, 'Stretch' )
            mc.setAttr ( finger_ctl + '.Stretch', 0 )

            if len( mc.ls ( '*_END_CTL' ) ) > 0:
                mc.delete ( mc.ls ( '*_END_CTL' ) )

            else:

                if side == '_l_' :
                    mc.connectAttr ( finger_ctl + '.Stretch', finger_bone + '.translateX' )

                elif side == '_r_' :
                    reverse = mc.createNode ( 'reverse', name = finger_ctl.replace ( '_CTL', '_stretch_RVS' ) )
                    mc.connectAttr ( finger_ctl + '.Stretch', reverse + '.inputX' )
                    mc.connectAttr ( reverse + '.outputX', finger_bone + '.translateX' )

                finger_ctl_list.append ( finger_ctl )

        finger_01_list = mc.ls ( '*_01_CTL' )

        for ctl in finger_ctl_list:
            if ctl in finger_01_list:
                rd.add_attr( ctl, 'Extra_CTL_vis', attr_type = 'bool' )

                child_group = mc.listRelatives ( ctl, children = True, shapes = False )[1]
                mc.connectAttr ( ctl + '.Extra_CTL_vis', child_group + '.visibility' )
    
    ##########################
    #
    # Other Elements for Arm Rig
    
    mc.select ( shoulder_jnt.replace ( 'JNT', 'IKJ' ) )
    ik_elbow = mc.listRelatives ( children = True )
    
    global_wrist_ori_loc = mc.spaceLocator ( name = 'arm' + side + 'global_wrist_ori_LOC' )[0]
    rd.get_position ( global_wrist_ori_loc, ik_elbow )
    mc.parent ( global_wrist_ori_loc, 'arm' + side + 'holder_GRP' )
    mc.move ( 0, 0, -1, relative = True, objectSpace = True, worldSpaceDistance = True )

    hand_parent_global_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_global_LOC' )[0]
    mc.parent ( hand_parent_global_loc, 'arm' + side + 'holder_GRP' )

    hand_parent_hip_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_hip_LOC' )[0]
    rd.get_position ( hand_parent_hip_loc, SpineJoint.ROOT, orient = False)
    mc.move ( 0, -5, 0, relative = True, objectSpace = True, worldSpaceDistance = True )
    mc.parent ( hand_parent_hip_loc, 'arm' + side + 'holder_GRP' )

    hand_parent_head_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_head_LOC' )[0]
    rd.get_position ( hand_parent_head_loc, SpineJoint.HEAD, orient = False )
    mc.move ( 0, 15, 0, relative = True, objectSpace = True, worldSpaceDistance = True )
    mc.parent ( hand_parent_head_loc, 'arm' + side + 'holder_GRP' )

    hand_parent_object_up_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_object_up_LOC' )[0]
    rd.get_position ( hand_parent_object_up_loc, wrist_jnt )
    mc.parent ( hand_parent_object_up_loc, 'arm' + side + 'holder_GRP' )

    hand_parent_object_loc = mc.spaceLocator ( name = 'arm' + side + 'hand_parent_object_LOC' )[0]
    rd.get_position ( hand_parent_object_loc, wrist_jnt )
    mc.parent ( hand_parent_object_loc, hand_parent_object_up_loc )

    ##########################
    #
    # Other connections
    ik_fk_switch = []
    ik_fk_switch.append ( mc.orientConstraint ( global_wrist_ori_loc, ik_ctl.replace ( 'CTL', 'elbow_CTL'), wrist_gp ) )
    
    ik_fk_switch.append ( mc.orientConstraint ( hand_parent_global_loc, wrist_follow_gp, maintainOffset = True ) )
    
    mc.pointConstraint ( clavicle_end, shoulder_jnt.replace ( 'JNT', 'IKJ') )
    mc.pointConstraint ( clavicle_end, shoulder_jnt.replace ( 'JNT', 'FKJ') )
    mc.orientConstraint ( ik_ctl.replace ( 'CTL', 'shoulder_CTL'), shoulder_jnt.replace ( 'JNT', 'FKJ') )
    mc.orientConstraint ( clav_ctl, clavicle_jnt.replace ( 'JNT', 'DRV' ) )
    mc.pointConstraint ( clav_ctl, clavicle_jnt.replace ( 'JNT', 'DRV' ) )
                         
    mc.pointConstraint ( clavicle_end, shoulder_jnt.replace ( 'JNT', 'BLD') )
    rd.get_position( 'arm' + side + 'Stretch_01_LOC', clavicle_end )
    mc.parent ( 'arm' + side + 'Stretch_01_LOC', clavicle_end )
    rd.get_position ( 'arm' + side + 'Stretch_02_LOC', ik_ctl.replace ( 'CTL', 'IKH' ) )
    mc.parent ( 'arm' + side + 'Stretch_02_LOC', ik_ctl.replace ( 'CTL', 'IKH' ) )
    
    constraint = ( mc.parentConstraint( ik_ctl, hand_parent_global_loc, pv_ctl.replace ( 'CTL', 'GRP'), maintainOffset = True ) )[0]
    rd.add_attr( pv_ctl, 'PV_follow', attr_type = 'enum', enum = ['hand','global'] )
    
    rvs = mc.createNode ( 'reverse', name = pv_ctl.replace ( '_CTL', '_follow_RVS' ) )
    mc.connectAttr ( pv_ctl + '.PV_follow', rvs + '.inputX' )
    
    mc.connectAttr ( pv_ctl + '.PV_follow', constraint + '.' + mc.listConnections ( constraint + '.target[1].targetParentMatrix', d = 0, s = 1 )[0] + 'W1' )
    mc.connectAttr ( rvs + '.outputX', constraint + '.' + mc.listConnections ( constraint + '.target[0].targetParentMatrix', d = 0, s = 1 )[0] + 'W0' )
    
    ##########################
    #
    # Arm IK/FK switch Rig

    for obj in ik_fk_switch :

        mc.connectAttr ( wrist_ctl + '.ik' , obj[0] + '.' + mc.listConnections ( obj[0] + '.target[0].targetParentMatrix', d = 0, s = 1 )[0] + 'W0' )
        mc.connectAttr ( wrist_ctl + '.fk' , obj[0] + '.' + mc.listConnections ( obj[0] + '.target[1].targetParentMatrix', d = 0, s = 1 )[0] + 'W1' )
Ejemplo n.º 3
0
def create_arm_leg ( part = 'arm', side = '_l_' ):
    
    if mc.objExists( Controllers.CHEST ):
        print "SPINE ALREADY exists"
    else:
        create_neck ()
        
    if side == '_l_':
        if part == 'arm':
            pv_ctl = Controllers.ARM_PV_LEFT
            ik_ctl = Controllers.ARM_LEFT
            shoulder_jnt = ArmLeftJoint.SHOULDER
            clavicle_end = ArmLeftJoint.CLAVICLE_END
            
        else:
            pv_ctl = Controllers.LEG_PV_LEFT
            ik_ctl = Controllers.LEG_LEFT
            shoulder_jnt = LegLeftJoint.THIGH
            
    else:
        if part == 'arm':
            pv_ctl = Controllers.ARM_PV_RIGHT
            ik_ctl = Controllers.ARM_RIGHT
            shoulder_jnt = ArmRightJoint.SHOULDER
            clavicle_end = ArmRightJoint.CLAVICLE_END
        else:
            pv_ctl = Controllers.LEG_PV_RIGHT
            ik_ctl = Controllers.LEG_RIGHT
            shoulder_jnt = LegRightJoint.THIGH

    name = part + side
    
    ##########################
    #
    # IK Rig

    ik_arm = rd.duplicate_bones ( shoulder_jnt, 'JNT1', 'IKJ' )

    arm_group = mc.group ( empty = True, name = name + 'holder_GRP' )
    mc.parent ( ik_arm[0], arm_group )
    mc.parent ( arm_group, Controllers.GLOBAL )
    
    mc.select ( arm_group, replace = True )
    mc.addAttr ( longName = 'global_scale_solver', attributeType = 'float' )
    mc.connectAttr ( Controllers.GLOBAL + '.Scale', arm_group + '.global_scale_solver' )

    arm_ctl = rd.create_ctrl( obj_type = 'cube', name = ik_ctl, size = Scales.IK, color = Colors.RED, option_attr = True, obj_pos = ik_arm[2] )
    mc.parent ( arm_ctl, arm_group )
    rd.parent_group( arm_ctl, arm_ctl.replace ( 'CTL', 'up_CTL_GRP' ) )
    rd.parent_group ( arm_ctl, arm_ctl.replace ( 'CTL', 'CTL_GRP' ) )

    rd.add_attr( arm_ctl, 'parent_hand_to', attr_type = 'enum', enum = ['global', 'hip', 'chest', 'head', 'object'] )
    rd.add_attr( arm_ctl, 'stretch', attr_type = 'bool' )
    rd.add_attr( arm_ctl, 'roll' )

    mc.setAttr ( arm_ctl + '.roll', 0 )

    arm_ik_old = mc.ikHandle ( name = arm_ctl.replace ( 'CTL', 'IKH' ), startJoint = ik_arm[0], endEffector = ik_arm[2], solver = 'ikRPsolver' )
    mc.rename ( arm_ik_old[1], arm_ik_old[0].replace ( 'IKH', 'EFF' ) )
    arm_ik = arm_ik_old[0]

    mc.connectAttr ( arm_ctl + '.roll', arm_ik + '.twist' )

    mc.parent ( arm_ik, arm_ctl )
    pv_loc = rd.create_pv()

    mc.move ( 62.266315, 0, 0, relative = True, objectSpace = True, worldSpaceDistance = True )

    mc.parent ( pv_loc, arm_group )

    pv_gp = rd.parent_group ( pv_loc, pv_loc.replace ( 'pv_LOC', 'pv_GRP' ) )

    mc.select ( arm_ik, add = True )
    

    pv_ctl = rd.create_ctrl( 'sphere', pv_ctl, Scales.PV, Colors.RED, obj_pos = pv_loc )
    mc.poleVectorConstraint ( pv_ctl, arm_ik )
    mc.parent ( pv_ctl, pv_gp )
    mc.delete ( pv_loc )

    ##########################
    #
    # FK Rig

    fk_arm = rd.duplicate_bones ( shoulder_jnt, 'JNT1', 'FKJ' )
    print 'FK ARM'
    print fk_arm

    arm_fk_loc = mc.rename ( mc.spaceLocator()[0], part + side + 'origin_LOC' )

    rd.get_position ( arm_fk_loc, fk_arm[0], 0, 1, 0 )
    
    if part == '_l_':
        mc.pointConstraint ( clavicle_end, arm_fk_loc )
    
    mc.parent ( arm_fk_loc, arm_group )
    
    if side == '_l_':
        if part == 'arm':
            arm_fk_ctl = ik_ctl.replace ( 'CTL', 'shoulder_CTL')
        else:
            arm_fk_ctl = ik_ctl.replace ( 'CTL', 'thigh_CTL')
    else: 
        if part == 'arm':
            arm_fk_ctl = ik_ctl.replace ( 'CTL', 'shoulder_CTL')
        else:
            arm_fk_ctl = ik_ctl.replace ( 'CTL', 'thigh_CTL')
            
    arm_fk_ctl = rd.create_ctrl ( 'circle', arm_fk_ctl, Scales.FK, Colors.BLUE, option_attr = 1, obj_pos = fk_arm[0] )

    rd.add_attr( arm_fk_ctl, 'Stretch' )
    rd.add_attr( arm_fk_ctl, 'Gimbal_CTL_Vis', attr_type = 'bool' )
    rd.add_attr( arm_fk_ctl, 'Arm_Orient_By', attr_type = 'enum', enum = ['chest','global'] )
    
    mc.setAttr ( arm_fk_ctl + '.Stretch', 1 )
  
    arm_fk_gimbal_ctl = rd.create_ctrl ( 'circle', arm_fk_ctl.replace ( '_CTL', '_gimbal_CTL' ), Scales.GIMBAL, Colors.YELLOW, obj_pos = fk_arm[0] )
    mc.parent ( arm_fk_gimbal_ctl, arm_fk_loc )

    mc.connectAttr ( arm_fk_ctl + '.Gimbal_CTL_Vis', arm_fk_gimbal_ctl + 'Shape.visibility' )

    rd.parent_group ( arm_fk_gimbal_ctl, arm_fk_gimbal_ctl.replace ( '_gimbal_CTL', '_GRP' ) )

    mc.parent ( arm_fk_ctl, arm_fk_gimbal_ctl )

    if side == '_l_':
        elbow_fk_ctl = ik_ctl.replace ( 'CTL', 'elbow_CTL')
    else: 
        elbow_fk_ctl = ik_ctl.replace ( 'CTL', 'elbow_CTL')

    elbow_fk_ctl = rd.create_ctrl ( 'circle', elbow_fk_ctl, Scales.FK, Colors.BLUE, option_attr = 1, obj_pos = fk_arm[1] )
    
    rd.add_attr( elbow_fk_ctl, 'Stretch' )
    mc.setAttr ( elbow_fk_ctl + '.Stretch', 1 )

    elbow_fk_ctl_group = rd.parent_group ( elbow_fk_ctl, elbow_fk_ctl.replace ( '_CTL', '_CTL_GRP' ) )
    mc.parent ( elbow_fk_ctl_group, arm_fk_ctl )
    mc.parent ( fk_arm[0], arm_group )
    
    print 'FK ARM [0]'
    print ( fk_arm[0] )
    mc.connectAttr ( arm_fk_ctl + '.Stretch', fk_arm[0] + '.scaleX' )

    mc.orientConstraint ( elbow_fk_ctl, fk_arm[1] )
    mc.connectAttr ( elbow_fk_ctl + '.Stretch', fk_arm[1] + '.scaleX' )

    mc.pointConstraint ( fk_arm[1], elbow_fk_ctl_group )
    
    ##########################
    #
    # Arm IK/FK blend Rig

    blend_arm = rd.duplicate_bones ( shoulder_jnt, 'JNT1', 'BLD' )
    
    mc.parent ( blend_arm[0], arm_group )

    ik_fk_switch = []
    ik_fk_switch.append ( mc.orientConstraint ( ik_arm[0], fk_arm[0], blend_arm[0] ))
    ik_fk_switch.append ( mc.parentConstraint ( ik_arm[1], fk_arm[1], blend_arm[1] ))
    ik_fk_switch.append ( mc.parentConstraint ( ik_arm[2], fk_arm[2], blend_arm[2] ))
    
    ##########################
    #
    # Ribbons

    arm_fol_group = mc.group ( name = part + side + 'holder_arm_GRP', empty = True )

    ribbon_ctrl = rd.create_ctrl( 'circle', part + side + 'ribbon_CTL', Scales.RIBBON_CTRL, Colors.YELLOW, option_attr = True, obj_pos = blend_arm[1] )

    rd.add_attr(ribbon_ctrl, 'Elbow_lock', 'float', min_max = 'both', min_val = 0 , max_val = 1)
    mc.setAttr ( ribbon_ctrl + '.Elbow_lock', 0)
    
    ribbon_ctrl_group = rd.parent_group ( ribbon_ctrl, ribbon_ctrl.replace ( 'CTL', 'GRP' ) )
    mc.parent ( ribbon_ctrl_group, arm_fol_group )

    ribbon_constraint = mc.parentConstraint ( blend_arm[1], pv_ctl, ribbon_ctrl_group )

    node = mc.createNode ( 'reverse', name = ribbon_ctrl.replace ( '_CTL', '_RVS' ) )
    mc.connectAttr ( ribbon_ctrl + '.Elbow_lock', node + '.inputX' )

    slot_1 = mc.listConnections ( ribbon_constraint[0] + '.target[0].targetParentMatrix', d = 0, s = 1 )
    slot_2 = mc.listConnections ( ribbon_constraint[0] + '.target[1].targetParentMatrix', d = 0, s = 1 )

    mc.connectAttr ( ribbon_ctrl + '.Elbow_lock' , ribbon_constraint[0] + '.' + slot_2[0] + 'W1' )
    mc.connectAttr ( node + '.outputX' , ribbon_constraint[0] + '.' + slot_1[0] + 'W0' )
    
    if part == 'arm':
        member01 = '_shoulder_'
        member02 = '_elbow_'
    else:
        member01 = '_thigh_'
        member02 = '_knee_'
    
    rd.create_ribbon(part, side, member01, blend_arm[0], ribbon_ctrl, arm_fol_group, Scales.RIBBON, Colors.YELLOW)
    rd.create_ribbon(part, side, member02, ribbon_ctrl, blend_arm[2], arm_fol_group, Scales.RIBBON, Colors.YELLOW)
    
    ##########################
    #
    # Ik fk blend
    
    ik_loc = mc.spaceLocator( name = part + side + 'ik_fk_blend_LOC' )[0]
    mc.parent ( ik_loc, arm_group )
    rd.add_attr( ik_loc, 'ik', min_max = 'both', min_val = 0, max_val = 1 )
    rd.add_attr( ik_loc, 'fk', min_max = 'both', min_val = 0, max_val = 1 )

    node = mc.createNode ( 'reverse', name = ik_loc + '_RVS' )
    mc.connectAttr ( ik_loc + '.ik', node + '.inputX' )
    mc.connectAttr ( node + '.outputX', ik_loc + '.fk' )
    mc.setAttr ( ik_loc + '.fk', lock = True )
    
    for obj in ik_fk_switch :
        slot_1 = mc.listConnections ( obj[0] + '.target[0].targetParentMatrix', d = 0, s = 1 )
        slot_2 = mc.listConnections ( obj[0] + '.target[1].targetParentMatrix', d = 0, s = 1 )

        mc.connectAttr ( ik_loc + '.ik' , obj[0] + '.' + slot_1[0] + 'W0' )
        mc.connectAttr ( ik_loc + '.fk' , obj[0] + '.' + slot_2[0] + 'W1' )

    ##########################
    #
    # Ik stretch
    
    if part == 'arm':
        if side == '_l_':
            num = 209
        else:
            num = 210
    else:
        if side == '_l_':
            num = 211
        else:
            num = 212
                
    dim = mc.distanceDimension( startPoint = [0, num, 0], endPoint = [0, num, 1])
    mc.parent ( dim, arm_group )
    locs = mc.listConnections( dim, source = True )
    print 'LOCS ========'
    print locs
    mc.rename ( locs[0], part + side + 'Stretch_01_LOC' )
    mc.rename ( locs[1], part + side + 'Stretch_02_LOC' )
    dim = mc.rename ( dim, part + side + 'DIST' )
    
    mdn_01 = mc.createNode ( 'multiplyDivide', name = part + side + '01_MDN' )
    mdn_02 = mc.createNode ( 'multiplyDivide', name = part + side + '02_MDN')
    cnd_01 = mc.createNode ( 'condition', name = part + side + '01_CND' )
    cnd_02 = mc.createNode ( 'condition', name = part + side + '02_CND' )
    
    mc.connectAttr ( dim + '.distance', mdn_01 + '.input1X' )
    mc.setAttr ( mdn_01 + '.input2X', mc.getAttr ( ik_arm[1] + '.translateX' ) + mc.getAttr ( ik_arm[2] + '.translateX' ) )
    mc.setAttr ( mdn_01 + '.operation', 2 )
    mc.connectAttr ( mdn_01 + '.outputX', mdn_02 + '.input1X' )
    mc.connectAttr ( arm_group + '.global_scale_solver', mdn_02 + '.input2X' )
    mc.setAttr ( mdn_02 + '.operation', 2 )
    mc.connectAttr ( mdn_02 + '.outputX', cnd_01 + '.firstTerm' )
    mc.setAttr ( cnd_01 + '.secondTerm', 1 )
    mc.setAttr ( cnd_01 + '.operation', 2 )
    mc.connectAttr ( mdn_02 + '.outputX', cnd_01 + '.colorIfTrueR' )
    mc.setAttr ( cnd_01 + '.colorIfFalseR', 1 )
    mc.connectAttr ( ik_ctl + '.stretch', cnd_02 + '.firstTerm' )
    mc.setAttr ( cnd_02 + '.secondTerm', 1 )
    mc.setAttr ( cnd_02 + '.operation', 0 )
    mc.setAttr ( cnd_02 + '.colorIfFalseR', 1 )
    mc.connectAttr ( cnd_01 + '.outColorR', cnd_02 + '.colorIfTrueR' )
    
    mc.connectAttr ( cnd_02 + '.outColorR', ik_arm[0] + '.scaleX' )
    mc.connectAttr ( cnd_02 + '.outColorR', ik_arm[1] + '.scaleX' )
Ejemplo n.º 4
0
def create_spine ():

    # Check if the spine rig already exists
    if mc.objExists( Controllers.ROOT ):
        print 'SPINE ALREADY exists'
        return

    # Check if the base elements exists
    if mc.objExists( Controllers.GLOBAL ):
        print "MAIN ROL exists"

    else:
        create_general()
    
    # Get distance from root to chest
    distance_x = mc.getAttr ( SpineJoint.CHEST + '.translateX' ) / 6

    # Create IK skeleton
    # 7 bones from root to chest
    _, drv_bones, ik_handle, ik_crv, spine_group = rd.create_ikspline( 7, distance_x, 'spine', SpineJoint.ROOT, Controllers.GLOBAL )
    
    # Create root_LOC
    root_loc = mc.spaceLocator( name = 'root_LOC' )[0]
    rd.get_position( root_loc, SpineJoint.ROOT )
    root_group = rd.parent_group( root_loc, root_loc.replace ( 'LOC', 'LOC_GRP' ) )
    mc.parent ( root_group, Controllers.GLOBAL )
    
    # Create root controller
    root_ctl = rd.create_ctrl ( 'cube', Controllers.ROOT, size = 20, color = Colors.BLUE, option_attr = True, obj_pos = SpineJoint.ROOT )
    rd.add_attr( root_ctl, 'Auto_center_pivot', attr_type = 'bool' )

    auto_center_gp = rd.parent_group ( root_ctl, root_ctl + '_auto_center_GRP' )
    root_ctl_gp = rd.parent_group ( auto_center_gp, root_ctl + '_GRP' )
    mc.parent ( root_ctl_gp, Controllers.GLOBAL )
    mc.parent ( spine_group, root_ctl_gp )
    
    # Create hip controller and DRV joint
    hip_ctl = rd.create_ctrl ( 'circle', Controllers.HIP, size = 10, color = Colors.BLUE, obj_pos = SpineJoint.ROOT )

    hip_drv = mc.rename ( mc.duplicate ( drv_bones[0] )[0], 'hip_DRV' )
    rd.get_position ( hip_drv, SpineJoint.ROOT )
    mc.parent ( hip_ctl, root_ctl )
    mc.parent ( hip_drv, hip_ctl )
    
    mdn = mc.createNode ( 'multiplyDivide', name = 'root_auto_center_on_off')
    mc.connectAttr ( mdn + '.outputX', auto_center_gp + '.translateX' )
    mc.connectAttr ( mdn + '.outputY', auto_center_gp + '.translateY' )
    mc.connectAttr ( mdn + '.outputZ', auto_center_gp + '.translateZ' )
    
    # Create spine controllers
    fk_spine_01_ctl = rd.create_ctrl ( 'circle', Controllers.SPINE_FK.replace ( 'CTL', '01_CTL' ), size = 10, color = Colors.BLUE, obj_pos = drv_bones[1] )

    fk_spine_01_gp = rd.parent_group ( fk_spine_01_ctl, fk_spine_01_ctl + '_GRP' )

    fk_spine_02_ctl = rd.create_ctrl ( 'circle', Controllers.SPINE_FK.replace ( 'CTL', '02_CTL' ), size = 10, color = Colors.BLUE, obj_pos = drv_bones[3] )

    fk_spine_02_gp = rd.parent_group ( fk_spine_02_ctl, fk_spine_02_ctl + '_GRP' )
    mc.parent ( fk_spine_02_gp, fk_spine_01_ctl )
    mc.parent ( fk_spine_01_gp, root_ctl )
    
    # Create chest controller
    chest_ctl = rd.create_ctrl ( 'cube', Controllers.CHEST, size = 20, color = Colors.BLUE, option_attr = True, obj_pos = SpineJoint.CHEST )
    chest_gp = rd.parent_group ( chest_ctl, chest_ctl + '_GRP' )

    chest_drv = mc.duplicate ( drv_bones[0] )[0]
    chest_drv = mc.rename ( chest_drv, 'chest_DRV' )
    DriveJoints.CHEST = chest_drv
    rd.get_position ( chest_drv, SpineJoint.CHEST )

    mc.parent ( chest_drv, chest_ctl )
    mc.parent ( chest_gp, fk_spine_02_ctl )
    
    chest_loc = mc.spaceLocator( name = chest_ctl.replace ( 'CTL', 'pos_CTL_LOC' ))
    rd.get_position( chest_loc, SpineJoint.CHEST )
    mc.parent ( chest_loc, chest_ctl )
    
    # Skin spline curve
    mc.skinCluster ( chest_drv, hip_drv, ik_crv, toSelectedBones = True )[0]

    # Twist system
    mc.setAttr ( ik_handle + '.dTwistControlEnable', 1 )
    mc.setAttr ( ik_handle + '.dWorldUpType', 4 )
    mc.connectAttr ( hip_ctl + '.worldMatrix[0]', ik_handle + '.dWorldUpMatrix' )
    mc.connectAttr ( chest_ctl + '.worldMatrix[0]', ik_handle + '.dWorldUpMatrixEnd' )
    
    # Create neck_root DRV
    neck_root_drv = mc.duplicate ( drv_bones[0] )[0]
    neck_root_drv = mc.rename ( neck_root_drv, 'neck_root_DRV' )
    DriveJoints.NECK = neck_root_drv
    rd.get_position ( neck_root_drv, SpineJoint.NECK )
    mc.parent ( neck_root_drv, chest_ctl )

    neck_ctl = rd.create_ctrl( 'circle', Controllers.NECK, 5, Colors.BLUE, obj_pos = neck_root_drv )
    neck_gp = rd.parent_group( neck_ctl, neck_ctl + '_GRP' )

    mc.parent ( neck_gp, chest_ctl )

    p_con = mc.pointConstraint ( SpineJoint.HEAD, SpineJoint.NECK, neck_gp )
    mc.delete ( p_con )

    neck_loc = mc.spaceLocator( name = neck_ctl + '_pos_LOC' )
    rd.get_position( neck_loc, SpineJoint.HEAD )
    mc.parent ( neck_loc, neck_ctl )