From a1c5e776264f8e30c7dc573f46fe23a8a0237a30 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 19 May 2022 13:19:45 +0900 Subject: [PATCH] =?UTF-8?q?UNSIGNED=5FSHORT=20=E3=81=AE=20index=20buffer?= =?UTF-8?q?=20=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=80=82=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/IO/Model/MeshImporterDivided.cs | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs index 49de5fc71..a615ffbf3 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs @@ -113,9 +113,12 @@ namespace UniVRM10 var disposables = new List(); - // 出力をushortにするべきかどうかを判別 + // + // https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_accessor_componenttype + // if (vertexCount < ushort.MaxValue) { + // vertex buffer への index が ushort に収まる var indices = new NativeArray(indexCount, Allocator.TempJob); disposables.Add(indices); var indexOffset = 0; @@ -124,7 +127,13 @@ namespace UniVRM10 { switch (mesh.IndexBuffer.ComponentType) { + case AccessorValueType.BYTE: + case AccessorValueType.UNSIGNED_BYTE: + case AccessorValueType.FLOAT: + throw new NotImplementedException($"{mesh.IndexBuffer.ComponentType}"); + case AccessorValueType.SHORT: + case AccessorValueType.UNSIGNED_SHORT: { // unsigned short -> unsigned short var source = mesh.IndexBuffer.Bytes.Reinterpret(1); @@ -135,6 +144,7 @@ namespace UniVRM10 .Schedule(mesh.IndexBuffer.Count, 1, jobHandle); break; } + case AccessorValueType.UNSIGNED_INT: { // unsigned int -> unsigned short @@ -146,8 +156,9 @@ namespace UniVRM10 .Schedule(mesh.IndexBuffer.Count, 1, jobHandle); break; } + default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentException($"unknown index buffer type: {mesh.IndexBuffer.ComponentType}"); } vertexOffset += mesh.VertexBuffer.Count; @@ -161,6 +172,7 @@ namespace UniVRM10 } else { + // vertex buffer への index が ushort を超える var indices = new NativeArray(indexCount, Allocator.TempJob); disposables.Add(indices); var indexOffset = 0; @@ -169,7 +181,13 @@ namespace UniVRM10 { switch (mesh.IndexBuffer.ComponentType) { + case AccessorValueType.BYTE: + case AccessorValueType.UNSIGNED_BYTE: + case AccessorValueType.FLOAT: + throw new NotImplementedException($"{mesh.IndexBuffer.ComponentType}"); + case AccessorValueType.SHORT: + case AccessorValueType.UNSIGNED_SHORT: { // unsigned short -> unsigned int var source = mesh.IndexBuffer.Bytes.Reinterpret(1); @@ -180,6 +198,7 @@ namespace UniVRM10 .Schedule(mesh.IndexBuffer.Count, 1, jobHandle); break; } + case AccessorValueType.UNSIGNED_INT: { // unsigned int -> unsigned int @@ -191,8 +210,9 @@ namespace UniVRM10 .Schedule(mesh.IndexBuffer.Count, 1, jobHandle); break; } + default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentException($"unknown index buffer type: {mesh.IndexBuffer.ComponentType}"); } vertexOffset += mesh.VertexBuffer.Count;