From e61f29b89ec6a3f8857cd3c311ebab144421662e Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 12 May 2022 16:22:16 +0900 Subject: [PATCH 1/4] =?UTF-8?q?primitive.indices=20=E3=81=8C=E7=84=A1?= =?UTF-8?q?=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AB=E3=80=81=E9=80=A3=E7=95=AA?= =?UTF-8?q?=E3=82=92=E8=A3=9C=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Runtime/IO/Model/MeshReader.cs | 7 +++++++ Assets/VRM10/Runtime/IO/Vrm10ImportData.cs | 1 + 2 files changed, 8 insertions(+) diff --git a/Assets/VRM10/Runtime/IO/Model/MeshReader.cs b/Assets/VRM10/Runtime/IO/Model/MeshReader.cs index 9a5383ec1..cd99b6896 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshReader.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshReader.cs @@ -67,6 +67,13 @@ namespace UniVRM10 mesh.IndexBuffer = storage.CreateAccessor(primitive.indices); } + if (mesh.IndexBuffer == null) + { + var indices = Enumerable.Range(0, mesh.VertexBuffer.Count).ToArray(); + var na = storage.Data.NativeArrayManager.CreateNativeArray(indices); + mesh.IndexBuffer = new BufferAccessor(storage.Data.NativeArrayManager, na.Reinterpret(4), AccessorValueType.UNSIGNED_INT, AccessorVectorType.SCALAR, na.Length); + } + { gltf_mesh_extras_targetNames.TryGet(x, out List targetNames); diff --git a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs index c174a3d62..c5b2efd32 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs @@ -12,6 +12,7 @@ namespace UniVRM10 public class Vrm10ImportData { UniGLTF.GltfData m_data; + public UniGLTF.GltfData Data => m_data; public UniGLTF.glTF Gltf => m_data.GLTF; public string AssetVersion => Gltf.asset.version; From bf872c962f7735e8b51bf790b5c14e26371f6f6c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 12 May 2022 16:43:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?new=20Matrix4x4=20=E3=81=8C=E8=BB=A2?= =?UTF-8?q?=E7=BD=AE=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=80=82=E5=BC=95=E6=95=B0=E5=90=8D=E3=81=AE=20column?= =?UTF-8?q?=20=E3=81=AE=E6=84=8F=E5=91=B3=E3=82=92=E5=8B=98=E9=81=95?= =?UTF-8?q?=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Runtime/IO/Vrm10ImportData.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs index c5b2efd32..ada4c16f8 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10ImportData.cs @@ -364,12 +364,7 @@ namespace UniVRM10 if (x.translation != null && x.translation.Length > 0) throw new Exception("matrix with translation"); if (x.rotation != null && x.rotation.Length > 0) throw new Exception("matrix with rotation"); if (x.scale != null && x.scale.Length > 0) throw new Exception("matrix with scale"); - var m = new Matrix4x4( - new Vector4(x.matrix[0], x.matrix[4], x.matrix[8], x.matrix[12]), - new Vector4(x.matrix[1], x.matrix[5], x.matrix[9], x.matrix[13]), - new Vector4(x.matrix[2], x.matrix[6], x.matrix[10], x.matrix[14]), - new Vector4(x.matrix[3], x.matrix[7], x.matrix[11], x.matrix[15]) - ); + var m = UnityExtensions.MatrixFromArray(x.matrix); node.SetLocalMatrix(m, true); } From 0be79c4dbc3c97517bfb9d196c011cb75878016f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 12 May 2022 16:43:41 +0900 Subject: [PATCH 3/4] =?UTF-8?q?index=20=E3=83=95=E3=82=A9=E3=83=BC?= =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=88=20uint8=20=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/UniGLTF/IO/BufferAccessor.cs | 3 +++ Assets/VRM10/Runtime/IO/Model/MeshImporter.cs | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs index 43e4a6273..6ead44a56 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/BufferAccessor.cs @@ -157,6 +157,9 @@ namespace UniGLTF } switch (ComponentType) { + case AccessorValueType.UNSIGNED_BYTE: + return ArrayManager.Convert(Bytes, (byte x) => (int)x); + case AccessorValueType.UNSIGNED_SHORT: return ArrayManager.Convert(Bytes.Reinterpret(1), (ushort x) => (int)x); diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs index d27a78e76..bf33aed6b 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs @@ -65,16 +65,27 @@ namespace UniVRM10 // Indexを更新 switch (src.IndexBuffer.ComponentType) { + case AccessorValueType.UNSIGNED_BYTE: + { + var intIndices = src.IndexBuffer.GetAsIntArray(); + mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); + mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); + break; + } case AccessorValueType.UNSIGNED_SHORT: - var shortIndices = src.IndexBuffer.Bytes.Reinterpret(1); - mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16); - mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length); - break; + { + var shortIndices = src.IndexBuffer.Bytes.Reinterpret(1); + mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16); + mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length); + break; + } case AccessorValueType.UNSIGNED_INT: - var intIndices = src.IndexBuffer.Bytes.Reinterpret(1); - mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); - mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); - break; + { + var intIndices = src.IndexBuffer.Bytes.Reinterpret(1); + mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32); + mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length); + break; + } default: throw new NotImplementedException(); } From 5360b44b0a93fb501c124b4e0613640497790078 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 12 May 2022 16:47:47 +0900 Subject: [PATCH 4/4] RecalculateNormals --- Assets/VRM10/Runtime/IO/Model/MeshImporter.cs | 4 ++++ Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs index bf33aed6b..035fdd7df 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporter.cs @@ -112,6 +112,10 @@ namespace UniVRM10 // 各種パラメーターを再計算 mesh.RecalculateBounds(); mesh.RecalculateTangents(); + if (src.VertexBuffer.Normals == null) + { + mesh.RecalculateNormals(); + } Profiler.EndSample(); diff --git a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs index 91d71c6e9..49de5fc71 100644 --- a/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs +++ b/Assets/VRM10/Runtime/IO/Model/MeshImporterDivided.cs @@ -42,6 +42,10 @@ namespace UniVRM10 // 各種データを再構築 resultMesh.RecalculateBounds(); resultMesh.RecalculateTangents(); + if (meshGroup.Meshes.Any(mesh => mesh.VertexBuffer.Normals == null)) + { + resultMesh.RecalculateNormals(); + } // BlendShapeを更新 var blendShapeCount = meshGroup.Meshes[0].MorphTargets.Count;