Exemplo n.º 1
0
    def toggleStretchNeck(self, jntEnd, grpHeadDNT, ctrlHead, stretchable,
                          ikNeckEnd, jntHead):

        locNeckTip = "LOC_neckTip"
        mc.spaceLocator(p=(0, 0, 0), name=locNeckTip)

        # parent the jntEnd under grpHeadDNT
        mc.matchTransform(locNeckTip, jntEnd, pos=True)
        mc.parent(locNeckTip, grpHeadDNT)

        # constrain the neck tip
        mc.pointConstraint(jntEnd, locNeckTip)
        mc.orientConstraint(ctrlHead, locNeckTip)

        # the ikNeckEnd will probably have constrained it already
        neckPrntConstr = mc.parentConstraint(ikNeckEnd, jntHead, mo=True)[0]
        mc.parentConstraint(locNeckTip, jntHead, mo=True)

        neckPrntConstrVals = mc.listAttr(neckPrntConstr)[-2:]
        CRU.setDriverDrivenValues(ctrlHead, stretchable, neckPrntConstr,
                                  neckPrntConstrVals[0], 0, 0)
        CRU.setDriverDrivenValues(ctrlHead, stretchable, neckPrntConstr,
                                  neckPrntConstrVals[0], 1, 1)

        CRU.setDriverDrivenValues(ctrlHead, stretchable, neckPrntConstr,
                                  neckPrntConstrVals[1], 0, 1)
        CRU.setDriverDrivenValues(ctrlHead, stretchable, neckPrntConstr,
                                  neckPrntConstrVals[1], 1, 0)
        return
    def createSideToSide(self, ctrlIKFoot, sideToSide, locInner, locOuter,
                         leftRight, isLeft, *args):

        if isLeft:
            imVal = 1
        else:
            imVal = -1

        # CRU.setDriverDrivenValues(driver, driverAttribute, driven, drivenAttribute, driverValue, drivenValue)
        CRU.setDriverDrivenValues(ctrlIKFoot, sideToSide, locInner, "rotateZ",
                                  0, 0)
        CRU.setDriverDrivenValues(ctrlIKFoot, sideToSide, locOuter, "rotateZ",
                                  0, 0)
        CRU.setDriverDrivenValues(ctrlIKFoot, sideToSide, locInner, "rotateZ",
                                  -90, imVal * 90)
        CRU.setDriverDrivenValues(ctrlIKFoot, sideToSide, locOuter, "rotateZ",
                                  90, imVal * -90)
