def setupScapula(self, jointScapula, colourTU, leftRight,
                     shoulderOffsetCtrl, *args):
        jntScap = jointScapula[0]
        childScap = mc.listRelatives(jntScap, c=True, type="joint")[0]
        scapLength = mc.getAttr("{0}.ty".format(childScap))
        scapulaOffsetCtrl = CRU.createCTRLs(jntScap,
                                            size=6,
                                            ornt=True,
                                            colour=colourTU,
                                            orientVal=(1, 0, 0),
                                            sectionsTU=8)

        mc.select(scapulaOffsetCtrl[1] + ".cv[:]")
        mc.move(-scapLength * 0.5, scapLength * 0.5, 0, r=True, ls=True)
        autoAttrName = "autoScapula"
        mc.addAttr(scapulaOffsetCtrl,
                   longName=autoAttrName,
                   at="float",
                   k=True,
                   min=0,
                   max=1,
                   dv=0.5)
        autoName = scapulaOffsetCtrl[2]
        xprNameScap = "expr_" + leftRight + "scapula"

        # AUTO_CTRL_l_scapula.rotateX = -1*CTRL_l_shoulder.rotateZ * CTRL_l_scapula.autoScapula;
        exprStringScap = "{0}.rotateX = -1*{1}.rotateZ * {2}.{3};\n".format(
            autoName, shoulderOffsetCtrl[1], scapulaOffsetCtrl[1],
            autoAttrName)

        mc.expression(s=exprStringScap, n=xprNameScap)
        mc.parent(scapulaOffsetCtrl[0], shoulderOffsetCtrl[1])

        return scapulaOffsetCtrl
    def createArmIK(self, ikJnts, leftRight, colourTU, isLeft, *args):

        ikJntsTDriveTemp = mc.duplicate(ikJnts[0], rc=True)
        ikJntsDrive = self.tgpCreateLimbFKIFList(ikJntsTDriveTemp,
                                                 addToEnd="Drive",
                                                 stripLastVal=1)

        ikSide = leftRight + "arm"

        ikArmName = "IK_" + ikSide
        effArmName = "EFF_" + ikSide
        ikArms = mc.ikHandle(n=ikArmName,
                             sj=ikJntsDrive[0],
                             ee=ikJntsDrive[-1],
                             sol="ikRPsolver")
        mc.rename(ikArms[1], effArmName)
        ikArms[1] = effArmName

        # fkJntOffsetCtrls.append(CRU.createCTRLs(temp, size=9, ornt=True, colour=colourTU, orientVal=(0, 1, 0)))
        ikOffsetCtrl = CRU.createCTRLs(ikArms[0],
                                       pnt=True,
                                       colour=colourTU,
                                       addPrefix=True,
                                       boxDimensionsLWH=[5, 5, 5])

        fkOrntUpperArm1 = mc.orientConstraint(ikJntsDrive[0], ikJnts[0])[0]
        fkOrntLowerArm1 = mc.orientConstraint(ikJntsDrive[1],
                                              ikJnts[1],
                                              skip="y")[0]

        return ikOffsetCtrl, ikArms, ikJntsDrive, ikSide
    def createLegOrFootIK(self, ikJntsToUse, ikJntsDriveToUse, leftRight,
                          colourTU, ikSuffix, createCtrl, ikSolver, *args):
        ikSide = leftRight + ikSuffix

        ikLegName = "IK_" + ikSide
        effLegName = "EFF_" + ikSide
        ikLegs = mc.ikHandle(n=ikLegName,
                             sj=ikJntsDriveToUse[0],
                             ee=ikJntsDriveToUse[-1],
                             sol=ikSolver)
        mc.rename(ikLegs[1], effLegName)

        # we are going to hide this eventually anyways
        mc.setAttr("{0}.v".format(ikLegName), False)
        mc.setAttr("{0}.v".format(effLegName), False)

        # fkJntOffsetCtrls.append(self.createCTRLs(temp, size=9, ornt=True, colour=colourTU, orientVal=(0, 1, 0)))
        ikOffsetCtrl = None
        if createCtrl:
            # We just want to create a control at the location, we'll be parenting it.
            ikOffsetCtrl = CRU.createCTRLs(ikLegs[0],
                                           9,
                                           pnt=False,
                                           ornt=False,
                                           prnt=False,
                                           colour=colourTU,
                                           addPrefix=True,
                                           orientVal=(0, 1, 0),
                                           boxDimensionsLWH=[6, 6, 6])
            return ikLegs, ikSide, ikOffsetCtrl

        return ikLegs, ikSide
    def setupClavicle(self, jointClavicle, colourTU, leftRight,
                      shoulderOffsetCtrl, jntArmArray, *args):
        jntClav = jointClavicle[0]
        childClavicle = mc.listRelatives(jntClav, c=True, type="joint")[0]
        clavLength = mc.getAttr("{0}.ty".format(childClavicle))
        clavicleOffsetCtrl = CRU.createCTRLs(jntClav,
                                             size=6,
                                             ornt=True,
                                             colour=colourTU,
                                             orientVal=(0, 0, 1),
                                             sectionsTU=6)
        mc.select(clavicleOffsetCtrl[1] + ".cv[:]")
        mc.move(clavLength * 0.5, clavLength * 0.5, 0, r=True, ls=True)
        autoAttrName = "autoClavicle"
        mc.addAttr(clavicleOffsetCtrl,
                   longName=autoAttrName,
                   at="float",
                   k=True,
                   min=0,
                   max=1,
                   dv=0.05)
        autoName = clavicleOffsetCtrl[2]
        xprNameClav = "expr_" + leftRight + "clavicle"

        # AUTO_CTRL_l_clavicle.rotateX = JNT_l_upperArm.rotateX * CTRL_l_clavicle.autoClavicle;
        exprStringClav = self.tgpAutoClavicleRotate(autoName, jntArmArray[0],
                                                    clavicleOffsetCtrl[1],
                                                    autoAttrName)

        mc.expression(s=exprStringClav, n=xprNameClav)
        mc.parent(clavicleOffsetCtrl[0], shoulderOffsetCtrl[1])

        return clavicleOffsetCtrl
    def createFKJntAndCtrls(self, jntSize, jntEndSize, spineIKCtrls, *args):

        # create FK joints, then orient them to world
        fkJnts = []
        for i in range(0, jntSize, 2):
            if i == jntSize - 1:
                lastTerm = "end"
            else:
                lastTerm = "{0}".format(i / 2 + 1)

            pos = mc.xform(self.jointArray[i],
                           query=True,
                           translation=True,
                           worldSpace=True)
            fkJnts.append(
                mc.joint(name="JNT_FK_spine_{0}".format(lastTerm),
                         p=pos,
                         rad=jntEndSize * 2))
            mc.joint("JNT_FK_spine_{0}".format(lastTerm),
                     e=True,
                     zso=True,
                     oj="none")

        # create CTRLs, then parent them appropriately
        offsetCtrlFKJnts = [
        ]  # keeps track of the offsets so we can parent them appropriately
        for i in range(len(fkJnts[:-1])):
            # Putting into a list so the CTRL sees it properly
            offsetCtrl = CRU.createCTRLs(fkJnts[i],
                                         23,
                                         ornt=True,
                                         orientVal=(0, 1, 0),
                                         colour=17)

            offsetCtrlFKJnts.append(offsetCtrl)

        cvsToMove = mc.select(offsetCtrlFKJnts[0][1] + ".cv[:]")
        mc.move(5, cvsToMove, y=True, r=True, wd=True, ls=True)

        cvsToMove = mc.select(offsetCtrlFKJnts[-1][1] + ".cv[:]")
        mc.move(-5, cvsToMove, y=True, r=True, wd=True, ls=True)

        # put the
        # mc.parent is driven, driver
        mc.parent(offsetCtrlFKJnts[1][0], offsetCtrlFKJnts[0][1])
        mc.parent(offsetCtrlFKJnts[2][0], offsetCtrlFKJnts[1][1])

        mc.parent(spineIKCtrls[1][0], offsetCtrlFKJnts[1][1])
        mc.parent(spineIKCtrls[2][0], offsetCtrlFKJnts[2][1])

        return fkJnts, offsetCtrlFKJnts
    def createLegFKs(self, fkJnts, colourTU, isLeft, sizeVals=None, *args):
        # we want to create FK controls for the limbs except the end
        if sizeVals == None:
            sizeToUse = 10
        fkJntOffsetCtrls = []
        for i in range(len(fkJnts)):
            temp = fkJnts[i]
            try:
                sizeToUse = sizeVals[i]
            except:
                sizeToUse = 10
            # createCTRLs(self, s, size=3, prnt=False, ornt=False, pnt=False, orientVal=(1, 0, 0), colour=5, sections=None):
            fkJntOffsetCtrls.append(
                CRU.createCTRLs(temp,
                                size=sizeToUse,
                                ornt=True,
                                colour=colourTU,
                                orientVal=(0, 1, 0)))
            # checks if the object is the ball or the lowerleg. The ball because it has no value in front of it in the fkJnts, and lowerleg because the value in front of it in fkJnts
            checkers = ["ball", "lower", "ankle"]
            # checks if ball or lower leg
            if any(checker in fkJnts[i] for checker in checkers[:-1]):
                legLength = mc.getAttr("{0}.ty".format(
                    mc.listRelatives(fkJnts[i], c=True, typ="joint")[0]))
            else:
                legLength = mc.getAttr("{0}.ty".format(fkJnts[i + 1]))
            # check if the lowerleg or ankle

            # only change the thigh location
            if not any(checker in fkJnts[i] for checker in checkers):
                mc.select(fkJntOffsetCtrls[i][1] + ".cv[:]")
                mc.move(0, legLength * 0.5, 0, r=True, ls=True)

            # if the ball, modify to prettify
            if checkers[0] in fkJnts[i]:
                if isLeft:
                    mc.select(fkJntOffsetCtrls[i][1] + ".cv[4:6]")
                    # mc.move(0, 0, -sizeToUse, r=True, ls=True)
                else:
                    mc.select(fkJntOffsetCtrls[i][1] + ".cv[0:2]")
                # scale to the center
                mc.scale(1, 1, 0, p=(0, 0, 0))

                mc.move(0, 0, legLength * 0.15, r=True, ls=True)

        # parent the fk lower leg controls under the fk upper leg controls
        for i in range(len(fkJntOffsetCtrls[:-1])):
            mc.parent(fkJntOffsetCtrls[i + 1][0], fkJntOffsetCtrls[i][1])

        return fkJntOffsetCtrls
    def setupShoulder(self, jntShoulderRoot, bndJnts, fkJntOffsetCtrls,
                      colourTU, *args):
        shoulderOffsetCtrl = CRU.createCTRLs(jntShoulderRoot,
                                             size=5,
                                             ornt=True,
                                             colour=colourTU)
        shoulderLength = mc.getAttr("{0}.ty".format(bndJnts[0]))

        mc.select(shoulderOffsetCtrl[1] + ".cv[:]")
        mc.move(-shoulderLength * 0.65,
                shoulderLength * 0.8,
                0,
                r=True,
                ls=True)

        mc.parent(fkJntOffsetCtrls[0][0], shoulderOffsetCtrl[1])

        return shoulderOffsetCtrl
    def createToeFKs(self, fkJnts, colourTU, isLeft, *args):

        fkJntOffsetCtrls = []
        for fkJnt in fkJnts:
            fkToeOffsetCtrls = []
            # we want to create FK controls for the toes except the end
            for i in range(len(fkJnt[:-1])):
                temp = fkJnt[i]

                if i == 0:
                    theSize = .95
                elif "thumb" in temp:
                    theSize = 2
                elif "pink" in temp:
                    theSize = .85
                else:
                    theSize = 1.25
                fkToeOffsetCtrls.append(
                    CRU.createCTRLs(temp,
                                    size=theSize,
                                    ornt=True,
                                    colour=colourTU,
                                    orientVal=(0, 1, 0)))
                toeLength = mc.getAttr("{0}.ty".format(fkJnt[i + 1]))

                mc.select(fkToeOffsetCtrls[i][1] + ".cv[:]")
                if isLeft:
                    moveZ = -3
                else:
                    moveZ = 3
                if i == 0:
                    mc.move(0, 0, moveZ, r=True, ls=True)
                else:
                    mc.move(0, toeLength * 0.5, 0, r=True, ls=True)
            fkJntOffsetCtrls.append(fkToeOffsetCtrls)

        # parents the toes fks under each other
        for i in range(len(fkJntOffsetCtrls)):
            for j in range(len(fkJntOffsetCtrls[i]) - 1):
                mc.parent(fkJntOffsetCtrls[i][j + 1][0],
                          fkJntOffsetCtrls[i][j][1])

        return fkJntOffsetCtrls
    def createIKSpineCtrls(self, crvSpine, ikMidSpine, ikChest, ikHip,
                           spineIKs, *args):
        '''
        Bind To: Selected Joints
        Bind Method: Closest Distance
        Skinning Method: Classic Linear
        Normalize Weights: Interactive
        '''
        mc.select(crvSpine, ikMidSpine, ikChest, ikHip)

        # mc.skinCluster (ikHip, ikMidSpine, ikChest, crvSpine, sm=0, nw = 1)

        scls = mc.skinCluster(ikMidSpine,
                              ikChest,
                              ikHip,
                              crvSpine,
                              name='spine_skinCluster',
                              toSelectedBones=True,
                              bindMethod=0,
                              skinMethod=0,
                              normalizeWeights=1)[0]

        # create controls for IK Spines
        spineIKCtrls = []
        spineIKSizes = [[1, 26, 20], [1, 28, 20], [1, 15, 15]]

        for i in range(len(spineIKs)):
            spineIKCtrls.append(
                CRU.createCTRLs(spineIKs[i],
                                19,
                                prnt=True,
                                colour=18,
                                boxDimensionsLWH=spineIKSizes[i]))

        # make the neck area more appealing
        '''cvsToMove = mc.select(spineIKCtrls[-1][1] + ".cv[:]")
        mc.rotate(-20, cvsToMove, y=True)
        mc.move(-2, cvsToMove, x=True, r=True, wd=True, ls=True)
        mc.move(2, cvsToMove, z=True, r=True, wd=True, ls=True)'''

        return spineIKCtrls
    def createArmFKs(self, fkJnts, colourTU, *args):
        # we want to create FK controls for the limbs except the end
        fkJntOffsetCtrls = []
        for i in range(len(fkJnts[:-1])):
            temp = fkJnts[i]

            # def createCTRLs(self, s, size=3, prnt=False, ornt=False, pnt=False, orientVal=(1, 0, 0), colour=5, sections=None):
            fkJntOffsetCtrls.append(
                CRU.createCTRLs(temp,
                                size=9,
                                ornt=True,
                                colour=colourTU,
                                orientVal=(0, 1, 0)))
            armLength = mc.getAttr("{0}.ty".format(fkJnts[i + 1]))
            mc.select(fkJntOffsetCtrls[i][1] + ".cv[:]")
            mc.move(0, armLength * 0.5, 0, r=True, ls=True)

        # parent the fk lower arm controls under the fk upper arm controls
        mc.parent(fkJntOffsetCtrls[1][0], fkJntOffsetCtrls[0][1])

        return armLength, fkJntOffsetCtrls
    def createHipCtrl(self, ikHip, spineIKCtrls, *args):
        # create hip controls

        fkHip = mc.duplicate(ikHip, n="JNT_FK_hip")
        # delete the children
        fkHipChilds = mc.listRelatives(fkHip[0], ad=True, f=True)
        mc.delete(fkHipChilds)
        fkHip = fkHip[0]

        fkHipEnd = mc.duplicate(fkHip, n="JNT_FK_hipEnd")[0]
        mc.move(-20, fkHipEnd, y=True, r=True)
        valToMove = mc.getAttr("{0}.ty".format(fkHipEnd))

        mc.parent(fkHipEnd, fkHip)

        fkHipOffsetCtrl = CRU.createCTRLs(fkHip, 27, prnt=True, colour=17)
        cvsToMove = mc.select(fkHipOffsetCtrl[1] + ".cv[:]")
        mc.move(-10, cvsToMove, x=True, r=True, wd=True, ls=True)

        mc.parent(fkHipOffsetCtrl[0], spineIKCtrls[0][1])
        mc.parent(fkHip, ikHip)

        return fkHip, fkHipOffsetCtrl
