Пример #1
0
    def _makeLayout(self, namer):


        MC.select(cl=1)
        jnts = []
        layoutCtls= []
        rigCtls = []

        #the number of ik controls will really be 1 greater than this, because
        #we will parent the first ik control the the first fk control and hide
        #it
        numIkCtls = self.options.getValue('numIkCtls')
        numJnts = self.options.getValue('numJnts')

        ctlKwargs = {'shape': 'sphere',
                     'color': 'purple',
                     's': [1.5, .5, 1.5]}

        doubleEndPoints=False
        if numIkCtls == 2:
            doubleEndPoints=True

        nurbsObjs = createBeingsSplineObjs(numIkCtls, numJnts, namer=namer,
                                           ctlKwargs = ctlKwargs,
                                           doubleEndPoints=doubleEndPoints)

        jntToks = self.__getToks(bndJnts=True)

        #create a pelvis joint that will remain oriented to the base control
        jnts = nurbsObjs['jnts']
        baseJnt = MC.joint(name=jntToks[0])
        utils.fixInverseScale([baseJnt])
        jnts.insert(0, baseJnt)

        for i in range(len(jnts)):
            jnts[i] = MC.rename(jnts[i], namer(jntToks[i], r='bnd'))
            self.registerBindJoint(jnts[i])



        tipXform = MC.xform(jnts[-1], q=1, t=1, ws=1)
        tipXform[1] = tipXform[1] + 2
        MC.select(jnts[-1])
        tip = MC.joint(p=tipXform,
                 n=namer('tip', r='bnd'))
        jnts.append(tip)

        bindNodesToSurface(jnts[:-1], nurbsObjs['surface'], skipTipOrient=True)
        #MC.orientConstraint(nurbsObjs['ikCtls'][-1], jnts[-2])


        #create ik rig controls
        ikRigCtls = []
        ikToks = self.__getToks(ikCtls=True)
        for i, ctl in enumerate(nurbsObjs['ikCtls']):
            self.registerControl(ctl, 'layout', uk=['ty','tz'])

            kwargs = {'color': 'yellow',
                      'shape': 'square',
                      's': [2, 2, 2]}

            n = namer(ikToks[i], r='ik')

            rigCtl = control.makeControl(n, **kwargs)
            MC.parent(rigCtl, ctl)
            MC.makeIdentity(rigCtl, t=1, r=1, s=1)
            control.setEditable(rigCtl, True)
            self.registerControl(rigCtl, 'rig')
            ikRigCtls.append(rigCtl)


        for i, tok in enumerate(jntToks[1:]):
            kwargs = {'color':'green',
                      'shape':'doublePin',
                      's': [2,2,2]}

            rigCtl = control.makeControl(namer(tok, r='fk'), **kwargs)
            utils.snap(jnts[i+1], rigCtl)
            MC.parent(rigCtl, jnts[i+1])

            control.setEditable(rigCtl, True)
            self.registerControl(rigCtl, 'rig')


        #make a tip joint control
        tipCtl = control.makeControl(namer('tip_layout'),
                                     shape='cube',
                                     s=[.75, .75, .75],
                                     color='purple')
        utils.snap(tip, tipCtl)
        MC.parent(tipCtl, nurbsObjs['ikCtls'][-1])
        self.registerControl(tipCtl, 'layout', uk=['ty', 'tz'])
        MC.pointConstraint(tipCtl, jnts[-1])
        MC.aimConstraint(tipCtl, jnts[-2],
                         aimVector = [0,1,0],
                         upVector = [1,0,0],
                         worldUpVector=[1,0,0])
