From 85fb330c8bdc253169f2abf757126e08844f4a87 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 13 Jan 2022 19:35:03 +0900 Subject: [PATCH] fix UNSIGNED_BYTE4 joints --- Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs index 47a4ed3d1..f85e8553d 100644 --- a/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs +++ b/Assets/VRM10/vrmlib/Runtime/BufferAccessor.cs @@ -122,7 +122,20 @@ namespace VrmLib } else { - throw new Exception($"Stride:{Stride}!= sizeof({typeof(T).Name}:{Marshal.SizeOf(typeof(T))}"); + if (typeof(T) == typeof(SkinJoints) && Stride == 4) + { + // 例えば SkinJoints を使う JOINTS_0 は UNSIGNED_BYTE と UNSIGNED_SHORT の2種類がありえる。 + fixed (UShort4* p = GetAsUShort4()) + { + var nativeArray = new NativeArray(Count, allocator); + UnsafeUtility.MemCpy(nativeArray.GetUnsafePtr(), p, Bytes.Count); + return nativeArray; + } + } + else + { + throw new Exception($"Stride:{Stride}!= sizeof({typeof(T).Name}:{Marshal.SizeOf(typeof(T))}"); + } } }