Exemplo n.º 3
0
    def toggleStretchTorso(self, locConstNeckShoulder, locHeadShoulder,
                           jntIKShoulder, grpTorsoDNT, jntSpineEnd,
                           ctrlShoulder):
        # create the group
        grpHeadShoulders = "GRP_head_shoulders"
        mc.group(em=True, w=True, n=grpHeadShoulders)
        mc.matchTransform(grpHeadShoulders, jntIKShoulder, pos=True)

        # put it under Do Not Touch torso
        mc.parent(grpHeadShoulders, grpTorsoDNT)

        # parent the locators under it
        mc.parent(locConstNeckShoulder, locHeadShoulder, grpHeadShoulders)

        # creates the spine tip locator which will drive a lot
        locSpineTip = "LOC_spineTip"
        mc.spaceLocator(p=(0, 0, 0), name=locSpineTip)
        mc.matchTransform(locSpineTip, jntSpineEnd)
        mc.parent(locSpineTip, grpTorsoDNT)

        mc.pointConstraint(jntSpineEnd, locSpineTip, mo=True)
        mc.orientConstraint(ctrlShoulder, locSpineTip, mo=True)

        grpPrntConstr = mc.parentConstraint(jntIKShoulder,
                                            grpHeadShoulders,
                                            mo=True)[0]
        mc.parentConstraint(locSpineTip, grpHeadShoulders, mo=True)

        stretchable = "stretchable"

        grpPrntConstrVals = mc.listAttr(grpPrntConstr)[-2:]
        CRU.setDriverDrivenValues(ctrlShoulder, stretchable, grpPrntConstr,
                                  grpPrntConstrVals[0], 0, 0)
        CRU.setDriverDrivenValues(ctrlShoulder, stretchable, grpPrntConstr,
                                  grpPrntConstrVals[0], 1, 1)

        CRU.setDriverDrivenValues(ctrlShoulder, stretchable, grpPrntConstr,
                                  grpPrntConstrVals[1], 0, 1)
        CRU.setDriverDrivenValues(ctrlShoulder, stretchable, grpPrntConstr,
                                  grpPrntConstrVals[1], 1, 0)

        return
    def makeFingersAttr(self,
                        ctrl,
                        attr,
                        cmpdCTRLs,
                        valPos,
                        valNeg,
                        drvnAttr,
                        passVals,
                        skipNeg=False,
                        isLocked=False):
        # the 4 finger joints
        tangentToUse = ["linear", "linear"]
        for j in range(len(valPos)):
            if passVals[j]:
                if isLocked:
                    CRU.lockHideCtrls(cmpdCTRLs[j],
                                      rotate=True,
                                      attrVisible=True,
                                      toLock=False)
                    # to delete: need to relock things at the end

                CRU.setDriverDrivenValues(ctrl,
                                          attr,
                                          cmpdCTRLs[j],
                                          drvnAttr,
                                          0,
                                          0,
                                          modifyInOut=tangentToUse)
                CRU.setDriverDrivenValues(ctrl,
                                          attr,
                                          cmpdCTRLs[j],
                                          drvnAttr,
                                          10,
                                          valPos[j],
                                          modifyInOut=tangentToUse)
                if not skipNeg:
                    CRU.setDriverDrivenValues(ctrl,
                                              attr,
                                              cmpdCTRLs[j],
                                              drvnAttr,
                                              -10,
                                              valNeg[j],
                                              modifyInOut=tangentToUse)

                if isLocked:
                    CRU.lockHideCtrls(cmpdCTRLs[j], rotate=True)

        return
    def makeSpreadFix(self, cmpdCtrlTIMRP, ctrlTIMRP, ctrlHand):
        fingerValsNeg = [-41, -15, -4, 1, 15]
        fingerValsPos = [15, 25, 5, -10, -30]
        for i in range(len(cmpdCtrlTIMRP)):

            if i == 0:
                CRU.setDriverDrivenValues(ctrlTIMRP[i],
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          0,
                                          0,
                                          modifyBoth="linear")
                CRU.setDriverDrivenValues(ctrlTIMRP[i],
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          -10,
                                          35,
                                          modifyBoth="linear")
                CRU.setDriverDrivenValues(ctrlTIMRP[i],
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          10,
                                          -20,
                                          modifyBoth="linear")

                CRU.setDriverDrivenValues(ctrlHand,
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          0,
                                          0,
                                          modifyBoth="linear")
                CRU.setDriverDrivenValues(ctrlHand,
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          -10,
                                          35,
                                          modifyBoth="linear")
                CRU.setDriverDrivenValues(ctrlHand,
                                          "spread",
                                          cmpdCtrlTIMRP[i][1],
                                          "rz",
                                          10,
                                          -20,
                                          modifyBoth="linear")

            # sets the JNT_cmpdCTRL_finger1
            CRU.setDriverDrivenValues(ctrlTIMRP[i], "spread",
                                      cmpdCtrlTIMRP[i][1], "ry", 0, 0)
            CRU.setDriverDrivenValues(ctrlTIMRP[i],
                                      "spread",
                                      cmpdCtrlTIMRP[i][1],
                                      "ry",
                                      -10,
                                      fingerValsNeg[i],
                                      modifyBoth="linear")
            CRU.setDriverDrivenValues(ctrlTIMRP[i],
                                      "spread",
                                      cmpdCtrlTIMRP[i][1],
                                      "ry",
                                      10,
                                      fingerValsPos[i],
                                      modifyBoth="linear")

            CRU.setDriverDrivenValues(ctrlHand, "spread", cmpdCtrlTIMRP[i][1],
                                      "ry", 0, 0)
            CRU.setDriverDrivenValues(ctrlHand,
                                      "spread",
                                      cmpdCtrlTIMRP[i][1],
                                      "ry",
                                      -10,
                                      fingerValsNeg[i],
                                      modifyBoth="linear")
            CRU.setDriverDrivenValues(ctrlHand,
                                      "spread",
                                      cmpdCtrlTIMRP[i][1],
                                      "ry",
                                      10,
                                      fingerValsPos[i],
                                      modifyBoth="linear")
        return