Пример #2
0
    def _makeLayout(self, namer):
        jntCnt =  self.options.getValue('numBones') + 1

        MC.select(cl=1)
        jnts = []
        layoutCtlZeros = []
        rigCtls = []
        ups = []
        for i in range(jntCnt):
            jnt = MC.joint(p=[0,i*2, 0], n=namer(r='bnd', alphaSuf=i))
            self.registerBindJoint(jnt)
            jnts.append(jnt)
            if i < jntCnt -1:
                rigCtl = control.makeControl(namer(r='fk', alphaSuf=i), color='green',
                                         shape='cube')

                control.setEditable(rigCtl, True)
                self.registerControl(rigCtl, 'rig')
                rigCtls.append(rigCtl)

            layoutCtl = control.makeControl(namer('layout_ctl', r='fk', alphaSuf=i),
                                            color='purple', shape='sphere')

            if i < (jntCnt-1):
                upCtl = control.makeControl(namer('layout_twist_ctl', r='fk', alphaSuf=i),
                                            color='blue', shape='triangle', t=[1.5,0,0],
                                            s=[.2, .2, .2])

                up = MC.createNode('transform', n=namer('layout_twist_up', r='fk', alphaSuf=i))
                MC.parent(up, upCtl)
                MC.setAttr('%s.t' % up, 2, 0, 0, type='double3')
                ups.append(up)
                utils.snap(jnt, upCtl)
                MC.parent(upCtl, layoutCtl)
                self.registerControl(upCtl, 'layout', uk=['ry'])

            utils.snap(jnt, layoutCtl)
            utils.snap(jnt, rigCtl)

            layoutCtlZeros.append(utils.insertNodeAbove(layoutCtl))
            MC.parent(rigCtl, jnt)


            MC.pointConstraint(layoutCtl, jnt)

            utils.fixJointConstraints(jnt)


            self.registerControl(layoutCtl, 'layout', uk=['t'])


            MC.select(jnt)

        MC.select(cl=1)

        #aim each fkControl at the next one
        for i in range(len(layoutCtlZeros)-1):


            nextCtl = MC.listRelatives(layoutCtlZeros[i+1])[0]
            thisZero = layoutCtlZeros[i]
            thisCtl = MC.listRelatives(thisZero)[0]

            control.centeredCtl(jnts[i], jnts[i+1], rigCtls[i])

            upVec = [1,0,0]

            MC.aimConstraint(nextCtl, thisCtl,
                             aimVector=[0,1,0],
                             upVector=[1,0,0],
                             worldUpVector=[1,0,0])

            MC.aimConstraint(nextCtl, jnts[i],
                             aimVector=[0,1,0],
                             upVector=upVec,
                             worldUpType='object',
                             worldUpObject = ups[i])

            utils.fixJointConstraints(thisCtl)

            lck = ['tx', 'ty', 'tz', 'rx', 'rz', 'sx', 'sy', 'sz']
            for attr in lck:
                par = MC.listRelatives(ups[i], parent=1)[0]
                #MC.setAttr('%s.%s' % (ups[i], attr) , l=1)
                MC.setAttr('%s.%s' % (par, attr) , l=1)
