I need to transfer animation from 3d party animation software ([spine][1]) in to unity.
Here is how it looks in spine
![alt text][2]
according to [this page][3]
> The Bézier curve array has 4 elements which define the control points: cx1, cy1, cx2, cy2. The X axis is from 0 to 1 and represents the percent of time between the two keyframes. The Y axis is from 0 to 1 and represents the percent of the difference between the keyframe’s values.
here is what I see in input data
[ 0.135, 0.74, 0.918, 0.17 ]
and this is cooridnates for **P1** = (0.135, 0.74) and **P2** = (0.918, 0.17).
for all cases **P0** = (0,0), **P3** = (1,1)
At unity side, i need to provide **outTangent** for P0 and **inTangent** for P3 which is **keyframe[0]** and **keframe[1]** in case of curve has just 2 points.
here is my calculation (which doesn't show correct result):
**i** and **nextI** is a keyframe indexes of **P0** and **P3** in AnimationCurve,
**tangentArray** is json array contains data specified above **[cx1,cy1,cx2,cy2]**
**parseFloat** custom method, i can't use default (float)cx1 or float.parse(cx1)
public static void setCustomTangents(AnimationCurve curve, int i, int nextI, JsonData tangentArray){
float cx1 = parseFloat(tangentArray[0]);
float cy1 = parseFloat(tangentArray[1]);
float cx2 = parseFloat(tangentArray[2]);
float cy2 = parseFloat(tangentArray[3]);
float time = (float)(curve.keys[nextI].time - curve.keys[i].time);
float value = (float)(curve.keys[nextI].value - curve.keys[i].value);
Keyframe thisKeyframe = curve[i];
Keyframe nextKeyframe = curve[nextI];
float outTangent = (cy1 * value)/ (cx1 * time);
float inTangent = ((1 - cy2) * value)/ ((1 - cx2) * time);
thisKeyframe.outTangent = outTangent;
nextKeyframe.inTangent = inTangent;
curve.MoveKey(i, thisKeyframe);
curve.MoveKey(nextI, nextKeyframe);
}
This is result in unity
![alt text][4]
I've already seen some similar bezier questions like [The algorithm of curve in Shuriken Particle System][5]. But 2d day can't figure out how to solve this problem, probably because my math skills is low =).
Thanks.
[1]: http://esotericsoftware.com
[2]: /storage/temp/21030-spinecurve.png
[3]: http://esotericsoftware.com/spine-json-format/
[4]: /storage/temp/21031-unity_curve.png
[5]: http://answers.unity3d.com/questions/438407/the-algorithm-of-curve-in-shuriken-particle-system.html
Trending Articles
More Pages to Explore .....