public KeyframeAnimation AllocateCopyAtFixedSampleRate(float sampleRate)
        {
            int numJoints = jointSamplers.Length;

            KeyframeAnimation anim = new KeyframeAnimation();

            anim.animationCurves = new List <CurveInfo>(animationCurves.Count);
            anim.jointSamplers   = new NativeArray <TransformSampler>(numJoints, Allocator.Persistent);
            anim.numFrames       = (int)math.ceil(sampleRate * duration);

            for (int jointIndex = 0; jointIndex < numJoints; ++jointIndex)
            {
                TransformSampler sourceSampler      = jointSamplers[jointIndex];
                TransformSampler destinationSampler = TransformSampler.CreateEmpty(sourceSampler.DefaultTransform);

                for (int curveIndex = 0; curveIndex < TransformSampler.NumCurves; ++curveIndex)
                {
                    if (sourceSampler.GetCurveProxy(curveIndex).HasCurve)
                    {
                        Curve curve = new Curve(anim.numFrames, Allocator.Persistent); // fixed framerate curve
                        anim.animationCurves.Add(new CurveInfo()
                        {
                            curve      = curve,
                            jointIndex = jointIndex,
                            curveIndex = curveIndex,
                        });
                        destinationSampler.SetCurve(curveIndex, curve);
                    }
                }

                anim.jointSamplers[jointIndex] = destinationSampler;
            }

            return(anim);
        }
        void InitWithRigTransforms(AnimationRig targetRig)
        {
            animationCurves = new List <CurveInfo>();
            jointSamplers   = new NativeArray <TransformSampler>(targetRig.NumJoints, Allocator.Persistent);

            for (int i = 0; i < targetRig.NumJoints; ++i)
            {
                jointSamplers[i] = TransformSampler.CreateEmpty(targetRig.Joints[i].localTransform);
            }
        }
        void MapEditorCurve(int jointIndex, string curveName, string posCurvePrefix, string rotCurvePrefix, AnimationCurve editorCurve)
        {
            int curveIndex;
            TransformSampler sampler = jointSamplers[jointIndex];
            Curve?           curve   = sampler.MapEditorCurve(curveName, posCurvePrefix, rotCurvePrefix, editorCurve, out curveIndex);

            jointSamplers[jointIndex] = sampler;

            if (curve.HasValue)
            {
                animationCurves.Add(new CurveInfo()
                {
                    curve      = curve.Value,
                    jointIndex = jointIndex,
                    curveIndex = curveIndex
                });
            }
        }