Пример #3
0
    def _makeLayout(self, namer):
        """
        build the layout
        """
        positions = [(0,0,0),
                     (10,0,-2),
                     (20,0,0),
                     (25,0,0)]
        MC.select(cl=1)

        jnts = {}
        layoutCtls = {}
        #create/register bind joints and layout controls
        for i, tok in enumerate(self.__toks):
            jnts[tok] = MC.joint(p=positions[i], n = namer.name(r='bnd', d=tok))
            self.registerBindJoint(jnts[tok])
            layoutCtls[tok] = control.makeControl(namer.name(d='%s_layout' % tok, r='ctl'),
                                               shape='sphere', color='purple')

            self.registerControl(layoutCtls[tok], 'layout', uk=['t', 'r'])
            utils.snap(jnts[tok], layoutCtls[tok], orient=False)
            MC.select(jnts[tok])

        for i, tok in enumerate(self.__toks):
            utils.orientJnt(jnts[tok], aimVec=[0,1,0], upVec=[1,0,0], worldUpVec=[1,0,0])

            MC.setAttr('%s.s' % layoutCtls[tok], l=1)
            if tok != 'ankle':
                MC.setAttr('%s.r' % layoutCtls[tok], l=1)

        for tok in self.__toks[:-1]:
            MC.pointConstraint(layoutCtls[tok], jnts[tok], mo=False)

        #create up-vec locs
        l = MC.spaceLocator(n=namer.name(d='orientor_loc'))[0]
        MC.pointConstraint(layoutCtls['uparm'], layoutCtls['hand'], l)
        MC.aimConstraint(layoutCtls['loarm'], l,
                          aimVector=[0,0,1], upVector=[1,0,0],
                          worldUpType='object',
                          worldUpObject = layoutCtls['uparm'])
        MC.setAttr('%s.v' % l, 0)

        #aim the uparm at the loarm
        MC.aimConstraint(layoutCtls['loarm'], jnts['uparm'], aimVector=[0,1,0],
                         upVector=[0,0,1],
                         worldUpType='object',
                         worldUpObject=l)

        #aim the loarm at the hand
        MC.aimConstraint(layoutCtls['hand'], jnts['loarm'], aimVector=[0,1,0],
                         upVector=[0,0,1],
                         worldUpType='object',
                         worldUpObject=l)


        #setup hand twist
        MC.parent(layoutCtls['hand_tip'], layoutCtls['hand'])

        handTwistNode = MC.createNode('transform', n=namer.name(d='hand_orientor_loc'))
        MC.parent(handTwistNode, layoutCtls['hand'])
        MC.makeIdentity(handTwistNode, t=1, r=1, s=1)
        MC.aimConstraint(layoutCtls['hand_tip'], handTwistNode,
                         aimVector=[0,1,0],
                         upVector=[0,0,1],
                         worldUpVector=[0,0,1])


        handUpCtl = control.makeControl(namer('hand_up', r='ctl'),
                                                    shape='cube',
                                                    s=[.75, .75, .75],
                                                    color='blue')
        self.registerControl(handUpCtl, 'layout', uk=['t', 'r'])
        MC.parent(handUpCtl, handTwistNode)
        MC.makeIdentity(handUpCtl, t=1, r=1, s=1)
        MC.setAttr('%s.tz' % handUpCtl, 3)


        aimVec = [0,1,0]
        upVec = [0,0,1]
        # if self.options.getValue('side') == 'rt':
        #     upVec = [1,0,0]

        MC.aimConstraint(layoutCtls['hand_tip'], jnts['hand'],
                         aimVector=aimVec,
                         upVector=upVec,
                         worldUpType='object',
                         worldUpObject=handUpCtl)

        MC.pointConstraint(layoutCtls['hand_tip'], jnts['hand_tip'])


        #hand
        handCtl = control.makeControl(namer.name(d='ctl', r='ik'),
                                              shape='jack',
                                              color='red',
                                              xformType='joint',
                                              s=[2,2,2])


        control.setEditable(handCtl, True)

        self.registerControl(handCtl, 'rig')

        par = utils.insertNodeAbove(handCtl)
        utils.snap(jnts['hand'], par, orient=False)

        MC.parentConstraint(jnts['hand'], par, mo=True)


        #pole vector
        pvPar = MC.createNode('transform', name=namer('pv_par_pvPar'))
        MC.pointConstraint(layoutCtls['uparm'], layoutCtls['hand'], pvPar)




        MC.aimConstraint(layoutCtls['hand'], pvPar, aimVector=[0,1,0],
                         upVector=[1,0,0],
                         worldUpType='object',
                         worldUpObject=layoutCtls['loarm'])

        pv = control.makeControl(namer('polevec', r='ik'),
                                       shape='diamond',
                                       color='salmon',
                                       s=[.5,.5,.5])
        MC.parent(pv, pvPar)
        MC.makeIdentity(pv, t=1, r=1, s=1)

        control.setEditable(pv, True)
        self.registerControl(pv, 'rig')

        zero = utils.insertNodeAbove(pv)

        dst = MC.createNode('distanceBetween', name=namer('pv_dst'))
        MC.connectAttr('%s.worldMatrix' % pvPar, '%s.im1' % dst)
        MC.connectAttr('%s.worldMatrix' % layoutCtls['uparm'], '%s.im2' % dst)
        mdn = MC.createNode('multiplyDivide', n=namer('pv_dst_mdn'))
        MC.connectAttr('%s.distance' % dst, '%s.input1X' % mdn)
        MC.setAttr('%s.input2X' % mdn, 2)
        MC.connectAttr("%s.outputX" % mdn, "%s.tx" % zero)
        MC.setAttr('%s.tz' % pv, l=1)

        #FK
        for tok, jnt in jnts.items():
            if tok == 'hand_tip':
                continue
            ctl = control.makeControl(namer.name(tok, r='fk'),
                                shape='cube',
                                color='yellow',
                                s=[2,2,2])

            control.setEditable(ctl, True)
            utils.snap(jnt, ctl)

            self.registerControl(ctl, ctlType='rig')

            #center and scale it
            childJnt = jnts[self.__toks[self.__toks.index(tok)+1]]
            control.centeredCtl(jnt, childJnt, ctl)

        return namer
