Advertisement
thelebaron

Untitled

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