Ejemplo n.º 12
0
    def createPalmCtrls(self, jntPalmBase, leftRight, colourTU, jntPalm,
                        isLeft, *args):

        # create the CTRL, then move it
        handOffsetCtrl = CRU.createCTRLs(jntPalmBase,
                                         5,
                                         ornt=True,
                                         pnt=True,
                                         colour=colourTU,
                                         orientVal=(1, 0, 0))
        handLength = mc.getAttr("{0}.ty".format(jntPalm[1]))
        mc.select(handOffsetCtrl[1] + ".cv[:]")
        moveX = -handLength / 2
        mc.move(moveX, handLength * 0.5, 0, r=True, ls=True)

        # add the twist limits for the wrists:
        lowerTwistVal = "lowerArmTwist"
        upperTwistVal = "upperArmTwist"
        mc.addAttr(handOffsetCtrl[1],
                   longName=lowerTwistVal,
                   at="float",
                   k=True,
                   min=0,
                   max=1,
                   dv=1)
        mc.addAttr(handOffsetCtrl[1],
                   longName=upperTwistVal,
                   at="float",
                   k=True,
                   min=0,
                   max=1,
                   dv=1)

        # get the expression (this is a bit unique to me) then edit it
        armExprName = "expr" + leftRight + "armTwist"
        armExpr = mc.expression(armExprName, q=True, s=True)

        ctrlPalmName = "CTRL" + leftRight + "palm"
        armExpr = armExpr.replace("armEnd", "palm")
        armExpr = armExpr.replace("JNT" + leftRight + "palm", ctrlPalmName)
        editExpr = armExpr.splitlines()
        for i in range(len(editExpr)):
            if "lowerArm.rotate" in editExpr[i]:
                # if we're rotating the upper arm twists with the lower arm
                replaceTwistVal = upperTwistVal
            elif "palm.rotate" in editExpr[i]:
                # if we're rotating the lower arm twists with the palm
                replaceTwistVal = lowerTwistVal

            editExpr[i] = editExpr[i].replace(
                ";", " * {0}.{1};\n".format(ctrlPalmName, replaceTwistVal))
            # print(editExpr[i])

        armExprReplace = "".join(editExpr)
        # print(armExprReplace)
        mc.delete(armExprName)

        mc.expression(s=armExprReplace, n=armExprName)

        # change the rotation order
        toRotateChange = [handOffsetCtrl[1], jntPalmBase]
        CRU.changeRotateOrder(toRotateChange, "YZX")

        return handOffsetCtrl
