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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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()