Advertisement
thelebaron

Untitled

Jun 18th, 2025
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. public static void ConstructData(this ref BlobBuilder builder, ref DenseClip root, Animator animator, AnimationClip clip,
  2.                                          Dictionary<string, EditorCurveBinding> curveDict)
  3.         {
  4.             int                           ratio   = curveDict.Count <= UseBucketCapacityRatioOfThreeUpTo ? 3 : 2;
  5.             List<Tuple<string, string[]>> mapping = HumanoidRemapping.BoneToMuscleList;
  6.    
  7.             int capacity       = curveDict.Count;
  8.             int bucketCapacity = math.ceilpow2(capacity * ratio);
  9.  
  10.             // bucketCapacityMask is neccessary for retrieval so set it on the data too
  11.             int bucketCapacityMask = bucketCapacity - 1;
  12.             int keyCapacity        = capacity;
  13.            
  14.             BlobBuilderArray<BlobArray<BlobCurve>> values  = builder.Allocate(ref root.HumanoidCurveData.data.values, capacity);
  15.             BlobBuilderArray<uint>                 keys    = builder.Allocate(ref root.HumanoidCurveData.data.keys, capacity);
  16.             BlobBuilderArray<int>                  next    = builder.Allocate(ref root.HumanoidCurveData.data.next, capacity);
  17.             BlobBuilderArray<int>                  buckets = builder.Allocate(ref root.HumanoidCurveData.data.buckets, bucketCapacity);
  18.  
  19.             Debug.Log($" values {values.Length}");
  20.  
  21.             // so far the only way I've found to modify the true count on the data itself (without using unsafe code)
  22.             // is by storing it in an array we can still access in the Add method.
  23.             // count is only used in GetKeyArray and GetValueArray to size the array to the true count instead of capacity
  24.             // count and keyCapacity are like
  25.             BlobBuilderArray<int> count = builder.Allocate(ref root.HumanoidCurveData.data.count, 1);
  26.             // Clear
  27.             for (int i = 0; i < buckets.Length; i++)
  28.                 buckets[i] = -1;
  29.             for (int i = 0; i < next.Length; i++)
  30.                 next[i] = -1;
  31.  
  32.             // Add logic
  33.             for (var index = 0; index < mapping.Count; index++)
  34.             {
  35.                 Tuple<string, string[]> boneMap       = mapping[index];
  36.                 uint      key           = mathex.CalculateHash32(boneMap.Item1);
  37.                 string[] propertyNames = boneMap.Item2;
  38.  
  39.                 ref int c      = ref count[0];
  40.                 int     bucket = key.GetHashCode() & bucketCapacityMask;
  41.                 int     bucketIndex  = c++;
  42.  
  43.                 int                         propertyCount     = 3;
  44.                 BlobBuilderArray<BlobCurve> curveArrayBuilder = builder.Allocate(ref values[index], propertyCount);
  45.  
  46.                 for (int i = 0; i < propertyCount; i++)
  47.                 {
  48.                     // we just add an empty key for missing properties
  49.                     if (propertyNames[i].Equals(""))
  50.                     {
  51.                         // Allocate single keyframe if no actual data
  52.                         BlobBuilderArray<Key> emptyKeyframeBuilder = builder.Allocate<Key>(ref curveArrayBuilder[i].Keyframes, 1);
  53.                         emptyKeyframeBuilder[0] = new Key();
  54.                         continue;
  55.                     }
  56.  
  57.                     // Get the curve for the property
  58.                     AnimationCurve        curve            = AnimationUtility.GetEditorCurve(clip, curveDict.GetValueOrDefault(propertyNames[i]));
  59.                     BlobBuilderArray<Key> keyframesBuilder = builder.Allocate<Key>(ref curveArrayBuilder[i].Keyframes, curve.keys.Length);
  60.  
  61.                     // Directly populate the blob array from curve keys
  62.                     for (int kIndex = 0; kIndex < curve.keys.Length; kIndex++)
  63.                     {
  64.                         keyframesBuilder[kIndex] = new Key(curve.keys[kIndex]);
  65.                     }
  66.                 }
  67.  
  68.                 keys[index] = key;
  69.                 //values[index] =
  70.                 next[index]     = buckets[bucket];
  71.                 buckets[bucket] = index;
  72.             }
  73.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement