diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs index e2a5dab45..8e7ce4b18 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs @@ -169,6 +169,29 @@ namespace UniGLTF } // BoneWeight用 + public NativeArray GetAsVector4Array() + { + if (AccessorType != AccessorVectorType.VEC4) + { + throw new InvalidOperationException("not VEC4"); + } + switch (ComponentType) + { + case AccessorValueType.FLOAT: + return Bytes.Reinterpret(1); + + case AccessorValueType.UNSIGNED_BYTE: + return ArrayManager.Convert(Bytes.Reinterpret(1), (Byte4 b) => new Vector4(b.x / 255.0f, b.y / 255.0f, b.z / 255.0f, b.w / 255.0f)); + + case AccessorValueType.UNSIGNED_SHORT: + return ArrayManager.Convert(Bytes.Reinterpret(1), (UShort4 b) => new Vector4(b.x / 65535.0f, b.y / 65535.0f, b.z / 65535.0f, b.w / 65535.0f)); + + default: + throw new NotImplementedException(); + } + } + + // BoneJoint用 public NativeArray GetAsSkinJointsArray() { if (AccessorType != AccessorVectorType.VEC4) diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs index 472c48d41..d27a78e76 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs @@ -27,7 +27,7 @@ namespace UniVRM10 var normals = src.VertexBuffer.Normals?.Bytes.Reinterpret(1) ?? default; var texCoords = src.VertexBuffer.TexCoords?.Bytes.Reinterpret(1) ?? default; var colors = src.VertexBuffer.Colors?.Bytes.Reinterpret(1) ?? default; - var weights = src.VertexBuffer.Weights?.Bytes.Reinterpret(1) ?? default; + var weights = src.VertexBuffer.Weights?.GetAsVector4Array() ?? default; var joints = src.VertexBuffer.Joints?.GetAsSkinJointsArray() ?? default; using (var vertices = new NativeArray(positions.Length, Allocator.TempJob))