Exemplo n.º 6
0
    def tgpMakeBC(self, mshChar, renameVals, *args):
        # print(mshChar)

        if renameVals:
            CRAd(mshChar=mshChar)

        history = mc.listHistory(mshChar)
        # print("history {0}".format(history))
        blndName = mc.ls(history, typ='blendShape')[0]
        # print("blndName {0}".format(blndName))
        blndVals = mc.aliasAttr(blndName, q=True)
        # print("blndVals {0}".format(blndVals))
        blndValNames = []
        blndValWeights = []

        weightName = [x for x in blndVals if ("weight" in x.lower())]
        nonWeightName = [x for x in blndVals if ("weight" not in x.lower())]

        for i in range(len(nonWeightName)):
            # "d_" will stand for delete
            if "d_" in nonWeightName[i][:2]:
                mc.aliasAttr("{0}.{1}".format(blndName, nonWeightName[i]),
                             rm=True)

        skip = False
        for i in range(len(blndVals)):
            if skip:
                skip = False
                continue  # skip to the next value. Only if Copy was the previous value
            if "Copy" in blndVals[i][-4:]:
                # If 'copy' is in there, it's probably badly named
                skip = True
                continue
            if "GEO_" in blndVals[i][:3]:
                # If 'GEO' is in there, it's probably badly named
                skip = True
                continue
            if "base" in blndVals[i][-4:]:
                # If 'base' is in there, it's referring to the basic shape
                skip = True
                continue
            if "d_" in blndVals[i][:2]:
                # If 'd_' is in there, it's referring to something to delete
                skip = True
                continue
            if "w[" in blndVals[i][:2]:
                # If 'w[' is in there, it's likely referring to something that has been deleted
                skip = True
                continue
            if "combo" in blndVals[i][:5]:
                # If 'combo' is in there, it's referring to the basic shape
                skip = True
                continue
            if "tempAlias" in blndVals[i]:
                # If 'tempAlias' is in there, it's referring to the basic shape
                skip = True
                continue
            if 'weight' in blndVals[i][:6]:
                # These are typically
                blndValWeights.append(blndVals[i])
                theVals = mc.getAttr("{0}.{1}".format(blndName, blndVals[i]))
                # print(theVals)
            else:
                blndValNames.append(blndVals[i])

        # print(blndValWeights)
        # print(blndValNames)

        # delete the preexisting blendshape animations
        test = mc.ls("blendShape1_*", type="animCurveUU")
        print("{0}".format(test))
        # deletes pre-existing lists
        if len(test) != 0:
            mc.delete(test)

        for i in range(len(blndValNames)):
            custVal = False
            try:
                driver, driverAttrDrvnVal = blndValNames[i].split("__", 1)
            except:
                print("Error! {0}".format(blndValNames[i]))
            if "FK_" in driver[:3]:

                driver = "CTRL_" + driver
            elif "CTRL_" in driver[:5]:
                custVal = True

            else:
                driver = "JNT_BND_" + driver
            # print(driver)
            # print(driverAttrDrvnVal)
            driverAttr, driverValNum = self.getDriverAttrDrivenVals(
                driverAttrDrvnVal, custVal)
            # print("driverAttr {0}".format(driverAttr))
            # print("drivenValue {0}".format(driverValNum))

            CRU.setDriverDrivenValues(driver,
                                      driverAttr,
                                      blndName,
                                      blndValWeights[i],
                                      drivenValue=0,
                                      driverValue=0,
                                      modifyBoth="linear")

            CRU.setDriverDrivenValues(driver,
                                      driverAttr,
                                      blndName,
                                      blndValWeights[i],
                                      drivenValue=1,
                                      driverValue=driverValNum,
                                      modifyBoth="linear")
