Exemplo n.º 1
0
    def makeHand(self, leftRight, jntsHand, jntArmEnd, jntPalm, colourTU,
                 fkColour, ikColour, ctrlFKIK, ctrlFKIKAttr, isLeft, checkGeo,
                 geoJntArray, *args):
        # Creating the Palm Control
        jntPalmBase = jntPalm[0]
        jntFingers, jntFingersUnsorted = self.getFingers(jntsHand)

        handOffsetCtrl = self.createPalmCtrls(jntPalmBase, leftRight, colourTU,
                                              jntPalm, isLeft)

        # Attaching the hand to the arm
        grpConPalm, conLocFKOffsetCtrl, conLocIKOffsetCtrl = self.attachHandToArm(
            leftRight,
            fkColour,
            ikColour,
            handOffsetCtrl,
            jntArmEnd,
            ctrlFKIK,
            ctrlFKIKAttr,
        )

        # Create the finger controls.
        # parent the finger offsets under the hands controls. We don't need to do so for the joints since we already assume it to be the case.
        fkFingerOffsetCtrls = self.createFingerFKs(jntFingers, colourTU,
                                                   isLeft)
        for i in range(len(fkFingerOffsetCtrls)):
            mc.parent(fkFingerOffsetCtrls[i][0][0], handOffsetCtrl[1])
        # clean up the outliner
        self.handCleanUp(handOffsetCtrl, fkFingerOffsetCtrls, leftRight,
                         jntPalmBase, jntPalm, jntFingersUnsorted, grpConPalm,
                         conLocFKOffsetCtrl, conLocIKOffsetCtrl)

        if checkGeo:
            CRU.tgpSetGeo(geoJntArray, setLayer=True)
