From abe2b82ddc30793136381cbebb89969a03de093d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 13 Nov 2020 20:18:08 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E3=81=AE=E9=A0=82?= =?UTF-8?q?=E7=82=B9=E3=81=8C=E5=BE=8C=E3=82=8D=E3=81=AB=E3=81=82=E3=82=8B?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E3=81=AB=E5=89=8A=E9=99=A4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #610 対策 --- Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs index ed1538029..09104286b 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshImporter.cs @@ -420,6 +420,43 @@ namespace UniGLTF } } } + + static void Truncate(List list, int maxIndex) + { + if (list == null) + { + return; + } + var count = maxIndex + 1; + if (list.Count > count) + { + // Debug.LogWarning($"remove {count} to {list.Count}"); + list.RemoveRange(count, list.Count - count); + } + } + + // + // https://github.com/vrm-c/UniVRM/issues/610 + // + // VertexBuffer の後ろに未使用頂点がある場合に削除する + // + public void DropUnusedVertices() + { + var maxIndex = m_subMeshes.SelectMany(x => x).Max(); + Truncate(m_positions, maxIndex); + Truncate(m_normals, maxIndex); + Truncate(m_uv, maxIndex); + Truncate(m_uv2, maxIndex); + Truncate(m_colors, maxIndex); + Truncate(m_boneWeights, maxIndex); + Truncate(m_tangents, maxIndex); + foreach (var blendshape in m_blendShapes) + { + Truncate(blendshape.Positions, maxIndex); + Truncate(blendshape.Normals, maxIndex); + Truncate(blendshape.Tangents, maxIndex); + } + } } static bool HasSharedVertexBuffer(glTFMesh gltfMesh) @@ -455,6 +492,8 @@ namespace UniGLTF meshContext.RenameBlendShape(gltfMesh); + meshContext.DropUnusedVertices(); + return meshContext; }