diff --git a/Assets/VRM10/Runtime/Migration/MeshUpdater.cs b/Assets/VRM10/Runtime/Migration/MeshUpdater.cs index 5fdf3fe61..d6b62d08b 100644 --- a/Assets/VRM10/Runtime/Migration/MeshUpdater.cs +++ b/Assets/VRM10/Runtime/Migration/MeshUpdater.cs @@ -76,7 +76,31 @@ namespace UniVRM10 // update Mesh foreach (var (gltfMesh, mesh) in Enumerable.Zip(gltf.meshes, model.MeshGroups, (l, r) => (l, r.Meshes[0]))) { - var indices = mesh.IndexBuffer.GetSpan(); + SpanLike indices; + switch (mesh.IndexBuffer.Stride) + { + case 2: + { + // ushort + var ushort_indices = mesh.IndexBuffer.GetSpan(); + indices = SpanLike.Create(ushort_indices.Length); + for (int i = 0; i < ushort_indices.Length; ++i) + { + indices[i] = ushort_indices[i]; + } + break; + } + + case 4: + { + // uint + indices = mesh.IndexBuffer.GetSpan(); + break; + } + + default: + throw new NotImplementedException(); + } var position = AddAccessor(mesh.VertexBuffer.Positions); var normal = AddAccessor(mesh.VertexBuffer.Normals); var uv = AddAccessor(mesh.VertexBuffer.TexCoords);