Пример #4
0
    def _makeRig(self, namer):

        #gather the bind joints and fk controls that were built
        bndJnts = []
        fkCtls = []
        for tok in self.__toks[:-1]:
            fkCtl = namer(tok, r='fk')
            if not MC.objExists(fkCtl):
                raise RuntimeError('%s does not exist'  % fkCtl)
            fkCtls.append(fkCtl)


        for tok in self.__toks:
            jnt = namer(tok, r='bnd')
            if not MC.objExists(jnt):
                raise RuntimeError('%s does not exist'  % jnt)
            bndJnts.append(jnt)
            if tok != 'hand_tip':
                self.setPlugNode('bnd_%s' % tok, jnt)

        MC.makeIdentity(bndJnts, apply=True, r=1, t=1, s=1)

        ikCtl = namer('ctl', r='ik')
        if not MC.objExists(ikCtl):
            raise RuntimeError("cannot find '%s'" % ikCtl)
        MC.makeIdentity(ikCtl, apply=True, r=1, s=1)

        # o = utils.Orientation()
        # side = self.options.getValue('side')
        # if side == 'rt':
        #     o.setAxis('aim', 'negY')
        #     o.reorientJoints(bndJnts)
        #     MC.setAttr('%s.rx' % ikCtl,
        #                 (MC.getAttr('%s.rx' % ikCtl) * -1))

        #     MC.setAttr('%s.rz' % ikCtl,
        #                (180 + MC.getAttr('%s.rz' % ikCtl) % 360))


        side = self.options.getValue('side')
        if side == 'rt':
            o = utils.Orientation()
            otherO = utils.Orientation()
            otherO.setAxis('aim', 'posX')
            otherO.setAxis('up', 'posY')

            o.setAxis('aim', 'posX')
            o.setAxis('up', 'negY')
            origOrient = MC.getAttr('%s.jointOrient' % ikCtl)[0]
            newOrient = o.newAngle(origOrient, origOrient=otherO)
            MC.setAttr('%s.jointOrient' % ikCtl, *newOrient, type='double3')


        fkCtls = control.setupFkCtls(bndJnts[:-1], fkCtls, self.__toks[:-1], namer)
        for ctl in fkCtls:
            control.setLockTag(ctl, uk=['r'])


        namer.setTokens(r='ik')
        ikJnts = utils.dupJntList(bndJnts, self.__toks, namer)
        for jnt in ikJnts:
            control.setLockTag(jnt, uu=['r', 't', 's'])

        MC.setAttr('%s.v' % ikJnts[0], 0)



        #keep the ik hand control rotated
        par = MC.createNode('transform', n='%s_zero' % ikCtl)
        utils.snap(ikCtl, par, orient=False)
        MC.parent(ikCtl, par)

        self.setNodeCateogry(par, 'ik')

        MC.addAttr(ikCtl, ln='fkIk', min=0, max=1, dv=1, k=1)
        fkIkRev = utils.blendJointChains(fkCtls, ikJnts[:-1], bndJnts[:-1],
                                         '%s.fkIk' % ikCtl, namer)
        control.setLockTag(ikCtl, uk=['t', 'r', 'fkIk'])

        for ctl in fkCtls:
            MC.connectAttr('%s.outputX' % fkIkRev, '%s.v' % ctl)

        ikHandle, ikEff = MC.ikHandle(sj=ikJnts[0],
                                      ee=ikJnts[2],
                                      solver='ikRPsolver',
                                      n=namer.name('ikh'))
        MC.parent(ikHandle, ikCtl)
        MC.setAttr('%s.v' % ikHandle, 0)

        #setup pole vec for ik ctl
        pv = namer('polevec', r='ik')
        MC.setAttr('%s.r' % pv, 0, 0, 0, type='double3')
        control.setLockTag(ikCtl, uk=['t'])

        MC.poleVectorConstraint(pv, ikHandle)
        MC.parent(utils.insertNodeAbove(pv), ikCtl)


        #orient the hand to the ik control
        handOrientJnt = MC.duplicate(ikJnts[2], rc=1, po=1)[0]
        handOrientJnt = MC.rename(handOrientJnt, namer('handorient_space', r='ik'))
        MC.parent(handOrientJnt, ikCtl)
        MC.setAttr('%s.v' % handOrientJnt, 0)
        MC.orientConstraint(handOrientJnt, ikJnts[2])
