From f52e6b481f96f9793ced0bcf572ce1053a5e48a7 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 14 Oct 2021 18:44:15 +0900 Subject: [PATCH] =?UTF-8?q?ushort=20=E3=81=AE=20index=20=E3=82=92=20uint?= =?UTF-8?q?=20=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Runtime/Migration/MeshUpdater.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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);