【问题标题】:How to get bone transform for a particular animation frame如何为特定的动画框架获得骨骼变换
【发布时间】:2013-08-11 13:08:41
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: animation unity3d


    【解决方案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;(假设关键帧是均匀间隔的。)

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

    【讨论】:

    • 我应该提到我拥有的动画是与 fbx 模型一起导入的,因此是剪辑而不是状态(或者我做错了什么?)
    猜你喜欢
    • 2017-01-30
    • 2013-08-19
    • 2023-03-23
    • 2012-10-17
    • 2020-09-27
    • 2015-07-21
    • 2016-02-26
    • 2014-10-16
    • 2017-04-10
    相关资源
    最近更新 更多