def tgpSetDriverEnumWorldFollowLeg(self, driver, driverAttr, driven,
                                       *args):

        # sets the leg enum to shift between world follow and knee follow
        w0w1Attr = mc.listAttr(driven)[-1:]
        CRU.setDriverDrivenValues(driver, driverAttr, driven, w0w1Attr[0], 0,
                                  1)
        CRU.setDriverDrivenValues(driver, driverAttr, driven, w0w1Attr[0], 1,
                                  0)
Beispiel #2
0
    def createSpaceSwitching(self, headCtrl, headOffsetCtrls, ctrlIKChest,
                             ctrlCOG, grpWorldFollow, *args):
        # creates the head follow attributes
        eyesHeadLocArray = []
        eyesHeadLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_headNeckFollow")[0])
        eyesHeadLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_headTorsoFollow")[0])
        eyesHeadLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_headCOGFollow")[0])
        eyesHeadLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_headWorldFollow")[0])

        # moves these to the CTRL_head
        for i in range(len(eyesHeadLocArray)):
            todelete = mc.parentConstraint(headCtrl,
                                           eyesHeadLocArray[i],
                                           mo=False)
            mc.delete(todelete)

        headFollowOrntConstr = mc.orientConstraint(eyesHeadLocArray,
                                                   headCtrl)[0]
        mc.addAttr(headCtrl,
                   longName='headFollow',
                   at="enum",
                   enumName="Neck:Torso:COG:World",
                   k=True)

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

            CRU.setDriverDrivenValues(headCtrl, "headFollow",
                                      headFollowOrntConstr, headSpaceFollow[i],
                                      i, 1)
            for i2 in range(len(headSpaceFollow)):
                if i2 != i:
                    # need to have the second to last value be i, not i2
                    CRU.setDriverDrivenValues(headCtrl, "headFollow",
                                              headFollowOrntConstr,
                                              headSpaceFollow[i2], i, 0)

        locParents = [
            headOffsetCtrls[1][1], ctrlIKChest, ctrlCOG, grpWorldFollow
        ]
        # parent LOC_headNeckFollow under CTRL_neck2
        # parent LOC_headTorsoFollow under CTRL_IK_chest
        # parent LOC_headCOGFollow under CTRL_COG
        # parent LOC_headWorldFollow under GRP_LOC_worldFollow
        for i in range(len(eyesHeadLocArray)):
            mc.parent(eyesHeadLocArray[i], locParents[i])
            mc.setAttr("{0}.v".format(eyesHeadLocArray[i]), False)
 def tgpSetDriverArmFKIKSwitch(self, driver, driverAttr, driven, *args):
     w0w1Attr = mc.listAttr(driven)[-2:]
     CRU.setDriverDrivenValues(driver,
                               driverAttr,
                               driven,
                               w0w1Attr[0],
                               drivenValue=0,
                               driverValue=1,
                               modifyBoth="linear")
     CRU.setDriverDrivenValues(driver,
                               driverAttr,
                               driven,
                               w0w1Attr[0],
                               drivenValue=1,
                               driverValue=0,
                               modifyBoth="linear")
     CRU.setDriverDrivenValues(driver,
                               driverAttr,
                               driven,
                               w0w1Attr[1],
                               drivenValue=0,
                               driverValue=0,
                               modifyBoth="linear")
     CRU.setDriverDrivenValues(driver,
                               driverAttr,
                               driven,
                               w0w1Attr[1],
                               drivenValue=1,
                               driverValue=1,
                               modifyBoth="linear")
 def setDigitVals(self, digit_drvnvls_autos_digitCtrl, driverVal,
                  ctrlDigits, digitAttr, *args):
     for i in range(len(digit_drvnvls_autos_digitCtrl)):
         for j in range(len(digit_drvnvls_autos_digitCtrl[i][0])):
             # skip if the value is a None
             if digit_drvnvls_autos_digitCtrl[i][0][j] is not None:
                 CRU.setDriverDrivenValues(
                     ctrlDigits, digitAttr,
                     digit_drvnvls_autos_digitCtrl[i][1][j],
                     digit_drvnvls_autos_digitCtrl[i][-1], driverVal,
                     digit_drvnvls_autos_digitCtrl[i][0][j])
                 # skip if the digit Control is not there
                 if digit_drvnvls_autos_digitCtrl[i][2] is not None:
                     CRU.setDriverDrivenValues(
                         digit_drvnvls_autos_digitCtrl[i][2], digitAttr,
                         digit_drvnvls_autos_digitCtrl[i][1][j],
                         digit_drvnvls_autos_digitCtrl[i][-1], driverVal,
                         digit_drvnvls_autos_digitCtrl[i][0][j])
 def setFootAttributeValues(self,
                            ctrlIKLeg,
                            footAttribute,
                            footAttributeValues,
                            loc,
                            footAttributeValuesLoc,
                            setValue,
                            isLeft=True):
     # the values may need to be negative when the foot is switched, but some of the values work fine with both sides so we make it a default
     if isLeft:
         mult = 1
     else:
         mult = -1
     for i in range(len(footAttributeValues)):
         # def setDriverDrivenValues(driver, driverAttribute, driven, drivenAttribute, driverValue, drivenValue):
         CRU.setDriverDrivenValues(ctrlIKLeg, footAttribute, loc, setValue,
                                   footAttributeValues[i],
                                   footAttributeValuesLoc[i] * mult)
