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;
- List<Tuple<string, string[]>> mapping = HumanoidRemapping.BoneToMuscleList;
- int capacity = curveDict.Count;
- int bucketCapacity = math.ceilpow2(capacity * ratio);
- // bucketCapacityMask is neccessary for retrieval so set it on the data too
- int bucketCapacityMask = bucketCapacity - 1;
- int keyCapacity = capacity;
- BlobBuilderArray<BlobArray<BlobCurve>> values = builder.Allocate(ref root.HumanoidCurveData.data.values, capacity);
- BlobBuilderArray<uint> keys = builder.Allocate(ref root.HumanoidCurveData.data.keys, capacity);
- BlobBuilderArray<int> next = builder.Allocate(ref root.HumanoidCurveData.data.next, capacity);
- BlobBuilderArray<int> buckets = builder.Allocate(ref root.HumanoidCurveData.data.buckets, bucketCapacity);
- Debug.Log($" values {values.Length}");
- // 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
- BlobBuilderArray<int> 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
- for (var index = 0; index < mapping.Count; index++)
- {
- Tuple<string, string[]> boneMap = mapping[index];
- uint key = mathex.CalculateHash32(boneMap.Item1);
- string[] propertyNames = boneMap.Item2;
- ref int c = ref count[0];
- int bucket = key.GetHashCode() & bucketCapacityMask;
- int bucketIndex = c++;
- int propertyCount = 3;
- BlobBuilderArray<BlobCurve> 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
- BlobBuilderArray<Key> emptyKeyframeBuilder = builder.Allocate<Key>(ref curveArrayBuilder[i].Keyframes, 1);
- emptyKeyframeBuilder[0] = new Key();
- continue;
- }
- // Get the curve for the property
- AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, curveDict.GetValueOrDefault(propertyNames[i]));
- BlobBuilderArray<Key> 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