def createBeingsSplineObjs(numIkCtls, numBndJnts, ctlSep=2, namer=None, ctlKwargs=None, doubleEndPoints=False): """ Create the components needed for a spline setup - ik controls, joints, a nurbs plane and a nurbs curve. @param numIkCtls: the number of ik controls to create @param numBndJnts: the number of bind joints to create. An extra 'tip' joint will also be created, so the total joints returned will be 1+numBndJnts """ if not namer: namer = utils.Namer('char', 'cn', 'spine') result = {} MC.select(cl=1) bndJnts = [] bndPosInc = ((numIkCtls-1) * ctlSep)/float(numBndJnts-1) for i in range(numBndJnts): pos = [0, i*bndPosInc, 0] name = namer(alphaSuf = i, r='bnd') if i == numBndJnts-1: name = namer('tip', r='bnd') j = MC.joint(p=pos, n=name) bndJnts.append(j) ikCtls = [] if not ctlKwargs: ctlKwargs = {'s': [2.5,.5, 2.5]} for i in range(numIkCtls): ikCtl = control.makeControl(namer('layout_ctl', r='ik', alphaSuf=i), **ctlKwargs) if i < numIkCtls: MC.setAttr('%s.ty' % ikCtl, i * ctlSep) else: MC.setAttr('%s.ty' % ikCtl, ((i-1) * ctlSep)+bndPosInc) ikCtls.append(ikCtl) result['curve'] = crv = curveFromNodes(ikCtls, name=namer('ikspline_crv'), doubleEndPoints=doubleEndPoints) result['surface'] = srf = surfaceFromNodes(ikCtls, name=namer('ikspline_srf'), doubleEndPoints=doubleEndPoints) result['ikCtls'] = ikCtls utils.fixInverseScale(bndJnts) result['jnts'] = bndJnts bindControlsToShape(ikCtls, crv, doubleEndPoints=doubleEndPoints) bindControlsToShape(ikCtls, srf, doubleEndPoints=doubleEndPoints) return result
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): 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])
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 _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 _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