【问题标题】:Unity Curve Evaluate is normalised time, or what units?Unity Curve Evaluate 是归一化时间,还是什么单位?
【发布时间】:2021-09-20 10:35:48
【问题描述】:

动画曲线上的Evaluate 函数一次获取一个值。

https://docs.unity3d.com/ScriptReference/AnimationCurve.Evaluate.html

但不清楚(对我来说)使用什么时基或单位。

对于ParticleSystem.MinMaxCurve,这被明确描述为被评估为曲线持续时间的归一化 0 到 1 范围值:

https://docs.unity3d.com/ScriptReference/ParticleSystem.MinMaxCurve.Evaluate.html

标准化时间(在 0 - 1 范围内,其中 1 表示 100%) 来评估曲线。这在以下情况下有效 ParticleSystem.MinMaxCurve.mode 设置为 ParticleSystemCurveMode.Curve 或 ParticleSystemCurveMode.TwoCurves。

更新:

对于那些考虑性能的人: AnimationCurve 的 Evaluate 在 Unity 的 MonoBehaviour 世界的传统意义上非常快,具有缓存查找周围键的内置方法,并保留最后评估的位置。因此,在评估循环中尤其快。由 Unity 优化的高度老式的学校。

但是,ParticleSystem.MinMaxCurve 的评估受益于 UnityEngine.ParticleSystemJobs 功能的 Jobs 友好更新,并且是其一部分。

在少量使用中(大约 1000 个评估步骤或更少),它们大致相同。但是有了 Jobs 和大量细粒度的评估(超过 10,000 次),MinMaxCurve 取得了领先。

【问题讨论】:

    标签: c# unity3d time curve evaluate


    【解决方案1】:

    它在大多数情况下使用01,但完全取决于您如何配置和使用您的...您可以轻松地扩展AnimationCurve,在0 之前和1 之前使用关键帧。

    但是,您可以获取 AnimationCurve 的持续时间,因此基本上您可以使用以下方法将任何动画曲线归一化为 01 之间的“时间”值

    public static class AniamtionCurveUtils
    {
        public static float EvaluateNormalizedTime(this AnimationCurve curve, float normalizedTime)
        {
            if(curve.length <= 0)
            {
                Debug.LogError("Given curve has 0 keyframes!");
                return float.NaN;
            }
    
             // get the time of the first keyframe in the curve
            var start = curve[0].time;
    
            if(curve.length == 1) 
            {
                Debug.LogWarning("Given curve has only 1 single keyframe!");
                return start;
            }
    
            // get the time of the last keyframe in the curve
            var end = curve[curve.length - 1].time;
           
            // get the duration fo the curve
            var duration = end - start;
            
            // get the de-normalized time mapping the input 0 to 1 onto the actual time range 
            // between start and end
            var actualTime = start + Mathf.Clamp(normalizedTime, 0, 1) * duration;
    
            // finally use that calculated time to actually evaluate the curve
            return curve.Evaluate(actualTime);
        }
    }
    

    然后例如

    var someValue = someCurve.EvaluateNormalizedTime(someNormalizedTime);
    

    【讨论】:

    • 你是人类的瑰宝。你怎么可能知道 AnimationCurve?
    • @Confused 经验 ;)
    猜你喜欢
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 2016-02-02
    • 1970-01-01
    • 2012-04-24
    • 1970-01-01
    相关资源
    最近更新 更多