コード例 #1
0
ファイル: face.py プロジェクト: guileschool/ls-rigging-tools
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)))
コード例 #2
0
ファイル: face.py プロジェクト: sayehaye3d/ls-rigging-tools
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)))
コード例 #3
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)
コード例 #4
0
ファイル: spine.py プロジェクト: sayehaye3d/ls-rigging-tools
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)