animation - 如何获取特定动画帧的骨骼变换

标签 animation unity-game-engine

我有一个大约 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/

相关文章:

RecyclerView 项目的 Android 动画问题

ios - 停止打字机动画并快速显示全文

android - CardView动画: raise and expand on click?

animation - Unity-停止动画循环

android - 没有AnimationDrawable可以做逐帧动画吗?

swift - 我需要一个 UIButton 飞入屏幕

c# - 游戏打开时如何打开任何特定场景

javascript - 从浏览器向 Unity3D 发送消息

ios - 结合-OpenGL-ES-Cocos2d 功能-和-OpenGL-ES-(Unity 3d) 导航--在-iOS-app 内

c# - Unity 在 Visual Studio 中找不到使用 Nuget 安装的包