Пример #5
0
    def _makeLayout(self, namer):
        """
        build the layout
        """
        positions = [(0,20,0),
                     (0,12,1),
                     (0,3,0),
                     (0,0,3),
                     (0,0,6),
                     (0,0,8)]

        legJoints = {}
        legCtls = {}
        MC.select(cl=1)

        #create/register bind joints and layout controls
        for i, tok in enumerate(self.__toks):
            legJoints[tok] = MC.joint(p=positions[i], n = namer.name(r='bnd', d=tok))
            self.registerBindJoint(legJoints[tok])

            legCtls[tok] = control.makeControl(namer.name(d='%s_layout' % tok, r='ctl'),
                                               shape='sphere',
                                               color='purple')

            if tok == 'ankle':
                self.registerControl(legCtls[tok], 'layout', uk=['t', 'ry'])
            elif tok in ['ball', 'toe']:
                self.registerControl(legCtls[tok], 'layout', uk=['ty', 'tz'])
            elif tok == 'toetip':
                self.registerControl(legCtls[tok], 'layout', uk=['tz'])
            else:
                self.registerControl(legCtls[tok], 'layout', uk=['t'])

            utils.snap(legJoints[tok], legCtls[tok], orient=False)
            MC.select(legJoints[tok])

        for i, tok in enumerate(self.__toks):
            utils.orientJnt(legJoints[tok], aimVec=[0,1,0], upVec=[1,0,0], worldUpVec=[1,0,0])


        ankleCtl = legCtls['ankle']
        for tok in ['ball', 'toe']:
            ctl = legCtls[tok]
            MC.parent(ctl, ankleCtl)

        MC.parentConstraint(legCtls['ankle'], utils.insertNodeAbove(legCtls['toetip']),
                            skipTranslate=['y'], mo=True)

        MC.pointConstraint(legCtls['hip'], legJoints['hip'], mo=False)
        MC.pointConstraint(legCtls['knee'], legJoints['knee'], mo=False)
        MC.pointConstraint(legCtls['ankle'], legJoints['ankle'], mo=True)

        #create up-vec locs
        l = MC.spaceLocator(n=namer.name(d='orientor_loc'))[0]
        MC.pointConstraint(legCtls['hip'], legCtls['ankle'], l)
        MC.aimConstraint(legCtls['knee'], l,
                          aimVector=[0,0,1], upVector=[1,0,0],
                          worldUpType='object',
                          worldUpObject = legCtls['hip'])
        MC.setAttr('%s.v' % l, 0)

        #aim the hip at the knee
        MC.aimConstraint(legCtls['knee'], legJoints['hip'], aimVector=[0,1,0],
                         upVector=[1,0,0],
                         worldUpVector=[0,-1,0],
                         worldUpType='objectRotation',
                         worldUpObject=l)

        #aim the knee at the ankle
        MC.aimConstraint(legCtls['ankle'], legJoints['knee'], aimVector=[0,1,0],
                         upVector=[1,0,0],
                         worldUpVector=[0,-1,0],
                         worldUpType='objectRotation',
                         worldUpObject=l)

        #setup IK
        for pr in [('ankle', 'ball'), ('ball', 'toe'), ('toe', 'toetip')]:
            handle = MC.ikHandle(solver='ikSCsolver', sj=legJoints[pr[0]],
                                 ee=legJoints[pr[1]],
                                 n=namer.name(d='%s_ikh' % pr[1]))[0]
            MC.parent(handle, legCtls[pr[1]])
            MC.makeIdentity(handle)
            MC.setAttr("%s.v" % handle, 0)
            utils.createStretch(legCtls[pr[0]], legCtls[pr[1]], legJoints[pr[0]], namer)

        #kneeIK
        toeIkCtl = control.makeControl(namer('toe_ctl', r='ik'),
                                        shape='circle',
                                        color='red',
                                        s=[2,2,2])
        toeLayoutCtl = control.makeControl(namer('toe_layout_ctl', r='ik'),
                                                 shape='cube',
                                                 color='purple',
                                                 s=[2, .75, 2])
        control.setEditable(toeIkCtl, True)
        self.registerControl(toeIkCtl, 'rig')

        self.registerControl(toeLayoutCtl, 'layout', uk=['tx', 'tz'])
        MC.parent(toeIkCtl, toeLayoutCtl)


        utils.snap(legJoints['toe'], toeLayoutCtl, orient=False)
        par = utils.insertNodeAbove(toeLayoutCtl)
        pm.pointConstraint(legJoints['toe'], par, mo=False, skip='y')

        #heel
        heelCtl = control.makeControl(namer.name(d='heel_ctl', r='ik'),
                                      shape='jack',
                                      color='red',
                                      s=[2,2,2])

        heelLayoutCtl = control.makeControl(namer('heel_layout_ctl', r='ik'),
                                                 shape='cube',
                                                 color='purple',
                                                 s=[3, 1, 3])
        self.registerControl(heelLayoutCtl, 'layout', uk=['tx', 'tz'])
        MC.parent(heelCtl, heelLayoutCtl)

        utils.snap(legJoints['ball'], heelLayoutCtl, orient=False)
        MC.setAttr("%s.tz" % heelLayoutCtl, -.5)
        par = utils.insertNodeAbove(heelLayoutCtl)
        pm.parentConstraint(legCtls['ankle'], par, mo=True, skipTranslate=['y'])
        control.setEditable(heelCtl, True)
        self.registerControl(heelCtl, 'rig')

        #FK
        for tok, jnt in legJoints.items():
            if tok == 'toetip':
                continue
            ctl = control.makeControl(namer.name(tok, r='fk'),
                                shape='cube',
                                color='green',
                s=[2,2,2])
            control.setEditable(ctl, True)
            utils.snap(jnt, ctl)

            self.registerControl(ctl, ctlType='rig')

            #center and scale it
            childJnt = legJoints[self.__toks[self.__toks.index(tok)+1]]
            control.centeredCtl(jnt, childJnt, ctl)

        return namer