Exemplo n.º 7
0
    def createEyeControls(self, eyeArray, ctrlHead, ctrlRootTrans, *args):
        # Create eye control
        eyeCtrlArray = []

        eyeGrpArray = []

        eyeRadBase = mc.listRelatives(eyeArray[-1], type="joint")[0]

        radiusBase = mc.getAttr("{0}.tz".format(eyeRadBase))

        for i in range(len(eyeArray)):
            # takes the eye joints, creates a corresponding locator
            eyeName = str(eyeArray[i]).replace("JNT_BND_", "")
            ctrlEye = "CTRL_" + eyeName
            grpEye = "GRP_" + ctrlEye
            eyeCtrlArray.append(mc.spaceLocator(p=(0, 0, 0), name=ctrlEye)[0])

            mc.setAttr('{0}.overrideEnabled'.format(eyeCtrlArray[i]), 1)
            if "_l_" in eyeCtrlArray[i]:
                mc.setAttr("{0}.overrideColor".format(eyeCtrlArray[i]), 14)
            elif "_r_" in eyeCtrlArray[i]:
                mc.setAttr("{0}.overrideColor".format(eyeCtrlArray[i]), 13)

            # groups them at the creation point

            eyeGrpArray.append(mc.group(ctrlEye, name=grpEye))

            # moves the eye into posiiton
            mc.matchTransform(eyeGrpArray[i], eyeArray[i], pos=True, rot=True)

            mc.move(radiusBase * 20, eyeGrpArray[i], z=True, r=True, os=True)

        # Create the eyes control
        eyesCtrlName = "CTRL_eyes"
        eyesCtrl = mc.circle(nr=(0, 1, 0),
                             r=radiusBase * 7.5,
                             n=eyesCtrlName,
                             degree=1,
                             sections=4)[0]

        mc.setAttr("{0}.ry".format(eyesCtrl), 45)
        mc.makeIdentity(eyesCtrl, a=True)  # freeze transform
        mc.setAttr("{0}.sx".format(eyesCtrl), 1.5)
        mc.makeIdentity(eyesCtrl, a=True)  # freeze transform
        mc.setAttr("{0}.rx".format(eyesCtrl), 90)
        mc.makeIdentity(eyesCtrl, a=True)  # freeze transform

        eyesGrp = mc.group(eyesCtrl, n="GRP_" + eyesCtrlName)

        todelete = mc.pointConstraint(eyeCtrlArray, eyesGrp)
        mc.delete(todelete)

        mc.parent(eyeGrpArray, eyesCtrl)
        mc.parent(eyesGrp, ctrlRootTrans)

        aimArray = []
        for i in range(len(eyeArray)):
            aimArray.append(
                mc.aimConstraint(eyeCtrlArray[i], eyeArray[i], aim=[0, 0, 1]))

        # create the eye follow settings
        eyesFollowLocArray = []

        locFollowHead = "LOC_follow_eyesHead"
        locFollowRoot = "LOC_follow_eyesRoot"

        eyesFollowLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name=locFollowHead)[0])
        eyesFollowLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name=locFollowRoot)[0])

        # moves the locators into position
        for i in range(len(eyesFollowLocArray)):
            todelete = mc.parentConstraint(eyesCtrl,
                                           eyesFollowLocArray[i],
                                           mo=False)
            mc.delete(todelete)

        mc.parent(eyesFollowLocArray[0], ctrlHead)

        mc.parent(eyesFollowLocArray[-1], ctrlRootTrans)

        eyesCtrlPrntConst = mc.parentConstraint(eyesFollowLocArray[0],
                                                eyesFollowLocArray[1],
                                                eyesGrp)[0]
        eyesFollow = 'eyesFollow'
        mc.addAttr(eyesCtrl,
                   longName=eyesFollow,
                   at="enum",
                   enumName="head:root",
                   k=True)

        # The last two attributes would be the relevant head and eye controls
        eyesFollowVals = mc.listAttr(eyesCtrlPrntConst)[-2:]

        CRU.setDriverDrivenValues(eyesCtrl, eyesFollow, eyesCtrlPrntConst,
                                  eyesFollowVals[0], 0, 1)
        CRU.setDriverDrivenValues(eyesCtrl, eyesFollow, eyesCtrlPrntConst,
                                  eyesFollowVals[0], 1, 0)

        CRU.setDriverDrivenValues(eyesCtrl, eyesFollow, eyesCtrlPrntConst,
                                  eyesFollowVals[1], 0, 0)
        CRU.setDriverDrivenValues(eyesCtrl, eyesFollow, eyesCtrlPrntConst,
                                  eyesFollowVals[1], 1, 1)

        for i in range(len(eyesFollowLocArray)):
            # hide the eye locators
            mc.setAttr("{0}.v".format(eyesFollowLocArray[i]), False)

        return eyeCtrlArray, eyesCtrl, eyeGrpArray, eyesGrp
