def postRig(self): ''' clean up for the rig build. ''' if common.isValid('%s.jointVis' % self.rigGrp): return True if cmds.ls(type = 'rig') and common.isValid(self.controlsGrp) and not common.isValid(self.rigGrp): return True jointVisAttr = attribute.addAttr(self.rigGrp, 'jointVis', attrType = 'enum', defValue = 'off:on') scaleAttr = attribute.addAttr(self.rigGrp, 'uniformScale', attrType = 'double', defValue = 1, min = 0) jointDisplayAttr = attribute.addAttr(self.rigGrp, 'displayJnts', attrType = 'enum', defValue = 'Normal:Template:Reference') cmds.setAttr(jointDisplayAttr, 2) #setup attribute for uniform scale attribute.connect(scaleAttr, '%s.sx' % self.rigGrp) attribute.connect(scaleAttr, '%s.sy' % self.rigGrp) attribute.connect(scaleAttr, '%s.sz' % self.rigGrp) if self.skinClusterJnts: for jnt in self.skinClusterJnts: if cmds.objExists(jnt): attribute.connect(jointVisAttr , '%s.v' % jnt) cmds.setAttr('%s.overrideEnabled' % jnt, 1) attribute.connect(jointDisplayAttr , '%s.overrideDisplayType' % jnt) #set joint visibility attribute cmds.setAttr(jointVisAttr, 1) for grp in [self.rigGrp, self.jointsGrp, self.controlsGrp]: attribute.lockAndHide(['t', 'r', 's', 'v'], grp)
def postSetupRig(self): if super(Limb, self).postSetupRig(): return True #Add attributes to the master guide to control the orientation of the ik and fk controls attribute.addAttr(self.masterGuide, 'fk_orient', attrType = 'enum', defValue = 'World:Local', value = 1) attribute.addAttr(self.masterGuide, 'ik_orient', attrType = 'enum', defValue = 'World:Local', value = 0)
def setupRig(self): if common.isValid(self.name()): return True self.setupConstraints = [] #makes component a puppet node self.puppetNode = puppet.create(self.name()) #Create master guide control and control.createSetup('{0}_master'.format(self.name()), type = 'square') common.setColor(self.masterGuide, 'darkred') #create hierarchy cmds.createNode('transform', n = self.setupRigGrp) cmds.createNode('transform', n = self.skeletonGrp) cmds.createNode('transform', n = self.guidesGrp) cmds.parent(self.skeletonGrp, self.setupRigGrp) cmds.parent(self.guidesGrp, self.setupRigGrp) cmds.parent(common.getParent(self.masterGuide),self.guidesGrp) #add attributes to groups attribute.addAttr(self.setupRigGrp, 'tag_guides', attrType = 'message') masterGuideAttr = attribute.addAttr(self.setupRigGrp, 'master_guide', attrType = 'message') attribute.connect(masterGuideAttr, '%s.tag_controls' % self.masterGuide)
def postSetupRig(self): ''' clean up section for the setup rig ''' if common.isValid('%s.displayAxis' % self.masterGuide) or common.isValid(self.masterGuide) != True: return True #create attributes and lock/hide attrs on top nodes as well as masterGuide control displayAttr = attribute.addAttr(self.masterGuide, 'displayAxis', attrType = 'enum', defValue = 'off:on') attribute.lockAndHide(['r','t','s','v'], [self.setupRigGrp, self.skeletonGrp,self.guidesGrp, common.getParent(self.masterGuide)]) attribute.lockAndHide('v', self.masterGuide) #resize guide controls for guide in self.getGuides(): cmds.setAttr('%s.radius' % common.getShapes(guide, 0), self.controlScale * .5) #resize masterGuide control control.scaleShape(self.masterGuide, scale = [self.controlScale * 2, self.controlScale * 2, self.controlScale * 2]) #declaring skeleton joints skeletonJnts = self.getSkeletonJnts() #connect joints to the attributes on the masterGuide control for jnt in skeletonJnts: if cmds.objExists(jnt): attribute.connect(displayAttr , '%s.displayLocalAxis' % jnt) common.setDisplayType(jnt, 'reference') #parent all constraints to guides group if self.setupConstraints: cmds.parent(self.setupConstraints, self.guidesGrp) #Put the build attributes onto setup rigs ''' cmds.addAttr(self.setupRigGrp, ln = 'kwargs', dt = "string") cmds.setAttr('%s.kwargs' % self.setupRigGrp, str(self._buildAttrs), type = "string") ''' attribute.copy('displayAxis', self.masterGuide, self.name(), reverseConnect = True) #parent setup under puppet node self._puppetNode.addChild(self.setupRigGrp) if self.parentHook: if cmds.objExists(self.parentHook): displayLine = control.displayLine(self.masterGuide, self.parentHook, name = self.masterGuide.replace('_%s' % common.GUIDES, '_%s' % common.CURVE)) cmds.parent(displayLine, self.guidesGrp) #set build args on puppet node attrs = dict() for attr in self.attributes(): attrs[attr.name()] = attr.value() self.puppetNode.storeArgs(**attrs)
def setupCtrl(self, name, obj, color = None): ''' :param name: The name of control created :type name: *str* :param obj: object to be controled :type obj: str :param color: object to be controled :type color: str :return: Guide control :rtype: str ''' #create hierarchy guideZero = cmds.createNode('transform', n = '%s_%s' % (name, common.ZERO)) guideShape = cmds.createNode('implicitSphere',n = '%s_%sShape' % (name,common.GUIDES)) guide = common.getParent(guideShape) guide = cmds.rename(guide, name + '_' + common.GUIDES) #set color if color: common.setColor(guideShape, color) else: common.setColor(guideShape, common.SIDE_COLOR[self._getSide()]) #parent guide to zero group cmds.parent(guide, guideZero) cmds.delete(cmds.parentConstraint(obj, guideZero, mo = False)) constraint = cmds.pointConstraint(guide, obj) cmds.parent([guideZero, constraint[0]],self.masterGuide) #lock and hide attributes attribute.lockAndHide(['r','s', 'v'], guide) #tag the guide control with a tag_guides attribute tagAttr = attribute.addAttr(guide, 'tag_guides', attrType = 'message') #connect attribute to the setupRigGrp attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr) return guide
def setupRig(self): if super(Hand, self).setupRig(): return True if self._getSide() == common.LEFT: #move master guide into position cmds.xform(common.getParent(self.masterGuide), ws = True, t = self.handPosition) for i,obj in enumerate(self.fingers): self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(), obj)) self.__fingers[obj].initialize(numJoints = self.numJoints, position=[self.position[0] + 10, self.position[1], (self.position[2] + 2 )- i], parent = self.parent) self.__fingers[obj].setupRig() cmds.parentConstraint(self.masterGuide, common.getParent(self.__fingers[obj].masterGuide), mo = True) for guide in self.__fingers[obj].getGuides(): #tag the guide control with a tag_guides attribute tagAttr = attribute.addAttr(guide, 'hand_guides', attrType = 'message') attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr) #end loop #end loop #end if elif self._getSide() == common.RIGHT: #move master guide into position cmds.xform(common.getParent(self.masterGuide), ws = True, t = self.handPosition) for i,obj in enumerate(self.fingers): self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(), obj)) self.__fingers[obj].initialize(numJoints = self.numJoints, position = [self.position[0] - 10, self.position[1], (self.position[2] + 2 ) - i], parent = self.parent) self.__fingers[obj].setupRig() cmds.parentConstraint(self.masterGuide, common.getParent(self.__fingers[obj].masterGuide), mo = True) for guide in self.__fingers[obj].getGuides(): #tag the guide control with a tag_guides attribute tagAttr = attribute.addAttr(guide, 'hand_guides', attrType = 'message') attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr) #end loop #end loop #end elif else: #move master guide into position cmds.xform(common.getParent(self.masterGuide), ws = True, t = self.handPosition) for i,obj in enumerate(self.fingers): self.__fingers[obj] = finger.Finger('%s_%s' % (self._getPrefix(), obj)) self.__fingers[obj].initialize(numJoints = self.numJoints, position = [self.position[0] - 10, self.position[1], (self.position[2] + 2 ) - i], parent = self.parent) self.__fingers[obj].setupRig() cmds.parentConstraint(self.masterGuide, common.getParent(self.__fingers[obj].masterGuide), mo = True) for guide in self.__fingers[obj].getGuides(): #tag the guide control with a tag_guides attribute tagAttr = attribute.addAttr(guide, 'hand_guides', attrType = 'message') attribute.connect('%s.tag_guides' % self.setupRigGrp, tagAttr) #end loop #end loop #end elif #create joint and guide if not common.isValid(self.handJoint): joint.create(self.handJoint, self.skeletonGrp, self.handPosition) if not common.isValid(self.handJoint.replace(common.JOINT,common.CONTROL)): self.setupCtrl(self.handGuide,self.handJoint, common.SIDE_COLOR[self._getSide()])
def rig(self): if not self._puppetNode: self.runSetupRig() if cmds.objExists('%s.master_guide' % self.setupRigGrp): self.masterGuide = attribute.getConnections('master_guide', self.setupRigGrp)[0].split('.')[0] if common.isValid(self.masterGuide): #get orientations for controls fkOrient = self.__fkOrient() ikOrient = self.__ikOrient() upVector = self.upVector aimVector = self.aimVector #call parent class rig function if super(Limb, self).rig(): return True #create ik fk switch ikfkDict = ikfk.create(jointChain = [self.startJoint, self.midJoint, self.tipJoint], stretch = self.stretch) ikfkDict['group'] = cmds.rename(ikfkDict['group'], '%s_%s' % (self.name(),ikfkDict['group'])) #set the visibility on the ik/fk/blend joints to off cmds.setAttr('%s.v' % ikfkDict['fkJoints'][0], 0) cmds.setAttr('%s.v' % ikfkDict['ikJoints'][0], 0) cmds.setAttr('%s.v' % ikfkDict['blendJoints'][0], 0) ikfkAttr = attribute.addAttr(self.rigGrp, attr = 'ikfk', attrType = 'enum', defValue = ['off','on'],value = 0) cmds.connectAttr(ikfkAttr, '%s.ikfk' % ikfkDict['group'], l = True, f = True) #parent ikfk group under joints group cmds.parent(ikfkDict['group'], self.jointsGrp) #rename all ik and blend joints for i,jnt in enumerate(ikfkDict['ikJoints']): jnt = cmds.rename(jnt, jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT, common.IK), '%s_%s' % (common.IK, common.JOINT))) ikfkDict['ikJoints'][i] = jnt for i,jnt in enumerate(ikfkDict['blendJoints']): jnt = cmds.rename(jnt, jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT, common.BLEND), '%s_%s' % (common.BLEND, common.JOINT))) ikfkDict['blendJoints'][i] = jnt #create ik setup ikCtrl = control.create(name = ikfkDict['ikJoints'][2].replace('_%s' % common.JOINT, ''),type = 'cube', parent = self.controlsGrp, color = common.SIDE_COLOR[self._getSide()]) ikCtrlZero = common.getParent(ikCtrl) attribute.copy('stretch', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False) attribute.copy('stretchTop', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False) attribute.copy('stretchBottom', ikfkDict['group'], destination = ikCtrl, connect = True,reverseConnect = False) if ikOrient == 'Local': transform.matchXform(ikfkDict['ikJoints'][2], ikCtrlZero, type = 'pose') else: transform.matchXform(ikfkDict['ikJoints'][2], ikCtrlZero, type = 'position') cmds.orientConstraint(ikCtrl, ikfkDict['ikJoints'][2], mo = True) common.setColor(ikCtrl, common.SIDE_COLOR[self._getSide()]) #setup poleVector pvCtrl = control.create(name = ikfkDict['ikJoints'][2].replace('_%s' % common.JOINT, '_%s' % common.POLEVECTOR),type = 'cube', parent = self.controlsGrp, color = common.SIDE_COLOR[self._getSide()]) #size polevector control for i in range(len(common.getShapes(pvCtrl))): control.scaleShape(pvCtrl, scale = [self.controlScale * .5, self.controlScale * .5, self.controlScale * .5], index = i) pvCtrlZero = common.getParent(pvCtrl) pvDisplayLineAttr = attribute.addAttr(pvCtrl, attr = 'pvLine', attrType = 'enum', defValue = 'off:on', value = 1) transform.matchXform(ikfkDict['ikJoints'][1], pvCtrlZero, type = 'position') #cmds.parent(ikfkDict['ikHandle'], w = True) pvPos = ikfk.getPoleVectorPosition(ikfkDict['ikJoints'][1], ikfkDict['ikHandle']) cmds.xform(pvCtrlZero, ws = True, t = pvPos) common.setColor(pvCtrlZero, common.SIDE_COLOR[self._getSide()]) #create polevector constraint and parent under control cmds.poleVectorConstraint(pvCtrl, ikfkDict['ikHandle']) targetConstraint = cmds.pointConstraint(ikCtrl, ikfkDict['targetJnts'][1], mo = True) #ikhandle is under target joint pvDisplayLine = control.displayLine(ikfkDict['ikJoints'][0], pvCtrl, name = pvCtrl.replace(common.CONTROL, common.DISPLAYLINE), parent = self.controlsGrp) cmds.orientConstraint(ikCtrl,ikfkDict['ikJoints'][0], mo = True) #adding attribute to ik ctrl ikTwistAttr = attribute.addAttr(ikCtrl, attr = 'twist') cmds.connectAttr(ikTwistAttr, '%s.twist' % ikfkDict['ikHandle'], f = True) #connecting to shapes ikfkReverse = cmds.createNode('reverse', n = ikCtrl.replace('%s_%s' % (common.IK, common.CONTROL), '%s_%s' % (common.REVERSE, common.UTILITY))) attribute.connect('%s.ikfk' % ikfkDict['group'], '%s.inputX' % ikfkReverse) for shape in common.getShapes(ikCtrl): attribute.connect('%s.outputX' % ikfkReverse,'%s.v' % shape) for shape in common.getShapes(pvCtrl): attribute.connect('%s.outputX' % ikfkReverse,'%s.v' % shape) #connect pvDisplayLineAttr in pvDisplayLine visibility displayLineMultiply = cmds.createNode('multiplyDivide', n = pvDisplayLine.replace(common.DISPLAYLINE, common.MULTIPLYDIVIDE)) attribute.connect(pvDisplayLineAttr, '%s.input1X' % displayLineMultiply) attribute.connect('%s.outputX' % ikfkReverse, '%s.input2X' % displayLineMultiply) attribute.connect('%s.outputX' % displayLineMultiply, '%s.v' % common.getChildren(pvDisplayLine)[0]) #create fk setup fkCtrls = list() parent = self.controlsGrp for i,jnt in enumerate(ikfkDict['fkJoints']): cmds.select(cl = True) #rename fk joint jnt = cmds.rename(jnt,jnt.replace('%s_%s_%s' % (common.SKINCLUSTER,common.JOINT,common.FK), '%s_%s' % (common.FK,common.JOINT))) ikfkDict['fkJoints'][i] = jnt #re-assign fk joint intop ikfkDict #create controls, set color, and make connections fkCtrl = control.create(name = jnt.replace('_%s' % common.JOINT, ''),type = 'circle', parent = parent, color = common.SIDE_COLOR[self._getSide()]) fkCtrlZero = common.getParent(fkCtrl) if fkOrient == 'Local': transform.matchXform(jnt, fkCtrlZero, type = 'pose') #end if else: transform.matchXform(jnt, fkCtrlZero, type = 'position') #end else cmds.connectAttr('%s.ikfk' % ikfkDict['group'], '%s.v' % common.getShapes(fkCtrl)[0], f = True) cmds.parentConstraint(fkCtrl, jnt, mo = True) attribute.lockAndHide('t', fkCtrl) attribute.lockAndHide('s', fkCtrl) attribute.lockAndHide('v', fkCtrl) #get joint rotate order and apply to control and parent group rotateOrder = attribute.getValue('rotateOrder', jnt) for node in [fkCtrl, fkCtrlZero]: cmds.setAttr('%s.rotateOrder' % node, rotateOrder) fkCtrls.append(fkCtrl) parent = fkCtrl #end loop #end loop aimAxis = transform.getAimAxis(ikfkDict['blendJoints'][0], allowNegative = False) #Up Twist Joint Setup if self.upTwistJnts: noTwistJnt = common.duplicate(self.startJoint, name = self.startJoint.replace('%s' % common.SKINCLUSTER, 'NoTwist_%s' % common.SKINCLUSTER), parent = self.startJoint) inverseMultNode = cmds.createNode('multiplyDivide', n = noTwistJnt.replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE))) cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][0], aimAxis), '%s.input1X' % inverseMultNode, f = True) cmds.setAttr('%s.input2X' % inverseMultNode, -1) cmds.connectAttr('%s.outputX' % inverseMultNode, '%s.r%s' % (noTwistJnt, aimAxis), f = True) step = 1.0 / (len(self.upTwistJnts) +1) for i in range( 1, (len(self.upTwistJnts)+1) ): twsitMultNode = cmds.createNode('multiplyDivide', n = self.upTwistJnts[i - 1].replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE))) cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][0], aimAxis), '%s.input1X' % twsitMultNode, f = True) cmds.setAttr('%s.input2X' % twsitMultNode, -(1-(step*i)) ) cmds.connectAttr('%s.outputX' % twsitMultNode, '%s.r%s' % (self.upTwistJnts[i -1], aimAxis),f = True) #end loop self.upTwistJnts.insert(0, noTwistJnt) #end if if self.loTwistJnts: twistJnt = common.duplicate(self.midJoint,name = self.midJoint.replace('%s' % common.SKINCLUSTER, 'loTwist_%s' % common.SKINCLUSTER), parent = self.midJoint) constraint = cmds.aimConstraint(ikfkDict['blendJoints'][2],twistJnt,aimVector = aimVector, upVector = upVector, worldUpType ="objectrotation", worldUpVector = upVector, worldUpObject = self.tipJoint) cmds.setAttr('%s.v' % twistJnt, 0) #end if step = 1.0 / (len(self.loTwistJnts) +1) for i in range( 1, (len(self.loTwistJnts)+1) ): twsitMultNode = cmds.createNode('multiplyDivide', n = self.loTwistJnts[i - 1].replace('%s_%s' % (common.SKINCLUSTER,common.JOINT), '%s_%s' % (common.UTILITY, common.MULTIPLYDIVIDE))) cmds.connectAttr('%s.r%s' % (ikfkDict['blendJoints'][2], aimAxis), '%s.input1X' % twsitMultNode, f = True) cmds.setAttr('%s.input2X' % twsitMultNode, 1-(step*i) ) cmds.connectAttr('%s.outputX' % twsitMultNode, '%s.r%s' % (self.loTwistJnts[i -1], aimAxis),f = True) #end loop #------------------------ #Add to class variables #------------------------ #assign joints to the joints list self.joints = {'ik' : ikfkDict['ikJoints'], 'fk' : ikfkDict['fkJoints'], 'blend' : ikfkDict['blendJoints'], 'target' : ikfkDict['targetJnts']} #assign controls to the controls list #assign fkCtrls into the controls dictionary self.controls = {'ik' : [ikCtrl, pvCtrl],'fk' : fkCtrls } self.ikfkGroup = ikfkDict['group'] #assign hooks self.hookRoot = [ikfkDict['ikJoints'][0], common.getParent(fkCtrls[0]), ikCtrl, ikfkDict['targetJnts'][-1]] self.hookPoint = [ikfkDict['blendJoints'][-1]] #add no twist joint to the skincluster list self.skinClusterJnts.append(noTwistJnt)
def rig(self): if not self._puppetNode: self.runSetupRig() if common.isValid('%s_%s%s' % (self.name(), common.IK, common.FK)): return True cmds.parent([self.__bankInPivot, self.__bankOutPivot, self.__heelPivot], w = True) if super(Foot,self).rig(): return True #create foot ik/fk chain and parent group to joints group self.__footIkFk = \ ikfk.IkFkFoot(self.ankleJoint, self.toeJoint, name = self.name()) #list the groups for the foot ik setup self.__footRollGroups.insert(0, 'anklePivot') footRollGrpList = self.__footRollGroups #create foot setup self.__footIkFk.create(searchReplace = '%s' % common.SKINCLUSTER, footRollGrpList = footRollGrpList) #parent to joints group cmds.parent(self.__footIkFk.group, self.jointsGrp) #get position of joints anklePosition = \ cmds.xform(self.ankleJoint, q = True, ws = True, rp = True) ballPosition = \ cmds.xform(self.ballJoint, q = True, ws = True, rp = True) toePosition = \ cmds.xform(self.toeJoint, q = True, ws = True, rp = True) bankInPosition = \ cmds.xform(self.__bankInPivot, q = True, ws = True, rp = True) bankOutPosition = \ cmds.xform(self.__bankOutPivot, q = True, ws = True, rp = True) heelPosition = \ cmds.xform(self.__heelPivot, q = True, ws = True, rp = True) #delete pivot joints for jnt in (self.__heelPivot,self.__bankOutPivot, self.__bankInPivot): cmds.delete(jnt) #end loop #get foot roll groups footRollGroups = self.__footIkFk.getFootRolls() handles = self.__footIkFk.getIkHandles() #position foot roll groups for grp in footRollGroups: if grp in ['ballRoll', 'toeBend']: cmds.xform(footRollGroups[grp], ws = True, rp = ballPosition) elif grp in ['heelRoll', 'heelPivot']: if grp == self.__heelPivotName: cmds.setAttr('%s.rotateOrder' % footRollGroups[grp], 2) cmds.xform(footRollGroups[grp], ws = True, rp = heelPosition) elif grp in ['toeRoll', 'toePivot']: cmds.xform(footRollGroups[grp], ws = True, rp = toePosition) elif grp in ['bankIn', self.__bankInZero]: cmds.xform(footRollGroups[grp], ws = True, rp = bankInPosition) elif grp in ['bankOut', self.__bankOutZero]: cmds.xform(footRollGroups[grp], ws = True, rp = bankOutPosition) cmds.setAttr('%s.rotateOrder' % footRollGroups[grp], 2) elif grp in ['anklePivot']: cmds.xform(footRollGroups[grp], ws = True, rp = anklePosition) #end loop #create controls self.__footCtrl = \ control.create(name= self.name(), type = 'implicitSphere', parent = self.controlsGrp, color = common.SIDE_COLOR[self._getSide()]) self.__bankInCtrl = \ control.create(name= footRollGroups[self.__bankIn] , type = 'implicitSphere', parent = self.controlsGrp, color = common.SIDE_COLOR_SECONDARY[self._getSide()]) self.__bankOutCtrl = \ control.create(name= footRollGroups[self.__bankOut] , type = 'implicitSphere', parent = self.controlsGrp, color = common.SIDE_COLOR_SECONDARY[self._getSide()]) self.__heelPivotCtrl = \ control.create(name= footRollGroups[self.__heelPivotName] , type = 'implicitSphere', parent = self.controlsGrp, color = common.SIDE_COLOR_SECONDARY[self._getSide()]) #parent of controls parentBankOutCtrl = common.getParent(self.__bankOutCtrl) parentBankInCtrl = common.getParent(self.__bankInCtrl) parentHeelPivotCtrl = common.getParent(self.__heelPivotCtrl) #scale controls for ctrl in [self.__footCtrl,self.__bankOutCtrl, self.__bankInCtrl, self.__heelPivotCtrl]: for i in range(len(common.getShapes(ctrl))): control.scaleShape (ctrl, scale = [.3, .3, .3], index = i) #place controls in correct positions transform.matchXform(self.ankleJoint, common.getParent(self.__footCtrl), type = 'pose') cmds.xform(common.getParent(self.__footCtrl), ws = True, r = True, t = [0,0,-2]) cmds.delete(cmds.parentConstraint(footRollGroups['bankIn'], parentBankInCtrl)) cmds.delete(cmds.parentConstraint(footRollGroups['bankOut'], parentBankOutCtrl)) cmds.delete(cmds.parentConstraint(footRollGroups['heelPivot'], parentHeelPivotCtrl)) #Decompose matrix nodes for pivots and connect the controls to them for ctrl, grp in zip([self.__bankInCtrl, self.__bankOutCtrl, self.__heelPivotCtrl] , [footRollGroups['bankIn'], footRollGroups['bankOut'], footRollGroups[self.__heelRoll]]): grpZero = common.getChildren(grp)[0] dcm = cmds.createNode('decomposeMatrix', n = '%s_%s' % (grp, common.DECOMPOSEMATRIX)) mdn = cmds.createNode('multiplyDivide', n = '%s_%s' % (grp, common.MULTIPLYDIVIDE)) attribute.connect('%s.worldMatrix[0]' % ctrl, '%s.inputMatrix' % dcm) #connect controls to pivots attribute.connect('%s.outputTranslate' % dcm, '%s.rotatePivot' % grp) attribute.connect('%s.outputTranslate' % dcm, '%s.rotatePivot' % grpZero) #Change attributes on Multiply divide node and make connections cmds.setAttr('%s.input2Y' % mdn, -1) attribute.connect('%s.ry' % ctrl, '%s.input1Y' % mdn) attribute.connect('%s.outputY' % mdn, '%s.ry' % grpZero) attribute.connect('%s.ry' % ctrl, '%s.ry' % grp) #parent constrain the foot control to the ankle joint for node in [self.__footCtrl,parentBankOutCtrl, parentBankInCtrl, parentHeelPivotCtrl]: cmds.parentConstraint(footRollGroups['anklePivot'], node, mo = True) #add attributes to the foot control and connect them to the pivots ikfkAttr = \ attribute.addAttr(self.__footCtrl, 'ikfk' , attrType = 'enum', defValue = ['off', 'on'], value = 0) bankAttr = \ attribute.addAttr(self.__footCtrl, 'bank' , attrType = 'double', defValue = 0, min = -10, max = 10) ballRollAttr = \ attribute.addAttr(self.__footCtrl, self.__ballRoll , attrType = 'double', defValue = 0, min = 0, max = 10) toeRollAttr = \ attribute.addAttr(self.__footCtrl, self.__toeRoll , attrType = 'double', defValue = 0, min = 0, max = 10) toePivotAttr = \ attribute.addAttr(self.__footCtrl, self.__toePivot , attrType = 'double', defValue = 0, min = -10, max = 10) toeBendAttr = \ attribute.addAttr(self.__footCtrl, self.__toeBend , attrType = 'double', defValue = 0, min = -10, max = 10) heelRollAttr = \ attribute.addAttr(self.__footCtrl, self.__heelRoll , attrType = 'double', defValue = 0, min = -10, max = 0) heelPivotAttr = \ attribute.addAttr(self.__footCtrl, self.__heelPivotName , attrType = 'double', defValue = 0, min = -10, max = 10) self.__footRollAttrs.extend([ikfkAttr, bankAttr, ballRollAttr, toeRollAttr , toePivotAttr, toeBendAttr, heelRollAttr, heelPivotAttr]) #create remap dictionary to place remap nodes in based on foot roll group names ramapNodes = dict() #create remap nodes and connect them to foot roll groups for attr in [bankAttr,toePivotAttr,toeBendAttr,heelPivotAttr]: node, attrName = attr.split('.') ramapNodes[attrName] = \ cmds.createNode('remapValue', n = '%s_%s_%s' % (node, attrName, common.REMAP)) attribute.connect(attr, '%s.inputValue' % ramapNodes[attrName]) cmds.setAttr('%s.outputMax' % ramapNodes[attrName], 100) cmds.setAttr('%s.outputMin' % ramapNodes[attrName], -100) cmds.setAttr('%s.inputMax' % ramapNodes[attrName], 10) cmds.setAttr('%s.inputMin' % ramapNodes[attrName], -10) #end loop for attr in [ballRollAttr,toeRollAttr, heelRollAttr]: node, attrName = attr.split('.') ramapNodes[attrName] = \ cmds.createNode('remapValue', n = '%s_%s_%s' % (node, attrName, common.REMAP)) attribute.connect(attr, '%s.inputValue' % ramapNodes[attrName]) cmds.setAttr('%s.outputMax' % ramapNodes[attrName], 100) cmds.setAttr('%s.outputMin' % ramapNodes[attrName], 0) cmds.setAttr('%s.inputMax' % ramapNodes[attrName], 10) cmds.setAttr('%s.inputMin' % ramapNodes[attrName], 0) if attr == heelRollAttr: cmds.setAttr('%s.outputMax' % ramapNodes[attrName], 0) cmds.setAttr('%s.outputMin' % ramapNodes[attrName], -100) cmds.setAttr('%s.inputMax' % ramapNodes[attrName], 0) cmds.setAttr('%s.inputMin' % ramapNodes[attrName], -10) #end if #end loop #connect remap nodes to roll groups #---Bank In/Out--- if self._getSide() == common.LEFT: attribute.connect('%s.outValue' % ramapNodes['bank'], '%s.rz' % footRollGroups[self.__bankIn]) attribute.connect('%s.outValue' % ramapNodes['bank'], '%s.rz' % footRollGroups[self.__bankOut]) cmds.transformLimits(footRollGroups[self.__bankIn], rz =[0, 100], erz = [1, 1]) cmds.transformLimits(footRollGroups[self.__bankOut], rz =[-100, 0], erz = [1, 1]) elif self._getSide() == common.RIGHT: invertMDN = \ cmds.createNode('multiplyDivide', n = '%s_bankInvert_%s' % (self._getSide(), common.MULTIPLYDIVIDE)) cmds.setAttr('%s.input2X' % invertMDN, -1) attribute.connect('%s.outValue' % ramapNodes['bank'], '%s.input1X' % invertMDN) attribute.connect('%s.outputX' % invertMDN, '%s.rz' % footRollGroups[self.__bankIn]) attribute.connect('%s.outputX' % invertMDN, '%s.rz' % footRollGroups[self.__bankOut]) cmds.transformLimits(footRollGroups[self.__bankIn], rz =[-100, 0], erz = [1, 1]) cmds.transformLimits(footRollGroups[self.__bankOut], rz =[0, 100], erz = [1, 1]) #---Ball Roll--- attribute.connect('%s.outValue' % ramapNodes[self.__ballRoll], '%s.rx' % footRollGroups[self.__ballRoll]) #---Toe Roll--- attribute.connect('%s.outValue' % ramapNodes[self.__toeRoll], '%s.rx' % footRollGroups[self.__toeRoll]) #---Toe Pivot--- attribute.connect('%s.outValue' % ramapNodes[self.__toePivot], '%s.ry' % footRollGroups[self.__toePivot]) #---Heel Roll--- attribute.connect('%s.outValue' % ramapNodes[self.__heelRoll], '%s.rx' % footRollGroups[self.__heelRoll]) #---Heel Pivot--- attribute.connect('%s.outValue' % ramapNodes[self.__heelPivotName], '%s.ry' % footRollGroups[self.__heelPivotName]) #---IK/FK--- attribute.connect(ikfkAttr, '%s.ikfk' % self.__footIkFk.group) #---Ball Roll--- attribute.connect('%s.outValue' % ramapNodes[self.__toeBend], '%s.rx' % footRollGroups[self.__toeBend]) #connect fk joints to the ankle pivot #cmds.parentConstraint(footRollGroups['anklePivot'], self.__footIkFk.fkJoints[0], mo = True) #connecting visibility of control shapes to the controls ikfkReverse = \ cmds.createNode('reverse', n = '%s_%s' % (self.name(),common.REVERSE)) attribute.connect(ikfkAttr, '%s.inputX' % ikfkReverse) for ikCtrl in [self.__bankInCtrl,self.__bankOutCtrl,self.__heelPivotCtrl]: cmds.setAttr('%s.rotateOrder' % ikCtrl, 2) for shape in common.getShapes(ikCtrl): if shape: attribute.connect('%s.outputX' % ikfkReverse, '%s.v' % shape) #----FK Setup--- fkCtrls = list() parent = self.controlsGrp for jnt in self.__footIkFk.fkJoints: if jnt == self.__footIkFk.fkJoints[-1]: continue #end if ctrl = \ control.create(name= jnt.split('_%s' % common.JOINT)[0], type = 'circle', parent = parent, color = common.SIDE_COLOR[self._getSide()]) ctrlParent = common.getParent(ctrl) transform.matchXform(jnt, ctrlParent, type = 'pose') cmds.parentConstraint(ctrl, jnt, mo = True) #----> might change this to connect rotations and not use translation if jnt == self.__footIkFk.fkJoints[0]: cmds.parentConstraint(footRollGroups['anklePivot'], ctrlParent, mo = True) #end if #connect visibility of shapes to foot control for shape in common.getShapes(ctrl): attribute.connect(ikfkAttr, '%s.v' % shape) #end for parent = ctrl fkCtrls.append(ctrl) #assign hooks self.hookRoot.extend([footRollGroups['anklePivot'], common.getParent(fkCtrls[0])]) self.hookPoint.extend([footRollGroups['ballRoll']])
def create( spaceNode, spaceAttrNode = None , parent=None ): ''' Create space switcher :param spaceNode: Transform node to be constrained. :type spaceNode: *str* :param spaceAttrNode: Node where the 'space' attribute is going to be created. :type spaceAttrNode: *str* :param parent: Parent for the spaces group. :type parent: *str* :return: Spaces group :rtype: *str* ''' # Load decompose matrix plugin # get attribute spaceNode if spaceAttrNode == None: spaceAttrNode = spaceNode # check if exists if cmds.objExists( '%s.spaceGrp' % spaceNode ): raise RuntimeError, 'This node has spaces already. Use addSpace instead' # -------------------------------------------------------------------------- # CREATE GROUP # grp = cmds.createNode('transform',n='%s%s' % (spaceNode,'Spaces'), parent=parent ) cmds.setAttr('%s.%s' % (grp,'inheritsTransform'),False) decomMatrixNode = cmds.createNode('decomposeMatrix') cmds.connectAttr( '%s.%s' % (spaceNode,'parentMatrix'), '%s.%s' % (decomMatrixNode,'inputMatrix') ) cmds.connectAttr( '%s.%s' % (decomMatrixNode,'outputTranslate'), '%s.%s' % (grp,'translate') ) cmds.connectAttr( '%s.%s' % (decomMatrixNode,'outputRotate'), '%s.%s' % (grp,'rotate') ) cmds.connectAttr( '%s.%s' % (decomMatrixNode,'outputScale'), '%s.%s' % (grp,'scale') ) # -------------------------------------------------------------------------- # CREATE LOCAL SPACE # attribute.addAttr( spaceAttrNode, 'space', attrType='enum', defValue=['local'] ) localSpace = cmds.createNode('transform', name='%s_%s' % (grp,'local'), parent=grp) transform.matchXform( localSpace, spaceNode, 'pose' ) attribute.lockAndHide( ['t','r','s','v'], localSpace ) # -------------------------------------------------------------------------- # CREATE CONSTRAINT # constraint = cmds.parentConstraint( localSpace, spaceNode )[0] # -------------------------------------------------------------------------- # CREATE MESSAGE ATTRIBUTES # # spaceAttrNode cmds.addAttr( spaceNode, k=True, ln='spaceAttrNode', at='message' ) cmds.connectAttr( '%s.%s' % (spaceAttrNode,'space'), '%s.%s' % (spaceNode,'spaceAttrNode') ) # spaceNode cmds.addAttr( spaceAttrNode, k=True, ln='spaceNode', at='message' ) cmds.connectAttr( '%s.%s' % (spaceNode,'message'), '%s.%s' % (spaceAttrNode,'spaceNode') ) # spaceGrp cmds.addAttr( spaceNode, k=True, ln='spaceGrp', at='message' ) cmds.connectAttr( '%s.%s' % (grp,'message'), '%s.%s' % (spaceNode,'spaceGrp') ) # spaceConstraint cmds.addAttr( spaceNode, k=True, ln='spaceConstraint', at='message' ) cmds.connectAttr( '%s.%s' % (constraint,'message'), '%s.%s' % (spaceNode,'spaceConstraint') ) # -------------------------------------------------------------------------- return grp