Пример #6
0
    def _makeLayout(self, namer):
        neckJntCnt =  self.options.getValue('numNeckBones')

        MC.select(cl=1)
        jnts = []
        layoutCtls= []
        rigCtls = []

        #the number of ik controls will really be 1 greater than this, because
        #we will parent the first ik control the the first fk control and hide
        #it
        numIkCtls = self.options.getValue('numIkCtls') + 1
        numJnts = self.options.getValue('numNeckBones') + 1

        ctlKwargs = {'shape': 'sphere',
                     'color': 'purple',
                     's': [6.5, 1.5, 6.5]}
        doubleEndPoints=False
        if numIkCtls == 2:
            doubleEndPoints=True
        nurbsObjs = createBeingsSplineObjs(numIkCtls, numJnts, namer=namer,
                                           ctlKwargs = ctlKwargs,
                                           doubleEndPoints=doubleEndPoints, ctlSep=4)
        del ctlKwargs

        #rename & regiser joints and add a 'tip' joint
        toks = self.__getToks()
        jnts = []
        for i, jnt in enumerate(nurbsObjs['jnts']):
            jnt = MC.rename(jnt, namer(toks[i], r='bnd'))
            jnts.append(jnt)
            self.registerBindJoint(jnt)

        tipXform = MC.xform(jnts[-1], q=1, t=1, ws=1)
        tipXform[1] = tipXform[1] + 10
        MC.select(jnts[-1])
        tip = MC.joint(p=tipXform,
                 n=namer(toks[-1], r='bnd'))
        jnts.append(tip)
        self.registerBindJoint(tip)

        bindNodesToSurface(jnts[:-1], nurbsObjs['surface'], skipTipOrient=True)
        #MC.orientConstraint(nurbsObjs['ikCtls'][-1], jnts[-2])


        ikRigCtls = []
        for i, ctl in enumerate(nurbsObjs['ikCtls']):
            self.registerControl(ctl, 'layout', uk=['ty', 'tz'])
            if i > 0:
                kwargs = {'color': 'yellow',
                          'shape': 'sphere',
                          's': [2,2,2]}
                if i < (numIkCtls-1):
                    n = namer('ctl', r='ik', alphaSuf=i-1)
                else:
                    n = namer('head_ctl', r='ik')
                    kwargs['s'] = [4,1,4]

                rigCtl = control.makeControl(n, **kwargs)

                if i == (numIkCtls-1):
                    control.centeredCtl(jnts[-2], jnts[-1], rigCtl)

                MC.parent(rigCtl, ctl)
                MC.makeIdentity(rigCtl, t=1, r=1, s=1)
                control.setEditable(rigCtl, True)

                self.registerControl(rigCtl, 'rig')
                ikRigCtls.append(rigCtl)



        rigCtls = []
        for i, tok in enumerate(toks):

            if tok != 'head_tip':
                kwargs = {'color':'green',
                          'shape':'cube',
                          's': [5,1,5]}

                rigCtl = control.makeControl(namer(tok, r='fk'), **kwargs)
                self.registerControl(rigCtl, 'rig')
                rigCtls.append(rigCtl)
                utils.snap(jnts[i], rigCtl)
                MC.parent(rigCtl, jnts[i])

                #control.centeredCtl(jnts[i], jnts[i+1], rigCtl)
                control.setEditable(rigCtl, True)

        #make a tip joint control
        tipCtl = control.makeControl(namer('tip_layout'),
                                     shape='cube',
                                     s=[1,1,1],
                                     color='blue')
        utils.snap(jnts[-1], tipCtl)
        MC.parent(tipCtl, nurbsObjs['ikCtls'][-1])
        self.registerControl(tipCtl, 'layout')
        MC.pointConstraint(tipCtl, jnts[-1])
        MC.aimConstraint(tipCtl, jnts[-2],
                         aimVector = [0,1,0],
                         upVector = [1,0,0],
                         worldUpVector=[1,0,0])


        return