Exemplo n.º 8
0
    def createSpaceSwitching(self, grpHead, ctrlHead, jntIKShoulder,
                             ctrlRootTrans, fkJnts, grpTorsoDNT, *args):
        # to delete: I might have constrained the head control when I should have used the grpHead
        # creates the head follow attributes

        locHeadNeck = "LOC_space_headNeck"
        locHeadShoulder = "LOC_space_headShoulder"
        locHeadBody = "LOC_space_headBody"
        locHeadRoot = "LOC_space_headRoot"
        headLocArray = [locHeadNeck, locHeadShoulder, locHeadBody, locHeadRoot]
        for i in range(len(headLocArray)):
            mc.spaceLocator(p=(0, 0, 0), name=headLocArray[i])
        '''headLocArray.append(mc.spaceLocator(p=(0, 0, 0), name="LOC_space_headNeck")[0])
        headLocArray.append(mc.spaceLocator(p=(0, 0, 0), name="LOC_space_headShoulder")[0])
        headLocArray.append(mc.spaceLocator(p=(0, 0, 0), name="LOC_space_headBody")[0])
        headLocArray.append(mc.spaceLocator(p=(0, 0, 0), name="LOC_space_headRoot")[0])'''

        # moves these to the head
        for i in range(len(headLocArray)):
            todelete = mc.pointConstraint(fkJnts[-1], headLocArray[i])
            mc.delete(todelete)

        # parent the head space to their respective parts
        mc.parent(headLocArray[0], fkJnts[-1])
        mc.parent(headLocArray[1], jntIKShoulder)
        mc.parent(headLocArray[2], grpTorsoDNT)
        mc.parent(headLocArray[3], ctrlRootTrans)

        headFollowOrntConstr = mc.orientConstraint(headLocArray, grpHead)[0]
        headFollowPntConstr = mc.pointConstraint(headLocArray, grpHead)[0]

        headFollowRot = 'rotationSpace'
        headFollowTrans = 'translationSpace'
        mc.addAttr(ctrlHead,
                   longName=headFollowRot,
                   at="enum",
                   enumName="Neck:Shoulders:upperBody:Root",
                   k=True)
        mc.addAttr(ctrlHead,
                   longName=headFollowTrans,
                   at="enum",
                   enumName="Neck:Shoulders:upperBody:Root",
                   k=True)

        # grab the last 4 attributes
        headSpaceFollowOrnt = mc.listAttr(headFollowOrntConstr)[-4:]
        headSpaceFollowPnt = mc.listAttr(headFollowPntConstr)[-4:]
        for i in range(len(headSpaceFollowOrnt)):
            # set the driven key to 1 and the undriven keys to 0

            CRU.setDriverDrivenValues(ctrlHead, headFollowRot,
                                      headFollowOrntConstr,
                                      headSpaceFollowOrnt[i], i, 1)
            CRU.setDriverDrivenValues(ctrlHead, headFollowTrans,
                                      headFollowPntConstr,
                                      headSpaceFollowPnt[i], i, 1)
            for i2 in range(len(headSpaceFollowOrnt)):
                if i2 != i:
                    # need to have the second to last value be i, not i2
                    CRU.setDriverDrivenValues(ctrlHead, headFollowRot,
                                              headFollowOrntConstr,
                                              headSpaceFollowOrnt[i2], i, 0)
                    CRU.setDriverDrivenValues(ctrlHead, headFollowTrans,
                                              headFollowPntConstr,
                                              headSpaceFollowPnt[i2], i, 0)

        for i in range(len(headLocArray)):
            mc.setAttr("{0}.v".format(headLocArray[i]), False)

        return headLocArray, locHeadShoulder