Example #1
0
    def _makeRig(self, namer):
        jntCnt =  self.options.getValue('numBones') + 1
        toks = ascii_lowercase[:jntCnt]
        bndJnts = [namer(r='bnd', alphaSuf=i) for i in range(jntCnt)]
        for jnt in bndJnts:
            MC.makeIdentity(jnt, apply=True, r=1, s=1, t=1)
        fkCtls = [namer(r='fk', alphaSuf=i) for i in range(jntCnt-1)]


        o = utils.Orientation()
        side = self.options.getValue('side')
        if side == 'rt':
            o.setAxis('aim', 'negY')
            o.reorientJoints(bndJnts)
        

        fkCtls = control.setupFkCtls(bndJnts[:-1], fkCtls, toks[:-1], namer)

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

        MC.delete(bndJnts[0])
        for i, ctl in enumerate(fkCtls):
            self.setPlugNode('fk_%s' % ascii_lowercase[i], ctl)
Example #2
0
    def _makeRig(self, namer):

        jntCnt =  self.options.getValue('numJnts')
        ikCtlCnt =  self.options.getValue('numIkCtls')
        jntToks = self.__getToks(bndJnts=True)
        ctlToks = self.__getToks(ikCtls=True)

        bndJnts = [namer(t, r='bnd') for t in jntToks]

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

        namer.setTokens(r='fk')

        fkCtls = [namer(t, r='fk') for t in jntToks[1:]]
        fkCtls = control.setupFkCtls(bndJnts[1:], fkCtls, jntToks[1:], namer)
        for ctl in fkCtls:
            control.setLockTag(ctl, uk=['rx', 'ry', 'rz'])

        for i, tok in enumerate(jntToks):
            self.setPlugNode(tok, bndJnts[i])

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

        ikCtls = []

        for tok in ctlToks:
            n = namer(tok, r='ik')
            utils.insertNodeAbove(n)
            control.setLockTag(n, uk=['r', 't'])
            ikCtls.append(n)
            self.setPlugNode(tok, n)

        #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 = setupSpineIkNode(ikCtls, ikJnts, nodeName='splinik', namer=namer,
                         crv=crv, surf=srf)

        self.setNodeCateogry(ikNode, 'dnt')
        MC.setAttr("%s.v" % ikNode, 0)


        #parent the fk control to the ik control
        MC.parent(fkCtls[0], ikCtls[0])
        utils.fixInverseScale(fkCtls[0])

        #constrain the pelvis jnt to the first ik control
        MC.parentConstraint(ikCtls[0], bndJnts[0])
        MC.scaleConstraint(ikCtls[0], bndJnts[0])

        #tag this node so the master connect the uniform scale
        core.Root.tagInputScaleAttr(ikNode, 'inputScaleAmt')

        MC.addAttr(ikCtls[-1], ln='fkIk', dv=1, 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)


        #parent the ikCtls
        parentToFirst = []
        parentToLast = []

        numParentedCtlsPerSide = (ikCtlCnt/2)-1

        parentToFirst = ikCtls[1:1+numParentedCtlsPerSide]
        parentToFirst = ikCtls[-1:-1-numParentedCtlsPerSide- ikCtlCnt % 2]

        _logger.debug('parentToFirst: %s' % parentToFirst)
        _logger.debug('parentToLast: %s' % parentToLast)        
        for node in parentToFirst:
            zero = MC.listRelatives(node, parent=1)[0]
            MC.parent(zero, ikCtls[0])

        for node in parentToLast:
            zero = MC.listRelatives(node, parent=1)[0]
            MC.parent(zero, ikCtls[-1])


        ikReverse = utils.blendJointChains(fkCtls, ikJnts, 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)