Exemplo n.º 2
0
    def tgpMakeBC(self, *args):
        checkGeo = mc.checkBox("selGeo_cb", q=True, v=True)
        checkboxSpine = mc.checkBox("selSpineEnd_cb", q=True, v=True)
        if checkboxSpine:
            ctrlIKChest = mc.textFieldButtonGrp("ctrlIKChestLoad_tf",
                                                q=True,
                                                text=True)
            grpJntSpine = mc.textFieldButtonGrp("grpJNTSpine_tfbg",
                                                q=True,
                                                text=True)
            ctrlCOG = mc.textFieldButtonGrp("cog_tfbg", q=True, text=True)

        self.jntNames = mc.textFieldButtonGrp("jointLoad_tfbg",
                                              q=True,
                                              text=True)

        # make sure the selections are not empty
        checkList = [self.jntNames]

        eyeArray = [x for x in self.jointArray if "eye" in x]

        # gets us most of the geos
        jntArrayNoEnd = [x for x in self.jointArray if "End" not in x]

        if ((checkList[0] == "")):
            mc.warning("You are missing a selection!")
            return
        else:
            if "neck1" not in checkList[0]:
                mc.warning("Make the first selection the root neck joint")
                return

            # CRU.createLocatorToDelete()
            # create the IK base controls
            # Creating the Neck and Head Controls.

            headOffsetCtrls = self.createNeckHeadCtrls(ctrlIKChest,
                                                       grpJntSpine,
                                                       checkboxSpine)

            headCtrl, eyeCtrlArray, eyesCtrl, grpWorldFollow = self.createEyeControls(
                eyeArray, headOffsetCtrls)

            if checkboxSpine:
                self.createSpaceSwitching(
                    headCtrl,
                    headOffsetCtrls,
                    ctrlIKChest,
                    ctrlCOG,
                    grpWorldFollow,
                )

            self.neckCleanUp(headOffsetCtrls, eyeCtrlArray, eyesCtrl)

            if checkGeo:
                CRU.tgpSetGeo(jntArrayNoEnd, setLayer=True)
    def makeToes(self, jntBall, jntMasterToes, ctrlToes, grpLegs,
                 jntAnkleTwist, leftRight, colourTU, isLeft, checkGeo, *args):

        toesJnts = mc.listRelatives(jntMasterToes,
                                    ad=True,
                                    s=False,
                                    type="joint")
        toesJnts.reverse()

        # Create the toe controls

        # TIMRP = Thumb, Index, Middle, Ring, Pinkie
        jntThumb = [
            x for x in toesJnts if ("thumb" in x.lower()) and "JNT" in x
        ]
        jntIndex = [
            x for x in toesJnts if ("index" in x.lower()) and "JNT" in x
        ]
        jntMiddle = [
            x for x in toesJnts if ("middle" in x.lower()) and "JNT" in x
        ]
        jntRing = [x for x in toesJnts if ("ring" in x.lower()) and "JNT" in x]
        jntPink = [x for x in toesJnts if ("pink" in x.lower()) and "JNT" in x]
        JNTTIMRP = [jntThumb, jntIndex, jntMiddle, jntRing, jntPink]

        fkJntOffsetCtrls = self.createToeFKs(JNTTIMRP, colourTU, isLeft)

        # Organize the toes
        grpCtrlFoot = self.parentToes(jntBall, jntMasterToes, fkJntOffsetCtrls,
                                      leftRight)
        toesAutoCtrlSetup = mc.listRelatives(grpCtrlFoot,
                                             ad=True,
                                             s=False,
                                             type="transform")

        toesAutoCtrlSetup.reverse()

        ctrlToesKids = mc.listRelatives(ctrlToes, c=True, type="transform")
        ctrlArrayToes = [x for x in ctrlToesKids if ("toes" not in x.lower())]

        ctrlThumb = [x for x in ctrlToesKids if ("thumb" in x.lower())][0]
        ctrlIndex = [x for x in ctrlToesKids if ("index" in x.lower())][0]
        ctrlMiddle = [x for x in ctrlToesKids if ("middle" in x.lower())][0]
        ctrlRing = [x for x in ctrlToesKids if ("ring" in x.lower())][0]
        ctrlPink = [x for x in ctrlToesKids if ("pink" in x.lower())][0]

        ctrlTIMRP = [ctrlThumb, ctrlIndex, ctrlMiddle, ctrlRing, ctrlPink]

        autoThumb = [
            x for x in toesAutoCtrlSetup
            if ("thumb" in x.lower()) and "AUTO" in x
        ]
        autoIndex = [
            x for x in toesAutoCtrlSetup
            if ("index" in x.lower()) and "AUTO" in x
        ]
        autoMiddle = [
            x for x in toesAutoCtrlSetup
            if ("middle" in x.lower()) and "AUTO" in x
        ]
        autoRing = [
            x for x in toesAutoCtrlSetup
            if ("ring" in x.lower()) and "AUTO" in x
        ]
        autoPink = [
            x for x in toesAutoCtrlSetup
            if ("pink" in x.lower()) and "AUTO" in x
        ]

        autoTIMRP = [autoThumb, autoIndex, autoMiddle, autoRing, autoPink]

        toeAttr = ["curl", "scrunch", "spread"]
        footAttr = list(toeAttr)

        footAttr.append("relax")
        valsMinMaxDef = [-10, 10, 0]

        # add the toes control attributes
        for i in range(len(footAttr)):
            mc.addAttr(ctrlToes,
                       longName=footAttr[i],
                       at="float",
                       k=True,
                       min=valsMinMaxDef[0],
                       max=valsMinMaxDef[1],
                       dv=valsMinMaxDef[2])

        # add the toes control attributes for the individual toes
        for i in range(len(toeAttr)):
            for j in range(len(ctrlTIMRP)):
                mc.addAttr(ctrlTIMRP[j],
                           longName=toeAttr[i],
                           at="float",
                           k=True,
                           min=valsMinMaxDef[0],
                           max=valsMinMaxDef[1],
                           dv=valsMinMaxDef[2])

        # creating the Toes Curl
        self.toeCurlsSetup(ctrlArrayToes, autoTIMRP, ctrlToes, footAttr)

        # creating the Toes scrunch
        self.toeScrunchSetup(ctrlArrayToes, autoTIMRP, ctrlToes, footAttr)

        # creating the Toes spread
        self.toeSpreadSetup(ctrlArrayToes, autoTIMRP, ctrlToes, footAttr)

        # creating the Toes relax
        self.toeRelaxSetup(ctrlArrayToes, autoTIMRP, ctrlToes, footAttr)

        # Cleaning up
        self.toesCleanup(ctrlToes, jntMasterToes, jntAnkleTwist,
                         fkJntOffsetCtrls, grpCtrlFoot, grpLegs, colourTU)
        if checkGeo:
            CRU.tgpSetGeo(toesJnts, setLayer=True)
    def tgpMakeBC(self, *args):
        checkGeo = mc.checkBox("selGeo_cb", q=True, v=True)

        self.jntNames = mc.textFieldButtonGrp("jointLoad_tfbg",
                                              q=True,
                                              text=True)
        # self.geoNames = mc.textFieldButtonGrp("GeoLoad_tfbg", q=True, text=True)

        # make sure the selections are not empty
        checkList = [self.jntNames]

        if ((checkList[0] == "")):
            mc.warning("You are missing a selection!")
            return
        else:
            # CRU.createLocatorToDelete()
            # create the IK base controls
            jntEnd = self.jointArray[-1]

            noUnicode = str(jntEnd)
            jntEndSize = mc.getAttr('{0}.radius'.format(noUnicode))

            # gets values for later use
            jntSize = len(self.jointArray)
            midValue = int(jntSize / 2)

            # Create the IK joints
            ikHip, ikMidSpine, ikChest, spineIKs = self.createSpineIK(
                jntEnd, jntEndSize, midValue)

            # Adding the Spline IK
            ikSpine, effSpine, crvSpine = self.createIKSpline(jntEnd)

            # Creating the IK Spine Controls:
            # bind the curve to the JNT IKs,
            spineIKCtrls = self.createIKSpineCtrls(crvSpine, ikMidSpine,
                                                   ikChest, ikHip, spineIKs)

            # Adding the IK twist
            self.addIkTwist(
                ikSpine,
                ikHip,
                ikChest,
            )

            # Adding Some Stretch
            self.addStretch(
                crvSpine,
                jntSize,
            )

            # FK Joints and Controls
            fkJnts, offsetCtrlFKJnts = self.createFKJntAndCtrls(
                jntSize, jntEndSize, spineIKCtrls)

            # Adding an extra hip control
            fkHip, fkHipOffsetCtrl = self.createHipCtrl(ikHip, spineIKCtrls)

            # Creating the COG control
            cogOffsetCtrl = self.createCOGCtrl(
                spineIKCtrls,
                offsetCtrlFKJnts,
                fkJnts,
                spineIKs,
                crvSpine,
                ikSpine,
            )

            # cleanup
            self.spineCleanup(fkHipOffsetCtrl, offsetCtrlFKJnts, spineIKs,
                              spineIKCtrls, cogOffsetCtrl, crvSpine, ikSpine,
                              fkHip, fkJnts)

            # make the last thing we do the geometry
            if checkGeo:
                CRU.tgpSetGeo(self.jointArray, "JNT_IK_", setLayer=True)
            try:
                CRU.tgpSetGeo([fkHip], "JNT_FK_", setLayer=True)
                # mc.parent("GEO_hip", ikHip)
            except:
                mc.warning(
                    "Hip geometry either does not exist or is not properly named"
                )
    def makeArm(self, isLeft, leftRight, jntArmArray, jntClavicle, jntScapula,
                colourTU, jntShoulderRoot, ctrlFKIK, ctrlFKIKAttr, jntSpine6,
                checkboxTwists, checkboxSpine, checkGeo, checkboxSwitch,
                ctrlIKChest, ctrlCOG, grpFollow, geoJntArray, *args):

        # Adding the twist joints
        if checkboxTwists:
            # xprNameTwist, twistExpression, geoJntArray = self.makeTwists(3, leftRight, jntArmArray, geoJntArray, makeExpression)
            xprNameTwist, twistExpression, geoJntArray = self.makeTwists(
                3, leftRight, jntArmArray, geoJntArray)

        # NOTE: I use a slightly different order than the originals, leaving the SetGeo section to the lat

        # Creating FK and IK Joints
        bndJnts, fkJnts, ikJnts = self.getBndFkIkJnts(jntArmArray)

        fkLen = len(fkJnts)
        ikLen = len(ikJnts)
        bndLen = len(bndJnts)

        if bndLen != fkLen or bndLen != ikLen:
            mc.warning("Your arm joints are somehow not equal")
            return
        else:
            ikFkJntConstraints = []
            for i in range(bndLen):
                temp = mc.orientConstraint(fkJnts[i], ikJnts[i], bndJnts[i])[0]
                ikFkJntConstraints.append(temp)

        for i in range(len(ikFkJntConstraints)):
            self.tgpSetDriverArmFKIKSwitch(ctrlFKIK, ctrlFKIKAttr,
                                           ikFkJntConstraints[i])

        # we want to create FK controls for the limbs except the end
        armLength, fkJntOffsetCtrls = self.createArmFKs(fkJnts, colourTU)

        # create the shoulder control
        shoulderOffsetCtrl = self.setupShoulder(jntShoulderRoot, bndJnts,
                                                fkJntOffsetCtrls, colourTU)

        # create the clavicle
        if jntClavicle:
            clavicleOffsetCtrl = self.setupClavicle(jntClavicle, colourTU,
                                                    leftRight,
                                                    shoulderOffsetCtrl,
                                                    jntArmArray)

        # create the scapula
        if jntScapula:
            scapulaOffsetCtrl = self.setupScapula(
                jntScapula,
                colourTU,
                leftRight,
                shoulderOffsetCtrl,
            )

        # for testing purposes only, setting the IK to active:
        mc.setAttr("{0}.{1}".format(ctrlFKIK, ctrlFKIKAttr), 0.5)

        # Setting up the IK Arm
        ikOffsetCtrl, ikArms, ikJntsDrive, ikSide = self.createArmIK(
            ikJnts, leftRight, colourTU, isLeft)
        # create the twists
        self.setupIkElblowArmTwist(ikOffsetCtrl, ikJnts, ikArms, isLeft)

        # change the rotation order
        rotationChange = [
            ikJnts[1], jntArmArray[1], fkJnts[1], ikJntsDrive[1],
            fkJntOffsetCtrls[1][1]
        ]

        CRU.changeRotateOrder(rotationChange, "YZX")

        # Adding the Elbow Control
        elbowOffsetCtrl = self.createElbow(
            ikJntsDrive,
            leftRight,
            armLength,
            ikArms,
            isLeft,
            colourTU,
        )

        # Adding Space Switching
        # NOTE: This is something I added from the finalizing section
        if checkboxSwitch:
            # self.makeArmSwitch(ctrlLimb, ctrlShoulder, ctrlChest, ctrlCOG, grpFollow, leftRight, colourTU)
            self.makeArmSwitch(fkJntOffsetCtrls[0][1], shoulderOffsetCtrl[1],
                               ctrlIKChest, ctrlCOG, grpFollow, leftRight,
                               colourTU)
        # Organize the rig
        self.armCleanUp(fkJnts, ikJnts, ikJntsDrive, bndJnts, jntShoulderRoot,
                        jntScapula, jntClavicle, checkboxSpine,
                        shoulderOffsetCtrl, scapulaOffsetCtrl,
                        clavicleOffsetCtrl, ikOffsetCtrl, elbowOffsetCtrl,
                        ikArms, jntSpine6, ikSide, fkJntOffsetCtrls, ctrlFKIK,
                        ctrlFKIKAttr)

        if checkGeo:
            CRU.tgpSetGeo(geoJntArray, setLayer=True)
    def makeLeg(self, isLeft, leftRight, jntLegArray, checkGeo, geoJntArray,
                colourTU, jntLegRoot, ctrlFKIK, ctrlFKIKAttr, ctrlFKHip,
                checkboxTwists, checkboxSwitch, ctrlIKHip, ctrlCOG, grpFollow,
                checkboxHip, *args):

        # create a special control for my own preferences
        footCtrlsOffsetCtrl = self.addFootCtrl(geoJntArray, isLeft, leftRight,
                                               colourTU)

        # Create the joint twists
        # Adding the twist joint (does this at the same time)
        # Twist Joints and low-res Mesh
        if checkboxTwists:
            xprNameTwist, twistExpression, geoJntArray = self.makeTwists(
                3, leftRight, jntLegArray, geoJntArray, footCtrlsOffsetCtrl)

        # for testing purposes only, setting the IK to active:
        mc.setAttr("{0}.{1}".format(ctrlFKIK, ctrlFKIKAttr), 0.5)

        # Adding the IK and FK and creating the FK Controls
        bndJnts, fkJnts, ikJnts, ikFkJntConstraints, fkJntOffsetCtrls = self.addIKFKCreateFKCtrl(
            jntLegArray, colourTU, isLeft)

        # IK Leg Control Part 1
        ikJntsDrive, ikOffsetCtrl, ikLegs = self.createIKCtrlsAndDrive(
            ikJnts, leftRight, colourTU)

        # IK Leg Control Part 2
        self.orientConstrainThenRotateOrder(ikJnts, ikJntsDrive, bndJnts,
                                            fkJnts, fkJntOffsetCtrls)

        # FK IK Switching
        # Adding the IK and FK and creating the FK Controls
        for i in range(len(ikFkJntConstraints)):
            self.tgpSetDriverLegFKIKSwitch(ctrlFKIK, ctrlFKIKAttr,
                                           ikFkJntConstraints[i])

        # Attaching the Leg to the Hip
        hipIKOffsetCtrl = self.attachLegToHip(fkJnts, ikJnts, bndJnts,
                                              ctrlFKIK, ctrlFKIKAttr,
                                              ikJntsDrive, fkJntOffsetCtrls,
                                              leftRight)

        # create the ik twist
        self.setupIkKneeLegTwist(ikOffsetCtrl, ikJnts, ikLegs, isLeft)

        # Adding Space Switching
        # NOTE: This is something I added from the finalizing section
        if checkboxSwitch:
            # self.makeArmSwitch(ctrlLimb, ctrlShoulder, ctrlChest, ctrlCOG, grpFollow, leftRight, colourTU)
            self.makeLegSwitch(fkJntOffsetCtrls[0][1], ctrlFKHip, ctrlIKHip,
                               ctrlCOG, grpFollow, leftRight, colourTU)

        # Organize the rig
        self.legCleanUp(fkJnts, ikJnts, ikJntsDrive, bndJnts, ikOffsetCtrl,
                        fkJntOffsetCtrls, hipIKOffsetCtrl, ctrlFKHip,
                        leftRight, ctrlFKIK, ctrlFKIKAttr, checkboxHip,
                        footCtrlsOffsetCtrl)

        if checkGeo:
            CRU.tgpSetGeo(geoJntArray, setLayer=True)