Beispiel #6
0
    def tgpMakeBC(self, *args):

        mc.textFieldButtonGrp("mshCharLoad_tf", e=True, bc=self.loadSrc1Btn)

        mshChar = mc.textFieldButtonGrp("mshCharLoad_tf", q=True, text=True)

        # print(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 = []

        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 "base" in blndVals[i][-4:]:
                # If 'base' is in there, it's referring to the basic shape
                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)

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

                driver = "CTRL_" + driver

            else:
                driver = "JNT_" + driver
            print(driver)
            print(driverAttrDrvnVal)
            driverAttr, driverValNum = self.getDriverAttrDrivenVals(
                driverAttrDrvnVal)
            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")
            # CRU.setDriverDrivenValues(driver, driverAttr, driven, w0w1Attr[0], drivenValue=0, driverValue=1,
            #                         modifyBoth="linear")

        # CRU.createLocatorToDelete()
        '''
    def armCleanUp(self, fkJnts, ikJnts, ikJntsDrive, bndJnts, jntShoulderRoot,
                   jntScapula, jntClavicle, checkboxSpine, shoulderOffsetCtrl,
                   scapulaOffsetCtrl, clavicleOffsetCtrl, ikOffsetCtrl,
                   elbowOffsetCtrl, ikArms, jntSpine6, ikSide,
                   fkJntOffsetCtrls, ctrlFKIK, ctrlFKIKAttr, *args):

        mc.parent(fkJnts[0], ikJnts[0], ikJntsDrive[0], jntShoulderRoot)

        if checkboxSpine:
            mc.parentConstraint(jntSpine6, shoulderOffsetCtrl[0], mo=True)

        mc.pointConstraint(shoulderOffsetCtrl[1], jntShoulderRoot)

        # group OFFSET_CTRL_IK_l_arm, OFFSET_CTRL_l_elbow into GRP_CTRL_IK_l_arm
        ikGrpCtrlName = "GRP_CTRL_IK_" + ikSide
        ikGrpCtrl = mc.group(n=ikGrpCtrlName, w=True, em=True)

        mc.parent(ikOffsetCtrl[0], elbowOffsetCtrl[0], ikGrpCtrl)

        # group IK_l_arm, JNT_l_shouder into GRP_jnt_l_arm
        armGrpRigName = "GRP_jnt_" + ikSide
        armRigGrp = mc.group(n=armGrpRigName, w=True, em=True)

        mc.parent(ikArms[0], jntShoulderRoot, armRigGrp)

        # creating lists to set invisible
        fksToVisible = [fkJntOffsetCtrls[0][1], fkJnts[0]]
        iksToVisible = [
            ikOffsetCtrl[1], ikJnts[0], ikJntsDrive[0], elbowOffsetCtrl[1]
        ]
        tangentToUse = ["linear", "step"]
        visMin = 0.001

        # set the FK to visible when not ctrlFKIK not 1 for arm attribute
        for i in range(len(fksToVisible)):
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      fksToVisible[i],
                                      "visibility",
                                      drivenValue=True,
                                      driverValue=0,
                                      modifyInOut=tangentToUse)
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      fksToVisible[i],
                                      "visibility",
                                      drivenValue=True,
                                      driverValue=1 - visMin,
                                      modifyInOut=tangentToUse)
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      fksToVisible[i],
                                      "visibility",
                                      drivenValue=False,
                                      driverValue=1,
                                      modifyInOut=tangentToUse)

        tangentToUse = ["linear", "step"]
        # set the IK to visible when not ctrlFKIK not 0 for arm attribute
        for i in range(len(iksToVisible)):
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      iksToVisible[i],
                                      "visibility",
                                      drivenValue=False,
                                      driverValue=0,
                                      modifyInOut=tangentToUse)
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      iksToVisible[i],
                                      "visibility",
                                      drivenValue=True,
                                      driverValue=visMin,
                                      modifyInOut=tangentToUse)
            CRU.setDriverDrivenValues(ctrlFKIK,
                                      ctrlFKIKAttr,
                                      iksToVisible[i],
                                      "visibility",
                                      drivenValue=True,
                                      driverValue=1,
                                      modifyInOut=tangentToUse)

        # locking and hiding the IK controls
        CRU.lockHideCtrls(ikOffsetCtrl[1],
                          rotate=True,
                          scale=True,
                          visible=True)
        for fkJntOC in fkJntOffsetCtrls:
            CRU.lockHideCtrls(fkJntOC[1], translate=True, scale=True)
            CRU.lockHideCtrls(fkJntOC[1], visible=True, toLock=False)
        CRU.lockHideCtrls(shoulderOffsetCtrl[1],
                          translate=True,
                          scale=True,
                          visible=True)
        CRU.lockHideCtrls(scapulaOffsetCtrl[1],
                          translate=True,
                          scale=True,
                          visible=True)
        CRU.lockHideCtrls(clavicleOffsetCtrl[1],
                          translate=True,
                          scale=True,
                          visible=True)
        CRU.lockHideCtrls(elbowOffsetCtrl[1],
                          rotate=True,
                          scale=True,
                          visible=True)

        # hiding the visibility for the FK

        # locking and hiding the effectors and IK
        # to delete: May need to not have this hidden
        mc.setAttr("{0}.visibility".format(ikArms[0]), False)
        CRU.lockHideCtrls(ikArms[0], visible=True)
        CRU.lockHideCtrls(ikArms[1], visible=True)

        CRU.layerEdit(ikJnts, ikLayer=True, noRecurse=True)
        CRU.layerEdit(fkJnts, fkLayer=True, noRecurse=True)
        CRU.layerEdit(ikJntsDrive, ikdriveLayer=True, noRecurse=True)
        CRU.layerEdit(bndJnts, bndLayer=True, noRecurse=True)
        CRU.layerEdit(jntShoulderRoot, bndLayer=True, noRecurse=True)
        CRU.layerEdit(jntScapula, bndLayer=True, noRecurse=True)
        CRU.layerEdit(jntClavicle, bndLayer=True, noRecurse=True)
    def legCleanUp(self, fkJnts, ikJnts, ikJntsDrive, bndJnts, ikOffsetCtrl,
                   fkJntOffsetCtrls, hipIKOffsetCtrl, ctrlFKHip, leftRight,
                   ctrlFKIK, ctrlFKIKAttr, checkboxHip, footCtrlsOffsetCtrl,
                   *args):

        # group the root leg joints and the IK control
        grpLegRigName = "GRP_rig_" + leftRight + "leg"
        grpLegJntName = "GRP_JNT_" + leftRight + "leg"

        grpLegRig = mc.group(n=grpLegRigName, w=True, em=True)
        grpLegJnt = mc.group(n=grpLegJntName, w=True, em=True)

        mc.parent(fkJnts[0], ikJnts[0], ikJntsDrive[0], bndJnts[0], grpLegJnt)
        mc.parent(grpLegJnt, ikOffsetCtrl[0], footCtrlsOffsetCtrl[0],
                  grpLegRig)

        # attach objects to the hip
        if checkboxHip:
            mc.parent(fkJntOffsetCtrls[0][0], hipIKOffsetCtrl[0], ctrlFKHip)

        # Hiding the visibility of the joints
        mc.setAttr("{0}.visibility".format(ikJnts[0]), False)
        mc.setAttr("{0}.visibility".format(ikJntsDrive[0]), False)
        mc.setAttr("{0}.visibility".format(fkJnts[0]), False)
        mc.setAttr("{0}.visibility".format(hipIKOffsetCtrl[1]), False)

        # locking and hiding the IK controls

        # my custom control shouldn't be moved by the animator
        CRU.lockHideCtrls(footCtrlsOffsetCtrl[1],
                          translate=True,
                          rotate=True,
                          scale=True,
                          visible=True)

        # locking and hiding the CTRL_IK_l_hip
        CRU.lockHideCtrls(hipIKOffsetCtrl[1], scale=True, visible=True)

        # set the FK to visible when not ctrlFKIK not 1 for leg attribute

        tangentToUse = ["linear", "step"]
        visMin = 0.001

        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  fkJntOffsetCtrls[0][1],
                                  "visibility",
                                  drivenValue=True,
                                  driverValue=0,
                                  modifyInOut=tangentToUse)
        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  fkJntOffsetCtrls[0][1],
                                  "visibility",
                                  drivenValue=True,
                                  driverValue=1 - visMin,
                                  modifyInOut=tangentToUse)
        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  fkJntOffsetCtrls[0][1],
                                  "visibility",
                                  drivenValue=False,
                                  driverValue=1,
                                  modifyInOut=tangentToUse)

        tangentToUse = ["linear", "step"]
        # set the IK to visible when not ctrlFKIK not 0 for leg attribute
        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  ikOffsetCtrl[1],
                                  "visibility",
                                  drivenValue=False,
                                  driverValue=0,
                                  modifyInOut=tangentToUse)
        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  ikOffsetCtrl[1],
                                  "visibility",
                                  drivenValue=True,
                                  driverValue=visMin,
                                  modifyInOut=tangentToUse)
        CRU.setDriverDrivenValues(ctrlFKIK,
                                  ctrlFKIKAttr,
                                  ikOffsetCtrl[1],
                                  "visibility",
                                  drivenValue=True,
                                  driverValue=1,
                                  modifyInOut=tangentToUse)

        CRU.layerEdit(fkJnts, fkLayer=True, noRecurse=True)
        CRU.layerEdit(ikJnts, ikLayer=True, noRecurse=True)
        CRU.layerEdit(ikJntsDrive, ikdriveLayer=True, noRecurse=True)
        CRU.layerEdit(bndJnts, bndLayer=True, noRecurse=True)

        CRU.lockHideCtrls(ikOffsetCtrl[1],
                          rotate=True,
                          scale=True,
                          visible=True)

        for fkOC in fkJntOffsetCtrls:
            CRU.lockHideCtrls(fkOC[1],
                              translate=True,
                              scale=True,
                              visible=True)
Beispiel #9
0
    def createEyeControls(self, eyeArray, headOffsetCtrls, *args):
        # Create eye control
        eyeCtrlArray = []

        eyeOffsetArray = []

        radiusBase = mc.getAttr("{0}.ty".format(self.jointEndArray[-1]))
        print("self.jointEndArray[-1]: {0}".format(self.jointEndArray[-1]))

        for i in range(len(eyeArray)):
            # takes the eye joints, creates a corresponding locator
            eyeName = str(eyeArray[i]).replace("JNT_", "")
            eyeCtrlArray.append(
                mc.spaceLocator(p=(0, 0, 0), name="CTRL_" + eyeName)[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
            autoGrp = mc.group(eyeCtrlArray[i], name="AUTO_" + eyeName)
            eyeOffsetArray.append(mc.group(autoGrp, name="OFFSET_" + eyeName))

            # moves the eye into posiiton
            todelete = mc.parentConstraint(eyeArray[i],
                                           eyeOffsetArray[i],
                                           mo=False)
            mc.delete(todelete)

            mc.move(radiusBase * 2, eyeOffsetArray[i], z=True, r=True)

        # Create the eyes control
        eyesCtrlName = "CTRL_eyes"
        eyesCtrl = mc.circle(nr=(0, 1, 0),
                             r=radiusBase * .75,
                             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

        eyesAuto = mc.group(eyesCtrl, n="AUTO_" + eyesCtrlName)

        eyesOffset = mc.group(eyesAuto, n="OFFSET_" + eyesCtrlName)

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

        mc.parent(eyeOffsetArray, eyesCtrl)

        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 = []

        eyesFollowLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_eyesHeadFollow")[0])
        eyesFollowLocArray.append(
            mc.spaceLocator(p=(0, 0, 0), name="LOC_eyesWorldFollow")[0])

        for i in range(len(eyesFollowLocArray)):
            todelete = mc.parentConstraint(eyesCtrl,
                                           eyesFollowLocArray[i],
                                           mo=False)
            mc.delete(todelete)
        headCtrl = ""
        for i in range(len(headOffsetCtrls)):
            if "head" in headOffsetCtrls[i][1]:
                headCtrl = headOffsetCtrls[i][1]

        mc.parent(eyesFollowLocArray[0], headCtrl)

        eyesCtrlPrntConst = mc.parentConstraint(eyesFollowLocArray[0],
                                                eyesFollowLocArray[1],
                                                eyesOffset)[0]

        mc.addAttr(eyesCtrl,
                   longName='eyesFollow',
                   at="enum",
                   enumName="Head:World",
                   k=True)

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

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

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

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

        grpWorldFollow = mc.group(n="GRP_LOC_follow", w=True, em=True)

        mc.parent(eyesFollowLocArray[1], grpWorldFollow)

        return headCtrl, eyeCtrlArray, eyesCtrl, grpWorldFollow