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.hipsAList, self.chestAList, self.volumeVariationAttrList = [], [], [] # 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.hipsAList.append(self.hipsA) self.chestAList.append(self.chestA) self.volumeVariationAttrList.append( side + self.userGuideName + "_" + self.langDic[self.langName]["c_volumeVariation"] ) # 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] rbnJointList = 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: self.clustersGrp = cmds.group(name=side + self.userGuideName + "_Rbn_Clusters_Grp", empty=True) if hideJoints: cmds.setAttr(self.clustersGrp + ".visibility", 0) cmds.parent(downCluster, upCluster, self.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(self.clustersGrp, scaleGrp, maintainOffset=True, name=rbnJntGrp + "_Scale") else: cmds.scaleConstraint( self.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] 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, self.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", rbnJointList[n] + ".scaleX") cmds.connectAttr(rbnBlendColors + ".outputR", rbnJointList[n] + ".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( self.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=self.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()