def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_'] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side + self.userGuideName + '_Guide_Base' # get the number of joints to be created: self.nJoints = cmds.getAttr(self.base + ".nJoints") # create controls: self.hipsA = ctrls.cvBox( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_hips'] + "A_Ctrl", r=self.ctrlRadius, h=(self.ctrlRadius * 0.25)) self.hipsB = \ cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_hips'] + "B_Ctrl", ch=False, o=True, nr=(0, 1, 0), d=1, s=8, radius=self.ctrlRadius)[0] self.chestA = ctrls.cvBox( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chest'] + "A_Ctrl", r=self.ctrlRadius, h=(self.ctrlRadius * 0.25)) self.chestB = \ cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chest'] + "B_Ctrl", ch=False, o=True, nr=(0, 1, 0), d=1, s=8, radius=self.ctrlRadius)[0] cmds.addAttr(self.hipsA, longName=side + self.userGuideName + '_' + self.langDic[self.langName][ 'c_volumeVariation'], attributeType="float", defaultValue=1, keyable=True) ctrls.setLockHide([self.hipsA, self.hipsB, self.chestA, self.chestB], ['v'], l=False) self.aHipsAList.append(self.hipsA) self.aChestAList.append(self.chestA) self.aVolVariationAttrList.append( side + self.userGuideName + '_' + self.langDic[self.langName]['c_volumeVariation']) # Setup axis order if self.rigType == Base.RigType.quadruped: cmds.setAttr(self.hipsA + ".rotateOrder", 1) cmds.setAttr(self.hipsB + ".rotateOrder", 1) cmds.setAttr(self.chestA + ".rotateOrder", 1) cmds.setAttr(self.chestB + ".rotateOrder", 1) else: cmds.setAttr(self.hipsA + ".rotateOrder", 4) cmds.setAttr(self.hipsB + ".rotateOrder", 4) cmds.setAttr(self.chestA + ".rotateOrder", 4) cmds.setAttr(self.chestB + ".rotateOrder", 4) # Keep a list of ctrls we want to colorize a certain way self.aFkCtrl.append([self.hipsB, self.chestB]) self.aIkCtrl.append([self.hipsA, self.chestA]) # organize hierarchy: cmds.parent(self.hipsB, self.hipsA) cmds.parent(self.chestB, self.chestA) cmds.parent(self.chestA, self.hipsA) cmds.rotate(-90, 0, 0, self.hipsA) cmds.makeIdentity(self.hipsA, apply=True, rotate=True) # position of controls: bottomLocGuide = side + self.userGuideName + "_Guide_JointLoc1" topLocGuide = side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints) # snap controls to guideLocators: tempDel = cmds.parentConstraint(bottomLocGuide, self.hipsA, maintainOffset=False) cmds.delete(tempDel) tempDel = cmds.parentConstraint(topLocGuide, self.chestA, maintainOffset=False) cmds.delete(tempDel) # zeroOut transformations: utils.zeroOut([self.hipsA, self.chestA]) # modify the pivots of chest controls: upPivotPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints - 1), query=True, worldSpace=True, translation=True) cmds.move(upPivotPos[0], upPivotPos[1], upPivotPos[2], self.chestA + ".scalePivot", self.chestA + ".rotatePivot") # , self.chestB+".scalePivot", self.chestB+".rotatePivot") # add originedFrom attributes to hipsA, hipsB and chestB: utils.originedFrom(objName=self.hipsA, attrString=self.base) utils.originedFrom(objName=self.hipsB, attrString=bottomLocGuide) utils.originedFrom(objName=self.chestB, attrString=topLocGuide) # create a simple spine ribbon: returnedRibbonList = ctrls.createSimpleRibbon(name=side + self.userGuideName + '_Rbn', totalJoints=(self.nJoints - 1)) rbnNurbsPlane = returnedRibbonList[0] rbnNurbsPlaneShape = returnedRibbonList[1] rbnJointGrpList = returnedRibbonList[2] self.aRbnJointList = returnedRibbonList[3] # position of ribbon nurbs plane: cmds.setAttr(rbnNurbsPlane + ".tz", -4) cmds.move(0, 0, 0, rbnNurbsPlane + ".scalePivot", rbnNurbsPlane + ".rotatePivot") cmds.rotate(90, 90, 0, rbnNurbsPlane) cmds.makeIdentity(rbnNurbsPlane, apply=True, translate=True, rotate=True) downLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc1", query=True, worldSpace=True, translation=True) upLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints), query=True, worldSpace=True, translation=True) cmds.move(downLocPos[0], downLocPos[1], downLocPos[2], rbnNurbsPlane) # create up and down clusters: downCluster = \ cmds.cluster(rbnNurbsPlane + ".cv[0:3][0:1]", name=side + self.userGuideName + '_Down_Cls')[1] upCluster = \ cmds.cluster(rbnNurbsPlane + ".cv[0:3][" + str(self.nJoints) + ":" + str(self.nJoints + 1) + "]", name=side + self.userGuideName + '_Up_Cls')[1] # get positions of joints from ribbon nurbs plane: startRbnJointPos = cmds.xform(side + self.userGuideName + "_Rbn0_Jnt", query=True, worldSpace=True, translation=True) endRbnJointPos = cmds.xform(side + self.userGuideName + "_Rbn" + str(self.nJoints - 1) + "_Jnt", query=True, worldSpace=True, translation=True) # move pivots of clusters to start and end positions: cmds.move(startRbnJointPos[0], startRbnJointPos[1], startRbnJointPos[2], downCluster + ".scalePivot", downCluster + ".rotatePivot") cmds.move(endRbnJointPos[0], endRbnJointPos[1], endRbnJointPos[2], upCluster + ".scalePivot", upCluster + ".rotatePivot") # snap clusters to guideLocators: tempDel = cmds.parentConstraint(bottomLocGuide, downCluster, maintainOffset=False) cmds.delete(tempDel) tempDel = cmds.parentConstraint(topLocGuide, upCluster, maintainOffset=False) cmds.delete(tempDel) # rotate clusters to compensate guide: upClusterRot = cmds.xform(upCluster, query=True, worldSpace=True, rotation=True) downClusterRot = cmds.xform(downCluster, query=True, worldSpace=True, rotation=True) cmds.xform(upCluster, worldSpace=True, rotation=(upClusterRot[0] + 90, upClusterRot[1], upClusterRot[2])) cmds.xform(downCluster, worldSpace=True, rotation=(downClusterRot[0] + 90, downClusterRot[1], downClusterRot[2])) # scaleY of the clusters in order to avoid great extremity deforms: rbnHeight = ctrls.distanceBet(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints), side + self.userGuideName + "_Guide_JointLoc1", keep=False)[0] cmds.setAttr(upCluster + ".sy", rbnHeight / 10) cmds.setAttr(downCluster + ".sy", rbnHeight / 10) # parent clusters in controls (up and down): cmds.parentConstraint(self.hipsB, downCluster, maintainOffset=True, name=downCluster + "_ParentConstraint") cmds.parentConstraint(self.chestB, upCluster, maintainOffset=True, name=upCluster + "_ParentConstraint") # organize a group of clusters: clustersGrp = cmds.group(name=side + self.userGuideName + "_Rbn_Clusters_Grp", empty=True) self.aClusterGrp.append(clustersGrp) if hideJoints: cmds.setAttr(clustersGrp + ".visibility", 0) cmds.parent(downCluster, upCluster, clustersGrp, relative=True) # make ribbon joints groups scalable: for r, rbnJntGrp in enumerate(rbnJointGrpList): if ((r >= 0) and (r < (len(rbnJointGrpList) - 1))): scaleGrp = cmds.group(rbnJntGrp, name=rbnJntGrp.replace("_Grp", "_Scale_Grp")) ctrls.directConnect(scaleGrp, rbnJntGrp, ['sx', 'sz']) cmds.scaleConstraint(clustersGrp, scaleGrp, maintainOffset=True, name=rbnJntGrp + "_Scale") else: cmds.scaleConstraint(clustersGrp, rbnJntGrp, maintainOffset=True, name=rbnJntGrp + "_Scale") # calculate the distance to volumeVariation: arcLenShape = cmds.createNode('arcLengthDimension', name=side + self.userGuideName + "_Rbn_ArcLenShape") arcLenFather = cmds.listRelatives(arcLenShape, parent=True)[0] arcLen = cmds.rename(arcLenFather, side + self.userGuideName + "_Rbn_ArcLen") arcLenShape = cmds.listRelatives(arcLen, children=True, shapes=True)[0] cmds.setAttr(arcLen + '.visibility', 0) # connect nurbsPlaneShape to arcLength node: cmds.connectAttr(rbnNurbsPlaneShape + '.worldSpace[0]', arcLenShape + '.nurbsGeometry') cmds.setAttr(arcLenShape + '.vParamValue', 1) # avoid undesired squash if rotateZ the nurbsPlane: cmds.setAttr(arcLenShape + '.uParamValue', 0.5) arcLenValue = cmds.getAttr(arcLenShape + '.arcLengthInV') # create a multiplyDivide to output the squashStretch values: rbnMD = cmds.createNode('multiplyDivide', name=side + self.userGuideName + "_Rbn_MD") cmds.connectAttr(arcLenShape + '.arcLengthInV', rbnMD + '.input2X') cmds.setAttr(rbnMD + '.input1X', arcLenValue) cmds.setAttr(rbnMD + '.operation', 2) # create a blendColor in order to get the correct result value of volumeVariation: rbnBlendColors = cmds.createNode('blendColors', name=side + self.userGuideName + "_Rbn_BlendColor") cmds.connectAttr(self.hipsA + '.' + side + self.userGuideName + '_' + self.langDic[self.langName][ 'c_volumeVariation'], rbnBlendColors + '.blender') cmds.connectAttr(rbnMD + '.outputX', rbnBlendColors + '.color1R') cmds.setAttr(rbnBlendColors + '.color2R', 1) # middle ribbon setup: for n in range(1, self.nJoints - 1): self.middle = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_middle'] + str( n) + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=self.ctrlRadius)[0] cmds.setAttr(self.middle + ".rotateOrder", 4) self.aFkCtrl[s].append(self.middle) ctrls.setLockHide([self.middle], ['sx', 'sy', 'sz']) cmds.setAttr(self.middle + '.visibility', keyable=False) cmds.parent(self.middle, self.hipsA) middleLocGuide = side + self.userGuideName + "_Guide_JointLoc" + str(n + 1) tempDel = cmds.parentConstraint(middleLocGuide, self.middle, maintainOffset=False) cmds.delete(tempDel) utils.zeroOut([self.middle]) middleCluster = cmds.cluster(rbnNurbsPlane + ".cv[0:3][" + str(n + 1) + "]", name=side + self.userGuideName + '_Middle_Cls')[1] middleLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(n), query=True, worldSpace=True, translation=True) tempDel = cmds.parentConstraint(middleLocGuide, middleCluster, maintainOffset=False) cmds.delete(tempDel) middleClusterRot = cmds.xform(middleCluster, query=True, worldSpace=True, rotation=True) cmds.xform(middleCluster, worldSpace=True, rotation=(middleClusterRot[0] + 90, middleClusterRot[1], middleClusterRot[2])) cmds.parentConstraint(self.middle, middleCluster, maintainOffset=True, name=middleCluster + "_ParentConstraint") # parenting constraints like guide locators: self.parentConst = cmds.parentConstraint(self.hipsB, self.chestB, self.middle + "_Zero", name=self.middle + "_ParentConstraint", maintainOffset=True)[0] nParentValue = (n) / float(self.nJoints - 1) cmds.setAttr(self.parentConst + "." + self.hipsB + "W0", 1 - nParentValue) cmds.setAttr(self.parentConst + "." + self.chestB + "W1", nParentValue) cmds.parent(middleCluster, clustersGrp, relative=True) # add originedFrom attribute to this middle ctrl: utils.originedFrom(objName=self.middle, attrString=middleLocGuide) # apply volumeVariation to joints in the middle ribbon setup: cmds.connectAttr(rbnBlendColors + '.outputR', self.aRbnJointList[n] + '.scaleX') cmds.connectAttr(rbnBlendColors + '.outputR', self.aRbnJointList[n] + '.scaleZ') # create a multiplyDivide to use the Stretch/Squash value on the first bone of the spine # lesser than the middle rbnFirstJntMD = cmds.createNode('multiplyDivide', name=side + self.userGuideName + "_Rbn_FirstJnt_MD") cmds.connectAttr(rbnBlendColors + '.outputR', rbnFirstJntMD + '.input2X') cmds.setAttr(rbnFirstJntMD + '.input1X', 0.8) cmds.setAttr(rbnFirstJntMD + '.operation', 1) # apply volumeVariation to the first joint of the ribbon: cmds.connectAttr(rbnFirstJntMD + '.outputX', self.aRbnJointList[0] + '.scaleX') cmds.connectAttr(rbnFirstJntMD + '.outputX', self.aRbnJointList[0] + '.scaleZ') # organize groups: self.rbnRigGrp = cmds.group(name=side + self.userGuideName + "_Grp", empty=True) self.rbnControlGrp = cmds.group(name=side + self.userGuideName + "_Control_Grp", empty=True) cmds.parent(self.hipsA + "_Zero", self.rbnControlGrp, relative=True) cmds.parent(clustersGrp, side + self.userGuideName + "_Rbn_RibbonJoint_Grp", self.rbnControlGrp, arcLen, self.rbnRigGrp, relative=True) if hideJoints: cmds.setAttr(side + self.userGuideName + "_Rbn_RibbonJoint_Grp.visibility", 0) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.rbnControlGrp, hookType='ctrlHook') utils.addHook(objName=clustersGrp, hookType='scalableHook') utils.addHook(objName=self.rbnRigGrp, hookType='staticHook') cmds.addAttr(self.rbnRigGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.rbnRigGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.rbnRigGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.rbnRigGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.rbnRigGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.rbnRigGrp + '.dpAR_count', dpAR_count) # lockHide scale of up and down controls: ctrls.setLockHide([self.hipsA, self.hipsB, self.chestA, self.chestB], ['sx', 'sy', 'sz']) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # create lists to be integrated: self.footCtrlList, self.revFootCtrlZeroFinalList, self.revFootCtrlShapeList, self.toLimbIkHandleGrpList, self.parentConstList, self.footJntList, self.ballRFList, self.middleFootCtrlList, self.reverseFootAttrList = [], [], [], [], [], [], [], [], [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # redeclaring variables: self.base = side + self.userGuideName + "_Guide_Base" self.cvFootLoc = side + self.userGuideName + "_Guide_foot" self.cvRFALoc = side + self.userGuideName + "_Guide_RfA" self.cvRFBLoc = side + self.userGuideName + "_Guide_RfB" self.cvRFCLoc = side + self.userGuideName + "_Guide_RfC" self.cvRFDLoc = side + self.userGuideName + "_Guide_RfD" self.cvRFELoc = side + self.userGuideName + "_Guide_RfE" self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" # declaring attributes reading from dictionary: ankleRFAttr = self.langDic[self.langName]['c_leg_extrem'] middleRFAttr = self.langDic[self.langName]['c_RevFoot_middle'] outsideRFAttr = self.langDic[self.langName]['c_RevFoot_A'] insideRFAttr = self.langDic[self.langName]['c_RevFoot_B'] heelRFAttr = self.langDic[self.langName]['c_RevFoot_C'] toeRFAttr = self.langDic[self.langName]['c_RevFoot_D'] ballRFAttr = self.langDic[self.langName]['c_RevFoot_E'] footRFAttr = self.langDic[self.langName]['c_RevFoot_F'] sideRFAttr = self.langDic[self.langName]['c_RevFoot_G'] rfRoll = self.langDic[self.langName]['c_RevFoot_roll'] rfSpin = self.langDic[self.langName]['c_RevFoot_spin'] rfTurn = self.langDic[self.langName]['c_RevFoot_turn'] # creating joints: cmds.select(clear=True) self.footJnt = cmds.joint(name=side + self.userGuideName + "_" + ankleRFAttr.capitalize() + "_Jnt") self.middleFootJxt = cmds.joint( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_Jxt") self.endJnt = cmds.joint(name=side + self.userGuideName + "_JEnd") cmds.select(clear=True) self.middleFootJnt = cmds.joint( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_Jnt") self.endBJnt = cmds.joint(name=side + self.userGuideName + "B_JEnd") cmds.parent(self.middleFootJnt, self.middleFootJxt) cmds.addAttr(self.footJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.addAttr(self.middleFootJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.select(clear=True) # reverse foot joints: self.RFAJxt = cmds.joint(name=side + self.userGuideName + "_" + outsideRFAttr.capitalize() + "_Jxt") self.RFBJxt = cmds.joint(name=side + self.userGuideName + "_" + insideRFAttr.capitalize() + "_Jxt") self.RFCJxt = cmds.joint(name=side + self.userGuideName + "_" + heelRFAttr.capitalize() + "_Jxt") self.RFDJxt = cmds.joint(name=side + self.userGuideName + "_" + toeRFAttr.capitalize() + "_Jxt") self.RFEJxt = cmds.joint(name=side + self.userGuideName + "_" + ballRFAttr.capitalize() + "_Jxt") self.RFEndJxt = cmds.joint(name=side + self.userGuideName + "_RFEnd_Jxt") rfJointList = [ self.RFAJxt, self.RFBJxt, self.RFCJxt, self.RFDJxt, self.RFEJxt ] self.ballRFList.append(self.RFEJxt) # set as template using overrides in order to permit no template children: for rfJoint in rfJointList: cmds.setAttr(rfJoint + '.overrideEnabled', 1) cmds.setAttr(rfJoint + '.overrideDisplayType', 1) cmds.setAttr(self.footJnt + '.overrideEnabled', 1) cmds.setAttr(self.middleFootJnt + '.overrideEnabled', 1) # reverse foot zero out joints: self.RFEJzt = utils.zeroOutJoints([self.RFEJxt])[0] self.RFDJzt = utils.zeroOutJoints([self.RFDJxt])[0] self.RFCJzt = utils.zeroOutJoints([self.RFCJxt])[0] self.RFBJzt = utils.zeroOutJoints([self.RFBJxt])[0] self.RFAJzt = utils.zeroOutJoints([self.RFAJxt])[0] rfJointZeroList = [ self.RFAJzt, self.RFBJzt, self.RFCJzt, self.RFDJzt, self.RFEJzt ] # putting joints in the correct place: tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footJnt, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootJxt, maintainOffset=False) tempToDelC = cmds.parentConstraint(self.cvEndJoint, self.endJnt, maintainOffset=False) tempToDelD = cmds.parentConstraint(self.cvEndJoint, self.endBJnt, maintainOffset=False) tempToDelE = cmds.parentConstraint(self.cvRFALoc, self.RFAJzt, maintainOffset=False) tempToDelF = cmds.parentConstraint(self.cvRFBLoc, self.RFBJzt, maintainOffset=False) tempToDelG = cmds.parentConstraint(self.cvRFCLoc, self.RFCJzt, maintainOffset=False) tempToDelH = cmds.parentConstraint(self.cvRFDLoc, self.RFDJzt, maintainOffset=False) tempToDelI = cmds.parentConstraint(self.cvRFELoc, self.RFEJzt, maintainOffset=False) tempToDelJ = cmds.parentConstraint(self.cvEndJoint, self.RFEndJxt, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB, tempToDelC, tempToDelD, tempToDelE, tempToDelF, tempToDelG, tempToDelH, tempToDelI, tempToDelJ) cmds.makeIdentity(rfJointZeroList, apply=True, translate=True, rotate=True, scale=True) # creating ikHandles: ikHandleAnkleList = cmds.ikHandle( name=side + self.userGuideName + "_" + ankleRFAttr.capitalize() + "_IkHandle", startJoint=self.footJnt, endEffector=self.middleFootJxt, solver='ikSCsolver') ikHandleMiddleList = cmds.ikHandle( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_IkHandle", startJoint=self.middleFootJxt, endEffector=self.endJnt, solver='ikSCsolver') cmds.rename(ikHandleAnkleList[1], ikHandleAnkleList[0] + "_Effector") cmds.rename(ikHandleMiddleList[1], ikHandleMiddleList[0] + "_Effector") cmds.setAttr(ikHandleAnkleList[0] + '.visibility', 0) cmds.setAttr(ikHandleMiddleList[0] + '.visibility', 0) # creating Fk controls: self.footCtrl = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_leg_extrem'] + "_Ctrl", ch=False, o=True, nr=(1, 0, 0), d=3, s=8, radius=self.ctrlRadius / 2.0)[0] self.footCtrlList.append(self.footCtrl) cmds.setAttr(self.footCtrl + ".rotateOrder", 1) self.revFootCtrlShapeList.append( cmds.listRelatives(self.footCtrl, children=True, type='nurbsCurve')[0]) self.middleFootCtrl = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[ self.langName]['c_RevFoot_middle'].capitalize() + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=1, s=8, radius=self.ctrlRadius / 2.0)[0] cmds.setAttr(self.middleFootCtrl + '.overrideEnabled', 1) cmds.setAttr(self.middleFootCtrl + ".rotateOrder", 4) tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footCtrl, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootCtrl, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB) self.footCtrlZeroList = utils.zeroOut( [self.footCtrl, self.middleFootCtrl]) self.revFootCtrlZeroFinalList.append(self.footCtrlZeroList[0]) self.middleFootCtrlList.append(self.middleFootCtrl) # mount hierarchy: cmds.parent(self.footCtrlZeroList[1], self.RFDJxt, absolute=True) cmds.parent(ikHandleMiddleList[0], self.middleFootCtrl, absolute=True) self.toLimbIkHandleGrp = cmds.group( empty=True, name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_leg_extrem'] + "_Grp") self.toLimbIkHandleGrpList.append(self.toLimbIkHandleGrp) cmds.parent(ikHandleAnkleList[0], self.toLimbIkHandleGrp, self.RFEJxt, absolute=True) cmds.makeIdentity(self.toLimbIkHandleGrp, apply=True, translate=True, rotate=True, scale=True) parentConst = cmds.parentConstraint(self.RFEJxt, self.footJnt, maintainOffset=True, name=self.footJnt + "_ParentConstraint")[0] self.parentConstList.append(parentConst) self.footJntList.append(self.footJnt) cmds.parent(self.RFAJzt, self.footCtrl, absolute=True) cmds.scaleConstraint(self.footCtrl, self.footJnt, maintainOffset=True, name=self.footJnt + "_ScaleConstraint") cmds.parentConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt + "_ParentConstraint") cmds.scaleConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt + "_ScaleConstraint") # add attributes to footCtrl and connect them to joint rotation: rfAttrList = [ outsideRFAttr, insideRFAttr, heelRFAttr, toeRFAttr, ballRFAttr ] rfTypeAttrList = [rfRoll, rfSpin] for j, rfAttr in enumerate(rfAttrList): for t, rfType in enumerate(rfTypeAttrList): if t == 1 and j == (len(rfAttrList) - 1): # create turn attr to ball cmds.addAttr(self.footCtrl, longName=rfAttr + "_" + rfTurn, attributeType='float', keyable=True) cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfTurn, rfJointList[j] + ".rotateX", force=True) self.reverseFootAttrList.append(rfAttr + "_" + rfTurn) cmds.addAttr(self.footCtrl, longName=rfAttr + "_" + rfType, attributeType='float', keyable=True) self.reverseFootAttrList.append(rfAttr + "_" + rfType) if t == 0: if j > 1: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateY", force=True) else: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateX", force=True) else: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateZ", force=True) # creating the originedFrom attributes (in order to permit integrated parents in the future): utils.originedFrom(objName=self.footCtrl, attrString=self.base + ";" + self.cvFootLoc + ";" + self.cvRFALoc + ";" + self.cvRFBLoc + ";" + self.cvRFCLoc + ";" + self.cvRFDLoc) utils.originedFrom(objName=self.middleFootCtrl, attrString=self.cvRFELoc + ";" + self.cvEndJoint) # creating pre-defined attributes for footRoll and sideRoll attributes: cmds.addAttr(self.footCtrl, longName=footRFAttr + "_" + rfRoll, attributeType='float', keyable=True) cmds.addAttr(self.footCtrl, longName=sideRFAttr + "_" + rfRoll, attributeType='float', keyable=True) # create clampNodes in order to limit the side rotations: sideClamp = cmds.createNode("clamp", name=side + self.userGuideName + "_Side_Clp") # outside values in R cmds.setAttr(sideClamp + ".maxR", 360) # inside values in G cmds.setAttr(sideClamp + ".minG", -360) # connections: cmds.connectAttr(self.footCtrl + "." + sideRFAttr + "_" + rfRoll, sideClamp + ".inputR", force=True) cmds.connectAttr(self.footCtrl + "." + sideRFAttr + "_" + rfRoll, sideClamp + ".inputG", force=True) cmds.connectAttr(sideClamp + ".outputR", self.RFAJzt + ".rotateX", force=True) cmds.connectAttr(sideClamp + ".outputG", self.RFBJzt + ".rotateX", force=True) # for footRoll: footClamp = cmds.createNode("clamp", name=side + self.userGuideName + "_Foot_Clp") # heel values in R cmds.setAttr(footClamp + ".maxR", 360) cmds.connectAttr(self.footCtrl + "." + footRFAttr + "_" + rfRoll, footClamp + ".inputR", force=True) cmds.connectAttr(footClamp + ".outputR", self.RFCJzt + ".rotateY", force=True) # set driven keys cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=0, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-45, value=-45, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-200, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-30, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-60, value=-30, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-360, value=-180, inTangentType="flat", outTangentType="flat") # organizing keyable attributes: ctrls.setLockHide([self.middleFootCtrl, self.footCtrl], ['v'], l=False) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( self.footCtrlZeroList[0], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( self.footJnt, name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # create lists to be integrated: # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_'] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # redeclaring variables: self.base = side + self.userGuideName + "_Guide_Base" self.cvFootLoc = side + self.userGuideName + "_Guide_foot" self.cvRFALoc = side + self.userGuideName + "_Guide_RfA" self.cvRFBLoc = side + self.userGuideName + "_Guide_RfB" self.cvRFCLoc = side + self.userGuideName + "_Guide_RfC" self.cvRFDLoc = side + self.userGuideName + "_Guide_RfD" self.cvRFELoc = side + self.userGuideName + "_Guide_RfE" self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" # declaring attributes reading from dictionary: ankleRFAttr = self.langDic[self.langName]['c_leg_extrem'] middleRFAttr = self.langDic[self.langName]['c_RevFoot_middle'] outsideRFAttr = self.langDic[self.langName]['c_RevFoot_A'] insideRFAttr = self.langDic[self.langName]['c_RevFoot_B'] heelRFAttr = self.langDic[self.langName]['c_RevFoot_C'] toeRFAttr = self.langDic[self.langName]['c_RevFoot_D'] ballRFAttr = self.langDic[self.langName]['c_RevFoot_E'] footRFAttr = self.langDic[self.langName]['c_RevFoot_F'] sideRFAttr = self.langDic[self.langName]['c_RevFoot_G'] rfRoll = self.langDic[self.langName]['c_RevFoot_roll'] rfSpin = self.langDic[self.langName]['c_RevFoot_spin'] rfTurn = self.langDic[self.langName]['c_RevFoot_turn'] # creating joints: cmds.select(clear=True) self.footJnt = cmds.joint(name=side + self.userGuideName + "_" + ankleRFAttr.capitalize() + "_Jnt") self.middleFootJxt = cmds.joint( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_Jxt") self.endJnt = cmds.joint(name=side + self.userGuideName + "_JEnd") cmds.select(clear=True) self.middleFootJnt = cmds.joint( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_Jnt") self.endBJnt = cmds.joint(name=side + self.userGuideName + "B_JEnd") cmds.parent(self.middleFootJnt, self.middleFootJxt) cmds.addAttr(self.footJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.addAttr(self.middleFootJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.select(clear=True) ''' Deactivate the segment scale compensate on the bone to prevent scaling problem in maya 2016 It will prevent a double scale problem that will come from the upper parent in the rig ''' if (int(cmds.about(version=True)[:4]) >= 2016): cmds.setAttr(self.footJnt+".segmentScaleCompensate", 0) cmds.setAttr(self.middleFootJxt+".segmentScaleCompensate", 0) cmds.setAttr(self.middleFootJnt+".segmentScaleCompensate", 0) # reverse foot groups: self.RFAJxt = cmds.group(name=side + self.userGuideName + "_" + outsideRFAttr.capitalize() + "_Grp", empty=True) self.RFBJxt = cmds.group(name=side + self.userGuideName + "_" + insideRFAttr.capitalize() + "_Grp", empty=True) self.RFCJxt = cmds.group(name=side + self.userGuideName + "_" + heelRFAttr.capitalize() + "_Grp", empty=True) self.RFDJxt = cmds.group(name=side + self.userGuideName + "_" + toeRFAttr.capitalize() + "_Grp", empty=True) self.RFEJxt = cmds.group(name=side + self.userGuideName + "_" + ballRFAttr.capitalize() + "_Grp", empty=True) self.RFEndJxt = cmds.group(name=side + self.userGuideName + "_RFEnd_Grp", empty=True) rfJointList = [self.RFAJxt, self.RFBJxt, self.RFCJxt, self.RFDJxt, self.RFEJxt] self.ballRFList.append(self.RFEJxt) cmds.parent(self.RFBJxt, self.RFAJxt) cmds.parent(self.RFCJxt, self.RFBJxt) cmds.parent(self.RFDJxt, self.RFCJxt) cmds.parent(self.RFEJxt, self.RFDJxt) cmds.parent(self.RFEndJxt, self.RFEJxt) # reverse foot zero out groups: self.RFEJzt = utils.zeroOut([self.RFEJxt])[0] self.RFDJzt = utils.zeroOut([self.RFDJxt])[0] self.RFCJzt = utils.zeroOut([self.RFCJxt])[0] self.RFBJzt = utils.zeroOut([self.RFBJxt])[0] self.RFAJzt = utils.zeroOut([self.RFAJxt])[0] self.RFAJztExtra = utils.zeroOut([self.RFAJzt])[0] rfJointZeroList = [self.RFAJzt, self.RFBJzt, self.RFCJzt, self.RFDJzt, self.RFEJzt] # putting groups in the correct place: tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footJnt, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootJxt, maintainOffset=False) tempToDelC = cmds.parentConstraint(self.cvEndJoint, self.endJnt, maintainOffset=False) tempToDelD = cmds.parentConstraint(self.cvEndJoint, self.endBJnt, maintainOffset=False) tempToDelE = cmds.parentConstraint(self.cvRFALoc, self.RFAJztExtra, maintainOffset=False) tempToDelF = cmds.parentConstraint(self.cvRFBLoc, self.RFBJzt, maintainOffset=False) tempToDelG = cmds.parentConstraint(self.cvRFCLoc, self.RFCJzt, maintainOffset=False) tempToDelH = cmds.parentConstraint(self.cvRFDLoc, self.RFDJzt, maintainOffset=False) tempToDelI = cmds.parentConstraint(self.cvRFELoc, self.RFEJzt, maintainOffset=False) tempToDelJ = cmds.parentConstraint(self.cvEndJoint, self.RFEndJxt, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB, tempToDelC, tempToDelD, tempToDelE, tempToDelF, tempToDelG, tempToDelH, tempToDelI, tempToDelJ) cmds.makeIdentity(rfJointZeroList, apply=True, translate=False, rotate=True, scale=True) # creating ikHandles: ikHandleAnkleList = cmds.ikHandle( name=side + self.userGuideName + "_" + ankleRFAttr.capitalize() + "_IkHandle", startJoint=self.footJnt, endEffector=self.middleFootJxt, solver='ikSCsolver') ikHandleMiddleList = cmds.ikHandle( name=side + self.userGuideName + "_" + middleRFAttr.capitalize() + "_IkHandle", startJoint=self.middleFootJxt, endEffector=self.endJnt, solver='ikSCsolver') cmds.rename(ikHandleAnkleList[1], ikHandleAnkleList[0] + "_Effector") cmds.rename(ikHandleMiddleList[1], ikHandleMiddleList[0] + "_Effector") cmds.setAttr(ikHandleAnkleList[0] + '.visibility', 0) cmds.setAttr(ikHandleMiddleList[0] + '.visibility', 0) # creating Fk controls: self.footCtrl = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_leg_extrem'] + "_Ctrl", ch=False, o=True, nr=(1, 0, 0), d=3, s=8, radius=self.ctrlRadius / 2.0)[0] self.footCtrlList.append(self.footCtrl) cmds.setAttr(self.footCtrl + ".rotateOrder", 1) self.revFootCtrlShapeList.append(cmds.listRelatives(self.footCtrl, children=True, type='nurbsCurve')[0]) self.middleFootCtrl = cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName][ 'c_RevFoot_middle'].capitalize() + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=1, s=8, radius=self.ctrlRadius / 2.0)[0] cmds.setAttr(self.middleFootCtrl + '.overrideEnabled', 1) cmds.setAttr(self.middleFootCtrl + ".rotateOrder", 4) tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footCtrl, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootCtrl, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB) self.footCtrlZeroList = utils.zeroOut([self.footCtrl, self.middleFootCtrl]) self.revFootCtrlZeroFinalList.append(self.footCtrlZeroList[0]) self.middleFootCtrlList.append(self.middleFootCtrl) # mount hierarchy: cmds.parent(self.footCtrlZeroList[1], self.RFDJxt, absolute=True) cmds.parent(ikHandleMiddleList[0], self.middleFootCtrl, absolute=True) self.toLimbIkHandleGrp = cmds.group(empty=True, name=side + self.userGuideName + "_" + self.langDic[self.langName][ 'c_leg_extrem'] + "_Grp") self.toLimbIkHandleGrpList.append(self.toLimbIkHandleGrp) cmds.parent(ikHandleAnkleList[0], self.toLimbIkHandleGrp, self.RFEJxt, absolute=True) cmds.makeIdentity(self.toLimbIkHandleGrp, apply=True, translate=True, rotate=True, scale=True) parentConst = cmds.parentConstraint(self.RFEJxt, self.footJnt, maintainOffset=True, name=self.footJnt + "_ParentConstraint")[0] self.parentConstList.append(parentConst) self.footJntList.append(self.footJnt) cmds.parent(self.RFAJztExtra, self.footCtrl, absolute=True) scaleConst = cmds.scaleConstraint(self.footCtrl, self.footJnt, maintainOffset=True, name=self.footJnt + "_ScaleConstraint") self.scaleConstList.append(scaleConst) cmds.parentConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt + "_ParentConstraint") cmds.scaleConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt + "_ScaleConstraint") # add attributes to footCtrl and connect them to reverseFoot groups rotation: rfAttrList = [outsideRFAttr, insideRFAttr, heelRFAttr, toeRFAttr, ballRFAttr] rfTypeAttrList = [rfRoll, rfSpin] for j, rfAttr in enumerate(rfAttrList): for t, rfType in enumerate(rfTypeAttrList): if t == 1 and j == (len(rfAttrList) - 1): # create turn attr to ball cmds.addAttr(self.footCtrl, longName=rfAttr + "_" + rfTurn, attributeType='float', keyable=True) cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfTurn, rfJointList[j] + ".rotateX", force=True) self.reverseFootAttrList.append(rfAttr + "_" + rfTurn) cmds.addAttr(self.footCtrl, longName=rfAttr + "_" + rfType, attributeType='float', keyable=True) self.reverseFootAttrList.append(rfAttr + "_" + rfType) if t == 0: if j > 1: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateY", force=True) else: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateX", force=True) else: cmds.connectAttr(self.footCtrl + "." + rfAttr + "_" + rfType, rfJointList[j] + ".rotateZ", force=True) # creating the originedFrom attributes (in order to permit integrated parents in the future): utils.originedFrom(objName=self.footCtrl, attrString=self.base + ";" + self.cvFootLoc + ";" + self.cvRFALoc + ";" + self.cvRFBLoc + ";" + self.cvRFCLoc + ";" + self.cvRFDLoc) utils.originedFrom(objName=self.middleFootCtrl, attrString=self.cvRFELoc + ";" + self.cvEndJoint) # creating pre-defined attributes for footRoll and sideRoll attributes: cmds.addAttr(self.footCtrl, longName=footRFAttr + "_" + rfRoll, attributeType='float', keyable=True) cmds.addAttr(self.footCtrl, longName=sideRFAttr + "_" + rfRoll, attributeType='float', keyable=True) # create clampNodes in order to limit the side rotations: sideClamp = cmds.createNode("clamp", name=side + self.userGuideName + "_Side_Clp") # outside values in R cmds.setAttr(sideClamp + ".maxR", 360) # inside values in G cmds.setAttr(sideClamp + ".minG", -360) # connections: cmds.connectAttr(self.footCtrl + "." + sideRFAttr + "_" + rfRoll, sideClamp + ".inputR", force=True) cmds.connectAttr(self.footCtrl + "." + sideRFAttr + "_" + rfRoll, sideClamp + ".inputG", force=True) cmds.connectAttr(sideClamp + ".outputR", self.RFAJzt + ".rotateX", force=True) cmds.connectAttr(sideClamp + ".outputG", self.RFBJzt + ".rotateX", force=True) # for footRoll: footClamp = cmds.createNode("clamp", name=side + self.userGuideName + "_Foot_Clp") # heel values in R cmds.setAttr(footClamp + ".maxR", 360) cmds.connectAttr(self.footCtrl + "." + footRFAttr + "_" + rfRoll, footClamp + ".inputR", force=True) cmds.connectAttr(footClamp + ".outputR", self.RFCJzt + ".rotateY", force=True) # set driven keys cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=0, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-45, value=-45, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFEJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-200, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-30, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-60, value=-30, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFDJzt + ".rotateY", currentDriver=self.footCtrl + "." + footRFAttr + "_" + rfRoll, driverValue=-360, value=-180, inTangentType="flat", outTangentType="flat") # organizing keyable attributes: ctrls.setLockHide([self.middleFootCtrl, self.footCtrl], ['v'], l=False) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(self.footCtrlZeroList[0], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.createNode("transform", name=side + self.userGuideName + "_Joint_Grp") mWorldFoot = cmds.getAttr(self.footJnt + ".worldMatrix") cmds.xform(self.toScalableHookGrp, m=mWorldFoot, ws=True) cmds.parent(self.footJnt, self.toScalableHookGrp, absolute=True) #Remove the Joint orient to make sure the bone is at the same orientation than it's parent cmds.setAttr(self.footJnt + ".jointOrientX", 0) cmds.setAttr(self.footJnt + ".jointOrientY", 0) cmds.setAttr(self.footJnt + ".jointOrientZ", 0) #self.toScalableHookGrp = cmds.group(self.footJnt, name=side + self.userGuideName + "_Joint_Grp") self.aScalableGrp.append(self.toScalableHookGrp) self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames)-1]+'_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr(side+self.userGuideName+"_Guide_Base.translate"+axis) flipedValue = gotValue*(-2) cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.translate'+axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side+self.userGuideName+'_Guide_Base' cmds.select(clear=True) # declare guide: self.guide = side+self.userGuideName+"_Guide_JointLoc1" # create a joint: self.jnt = cmds.joint(name=side+self.userGuideName+"_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) # create a control: if self.getHasIndirectSkin(): self.ctrl = cmds.circle(name=side+self.userGuideName+"_Ctrl", degree=3, normal=(0, 0, 1), r=self.ctrlRadius, s=6, ch=False)[0] else: self.ctrl = cmds.circle(name=side+self.userGuideName+"_Ctrl", degree=1, normal=(0, 0, 1), r=self.ctrlRadius, s=6, ch=False)[0] utils.originedFrom(objName=self.ctrl, attrString=self.base+";"+self.guide) # position and orientation of joint and control: cmds.delete(cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False)) cmds.delete(cmds.parentConstraint(self.guide, self.ctrl, maintainOffset=False)) # zeroOut controls: zeroOutCtrlGrp = utils.zeroOut([self.ctrl])[0] # hide visibility attribute: cmds.setAttr(self.ctrl+'.visibility', keyable=False) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 1: cmds.setAttr(zeroOutCtrlGrp+".scaleX", -1) cmds.setAttr(zeroOutCtrlGrp+".scaleY", -1) cmds.setAttr(zeroOutCtrlGrp+".scaleZ", -1) cmds.addAttr(self.ctrl, longName='scaleCompensate', attributeType="bool", keyable=True) cmds.setAttr(self.ctrl+".scaleCompensate", 1) cmds.connectAttr(self.ctrl+".scaleCompensate", self.jnt+".segmentScaleCompensate", force=True) if self.getHasIndirectSkin(): # create a fatherJoint: cmds.select(clear=True) jxtName = self.jnt.replace("_Jnt", "_Jxt") self.jxt = cmds.duplicate(self.jnt, name=jxtName)[0] cmds.deleteAttr(self.jxt, attribute="dpAR_joint") cmds.parent(self.jnt, self.jxt) attrList = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz'] for attr in attrList: cmds.connectAttr(self.ctrl+'.'+attr, self.jnt+'.'+attr) else: # create parentConstraint from ctrl to jnt: cmds.parentConstraint(self.ctrl, self.jnt, maintainOffset=False, name=self.jnt+"_ParentConstraint") # create scaleConstraint from ctrl to jnt: cmds.scaleConstraint(self.ctrl, self.jnt, maintainOffset=True, name=self.jnt+"_ScaleConstraint") # create end joint: cmds.select(self.jnt) self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" self.endJoint = cmds.joint(name=side+self.userGuideName+"_JEnd") cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(side+self.userGuideName+"_Ctrl_Zero", name=side+self.userGuideName+"_Control_Grp") if self.getHasIndirectSkin(): locScale = cmds.spaceLocator(name=side+self.userGuideName+"_Scalable_DO_NOT_DELETE")[0] self.toScalableHookGrp = cmds.group(locScale, name=side+self.userGuideName+"_IndirectSkin_Grp") jxtGrp = cmds.group(side+self.userGuideName+"_Jxt", name=side+self.userGuideName+"_Joint_Grp") self.toStaticHookGrp = cmds.group(jxtGrp, self.toScalableHookGrp, self.toCtrlHookGrp, name=side+self.userGuideName+"_Grp") else: self.toScalableHookGrp = cmds.group(side+self.userGuideName+"_Jnt", name=side+self.userGuideName+"_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side+self.userGuideName+"_Grp") # create a locator in order to avoid delete static or scalable group loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc+".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # create lists to be integrated: # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames) - 1]+'_'] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type")+1 # run for all sides for s, side in enumerate(sideList): # redeclaring variables: self.base = side+self.userGuideName+"_Guide_Base" self.cvFootLoc = side+self.userGuideName+"_Guide_Foot" self.cvRFALoc = side+self.userGuideName+"_Guide_RfA" self.cvRFBLoc = side+self.userGuideName+"_Guide_RfB" self.cvRFCLoc = side+self.userGuideName+"_Guide_RfC" self.cvRFDLoc = side+self.userGuideName+"_Guide_RfD" self.cvRFELoc = side+self.userGuideName+"_Guide_RfE" self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" # declaring attributes reading from dictionary: ankleRFAttr = self.langDic[self.langName]['c009_leg_extrem'] middleRFAttr = self.langDic[self.langName]['c017_RevFoot_middle'] outsideRFAttr = self.langDic[self.langName]['c010_RevFoot_A'] insideRFAttr = self.langDic[self.langName]['c011_RevFoot_B'] heelRFAttr = self.langDic[self.langName]['c012_RevFoot_C'] toeRFAttr = self.langDic[self.langName]['c013_RevFoot_D'] ballRFAttr = self.langDic[self.langName]['c014_RevFoot_E'] footRFAttr = self.langDic[self.langName]['c015_RevFoot_F'] sideRFAttr = self.langDic[self.langName]['c016_RevFoot_G'] rfRoll = self.langDic[self.langName]['c018_RevFoot_roll'] rfSpin = self.langDic[self.langName]['c019_RevFoot_spin'] rfTurn = self.langDic[self.langName]['c020_RevFoot_turn'] showCtrlsAttr = self.langDic[self.langName]['c021_showControls'] # creating joints: cmds.select(clear=True) self.footJnt = cmds.joint(name=side+self.userGuideName+"_"+ankleRFAttr.capitalize()+"_Jnt") utils.setJointLabel(self.footJnt, s+jointLabelAdd, 18, self.userGuideName+ "_"+ankleRFAttr.capitalize()) self.middleFootJxt = cmds.joint(name=side+self.userGuideName+"_"+middleRFAttr.capitalize()+"_Jxt") self.endJnt = cmds.joint(name=side+self.userGuideName+"_JEnd") cmds.select(clear=True) self.middleFootJnt = cmds.joint(name=side+self.userGuideName+"_"+middleRFAttr.capitalize()+"_Jnt") utils.setJointLabel(self.middleFootJnt, s+jointLabelAdd, 18, self.userGuideName+"_"+middleRFAttr.capitalize()) self.endBJnt = cmds.joint(name=side+self.userGuideName+"B_JEnd") cmds.parent(self.middleFootJnt, self.middleFootJxt) cmds.addAttr(self.footJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.addAttr(self.middleFootJnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.select(clear=True) ''' Deactivate the segment scale compensate on the bone to prevent scaling problem in maya 2016 It will prevent a double scale problem that will come from the upper parent in the rig ''' if (int(cmds.about(version=True)[:4]) >= 2016): cmds.setAttr(self.footJnt+".segmentScaleCompensate", 0) cmds.setAttr(self.middleFootJxt+".segmentScaleCompensate", 0) cmds.setAttr(self.middleFootJnt+".segmentScaleCompensate", 0) # reverse foot controls: self.RFACtrl = self.ctrls.cvControl("id_018_FootReverse", side+self.userGuideName+"_"+outsideRFAttr.capitalize()+"_Ctrl", r=(self.ctrlRadius*0.1), d=self.curveDegree) self.RFBCtrl = self.ctrls.cvControl("id_018_FootReverse", side+self.userGuideName+"_"+insideRFAttr.capitalize()+"_Ctrl", r=(self.ctrlRadius*0.1), d=self.curveDegree) self.RFCCtrl = self.ctrls.cvControl("id_018_FootReverse", side+self.userGuideName+"_"+heelRFAttr.capitalize()+"_Ctrl", r=(self.ctrlRadius*0.1), d=self.curveDegree, dir="+Y", rot=(0, 90, 0)) self.RFDCtrl = self.ctrls.cvControl("id_018_FootReverse", side+self.userGuideName+"_"+toeRFAttr.capitalize()+"_Ctrl", r=(self.ctrlRadius*0.1), d=self.curveDegree, dir="+Y", rot=(0, 90, 0)) self.RFECtrl = self.ctrls.cvControl("id_019_FootReverseE", side+self.userGuideName+"_"+ballRFAttr.capitalize()+"_Ctrl", r=(self.ctrlRadius*0.1), d=self.curveDegree, rot=(0, 90, 0)) # reverse foot groups: self.RFAGrp = cmds.group(self.RFACtrl, name=self.RFACtrl+"_Grp") self.RFBGrp = cmds.group(self.RFBCtrl, name=self.RFBCtrl+"_Grp") self.RFCGrp = cmds.group(self.RFCCtrl, name=self.RFCCtrl+"_Grp") self.RFDGrp = cmds.group(self.RFDCtrl, name=self.RFDCtrl+"_Grp") self.RFEGrp = cmds.group(self.RFECtrl, name=self.RFECtrl+"_Grp") rfGrpList = [self.RFAGrp, self.RFBGrp, self.RFCGrp, self.RFDGrp, self.RFEGrp] self.ballRFList.append(self.RFEGrp) # putting groups in the correct place: tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footJnt, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootJxt, maintainOffset=False) tempToDelC = cmds.parentConstraint(self.cvEndJoint, self.endJnt, maintainOffset=False) tempToDelD = cmds.parentConstraint(self.cvEndJoint, self.endBJnt, maintainOffset=False) tempToDelE = cmds.parentConstraint(self.cvRFALoc, self.RFAGrp, maintainOffset=False) tempToDelF = cmds.parentConstraint(self.cvRFBLoc, self.RFBGrp, maintainOffset=False) tempToDelG = cmds.parentConstraint(self.cvRFCLoc, self.RFCGrp, maintainOffset=False) tempToDelH = cmds.parentConstraint(self.cvRFDLoc, self.RFDGrp, maintainOffset=False) tempToDelI = cmds.parentConstraint(self.cvRFELoc, self.RFEGrp, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB, tempToDelC, tempToDelD, tempToDelE, tempToDelF, tempToDelG, tempToDelH, tempToDelI) # mounting hierarchy: cmds.parent(self.RFBGrp, self.RFACtrl) cmds.parent(self.RFCGrp, self.RFBCtrl) cmds.parent(self.RFDGrp, self.RFCCtrl) cmds.parent(self.RFEGrp, self.RFDCtrl) # reverse foot zero out groups: self.RFEZero = utils.zeroOut([self.RFEGrp])[0] self.RFDZero = utils.zeroOut([self.RFDGrp])[0] self.RFCZero = utils.zeroOut([self.RFCGrp])[0] self.RFBZero = utils.zeroOut([self.RFBGrp])[0] self.RFAZero = utils.zeroOut([self.RFAGrp])[0] self.RFAZeroExtra = utils.zeroOut([self.RFAZero])[0] rfJointZeroList = [self.RFAZero, self.RFBZero, self.RFCZero, self.RFDZero, self.RFEZero] # fixing side rool rotation order: cmds.setAttr(self.RFBZero+".rotateOrder", 5) # creating ikHandles: ikHandleAnkleList = cmds.ikHandle(name=side+self.userGuideName+"_"+ankleRFAttr.capitalize()+"_IkHandle", startJoint=self.footJnt, endEffector=self.middleFootJxt, solver='ikSCsolver') ikHandleMiddleList = cmds.ikHandle(name=side+self.userGuideName+"_"+middleRFAttr.capitalize()+"_IkHandle", startJoint=self.middleFootJxt, endEffector=self.endJnt, solver='ikSCsolver') cmds.rename(ikHandleAnkleList[1], ikHandleAnkleList[0]+"_Effector") cmds.rename(ikHandleMiddleList[1], ikHandleMiddleList[0]+"_Effector") cmds.setAttr(ikHandleAnkleList[0]+'.visibility', 0) cmds.setAttr(ikHandleMiddleList[0]+'.visibility', 0) # creating Fk controls: self.footCtrl = self.ctrls.cvControl("id_020_FootFk", side+self.userGuideName+"_"+self.langDic[self.langName]['c009_leg_extrem']+"_Ctrl", r=(self.ctrlRadius*0.5), d=self.curveDegree, dir="+Z") self.footCtrlList.append(self.footCtrl) cmds.setAttr(self.footCtrl+".rotateOrder", 1) self.revFootCtrlShapeList.append(cmds.listRelatives(self.footCtrl, children=True, type='nurbsCurve')[0]) self.middleFootCtrl = self.ctrls.cvControl("id_021_FootMiddle", side+self.userGuideName+"_"+self.langDic[self.langName]['c017_RevFoot_middle'].capitalize()+"_Ctrl", r=(self.ctrlRadius*0.5), d=self.curveDegree) cmds.setAttr(self.middleFootCtrl+'.overrideEnabled', 1) cmds.setAttr(self.middleFootCtrl+".rotateOrder", 4) tempToDelA = cmds.parentConstraint(self.cvFootLoc, self.footCtrl, maintainOffset=False) tempToDelB = cmds.parentConstraint(self.cvRFELoc, self.middleFootCtrl, maintainOffset=False) cmds.delete(tempToDelA, tempToDelB) if s == 1: cmds.setAttr(self.middleFootCtrl+".scaleX", -1) cmds.setAttr(self.middleFootCtrl+".scaleY", -1) cmds.setAttr(self.middleFootCtrl+".scaleZ", -1) self.footCtrlZeroList = utils.zeroOut([self.footCtrl, self.middleFootCtrl]) self.middleFootCtrlList.append(self.middleFootCtrl) # mount hierarchy: cmds.parent(self.footCtrlZeroList[1], self.RFDCtrl, absolute=True) cmds.parent(ikHandleMiddleList[0], self.middleFootCtrl, absolute=True) self.toLimbIkHandleGrp = cmds.group(empty=True, name=side+self.userGuideName+"_"+self.langDic[self.langName]['c009_leg_extrem']+"_Grp") self.toLimbIkHandleGrpList.append(self.toLimbIkHandleGrp) cmds.parent(ikHandleAnkleList[0], self.toLimbIkHandleGrp, self.RFECtrl, absolute=True) cmds.makeIdentity(self.toLimbIkHandleGrp, apply=True, translate=True, rotate=True, scale=True) parentConst = cmds.parentConstraint(self.RFECtrl, self.footJnt, maintainOffset=True, name=self.footJnt+"_ParentConstraint")[0] self.parentConstList.append(parentConst) self.footJntList.append(self.footJnt) cmds.parent(self.RFAZeroExtra, self.footCtrl, absolute=True) scaleConst = cmds.scaleConstraint(self.footCtrl, self.footJnt, maintainOffset=True, name=self.footJnt+"_ScaleConstraint") self.scaleConstList.append(scaleConst) cmds.parentConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt+"_ParentConstraint") cmds.scaleConstraint(self.middleFootCtrl, self.middleFootJnt, maintainOffset=True, name=self.middleFootJnt+"_ScaleConstraint") # add attributes to footCtrl and connect them to reverseFoot groups rotation: rfAttrList = [outsideRFAttr, insideRFAttr, heelRFAttr, toeRFAttr, ballRFAttr] rfTypeAttrList = [rfRoll, rfSpin] for j, rfAttr in enumerate(rfAttrList): for t, rfType in enumerate(rfTypeAttrList): if t == 1 and j == (len(rfAttrList) - 1): # create turn attr to ball cmds.addAttr(self.footCtrl, longName=rfAttr+"_"+rfTurn, attributeType='float', keyable=True) cmds.connectAttr(self.footCtrl+"."+rfAttr+"_"+rfTurn, rfGrpList[j]+".rotateZ", force=True) self.reverseFootAttrList.append(rfAttr+"_"+rfTurn) cmds.addAttr(self.footCtrl, longName=rfAttr+"_"+rfType, attributeType='float', keyable=True) self.reverseFootAttrList.append(rfAttr+"_"+rfType) if t == 0: if j > 1: cmds.connectAttr(self.footCtrl+"."+rfAttr+"_"+rfType, rfGrpList[j]+".rotateX", force=True) else: cmds.connectAttr(self.footCtrl+"."+rfAttr+"_"+rfType, rfGrpList[j]+".rotateZ", force=True) else: cmds.connectAttr(self.footCtrl+"."+rfAttr+"_"+rfType, rfGrpList[j]+".rotateY", force=True) # creating the originedFrom attributes (in order to permit integrated parents in the future): utils.originedFrom(objName=self.footCtrl, attrString=self.base+";"+self.cvFootLoc+";"+self.cvRFALoc+";"+self.cvRFBLoc+";"+self.cvRFCLoc+";"+self.cvRFDLoc) utils.originedFrom(objName=self.middleFootCtrl, attrString=self.cvRFELoc+";"+self.cvEndJoint) # creating pre-defined attributes for footRoll and sideRoll attributes: cmds.addAttr(self.footCtrl, longName=footRFAttr+"_"+rfRoll, attributeType='float', keyable=True) cmds.addAttr(self.footCtrl, longName=sideRFAttr+"_"+rfRoll, attributeType='float', keyable=True) # create clampNodes in order to limit the side rotations: sideClamp = cmds.createNode("clamp", name=side+self.userGuideName+"_Side_Clp") # outside values in R cmds.setAttr(sideClamp+".minR", -360) # inside values in G cmds.setAttr(sideClamp+".maxG", 360) # inverting sideRoll values: sideMD = cmds.createNode("multiplyDivide", name=side+self.userGuideName+"_Side_MD") cmds.setAttr(sideMD+".input2X", -1) # connections: cmds.connectAttr(self.footCtrl+"."+sideRFAttr+"_"+rfRoll, sideMD+".input1X", force=True) cmds.connectAttr(sideMD+".outputX", sideClamp+".inputR", force=True) cmds.connectAttr(sideMD+".outputX", sideClamp+".inputG", force=True) cmds.connectAttr(sideClamp+".outputR", self.RFAZero+".rotateZ", force=True) cmds.connectAttr(sideClamp+".outputG", self.RFBZero+".rotateZ", force=True) # for footRoll: footClamp = cmds.createNode("clamp", name=side+self.userGuideName+"_Foot_Clp") # heel values in R cmds.setAttr(footClamp+".minR", -360) cmds.connectAttr(self.footCtrl+"."+footRFAttr+"_"+rfRoll, footClamp+".inputR", force=True) cmds.connectAttr(footClamp+".outputR", self.RFCZero+".rotateX", force=True) # set driven keys cmds.setDrivenKeyframe(self.RFEZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=0, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFEZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=45, value=45, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFEZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=200, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=30, value=0, inTangentType="flat", outTangentType="flat") cmds.setDrivenKeyframe(self.RFDZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=60, value=30, inTangentType="spline", outTangentType="spline") cmds.setDrivenKeyframe(self.RFDZero+".rotateX", currentDriver=self.footCtrl+"."+footRFAttr+"_"+rfRoll, driverValue=360, value=180, inTangentType="flat", outTangentType="flat") # organizing keyable attributes: self.ctrls.setLockHide([self.middleFootCtrl, self.footCtrl], ['v'], l=False) # show or hide reverseFoot controls: cmds.addAttr(self.footCtrl, longName=showCtrlsAttr, attributeType='long', min=0, max=1, defaultValue=1) cmds.setAttr(self.footCtrl+"."+showCtrlsAttr, keyable=False, channelBox=True) showHideCtrlList = [self.RFACtrl, self.RFBCtrl, self.RFCCtrl, self.RFDCtrl] for rfCtrl in showHideCtrlList: rfCtrlShape = cmds.listRelatives(rfCtrl, children=True, type='nurbsCurve')[0] cmds.connectAttr(self.footCtrl+"."+showCtrlsAttr, rfCtrlShape+".visibility", force=True) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(self.footCtrlZeroList[0], name=side+self.userGuideName+"_Control_Grp") self.revFootCtrlGrpFinalList.append(self.toCtrlHookGrp) self.toScalableHookGrp = cmds.createNode("transform", name=side+self.userGuideName+"_Joint_Grp") mWorldFoot = cmds.getAttr(self.footJnt+".worldMatrix") cmds.xform(self.toScalableHookGrp, matrix=mWorldFoot, worldSpace=True) cmds.parent(self.footJnt, self.toScalableHookGrp, absolute=True) #Remove the Joint orient to make sure the bone is at the same orientation than it's parent cmds.setAttr(self.footJnt+".jointOrientX", 0) cmds.setAttr(self.footJnt+".jointOrientY", 0) cmds.setAttr(self.footJnt+".jointOrientZ", 0) self.aScalableGrp.append(self.toScalableHookGrp) self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side+self.userGuideName+"_Grp") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc+".visibility", 0) self.ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declare lists to store names and attributes: self.suspensionBCtrlGrpList, self.fatherBList, self.ctrlHookGrpList = [], [], [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # declare guide: self.base = side + self.userGuideName + '_Guide_Base' self.cvALoc = side + self.userGuideName + "_Guide_JointLocA" self.cvBLoc = side + self.userGuideName + "_Guide_JointLocB" self.radiusGuide = side + self.userGuideName + "_Guide_Base_RadiusCtrl" self.locatorsGrp = cmds.group(name=side + self.userGuideName + "_Loc_Grp", empty=True) # calculate distance between guide and end: self.dist = self.ctrls.distanceBet(self.cvALoc, self.cvBLoc)[0] * 0.2 self.jointList, self.mainCtrlList, self.ctrlZeroList, self.ctrlList, self.aimLocList, self.upLocList = [], [], [], [], [], [] for p, letter in enumerate(["A", "B"]): # create joints: cmds.select(clear=True) jnt = cmds.joint(name=side + self.userGuideName + "_" + letter + "_1_Jnt", scaleCompensate=False) endJoint = cmds.joint(name=side + self.userGuideName + "_" + letter + "_JEnd", scaleCompensate=False, radius=0.5) cmds.addAttr(jnt, longName='dpAR_joint', attributeType='float', keyable=False) cmds.setAttr(endJoint + ".translateZ", self.dist) # joint labelling: utils.setJointLabel(jnt, s + jointLabelAdd, 18, self.userGuideName + "_" + letter) self.jointList.append(jnt) # create a control: mainCtrl = self.ctrls.cvControl( "id_055_SuspensionMain", side + self.userGuideName + "_" + self.langDic[self.langName]["c058_main"] + "_" + letter + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree) ctrl = self.ctrls.cvControl("id_056_SuspensionAB", side + self.userGuideName + "_" + letter + "_Ctrl", r=self.ctrlRadius * 0.5, d=self.curveDegree) upLocCtrl = self.ctrls.cvControl( "id_057_SuspensionUpLoc", side + self.userGuideName + "_" + letter + "_UpLoc_Ctrl", r=self.ctrlRadius * 0.1, d=self.curveDegree) self.ctrls.setLockHide([ctrl], ['tx', 'ty', 'tz', 'v']) self.ctrls.setLockHide( [upLocCtrl], ['rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # position and orientation of joint and control: cmds.parent(ctrl, upLocCtrl, mainCtrl) cmds.parentConstraint(ctrl, jnt, maintainOffset=False, name=jnt + "_PaC") cmds.scaleConstraint(ctrl, jnt, maintainOffset=False, name=jnt + "_ScC") self.ctrlList.append(ctrl) # zeroOut controls: zeroOutCtrlGrp = utils.zeroOut([mainCtrl, ctrl, upLocCtrl]) self.mainCtrlList.append(zeroOutCtrlGrp[0]) self.ctrlZeroList.append(zeroOutCtrlGrp[1]) cmds.setAttr(zeroOutCtrlGrp[2] + ".translateX", self.dist) # origined from data: if p == 0: utils.originedFrom(objName=mainCtrl, attrString=self.base + ";" + self.cvALoc + ";" + self.radiusGuide) cmds.delete( cmds.parentConstraint(self.cvALoc, zeroOutCtrlGrp[0], maintainOffset=False)) else: utils.originedFrom(objName=mainCtrl, attrString=self.cvBLoc) cmds.delete( cmds.parentConstraint(self.cvBLoc, zeroOutCtrlGrp[0], maintainOffset=False)) # integrating data: self.suspensionBCtrlGrpList.append(zeroOutCtrlGrp[0]) # hide visibility attribute: cmds.setAttr(mainCtrl + '.visibility', keyable=False) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr(zeroOutCtrlGrp[0] + ".scaleX", -1) cmds.setAttr(zeroOutCtrlGrp[0] + ".scaleY", -1) cmds.setAttr(zeroOutCtrlGrp[0] + ".scaleZ", -1) cmds.addAttr(ctrl, longName='scaleCompensate', attributeType="bool", keyable=False) cmds.setAttr(ctrl + ".scaleCompensate", 1, channelBox=True) cmds.connectAttr(ctrl + ".scaleCompensate", jnt + ".segmentScaleCompensate", force=True) # working with aim setup: cmds.addAttr(ctrl, longName="active", attributeType="bool", defaultValue=1, keyable=True) aimLoc = cmds.spaceLocator(name=side + self.userGuideName + "_" + letter + "_Aim_Loc")[0] upLoc = cmds.spaceLocator(name=side + self.userGuideName + "_" + letter + "_Up_Loc")[0] locGrp = cmds.group(aimLoc, upLoc, name=side + self.userGuideName + "_" + letter + "_Loc_Grp") cmds.parent(locGrp, self.locatorsGrp, relative=True) cmds.delete( cmds.parentConstraint(ctrl, locGrp, maintainOffset=False)) cmds.parentConstraint(upLocCtrl, upLoc, maintainOffset=False, name=upLoc + "_PaC") cmds.parentConstraint(mainCtrl, locGrp, maintainOffset=True, name=locGrp + "_PaC") cmds.setAttr(locGrp + ".visibility", 0) self.aimLocList.append(aimLoc) self.upLocList.append(upLoc) # aim constraints: # B to A: aAimConst = cmds.aimConstraint(self.aimLocList[1], self.ctrlZeroList[0], aimVector=(0, 0, 1), upVector=(1, 0, 0), worldUpType="object", worldUpObject=self.upLocList[0], maintainOffset=True, name=self.ctrlZeroList[0] + "_AiC")[0] cmds.connectAttr(self.ctrlList[0] + ".active", aAimConst + "." + self.aimLocList[1] + "W0", force=True) # A to B: bAimConst = cmds.aimConstraint(self.aimLocList[0], self.ctrlZeroList[1], aimVector=(0, 0, 1), upVector=(1, 0, 0), worldUpType="object", worldUpObject=self.upLocList[1], maintainOffset=True, name=self.ctrlZeroList[0] + "_AiC")[0] cmds.connectAttr(self.ctrlList[1] + ".active", bAimConst + "." + self.aimLocList[0] + "W0", force=True) # integrating data: self.loadedFatherB = cmds.getAttr(self.moduleGrp + ".fatherB") if self.loadedFatherB: self.fatherBList.append(self.loadedFatherB) else: self.fatherBList.append(None) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( self.mainCtrlList, name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( self.jointList, name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, self.locatorsGrp, name=side + self.userGuideName + "_Grp") # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) self.ctrlHookGrpList.append(self.toCtrlHookGrp) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames)-1]+'_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr(side+self.userGuideName+"_Guide_Base.translate"+axis) flipedValue = gotValue*(-2) cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.translate'+axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # store the number of this guide by module type: dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # create a list to export: self.eyeScaleGrpList = [] # create the main control: self.eyeCtrl = cmds.circle(name=self.userGuideName+"_A_Ctrl", radius=(2.25*self.ctrlRadius), normal=(0,0,1), degree=3, constructionHistory=False)[0] cmds.addAttr(self.eyeCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', keyable=True, minValue=0, maxValue=1) cmds.setAttr(self.eyeCtrl+"."+self.langDic[self.langName]['c_Follow'], 1) cmds.move(0,-1,0, self.eyeCtrl+".cv[1]", relative=True) cmds.move(0,1,0, self.eyeCtrl+".cv[5]", relative=True) cmds.delete(cmds.parentConstraint(sideList[0]+self.userGuideName+"_Guide_JointEnd", self.eyeCtrl, maintainOffset=False)) cmds.setAttr(self.eyeCtrl+".translateX", 0) self.eyeGrp = cmds.group(self.eyeCtrl, name=self.userGuideName+"_A_Grp") utils.zeroOut([self.eyeCtrl]) self.upLocGrp = cmds.group(name=self.userGuideName+"_UpLoc_Grp", empty=True) # run for all sides: for s, side in enumerate(sideList): cmds.select(clear=True) self.base = side+self.userGuideName+'_Guide_Base' # declare guide: self.guide = side+self.userGuideName+"_Guide_JointLoc1" # create a joint: self.jxt = cmds.joint(name=side+self.userGuideName+"_1_Jxt", scaleCompensate=False) self.jnt = cmds.joint(name=side+self.userGuideName+"_1_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) self.fkEyeCtrl = cmds.circle(name=side+self.userGuideName+"_Fk_Ctrl", radius=self.ctrlRadius, normal=(0,0,1), degree=1, sections=6, constructionHistory=False)[0] utils.originedFrom(objName=self.fkEyeCtrl, attrString=self.base+";"+self.guide) self.baseEyeCtrl = ctrls.cvBox(ctrlName=side+self.userGuideName+"_Base_Ctrl", r=self.ctrlRadius) utils.originedFrom(objName=self.baseEyeCtrl, attrString=self.base+";"+self.guide) # position and orientation of joint and control: cmds.delete(cmds.parentConstraint(self.guide, self.jxt, maintainOffset=False)) cmds.delete(cmds.parentConstraint(self.guide, self.fkEyeCtrl, maintainOffset=False)) cmds.delete(cmds.parentConstraint(self.guide, self.baseEyeCtrl, maintainOffset=False)) cmds.makeIdentity(self.baseEyeCtrl, self.fkEyeCtrl, apply=True) # zeroOut controls: eyeZeroList = utils.zeroOut([self.baseEyeCtrl, self.fkEyeCtrl]) cmds.parent(eyeZeroList[1], self.baseEyeCtrl) # hide visibility attribute: cmds.setAttr(self.fkEyeCtrl+'.visibility', keyable=False) ctrls.setLockHide([self.fkEyeCtrl], ['tx', 'ty', 'tz']) # create end joint: self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" self.endJoint = cmds.joint(name=side+self.userGuideName+"_JEnd") cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) cmds.parent(self.endJoint, self.jnt, absolute=True) # create parentConstraint from ctrl to jxt: cmds.parentConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=False, name=self.jnt+"_ParentConstraint") # create scaleConstraint from ctrl to jnt: cmds.scaleConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=True, name=self.jnt+"_ScaleConstraint") # lookAt control: self.lookAtCtrl = cmds.circle(name=side+self.userGuideName+"_LookAt_Ctrl", radius=self.ctrlRadius, normal=(0,0,1), degree=3, constructionHistory=False)[0] cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.lookAtCtrl, maintainOffset=False)) cmds.parent(self.lookAtCtrl, self.eyeCtrl, relative=False) cmds.makeIdentity(self.lookAtCtrl, apply=True) cmds.addAttr(self.lookAtCtrl, longName="active", attributeType="bool", defaultValue=1, keyable=True) # up locator: self.lUpGrpLoc = cmds.group(name=side+self.userGuideName+"_Up_Loc_Grp", empty=True) cmds.delete(cmds.parentConstraint(self.jnt, self.lUpGrpLoc, maintainOffset=False)) self.lUpLoc = cmds.spaceLocator(name=side+self.userGuideName+"_Up_Loc")[0] cmds.delete(cmds.parentConstraint(self.jnt, self.lUpLoc, maintainOffset=False)) cmds.move(cmds.getAttr(self.guideName+"_JointEnd.translateZ"), self.lUpLoc, moveY=True, relative=True) cmds.parent(self.lUpLoc, self.lUpGrpLoc, relative=False) cmds.parent(self.lUpGrpLoc, self.upLocGrp, relative=False) # look at aim constraint: aimConst = cmds.aimConstraint(self.lookAtCtrl, self.fkEyeCtrl+"_Zero", worldUpType="object", worldUpObject=self.upLocGrp+"|"+self.lUpGrpLoc+"|"+self.lUpLoc, maintainOffset=True)[0] cmds.connectAttr(self.lookAtCtrl+".active", aimConst+"."+self.lookAtCtrl+"W0", force=True) # eye aim rotation cmds.addAttr(self.fkEyeCtrl, longName="aimRotation", attributeType="float", keyable=True) cmds.connectAttr(self.fkEyeCtrl+".aimRotation", self.jnt+".rotateZ", force=True) cmds.pointConstraint(self.baseEyeCtrl, self.lUpGrpLoc, maintainOffset=True, name=self.lUpGrpLoc+"_PointConstraint") # create eyeScale setup: cmds.select(clear=True) self.eyeScaleJnt = cmds.joint(name=side+self.userGuideName+"Scale_1_Jnt", scaleCompensate=False) cmds.addAttr(self.eyeScaleJnt, longName='dpAR_joint', attributeType='float', keyable=False) # jointScale position: cmds.delete(cmds.parentConstraint(self.guide, self.eyeScaleJnt, maintainOffset=False)) # create endScale joint: self.endScaleJoint = cmds.joint(name=side+self.userGuideName+"Scale_JEnd") cmds.delete(cmds.parentConstraint(self.eyeScaleJnt, self.endScaleJoint, maintainOffset=False)) cmds.setAttr(self.endScaleJoint+".translateZ", 1) # create constraints to eyeScale: cmds.pointConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=False, name=self.eyeScaleJnt+"_PointConstraint") cmds.scaleConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=True, name=self.eyeScaleJnt+"_ScaleConstraint") self.eyeScaleGrp = cmds.group(self.eyeScaleJnt, name=self.eyeScaleJnt+"_Grp") self.eyeScaleGrpList.append(self.eyeScaleGrp) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(eyeZeroList[0], name=side+self.userGuideName+"_Control_Grp") self.toScalableHookGrp = cmds.group(self.jxt, self.eyeScaleGrp, name=side+self.userGuideName+"_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side+self.userGuideName+"_Grp") if s == 0: cmds.parent(self.eyeGrp, self.toCtrlHookGrp) cmds.parent(self.upLocGrp, self.toScalableHookGrp) # create a locator in order to avoid delete static group: loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc+".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type: dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # create a list to export: self.eyeScaleGrpList = [] # create the main control: self.eyeCtrl = cmds.circle(name=self.userGuideName + "_A_Ctrl", radius=(2.25 * self.ctrlRadius), normal=(0, 0, 1), degree=3, constructionHistory=False)[0] cmds.addAttr(self.eyeCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', keyable=True, minValue=0, maxValue=1) cmds.setAttr( self.eyeCtrl + "." + self.langDic[self.langName]['c_Follow'], 1) cmds.move(0, -1, 0, self.eyeCtrl + ".cv[1]", relative=True) cmds.move(0, 1, 0, self.eyeCtrl + ".cv[5]", relative=True) cmds.delete( cmds.parentConstraint(sideList[0] + self.userGuideName + "_Guide_JointEnd", self.eyeCtrl, maintainOffset=False)) cmds.setAttr(self.eyeCtrl + ".translateX", 0) self.eyeGrp = cmds.group(self.eyeCtrl, name=self.userGuideName + "_A_Grp") utils.zeroOut([self.eyeCtrl]) self.upLocGrp = cmds.group(name=self.userGuideName + "_UpLoc_Grp", empty=True) # run for all sides: for s, side in enumerate(sideList): cmds.select(clear=True) self.base = side + self.userGuideName + '_Guide_Base' # declare guide: self.guide = side + self.userGuideName + "_Guide_JointLoc1" # create a joint: self.jxt = cmds.joint(name=side + self.userGuideName + "_1_Jxt", scaleCompensate=False) self.jnt = cmds.joint(name=side + self.userGuideName + "_1_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) self.fkEyeCtrl = cmds.circle(name=side + self.userGuideName + "_Fk_Ctrl", radius=self.ctrlRadius, normal=(0, 0, 1), degree=1, sections=6, constructionHistory=False)[0] utils.originedFrom(objName=self.fkEyeCtrl, attrString=self.base + ";" + self.guide) self.baseEyeCtrl = ctrls.cvBox( ctrlName=side + self.userGuideName + "_Base_Ctrl", r=self.ctrlRadius) utils.originedFrom(objName=self.baseEyeCtrl, attrString=self.base + ";" + self.guide) # position and orientation of joint and control: cmds.delete( cmds.parentConstraint(self.guide, self.jxt, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.guide, self.fkEyeCtrl, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.guide, self.baseEyeCtrl, maintainOffset=False)) cmds.makeIdentity(self.baseEyeCtrl, self.fkEyeCtrl, apply=True) # zeroOut controls: eyeZeroList = utils.zeroOut([self.baseEyeCtrl, self.fkEyeCtrl]) cmds.parent(eyeZeroList[1], self.baseEyeCtrl) # hide visibility attribute: cmds.setAttr(self.fkEyeCtrl + '.visibility', keyable=False) ctrls.setLockHide([self.fkEyeCtrl], ['tx', 'ty', 'tz']) # create end joint: self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" self.endJoint = cmds.joint(name=side + self.userGuideName + "_JEnd") cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) cmds.parent(self.endJoint, self.jnt, absolute=True) # create parentConstraint from ctrl to jxt: cmds.parentConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=False, name=self.jnt + "_ParentConstraint") # create scaleConstraint from ctrl to jnt: cmds.scaleConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=True, name=self.jnt + "_ScaleConstraint") # lookAt control: self.lookAtCtrl = cmds.circle(name=side + self.userGuideName + "_LookAt_Ctrl", radius=self.ctrlRadius, normal=(0, 0, 1), degree=3, constructionHistory=False)[0] cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.lookAtCtrl, maintainOffset=False)) cmds.parent(self.lookAtCtrl, self.eyeCtrl, relative=False) cmds.makeIdentity(self.lookAtCtrl, apply=True) cmds.addAttr(self.lookAtCtrl, longName="active", attributeType="bool", defaultValue=1, keyable=True) # up locator: self.lUpGrpLoc = cmds.group(name=side + self.userGuideName + "_Up_Loc_Grp", empty=True) cmds.delete( cmds.parentConstraint(self.jnt, self.lUpGrpLoc, maintainOffset=False)) self.lUpLoc = cmds.spaceLocator( name=side + self.userGuideName + "_Up_Loc")[0] cmds.delete( cmds.parentConstraint(self.jnt, self.lUpLoc, maintainOffset=False)) cmds.move(cmds.getAttr(self.guideName + "_JointEnd.translateZ"), self.lUpLoc, moveY=True, relative=True) cmds.parent(self.lUpLoc, self.lUpGrpLoc, relative=False) cmds.parent(self.lUpGrpLoc, self.upLocGrp, relative=False) # look at aim constraint: aimConst = cmds.aimConstraint(self.lookAtCtrl, self.fkEyeCtrl + "_Zero", worldUpType="object", worldUpObject=self.upLocGrp + "|" + self.lUpGrpLoc + "|" + self.lUpLoc, maintainOffset=True)[0] cmds.connectAttr(self.lookAtCtrl + ".active", aimConst + "." + self.lookAtCtrl + "W0", force=True) # eye aim rotation cmds.addAttr(self.fkEyeCtrl, longName="aimRotation", attributeType="float", keyable=True) cmds.connectAttr(self.fkEyeCtrl + ".aimRotation", self.jnt + ".rotateZ", force=True) cmds.pointConstraint(self.baseEyeCtrl, self.lUpGrpLoc, maintainOffset=True, name=self.lUpGrpLoc + "_PointConstraint") # create eyeScale setup: cmds.select(clear=True) self.eyeScaleJnt = cmds.joint(name=side + self.userGuideName + "Scale_1_Jnt", scaleCompensate=False) cmds.addAttr(self.eyeScaleJnt, longName='dpAR_joint', attributeType='float', keyable=False) # jointScale position: cmds.delete( cmds.parentConstraint(self.guide, self.eyeScaleJnt, maintainOffset=False)) # create endScale joint: self.endScaleJoint = cmds.joint( name=side + self.userGuideName + "Scale_JEnd") cmds.delete( cmds.parentConstraint(self.eyeScaleJnt, self.endScaleJoint, maintainOffset=False)) cmds.setAttr(self.endScaleJoint + ".translateZ", 1) # create constraints to eyeScale: cmds.pointConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=False, name=self.eyeScaleJnt + "_PointConstraint") cmds.scaleConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=True, name=self.eyeScaleJnt + "_ScaleConstraint") self.eyeScaleGrp = cmds.group(self.eyeScaleJnt, name=self.eyeScaleJnt + "_Grp") self.eyeScaleGrpList.append(self.eyeScaleGrp) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( eyeZeroList[0], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( self.jxt, self.eyeScaleGrp, name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") if s == 0: cmds.parent(self.eyeGrp, self.toCtrlHookGrp) cmds.parent(self.upLocGrp, self.toScalableHookGrp) # create a locator in order to avoid delete static group: loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side + self.userGuideName + '_Guide_Base' cmds.select(clear=True) # declare guide: self.guide = side + self.userGuideName + "_Guide_JointLoc1" # create a joint: self.jnt = cmds.joint(name=side + self.userGuideName + "_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(self.jnt, s + jointLabelAdd, 18, self.userGuideName) # create a control: if not self.getHasIndirectSkin(): if self.curveDegree == 0: self.curveDegree = 1 # work with curve shape and rotation cases: indirectSkinRot = (0, 0, 0) if self.langDic[ self.langName]['c058_main'] in self.userGuideName: ctrlTypeID = "id_054_SingleMain" if len(sideList) > 1: if self.langDic[self.langName][ 'c041_eyebrow'] in self.userGuideName: indirectSkinRot = (0, 0, -90) else: indirectSkinRot = (0, 0, 90) else: ctrlTypeID = "id_029_SingleIndSkin" if self.langDic[ self.langName]['c045_lower'] in self.userGuideName: indirectSkinRot = (0, 0, 180) elif self.langDic[self.langName][ 'c043_corner'] in self.userGuideName: if "00" in self.userGuideName: indirectSkinRot = (0, 0, 90) else: indirectSkinRot = (0, 0, -90) self.singleCtrl = self.ctrls.cvControl( ctrlTypeID, side + self.userGuideName + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree, rot=indirectSkinRot) utils.originedFrom(objName=self.singleCtrl, attrString=self.base + ";" + self.guide) # position and orientation of joint and control: cmds.delete( cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.guide, self.singleCtrl, maintainOffset=False)) # zeroOut controls: zeroOutCtrlGrp = utils.zeroOut([self.singleCtrl], offset=True)[0] # hide visibility attribute: cmds.setAttr(self.singleCtrl + '.visibility', keyable=False) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr(zeroOutCtrlGrp + ".scaleX", -1) cmds.setAttr(zeroOutCtrlGrp + ".scaleY", -1) cmds.setAttr(zeroOutCtrlGrp + ".scaleZ", -1) if not self.getHasIndirectSkin(): cmds.addAttr(self.singleCtrl, longName='scaleCompensate', attributeType="bool", keyable=False) cmds.setAttr(self.singleCtrl + ".scaleCompensate", 1, channelBox=True) cmds.connectAttr(self.singleCtrl + ".scaleCompensate", self.jnt + ".segmentScaleCompensate", force=True) if self.getHasIndirectSkin(): # create a fatherJoint in order to zeroOut the skinning joint: cmds.select(clear=True) jxtName = self.jnt.replace("_Jnt", "_Jxt") self.jxt = cmds.duplicate(self.jnt, name=jxtName)[0] cmds.deleteAttr(self.jxt, attribute="dpAR_joint") cmds.parent(self.jnt, self.jxt) cmds.makeIdentity(self.jnt, apply=True, jointOrient=False) attrList = [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz' ] for attr in attrList: cmds.connectAttr(self.singleCtrl + '.' + attr, self.jnt + '.' + attr) if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr(self.jxt + ".scaleX", -1) cmds.setAttr(self.jxt + ".scaleY", -1) cmds.setAttr(self.jxt + ".scaleZ", -1) if self.getHasHolder(): cmds.delete(self.singleCtrl + "Shape", shape=True) self.singleCtrl = cmds.rename( self.singleCtrl, self.singleCtrl + "_" + self.langDic[self.langName]['c046_holder'] + "_Grp") self.ctrls.setLockHide([self.singleCtrl], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz' ]) self.jnt = cmds.rename( self.jnt, self.jnt.replace( "_Jnt", "_" + self.langDic[self.langName]['c046_holder'] + "_Jis")) self.ctrls.setLockHide([self.jnt], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz' ], True, True) else: self.jnt = cmds.rename( self.jnt, self.jnt.replace("_Jnt", "_Jis")) else: # like a fkLine # create parentConstraint from ctrl to jnt: cmds.parentConstraint(self.singleCtrl, self.jnt, maintainOffset=False, name=self.jnt + "_ParentConstraint") # create scaleConstraint from ctrl to jnt: cmds.scaleConstraint(self.singleCtrl, self.jnt, maintainOffset=True, name=self.jnt + "_ScaleConstraint") # create end joint: cmds.select(self.jnt) self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" self.endJoint = cmds.joint(name=side + self.userGuideName + "_JEnd") cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) self.mainJisList.append(self.jnt) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( side + self.userGuideName + "_Ctrl_Zero_0_Grp", name=side + self.userGuideName + "_Control_Grp") if self.getHasIndirectSkin(): locScale = cmds.spaceLocator(name=side + self.userGuideName + "_Scalable_DO_NOT_DELETE")[0] cmds.setAttr(locScale + ".visibility", 0) self.toScalableHookGrp = cmds.group( locScale, name=side + self.userGuideName + "_IndirectSkin_Grp") jxtGrp = cmds.group(side + self.userGuideName + "_Jxt", name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group( jxtGrp, self.toScalableHookGrp, self.toCtrlHookGrp, name=side + self.userGuideName + "_Grp") else: self.toScalableHookGrp = cmds.group( side + self.userGuideName + "_Jnt", name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group( self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") # create a locator in order to avoid delete static or scalable group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) self.ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") self.aStaticGrpList.append(self.toStaticHookGrp) self.aCtrlGrpList.append(self.toCtrlHookGrp) # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # check mirror indirectSkin bug in Maya2018: if (int(cmds.about(version=True)[:4]) == 2018): if self.mirrorAxis != 'off': if self.getHasIndirectSkin(): meshList = cmds.ls(selection=False, type="mesh") if meshList: self.detectedBug = True # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declaring lists to send information for integration: self.scalableGrpList, self.ikCtrlZeroList = [], [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames)-1]+'_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.skinJointList = [] self.base = side+self.userGuideName+'_Guide_Base' # get the number of joints to be created: self.nJoints = cmds.getAttr(self.base+".nJoints") for n in range(0, self.nJoints+1): cmds.select(clear=True) # declare guide: self.guide = side+self.userGuideName+"_Guide_JointLoc"+str(n) # create a joint: self.jnt = cmds.joint(name=side+self.userGuideName+"_"+str(n)+"_Jnt", scaleCompensate=False) self.skinJointList.append(self.jnt) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) # create a control: if n == 1: self.ctrl = ctrls.cvFinger(ctrlName=side+self.userGuideName+"_"+str(n)+"_Ctrl", r=self.ctrlRadius) cmds.setAttr(self.ctrl + ".rotateOrder", 1) utils.originedFrom(objName=self.ctrl, attrString=self.base+";"+self.guide) # edit the mirror shape to a good direction of controls: if s == 1: if self.mirrorAxis == 'X': cmds.setAttr(self.ctrl+'.rotateZ', 180) elif self.mirrorAxis == 'Y': cmds.setAttr(self.ctrl+'.rotateY', 180) elif self.mirrorAxis == 'Z': cmds.setAttr(self.ctrl+'.rotateZ', 180) elif self.mirrorAxis == 'XY': cmds.setAttr(self.ctrl+'.rotateX', 180) elif self.mirrorAxis == 'XYZ': cmds.setAttr(self.ctrl+'.rotateZ', 180) cmds.makeIdentity(self.ctrl, apply=True, translate=False, rotate=True, scale=False) else: self.ctrl = cmds.circle(name=side+self.userGuideName+"_"+str(n)+"_Ctrl", degree=1, normal=(0, 0, 1), r=self.ctrlRadius, s=6, ch=False)[0] cmds.setAttr(self.ctrl + ".rotateOrder", 1) utils.originedFrom(objName=self.ctrl, attrString=self.guide) # scaleCompensate attribute: if n > 0 or self.nJoints == 2: cmds.addAttr(self.ctrl, longName="scaleCompensate", attributeType='bool', keyable=True) scaleCompensateCond = cmds.createNode("condition", name=side+self.userGuideName+"_"+str(n)+"_ScaleCompensate_Cnd") cmds.setAttr(scaleCompensateCond+".secondTerm", 1) cmds.connectAttr(self.ctrl+".scaleCompensate", scaleCompensateCond+".colorIfTrueR", force=True) cmds.connectAttr(scaleCompensateCond+".outColorR", self.jnt+".segmentScaleCompensate", force=True) # hide visibility attribute: cmds.setAttr(self.ctrl+'.visibility', keyable=False) # put another group over the control in order to use this to connect values from mainFingerCtrl: self.sdkGrp = cmds.group(self.ctrl, name=side+self.userGuideName+"_"+str(n)+"_SDKGrp") if n == 1: # change pivot of this group to control pivot: pivotPos = cmds.xform(self.ctrl, query=True, worldSpace=True, rotatePivot=True) cmds.setAttr(self.sdkGrp+'.rotatePivotX', pivotPos[0]) cmds.setAttr(self.sdkGrp+'.rotatePivotY', pivotPos[1]) cmds.setAttr(self.sdkGrp+'.rotatePivotZ', pivotPos[2]) # position and orientation of joint and control: tempDel = cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False) cmds.delete(tempDel) tempDel = cmds.parentConstraint(self.guide, self.sdkGrp, maintainOffset=False) cmds.delete(tempDel) # zeroOut controls: utils.zeroOut([self.sdkGrp]) # create end joint: self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" self.endJoint = cmds.joint(name=side+self.userGuideName+"_JEnd", scaleCompensate=False) tempDel = cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False) cmds.delete(tempDel) cmds.parent(self.endJoint, side+self.userGuideName+"_"+str(self.nJoints)+"_Jnt", absolute=True) # grouping: for n in range(0, self.nJoints+1): self.jnt = side+self.userGuideName+"_"+str(n)+"_Jnt" self.ctrl = side+self.userGuideName+"_"+str(n)+"_Ctrl" self.zeroCtrl = side+self.userGuideName+"_"+str(n)+"_SDKGrp_Zero" if n > 0: if n == 1: if not cmds.objExists(self.ctrl+'.ikFkBlend'): cmds.addAttr(self.ctrl, longName="ikFkBlend", attributeType='float', keyable=True, minValue=0.0, maxValue=1.0, defaultValue=1.0) self.ikFkRevNode = cmds.createNode("reverse", name=side+self.userGuideName+"_ikFk_Rev") cmds.connectAttr(self.ctrl+".ikFkBlend", self.ikFkRevNode+".inputX", force=True) if not cmds.objExists(self.ctrl+'.'+self.langDic[self.langName]['c_showControls']): cmds.addAttr(self.ctrl, longName=self.langDic[self.langName]['c_showControls'], attributeType='float', keyable=True, minValue=0.0, maxValue=1.0, defaultValue=0.0) self.ctrlShape0 = cmds.listRelatives(side+self.userGuideName+"_0_Ctrl", children=True, type='nurbsCurve')[0] cmds.connectAttr(self.ctrl+"."+self.langDic[self.langName]['c_showControls'], self.ctrlShape0+".visibility", force=True) cmds.setAttr(self.ctrl+'.'+self.langDic[self.langName]['c_showControls'], keyable=False, channelBox=True) for j in range(1, self.nJoints+1): cmds.addAttr(self.ctrl, longName=self.langDic[self.langName]['c_falange']+str(j), attributeType='float', keyable=True) # parent joints as a simple chain (line) self.fatherJnt = side+self.userGuideName+"_"+str(n-1)+"_Jnt" cmds.parent(self.jnt, self.fatherJnt, absolute=True) # parent zeroCtrl Group to the before ctrl: self.fatherCtrl = side+self.userGuideName+"_"+str(n-1)+"_Ctrl" cmds.parent(self.zeroCtrl, self.fatherCtrl, absolute=True) # freeze joints rotation cmds.makeIdentity(self.jnt, apply=True) # create parent and scale constraints from ctrl to jnt: cmds.delete(cmds.parentConstraint(self.ctrl, self.jnt, maintainOffset=False, name=self.jnt+"_ParentConstraint")) # make first falange be leads from base finger control: cmds.parentConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_1_SDKGrp_Zero", maintainOffset=True, name=side+self.userGuideName+"_1_SDKGrp_Zero"+"_ParentConstraint") cmds.scaleConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_1_SDKGrp_Zero", maintainOffset=True, name=side+self.userGuideName+"_1_SDKGrp_Zero"+"_ScaleConstraint") if self.nJoints != 2: cmds.parentConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_0_Jnt", maintainOffset=True, name=side+self.userGuideName+"_ParentConstraint") cmds.scaleConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_0_Jnt", maintainOffset=True, name=side+self.userGuideName+"_ScaleConstraint") # connecting the attributes from control 1 to falanges rotate: for n in range(1, self.nJoints+1): self.ctrl = side+self.userGuideName+"_1_Ctrl" self.sdkGrp = side+self.userGuideName+"_"+str(n)+"_SDKGrp" cmds.connectAttr(self.ctrl+"."+self.langDic[self.langName]['c_falange']+str(n), self.sdkGrp+".rotateY", force=True) if n > 1: self.ctrlShape = cmds.listRelatives(side+self.userGuideName+"_"+str(n)+"_Ctrl", children=True, type='nurbsCurve')[0] cmds.connectAttr(self.ctrl+"."+self.langDic[self.langName]['c_showControls'], self.ctrlShape+".visibility", force=True) # ik and Fk setup if self.nJoints == 2: dupIk = cmds.duplicate(self.skinJointList[0])[0] dupFk = cmds.duplicate(self.skinJointList[0])[0] else: dupIk = cmds.duplicate(self.skinJointList[1])[0] dupFk = cmds.duplicate(self.skinJointList[1])[0] # ik setup childrenIkList = cmds.listRelatives(dupIk, children=True, allDescendents=True, fullPath=True) if childrenIkList: for child in childrenIkList: if not cmds.objectType(child) == "joint": cmds.delete(child) jointIkList = cmds.listRelatives(dupIk, children=True, allDescendents=True, fullPath=True) for jointNode in jointIkList: if "_Jnt" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|")+1:].replace("_Jnt", "_Ik_Jxt")) elif "_JEnd" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|")+1:].replace("_JEnd", "_Ik_JEnd")) ikBaseJoint = cmds.rename(dupIk, dupIk.replace("_Jnt1", "_Ik_Jxt")) ikJointList = cmds.listRelatives(ikBaseJoint, children=True, allDescendents=True) ikJointList.append(ikBaseJoint) # Fk setup childrenFkList = cmds.listRelatives(dupFk, children=True, allDescendents=True, fullPath=True) if childrenFkList: for child in childrenFkList: if not cmds.objectType(child) == "joint": cmds.delete(child) jointFkList = cmds.listRelatives(dupFk, children=True, allDescendents=True, fullPath=True) for jointNode in jointFkList: if "_Jnt" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|")+1:].replace("_Jnt", "_Fk_Jxt")) elif "_JEnd" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|")+1:].replace("_JEnd", "_Fk_JEnd")) fkBaseJoint = cmds.rename(dupFk, dupFk.replace("_Jnt2", "_Fk_Jxt")) fkJointList = cmds.listRelatives(fkBaseJoint, children=True, allDescendents=True) fkJointList.append(fkBaseJoint) # ik fk blend connnections for i, ikJoint in enumerate(ikJointList): if not "_JEnd" in ikJoint: if cmds.objExists(ikJoint+".dpAR_joint"): cmds.deleteAttr(ikJoint+".dpAR_joint") fkJoint = ikJoint.replace("_Ik_Jxt", "_Fk_Jxt") skinJoint = ikJoint.replace("_Ik_Jxt", "_Jnt") self.ctrl = side+self.userGuideName+"_1_Ctrl" scaleCompensateCond = ikJoint.replace("_Ik_Jxt", "_ScaleCompensate_Cnd") ikFkParentConst = cmds.parentConstraint(ikJoint, fkJoint, skinJoint, maintainOffset=True, name=skinJoint+"_ParentConstraint")[0] ikFkScaleConst = cmds.scaleConstraint(ikJoint, fkJoint, skinJoint, maintainOffset=True, name=skinJoint+"_ScaleConstraint")[0] cmds.connectAttr(self.ctrl+".ikFkBlend", ikFkParentConst+"."+fkJoint+"W1", force=True) cmds.connectAttr(self.ikFkRevNode+".outputX", ikFkParentConst+"."+ikJoint+"W0", force=True) cmds.connectAttr(self.ctrl+".ikFkBlend", ikFkScaleConst+"."+fkJoint+"W1", force=True) cmds.connectAttr(self.ikFkRevNode+".outputX", ikFkScaleConst+"."+ikJoint+"W0", force=True) cmds.setAttr(ikJoint+".segmentScaleCompensate", 1) cmds.connectAttr(self.ctrl+".ikFkBlend", scaleCompensateCond+".firstTerm", force=True) # fk control drives fk joints for i, fkJoint in enumerate(fkJointList): if not "_JEnd" in fkJoint: if cmds.objExists(fkJoint+".dpAR_joint"): cmds.deleteAttr(fkJoint+".dpAR_joint") fkCtrl = fkJoint.replace("_Fk_Jxt", "_Ctrl") scaleCompensateCond = fkCtrl.replace("_Ctrl", "_ScaleCompensate_Cnd") cmds.parentConstraint(fkCtrl, fkJoint, maintainOffset=True, name=fkJoint+"_ParentConstraint") cmds.scaleConstraint(fkCtrl, fkJoint, maintainOffset=True, name=fkJoint+"_ScaleConstraint") cmds.connectAttr(fkCtrl+".scaleCompensate", fkJoint+".segmentScaleCompensate", force=True) cmds.setAttr(fkCtrl + ".rotateOrder", 1) # ik handle if self.nJoints >= 2: if self.nJoints == 2: ikHandleList = cmds.ikHandle(startJoint=side+self.userGuideName+"_0_Ik_Jxt", endEffector=side+self.userGuideName+"_"+str(self.nJoints)+"_Ik_Jxt", solver="ikRPsolver", name=side+self.userGuideName+"_IkHandle") else: ikHandleList = cmds.ikHandle(startJoint=side+self.userGuideName+"_1_Ik_Jxt", endEffector=side+self.userGuideName+"_"+str(self.nJoints)+"_Ik_Jxt", solver="ikRPsolver", name=side+self.userGuideName+"_IkHandle") cmds.rename(ikHandleList[1], side+self.userGuideName+"_Effector") endIkHandleList = cmds.ikHandle(startJoint=side+self.userGuideName+"_"+str(self.nJoints)+"_Ik_Jxt", endEffector=side+self.userGuideName+"_Ik_JEnd", solver="ikSCsolver", name=side+self.userGuideName+"_EndIkHandle") cmds.rename(endIkHandleList[1], side+self.userGuideName+"_EndEffector") self.ikCtrl = ctrls.cvBox(ctrlName=side+self.userGuideName+"_Ik_Ctrl", r=self.ctrlRadius) cmds.addAttr(self.ikCtrl, longName='twist', attributeType='float', keyable=True) cmds.connectAttr(self.ikCtrl+".twist", ikHandleList[0]+".twist", force=True) cmds.delete(cmds.parentConstraint(side+self.userGuideName+"_Ik_JEnd", self.ikCtrl)) cmds.setAttr(self.ikCtrl + ".rotateOrder", 1) self.ikCtrlZero = utils.zeroOut([self.ikCtrl])[0] self.ikCtrlZeroList.append(self.ikCtrlZero) cmds.connectAttr(self.ikFkRevNode+".outputX", self.ikCtrlZero+".visibility", force=True) for q in range(2, self.nJoints): cmds.connectAttr(side+self.userGuideName+"_1_Ctrl.ikFkBlend", side+self.userGuideName+"_"+str(q)+"_Ctrl.visibility", force=True) cmds.parentConstraint(self.ikCtrl, ikHandleList[0], name=side+self.userGuideName+"_IkHandle_ParentConstraint", maintainOffset=True) cmds.parentConstraint(self.ikCtrl, endIkHandleList[0], name=side+self.userGuideName+"_EndIkHandle_ParentConstraint", maintainOffset=True) ikHandleGrp = cmds.group(ikHandleList[0], endIkHandleList[0], name=side+self.userGuideName+"_IkHandle_Grp") ctrls.setLockHide([self.ikCtrl], ['sx', 'sy', 'sz', 'v']) if self.nJoints == 2: cmds.parentConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_0_Ik_Jxt", maintainOffset=True, name=side+self.userGuideName+"_0_Ik_Jxt_ParentConstraint") cmds.scaleConstraint(side+self.userGuideName+"_0_Ctrl", side+self.userGuideName+"_0_Ik_Jxt", maintainOffset=True, name=side+self.userGuideName+"_0_Ik_Jxt_ScaleConstraint") # stretch cmds.addAttr(self.ikCtrl, longName='stretchable', attributeType='float', minValue=0, maxValue=1, defaultValue=0, keyable=True) stretchNormMD = cmds.createNode("multiplyDivide", name=side+self.userGuideName+"_StretchNormalize_MD") cmds.setAttr(stretchNormMD+".operation", 2) distBetweenList = ctrls.distanceBet(side+self.userGuideName+"_0_Ctrl", self.ikCtrl, name=side+self.userGuideName+"_DistBet", keep=True) cmds.connectAttr(self.ikFkRevNode+".outputX", distBetweenList[5]+"."+self.ikCtrl+"W0", force=True) cmds.connectAttr(self.ctrl+".ikFkBlend", distBetweenList[5]+"."+distBetweenList[4]+"W1", force=True) cmds.connectAttr(distBetweenList[1]+".distance", stretchNormMD+".input1X", force=True) cmds.setAttr(stretchNormMD+".input2X", distBetweenList[0]) stretchScaleMD = cmds.createNode("multiplyDivide", name=side+self.userGuideName+"_StretchScale_MD") cmds.connectAttr(stretchNormMD+".outputX", stretchScaleMD+".input1X", force=True) cmds.connectAttr(self.ikCtrl+".stretchable", stretchScaleMD+".input2X", force=True) stretchCond = cmds.createNode("condition", name=side+self.userGuideName+"_Stretch_Cnd") cmds.connectAttr(stretchScaleMD+".outputX", stretchCond+".firstTerm", force=True) cmds.setAttr(stretchCond+".secondTerm", 1) cmds.setAttr(stretchCond+".operation", 2) cmds.connectAttr(stretchScaleMD+".outputX", stretchCond+".colorIfTrueR", force=True) for i, ikJoint in enumerate(ikJointList): if not "_JEnd" in ikJoint: if self.nJoints == 2 and i == 0: pass else: cmds.connectAttr(stretchCond+".outColorR", ikJoint+".scaleZ", force=True) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(self.ikCtrlZero, side+self.userGuideName+"_0_SDKGrp_Zero", side+self.userGuideName+"_1_SDKGrp_Zero", name=side+self.userGuideName+"_Control_Grp") if self.nJoints == 2: self.toScalableHookGrp = cmds.group(side+self.userGuideName+"_0_Jnt", ikBaseJoint, fkBaseJoint, ikHandleGrp, distBetweenList[2], distBetweenList[3], distBetweenList[4], name=side+self.userGuideName+"_Joint_Grp") else: self.toScalableHookGrp = cmds.group(side+self.userGuideName+"_0_Jnt", ikHandleGrp, distBetweenList[2], distBetweenList[3], distBetweenList[4], name=side+self.userGuideName+"_Joint_Grp") else: self.toCtrlHookGrp = cmds.group(side+self.userGuideName+"_0_SDKGrp_Zero", side+self.userGuideName+"_1_SDKGrp_Zero", name=side+self.userGuideName+"_Control_Grp") self.toScalableHookGrp = cmds.group(side+self.userGuideName+"_0_Jnt", name=side+self.userGuideName+"_Joint_Grp") self.scalableGrpList.append(self.toScalableHookGrp) self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side+self.userGuideName+"_Grp") # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc+".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declare lists to store names and attributes: self.worldRefList, self.headCtrlList = [], [] self.aCtrls = [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames)-1]+'_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # redeclaring variables: self.base = side+self.userGuideName+"_Guide_Base" self.cvNeckLoc = side+self.userGuideName+"_Guide_neck" self.cvHeadLoc = side+self.userGuideName+"_Guide_head" self.cvJawLoc = side+self.userGuideName+"_Guide_jaw" self.cvChinLoc = side+self.userGuideName+"_Guide_chin" self.cvLLipLoc = side+self.userGuideName+"_Guide_lLip" self.cvRLipLoc = side+self.userGuideName+"_Guide_rLip" self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" # creating joints: self.neckJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c_neck']+"_Jnt") self.headJxt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c_head']+"_Jxt") cmds.select(clear=True) self.headJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c_head']+"_Jnt", scaleCompensate=False) self.jawJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c_jaw']+"_Jnt", scaleCompensate=False) self.chinJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c_chin']+"_Jnt", scaleCompensate=False) self.endJnt = cmds.joint(name=side+self.userGuideName+"_JEnd", scaleCompensate=False) cmds.select(clear=True) self.lLipJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['p002_left']+"_"+self.langDic[self.langName]['c_lip']+"_Jnt", scaleCompensate=False) cmds.select(clear=True) self.rLipJnt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['p003_right']+"_"+self.langDic[self.langName]['c_lip']+"_Jnt", scaleCompensate=False) dpARJointList = [self.neckJnt, self.headJnt, self.jawJnt, self.chinJnt, self.lLipJnt, self.rLipJnt] for dpARJoint in dpARJointList: cmds.addAttr(dpARJoint, longName='dpAR_joint', attributeType='float', keyable=False) # creating controls: self.neckCtrl = ctrls.cvNeck(ctrlName=side+self.userGuideName+"_"+self.langDic[self.langName]['c_neck']+"_Ctrl", r=self.ctrlRadius/2.0) self.headCtrl = ctrls.cvHead(ctrlName=side+self.userGuideName+"_"+self.langDic[self.langName]['c_head']+"_Ctrl", r=self.ctrlRadius/2.0) self.jawCtrl = ctrls.cvJaw( ctrlName=side+self.userGuideName+"_"+self.langDic[self.langName]['c_jaw']+"_Ctrl", r=self.ctrlRadius/2.0) self.chinCtrl = ctrls.cvChin(ctrlName=side+self.userGuideName+"_"+self.langDic[self.langName]['c_chin']+"_Ctrl", r=self.ctrlRadius/2.0) self.lLipCtrl = cmds.circle(name=side+self.userGuideName+"_"+self.langDic[self.langName]['p002_left']+"_"+self.langDic[self.langName]['c_lip']+"_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=(self.ctrlRadius * 0.25))[0] self.rLipCtrl = cmds.circle(name=side+self.userGuideName+"_"+self.langDic[self.langName]['p003_right']+"_"+self.langDic[self.langName]['c_lip']+"_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=(self.ctrlRadius * 0.25))[0] self.headCtrlList.append(self.headCtrl) self.aCtrls.append([self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl, self.lLipCtrl, self.rLipCtrl]) #Setup Axis Order if self.rigType == Base.RigType.quadruped: cmds.setAttr(self.neckCtrl + ".rotateOrder", 1) cmds.setAttr(self.headCtrl + ".rotateOrder", 1) cmds.setAttr(self.jawCtrl + ".rotateOrder", 1) else: cmds.setAttr(self.neckCtrl + ".rotateOrder", 4) cmds.setAttr(self.headCtrl + ".rotateOrder", 4) cmds.setAttr(self.jawCtrl + ".rotateOrder", 4) # creating the originedFrom attributes (in order to permit integrated parents in the future): utils.originedFrom(objName=self.neckCtrl, attrString=self.base+";"+self.cvNeckLoc) utils.originedFrom(objName=self.headCtrl, attrString=self.cvHeadLoc) utils.originedFrom(objName=self.jawCtrl, attrString=self.cvJawLoc) utils.originedFrom(objName=self.chinCtrl, attrString=self.cvChinLoc+";"+self.cvEndJoint) # orientation of controls: ctrls.setAndFreeze(nodeName=self.neckCtrl, rx=90, rz=-90) ctrls.setAndFreeze(nodeName=self.headCtrl, rx=90, rz=-90) ctrls.setAndFreeze(nodeName=self.jawCtrl, rz=-90) ctrls.setAndFreeze(nodeName=self.chinCtrl, rz=-90) # edit the mirror shape to a good direction of controls: ctrlList = [ self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl ] if s == 1: for ctrl in ctrlList: if self.mirrorAxis == 'X': cmds.setAttr(ctrl+'.rotateY', 180) elif self.mirrorAxis == 'Y': cmds.setAttr(ctrl+'.rotateY', 180) elif self.mirrorAxis == 'Z': cmds.setAttr(ctrl+'.rotateX', 180) cmds.setAttr(ctrl+'.rotateZ', 180) elif self.mirrorAxis == 'XYZ': cmds.setAttr(ctrl+'.rotateX', 180) cmds.setAttr(ctrl+'.rotateZ', 180) cmds.makeIdentity(ctrlList, apply=True, translate=False, rotate=True, scale=False) # temporary parentConstraints: tempDelNeck = cmds.parentConstraint(self.cvNeckLoc, self.neckCtrl, maintainOffset=False) tempDelHead = cmds.parentConstraint(self.cvHeadLoc, self.headCtrl, maintainOffset=False) tempDelJaw = cmds.parentConstraint(self.cvJawLoc, self.jawCtrl, maintainOffset=False) tempDelChin = cmds.parentConstraint(self.cvChinLoc, self.chinCtrl, maintainOffset=False) tempDelLLip = cmds.parentConstraint(self.cvLLipLoc, self.lLipCtrl, maintainOffset=False) tempDelRLip = cmds.parentConstraint(self.cvRLipLoc, self.rLipCtrl, maintainOffset=False) cmds.delete(tempDelNeck, tempDelHead, tempDelJaw, tempDelChin, tempDelLLip, tempDelRLip) # zeroOut controls: self.zeroLipCtrlList = utils.zeroOut([self.lLipCtrl, self.rLipCtrl]) self.lLipGrp = cmds.group(self.lLipCtrl, name=self.lLipCtrl+"_Grp") self.rLipGrp = cmds.group(self.rLipCtrl, name=self.rLipCtrl+"_Grp") self.zeroCtrlList = utils.zeroOut([self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl, self.zeroLipCtrlList[0], self.zeroLipCtrlList[1]]) # make joints be ride by controls: cmds.makeIdentity(self.neckJnt, self.headJxt, self.headJnt, self.jawJnt, self.chinJnt, self.endJnt, rotate=True, apply=True) cmds.parentConstraint(self.neckCtrl, self.neckJnt, maintainOffset=False, name=self.neckJnt+"_ParentConstraint") cmds.scaleConstraint(self.neckCtrl, self.neckJnt, maintainOffset=False, name=self.neckJnt+"_ScaleConstraint") cmds.delete(cmds.parentConstraint(self.headCtrl, self.headJxt, maintainOffset=False)) cmds.parentConstraint(self.headCtrl, self.headJnt, maintainOffset=False, name=self.headJnt+"_ParentConstraint") cmds.parentConstraint(self.jawCtrl, self.jawJnt, maintainOffset=False, name=self.jawJnt+"_ParentConstraint") cmds.parentConstraint(self.chinCtrl, self.chinJnt, maintainOffset=False, name=self.chinJnt+"_ParentConstraint") cmds.parentConstraint(self.lLipCtrl, self.lLipJnt, maintainOffset=False, name=self.lLipJnt+"_ParentConstraint") cmds.parentConstraint(self.rLipCtrl, self.rLipJnt, maintainOffset=False, name=self.rLipJnt+"_ParentConstraint") cmds.scaleConstraint(self.headCtrl, self.headJnt, maintainOffset=False, name=self.headJnt+"_ScaleConstraint") cmds.scaleConstraint(self.jawCtrl, self.jawJnt, maintainOffset=False, name=self.jawJnt+"_ScaleConstraint") cmds.scaleConstraint(self.chinCtrl, self.chinJnt, maintainOffset=False, name=self.chinJnt+"_ScaleConstraint") cmds.scaleConstraint(self.lLipCtrl, self.lLipJnt, maintainOffset=False, name=self.lLipJnt+"_ScaleConstraint") cmds.scaleConstraint(self.rLipCtrl, self.rLipJnt, maintainOffset=False, name=self.rLipJnt+"_ScaleConstraint") cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.endJnt, maintainOffset=False)) cmds.setAttr(self.jawJnt+".segmentScaleCompensate", 0) # create interations between neck and head: self.grpNeck = cmds.group(self.zeroCtrlList[0], name=self.neckCtrl+"_Grp") self.grpHeadA = cmds.group(empty=True, name=self.headCtrl+"_A_Grp") self.grpHead = cmds.group(self.grpHeadA, name=self.headCtrl+"_Grp") # arrange pivots: self.neckPivot = cmds.xform(self.neckCtrl, query=True, worldSpace=True, translation=True) self.headPivot = cmds.xform(self.headCtrl, query=True, worldSpace=True, translation=True) cmds.xform(self.grpNeck, pivots=(self.neckPivot[0], self.neckPivot[1], self.neckPivot[2])) cmds.xform(self.grpHead, self.grpHeadA, pivots=(self.headPivot[0], self.headPivot[1], self.headPivot[2])) self.worldRef = cmds.group(empty=True, name=side+self.userGuideName+"_WorldRef") self.worldRefList.append(self.worldRef) cmds.delete(cmds.parentConstraint(self.neckCtrl, self.worldRef, maintainOffset=False)) cmds.parentConstraint(self.neckCtrl, self.grpHeadA, maintainOffset=True, skipRotate=["x", "y", "z"], name=self.grpHeadA+"_ParentConstraint") orientConst = cmds.orientConstraint(self.neckCtrl, self.worldRef, self.grpHeadA, maintainOffset=False, name=self.grpHeadA+"_OrientConstraint")[0] cmds.scaleConstraint(self.neckCtrl, self.grpHeadA, maintainOffset=True, name=self.grpHeadA+"_ScaleConstraint") cmds.parent(self.zeroCtrlList[1], self.grpHeadA, absolute=True) # connect reverseNode: cmds.addAttr(self.headCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, keyable=True) cmds.connectAttr(self.headCtrl+'.'+self.langDic[self.langName]['c_Follow'], orientConst+"."+self.neckCtrl+"W0", force=True) self.headRevNode = cmds.createNode('reverse', name=side+self.userGuideName+"_Rev") cmds.connectAttr(self.headCtrl+'.'+self.langDic[self.langName]['c_Follow'], self.headRevNode+".inputX", force=True) cmds.connectAttr(self.headRevNode+'.outputX', orientConst+"."+self.worldRef+"W1", force=True) # mount controls hierarchy: cmds.parent(self.zeroCtrlList[3], self.jawCtrl, absolute=True) # jaw follow head or root ctrl (using worldRef) jawParentConst = cmds.parentConstraint(self.headCtrl, self.worldRef, self.zeroCtrlList[2], maintainOffset=True, name=self.zeroCtrlList[2]+"_ParentConstraint")[0] cmds.setAttr(jawParentConst+".interpType", 2) #Shortest, no flip cause problem with scrubing cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType="float", minValue=0, maxValue=1, defaultValue=1, keyable=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_Follow'], jawParentConst+"."+self.headCtrl+"W0", force=True) jawFollowRev = cmds.createNode("reverse", name=self.jawCtrl+"_Rev") cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_Follow'], jawFollowRev+".inputX", force=True) cmds.connectAttr(jawFollowRev+".outputX", jawParentConst+"."+self.worldRef+"W1", force=True) cmds.scaleConstraint(self.headCtrl, self.zeroCtrlList[2], maintainOffset=True, name=self.zeroCtrlList[2]+"_ScaleConstraint")[0] # setup jaw auto translation self.jawSdkGrp = cmds.group(self.jawCtrl, name=self.jawCtrl+"_SDK_Grp") cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName]['c_moveIntensity']+"Y", attributeType='float', keyable=True) cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName]['c_moveIntensity']+"Z", attributeType='float', keyable=True) cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName]['c_moveStartRotation'], attributeType='float', keyable=True) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Y", keyable=False, channelBox=True) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Z", keyable=False, channelBox=True) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveStartRotation'], keyable=False, channelBox=True) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Y", 0.01) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Z", 0.02) cmds.setAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveStartRotation'], -10) self.jawIntensityMD = cmds.createNode('multiplyDivide', name="JawMoveIntensity_MD") self.jawIntensityZMD = cmds.createNode('multiplyDivide', name="JawMoveIntensityZ_MD") self.jawIntensityZInvMD = cmds.createNode('multiplyDivide', name="JawMoveIntensityZInv_MD") self.jawStartIntensityMD = cmds.createNode('multiplyDivide', name="JawMoveIntensityStart_MD") self.jawIntensityPMA = cmds.createNode('plusMinusAverage', name="JawMoveIntensity_PMA") self.jawIntensityCnd = cmds.createNode('condition', name="JawMoveIntensity_Cnd") cmds.connectAttr(self.jawCtrl+".rotateY", self.jawIntensityMD+".input1Y", force=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Y", self.jawIntensityMD+".input2Y", force=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Y", self.jawStartIntensityMD+".input1X", force=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveStartRotation'], self.jawStartIntensityMD+".input2X", force=True) cmds.setAttr(self.jawIntensityPMA+".operation", 2) cmds.connectAttr(self.jawIntensityMD+".outputY", self.jawIntensityPMA+".input1D[0]", force=True) cmds.connectAttr(self.jawStartIntensityMD+".outputX", self.jawIntensityPMA+".input1D[1]", force=True) cmds.connectAttr(self.jawIntensityPMA+".output1D", self.jawIntensityCnd+".colorIfTrueG", force=True) cmds.connectAttr(self.jawCtrl+".rotateY", self.jawIntensityCnd+".firstTerm", force=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveStartRotation'], self.jawIntensityCnd+".secondTerm", force=True) cmds.setAttr(self.jawIntensityCnd+".operation", 4) cmds.setAttr(self.jawIntensityCnd+".colorIfFalseG", 0) cmds.connectAttr(self.jawIntensityCnd+".outColorG", self.jawSdkGrp+".translateX", force=True) cmds.connectAttr(self.jawIntensityCnd+".outColorG", self.jawIntensityZMD+".input1Z", force=True) cmds.connectAttr(self.jawCtrl+"."+self.langDic[self.langName]['c_moveIntensity']+"Z", self.jawIntensityZMD+".input2Z", force=True) cmds.connectAttr(self.jawIntensityZMD+".outputZ", self.jawIntensityZInvMD+".input1Z", force=True) cmds.setAttr(self.jawIntensityZInvMD+".input2Z", -1) cmds.connectAttr(self.jawIntensityZInvMD+".outputZ", self.jawSdkGrp+".translateZ", force=True) # create lip setup: # left side lip: lLipParentConst = cmds.parentConstraint(self.jawCtrl, self.headCtrl, self.lLipGrp, maintainOffset=True, name=self.lLipGrp+"_ParentConstraint")[0] cmds.setAttr(lLipParentConst+".interpType", 2) cmds.addAttr(self.lLipCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, defaultValue=0.5, keyable=True) cmds.connectAttr(self.lLipCtrl+'.'+self.langDic[self.langName]['c_Follow'], lLipParentConst+"."+self.jawCtrl+"W0", force=True) self.lLipRevNode = cmds.createNode('reverse', name=side+self.userGuideName+"_"+self.langDic[self.langName]['p002_left']+"_"+self.langDic[self.langName]['c_lip']+"_Rev") cmds.connectAttr(self.lLipCtrl+'.'+self.langDic[self.langName]['c_Follow'], self.lLipRevNode+".inputX", force=True) cmds.connectAttr(self.lLipRevNode+'.outputX', lLipParentConst+"."+self.headCtrl+"W1", force=True) cmds.scaleConstraint(self.headCtrl, self.lLipGrp, maintainOffset=True, name=self.lLipGrp+"_ScaleConstraint")[0] # right side lip: rLipParentConst = cmds.parentConstraint(self.jawCtrl, self.headCtrl, self.rLipGrp, maintainOffset=True, name=self.rLipGrp+"_ParentConstraint")[0] cmds.setAttr(rLipParentConst+".interpType", 2) cmds.addAttr(self.rLipCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, defaultValue=0.5, keyable=True) cmds.connectAttr(self.rLipCtrl+'.'+self.langDic[self.langName]['c_Follow'], rLipParentConst+"."+self.jawCtrl+"W0", force=True) self.rLipRevNode = cmds.createNode('reverse', name=side+self.userGuideName+"_"+self.langDic[self.langName]['p003_right']+"_"+self.langDic[self.langName]['c_lip']+"_Rev") cmds.connectAttr(self.rLipCtrl+'.'+self.langDic[self.langName]['c_Follow'], self.rLipRevNode+".inputX", force=True) cmds.connectAttr(self.rLipRevNode+'.outputX', rLipParentConst+"."+self.headCtrl+"W1", force=True) cmds.scaleConstraint(self.headCtrl, self.rLipGrp, maintainOffset=True, name=self.rLipGrp+"_ScaleConstraint")[0] # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.worldRef, absolute=True) cmds.setAttr(loc+".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # hiding visibility attributes: ctrls.setLockHide([self.headCtrl, self.neckCtrl, self.jawCtrl, self.chinCtrl], ['v'], l=False) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(self.grpNeck, self.grpHead, self.zeroCtrlList[2], self.zeroCtrlList[4], self.zeroCtrlList[5], name=side+self.userGuideName+"_Control_Grp") self.toScalableHookGrp = cmds.group(self.neckJnt, self.headJnt, self.lLipJnt, self.rLipJnt, name=side+self.userGuideName+"_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, self.grpHead, self.worldRef, name=side+self.userGuideName+"_Grp") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.grpHead, hookType='rootHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 self.currentStyle = cmds.getAttr(self.moduleGrp + ".style") # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_'] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side + self.userGuideName + '_Guide_Base' # get the number of joints to be created: self.nJoints = cmds.getAttr(self.base + ".nJoints") # create controls: self.hipsA = ctrls.cvBox(ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_hips'] + "A_Ctrl", r=self.ctrlRadius, h=(self.ctrlRadius * 0.25)) self.hipsB = cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_hips'] + "B_Ctrl", ch=False, o=True, nr=(0, 1, 0), d=1, s=8, radius=self.ctrlRadius)[0] self.chestA = ctrls.cvBox(ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chest'] + "A_Ctrl", r=self.ctrlRadius, h=(self.ctrlRadius * 0.25)) self.chestB = cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chest'] + "B_Ctrl", ch=False, o=True, nr=(0, 1, 0), d=1, s=8, radius=self.ctrlRadius)[0] cmds.addAttr(self.hipsA, longName=side + self.userGuideName + '_' + self.langDic[self.langName]['c_volumeVariation'], attributeType="float", defaultValue=1, keyable=True) cmds.addAttr(self.hipsA, longName=side + self.userGuideName + '_active_' + self.langDic[self.langName]['c_volumeVariation'], attributeType="float", defaultValue=1, keyable=True) cmds.addAttr(self.hipsA, longName=side + self.userGuideName + '_masterScale_' + self.langDic[self.langName]['c_volumeVariation'], attributeType="float", defaultValue=1, keyable=True) ctrls.setLockHide([self.hipsA, self.hipsB, self.chestA, self.chestB], ['v'], l=False) self.aHipsAList.append(self.hipsA) self.aChestAList.append(self.chestA) self.aVolVariationAttrList.append(side + self.userGuideName + '_' + self.langDic[self.langName]['c_volumeVariation']) self.aActVolVariationAttrList.append(side + self.userGuideName + '_active_' + self.langDic[self.langName]['c_volumeVariation']) self.aMScaleVolVariationAttrList.append(side + self.userGuideName + '_masterScale_' + self.langDic[self.langName]['c_volumeVariation']) # Setup axis order if self.rigType == Base.RigType.quadruped: cmds.setAttr(self.hipsA + ".rotateOrder", 1) cmds.setAttr(self.hipsB + ".rotateOrder", 1) cmds.setAttr(self.chestA + ".rotateOrder", 1) cmds.setAttr(self.chestB + ".rotateOrder", 1) cmds.rotate(90, 0, 0, self.hipsA, self.hipsB, self.chestA, self.chestB) cmds.makeIdentity(self.hipsA, self.hipsB, self.chestA, self.chestB, apply=True, rotate=True) else: cmds.setAttr(self.hipsA + ".rotateOrder", 3) cmds.setAttr(self.hipsB + ".rotateOrder", 3) cmds.setAttr(self.chestA + ".rotateOrder", 3) cmds.setAttr(self.chestB + ".rotateOrder", 3) # Keep a list of ctrls we want to colorize a certain way self.aFkCtrl.append([self.hipsB, self.chestB]) self.aIkCtrl.append([self.hipsA, self.chestA]) # organize hierarchy: cmds.parent(self.hipsB, self.hipsA) cmds.parent(self.chestB, self.chestA) if self.currentStyle == 0: #default cmds.rotate(-90, 0, 0, self.hipsA, self.chestA) cmds.makeIdentity(self.hipsA, self.chestA, apply=True, rotate=True) # position of controls: bottomLocGuide = side + self.userGuideName + "_Guide_JointLoc1" topLocGuide = side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints) # snap controls to guideLocators: cmds.delete(cmds.parentConstraint(bottomLocGuide, self.hipsA, maintainOffset=False)) cmds.delete(cmds.parentConstraint(topLocGuide, self.chestA, maintainOffset=False)) # change axis orientation for biped stype if self.currentStyle == 1: #biped cmds.rotate(0, 0, 0, self.hipsA, self.chestA) cmds.makeIdentity(self.hipsA, self.chestA, apply=True, rotate=True) cmds.parent(self.chestA, self.hipsA) # zeroOut transformations: utils.zeroOut([self.hipsA, self.chestA]) # modify the pivots of chest controls: upPivotPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints - 1), query=True, worldSpace=True, translation=True) cmds.move(upPivotPos[0], upPivotPos[1], upPivotPos[2], self.chestA + ".scalePivot", self.chestA + ".rotatePivot") # , self.chestB+".scalePivot", self.chestB+".rotatePivot") # add originedFrom attributes to hipsA, hipsB and chestB: utils.originedFrom(objName=self.hipsA, attrString=self.base) utils.originedFrom(objName=self.hipsB, attrString=bottomLocGuide) utils.originedFrom(objName=self.chestB, attrString=topLocGuide) # create a simple spine ribbon: returnedRibbonList = ctrls.createSimpleRibbon(name=side + self.userGuideName,totalJoints=(self.nJoints - 1)) rbnNurbsPlane = returnedRibbonList[0] rbnNurbsPlaneShape = returnedRibbonList[1] rbnJointGrpList = returnedRibbonList[2] self.aRbnJointList = returnedRibbonList[3] # position of ribbon nurbs plane: cmds.setAttr(rbnNurbsPlane + ".tz", -4) cmds.move(0, 0, 0, rbnNurbsPlane + ".scalePivot", rbnNurbsPlane + ".rotatePivot") cmds.rotate(90, 90, 0, rbnNurbsPlane) cmds.makeIdentity(rbnNurbsPlane, apply=True, translate=True, rotate=True) downLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc1", query=True, worldSpace=True, translation=True) upLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints), query=True, worldSpace=True, translation=True) cmds.move(downLocPos[0], downLocPos[1], downLocPos[2], rbnNurbsPlane) # create up and down clusters: downCluster = cmds.cluster(rbnNurbsPlane + ".cv[0:3][0:1]", name=side + self.userGuideName + '_Down_Cls')[1] upCluster = cmds.cluster(rbnNurbsPlane + ".cv[0:3][" + str(self.nJoints) + ":" + str(self.nJoints + 1) + "]", name=side + self.userGuideName + '_Up_Cls')[1] # get positions of joints from ribbon nurbs plane: startRbnJointPos = cmds.xform(side + self.userGuideName + "_00_Jnt", query=True, worldSpace=True, translation=True) endRbnJointPos = cmds.xform(side + self.userGuideName + "_%02d_Jnt"%(self.nJoints - 1), query=True, worldSpace=True, translation=True) # move pivots of clusters to start and end positions: cmds.move(startRbnJointPos[0], startRbnJointPos[1], startRbnJointPos[2], downCluster + ".scalePivot", downCluster + ".rotatePivot") cmds.move(endRbnJointPos[0], endRbnJointPos[1], endRbnJointPos[2], upCluster + ".scalePivot", upCluster + ".rotatePivot") # snap clusters to guideLocators: tempDel = cmds.parentConstraint(bottomLocGuide, downCluster, maintainOffset=False) cmds.delete(tempDel) tempDel = cmds.parentConstraint(topLocGuide, upCluster, maintainOffset=False) cmds.delete(tempDel) # rotate clusters to compensate guide: upClusterRot = cmds.xform(upCluster, query=True, worldSpace=True, rotation=True) downClusterRot = cmds.xform(downCluster, query=True, worldSpace=True, rotation=True) cmds.xform(upCluster, worldSpace=True, rotation=(upClusterRot[0] + 90, upClusterRot[1], upClusterRot[2])) cmds.xform(downCluster, worldSpace=True, rotation=(downClusterRot[0] + 90, downClusterRot[1], downClusterRot[2])) # scaleY of the clusters in order to avoid great extremity deforms: rbnHeight = ctrls.distanceBet(side + self.userGuideName + "_Guide_JointLoc" + str(self.nJoints), side + self.userGuideName + "_Guide_JointLoc1", keep=False)[0] cmds.setAttr(upCluster + ".sy", rbnHeight / 10) cmds.setAttr(downCluster + ".sy", rbnHeight / 10) # parent clusters in controls (up and down): cmds.parentConstraint(self.hipsB, downCluster, maintainOffset=True, name=downCluster + "_ParentConstraint") cmds.parentConstraint(self.chestB, upCluster, maintainOffset=True, name=upCluster + "_ParentConstraint") # organize a group of clusters: clustersGrp = cmds.group(name=side + self.userGuideName + "_Rbn_Clusters_Grp", empty=True) self.aClusterGrp.append(clustersGrp) if hideJoints: cmds.setAttr(clustersGrp + ".visibility", 0) cmds.parent(downCluster, upCluster, clustersGrp, relative=True) # make ribbon joints groups scalable: for r, rbnJntGrp in enumerate(rbnJointGrpList): if ((r > 0) and (r < (len(rbnJointGrpList) - 1))): scaleGrp = cmds.group(rbnJntGrp, name=rbnJntGrp.replace("_Grp", "_Scale_Grp")) ctrls.directConnect(scaleGrp, rbnJntGrp, ['sx', 'sz']) cmds.scaleConstraint(clustersGrp, scaleGrp, maintainOffset=True, name=rbnJntGrp + "_Scale") else: cmds.scaleConstraint(clustersGrp, rbnJntGrp, maintainOffset=True, name=rbnJntGrp + "_Scale") # calculate the distance to volumeVariation: arcLenShape = cmds.createNode('arcLengthDimension', name=side + self.userGuideName + "_Rbn_ArcLenShape") arcLenFather = cmds.listRelatives(arcLenShape, parent=True)[0] arcLen = cmds.rename(arcLenFather, side + self.userGuideName + "_Rbn_ArcLen") arcLenShape = cmds.listRelatives(arcLen, children=True, shapes=True)[0] cmds.setAttr(arcLen + '.visibility', 0) # connect nurbsPlaneShape to arcLength node: cmds.connectAttr(rbnNurbsPlaneShape + '.worldSpace[0]', arcLenShape + '.nurbsGeometry') cmds.setAttr(arcLenShape + '.vParamValue', 1) # avoid undesired squash if rotateZ the nurbsPlane: cmds.setAttr(arcLenShape + '.uParamValue', 0.5) arcLenValue = cmds.getAttr(arcLenShape + '.arcLengthInV') # create a multiplyDivide to output the squashStretch values: rbnMD = cmds.createNode('multiplyDivide', name=side + self.userGuideName + "_Rbn_MD") cmds.connectAttr(arcLenShape + '.arcLengthInV', rbnMD + '.input2X') cmds.setAttr(rbnMD + '.input1X', arcLenValue) cmds.setAttr(rbnMD + '.operation', 2) # create a blendColor, a condition and a multiplyDivide in order to get the correct result value of volumeVariation: rbnBlendColors = cmds.createNode('blendColors', name=side + self.userGuideName + "_Rbn_BlendColor") cmds.connectAttr(self.hipsA + '.' + side + self.userGuideName + '_' + self.langDic[self.langName]['c_volumeVariation'], rbnBlendColors + '.blender') rbnCond = cmds.createNode('condition', name=side+self.userGuideName+'_Rbn_Cond') cmds.connectAttr(self.hipsA + '.' + side + self.userGuideName + '_active_' + self.langDic[self.langName]['c_volumeVariation'], rbnCond + '.firstTerm') cmds.connectAttr(rbnBlendColors+'.outputR', rbnCond + '.colorIfTrueR') cmds.connectAttr(rbnMD + '.outputX', rbnBlendColors + '.color1R') rbnVVMD = cmds.createNode('multiplyDivide', name=side + self.userGuideName + "_Rbn_VV_MD") cmds.connectAttr(self.hipsA + '.' + side + self.userGuideName + '_masterScale_' + self.langDic[self.langName]['c_volumeVariation'], rbnVVMD + '.input2X') cmds.connectAttr(rbnVVMD + '.outputX', rbnCond + '.colorIfFalseR') cmds.setAttr(rbnVVMD + '.operation', 2) cmds.setAttr(rbnBlendColors + '.color2R', 1) cmds.setAttr(rbnCond+".secondTerm", 1) # middle ribbon setup: for n in range(1, self.nJoints - 1): if self.currentStyle == 0: #default self.middle = cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_middle'] + str(n) + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=self.ctrlRadius)[0] cmds.setAttr(self.middle + ".rotateOrder", 4) else: #biped self.middle = cmds.circle(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_middle'] + str(n) + "_Ctrl", ch=False, o=True, nr=(0, 1, 0), d=3, s=8, radius=self.ctrlRadius)[0] cmds.setAttr(self.middle + ".rotateOrder", 3) self.aFkCtrl[s].append(self.middle) ctrls.setLockHide([self.middle], ['sx', 'sy', 'sz']) cmds.setAttr(self.middle + '.visibility', keyable=False) cmds.parent(self.middle, self.hipsA) middleLocGuide = side + self.userGuideName + "_Guide_JointLoc" + str(n + 1) cmds.delete(cmds.parentConstraint(middleLocGuide, self.middle, maintainOffset=False)) if self.currentStyle == 1: #biped cmds.rotate(0, 0, 0, self.middle) if self.rigType == Base.RigType.quadruped: cmds.rotate(90, 0, 0, self.middle) cmds.makeIdentity(self.middle, apply=True, rotate=True) utils.zeroOut([self.middle]) middleCluster = cmds.cluster(rbnNurbsPlane + ".cv[0:3][" + str(n + 1) + "]", name=side + self.userGuideName + '_Middle_Cls')[1] middleLocPos = cmds.xform(side + self.userGuideName + "_Guide_JointLoc" + str(n), query=True, worldSpace=True, translation=True) tempDel = cmds.parentConstraint(middleLocGuide, middleCluster, maintainOffset=False) cmds.delete(tempDel) middleClusterRot = cmds.xform(middleCluster, query=True, worldSpace=True, rotation=True) cmds.xform(middleCluster, worldSpace=True, rotation=(middleClusterRot[0] + 90, middleClusterRot[1], middleClusterRot[2])) cmds.parentConstraint(self.middle, middleCluster, maintainOffset=True, name=middleCluster + "_ParentConstraint") # parenting constraints like guide locators: self.parentConst = cmds.parentConstraint(self.hipsB, self.chestB, self.middle + "_Zero", name=self.middle + "_ParentConstraint", maintainOffset=True)[0] nParentValue = (n) / float(self.nJoints - 1) cmds.setAttr(self.parentConst + "." + self.hipsB + "W0", 1 - nParentValue) cmds.setAttr(self.parentConst + "." + self.chestB + "W1", nParentValue) cmds.parent(middleCluster, clustersGrp, relative=True) # add originedFrom attribute to this middle ctrl: utils.originedFrom(objName=self.middle, attrString=middleLocGuide) # apply volumeVariation to joints in the middle ribbon setup: cmds.connectAttr(rbnCond + '.outColorR', self.aRbnJointList[n] + '.scaleX') cmds.connectAttr(rbnCond + '.outColorR', self.aRbnJointList[n] + '.scaleZ') # update spine volume variation setup currentVV = cmds.getAttr(rbnMD + '.outputX') cmds.setAttr(rbnVVMD + '.input1X', currentVV) # organize groups: self.rbnRigGrp = cmds.group(name=side + self.userGuideName + "_Grp", empty=True) self.rbnControlGrp = cmds.group(name=side + self.userGuideName + "_Control_Grp", empty=True) cmds.parent(self.hipsA + "_Zero", self.rbnControlGrp, relative=True) cmds.parent(clustersGrp, side + self.userGuideName + "_Rbn_RibbonJoint_Grp", self.rbnControlGrp, arcLen, self.rbnRigGrp, relative=True) if hideJoints: cmds.setAttr(side + self.userGuideName + "_Rbn_RibbonJoint_Grp.visibility", 0) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.rbnControlGrp, hookType='ctrlHook') utils.addHook(objName=clustersGrp, hookType='scalableHook') utils.addHook(objName=self.rbnRigGrp, hookType='staticHook') cmds.addAttr(self.rbnRigGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.rbnRigGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.rbnRigGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.rbnRigGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.rbnRigGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.rbnRigGrp + '.dpAR_count', dpAR_count) # lockHide scale of up and down controls: ctrls.setLockHide([self.hipsA, self.hipsB, self.chestA, self.chestB], ['sx', 'sy', 'sz']) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declaring lists to send information for integration: self.scalableGrpList, self.ikCtrlZeroList = [], [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_'] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr(side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.skinJointList = [] self.base = side + self.userGuideName + '_Guide_Base' # get the number of joints to be created: self.nJoints = cmds.getAttr(self.base + ".nJoints") for n in range(0, self.nJoints + 1): cmds.select(clear=True) # declare guide: self.guide = side + self.userGuideName + "_Guide_JointLoc" + str(n) # create a joint: self.jnt = cmds.joint(name=side + self.userGuideName + "_" + str(n) + "_Jnt", scaleCompensate=False) self.skinJointList.append(self.jnt) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) # create a control: if n == 1: self.ctrl = ctrls.cvFinger(ctrlName=side + self.userGuideName + "_" + str(n) + "_Ctrl", r=self.ctrlRadius) cmds.setAttr(self.ctrl + ".rotateOrder", 1) utils.originedFrom(objName=self.ctrl, attrString=self.base + ";" + self.guide) # edit the mirror shape to a good direction of controls: if s == 1: if self.mirrorAxis == 'X': cmds.setAttr(self.ctrl + '.rotateZ', 180) elif self.mirrorAxis == 'Y': cmds.setAttr(self.ctrl + '.rotateY', 180) elif self.mirrorAxis == 'Z': cmds.setAttr(self.ctrl + '.rotateZ', 180) elif self.mirrorAxis == 'XY': cmds.setAttr(self.ctrl + '.rotateX', 180) elif self.mirrorAxis == 'XYZ': cmds.setAttr(self.ctrl + '.rotateZ', 180) cmds.makeIdentity(self.ctrl, apply=True, translate=False, rotate=True, scale=False) else: self.ctrl = \ cmds.circle(name=side + self.userGuideName + "_" + str(n) + "_Ctrl", degree=1, normal=(0, 0, 1), r=self.ctrlRadius, s=6, ch=False)[0] cmds.setAttr(self.ctrl + ".rotateOrder", 1) utils.originedFrom(objName=self.ctrl, attrString=self.guide) # scaleCompensate attribute: #Not needed in Maya 2016 since we need to deactivate scale compensate on all finger bone if (int(cmds.about(version=True)[:4]) < 2016): if n > 0 or self.nJoints == 2: cmds.addAttr(self.ctrl, longName="scaleCompensate", attributeType='bool', keyable=True) scaleCompensateCond = cmds.createNode("condition", name=side + self.userGuideName + "_" + str( n) + "_ScaleCompensate_Cnd") cmds.setAttr(scaleCompensateCond + ".secondTerm", 1) cmds.connectAttr(self.ctrl + ".scaleCompensate", scaleCompensateCond + ".colorIfTrueR", force=True) cmds.connectAttr(scaleCompensateCond + ".outColorR", self.jnt + ".segmentScaleCompensate", force=True) # hide visibility attribute: cmds.setAttr(self.ctrl + '.visibility', keyable=False) # put another group over the control in order to use this to connect values from mainFingerCtrl: self.sdkGrp = cmds.group(self.ctrl, name=side + self.userGuideName + "_" + str(n) + "_SDKGrp") if n == 1: # change pivot of this group to control pivot: pivotPos = cmds.xform(self.ctrl, query=True, worldSpace=True, rotatePivot=True) cmds.setAttr(self.sdkGrp + '.rotatePivotX', pivotPos[0]) cmds.setAttr(self.sdkGrp + '.rotatePivotY', pivotPos[1]) cmds.setAttr(self.sdkGrp + '.rotatePivotZ', pivotPos[2]) # position and orientation of joint and control: tempDel = cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False) cmds.delete(tempDel) tempDel = cmds.parentConstraint(self.guide, self.sdkGrp, maintainOffset=False) cmds.delete(tempDel) # zeroOut controls: utils.zeroOut([self.sdkGrp]) # create end joint: self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" self.endJoint = cmds.joint(name=side + self.userGuideName + "_JEnd", scaleCompensate=False) tempDel = cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False) cmds.delete(tempDel) cmds.parent(self.endJoint, side + self.userGuideName + "_" + str(self.nJoints) + "_Jnt", absolute=True) # grouping: for n in range(0, self.nJoints + 1): self.jnt = side + self.userGuideName + "_" + str(n) + "_Jnt" self.ctrl = side + self.userGuideName + "_" + str(n) + "_Ctrl" self.zeroCtrl = side + self.userGuideName + "_" + str(n) + "_SDKGrp_Zero" if n > 0: if n == 1: if not cmds.objExists(self.ctrl + '.ikFkBlend'): cmds.addAttr(self.ctrl, longName="ikFkBlend", attributeType='float', keyable=True, minValue=0.0, maxValue=1.0, defaultValue=1.0) self.ikFkRevNode = cmds.createNode("reverse", name=side + self.userGuideName + "_ikFk_Rev") cmds.connectAttr(self.ctrl + ".ikFkBlend", self.ikFkRevNode + ".inputX", force=True) if not cmds.objExists(self.ctrl + '.' + self.langDic[self.langName]['c_showControls']): cmds.addAttr(self.ctrl, longName=self.langDic[self.langName]['c_showControls'], attributeType='float', keyable=True, minValue=0.0, maxValue=1.0, defaultValue=0.0) self.ctrlShape0 = \ cmds.listRelatives(side + self.userGuideName + "_0_Ctrl", children=True, type='nurbsCurve')[0] cmds.connectAttr(self.ctrl + "." + self.langDic[self.langName]['c_showControls'], self.ctrlShape0 + ".visibility", force=True) cmds.setAttr(self.ctrl + '.' + self.langDic[self.langName]['c_showControls'], keyable=False, channelBox=True) for j in range(1, self.nJoints + 1): cmds.addAttr(self.ctrl, longName=self.langDic[self.langName]['c_falange'] + str(j), attributeType='float', keyable=True) # parent joints as a simple chain (line) self.fatherJnt = side + self.userGuideName + "_" + str(n - 1) + "_Jnt" cmds.parent(self.jnt, self.fatherJnt, absolute=True) # parent zeroCtrl Group to the before ctrl: self.fatherCtrl = side + self.userGuideName + "_" + str(n - 1) + "_Ctrl" cmds.parent(self.zeroCtrl, self.fatherCtrl, absolute=True) # freeze joints rotation cmds.makeIdentity(self.jnt, apply=True) # create parent and scale constraints from ctrl to jnt: cmds.delete(cmds.parentConstraint(self.ctrl, self.jnt, maintainOffset=False, name=self.jnt + "_ParentConstraint")) # make first falange be leads from base finger control: cmds.parentConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_1_SDKGrp_Zero", maintainOffset=True, name=side + self.userGuideName + "_1_SDKGrp_Zero" + "_ParentConstraint") cmds.scaleConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_1_SDKGrp_Zero", maintainOffset=True, name=side + self.userGuideName + "_1_SDKGrp_Zero" + "_ScaleConstraint") if self.nJoints != 2: cmds.parentConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_0_Jnt", maintainOffset=True, name=side + self.userGuideName + "_ParentConstraint") cmds.scaleConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_0_Jnt", maintainOffset=True, name=side + self.userGuideName + "_ScaleConstraint") # connecting the attributes from control 1 to falanges rotate: for n in range(1, self.nJoints + 1): self.ctrl = side + self.userGuideName + "_1_Ctrl" self.sdkGrp = side + self.userGuideName + "_" + str(n) + "_SDKGrp" cmds.connectAttr(self.ctrl + "." + self.langDic[self.langName]['c_falange'] + str(n), self.sdkGrp + ".rotateY", force=True) if n > 1: self.ctrlShape = \ cmds.listRelatives(side + self.userGuideName + "_" + str(n) + "_Ctrl", children=True, type='nurbsCurve')[0] cmds.connectAttr(self.ctrl + "." + self.langDic[self.langName]['c_showControls'], self.ctrlShape + ".visibility", force=True) # ik and Fk setup if self.nJoints == 2: dupIk = cmds.duplicate(self.skinJointList[0])[0] dupFk = cmds.duplicate(self.skinJointList[0])[0] else: dupIk = cmds.duplicate(self.skinJointList[1])[0] dupFk = cmds.duplicate(self.skinJointList[1])[0] # hide ik and fk joints in order to be rigger friendly whe skinning cmds.setAttr(dupIk+".visibility", 0) cmds.setAttr(dupFk+".visibility", 0) # ik setup childrenIkList = cmds.listRelatives(dupIk, children=True, allDescendents=True, fullPath=True) if childrenIkList: for child in childrenIkList: if not cmds.objectType(child) == "joint": cmds.delete(child) jointIkList = cmds.listRelatives(dupIk, children=True, allDescendents=True, fullPath=True) for jointNode in jointIkList: if "_Jnt" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|") + 1:].replace("_Jnt", "_Ik_Jxt")) elif "_JEnd" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|") + 1:].replace("_JEnd", "_Ik_JEnd")) ikBaseJoint = cmds.rename(dupIk, dupIk.replace("_Jnt1", "_Ik_Jxt")) ikJointList = cmds.listRelatives(ikBaseJoint, children=True, allDescendents=True) ikJointList.append(ikBaseJoint) # Fk setup childrenFkList = cmds.listRelatives(dupFk, children=True, allDescendents=True, fullPath=True) if childrenFkList: for child in childrenFkList: if not cmds.objectType(child) == "joint": cmds.delete(child) jointFkList = cmds.listRelatives(dupFk, children=True, allDescendents=True, fullPath=True) for jointNode in jointFkList: if "_Jnt" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|") + 1:].replace("_Jnt", "_Fk_Jxt")) elif "_JEnd" in jointNode[jointNode.rfind("|"):]: cmds.rename(jointNode, jointNode[jointNode.rfind("|") + 1:].replace("_JEnd", "_Fk_JEnd")) fkBaseJoint = cmds.rename(dupFk, dupFk.replace("_Jnt2", "_Fk_Jxt")) fkJointList = cmds.listRelatives(fkBaseJoint, children=True, allDescendents=True) fkJointList.append(fkBaseJoint) # ik fk blend connnections for i, ikJoint in enumerate(ikJointList): if not "_JEnd" in ikJoint: if cmds.objExists(ikJoint + ".dpAR_joint"): cmds.deleteAttr(ikJoint + ".dpAR_joint") fkJoint = ikJoint.replace("_Ik_Jxt", "_Fk_Jxt") skinJoint = ikJoint.replace("_Ik_Jxt", "_Jnt") self.ctrl = side + self.userGuideName + "_1_Ctrl" scaleCompensateCond = ikJoint.replace("_Ik_Jxt", "_ScaleCompensate_Cnd") ikFkParentConst = cmds.parentConstraint(ikJoint, fkJoint, skinJoint, maintainOffset=True, name=skinJoint + "_ParentConstraint")[0] ikFkScaleConst = cmds.scaleConstraint(ikJoint, fkJoint, skinJoint, maintainOffset=True, name=skinJoint + "_ScaleConstraint")[0] cmds.connectAttr(self.ctrl + ".ikFkBlend", ikFkParentConst + "." + fkJoint + "W1", force=True) cmds.connectAttr(self.ikFkRevNode + ".outputX", ikFkParentConst + "." + ikJoint + "W0", force=True) cmds.connectAttr(self.ctrl + ".ikFkBlend", ikFkScaleConst + "." + fkJoint + "W1", force=True) cmds.connectAttr(self.ikFkRevNode + ".outputX", ikFkScaleConst + "." + ikJoint + "W0", force=True) cmds.setAttr(ikJoint + ".segmentScaleCompensate", 1) #Condition for scale compensate will not exist in maya 2016 since we need to have the compensate #off for almost every joint if (int(cmds.about(version=True)[:4]) < 2016): cmds.connectAttr(self.ctrl + ".ikFkBlend", scaleCompensateCond + ".firstTerm", force=True) # fk control drives fk joints for i, fkJoint in enumerate(fkJointList): if not "_JEnd" in fkJoint: if cmds.objExists(fkJoint + ".dpAR_joint"): cmds.deleteAttr(fkJoint + ".dpAR_joint") fkCtrl = fkJoint.replace("_Fk_Jxt", "_Ctrl") scaleCompensateCond = fkCtrl.replace("_Ctrl", "_ScaleCompensate_Cnd") cmds.parentConstraint(fkCtrl, fkJoint, maintainOffset=True, name=fkJoint + "_ParentConstraint") cmds.scaleConstraint(fkCtrl, fkJoint, maintainOffset=True, name=fkJoint + "_ScaleConstraint") #Not needed in Maya 2016 since we need to deactivate scale compensate on all finger bone if (int(cmds.about(version=True)[:4]) < 2016): cmds.connectAttr(fkCtrl + ".scaleCompensate", fkJoint + ".segmentScaleCompensate", force=True) else: cmds.setAttr(fkJoint + ".segmentScaleCompensate", 0) cmds.setAttr(fkCtrl + ".rotateOrder", 1) #Force Scale compensate to prevent scale problem in Maya 2016 for nJnt in self.skinJointList: if (int(cmds.about(version=True)[:4]) >= 2016): cmds.setAttr(nJnt + ".segmentScaleCompensate", 0) # ik handle if self.nJoints >= 2: if self.nJoints == 2: ikHandleList = cmds.ikHandle(startJoint=side + self.userGuideName + "_0_Ik_Jxt", endEffector=side + self.userGuideName + "_" + str( self.nJoints) + "_Ik_Jxt", solver="ikRPsolver", name=side + self.userGuideName + "_IkHandle") else: ikHandleList = cmds.ikHandle(startJoint=side + self.userGuideName + "_1_Ik_Jxt", endEffector=side + self.userGuideName + "_" + str( self.nJoints) + "_Ik_Jxt", solver="ikRPsolver", name=side + self.userGuideName + "_IkHandle") cmds.rename(ikHandleList[1], side + self.userGuideName + "_Effector") endIkHandleList = cmds.ikHandle( startJoint=side + self.userGuideName + "_" + str(self.nJoints) + "_Ik_Jxt", endEffector=side + self.userGuideName + "_Ik_JEnd", solver="ikSCsolver", name=side + self.userGuideName + "_EndIkHandle") cmds.rename(endIkHandleList[1], side + self.userGuideName + "_EndEffector") self.ikCtrl = ctrls.cvBox(ctrlName=side + self.userGuideName + "_Ik_Ctrl", r=self.ctrlRadius) cmds.addAttr(self.ikCtrl, longName='twist', attributeType='float', keyable=True) cmds.connectAttr(self.ikCtrl + ".twist", ikHandleList[0] + ".twist", force=True) cmds.delete(cmds.parentConstraint(side + self.userGuideName + "_Ik_JEnd", self.ikCtrl)) cmds.setAttr(self.ikCtrl + ".rotateOrder", 1) self.ikCtrlZero = utils.zeroOut([self.ikCtrl])[0] self.ikCtrlZeroList.append(self.ikCtrlZero) cmds.connectAttr(self.ikFkRevNode + ".outputX", self.ikCtrlZero + ".visibility", force=True) for q in range(2, self.nJoints): cmds.connectAttr(side + self.userGuideName + "_1_Ctrl.ikFkBlend", side + self.userGuideName + "_" + str(q) + "_Ctrl.visibility", force=True) cmds.parentConstraint(self.ikCtrl, ikHandleList[0], name=side + self.userGuideName + "_IkHandle_ParentConstraint", maintainOffset=True) cmds.parentConstraint(self.ikCtrl, endIkHandleList[0], name=side + self.userGuideName + "_EndIkHandle_ParentConstraint", maintainOffset=True) ikHandleGrp = cmds.group(ikHandleList[0], endIkHandleList[0], name=side + self.userGuideName + "_IkHandle_Grp") cmds.setAttr(ikHandleGrp+".visibility", 0) ctrls.setLockHide([self.ikCtrl], ['sx', 'sy', 'sz', 'v']) if self.nJoints == 2: cmds.parentConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_0_Ik_Jxt", maintainOffset=True, name=side + self.userGuideName + "_0_Ik_Jxt_ParentConstraint") cmds.scaleConstraint(side + self.userGuideName + "_0_Ctrl", side + self.userGuideName + "_0_Ik_Jxt", maintainOffset=True, name=side + self.userGuideName + "_0_Ik_Jxt_ScaleConstraint") # stretch cmds.addAttr(self.ikCtrl, longName='stretchable', attributeType='float', minValue=0, maxValue=1, defaultValue=0, keyable=True) stretchNormMD = cmds.createNode("multiplyDivide", name=side + self.userGuideName + "_StretchNormalize_MD") cmds.setAttr(stretchNormMD + ".operation", 2) distBetweenList = ctrls.distanceBet(side + self.userGuideName + "_0_Ctrl", self.ikCtrl, name=side + self.userGuideName + "_DistBet", keep=True) cmds.connectAttr(self.ikFkRevNode + ".outputX", distBetweenList[5] + "." + self.ikCtrl + "W0", force=True) cmds.connectAttr(self.ctrl + ".ikFkBlend", distBetweenList[5] + "." + distBetweenList[4] + "W1", force=True) cmds.connectAttr(distBetweenList[1] + ".distance", stretchNormMD + ".input1X", force=True) cmds.setAttr(stretchNormMD + ".input2X", distBetweenList[0]) stretchScaleMD = cmds.createNode("multiplyDivide", name=side + self.userGuideName + "_StretchScale_MD") cmds.connectAttr(stretchNormMD + ".outputX", stretchScaleMD + ".input1X", force=True) cmds.connectAttr(self.ikCtrl + ".stretchable", stretchScaleMD + ".input2X", force=True) stretchCond = cmds.createNode("condition", name=side + self.userGuideName + "_Stretch_Cnd") cmds.connectAttr(stretchScaleMD + ".outputX", stretchCond + ".firstTerm", force=True) cmds.setAttr(stretchCond + ".secondTerm", 1) cmds.setAttr(stretchCond + ".operation", 2) cmds.connectAttr(stretchScaleMD + ".outputX", stretchCond + ".colorIfTrueR", force=True) for i, ikJoint in enumerate(ikJointList): if not "_JEnd" in ikJoint: if self.nJoints == 2 and i == 0: pass else: cmds.connectAttr(stretchCond + ".outColorR", ikJoint + ".scaleZ", force=True) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(self.ikCtrlZero, side + self.userGuideName + "_0_SDKGrp_Zero", side + self.userGuideName + "_1_SDKGrp_Zero", name=side + self.userGuideName + "_Control_Grp") if self.nJoints == 2: self.toScalableHookGrp = cmds.group(side + self.userGuideName + "_0_Jnt", ikBaseJoint, fkBaseJoint, ikHandleGrp, distBetweenList[2], distBetweenList[3], distBetweenList[4], name=side + self.userGuideName + "_Joint_Grp") else: self.toScalableHookGrp = cmds.group(side + self.userGuideName + "_0_Jnt", ikHandleGrp, distBetweenList[2], distBetweenList[3], distBetweenList[4], name=side + self.userGuideName + "_Joint_Grp") else: self.toCtrlHookGrp = cmds.group(side + self.userGuideName + "_0_SDKGrp_Zero", side + self.userGuideName + "_1_SDKGrp_Zero", name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group(side + self.userGuideName + "_0_Jnt", name=side + self.userGuideName + "_Joint_Grp") self.scalableGrpList.append(self.toScalableHookGrp) self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declare lists to store names and attributes: self.worldRefList, self.headCtrlList = [], [] self.aCtrls = [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # redeclaring variables: self.base = side + self.userGuideName + "_Guide_Base" self.cvNeckLoc = side + self.userGuideName + "_Guide_neck" self.cvHeadLoc = side + self.userGuideName + "_Guide_head" self.cvJawLoc = side + self.userGuideName + "_Guide_jaw" self.cvChinLoc = side + self.userGuideName + "_Guide_chin" self.cvLLipLoc = side + self.userGuideName + "_Guide_lLip" self.cvRLipLoc = side + self.userGuideName + "_Guide_rLip" self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" # creating joints: self.neckJnt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_neck'] + "_Jnt") self.headJxt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_head'] + "_Jxt") cmds.select(clear=True) self.headJnt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_head'] + "_Jnt", scaleCompensate=False) self.jawJnt = cmds.joint(name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_jaw'] + "_Jnt", scaleCompensate=False) self.chinJnt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chin'] + "_Jnt", scaleCompensate=False) self.endJnt = cmds.joint(name=side + self.userGuideName + "_JEnd", scaleCompensate=False) cmds.select(clear=True) self.lLipJnt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['p002_left'] + "_" + self.langDic[self.langName]['c_lip'] + "_Jnt", scaleCompensate=False) cmds.select(clear=True) self.rLipJnt = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['p003_right'] + "_" + self.langDic[self.langName]['c_lip'] + "_Jnt", scaleCompensate=False) dpARJointList = [ self.neckJnt, self.headJnt, self.jawJnt, self.chinJnt, self.lLipJnt, self.rLipJnt ] for dpARJoint in dpARJointList: cmds.addAttr(dpARJoint, longName='dpAR_joint', attributeType='float', keyable=False) # creating controls: self.neckCtrl = ctrls.cvNeck( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_neck'] + "_Ctrl", r=self.ctrlRadius / 2.0) self.headCtrl = ctrls.cvHead( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_head'] + "_Ctrl", r=self.ctrlRadius / 2.0) self.jawCtrl = ctrls.cvJaw( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_jaw'] + "_Ctrl", r=self.ctrlRadius / 2.0) self.chinCtrl = ctrls.cvChin( ctrlName=side + self.userGuideName + "_" + self.langDic[self.langName]['c_chin'] + "_Ctrl", r=self.ctrlRadius / 2.0) self.lLipCtrl = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[self.langName]['p002_left'] + "_" + self.langDic[self.langName]['c_lip'] + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=(self.ctrlRadius * 0.25))[0] self.rLipCtrl = cmds.circle( name=side + self.userGuideName + "_" + self.langDic[self.langName]['p003_right'] + "_" + self.langDic[self.langName]['c_lip'] + "_Ctrl", ch=False, o=True, nr=(0, 0, 1), d=3, s=8, radius=(self.ctrlRadius * 0.25))[0] self.headCtrlList.append(self.headCtrl) self.aCtrls.append([ self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl, self.lLipCtrl, self.rLipCtrl ]) #Setup Axis Order if self.rigType == Base.RigType.quadruped: cmds.setAttr(self.neckCtrl + ".rotateOrder", 1) cmds.setAttr(self.headCtrl + ".rotateOrder", 1) cmds.setAttr(self.jawCtrl + ".rotateOrder", 1) else: cmds.setAttr(self.neckCtrl + ".rotateOrder", 4) cmds.setAttr(self.headCtrl + ".rotateOrder", 4) cmds.setAttr(self.jawCtrl + ".rotateOrder", 4) # creating the originedFrom attributes (in order to permit integrated parents in the future): utils.originedFrom(objName=self.neckCtrl, attrString=self.base + ";" + self.cvNeckLoc) utils.originedFrom(objName=self.headCtrl, attrString=self.cvHeadLoc) utils.originedFrom(objName=self.jawCtrl, attrString=self.cvJawLoc) utils.originedFrom(objName=self.chinCtrl, attrString=self.cvChinLoc + ";" + self.cvEndJoint) # orientation of controls: ctrls.setAndFreeze(nodeName=self.neckCtrl, rx=90, rz=-90) ctrls.setAndFreeze(nodeName=self.headCtrl, rx=90, rz=-90) ctrls.setAndFreeze(nodeName=self.jawCtrl, rz=-90) ctrls.setAndFreeze(nodeName=self.chinCtrl, rz=-90) # edit the mirror shape to a good direction of controls: ctrlList = [ self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl ] if s == 1: for ctrl in ctrlList: if self.mirrorAxis == 'X': cmds.setAttr(ctrl + '.rotateY', 180) elif self.mirrorAxis == 'Y': cmds.setAttr(ctrl + '.rotateY', 180) elif self.mirrorAxis == 'Z': cmds.setAttr(ctrl + '.rotateX', 180) cmds.setAttr(ctrl + '.rotateZ', 180) elif self.mirrorAxis == 'XYZ': cmds.setAttr(ctrl + '.rotateX', 180) cmds.setAttr(ctrl + '.rotateZ', 180) cmds.makeIdentity(ctrlList, apply=True, translate=False, rotate=True, scale=False) # temporary parentConstraints: tempDelNeck = cmds.parentConstraint(self.cvNeckLoc, self.neckCtrl, maintainOffset=False) tempDelHead = cmds.parentConstraint(self.cvHeadLoc, self.headCtrl, maintainOffset=False) tempDelJaw = cmds.parentConstraint(self.cvJawLoc, self.jawCtrl, maintainOffset=False) tempDelChin = cmds.parentConstraint(self.cvChinLoc, self.chinCtrl, maintainOffset=False) tempDelLLip = cmds.parentConstraint(self.cvLLipLoc, self.lLipCtrl, maintainOffset=False) tempDelRLip = cmds.parentConstraint(self.cvRLipLoc, self.rLipCtrl, maintainOffset=False) cmds.delete(tempDelNeck, tempDelHead, tempDelJaw, tempDelChin, tempDelLLip, tempDelRLip) # zeroOut controls: self.zeroLipCtrlList = utils.zeroOut( [self.lLipCtrl, self.rLipCtrl]) self.lLipGrp = cmds.group(self.lLipCtrl, name=self.lLipCtrl + "_Grp") self.rLipGrp = cmds.group(self.rLipCtrl, name=self.rLipCtrl + "_Grp") self.zeroCtrlList = utils.zeroOut([ self.neckCtrl, self.headCtrl, self.jawCtrl, self.chinCtrl, self.zeroLipCtrlList[0], self.zeroLipCtrlList[1] ]) # make joints be ride by controls: cmds.makeIdentity(self.neckJnt, self.headJxt, self.headJnt, self.jawJnt, self.chinJnt, self.endJnt, rotate=True, apply=True) cmds.parentConstraint(self.neckCtrl, self.neckJnt, maintainOffset=False, name=self.neckJnt + "_ParentConstraint") cmds.scaleConstraint(self.neckCtrl, self.neckJnt, maintainOffset=False, name=self.neckJnt + "_ScaleConstraint") cmds.delete( cmds.parentConstraint(self.headCtrl, self.headJxt, maintainOffset=False)) cmds.parentConstraint(self.headCtrl, self.headJnt, maintainOffset=False, name=self.headJnt + "_ParentConstraint") cmds.parentConstraint(self.jawCtrl, self.jawJnt, maintainOffset=False, name=self.jawJnt + "_ParentConstraint") cmds.parentConstraint(self.chinCtrl, self.chinJnt, maintainOffset=False, name=self.chinJnt + "_ParentConstraint") cmds.parentConstraint(self.lLipCtrl, self.lLipJnt, maintainOffset=False, name=self.lLipJnt + "_ParentConstraint") cmds.parentConstraint(self.rLipCtrl, self.rLipJnt, maintainOffset=False, name=self.rLipJnt + "_ParentConstraint") cmds.scaleConstraint(self.headCtrl, self.headJnt, maintainOffset=False, name=self.headJnt + "_ScaleConstraint") cmds.scaleConstraint(self.jawCtrl, self.jawJnt, maintainOffset=False, name=self.jawJnt + "_ScaleConstraint") cmds.scaleConstraint(self.chinCtrl, self.chinJnt, maintainOffset=False, name=self.chinJnt + "_ScaleConstraint") cmds.scaleConstraint(self.lLipCtrl, self.lLipJnt, maintainOffset=False, name=self.lLipJnt + "_ScaleConstraint") cmds.scaleConstraint(self.rLipCtrl, self.rLipJnt, maintainOffset=False, name=self.rLipJnt + "_ScaleConstraint") cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.endJnt, maintainOffset=False)) cmds.setAttr(self.jawJnt + ".segmentScaleCompensate", 0) # create interations between neck and head: self.grpNeck = cmds.group(self.zeroCtrlList[0], name=self.neckCtrl + "_Grp") self.grpHeadA = cmds.group(empty=True, name=self.headCtrl + "_A_Grp") self.grpHead = cmds.group(self.grpHeadA, name=self.headCtrl + "_Grp") # arrange pivots: self.neckPivot = cmds.xform(self.neckCtrl, query=True, worldSpace=True, translation=True) self.headPivot = cmds.xform(self.headCtrl, query=True, worldSpace=True, translation=True) cmds.xform(self.grpNeck, pivots=(self.neckPivot[0], self.neckPivot[1], self.neckPivot[2])) cmds.xform(self.grpHead, self.grpHeadA, pivots=(self.headPivot[0], self.headPivot[1], self.headPivot[2])) self.worldRef = cmds.group(empty=True, name=side + self.userGuideName + "_WorldRef") self.worldRefList.append(self.worldRef) cmds.delete( cmds.parentConstraint(self.neckCtrl, self.worldRef, maintainOffset=False)) cmds.parentConstraint(self.neckCtrl, self.grpHeadA, maintainOffset=True, skipRotate=["x", "y", "z"], name=self.grpHeadA + "_ParentConstraint") orientConst = cmds.orientConstraint(self.neckCtrl, self.worldRef, self.grpHeadA, maintainOffset=False, name=self.grpHeadA + "_OrientConstraint")[0] cmds.scaleConstraint(self.neckCtrl, self.grpHeadA, maintainOffset=True, name=self.grpHeadA + "_ScaleConstraint") cmds.parent(self.zeroCtrlList[1], self.grpHeadA, absolute=True) # connect reverseNode: cmds.addAttr(self.headCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, keyable=True) cmds.connectAttr(self.headCtrl + '.' + self.langDic[self.langName]['c_Follow'], orientConst + "." + self.neckCtrl + "W0", force=True) self.headRevNode = cmds.createNode('reverse', name=side + self.userGuideName + "_Rev") cmds.connectAttr(self.headCtrl + '.' + self.langDic[self.langName]['c_Follow'], self.headRevNode + ".inputX", force=True) cmds.connectAttr(self.headRevNode + '.outputX', orientConst + "." + self.worldRef + "W1", force=True) # mount controls hierarchy: cmds.parent(self.zeroCtrlList[3], self.jawCtrl, absolute=True) # jaw follow head or root ctrl (using worldRef) jawParentConst = cmds.parentConstraint( self.headCtrl, self.worldRef, self.zeroCtrlList[2], maintainOffset=True, name=self.zeroCtrlList[2] + "_ParentConstraint")[0] cmds.setAttr(jawParentConst + ".interpType", 2) #Shortest, no flip cause problem with scrubing cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType="float", minValue=0, maxValue=1, defaultValue=1, keyable=True) cmds.connectAttr(self.jawCtrl + "." + self.langDic[self.langName]['c_Follow'], jawParentConst + "." + self.headCtrl + "W0", force=True) jawFollowRev = cmds.createNode("reverse", name=self.jawCtrl + "_Rev") cmds.connectAttr(self.jawCtrl + "." + self.langDic[self.langName]['c_Follow'], jawFollowRev + ".inputX", force=True) cmds.connectAttr(jawFollowRev + ".outputX", jawParentConst + "." + self.worldRef + "W1", force=True) cmds.scaleConstraint(self.headCtrl, self.zeroCtrlList[2], maintainOffset=True, name=self.zeroCtrlList[2] + "_ScaleConstraint")[0] # setup jaw auto translation self.jawSdkGrp = cmds.group(self.jawCtrl, name=self.jawCtrl + "_SDK_Grp") cmds.addAttr( self.jawCtrl, longName=self.langDic[self.langName]['c_moveIntensity'] + "Y", attributeType='float', keyable=True) cmds.addAttr( self.jawCtrl, longName=self.langDic[self.langName]['c_moveIntensity'] + "Z", attributeType='float', keyable=True) cmds.addAttr(self.jawCtrl, longName=self.langDic[self.langName] ['c_moveStartRotation'], attributeType='float', keyable=True) cmds.setAttr(self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Y", keyable=False, channelBox=True) cmds.setAttr(self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Z", keyable=False, channelBox=True) cmds.setAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveStartRotation'], keyable=False, channelBox=True) cmds.setAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Y", 0.01) cmds.setAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Z", 0.02) cmds.setAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveStartRotation'], -10) self.jawIntensityMD = cmds.createNode( 'multiplyDivide', name="JawMoveIntensity_MD") self.jawIntensityZMD = cmds.createNode( 'multiplyDivide', name="JawMoveIntensityZ_MD") self.jawIntensityZInvMD = cmds.createNode( 'multiplyDivide', name="JawMoveIntensityZInv_MD") self.jawStartIntensityMD = cmds.createNode( 'multiplyDivide', name="JawMoveIntensityStart_MD") self.jawIntensityPMA = cmds.createNode( 'plusMinusAverage', name="JawMoveIntensity_PMA") self.jawIntensityCnd = cmds.createNode( 'condition', name="JawMoveIntensity_Cnd") cmds.connectAttr(self.jawCtrl + ".rotateY", self.jawIntensityMD + ".input1Y", force=True) cmds.connectAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Y", self.jawIntensityMD + ".input2Y", force=True) cmds.connectAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Y", self.jawStartIntensityMD + ".input1X", force=True) cmds.connectAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveStartRotation'], self.jawStartIntensityMD + ".input2X", force=True) cmds.setAttr(self.jawIntensityPMA + ".operation", 2) cmds.connectAttr(self.jawIntensityMD + ".outputY", self.jawIntensityPMA + ".input1D[0]", force=True) cmds.connectAttr(self.jawStartIntensityMD + ".outputX", self.jawIntensityPMA + ".input1D[1]", force=True) cmds.connectAttr(self.jawIntensityPMA + ".output1D", self.jawIntensityCnd + ".colorIfTrueG", force=True) cmds.connectAttr(self.jawCtrl + ".rotateY", self.jawIntensityCnd + ".firstTerm", force=True) cmds.connectAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveStartRotation'], self.jawIntensityCnd + ".secondTerm", force=True) cmds.setAttr(self.jawIntensityCnd + ".operation", 4) cmds.setAttr(self.jawIntensityCnd + ".colorIfFalseG", 0) cmds.connectAttr(self.jawIntensityCnd + ".outColorG", self.jawSdkGrp + ".translateX", force=True) cmds.connectAttr(self.jawIntensityCnd + ".outColorG", self.jawIntensityZMD + ".input1Z", force=True) cmds.connectAttr( self.jawCtrl + "." + self.langDic[self.langName]['c_moveIntensity'] + "Z", self.jawIntensityZMD + ".input2Z", force=True) cmds.connectAttr(self.jawIntensityZMD + ".outputZ", self.jawIntensityZInvMD + ".input1Z", force=True) cmds.setAttr(self.jawIntensityZInvMD + ".input2Z", -1) cmds.connectAttr(self.jawIntensityZInvMD + ".outputZ", self.jawSdkGrp + ".translateZ", force=True) # create lip setup: # left side lip: lLipParentConst = cmds.parentConstraint(self.jawCtrl, self.headCtrl, self.lLipGrp, maintainOffset=True, name=self.lLipGrp + "_ParentConstraint")[0] cmds.setAttr(lLipParentConst + ".interpType", 2) cmds.addAttr(self.lLipCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, defaultValue=0.5, keyable=True) cmds.connectAttr(self.lLipCtrl + '.' + self.langDic[self.langName]['c_Follow'], lLipParentConst + "." + self.jawCtrl + "W0", force=True) self.lLipRevNode = cmds.createNode( 'reverse', name=side + self.userGuideName + "_" + self.langDic[self.langName]['p002_left'] + "_" + self.langDic[self.langName]['c_lip'] + "_Rev") cmds.connectAttr(self.lLipCtrl + '.' + self.langDic[self.langName]['c_Follow'], self.lLipRevNode + ".inputX", force=True) cmds.connectAttr(self.lLipRevNode + '.outputX', lLipParentConst + "." + self.headCtrl + "W1", force=True) cmds.scaleConstraint(self.headCtrl, self.lLipGrp, maintainOffset=True, name=self.lLipGrp + "_ScaleConstraint")[0] # right side lip: rLipParentConst = cmds.parentConstraint(self.jawCtrl, self.headCtrl, self.rLipGrp, maintainOffset=True, name=self.rLipGrp + "_ParentConstraint")[0] cmds.setAttr(rLipParentConst + ".interpType", 2) cmds.addAttr(self.rLipCtrl, longName=self.langDic[self.langName]['c_Follow'], attributeType='float', minValue=0, maxValue=1, defaultValue=0.5, keyable=True) cmds.connectAttr(self.rLipCtrl + '.' + self.langDic[self.langName]['c_Follow'], rLipParentConst + "." + self.jawCtrl + "W0", force=True) self.rLipRevNode = cmds.createNode( 'reverse', name=side + self.userGuideName + "_" + self.langDic[self.langName]['p003_right'] + "_" + self.langDic[self.langName]['c_lip'] + "_Rev") cmds.connectAttr(self.rLipCtrl + '.' + self.langDic[self.langName]['c_Follow'], self.rLipRevNode + ".inputX", force=True) cmds.connectAttr(self.rLipRevNode + '.outputX', rLipParentConst + "." + self.headCtrl + "W1", force=True) cmds.scaleConstraint(self.headCtrl, self.rLipGrp, maintainOffset=True, name=self.rLipGrp + "_ScaleConstraint")[0] # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.worldRef, absolute=True) cmds.setAttr(loc + ".visibility", 0) ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # hiding visibility attributes: ctrls.setLockHide([ self.headCtrl, self.neckCtrl, self.jawCtrl, self.chinCtrl ], ['v'], l=False) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( self.grpNeck, self.grpHead, self.zeroCtrlList[2], self.zeroCtrlList[4], self.zeroCtrlList[5], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( self.neckJnt, self.headJnt, self.lLipJnt, self.rLipJnt, name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, self.grpHead, self.worldRef, name=side + self.userGuideName + "_Grp") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.grpHead, hookType='rootHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declare lists to store names and attributes: self.mainCtrlList, self.wheelCtrlList, self.steeringGrpList, self.ctrlHookGrpList = [], [], [], [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): # declare guides: self.base = side + self.userGuideName + '_Guide_Base' self.cvCenterLoc = side + self.userGuideName + "_Guide_CenterLoc" self.cvFrontLoc = side + self.userGuideName + "_Guide_FrontLoc" self.cvInsideLoc = side + self.userGuideName + "_Guide_InsideLoc" self.cvOutsideLoc = side + self.userGuideName + "_Guide_OutsideLoc" # create a joint: cmds.select(clear=True) self.centerJoint = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Jnt", scaleCompensate=False) cmds.addAttr(self.centerJoint, longName='dpAR_joint', attributeType='float', keyable=False) # joint labelling: utils.setJointLabel( self.centerJoint, s + jointLabelAdd, 18, self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel']) # create end joint: self.endJoint = cmds.joint( name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_JEnd") # create controls: self.wheelCtrl = self.ctrls.cvControl( "id_060_WheelCenter", side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree) self.mainCtrl = self.ctrls.cvControl( "id_061_WheelMain", side + self.userGuideName + "_" + self.langDic[self.langName]['c058_main'] + "_Ctrl", r=self.ctrlRadius * 0.4, d=self.curveDegree) self.insideCtrl = self.ctrls.cvControl( "id_062_WheelPivot", side + self.userGuideName + "_" + self.langDic[self.langName]['c011_RevFoot_B'].capitalize() + "_Ctrl", r=self.ctrlRadius * 0.2, d=self.curveDegree, rot=(0, 90, 0)) self.outsideCtrl = self.ctrls.cvControl( "id_062_WheelPivot", side + self.userGuideName + "_" + self.langDic[self.langName]['c010_RevFoot_A'].capitalize() + "_Ctrl", r=self.ctrlRadius * 0.2, d=self.curveDegree, rot=(0, 90, 0)) self.mainCtrlList.append(self.mainCtrl) self.wheelCtrlList.append(self.wheelCtrl) # origined from attributes: utils.originedFrom(objName=self.mainCtrl, attrString=self.base + ";" + self.cvCenterLoc + ";" + self.cvFrontLoc + ";" + self.cvInsideLoc + ";" + self.cvOutsideLoc) #utils.originedFrom(objName=self.wheelCtrl, attrString=self.cvCenterLoc) # prepare group to receive steering wheel connection: self.toSteeringGrp = cmds.group( self.insideCtrl, name=side + self.userGuideName + "_" + self.langDic[self.langName]['c070_steering'].capitalize() + "_Grp") cmds.addAttr( self.toSteeringGrp, longName=self.langDic[self.langName]['c070_steering'], attributeType='bool', keyable=True) cmds.addAttr( self.toSteeringGrp, longName=self.langDic[self.langName]['c070_steering'] + self.langDic[self.langName]['m151_invert'], attributeType='bool', keyable=True) cmds.setAttr( self.toSteeringGrp + "." + self.langDic[self.langName]['c070_steering'], 1) self.steeringGrpList.append(self.toSteeringGrp) # position and orientation of joint and control: cmds.delete( cmds.parentConstraint(self.cvCenterLoc, self.centerJoint, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvFrontLoc, self.endJoint, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, self.wheelCtrl, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, self.mainCtrl, maintainOffset=False)) if s == 1 and cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.move(self.ctrlRadius, self.mainCtrl, moveY=True, relative=True, objectSpace=True, worldSpaceDistance=True) else: cmds.move(-self.ctrlRadius, self.mainCtrl, moveY=True, relative=True, objectSpace=True, worldSpaceDistance=True) cmds.delete( cmds.parentConstraint(self.cvInsideLoc, self.toSteeringGrp, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvOutsideLoc, self.outsideCtrl, maintainOffset=False)) # zeroOut controls: zeroGrpList = utils.zeroOut([ self.mainCtrl, self.wheelCtrl, self.toSteeringGrp, self.outsideCtrl ]) wheelAutoGrp = utils.zeroOut([self.wheelCtrl]) wheelAutoGrp = cmds.rename( wheelAutoGrp, side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Auto_Grp") # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: for zeroOutGrp in zeroGrpList: cmds.setAttr(zeroOutGrp + ".scaleX", -1) cmds.setAttr(zeroOutGrp + ".scaleY", -1) cmds.setAttr(zeroOutGrp + ".scaleZ", -1) cmds.addAttr(self.wheelCtrl, longName='scaleCompensate', attributeType="bool", keyable=False) cmds.setAttr(self.wheelCtrl + ".scaleCompensate", 1, channelBox=True) cmds.connectAttr(self.wheelCtrl + ".scaleCompensate", self.centerJoint + ".segmentScaleCompensate", force=True) # hide visibility attributes: self.ctrls.setLockHide( [self.mainCtrl, self.insideCtrl, self.outsideCtrl], ['v']) self.ctrls.setLockHide( [self.wheelCtrl], ['tx', 'ty', 'tz', 'rx', 'ry', 'sx', 'sy', 'sz', 'v']) # grouping: cmds.parentConstraint(self.wheelCtrl, self.centerJoint, maintainOffset=False, name=self.centerJoint + "_ParentConstraint") cmds.scaleConstraint(self.wheelCtrl, self.centerJoint, maintainOffset=True, name=self.centerJoint + "_ScaleConstraint") cmds.parent(zeroGrpList[1], self.mainCtrl, absolute=True) cmds.parent(zeroGrpList[0], self.outsideCtrl, absolute=True) cmds.parent(zeroGrpList[3], self.insideCtrl, absolute=True) # add attributes: cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c047_autoRotate'], attributeType="bool", defaultValue=1, keyable=True) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c068_startFrame'], attributeType="long", defaultValue=1, keyable=False) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c067_radius'], attributeType="float", min=0.01, defaultValue=self.ctrlRadius, keyable=True) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c069_radiusScale'], attributeType="float", defaultValue=1, keyable=False) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c021_showControls'], attributeType="long", min=0, max=1, defaultValue=0, keyable=True) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c070_steering'], attributeType="bool", defaultValue=0, keyable=True) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['i037_to'] + self.langDic[self.langName]['c070_steering'].capitalize(), attributeType="float", defaultValue=0, keyable=False) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c070_steering'] + self.langDic[self.langName]['c053_invert'].capitalize(), attributeType="long", min=0, max=1, defaultValue=1, keyable=False) cmds.addAttr( self.wheelCtrl, longName=self.langDic[self.langName]['c093_tryKeepUndo'], attributeType="long", min=0, max=1, defaultValue=1, keyable=False) # get stored values by user: startFrameValue = cmds.getAttr(self.moduleGrp + ".startFrame") steeringValue = cmds.getAttr(self.moduleGrp + ".steering") showControlsValue = cmds.getAttr(self.moduleGrp + ".showControls") cmds.setAttr(self.wheelCtrl + "." + self.langDic[self.langName]['c068_startFrame'], startFrameValue, channelBox=True) cmds.setAttr(self.wheelCtrl + "." + self.langDic[self.langName]['c070_steering'], steeringValue, channelBox=True) cmds.setAttr(self.wheelCtrl + "." + self.langDic[self.langName]['c021_showControls'], showControlsValue, channelBox=True) cmds.setAttr( self.wheelCtrl + "." + self.langDic[self.langName]['c070_steering'] + self.langDic[self.langName]['c053_invert'].capitalize(), 1, channelBox=True) cmds.setAttr(self.wheelCtrl + "." + self.langDic[self.langName]['c093_tryKeepUndo'], 1, channelBox=True) if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr( self.wheelCtrl + "." + self.langDic[self.langName]['c070_steering'] + self.langDic[ self.langName]['c053_invert'].capitalize(), 0) # automatic rotation wheel setup: receptSteeringMD = cmds.createNode( 'multiplyDivide', name=side + self.userGuideName + "_" + self.langDic[self.langName]['c070_steering'] + "_MD") inverseSteeringMD = cmds.createNode( 'multiplyDivide', name=side + self.userGuideName + "_" + self.langDic[self.langName]['c070_steering'] + "_Inv_MD") steeringInvCnd = cmds.createNode( 'condition', name=side + self.userGuideName + "_" + self.langDic[self.langName]['c070_steering'] + "_Inv_Cnd") cmds.setAttr(steeringInvCnd + ".colorIfTrueR", 1) cmds.setAttr(steeringInvCnd + ".colorIfFalseR", -1) cmds.connectAttr( self.wheelCtrl + "." + self.langDic[self.langName]['i037_to'] + self.langDic[self.langName]['c070_steering'].capitalize(), receptSteeringMD + ".input1X", force=True) cmds.connectAttr(self.wheelCtrl + "." + self.langDic[self.langName]['c070_steering'], receptSteeringMD + ".input2X", force=True) cmds.connectAttr(receptSteeringMD + ".outputX", inverseSteeringMD + ".input1X", force=True) cmds.connectAttr(steeringInvCnd + ".outColorR", inverseSteeringMD + ".input2X", force=True) cmds.connectAttr( self.wheelCtrl + "." + self.langDic[self.langName]['c070_steering'] + self.langDic[self.langName]['c053_invert'].capitalize(), steeringInvCnd + ".firstTerm", force=True) cmds.connectAttr(inverseSteeringMD + ".outputX", self.toSteeringGrp + ".rotateY", force=True) # create locators (frontLoc to get direction and oldLoc to store wheel old position): self.frontLoc = cmds.spaceLocator( name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Front_Loc")[0] self.oldLoc = cmds.spaceLocator( name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Old_Loc")[0] cmds.delete( cmds.parentConstraint(self.cvFrontLoc, self.frontLoc, maintainOffset=False)) cmds.parent(self.frontLoc, self.mainCtrl) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, self.oldLoc, maintainOffset=False)) cmds.setAttr(self.frontLoc + ".visibility", 0, lock=True) cmds.setAttr(self.oldLoc + ".visibility", 0, lock=True) # this wheel auto group locator could be replaced by a decomposeMatrix to get the translation in world space of the Wheel_Auto_Ctrl_Grp instead: self.wheelAutoGrpLoc = cmds.spaceLocator( name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Auto_Loc")[0] cmds.pointConstraint(wheelAutoGrp, self.wheelAutoGrpLoc, maintainOffset=False, name=self.wheelAutoGrpLoc + "_PointConstraint") cmds.setAttr(self.wheelAutoGrpLoc + ".visibility", 0, lock=True) expString = "if ("+self.wheelCtrl+"."+self.langDic[self.langName]['c047_autoRotate']+" == 1) {"+\ "\nif ("+self.wheelCtrl+"."+self.langDic[self.langName]['c093_tryKeepUndo']+" == 1) { undoInfo -stateWithoutFlush 0; };"+\ "\nfloat $radius = "+self.wheelCtrl+"."+self.langDic[self.langName]['c067_radius']+" * "+self.wheelCtrl+"."+self.langDic[self.langName]['c069_radiusScale']+\ ";\nvector $moveVectorOld = `xform -q -ws -t \""+self.oldLoc+\ "\"`;\nvector $moveVector = << "+self.wheelAutoGrpLoc+".translateX, "+self.wheelAutoGrpLoc+".translateY, "+self.wheelAutoGrpLoc+".translateZ >>;"+\ "\nvector $dirVector = `xform -q -ws -t \""+self.frontLoc+\ "\"`;\nvector $wheelVector = ($dirVector - $moveVector);"+\ "\nvector $motionVector = ($moveVector - $moveVectorOld);"+\ "\nfloat $distance = mag($motionVector);"+\ "\n$dot = dotProduct($motionVector, $wheelVector, 1);\n"+\ wheelAutoGrp+".rotateZ = "+wheelAutoGrp+".rotateZ - 360 / (6.283*$radius) * ($dot*$distance);"+\ "\nxform -t ($moveVector.x) ($moveVector.y) ($moveVector.z) "+self.oldLoc+\ ";\nif (frame == "+self.wheelCtrl+"."+self.langDic[self.langName]['c068_startFrame']+") { "+wheelAutoGrp+".rotateZ = 0; };"+\ "\nif ("+self.wheelCtrl+"."+self.langDic[self.langName]['c093_tryKeepUndo']+" == 1) { undoInfo -stateWithoutFlush 1; };};" # expression: cmds.expression(name=side + self.userGuideName + "_" + self.langDic[self.langName]['m156_wheel'] + "_Exp", object=self.frontLoc, string=expString) self.ctrls.setLockHide([self.frontLoc, self.wheelAutoGrpLoc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # deformers: self.loadedGeo = cmds.getAttr(self.moduleGrp + ".geo") # geometry holder: self.geoHolder = cmds.polyCube( name=side + self.userGuideName + "_" + self.langDic[self.langName]['c046_holder'] + "_Geo", constructionHistory=False)[0] cmds.delete( cmds.parentConstraint(self.cvCenterLoc, self.geoHolder, maintainOffset=False)) cmds.setAttr(self.geoHolder + ".visibility", 0, lock=True) # skinning: cmds.skinCluster(self.centerJoint, self.geoHolder, toSelectedBones=True, dropoffRate=4.0, maximumInfluences=3, skinMethod=0, normalizeWeights=1, removeUnusedInfluence=False, name=side + self.userGuideName + "_" + self.langDic[self.langName]['c046_holder'] + "_SC") if self.loadedGeo: if cmds.objExists(self.loadedGeo): baseName = utils.extractSuffix(self.loadedGeo) skinClusterName = baseName + "_SC" if "|" in skinClusterName: skinClusterName = skinClusterName[skinClusterName. rfind("|") + 1:] try: cmds.skinCluster(self.centerJoint, self.loadedGeo, toSelectedBones=True, dropoffRate=4.0, maximumInfluences=3, skinMethod=0, normalizeWeights=1, removeUnusedInfluence=False, name=skinClusterName) except: childList = cmds.listRelatives(self.loadedGeo, children=True, allDescendents=True) if childList: for item in childList: itemType = cmds.objectType(item) if itemType == "mesh" or itemType == "nurbsSurface": try: skinClusterName = utils.extractSuffix( item) + "_SC" cmds.skinCluster( self.centerJoint, item, toSelectedBones=True, dropoffRate=4.0, maximumInfluences=3, skinMethod=0, normalizeWeights=1, removeUnusedInfluence=False, name=skinClusterName) except: pass # lattice: latticeList = cmds.lattice(self.geoHolder, divisions=(6, 6, 6), outsideLattice=2, outsideFalloffDistance=1, position=(0, 0, 0), scale=(self.ctrlRadius * 2, self.ctrlRadius * 2, self.ctrlRadius * 2), name=side + self.userGuideName + "_FFD") #[deformer, lattice, base] cmds.scale(self.ctrlRadius * 2, self.ctrlRadius * 2, self.ctrlRadius * 2, latticeList[2]) # clusters: upperClusterList = cmds.cluster( latticeList[1] + ".pt[0:5][4:5][0:5]", relative=True, name=side + self.userGuideName + "_" + self.langDic[self.langName]['c044_upper'] + "_Cls") #[deform, handle] middleClusterList = cmds.cluster( latticeList[1] + ".pt[0:5][2:3][0:5]", relative=True, name=side + self.userGuideName + "_" + self.langDic[self.langName]['m033_middle'] + "_Cls") #[deform, handle] lowerClusterList = cmds.cluster( latticeList[1] + ".pt[0:5][0:1][0:5]", relative=True, name=side + self.userGuideName + "_" + self.langDic[self.langName]['c045_lower'] + "_Cls") #[deform, handle] clusterGrpList = utils.zeroOut([ upperClusterList[1], middleClusterList[1], lowerClusterList[1] ]) clustersGrp = cmds.group(clusterGrpList, name=side + self.userGuideName + "_Clusters_Grp") # deform controls: upperDefCtrl = self.ctrls.cvControl( "id_063_WheelDeform", side + self.userGuideName + "_" + self.langDic[self.langName]['c044_upper'] + "_Ctrl", r=self.ctrlRadius * 0.5, d=self.curveDegree) middleDefCtrl = self.ctrls.cvControl( "id_064_WheelMiddle", side + self.userGuideName + "_" + self.langDic[self.langName]['m033_middle'] + "_Ctrl", r=self.ctrlRadius * 0.5, d=self.curveDegree) lowerDefCtrl = self.ctrls.cvControl( "id_063_WheelDeform", side + self.userGuideName + "_" + self.langDic[self.langName]['c045_lower'] + "_Ctrl", r=self.ctrlRadius * 0.5, d=self.curveDegree, rot=(0, 0, 180)) defCtrlGrpList = utils.zeroOut( [upperDefCtrl, middleDefCtrl, lowerDefCtrl]) defCtrlGrp = cmds.group(defCtrlGrpList, name=side + self.userGuideName + "_Ctrl_Grp") # positions: cmds.delete( cmds.parentConstraint(upperClusterList[1], defCtrlGrpList[0], maintainOffset=False)) cmds.delete( cmds.parentConstraint(middleClusterList[1], defCtrlGrpList[1], maintainOffset=False)) cmds.delete( cmds.parentConstraint(lowerClusterList[1], defCtrlGrpList[2], maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, latticeList[1], maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, latticeList[2], maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, clustersGrp, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvCenterLoc, defCtrlGrp, maintainOffset=False)) outsideDist = cmds.getAttr(self.cvOutsideLoc + ".tz") if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: outsideDist = -outsideDist cmds.move(outsideDist, defCtrlGrp, moveZ=True, relative=True, objectSpace=True, worldSpaceDistance=True) self.ctrls.directConnect(upperDefCtrl, upperClusterList[1]) self.ctrls.directConnect(middleDefCtrl, middleClusterList[1]) self.ctrls.directConnect(lowerDefCtrl, lowerClusterList[1]) # grouping deformers: if self.loadedGeo: if cmds.objExists(self.loadedGeo): cmds.lattice(latticeList[0], edit=True, geometry=self.loadedGeo) defGrp = cmds.group(latticeList[1], latticeList[2], clustersGrp, name=side + self.userGuideName + "_Deform_Grp") cmds.parentConstraint(self.mainCtrl, defGrp, maintainOffset=True, name=defGrp + "_ParentConstraint") cmds.scaleConstraint(self.mainCtrl, defGrp, maintainOffset=True, name=defGrp + "_ScaleConstraint") cmds.parent(defCtrlGrp, self.mainCtrl) cmds.connectAttr( self.wheelCtrl + "." + self.langDic[self.langName]['c021_showControls'], defCtrlGrp + ".visibility", force=True) # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( zeroGrpList[2], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( self.centerJoint, defGrp, name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, self.oldLoc, self.wheelAutoGrpLoc, self.geoHolder, name=side + self.userGuideName + "_Grp") # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) self.ctrlHookGrpList.append(self.toCtrlHookGrp) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side + self.userGuideName + '_Guide_Base' # get the number of joints to be created: self.nJoints = cmds.getAttr(self.base + ".nJoints") for n in range(1, self.nJoints + 1): cmds.select(clear=True) # declare guide: self.guide = side + self.userGuideName + "_Guide_JointLoc" + str( n) # create a joint: self.jnt = cmds.joint(name=side + self.userGuideName + "_" + str(n) + "_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) # joint labelling: utils.setJointLabel(self.jnt, s + jointLabelAdd, 18, self.userGuideName + "_" + str(n)) # create a control: # self.mainCtrl = cmds.circle(name=side+self.userGuideName+"_"+str(n)+"_Ctrl", degree=1, normal=(0, 0, 1), r=self.ctrlRadius, s=6, ch=False)[0] self.mainCtrl = self.ctrls.cvControl( "id_007_FkLine", side + self.userGuideName + "_" + str(n) + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree) if n == 1: utils.originedFrom(objName=self.mainCtrl, attrString=self.base + ";" + self.guide) else: utils.originedFrom(objName=self.mainCtrl, attrString=self.guide) # position and orientation of joint and control: cmds.delete( cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.guide, self.mainCtrl, maintainOffset=False)) # zeroOut controls: zeroOutCtrlGrp = utils.zeroOut([self.mainCtrl])[0] # hide visibility attribute: cmds.setAttr(self.mainCtrl + '.visibility', keyable=False) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr(zeroOutCtrlGrp + ".scaleX", -1) cmds.setAttr(zeroOutCtrlGrp + ".scaleY", -1) cmds.setAttr(zeroOutCtrlGrp + ".scaleZ", -1) cmds.addAttr(self.mainCtrl, longName='scaleCompensate', attributeType="bool", keyable=False) cmds.setAttr(self.mainCtrl + ".scaleCompensate", 1, channelBox=True) cmds.connectAttr(self.mainCtrl + ".scaleCompensate", self.jnt + ".segmentScaleCompensate", force=True) if n == self.nJoints: # create end joint: cmds.select(self.jnt) self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" self.endJoint = cmds.joint( name=side + self.userGuideName + "_JEnd") cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) # grouping: for n in range(1, self.nJoints + 1): self.jnt = side + self.userGuideName + "_" + str( n) + "_Jnt" self.mainCtrl = side + self.userGuideName + "_" + str( n) + "_Ctrl" self.zeroCtrl = side + self.userGuideName + "_" + str( n) + "_Ctrl_Zero_Grp" if n > 1: # parent joints as a simple chain (line) self.fatherJnt = side + self.userGuideName + "_" + str( n - 1) + "_Jnt" cmds.parent(self.jnt, self.fatherJnt, absolute=True) # parent zeroCtrl Group to the before mainCtrl: self.fatherCtrl = side + self.userGuideName + "_" + str( n - 1) + "_Ctrl" cmds.parent(self.zeroCtrl, self.fatherCtrl, absolute=True) # create parentConstraint from mainCtrl to jnt: cmds.parentConstraint(self.mainCtrl, self.jnt, maintainOffset=False, name=self.jnt + "_ParentConstraint") # create scaleConstraint from mainCtrl to jnt: cmds.scaleConstraint(self.mainCtrl, self.jnt, maintainOffset=True, name=self.jnt + "_ScaleConstraint") # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( side + self.userGuideName + "_1_Ctrl_Zero_Grp", name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( side + self.userGuideName + "_1_Jnt", name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) self.ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # declare lists to store names and attributes: self.steeringCtrlList = [] # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp + ".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp + ".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0] + '_', self.mirrorNames[len(self.mirrorNames) - 1] + '_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate( self.moduleGrp, name=side + self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side + self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side + self.userGuideName + '_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename( self.mirrorGrp, side + self.userGuideName + '_' + self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr( side + self.userGuideName + "_Guide_Base.translate" + axis) flipedValue = gotValue * (-2) cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.translate' + axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr( side + self.userGuideName + '_' + self.mirrorGrp + '.scale' + axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName + '_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName + "_" + item) self.mirrorGrp = cmds.group(self.userGuideName + '_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName + '_' + self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # run for all sides for s, side in enumerate(sideList): self.base = side + self.userGuideName + '_Guide_Base' cmds.select(clear=True) # declare guide: self.guide = side + self.userGuideName + "_Guide_JointLoc1" self.cvEndJoint = side + self.userGuideName + "_Guide_JointEnd" self.radiusGuide = side + self.userGuideName + "_Guide_Base_RadiusCtrl" # create a joint: self.jnt = cmds.joint(name=side + self.userGuideName + "_1_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) self.endJoint = cmds.joint(name=side + self.userGuideName + "_JEnd", radius=0.5) # joint labelling: utils.setJointLabel(self.jnt, s + jointLabelAdd, 18, self.userGuideName + "_1") # create a control: self.steeringCtrl = self.ctrls.cvControl( "id_065_SteeringWheel", side + self.userGuideName + "_" + self.langDic[self.langName]['m158_steering'] + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree) self.mainCtrl = self.ctrls.cvControl( "id_066_SteeringMain", side + self.userGuideName + "_" + self.langDic[self.langName]['c058_main'] + "_Ctrl", r=self.ctrlRadius, d=self.curveDegree) utils.originedFrom(objName=self.steeringCtrl, attrString=self.guide) utils.originedFrom(objName=self.mainCtrl, attrString=self.base + ";" + self.cvEndJoint + ";" + self.radiusGuide) self.steeringCtrlList.append(self.steeringCtrl) # position and orientation of joint and control: cmds.delete( cmds.parentConstraint(self.guide, self.jnt, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.guide, self.steeringCtrl, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.mainCtrl, maintainOffset=False)) cmds.delete( cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) cmds.setAttr(self.endJoint + ".translateY", 1) # zeroOut controls: zeroOutCtrlGrpList = utils.zeroOut( [self.steeringCtrl, self.mainCtrl]) # hide visibility attribute: self.ctrls.setLockHide( [self.steeringCtrl], ['tx', 'ty', 'tz', 'rx', 'ry', 'sx', 'sy', 'sz', 'v']) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp + ".flip") == 1: cmds.setAttr(zeroOutCtrlGrpList[0] + ".scaleX", -1) cmds.setAttr(zeroOutCtrlGrpList[0] + ".scaleY", -1) cmds.setAttr(zeroOutCtrlGrpList[0] + ".scaleZ", -1) cmds.addAttr(self.steeringCtrl, longName='scaleCompensate', attributeType="bool", keyable=False) cmds.setAttr(self.steeringCtrl + ".scaleCompensate", 1, channelBox=True) cmds.connectAttr(self.steeringCtrl + ".scaleCompensate", self.jnt + ".segmentScaleCompensate", force=True) # integrating setup: cmds.addAttr( self.steeringCtrl, longName=self.langDic[self.langName]['c071_limit'], defaultValue=500, attributeType="float", keyable=False) cmds.addAttr( self.steeringCtrl, longName=self.langDic[self.langName]['c049_intensity'], min=0, defaultValue=0.8, attributeType="float", keyable=False) cmds.addAttr( self.steeringCtrl, longName=self.langDic[self.langName]['c070_steering'], attributeType="float", keyable=False) cmds.setAttr(self.steeringCtrl + "." + self.langDic[self.langName]['c071_limit'], 500, channelBox=True) cmds.setAttr(self.steeringCtrl + "." + self.langDic[self.langName]['c049_intensity'], 0.8, channelBox=True) self.steeringUnitMD = cmds.createNode( 'multiplyDivide', name=side + self.userGuideName + "_Unit_MD") self.steeringInvertMD = cmds.createNode( 'multiplyDivide', name=side + self.userGuideName + "_Rotate_MD") self.steeringMD = cmds.createNode('multiplyDivide', name=side + self.userGuideName + "_MD") cmds.setAttr(self.steeringInvertMD + ".input2X", 0.1) cmds.setAttr(self.steeringUnitMD + ".input2X", -1) cmds.transformLimits(self.steeringCtrl, enableRotationZ=(1, 1)) cmds.connectAttr(self.steeringCtrl + "." + self.langDic[self.langName]['c071_limit'], self.steeringUnitMD + ".input1X", force=True) cmds.connectAttr(self.steeringUnitMD + ".outputX", self.steeringCtrl + ".minRotLimit.minRotZLimit", force=True) cmds.connectAttr(self.steeringCtrl + "." + self.langDic[self.langName]['c071_limit'], self.steeringCtrl + ".maxRotLimit.maxRotZLimit", force=True) cmds.connectAttr(self.steeringCtrl + ".rotateZ", self.steeringInvertMD + ".input1X", force=True) cmds.connectAttr(self.steeringInvertMD + ".outputX", self.steeringMD + ".input1X", force=True) cmds.connectAttr(self.steeringCtrl + "." + self.langDic[self.langName]['c049_intensity'], self.steeringMD + ".input2X", force=True) cmds.connectAttr(self.steeringMD + ".outputX", self.steeringCtrl + "." + self.langDic[self.langName]['c070_steering'], force=True) # grouping: cmds.parent(zeroOutCtrlGrpList[0], self.mainCtrl) # create parentConstraint from steeringCtrl to jnt: cmds.parentConstraint(self.steeringCtrl, self.jnt, maintainOffset=False, name=self.jnt + "_PaC") # create scaleConstraint from steeringCtrl to jnt: cmds.scaleConstraint(self.steeringCtrl, self.jnt, maintainOffset=True, name=self.jnt + "_ScC") # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group( zeroOutCtrlGrpList[1], name=side + self.userGuideName + "_Control_Grp") self.toScalableHookGrp = cmds.group( side + self.userGuideName + "_1_Jnt", name=side + self.userGuideName + "_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side + self.userGuideName + "_Grp") # create a locator in order to avoid delete static group loc = cmds.spaceLocator(name=side + self.userGuideName + "_DO_NOT_DELETE_PLEASE_Loc")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc + ".visibility", 0) self.ctrls.setLockHide([loc], [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ]) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp + ".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp + '.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp + ".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side + self.userGuideName + '_' + self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()
def rigModule(self, *args): Base.StartClass.rigModule(self) # verify if the guide exists: if cmds.objExists(self.moduleGrp): try: hideJoints = cmds.checkBox('hideJointsCB', query=True, value=True) except: hideJoints = 1 # start as no having mirror: sideList = [""] # analisys the mirror module: self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis") if self.mirrorAxis != 'off': # get rigs names: self.mirrorNames = cmds.getAttr(self.moduleGrp+".mirrorName") # get first and last letters to use as side initials (prefix): sideList = [ self.mirrorNames[0]+'_', self.mirrorNames[len(self.mirrorNames)-1]+'_' ] for s, side in enumerate(sideList): duplicated = cmds.duplicate(self.moduleGrp, name=side+self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, side+self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(name="Guide_Base_Grp", empty=True) cmds.parent(side+self.userGuideName+'_Guide_Base', self.mirrorGrp, absolute=True) # re-rename grp: cmds.rename(self.mirrorGrp, side+self.userGuideName+'_'+self.mirrorGrp) # do a group mirror with negative scaling: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 0: for axis in self.mirrorAxis: gotValue = cmds.getAttr(side+self.userGuideName+"_Guide_Base.translate"+axis) flipedValue = gotValue*(-2) cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.translate'+axis, flipedValue) else: for axis in self.mirrorAxis: cmds.setAttr(side+self.userGuideName+'_'+self.mirrorGrp+'.scale'+axis, -1) # joint labelling: jointLabelAdd = 1 else: # if not mirror: duplicated = cmds.duplicate(self.moduleGrp, name=self.userGuideName+'_Guide_Base')[0] allGuideList = cmds.listRelatives(duplicated, allDescendents=True) for item in allGuideList: cmds.rename(item, self.userGuideName+"_"+item) self.mirrorGrp = cmds.group(self.userGuideName+'_Guide_Base', name="Guide_Base_Grp", relative=True) #for Maya2012: self.userGuideName+'_'+self.moduleGrp+"_Grp" # re-rename grp: cmds.rename(self.mirrorGrp, self.userGuideName+'_'+self.mirrorGrp) # joint labelling: jointLabelAdd = 0 # store the number of this guide by module type: dpAR_count = utils.findModuleLastNumber(CLASS_NAME, "dpAR_type") + 1 # create lists to export: self.eyeScaleGrpList, self.irisCtrlList, self.pupilCtrlList = [], [], [] self.hasIris = False self.hasPupil = False # create the main control: self.eyeCtrl = self.ctrls.cvControl("id_010_EyeLookAtMain", self.userGuideName+"_A_Ctrl", r=(2.25*self.ctrlRadius), d=self.curveDegree) cmds.addAttr(self.eyeCtrl, longName=self.langDic[self.langName]['c032_follow'], attributeType='float', keyable=True, minValue=0, maxValue=1) cmds.setAttr(self.eyeCtrl+"."+self.langDic[self.langName]['c032_follow'], 1) cmds.delete(cmds.parentConstraint(sideList[0]+self.userGuideName+"_Guide_JointEnd", self.eyeCtrl, maintainOffset=False)) if self.mirrorAxis != 'off': cmds.setAttr(self.eyeCtrl+".translate"+self.mirrorAxis, 0) self.eyeGrp = cmds.group(self.eyeCtrl, name=self.userGuideName+"_A_Grp") utils.zeroOut([self.eyeCtrl]) self.upLocGrp = cmds.group(name=self.userGuideName+"_UpLoc_Grp", empty=True) # run for all sides: for s, side in enumerate(sideList): cmds.select(clear=True) self.base = side+self.userGuideName+'_Guide_Base' # declare guide: self.guide = side+self.userGuideName+"_Guide_JointLoc1" self.cvEndJointZero = side+self.userGuideName+"_Guide_JointEnd_Grp" # create a joint: self.jxt = cmds.joint(name=side+self.userGuideName+"_1_Jxt", scaleCompensate=False) self.jnt = cmds.joint(name=side+self.userGuideName+"_1_Jnt", scaleCompensate=False) cmds.addAttr(self.jnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(self.jnt, s+jointLabelAdd, 18, self.userGuideName+"_1") self.fkEyeCtrl = self.ctrls.cvControl("id_014_EyeFk", side+self.userGuideName+"_Fk_Ctrl", r=self.ctrlRadius, d=self.curveDegree) utils.originedFrom(objName=self.fkEyeCtrl, attrString=self.base+";"+self.guide) self.baseEyeCtrl = self.ctrls.cvControl("id_009_EyeBase", ctrlName=side+self.userGuideName+"_Base_Ctrl", r=self.ctrlRadius, d=self.curveDegree) utils.originedFrom(objName=self.baseEyeCtrl, attrString=self.base+";"+self.guide) # position and orientation of joint and control: cmds.delete(cmds.pointConstraint(self.guide, self.jxt, maintainOffset=False)) cmds.delete(cmds.orientConstraint(self.cvEndJointZero, self.jxt, maintainOffset=False)) cmds.delete(cmds.pointConstraint(self.guide, self.fkEyeCtrl, maintainOffset=False)) cmds.delete(cmds.orientConstraint(self.cvEndJointZero, self.fkEyeCtrl, maintainOffset=False)) cmds.delete(cmds.parentConstraint(self.guide, self.baseEyeCtrl, maintainOffset=False)) # zeroOut controls: eyeZeroList = utils.zeroOut([self.baseEyeCtrl, self.fkEyeCtrl]) # fixing flip mirror: if s == 1: if cmds.getAttr(self.moduleGrp+".flip") == 1: cmds.setAttr(eyeZeroList[0]+".scaleX", -1) cmds.setAttr(eyeZeroList[0]+".scaleY", -1) cmds.setAttr(eyeZeroList[0]+".scaleZ", -1) cmds.parent(eyeZeroList[1], self.baseEyeCtrl) # hide visibility attribute: cmds.setAttr(self.fkEyeCtrl+'.visibility', keyable=False) self.ctrls.setLockHide([self.fkEyeCtrl], ['tx', 'ty', 'tz']) # create end joint: self.cvEndJoint = side+self.userGuideName+"_Guide_JointEnd" self.endJoint = cmds.joint(name=side+self.userGuideName+"_JEnd") cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.endJoint, maintainOffset=False)) cmds.parent(self.endJoint, self.jnt, absolute=True) # create parentConstraint from ctrl to jxt: cmds.parentConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=False, name=self.jnt+"_ParentConstraint") # create scaleConstraint from ctrl to jnt: cmds.scaleConstraint(self.fkEyeCtrl, self.jxt, maintainOffset=True, name=self.jnt+"_ScaleConstraint") # lookAt control: self.lookAtCtrl = self.ctrls.cvControl("id_011_EyeLookAt", side+self.userGuideName+"_LookAt_Ctrl", r=self.ctrlRadius, d=self.curveDegree) cmds.delete(cmds.parentConstraint(self.cvEndJoint, self.lookAtCtrl, maintainOffset=False)) cmds.parent(self.lookAtCtrl, self.eyeCtrl, relative=False) cmds.makeIdentity(self.lookAtCtrl, apply=True) cmds.addAttr(self.lookAtCtrl, longName="active", attributeType="bool", defaultValue=1, keyable=True) # up locator: self.cvUpLocGuide = side+self.userGuideName+"_Guide_JointEnd_UpLoc" self.lUpGrpLoc = cmds.group(name=side+self.userGuideName+"_Up_Loc_Grp", empty=True) cmds.delete(cmds.pointConstraint(self.jnt, self.lUpGrpLoc, maintainOffset=False)) cmds.delete(cmds.orientConstraint(self.cvEndJointZero, self.lUpGrpLoc, maintainOffset=False)) self.lUpLoc = cmds.spaceLocator(name=side+self.userGuideName+"_Up_Loc")[0] cmds.delete(cmds.parentConstraint(self.cvUpLocGuide, self.lUpLoc, maintainOffset=False)) cmds.parent(self.lUpLoc, self.lUpGrpLoc, relative=False) cmds.parent(self.lUpGrpLoc, self.upLocGrp, relative=False) # look at aim constraint: aimConst = cmds.aimConstraint(self.lookAtCtrl, eyeZeroList[1], worldUpType="object", worldUpObject=self.upLocGrp+"|"+self.lUpGrpLoc+"|"+self.lUpLoc, maintainOffset=True, name=self.fkEyeCtrl+"_Zero"+"_AimConstraint")[0] cmds.connectAttr(self.lookAtCtrl+".active", aimConst+"."+self.lookAtCtrl+"W0", force=True) # eye aim rotation cmds.addAttr(self.fkEyeCtrl, longName="aimRotation", attributeType="float", keyable=True) cmds.connectAttr(self.fkEyeCtrl+".aimRotation", self.jnt+".rotateZ", force=True) cmds.pointConstraint(self.baseEyeCtrl, self.lUpGrpLoc, maintainOffset=True, name=self.lUpGrpLoc+"_PointConstraint") # create eyeScale setup: cmds.select(clear=True) self.eyeScaleJnt = cmds.joint(name=side+self.userGuideName+"Scale_1_Jnt", scaleCompensate=False) cmds.addAttr(self.eyeScaleJnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(self.eyeScaleJnt, s+jointLabelAdd, 18, self.userGuideName+"Scale_1") # jointScale position: cmds.delete(cmds.parentConstraint(self.guide, self.eyeScaleJnt, maintainOffset=False)) # create endScale joint: self.endScaleJoint = cmds.joint(name=side+self.userGuideName+"Scale_JEnd") cmds.delete(cmds.parentConstraint(self.eyeScaleJnt, self.endScaleJoint, maintainOffset=False)) cmds.setAttr(self.endScaleJoint+".translateZ", 1) # create constraints to eyeScale: cmds.pointConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=False, name=self.eyeScaleJnt+"_PointConstraint") cmds.orientConstraint(self.baseEyeCtrl, self.eyeScaleJnt, maintainOffset=False, name=self.eyeScaleJnt+"_OrientConstraint") cmds.scaleConstraint(self.jnt, self.eyeScaleJnt, maintainOffset=True, name=self.eyeScaleJnt+"_ScaleConstraint") self.eyeScaleGrp = cmds.group(self.eyeScaleJnt, name=self.eyeScaleJnt+"_Grp") self.eyeScaleGrpList.append(self.eyeScaleGrp) # create eyelid setup: if self.getModuleAttr(EYELID): # declare eyelid guides: self.cvUpperEyelidLoc = side+self.userGuideName+"_Guide_UpperEyelidLoc" self.cvLowerEyelidLoc = side+self.userGuideName+"_Guide_LowerEyelidLoc" # creating eyelids joints: cmds.select(clear=True) self.eyelidJxt = cmds.joint(name=side+self.userGuideName+"_"+self.langDic[self.langName]['c042_eyelid']+"_Jxt", scaleCompensate=False) cmds.delete(cmds.parentConstraint(self.guide, self.eyelidJxt, mo=False)) cmds.parent(self.eyelidJxt, self.eyeScaleJnt) self.upperEyelidBaseJxt, self.upperEyelidJnt = self.createEyelidJoints(side, 'c044_upper', "", self.cvUpperEyelidLoc, s+jointLabelAdd) self.upperEyelidMiddleBaseJxt, self.upperEyelidMiddleJnt = self.createEyelidJoints(side, 'c044_upper', self.langDic[self.langName]['c029_middle'], self.cvUpperEyelidLoc, s+jointLabelAdd) self.lowerEyelidBaseJxt, self.lowerEyelidJnt = self.createEyelidJoints(side, 'c045_lower', "", self.cvLowerEyelidLoc, s+jointLabelAdd) self.lowerEyelidMiddleBaseJxt, self.lowerEyelidMiddleJnt = self.createEyelidJoints(side, 'c045_lower', self.langDic[self.langName]['c029_middle'], self.cvLowerEyelidLoc, s+jointLabelAdd) # creating eyelids controls and setup: self.upperEyelidCtrl, self.upperEyelidCtrlZero = self.createEyelidSetup(side, 'c044_upper', self.upperEyelidJnt, self.upperEyelidBaseJxt, self.upperEyelidMiddleBaseJxt, self.upperEyelidMiddleJnt, 30, (0, 0, 0)) self.lowerEyelidCtrl, self.lowerEyelidCtrlZero = self.createEyelidSetup(side, 'c045_lower', self.lowerEyelidJnt, self.lowerEyelidBaseJxt, self.lowerEyelidMiddleBaseJxt, self.lowerEyelidMiddleJnt, 30, (0, 0, 180)) # fixing mirror behavior for side controls: if s == 0: #left cmds.setAttr(self.upperEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"X", 1) cmds.setAttr(self.upperEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"Y", 1) cmds.setAttr(self.lowerEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"Y", 1) else: #right if cmds.getAttr(self.moduleGrp+".flip") == 0: cmds.setAttr(self.upperEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"Y", 1) cmds.setAttr(self.lowerEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"X", 1) cmds.setAttr(self.lowerEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"Y", 1) cmds.setAttr(self.upperEyelidCtrlZero+".rotateY", 180) cmds.setAttr(self.lowerEyelidCtrlZero+".rotateY", 180) else: cmds.setAttr(self.lowerEyelidCtrl+"."+self.langDic[self.langName]['c053_invert']+"X", 1) # create iris setup: if self.getModuleAttr(IRIS): self.irisCtrl = self.createIrisPupilSetup(s, side, IRIS, 'i080_iris', 12, s+jointLabelAdd) self.irisCtrlList.append(self.irisCtrl) self.hasIris = True # create pupil setup: if self.getModuleAttr(PUPIL): self.pupilCtrl = self.createIrisPupilSetup(s, side, PUPIL, 'i081_pupil', 4, s+jointLabelAdd) self.pupilCtrlList.append(self.pupilCtrl) self.hasPupil = True # create a masterModuleGrp to be checked if this rig exists: self.toCtrlHookGrp = cmds.group(eyeZeroList[0], name=side+self.userGuideName+"_Control_Grp") self.toScalableHookGrp = cmds.group(self.jxt, self.eyeScaleGrp, name=side+self.userGuideName+"_Joint_Grp") self.toStaticHookGrp = cmds.group(self.toCtrlHookGrp, self.toScalableHookGrp, name=side+self.userGuideName+"_Grp") if s == 0: cmds.parent(self.eyeGrp, self.toCtrlHookGrp) cmds.parent(self.upLocGrp, self.toScalableHookGrp) # create a locator in order to avoid delete static group: loc = cmds.spaceLocator(name=side+self.userGuideName+"_DO_NOT_DELETE")[0] cmds.parent(loc, self.toStaticHookGrp, absolute=True) cmds.setAttr(loc+".visibility", 0) self.ctrls.setLockHide([loc], ['tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v']) # add hook attributes to be read when rigging integrated modules: utils.addHook(objName=self.toCtrlHookGrp, hookType='ctrlHook') utils.addHook(objName=self.toScalableHookGrp, hookType='scalableHook') utils.addHook(objName=self.toStaticHookGrp, hookType='staticHook') cmds.addAttr(self.toStaticHookGrp, longName="dpAR_name", dataType="string") cmds.addAttr(self.toStaticHookGrp, longName="dpAR_type", dataType="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_name", self.userGuideName, type="string") cmds.setAttr(self.toStaticHookGrp+".dpAR_type", CLASS_NAME, type="string") # add module type counter value cmds.addAttr(self.toStaticHookGrp, longName='dpAR_count', attributeType='long', keyable=False) cmds.setAttr(self.toStaticHookGrp+'.dpAR_count', dpAR_count) if hideJoints: cmds.setAttr(self.toScalableHookGrp+".visibility", 0) # delete duplicated group for side (mirror): cmds.delete(side+self.userGuideName+'_'+self.mirrorGrp) # finalize this rig: self.integratingInfo() cmds.select(clear=True) # delete UI (moduleLayout), GUIDE and moduleInstance namespace: self.deleteModule()