Hello,
I would like to retrieve the Transform/Position of an animationClip at a given time/frame.
Is that possible ? If not, do you have any possible alternative ?
Thank you
Hello,
I would like to retrieve the Transform/Position of an animationClip at a given time/frame.
Is that possible ? If not, do you have any possible alternative ?
Thank you
I’ve found the solution, it takes a lot of process, but as it’s done only in Editor it doesn’t affect the game. I am getting the curve of the animationclip and I store 10 position, each corresponding to 10% of the animation.
For this I need to compute each x, y and z axis curves :
void OnValidate()
{
//Check if we are in the Editor, and the animationClip is getting change
if (Application.isEditor && !Application.isPlaying && previousClip != animationClip)
{
previousClip = animationClip;
m_checkPoints = new Vector3[10];
int index = 0;
//Taking the curves form the animation clip
AnimationCurve curve;
var curveBindings = AnimationUtility.GetCurveBindings(animationClip);
//Going into each curves
foreach (var curveBinding in curveBindings)
{
//Checking curve's name, as we only need those about the position
if (curveBinding.propertyName == "m_LocalPosition.x")
index = 0;
else if (curveBinding.propertyName == "m_LocalPosition.y")
index = 1;
else if (curveBinding.propertyName == "m_LocalPosition.z")
index = 2;
else
continue;
//Get the curveform the editor
curve = AnimationUtility.GetEditorCurve(animationClip, curveBinding);
for (float i = 1; i < 11; i++)
{
//Evaluate the curves at a given time
if(i == 1)
m_checkPoints[(int)i - 1][index] = curve.Evaluate(0);
else
m_checkPoints[(int)i - 1][index] = curve.Evaluate(animationClip.length * (i / 10));
}
}
}
}
}