/// <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); }
public static BlobAssetReference <Collider> CreateTriangle(float3 vertex0, float3 vertex1, float3 vertex2, CollisionFilter?filter = null, Material?material = null) { if (math.any(!math.isfinite(vertex0)) || math.any(!math.isfinite(vertex1)) || math.any(!math.isfinite(vertex2))) { throw new System.ArgumentException("Tried to create triangle collider with nan/inf vertex"); } using (var allocator = new BlobAllocator(-1)) { ref PolygonCollider collider = ref allocator.ConstructRoot <PolygonCollider>(); collider.InitAsTriangle(vertex0, vertex1, vertex2, filter ?? CollisionFilter.Default, material ?? Material.Default); return(allocator.CreateBlobAssetReference <Collider>(Allocator.Persistent)); }