我有一个大约 20 帧的动画。我需要能够访问给定动画帧的每个骨骼的本地变换。我知道如何访问骨骼及其局部变换(代码示例)
Transform root, spine1;
getChildFromName(gameObj, "Jnt_Root", out root);
getChildFromName(root, "Jnt_Spine1", out spine1);
spine1.localRotation = someValue;
所有这些工作正常,但我不知道我得到的值来自哪个动画帧?我假设它来自第 1 帧(可以使用调试器进行验证,但这不是重点)
问题是如何获取和设置特定框架的这些值?谢谢!
最佳答案
类似这样的东西应该可以用于获取当前的转换:
AnimationState state = animation["your_animation"];
state.enabled = true;
state.normalizedTime = (1.0f/totalAnimationTime) * specificFrame;
animation.Sample();
// get all transforms of this animation, extract your root and spine from here.
Transform[] transforms = animation.gameObject.GetComponentsInChildren<Transform>();
或者,如果您尝试在动画运行时进行采样,您可以执行以下操作:
if(animation["your_animation"].normalizedTime > 0.3 && animation["your_animation"].normalizedTime < 0.5) {
//... do something at this point in time. You'll have to figure out the frame
//from the time
}
上次我检查过您无法显式提取特定帧。但是,如果您知道动画的总长度(时间方面),则可以使用以下命令将动画移动到该点:(1.0f/totalAnimationTime) * SpecificFrame;
(假设关键帧是均匀间隔。)
存储后,您应该能够直接修改转换,但我从未尝试过。
关于animation - 如何获取特定动画帧的骨骼变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18149434/