def fixTangentOpposite(self, aCurve, keyVal, index, tangentType, curTangType, keysIndexSelN, *args): if index == None: return currVal = keyVal[index] nextVal = keyVal[index + 1] currTime = cmds.keyframe(aCurve, query=True, index=(index, index), timeChange=True)[0] # current time value nextTime = cmds.keyframe(aCurve, query=True, index=(index + 1, index + 1), timeChange=True)[ 0 ] # current time value power = 2 # get in values for next key ix = cmds.keyTangent(aCurve, query=True, index=(index + 1, index + 1), ix=True)[ 0 ] # in tangent handle x position iy = cmds.keyTangent(aCurve, query=True, index=(index + 1, index + 1), iy=True)[ 0 ] # in tangent handle y position # get out values ox = cmds.keyTangent(aCurve, query=True, index=(index, index), ox=True)[0] # out tangent handle x position oy = cmds.keyTangent(aCurve, query=True, index=(index, index), oy=True)[0] # out tangent handle y position # curve position at handle valIn = ( nextVal - cmds.keyframe( aCurve, query=True, eval=True, time=(nextTime - ix / 0.125, nextTime - ix / 0.125), valueChange=True )[0] ) valOut = ( cmds.keyframe( aCurve, query=True, eval=True, time=(currTime + ox / 0.125, currTime + ox / 0.125), valueChange=True )[0] - currVal ) # convert to radians if rotate isRotate = animMod.isAnimCurveRotate(aCurve) if isRotate: currVal = math.radians(currVal) nextVal = math.radians(nextVal) valIn = math.radians(valIn) valOut = math.radians(valOut) # difference btw val and y difIn = iy / 3 - valIn difOut = oy / 3 - valOut # detect if (difIn > 0 and difOut > 0) or (difIn < 0 and difOut < 0): if abs(difIn) > abs(difOut): inOut = "in" else: inOut = "out" for x in xrange(5): currVal = keyVal[index] nextVal = keyVal[index + 1] # get in values for next key ix = cmds.keyTangent(aCurve, query=True, index=(index + 1, index + 1), ix=True)[ 0 ] # in tangent handle x position iy = cmds.keyTangent(aCurve, query=True, index=(index + 1, index + 1), iy=True)[ 0 ] # in tangent handle y position # get out values ox = cmds.keyTangent(aCurve, query=True, index=(index, index), ox=True)[ 0 ] # out tangent handle x position oy = cmds.keyTangent(aCurve, query=True, index=(index, index), oy=True)[ 0 ] # out tangent handle y position # curve position at handle valIn = ( nextVal - cmds.keyframe( aCurve, query=True, eval=True, time=(nextTime - ix / 0.125, nextTime - ix / 0.125), valueChange=True, )[0] ) valOut = ( cmds.keyframe( aCurve, query=True, eval=True, time=(currTime + ox / 0.125, currTime + ox / 0.125), valueChange=True, )[0] - currVal ) # convert to radians if rotate isRotate = animMod.isAnimCurveRotate(aCurve) if isRotate: currVal = math.radians(currVal) nextVal = math.radians(nextVal) valIn = math.radians(valIn) valOut = math.radians(valOut) # difference btw val and y difIn = iy / 3 - valIn difOut = oy / 3 - valOut if inOut == "in": # print"IN" # if next key is is array if index + 1 in keysIndexSelN: newY = (iy / 3) + (valOut - (oy / 3)) * power cmds.keyTangent( aCurve, edit=True, index=(index + 1, index + 1), iy=newY * 3, oy=newY * 3, ox=ix ) else: # print"OUT" newY = (oy / 3) + (valIn - (iy / 3)) * power cmds.keyTangent(aCurve, edit=True, index=(index, index), iy=newY * 3, oy=newY * 3, ix=ox) """
def flowTangent(self, aCurve, keyVal, index, tangentType, curTangType, *args): if curTangType == "Zero" and tangentType == "flow": return if index == None: return # is it first or last key? keyLocation = self.getKeyLocation(keyVal, index) if keyLocation != "mid" and tangentType != "bounce": return currVal = keyVal[index] currTime = cmds.keyframe(aCurve, query=True, index=(index, index), timeChange=True)[0] # current time value # get in values ix = cmds.keyTangent(aCurve, query=True, index=(index, index), ix=True)[0] # in tangent handle x position iy = cmds.keyTangent(aCurve, query=True, index=(index, index), iy=True)[0] # in tangent handle y position # get out values ox = cmds.keyTangent(aCurve, query=True, index=(index, index), ox=True)[0] # out tangent handle x position oy = cmds.keyTangent(aCurve, query=True, index=(index, index), oy=True)[0] # out tangent handle y position cmds.undoInfo(stateWithoutFlush=False) cmds.keyTangent(aCurve, index=(index, index), lock=False) cmds.undoInfo(stateWithoutFlush=True) if tangentType == "flow": if ox > ix: ox = ix oy = iy cmds.keyTangent(aCurve, edit=True, index=(index, index), ox=ox, oy=oy) else: ix = ox iy = oy cmds.keyTangent(aCurve, edit=True, index=(index, index), ix=ix, iy=iy) # curve position at handle valIn = cmds.keyframe( aCurve, query=True, eval=True, time=(currTime - ix / 0.125, currTime - ix / 0.125), valueChange=True )[0] valOut = cmds.keyframe( aCurve, query=True, eval=True, time=(currTime + ox / 0.125, currTime + ox / 0.125), valueChange=True )[0] # if the anim curve is rotate, convert to radians isRotate = animMod.isAnimCurveRotate(aCurve) if isRotate: currVal = math.radians(currVal) valIn = math.radians(valIn) valOut = math.radians(valOut) # print "isrotate" # distance between the curve position and the key value distValueIn = valIn - currVal distValueOut = valOut - currVal # distance between the curve position and the tangent y position distTangIn = distValueIn + (iy / 3) distTangOut = distValueOut - (oy / 3) if tangentType == "flow": # calculate the difference btween the distances between the curve position and the tangent y position dif = distTangIn - distTangOut newOy = (oy / 3) - dif # newIy = (iy/3)-dif newIy = newOy # print "newIy",newIy,"(iy/3)",(iy/3),"(oy/3)",(oy/3),"currVal",currVal,"valOut",valOut,"distIn",distTangIn,"distOut",distTangOut,"dif",dif,"distValueIn",distValueIn,"distValueOut",distValueOut elif tangentType == "bounce": newIy = -distValueIn + (-distValueIn - (iy / 3)) newOy = distValueOut + (distValueOut - (oy / 3)) """ print "---------------------------" print "newIy",newIy print "newOy",newOy print "(iy/3)",(iy/3) print "(oy/3)",(oy/3) print "currVal",currVal print "valOut",valOut print "distIn",distTangIn print "distOut",distTangOut print "distValueIn",distValueIn print "distValueOut",distValueOut """ # apply cmds.keyTangent(aCurve, edit=True, index=(index, index), iy=newIy * 3, oy=newOy * 3)
def fixTangentOvershoot(self, aCurve, keyVal, index, tangentType, curTangType, keysIndexSelN, *args): # print "qual index? ", index if index == None: return # fix tangent limit ---------------------------------------------------------------------------- applied = False power = 0.8 # get in values iy = ( cmds.keyTangent(aCurve, query=True, index=(index, index), iy=True)[0] / 3 * power ) # in tangent handle y position oy = ( cmds.keyTangent(aCurve, query=True, index=(index, index), oy=True)[0] / 3 * power ) # out tangent handle y position prevVal = keyVal[index - 1] currVal = keyVal[index] nextVal = keyVal[index + 1] # convert to radians if rotate isRotate = animMod.isAnimCurveRotate(aCurve) if isRotate: prevVal = math.radians(prevVal) currVal = math.radians(currVal) nextVal = math.radians(nextVal) difNext = (nextVal - currVal) * power difPrev = (currVal - prevVal) * power if (difNext < 0 and oy < difNext) or (difNext > 0 and oy > difNext): cmds.keyTangent(aCurve, edit=True, index=(index, index), inTangentType="auto", outTangentType="auto") cmds.keyTangent(aCurve, edit=True, index=(index, index), oy=difNext * 3) applied = True if (difPrev < 0 and iy < difPrev) or (difPrev > 0 and iy > difPrev): cmds.keyTangent(aCurve, edit=True, index=(index, index), inTangentType="auto", outTangentType="auto") cmds.keyTangent(aCurve, edit=True, index=(index, index), iy=difPrev * 3) # print "aplicou index:", index if index - 1 in keysIndexSelN: cmds.keyTangent( aCurve, edit=True, index=(index - 1, index - 1), inTangentType="auto", outTangentType="auto" ) self.flowTangent(aCurve, keyVal, index - 1, tangentType) applied = True # print "flow index:", index-1 """ print "--------------------------------" print "index", index print "iy",iy print "oy",oy print "difPrev",difPrev print "prevVal",prevVal print "nextVal",nextVal print "currVal",currVal """ return applied