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