using Unity.Collections; using Unity.Entities; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace Rukhanka { public static class AnimationUtils { public static Hash128 CalculateBoneRemapTableHash(in BlobAssetReference skinnedMesh, in BlobAssetReference rigDef) { var rv = new Hash128(skinnedMesh.Value.hash.Value.x, skinnedMesh.Value.hash.Value.y, rigDef.Value.hash.Value.x, rigDef.Value.hash.Value.y); return rv; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static BlobAssetReference MakeSkinnedMeshToRigRemapTable(in SkinnedMeshRendererComponent sm, in RigDefinitionComponent rigDef, Allocator allocator) { var bb = new BlobBuilder(Allocator.Temp); ref var brt = ref bb.ConstructRoot(); var bba = bb.Allocate(ref brt.remapIndices, sm.smrInfoBlob.Value.bones.Length); for (int i = 0; i < bba.Length; ++i) { bba[i] = -1; ref var rb = ref sm.smrInfoBlob.Value.bones[i]; var rbHash = rb.hash; for (int j = 0; j < rigDef.rigBlob.Value.bones.Length; ++j) { ref var bn = ref rigDef.rigBlob.Value.bones[j]; var bnHash = bn.hash; if (bnHash == rbHash) { bba[i] = j; } } } var rv = bb.CreateBlobAssetReference(allocator); return rv; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static bool IsGPUAnimator(Entity animatedRigEntity, in ComponentLookup gpuAnimationEngineTagLookup) { return animatedRigEntity != Entity.Null && gpuAnimationEngineTagLookup.IsComponentEnabled(animatedRigEntity); } } }