I understand how to use animation curves in Unity, but I'm more interested in how Unity actually evaluates an animation curve at a given point. In other words, what is the math behind the function Evaluate? The reason I ask is that I have a lot of animation data in animation curve format: time, value, in tangent, out tangent. I want to convert this data into splines like bezier curves or other functions, but I am not sure what the formula for this conversion would be. Anyone have ideas?
(comments are locked)

Alright ,so empiricaly I found something that matches exactly the animation curve drawn by unity ... it can be drawn as a bezier curve ... as you know the AnimationCurve of Unity , has .time and .value for the two keyframes of the segment(lets call the two endpoints P1,P2, time is x and value is y coordinate), and a out tangent(first point) and in tangent(2nd point) , can be called tgOut and tgIn. The Bezier curve (the cubic one),its equation is well known,can be found on wiki, has aside the 2 end points(P1,P2), 2 control points ... let's call them C1 , C2 . We have to corelate C1,C2 with tgOut and tgIn ,this relation is not given by unity,and I found it empiricaly:
//draw now the bezier using p1,c1,c2,p2
ratio = (gridRect.height/gridRect.width)(gradRect.width/gradRect.height) then tgOut* is ratiocurve[i].outTangent and tgIn* is ratio*curve[i+1].inTangent (where curve is of type AnimationCurve)
(comments are locked)

It should be something like this:
have you tried this one,did you drawn twice the curve ?, me I drawn the curve twice,once using directly the evaluate method from unity and once with the formula I explained above your comment ... and the curves are matching 99,9%..of course the tangents needs scaling with the aspect ratio ... what I see strange in your method, is that you evaluate by 't' :) ... the unity evaluates by time...so perhaps from that time it's finding the 't' and then back the keyframe.value ... in my case ,what I needed was just to have bezier curve exactly matching the curve drawn by unity
Aug 06 '13 at 10:16 AM
Varaughe
t is from 0 to 1 in this case, i.e. t = Mathf.InverseLerp(keyframe0.time, keyframe1.time, time)
Aug 06 '13 at 11:46 AM
Paulius Liekis
No, I haven't tried it myself. I copied this function from one of my projects (this is slightly modified version). As far as I remember Unity uses this kind of code (a bit more optimized).
Aug 06 '13 at 11:49 AM
Paulius Liekis
(comments are locked)

It uses Bezier Curves, like it should. If you want to evaluate those, you can do a quick google search :)
well of course is bezier curves(which can be represented as hermit also),but it's not that cubic bezier curve,which anyone knows,I mean the factors are particular for the unity implementation ... at a moment I also thought they are using only trigonometric function ... whichever way,it would be of great help the exact formula