Exemple #1
0
def addElbowFkOffset(pvCtl, ikJnts, handCtl, handIkH, wristDrv, elbowDrnCons):
    '''
    ikJnts - (shoulder, elbow, wrist)
    '''
    prefix_side = ikJnts[0].split('_')[-1] + '_'

    armGrp = mc.group(em=True, n=prefix_side + 'armGrp')
    """
    NOT NEEDED - 
    Wrist control will be directed controlled by pvCtl
    
    elbowFKCtl = cs.ctlCurve(prefix_side+'elbowFKOffset_ctl', 'circle', 0, (0,0,0), size=3, colorId=22, snap=pvCtl)
    mc.parent(elbowFKCtl.home, armGrp)
    abRT.hideAttr(elbowFKCtl.crv, ['tx','ty','tz','sx','sy','sz','v'])
    
    # elbowOffsetCtl is in the pvCtl space
    # mc.parentConstraint(ikJnts[1], elbowFKCtl.grp['space'])
    elbowFKCtl.setSpaces([pvCtl], ['PoleVector'])
    """

    # duplicate joint chain (ikJnts[1:]) don't need the shoulder
    fkOffsetGrp = mc.group(em=True,
                           n=prefix_side + 'armFkOffset_grp',
                           p=armGrp)
    fkOffsetJnts = abRT.duplicateJointHierarchy(
        ikJnts[1:], [jnt.replace('IKX', 'FKOffset') for jnt in ikJnts[1:]],
        fkOffsetGrp)
    '''
    # get transforms from IK chain
    mc.parentConstraint(ikJnts[0], fkOffsetJnts[0]) # position & rotation for shoulder
    mc.connectAttr(ikJnts[1]+'.tx', fkOffsetJnts[1]+'.tx', f=True) # stretchy for upperArm
    mc.connectAttr(ikJnts[2]+'.tx', fkOffsetJnts[2]+'.tx', f=True) # stretchy for lowerArm
    '''

    # get offset rotations & rotations from ctrl
    pos = mc.xform(pvCtl, q=True, ws=True, t=True)
    mc.xform(fkOffsetJnts[0], t=pos, ws=True)
    # abRT.snapToPosition(elbowFKCtl.crv, fkOffsetJnts[0])
    mc.setAttr(fkOffsetJnts[0] + '.jointOrient', 0, 0, 0)
    mc.setAttr(fkOffsetJnts[0] + '.ry', 180)
    mc.setAttr(fkOffsetJnts[1] + '.jointOrient', 0, 0, 0)
    mc.setAttr(fkOffsetJnts[1] + '.r', 0, 0, 0)
    mc.parentConstraint(pvCtl, fkOffsetJnts[0], mo=True)

    # unlock rotations for pvCtl, so that we can rotate the elbow
    mc.setAttr(pvCtl + '.rx', l=False, k=True)
    mc.setAttr(pvCtl + '.ry', l=False, k=True)
    mc.setAttr(pvCtl + '.rz', l=False, k=True)
    """
    NOT NEEDED - 
    since FKOffset will drive the Hand
    the Hand will drive the ikHandle
    the ikHandle drive the ikJoints
    Therefore, the deformation system should still follow the ikJoints
    
    #===========================================================================
    # REPLACE IK DRIVERS WITH FKOFFSET DRIVERS
    #===========================================================================
    
    # 1. WRIST DRV (END OF CHAIN)
    # wristDrv = IKFKAlignedArm_L is responsible for driving the endLoc of the bendyCrv
    # therefore, reparent from IKWrist to FKOffsetWrist
    mc.parent(wristDrv, fkOffsetJnts[2])
    
    # 2. ELBOW DRV (START OF CHAIN)
    # elbowDrvCons is responsible for driving the startLoc of the bendyCrv
    mc.parentConstraint(fkOffsetJnts[1], elbowDrnCons)
    wal = mc.parentConstraint(elbowDrnCons, q=1, wal=1)
    targets = mc.parentConstraint(elbowDrnCons, q=1, tl=1)
    targetIndex = targets.index(ikJnts[1])
    #transfer connection from IK to FKOffset
    inConns = mc.listConnections(elbowDrnCons + '.' + wal[targetIndex], p=1, s=1)
    mc.connectAttr(inConns[0], elbowDrnCons+'.'+wal[2], f=True)
    # remove the old IK target
    mc.parentConstraint(ikJnts[1], elbowDrnCons, e=1, rm=1)
    """

    # add wristFKOffsetCtl
    wristFKCtl = cs.ctlCurve(prefix_side + 'wristFKOffset_ctl',
                             'circle',
                             0, (0, 0, 0),
                             size=2,
                             colorId=22,
                             snap=fkOffsetJnts[1],
                             ctlOffsets=['stretchy', 'IkOri'])
    mc.parent(wristFKCtl.home, armGrp)
    abRT.hideAttr(wristFKCtl.crv, ['tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'v'])

    # wristOffsetCtl is in the FKOffset-elbow space
    # mc.parentConstraint(fkOffsetJnts[1], wristFKCtl.grp['space'])
    wristFKCtl.setSpaces([fkOffsetJnts[0]], ['Elbow'])

    # length for lower arm
    mc.addAttr(pvCtl, ln='length', at='double', dv=0, k=True)
    mc.connectAttr(pvCtl + '.length',
                   wristFKCtl.grp['stretchy'] + '.tx',
                   f=True)
    """
    NOT NEEDED ANYMORE-
    It will just follow orientation of FKOffsetElbow
    
    # wristOffsetCtl's align can be switched between parent (FKOffset) or IKHand
    # place a group aligned properly to hand under IKHand for better orientConstraint (since IKHand is in world-space orientation)
    IkHandAlignTarget = mc.group(em=True, n=handCtl+'_alignTarget')
    rt.parentSnap(IkHandAlignTarget, wristFKCtl.crv)
    mc.parent(IkHandAlignTarget, handCtl)
    rt.spaceSwitchSetup([IkHandAlignTarget, elbowFKCtl.crv], wristFKCtl.grp['IkOri'], wristFKCtl.crv, 'orientConstraint', ['IkHand','FkElbow'])
    """

    # create group to blend between IK & FKOffset
    blendGrp = mc.group(em=True, n=handCtl + '-IKFKOffsetBlend_grp', p=armGrp)
    abRT.snapToPosition(handCtl, blendGrp)
    fkOffsetWristTgt = mc.group(em=True, n=wristFKCtl.crv + '_spaceTgt')
    abRT.snapToPosition(handCtl, fkOffsetWristTgt)
    mc.parent(fkOffsetWristTgt, wristFKCtl.crv)
    mc.setAttr(fkOffsetWristTgt + '.t', 0, 0, 0)
    pCons = mc.parentConstraint(handCtl, fkOffsetWristTgt, blendGrp)[0]
    wal = mc.parentConstraint(pCons, q=True, wal=True)

    # connect blend for fkOffset (together with elbow)
    mc.addAttr(pvCtl,
               ln='elbowFkOffsetViz',
               at='double',
               dv=0,
               min=0,
               max=1,
               k=True)
    mc.connectAttr(pvCtl + '.elbowFkOffsetViz', wristFKCtl.crv + '.v', f=True)
    rev = mc.createNode('reverse', n=pvCtl + '_elbowFkOffsetViz_rev')
    mc.connectAttr(pvCtl + '.elbowFkOffsetViz', rev + '.inputX', f=True)
    mc.connectAttr(rev + '.outputX', pCons + '.' + wal[0], f=True)
    mc.connectAttr(pvCtl + '.elbowFkOffsetViz', pCons + '.' + wal[1], f=True)

    mc.parentConstraint(wristFKCtl.crv, fkOffsetJnts[1],
                        mo=True)  # final rotation & position for wristOffset
Exemple #2
0
def rigEyes():
    # eyeBall - eyeLids intersections
    surf1 = 'LT_eyeBallIntersect_srf_0'
    surf2 = 'CT_eyeBallHeadIntersecter_srf_0'
    jntsNum = 20
    addJntsOnSurfIntersection(surf1, surf2, jntsNum)

    # eyeBall pop controls
    baseTangentMP = ms.addTangentMPTo('LT_eyeBase_mPt',
                                      'LT_eyeTip_mPt',
                                      'z',
                                      default=0.2,
                                      reverse=False)
    tipTangentMP = ms.addTangentMPTo('LT_eyeTip_mPt',
                                     'LT_eyeBase_mPt',
                                     'z',
                                     default=0.2,
                                     reverse=True)
    midMP = ms.addMidMP(baseTangentMP, tipTangentMP, 'LT_eyeBase_mPt',
                        'LT_eyeTip_mPt', (0, 0, 1), (0, 1, 0), 'LT_mid_mPt')
    crv = ms.createSplineMPs(('LT_eyeBase_mPt', baseTangentMP, midMP,
                              tipTangentMP, 'LT_eyeTip_mPt'), 8, 'LT_eyeSpine',
                             (0, 3, 0))

    baseTangentMP = ms.addTangentMPTo('RT_eyeBase_mPt',
                                      'RT_eyeTip_mPt',
                                      'z',
                                      default=0.2,
                                      reverse=False)
    tipTangentMP = ms.addTangentMPTo('RT_eyeTip_mPt',
                                     'RT_eyeBase_mPt',
                                     'z',
                                     default=0.2,
                                     reverse=True)
    midMP = ms.addMidMP(baseTangentMP, tipTangentMP, 'RT_eyeBase_mPt',
                        'RT_eyeTip_mPt', (0, 0, 1), (0, 1, 0), 'RT_mid_mPt')
    crv = ms.createSplineMPs(('RT_eyeBase_mPt', baseTangentMP, midMP,
                              tipTangentMP, 'RT_eyeTip_mPt'), 8, 'RT_eyeSpine',
                             (0, 3, 0))

    #===========================================================================
    # add IK offset ctrls to eyeball
    #===========================================================================
    lfMps = mc.ls(sl=True)
    ctls = []

    # create left controls
    for ctlId in range(0, len(lfMps)):
        ctl = cs.ctlCurve(lfMps[ctlId].replace('_MPJnt_', '_ctl_'),
                          'circle',
                          0,
                          size=6,
                          snap=lfMps[ctlId])
        ctl.setSpaces([lfMps[ctlId]], ['Eye'])
        ctls.append(ctl)

    rtMps = mc.ls(sl=True)
    ctls = []

    # create right controls
    for ctlId in range(0, len(rtMps)):
        ctl = cs.ctlCurve(rtMps[ctlId].replace('_MPJnt_', '_ctl_'),
                          'circle',
                          0,
                          size=6,
                          snap=rtMps[ctlId])
        ctl.setSpaces([rtMps[ctlId]], ['Eye'])
        ctls.append(ctl)

    #===========================================================================
    # Add stretchy volume for eyeBall spine
    #===========================================================================

    stretchAmts = {
        'LT_eyeSpine_ctl_0_space': 10,
        'LT_eyeSpine_ctl_1_space': 9,
        'LT_eyeSpine_ctl_2_space': 8,
        'LT_eyeSpine_ctl_3_space': 5,
        'LT_eyeSpine_ctl_4_space': 3,
        'LT_eyeSpine_ctl_5_space': 1.25,
        'LT_eyeSpine_ctl_6_space': 0,
        'LT_eyeSpine_ctl_7_space': -1
    }

    ms.addVolume('LT_eyeSpine_uniform_crv_crv', stretchAmts)

    stretchAmts = {
        'RT_eyeSpine_ctl_0_space': 10,
        'RT_eyeSpine_ctl_1_space': 9,
        'RT_eyeSpine_ctl_2_space': 8,
        'RT_eyeSpine_ctl_3_space': 5,
        'RT_eyeSpine_ctl_4_space': 3,
        'RT_eyeSpine_ctl_5_space': 1.25,
        'RT_eyeSpine_ctl_6_space': 0,
        'RT_eyeSpine_ctl_7_space': -1
    }

    ms.addVolume('RT_eyeSpine_uniform_crv_crv', stretchAmts)
    #===========================================================================
    # Add control lattice to eyeBall nurbs
    #===========================================================================

    # Create lattice - hard coded to 8 ctls in Z
    eyeSphere = 'LT_eyeBallIntersect_srf_0'
    prefix = 'LT_eyeBallIntersect_'
    ffd, lat, latBase = mc.lattice(eyeSphere,
                                   n=prefix + 'ffd',
                                   oc=True,
                                   dv=(4, 4, 8))
    grp = abRT.groupFreeze(lat)
    rt.transferAttrValues(lat + '.s', grp + '.s', False)
    mc.setAttr(lat + '.s', 1, 1, 1)
    mc.parent(latBase, grp)

    # Create lattice - hard coded to 8 ctls in Z
    eyeSphere = 'RT_eyeBallIntersect_srf_0'
    prefix = 'RT_eyeBallIntersect_'
    ffd, lat, latBase = mc.lattice(eyeSphere,
                                   n=prefix + 'ffd',
                                   oc=True,
                                   dv=(4, 4, 8))
    grp = abRT.groupFreeze(lat)
    rt.transferAttrValues(lat + '.s', grp + '.s', False)
    mc.setAttr(lat + '.s', 1, 1, 1)
    mc.parent(latBase, grp)

    # DO THIS FOR LEFT AND RIGHT SIDES

    # Create joints under each ctl
    ctls = mc.ls(os=True)
    jnts = []
    for eachCtl in ctls:
        mc.select(cl=True)
        jnt = mc.joint(n=eachCtl.replace('_ctl', '_jnt'))
        rt.parentSnap(jnt, eachCtl)
        jnts.append(jnt)
        mc.setAttr(jnt + '.radius', 3)
        mc.setAttr(jnt + '.jointOrient', 0, 0, 0)

    # Weight joints to lattice
    skn = mc.skinCluster(jnts, lat, name=lat + '_skn')[0]
    for jnt in jnts:
        i = jnts.index(jnt)
        mc.skinPercent(skn, lat + '.pt[*][*][%d]' % i, tv=((jnt, 1)))
Exemple #3
0
def rigEyes():
    # eyeBall - eyeLids intersections
    surf1 = 'LT_eyeBallIntersect_srf_0'
    surf2 = 'CT_eyeBallHeadIntersecter_srf_0'
    jntsNum = 20
    addJntsOnSurfIntersection(surf1, surf2, jntsNum)
    
    # eyeBall pop controls
    baseTangentMP = ms.addTangentMPTo('LT_eyeBase_mPt', 'LT_eyeTip_mPt', 'z', default=0.2, reverse=False)
    tipTangentMP = ms.addTangentMPTo('LT_eyeTip_mPt', 'LT_eyeBase_mPt', 'z', default=0.2, reverse=True)
    midMP = ms.addMidMP(baseTangentMP, tipTangentMP, 'LT_eyeBase_mPt', 'LT_eyeTip_mPt', (0,0,1), (0,1,0), 'LT_mid_mPt')
    crv = ms.createSplineMPs(('LT_eyeBase_mPt', baseTangentMP, midMP, tipTangentMP, 'LT_eyeTip_mPt'), 8, 'LT_eyeSpine', (0,3,0))
    
    baseTangentMP = ms.addTangentMPTo('RT_eyeBase_mPt', 'RT_eyeTip_mPt', 'z', default=0.2, reverse=False)
    tipTangentMP = ms.addTangentMPTo('RT_eyeTip_mPt', 'RT_eyeBase_mPt', 'z', default=0.2, reverse=True)
    midMP = ms.addMidMP(baseTangentMP, tipTangentMP, 'RT_eyeBase_mPt', 'RT_eyeTip_mPt', (0,0,1), (0,1,0), 'RT_mid_mPt')
    crv = ms.createSplineMPs(('RT_eyeBase_mPt', baseTangentMP, midMP, tipTangentMP, 'RT_eyeTip_mPt'), 8, 'RT_eyeSpine', (0,3,0))
    
    #===========================================================================
    # add IK offset ctrls to eyeball
    #===========================================================================
    lfMps = mc.ls(sl=True)
    ctls = []
    
    # create left controls
    for ctlId in range(0,len(lfMps)):
        ctl = cs.ctlCurve(lfMps[ctlId].replace('_MPJnt_', '_ctl_'), 'circle', 0, size=6, snap=lfMps[ctlId])
        ctl.setSpaces([lfMps[ctlId]], ['Eye'])
        ctls.append(ctl)
        
    rtMps = mc.ls(sl=True)
    ctls = []
    
    # create right controls
    for ctlId in range(0,len(rtMps)):
        ctl = cs.ctlCurve(rtMps[ctlId].replace('_MPJnt_', '_ctl_'), 'circle', 0, size=6, snap=rtMps[ctlId])
        ctl.setSpaces([rtMps[ctlId]], ['Eye'])
        ctls.append(ctl)
        
    #===========================================================================
    # Add stretchy volume for eyeBall spine
    #===========================================================================
    
    stretchAmts = {'LT_eyeSpine_ctl_0_space':10,
                'LT_eyeSpine_ctl_1_space':9,
                'LT_eyeSpine_ctl_2_space':8,
                'LT_eyeSpine_ctl_3_space':5,
                'LT_eyeSpine_ctl_4_space':3,
                'LT_eyeSpine_ctl_5_space':1.25,
                'LT_eyeSpine_ctl_6_space':0,
                'LT_eyeSpine_ctl_7_space':-1}
    
    ms.addVolume('LT_eyeSpine_uniform_crv_crv', stretchAmts)
    
    stretchAmts = {'RT_eyeSpine_ctl_0_space':10,
                'RT_eyeSpine_ctl_1_space':9,
                'RT_eyeSpine_ctl_2_space':8,
                'RT_eyeSpine_ctl_3_space':5,
                'RT_eyeSpine_ctl_4_space':3,
                'RT_eyeSpine_ctl_5_space':1.25,
                'RT_eyeSpine_ctl_6_space':0,
                'RT_eyeSpine_ctl_7_space':-1}
    
    ms.addVolume('RT_eyeSpine_uniform_crv_crv', stretchAmts)
    #===========================================================================
    # Add control lattice to eyeBall nurbs
    #===========================================================================
    
    # Create lattice - hard coded to 8 ctls in Z
    eyeSphere = 'LT_eyeBallIntersect_srf_0'
    prefix = 'LT_eyeBallIntersect_'
    ffd, lat, latBase = mc.lattice(eyeSphere, n=prefix+'ffd', oc=True, dv=(4,4,8))
    grp = abRT.groupFreeze(lat)
    rt.transferAttrValues(lat+'.s', grp+'.s', False)
    mc.setAttr(lat+'.s',1,1,1)
    mc.parent(latBase, grp)
    
    # Create lattice - hard coded to 8 ctls in Z
    eyeSphere = 'RT_eyeBallIntersect_srf_0'
    prefix = 'RT_eyeBallIntersect_'
    ffd, lat, latBase = mc.lattice(eyeSphere, n=prefix+'ffd', oc=True, dv=(4,4,8))
    grp = abRT.groupFreeze(lat)
    rt.transferAttrValues(lat+'.s', grp+'.s', False)
    mc.setAttr(lat+'.s',1,1,1)
    mc.parent(latBase, grp)
    
    # DO THIS FOR LEFT AND RIGHT SIDES
    
    # Create joints under each ctl
    ctls = mc.ls(os=True)
    jnts = []
    for eachCtl in ctls:
        mc.select(cl=True)
        jnt = mc.joint(n=eachCtl.replace('_ctl', '_jnt'))
        rt.parentSnap(jnt, eachCtl)
        jnts.append(jnt)
        mc.setAttr(jnt+'.radius', 3)
        mc.setAttr(jnt+'.jointOrient', 0,0,0)
        
    # Weight joints to lattice
    skn = mc.skinCluster(jnts, lat, name=lat+'_skn')[0]
    for jnt in jnts:
        i = jnts.index(jnt)
        mc.skinPercent(skn, lat+'.pt[*][*][%d]'%i, tv=((jnt, 1)))
Exemple #4
0
def buildSpineRig(hipMP, headMP, cogCtl, masterCtl):
    '''
    Set up motion system for the spine rig
    
    Return: (spineDrvCrv, spineTwistCrv)
    '''

    #===========================================================================
    # CREATE CONTROLS
    #===========================================================================
    # hip
    hipCtl = cs.ctlCurve('CT_hip_ctl',
                         'cube',
                         1,
                         colorId=22,
                         snap=hipMP,
                         ctlOffsets=['space'])
    mc.setAttr(hipCtl.crv + '.s', 0.3, 1, 1)
    mc.makeIdentity(hipCtl.crv, a=True, s=True)

    # spine-shaper
    spineCtl = cs.ctlCurve('CT_spine_ctl',
                           'circle',
                           0,
                           colorId=22,
                           size=18,
                           ctlOffsets=['point', 'orient'])

    # head
    headCtl = cs.ctlCurve('CT_head_ctl',
                          'cube',
                          1,
                          colorId=22,
                          snap=headMP,
                          ctlOffsets=['space'])
    mc.setAttr(headCtl.crv + '.s', 0.3, 1, 1)
    mc.makeIdentity(headCtl.crv, a=True, s=True)

    # group controls nicely
    ctrlGrp = mc.group(hipCtl.home,
                       spineCtl.home,
                       headCtl.home,
                       n='CT_control_grp_0')

    #===========================================================================
    # CREATE DEBUG GRP - to toggle visibility of "under-the-hood" stuff
    #===========================================================================

    debugGrp = mc.group(em=True, n='CT_debug_grp')
    abRT.hideAttr(debugGrp,
                  ['tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'rx', 'ry', 'rz', 'v'])

    #===========================================================================
    # ADD TANGENT LOCS
    #===========================================================================

    hipTangentMP = ms.addTangentMPTo(hipCtl.crv,
                                     headCtl.crv,
                                     'x',
                                     default=0.1,
                                     reverse=False)
    headTangentMP = ms.addTangentMPTo(headCtl.crv,
                                      hipCtl.crv,
                                      'x',
                                      default=0.5,
                                      reverse=True)

    #===========================================================================
    # ADD MID POINT for spine-shaper control
    #===========================================================================
    midMP = ms.addMidMP(hipTangentMP, headTangentMP, hipCtl.crv, headCtl.crv,
                        (1, 0, 0), (0, 1, 0), 'CT_spineMid_mPt')
    spineCrvs, spineMPs = ms.createSplineMPs(
        (hipCtl.crv, hipTangentMP, spineCtl.crv, headTangentMP, headCtl.crv),
        12, 'CT_spine', (0, 5, 0))

    #===========================================================================
    # add SQUASH AND STRETCH to spineMPs
    #===========================================================================
    stretchAmts = {}
    for eachMP in spineMPs:
        stretchAmts[eachMP] = 1.5

    ms.addVolume(spineCrvs[0], stretchAmts)

    #===========================================================================
    # SPACE SWITCHING
    #===========================================================================

    # space switching for hipCtl

    hipAlignTgt = mc.group(em=True, n='CT_hip_alignTarget')
    abRT.snapToPosition(hipCtl.crv, hipAlignTgt)
    cogOffsetLoc = rt.makeOffsetLoc(cogCtl, hipAlignTgt)
    masterOffsetLoc = rt.makeOffsetLoc(masterCtl, hipAlignTgt)
    rt.spaceSwitchSetup((cogOffsetLoc, masterOffsetLoc), hipAlignTgt,
                        hipCtl.crv, 'orientConstraint', ('COG', 'Master'))

    hipSpaceTgt = mc.group(em=True, n='CT_hip_spaceTarget')
    abRT.snapToPosition(hipCtl.crv, hipSpaceTgt)
    rt.spaceSwitchSetup((cogOffsetLoc, masterOffsetLoc), hipSpaceTgt,
                        hipCtl.crv, 'parentConstraint', ('COG', 'Master'))

    mc.pointConstraint(hipSpaceTgt, hipAlignTgt, mo=True)
    mc.parentConstraint(hipAlignTgt, hipCtl.grp['space'], mo=True)

    # space switching for headCtl

    headAlignTgt = mc.group(em=True, n='CT_head_alignTarget')
    abRT.snapToPosition(headCtl.crv, headAlignTgt)
    cogOffsetLoc = rt.makeOffsetLoc(cogCtl, headAlignTgt)
    masterOffsetLoc = rt.makeOffsetLoc(masterCtl, headAlignTgt)
    rt.spaceSwitchSetup((hipCtl.crv, cogOffsetLoc, masterOffsetLoc),
                        headAlignTgt, headCtl.crv, 'orientConstraint',
                        ('Hip', 'COG', 'Master'))

    headSpaceTgt = mc.group(em=True, n='CT_head_spaceTarget')
    abRT.snapToPosition(headCtl.crv, headSpaceTgt)
    rt.spaceSwitchSetup((hipCtl.crv, cogOffsetLoc, masterOffsetLoc),
                        headSpaceTgt, headCtl.crv, 'parentConstraint',
                        ('Hip', 'COG', 'Master'))

    mc.pointConstraint(headSpaceTgt, headAlignTgt, mo=True)
    mc.parentConstraint(headAlignTgt, headCtl.grp['space'], mo=True)

    # group space groups nicely
    spaceGrp = mc.group(hipAlignTgt,
                        hipSpaceTgt,
                        headAlignTgt,
                        headSpaceTgt,
                        n='CT_spaceSwitching_grp')

    # space for spineCtl
    mc.parentConstraint(midMP, spineCtl.space)

    #===========================================================================
    # DRIVE ORIGINAL MPS (to drive the rest of the upper body)
    #===========================================================================
    mc.parentConstraint(hipCtl.crv, hipMP)
    mc.parentConstraint(headCtl.crv, headMP)
Exemple #5
0
def buildSpineRig(hipMP, headMP, cogCtl, masterCtl):
    '''
    Set up motion system for the spine rig
    
    Return: (spineDrvCrv, spineTwistCrv)
    '''
    
    #===========================================================================
    # CREATE CONTROLS
    #===========================================================================
    # hip
    hipCtl = cs.ctlCurve('CT_hip_ctl', 'cube', 1, colorId=22, snap=hipMP, ctlOffsets=['space'])
    mc.setAttr(hipCtl.crv + '.s', 0.3, 1, 1)
    mc.makeIdentity(hipCtl.crv, a=True, s=True)
    
    # spine-shaper
    spineCtl = cs.ctlCurve('CT_spine_ctl', 'circle', 0, colorId=22, size=18, ctlOffsets=['point', 'orient'])
    
    # head
    headCtl = cs.ctlCurve('CT_head_ctl', 'cube', 1, colorId=22, snap=headMP, ctlOffsets=['space'])
    mc.setAttr(headCtl.crv + '.s', 0.3, 1, 1)
    mc.makeIdentity(headCtl.crv, a=True, s=True)
    
    # group controls nicely
    ctrlGrp = mc.group(hipCtl.home, spineCtl.home, headCtl.home, n='CT_control_grp_0')
    
    #===========================================================================
    # CREATE DEBUG GRP - to toggle visibility of "under-the-hood" stuff
    #===========================================================================

    debugGrp = mc.group(em=True, n='CT_debug_grp')
    abRT.hideAttr(debugGrp, ['tx', 'ty', 'tz', 'sx', 'sy', 'sz', 'rx', 'ry', 'rz', 'v'])

    #===========================================================================
    # ADD TANGENT LOCS
    #===========================================================================

    hipTangentMP = ms.addTangentMPTo(hipCtl.crv, headCtl.crv, 'x', default=0.1, reverse=False)
    headTangentMP = ms.addTangentMPTo(headCtl.crv, hipCtl.crv, 'x', default=0.5, reverse=True)
    
    #===========================================================================
    # ADD MID POINT for spine-shaper control
    #===========================================================================
    midMP = ms.addMidMP(hipTangentMP, headTangentMP, hipCtl.crv, headCtl.crv, (1,0,0), (0,1,0), 'CT_spineMid_mPt')
    spineCrvs, spineMPs = ms.createSplineMPs((hipCtl.crv, hipTangentMP, spineCtl.crv, headTangentMP, headCtl.crv), 12, 'CT_spine', (0,5,0))
    
    #===========================================================================
    # add SQUASH AND STRETCH to spineMPs
    #===========================================================================
    stretchAmts = {}
    for eachMP in spineMPs:
        stretchAmts[eachMP] = 1.5
        
    ms.addVolume(spineCrvs[0], stretchAmts)
    
    #===========================================================================
    # SPACE SWITCHING
    #===========================================================================
    
    # space switching for hipCtl

    hipAlignTgt = mc.group(em=True, n='CT_hip_alignTarget')
    abRT.snapToPosition(hipCtl.crv, hipAlignTgt)
    cogOffsetLoc = rt.makeOffsetLoc(cogCtl, hipAlignTgt)
    masterOffsetLoc = rt.makeOffsetLoc(masterCtl, hipAlignTgt)
    rt.spaceSwitchSetup((cogOffsetLoc, masterOffsetLoc), hipAlignTgt, hipCtl.crv, 'orientConstraint', ('COG', 'Master'))
    
    hipSpaceTgt = mc.group(em=True, n='CT_hip_spaceTarget')
    abRT.snapToPosition(hipCtl.crv, hipSpaceTgt)
    rt.spaceSwitchSetup((cogOffsetLoc, masterOffsetLoc), hipSpaceTgt, hipCtl.crv, 'parentConstraint', ('COG', 'Master'))
    
    mc.pointConstraint(hipSpaceTgt, hipAlignTgt, mo=True)
    mc.parentConstraint(hipAlignTgt, hipCtl.grp['space'], mo=True)
    
    # space switching for headCtl
    
    headAlignTgt = mc.group(em=True, n='CT_head_alignTarget')
    abRT.snapToPosition(headCtl.crv, headAlignTgt)
    cogOffsetLoc = rt.makeOffsetLoc(cogCtl, headAlignTgt)
    masterOffsetLoc = rt.makeOffsetLoc(masterCtl, headAlignTgt)
    rt.spaceSwitchSetup((hipCtl.crv, cogOffsetLoc, masterOffsetLoc), headAlignTgt, headCtl.crv, 'orientConstraint', ('Hip', 'COG', 'Master'))
    
    headSpaceTgt = mc.group(em=True, n='CT_head_spaceTarget')
    abRT.snapToPosition(headCtl.crv, headSpaceTgt)
    rt.spaceSwitchSetup((hipCtl.crv, cogOffsetLoc, masterOffsetLoc), headSpaceTgt, headCtl.crv, 'parentConstraint', ('Hip', 'COG', 'Master'))
    
    mc.pointConstraint(headSpaceTgt, headAlignTgt, mo=True)
    mc.parentConstraint(headAlignTgt, headCtl.grp['space'], mo=True)

    # group space groups nicely
    spaceGrp = mc.group(hipAlignTgt, hipSpaceTgt, headAlignTgt, headSpaceTgt, n='CT_spaceSwitching_grp')
    
    # space for spineCtl
    mc.parentConstraint(midMP, spineCtl.space)
    
    #===========================================================================
    # DRIVE ORIGINAL MPS (to drive the rest of the upper body)
    #===========================================================================
    mc.parentConstraint(hipCtl.crv, hipMP)
    mc.parentConstraint(headCtl.crv, headMP)