Beispiel #1
0
    def tangentOppositeReorder(self, indexes, values):
        # put bigger segments first

        difList = []
        for n, loopVal in enumerate(values[2:-3]):
            dif = values[n + 1 + 2] - values[n + 2]
            difList.append(abs(dif))

        indexList = []
        tmpDifList = utilMod.dupList(difList)
        for n, loopDif in enumerate(tmpDifList):
            maxDif = max(tmpDifList)
            index = difList.index(maxDif)
            tmpDifList[index] = -1
            indexList.append(index)

        newIndexes = []
        for loopIndex in indexList:
            if loopIndex in indexes:
                newIndexes.append(loopIndex)

        """       
        print "indexList",indexList 
        print "values",values 
        print "difList",difList      
        print "indexes",indexes
        print "newIndexes",newIndexes
        """

        return newIndexes
Beispiel #2
0
    def tangType(self, keyVal, keyTimes, index):

        keyValTmp = utilMod.dupList(keyVal)

        keyLocation = self.getKeyLocation(keyValTmp, index)
        nKeys = len(keyValTmp)

        if keyLocation == "first":
            if keyValTmp[index] == keyValTmp[index + 1] == keyValTmp[index + 2]:
                return "Zero"
        elif keyLocation == "last":
            if keyValTmp[index] == keyValTmp[index - 1] == keyValTmp[index - 2]:
                return "Zero"
        else:
            index += 2
            for x in xrange(2):
                keyValTmp.insert(0, keyValTmp[0])
                keyValTmp.append(keyValTmp[-1])

            if (
                keyValTmp[index] == keyValTmp[index + 1] == keyValTmp[index + 2]
                or keyValTmp[index] == keyValTmp[index - 1] == keyValTmp[index - 2]
                or keyValTmp[index] == keyValTmp[index + 1] == keyValTmp[index - 1]
            ):
                return "Zero"

        # or....
        return "Average"
Beispiel #3
0
    def applyPass(self, passes, animCurves, keyTimes, keyValues, keysIndexSel, tangentType):

        newKeysIndexSel = utilMod.dupList(keysIndexSel)

        for loopFunction in passes:

            # utilMod.timer("s")

            for n, aCurve in enumerate(animCurves):

                if keysIndexSel != None and keyTimes[n] != None and keysIndexSel[n] != None and len(keyTimes[n]) >= 2:

                    # utilMod.timer()

                    # unlock weights
                    weighted = cmds.keyTangent(aCurve, query=True, weightedTangents=True)[0]
                    locked = cmds.keyTangent(aCurve, query=True, lock=True)

                    # utilMod.timer()

                    if weighted:
                        cmds.keyTangent(
                            aCurve, edit=True, weightedTangents=False
                        )  # weight to balance in and out tangents
                    cmds.keyTangent(aCurve, edit=True, weightedTangents=True)

                    # utilMod.timer()

                    if loopFunction == self.fixTangentOpposite:
                        # remove last index
                        if len(keysIndexSel[n]) > 0:
                            keysIndexSel[n].pop()
                        if len(newKeysIndexSel[n]) > 0:
                            newKeysIndexSel[n].pop()
                        # reorder index according with size of segment
                        keysIndexSel[n] = self.tangentOppositeReorder(keysIndexSel[n], keyValues[n])

                    # utilMod.timer()

                    # apply the damn function
                    for loopIndex in keysIndexSel[n]:

                        curTangType = self.tangType(keyValues[n], keyTimes[n], loopIndex)

                        applied = loopFunction(
                            aCurve, keyValues[n], loopIndex, tangentType, curTangType, keysIndexSel[n], keyTimes[n]
                        )

                        if loopFunction == self.fixTangentOvershoot and applied:
                            # remove the applied index to avoid changind that tangent again
                            if newKeysIndexSel[n]:
                                newKeysIndexSel[n].remove(loopIndex)

                    # utilMod.timer()

                    # put back
                    for i, loopLocked in enumerate(locked):
                        cmds.undoInfo(stateWithoutFlush=False)
                        if loopLocked:
                            cmds.keyTangent(aCurve, edit=True, index=(i, i), lock=loopLocked)
                        cmds.undoInfo(stateWithoutFlush=True)

                    # utilMod.timer()

                    if weighted:
                        cmds.keyTangent(
                            aCurve, edit=True, weightedTangents=False
                        )  # weight to balance in and out tangents
                    cmds.keyTangent(aCurve, edit=True, weightedTangents=weighted)