/// <summary> /// Replicate all keyframes of <paramref name="animationCurve"> into the struct, /// making this independent from the original reference type curve. /// </summary> public JobAnimationCurve(AnimationCurve animationCurve, Allocator allocator) { List <Keyframe> sortedKeyframes = new List <Keyframe>(animationCurve.keys); if (sortedKeyframes.Any(x => x.weightedMode != WeightedMode.None)) { throw new NotSupportedException($"Found a keyframe in the curve that has a weighted node. This is not supported until I figured out where to put the weight."); } sortedKeyframes.Sort(KeyframeTimeSort); //Debug.Log(string.Join("\n", sortedKeyframes.Select(x => $"{x.time} {x.value} | {x.inTangent} {x.outTangent} | {x.inWeight} {x.outWeight} {x.weightedMode}"))); var sortedTimes = sortedKeyframes.Select(x => x.time).ToArray(); using (var ba = new BlobAllocator(-1)) { ref var root = ref ba.ConstructRoot <AnimationData>(); int processorCount = SystemInfo.processorCount + 1; ba.Allocate(sortedKeyframes.Count, ref root.keyframes); ba.Allocate(sortedKeyframes.Count, ref root.soaTimes); ba.Allocate(processorCount, ref root.cachedIndex); for (int i = 0; i < sortedKeyframes.Count; i++) { root.keyframes[i] = sortedKeyframes[i]; root.soaTimes[i] = sortedTimes[i]; } for (int i = 0; i < processorCount; i++) { root.cachedIndex[i] = 0; } bar = ba.CreateBlobAssetReference <AnimationData>(allocator); }