Example #3
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)

        MC.makeIdentity(bndJnts, apply=True, r=1, t=1, s=1)
        for jnt in bndJnts:
            control.setLockTag(jnt, uu=['t', 'r', 's'])

        for i, tok in enumerate(self.__toks[:3]):
            self.setPlugNode('bnd_%s' % tok, bndJnts[i])

        o = utils.Orientation()
        side = self.options.getValue('side')
        if side == 'rt':
            o.setAxis('aim', 'negY')
            o.reorientJoints(bndJnts)

        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)
        MC.setAttr('%s.v' % ikJnts[0], 0)


        ikCtl = namer('heel_ctl', r='ik')
        if not MC.objExists(ikCtl):
            raise RuntimeError("Cannot find '%s'" % ikCtl)

        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)

        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'))

        #use the no-flip setup
        xp = utils.getXProductFromNodes(ikJnts[1],  ikJnts[0], ikJnts[2])
        sp = MC.xform(ikJnts[0], q=1, ws=1, t=1)
        l = MC.spaceLocator()[0]
        MC.xform(l, t=[sp[0] + xp[0], sp[1]+xp[1], sp[2]+xp[2]], ws=1)
        MC.delete(MC.poleVectorConstraint(l, ikHandle))
        MC.delete(l)
        MC.setAttr("%s.twist" % ikHandle, 90)

        MC.addAttr(ikCtl, ln='twist', dv=0, k=1)
        control.setLockTag(ikCtl, uk=['twist'])

        pma = MC.createNode('plusMinusAverage', n=namer('twist_pma'))
        MC.connectAttr("%s.twist" % ikCtl, "%s.input1D[0]" % pma)
        MC.setAttr("%s.input1D[1]" % pma, 90)
        MC.connectAttr("%s.output1D" % pma, "%s.twist" % ikHandle)

        del l, sp, xp


        ##set up the reverse foot
        #create the ik hanldes
        ikHandles = {}
        names = ['ankle', 'ball', 'toe', 'toetip']
        for i in range(len(names)-1):

            startIndex = self.__toks.index(names[i])
            endIndex = self.__toks.index(names[i+1])
            start = names[i]
            end = names[i+1]

            name = namer.name(d='revfoot_%s_to_%s_ikh' % (start, end),
                                 r='ik')
            handle = MC.ikHandle(sj=ikJnts[startIndex], ee=ikJnts[endIndex], n=name, sol='ikSCsolver')
            ikHandles[names[i+1]] = handle[0]
            MC.rename(handle[1], name + '_eff')



        #setup the toe control to have an inverse pivot
        toeCtl = namer('toe_ctl', r='ik')
        MC.connectAttr("%s.fkIk" % ikCtl, "%s.v" % toeCtl)
        
        MC.parent(toeCtl, ikCtl)
        utils.insertNodeAbove(toeCtl)

        toeCtlInv = MC.createNode('transform', n = namer('toe_inv', r='ik'))

        MC.parent(toeCtlInv, toeCtl)


        toeCtlInvMdn = MC.createNode('multiplyDivide', n=namer('toe_inv_mdn', r='ik'))
        MC.connectAttr('%s.t' % toeCtl, '%s.input1' % toeCtlInvMdn)
        MC.setAttr('%s.input2' % toeCtlInvMdn, -1, -1, -1, type='double3')
        MC.connectAttr('%s.output' % toeCtlInvMdn, '%s.t' % toeCtlInv)

        #setup the rev foot joints
        revFootJnts = {}
        revFkToks = ['heel', 'toetip', 'toe', 'ball', 'ankle']
        positions = [ikCtl, bndJnts[-1], bndJnts[-2], bndJnts[-3], bndJnts[-4]]


        MC.select(cl=1)
        for i in range(len(revFkToks)):
            tok = revFkToks[i]
            posNode = positions[i]
            pos = MC.xform(posNode, q=1, t=1, ws=1)
            if i == 1:
                pos[1] = MC.xform(positions[0], q=1, t=1, ws=1)[1]

            j = MC.joint(name=namer('%s_revfoot_jnt' % tok, r='ik'),
                     p = pos )
            revFootJnts[tok] = j
            if i == 0:
                MC.setAttr('%s.v' % j, 0)
        del i, j


        #orient the joints to aim down pos y and up axis along the plane formed by
        #the upper leg
        xp = utils.getXProductFromNodes(ikJnts[1],  ikJnts[0], ikJnts[2])
        for jnt in revFootJnts.values():
            utils.orientJnt(jnt, aimVec=[0,1,0], upVec=[1,0,0], worldUpVec=[xp[0],0,xp[2]])
        del jnt, xp


        MC.parent(revFootJnts['heel'], toeCtlInv)
        MC.parent(ikHandles['toetip'], revFootJnts['toetip'])
        MC.parent(ikHandles['toe'], revFootJnts['toe'])
        MC.parent(ikHandles['ball'], revFootJnts['ball'])
        MC.parent(ikHandle, revFootJnts['ankle'])


        #setup the foot roll
        self.__setupFootRoll(ikCtl, revFootJnts, namer)

        control.setLockTag(toeCtl, uk=['r', 't'])
        control.setLockTag(ikCtl, uk=['r', 't', 'fkIk'])
        
        self.setNodeCateogry(utils.insertNodeAbove(ikCtl, 'transform'), 'ik')
Example #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])
Example #5
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)