1

我有一个大约 20 帧的动画。我需要能够访问给定动画帧的每个骨骼的本地变换。我知道如何访问骨骼及其局部变换(代码示例)

Transform root, spine1;
getChildFromName(gameObj, "Jnt_Root", out root);
getChildFromName(root, "Jnt_Spine1", out spine1);
spine1.localRotation = someValue;

所有这些工作正常,但我不知道我得到的值来自哪个动画帧?我假设它从第 1 帧开始(可以使用调试器进行验证,但这不是重点)

问题是如何为特定框架获取和设置这些值?谢谢!

4

1 回答 1

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;假设关键帧是均匀间隔的。)

存储后,您应该可以直接修改转换,但我从未尝试过。

于 2013-08-12T13:32:15.620 回答