Пример #7
0
    def _makeRig(self, namer):

        neckJntCnt =  self.options.getValue('numNeckBones') + 1
        ikCtlCnt =  self.options.getValue('numIkCtls')
        toks = self.__getToks()
        bndJnts = [namer(t, r='bnd') for t in toks]
    

        MC.makeIdentity(bndJnts, apply=True, r=1, t=1, s=1)

        namer.setTokens(r='fk')
        #fkJnts = utils.dupJntList(bndJnts, toks, namer)

        fkCtls = [namer(t, r='fk') for t in toks[:-1]]
        fkCtls = control.setupFkCtls(bndJnts[:-1], fkCtls, toks[:-1], namer)
        for ctl in fkCtls:
            control.setLockTag(ctl, uk=['r'])

        for i, tok in enumerate(toks[:-1]):
            self.setPlugNode(tok, fkCtls[i])

        namer.setTokens(r='ik')
        ikJnts = utils.dupJntList(bndJnts, toks, namer)
        MC.setAttr('%s.v' % ikJnts[0], 0)

        ikCtls = []
        for i in range(ikCtlCnt):
            if i < (ikCtlCnt-1):
                n = namer('ctl', r='ik', alphaSuf=i)
                utils.insertNodeAbove(n)
            else:
                n = namer('head_ctl', r='ik')
            ikCtls.append(n)


        baseIkCtl = MC.createNode('transform', n=namer('base', r='ik'))
        utils.snap(bndJnts[0], baseIkCtl, orient=False)
        ikCtls.insert(0, baseIkCtl)

        for ctl in ikCtls:
            control.setLockTag(ctl, uk=['r', 't'])

        tmp = MC.createNode('transform', n="TMP")
        utils.parentShape(tmp, ikCtls[-1], deleteChildXform=False)
        utils.snap(bndJnts[-2], ikCtls[-1])
        utils.parentShape(ikCtls[-1], tmp)
        utils.insertNodeAbove(ikCtls[-1])

        #doubling the cvs on the end allows us to build a curve with only 2 controls,
        #but causes popping otherwise.  Only use if needed
        doubleEndPoints = False
        if ikCtlCnt == 1:
            doubleEndPoints = True

        crv = curveFromNodes(ikCtls, name=namer('ikspline_crv'), doubleEndPoints=doubleEndPoints )
        srf = surfaceFromNodes(ikCtls, name=namer('ikspline_srf'), doubleEndPoints=doubleEndPoints)

        bindControlsToShape(ikCtls, crv,  doubleEndPoints=doubleEndPoints)
        bindControlsToShape(ikCtls, srf,  doubleEndPoints=doubleEndPoints)

        ikNode, ikHandle = setupSpineIkNode(ikCtls, ikJnts[:-1], nodeName='splinik', namer=namer,
                         crv=crv, surf=srf)
        self.setNodeCateogry(ikNode, 'dnt')
        MC.setAttr("%s.v" % ikNode, 0)
        #tag this node so the master connect the uniform scale
        core.Root.tagInputScaleAttr(ikNode, 'inputScaleAmt')

        MC.addAttr(ikCtls[-1], ln='fkIk', dv=0, k=1, min=0, max=1)
        MC.addAttr(ikCtls[-1], ln='stretchAmt', dv=0, k=1, min=0, max=1)
        MC.addAttr(ikCtls[-1], ln='evenStretchAmt', dv=0, k=1, min=0, max=1)

        control.setLockTag(ikCtls[-1], uk=['fkIk', 'stretchAmt', 'evenStretchAmt'])

        MC.connectAttr('%s.stretchAmt' % ikCtls[-1], '%s.stretchAmt' % ikNode)
        MC.connectAttr('%s.evenStretchAmt' % ikCtls[-1], '%s.evenStretchAmt' % ikNode)


        ikReverse = utils.blendJointChains(fkCtls, ikJnts[:-1], bndJnts[:-1], '%s.fkIk' % ikCtls[-1], namer)
        for ctl in fkCtls:
            MC.connectAttr('%s.outputX' % (ikReverse), '%s.v' % ctl)
        for ctl in ikCtls[1:-1]:
            MC.connectAttr('%s.fkIk' % (ikCtls[-1]), '%s.v' % ctl)