Ejemplo n.º 13
0
    def createNeckHeadCtrls(self, ctrlIKChest, grpJntSpine, checkboxSpine,
                            *args):
        listCtrls = ["neck", "head", "jaw1"]
        headOffsetCtrls = []
        specVal = 0
        for i in range(len(self.jointArray)):
            val = str(self.jointArray[i])
            colourTU = 17

            if any(x in val for x in listCtrls):
                # if the neck, do the following
                if listCtrls[0] in val:
                    sizeCtrl = 10
                    orntVal = (0, 1, 0)
                    headOffsetCtrls.append(
                        CRU.createCTRLs(val,
                                        prnt=False,
                                        ornt=True,
                                        size=sizeCtrl,
                                        orientVal=orntVal,
                                        colour=colourTU))

                    child = mc.listRelatives(val, c=True)[0]
                    boneLength = mc.getAttr("{0}.ty".format(child))

                    mc.select(headOffsetCtrls[specVal][1] + ".cv[:]")
                    mc.move(boneLength * .2, z=True, r=True, os=True, wd=True)
                elif listCtrls[1] in val:
                    # if the head, do the following
                    sizeCtrl = 15
                    orntVal = (0, 1, 0)

                    boneLength = mc.getAttr("{0}End.ty".format(val))
                    headOffsetCtrls.append(
                        CRU.createCTRLs(val,
                                        prnt=False,
                                        ornt=True,
                                        size=sizeCtrl,
                                        orientVal=orntVal,
                                        colour=colourTU))
                    mc.select(headOffsetCtrls[specVal][1] + ".cv[:]")
                    mc.move(boneLength * .65, y=True, r=True)

                elif listCtrls[2] in val:
                    # if the jaw, do the following
                    sizeCtrl = 3
                    orntVal = (0, 1, 0)
                    # get the length of the bone
                    getBoneChild = mc.listRelatives(val, type="joint", ad=True)
                    boneLength = mc.getAttr("{0}.ty".format(getBoneChild[0]))
                    boneLength2 = mc.getAttr("{0}.ty".format(getBoneChild[1]))
                    headOffsetCtrls.append(
                        CRU.createCTRLs(val,
                                        prnt=False,
                                        ornt=True,
                                        pnt=True,
                                        size=sizeCtrl,
                                        orientVal=orntVal,
                                        colour=colourTU))
                    # move the CVs into place
                    mc.select(headOffsetCtrls[specVal][1] + ".cv[:]")
                    mc.move(0, -boneLength2 * 2, boneLength * 1.1, r=True)

                specVal += 1

        mc.parent(headOffsetCtrls[1][0], headOffsetCtrls[0][1])
        mc.parent(headOffsetCtrls[2][0], headOffsetCtrls[1][1])
        mc.parent(headOffsetCtrls[3][0], headOffsetCtrls[2][1])

        # CTRL_neck1 point constrains JNT_neck1
        # parent OFFSET_CTRL_neck1 under CTRL_IK_chest
        if checkboxSpine:
            mc.pointConstraint(headOffsetCtrls[0][1], self.jointArray[0])
            noUnicode = str(self.jointArray[0])
            grpHead = mc.group(n="GRP_JNT_head", w=True, em=True)
            mc.parent(noUnicode, grpHead)

            mc.parent(headOffsetCtrls[0][0], ctrlIKChest)

            # was originally GRP_JNT_torso, but changed to GRP_rig_torso
            grpTorso = mc.group(n="GRP_rig_torso", w=True, em=True)
            mc.parent(grpHead, grpJntSpine, grpTorso)

        return headOffsetCtrls