Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void ConstructData(this ref BlobBuilder builder, ref DenseClip root, Animator animator, AnimationClip clip,
- Dictionary<string, EditorCurveBinding> curveDict)
- {
- int ratio = curveDict.Count <= UseBucketCapacityRatioOfThreeUpTo ? 3 : 2;
- var mapping = HumanoidRemapping.BoneToMuscleList;
- var capacity = curveDict.Count;
- int bucketCapacity = math.ceilpow2(capacity * ratio);
- // bucketCapacityMask is neccessary for retrieval so set it on the data too
- var bucketCapacityMask = bucketCapacity - 1;
- var keyCapacity = capacity;
- BlobBuilderArray<BlobArray<BlobCurve>> values = builder.Allocate(ref root.HumanoidCurveData.data.values, capacity);
- var keys = builder.Allocate(ref root.HumanoidCurveData.data.keys, capacity);
- var next = builder.Allocate(ref root.HumanoidCurveData.data.next, capacity);
- var buckets = builder.Allocate(ref root.HumanoidCurveData.data.buckets, bucketCapacity);
- // so far the only way I've found to modify the true count on the data itself (without using unsafe code)
- // is by storing it in an array we can still access in the Add method.
- // count is only used in GetKeyArray and GetValueArray to size the array to the true count instead of capacity
- // count and keyCapacity are like
- var count = builder.Allocate(ref root.HumanoidCurveData.data.count, 1);
- // Clear
- for (int i = 0; i < buckets.Length; i++)
- buckets[i] = -1;
- for (int i = 0; i < next.Length; i++)
- next[i] = -1;
- // Add logic
- foreach (Tuple<string, string[]> boneMap in mapping)
- {
- var key = mathex.CalculateHash32(boneMap.Item1);
- string[] propertyNames = boneMap.Item2;
- ref int c = ref count[0];
- int bucket = key.GetHashCode() & bucketCapacityMask;
- int index = c++;
- var propertyCount = 3;
- var curveArrayBuilder = builder.Allocate(ref values[index], propertyCount);
- for (int i = 0; i < propertyCount; i++)
- {
- // we just add an empty key for missing properties
- if (propertyNames[i].Equals(""))
- {
- // Allocate single keyframe if no actual data
- var emptyKeyframeBuilder = builder.Allocate<Key>(ref curveArrayBuilder[i].Keyframes, 1);
- emptyKeyframeBuilder[0] = new Key();
- continue;
- }
- // Get the curve for the property
- var curve = AnimationUtility.GetEditorCurve(clip, curveDict.GetValueOrDefault(propertyNames[i]));
- var keyframesBuilder = builder.Allocate<Key>(ref curveArrayBuilder[i].Keyframes, curve.keys.Length);
- // Directly populate the blob array from curve keys
- for (int kIndex = 0; kIndex < curve.keys.Length; kIndex++)
- {
- keyframesBuilder[kIndex] = new Key(curve.keys[kIndex]);
- }
- }
- keys[index] = key;
- //values[index] =
- next[index] = buckets[bucket];
- buckets[bucket] = index;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement