public static int Bake(ref Keyframe[] keys, float frameRate, InterpolationMode mode = InterpolationMode.Auto)
    {
        var   nativeKeys = new NativeArray <Keyframe>(keys, Allocator.Temp);
        float duration   = keys[keys.Length - 1].time - keys[0].time;
        int   frameCount = (int)math.ceil(frameRate * duration);
        var   bakedKeys  = new NativeArray <Keyframe>(frameCount, Allocator.Temp);

        ThreadSafe.Bake(nativeKeys, frameRate, bakedKeys, new SampleRange()
        {
            startFrameIndex = 0, numFrames = frameCount
        });

        switch (mode)
        {
        case InterpolationMode.Linear:
            KeyframeUtilities.AlignTangentsLinear(bakedKeys);
            break;

        case InterpolationMode.Auto:
            KeyframeUtilities.AlignTangentsSmooth(bakedKeys);
            break;

        case InterpolationMode.ClampedAuto:
            KeyframeUtilities.AlignTangentsClamped(bakedKeys);
            break;

        default:
            throw new System.InvalidOperationException("Not Implemented");
        }


        keys = bakedKeys.ToArray();
        bakedKeys.Dispose();
        return(frameCount);
    }
    public static int Bake(AnimationCurve curve, float frameRate, InterpolationMode mode)
    {
        var keys = new NativeArray <Keyframe>(curve.keys, Allocator.Temp);

        float duration   = keys[keys.Length - 1].time - keys[0].time;
        int   frameCount = (int)math.ceil(frameRate * duration);
        var   bakedKeys  = new NativeArray <Keyframe>(frameCount, Allocator.Temp);

        switch (mode)
        {
        case InterpolationMode.Linear:
            KeyframeUtilities.AlignTangentsLinear(bakedKeys);
            break;

        case InterpolationMode.Auto:
            KeyframeUtilities.AlignTangentsSmooth(bakedKeys);
            break;

        case InterpolationMode.ClampedAuto:
            KeyframeUtilities.AlignTangentsClamped(bakedKeys);
            break;

        default:
            throw new System.InvalidOperationException("Not Implemented");
        }
        curve.keys = bakedKeys.ToArray();
        keys.Dispose();
        bakedKeys.Dispose();
        return(frameCount);
    }