From 477f6d2eb1243107c18bdb39e02bd4dbfe99620d Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 13:56:21 +0900 Subject: [PATCH 1/6] feat: basic support for normal-less Mesh --- .../MergeSkinnedMeshProcessor.cs | 1 + Editor/Processors/SkinnedMeshes/MeshInfo2.cs | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs index 94bc761e8..af7ab9c06 100644 --- a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs @@ -127,6 +127,7 @@ TexCoordStatus TexCoordStatusMax(TexCoordStatus x, TexCoordStatus y) => target.Bones.AddRange(meshInfo.Bones); target.HasColor |= meshInfo.HasColor; + target.HasNormals |= meshInfo.HasNormals; target.HasTangent |= meshInfo.HasTangent; target.AssertInvariantContract($"processing meshInfo {Target.gameObject.name}"); diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs index 853897970..f118a65e6 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs @@ -30,6 +30,7 @@ internal class MeshInfo2 public readonly List Bones = new List(); public bool HasColor { get; set; } + public bool HasNormals { get; set; } public bool HasTangent { get; set; } public MeshInfo2(SkinnedMeshRenderer renderer) @@ -192,7 +193,11 @@ public void ReadStaticMesh([NotNull] Mesh mesh) for (var i = 0; i < mesh.vertexCount; i++) Vertices.Add(new Vertex()); CopyVertexAttr(mesh.vertices, (x, v) => x.Position = v); - CopyVertexAttr(mesh.normals, (x, v) => x.Normal = v); + if (mesh.GetVertexAttributeDimension(VertexAttribute.Normal) != 0) + { + HasNormals = true; + CopyVertexAttr(mesh.normals, (x, v) => x.Normal = v); + } if (mesh.GetVertexAttributeDimension(VertexAttribute.Tangent) != 0) { HasTangent = true; @@ -275,6 +280,7 @@ public void Clear() BlendShapes.Clear(); Bones.Clear(); HasColor = false; + HasNormals = false; HasTangent = false; } @@ -301,14 +307,17 @@ public void WriteToMesh(Mesh destMesh) // Basic Vertex Attributes: vertices, normals { var vertices = new Vector3[Vertices.Count]; - var normals = new Vector3[Vertices.Count]; for (var i = 0; i < Vertices.Count; i++) - { vertices[i] = Vertices[i].Position; - normals[i] = Vertices[i].Normal; - } - destMesh.vertices = vertices; + } + + // tangents + if (HasNormals) + { + var normals = new Vector3[Vertices.Count]; + for (var i = 0; i < Vertices.Count; i++) + normals[i] = Vertices[i].Normal; destMesh.normals = normals; } From fb45d2bd1906a4078544fc265d70f5a67fc268b2 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 14:05:56 +0900 Subject: [PATCH 2/6] feat(MergeSkinnedMesh): normal setting mismatch error --- .../SkinnedMeshes/MergeSkinnedMeshProcessor.cs | 10 ++++++++++ Localization/en.po | 5 +++++ Localization/ja.po | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs index af7ab9c06..b15831c06 100644 --- a/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs +++ b/Editor/Processors/SkinnedMeshes/MergeSkinnedMeshProcessor.cs @@ -44,6 +44,16 @@ public override void Process(OptimizerSession session, MeshInfo2 target) .ToArray(); var sourceMaterials = meshInfos.Select(x => x.SubMeshes.Select(y => y.SharedMaterial).ToArray()).ToArray(); + // check normal information. + int hasNormal = 0; + foreach (var meshInfo2 in meshInfos) + hasNormal |= meshInfo2.HasNormals ? 1 : 2; + + if (hasNormal == 3) + { + BuildReport.LogFatal("MergeSkinnedMesh:error:mix-normal-existence")?.WithContext(Component); + } + var (subMeshIndexMap, materials) = CreateMergedMaterialsAndSubMeshIndexMapping(sourceMaterials); var sourceRootBone = target.RootBone; diff --git a/Localization/en.po b/Localization/en.po index ea63dcddd..9f7684c81 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -272,6 +272,11 @@ msgstr "Merge" msgid "MergeSkinnedMesh:label:Renderers" msgstr "Renderers:" +msgid "MergeSkinnedMesh:error:mix-normal-existence" +msgstr "" +"Merging mesh with normal and without normal is not supported! " +"Please change import setting of Normals to include normals!" + # endregion # region MergeToonLitMaterial diff --git a/Localization/ja.po b/Localization/ja.po index 6da4bef18..50af05dc9 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -209,6 +209,11 @@ msgstr "統合する" msgid "MergeSkinnedMesh:label:Renderers" msgstr "レンダラー:" +msgid "MergeSkinnedMesh:error:mix-normal-existence" +msgstr "" +"法線のあるモデルとないモデルを統合するのはサポートされてません! " +"法線を含むようにモデルのインポート設定を変更してください!" + # endregion # region MergeToonLitMaterial From 61642d436183b88ba5efff664eaa1085ab02373f Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 14:12:23 +0900 Subject: [PATCH 3/6] docs(changelog): Unclear behaviour if we merged meshes with and normals without that --- CHANGELOG-PRERELEASE.md | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 38d78e592..9b144dc23 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog]. ### Fixed - AnimatorOverrideController may not be proceed correctly `#567` +- Unclear behaviour if we merged meshes with and normals without that `#569` ### Security diff --git a/CHANGELOG.md b/CHANGELOG.md index 796b698f2..08d0929aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog]. ### Fixed - AnimatorController with Synced can be broken `#564` - AnimatorOverrideController may not be proceed correctly `#567` +- Unclear behaviour if we merged meshes with and normals without that `#569` ### Security From 3291667c59d5e35b72990079f9c6f3a12a652042 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 22:18:33 +0900 Subject: [PATCH 4/6] docs(changelog): Apply suggestions from code review Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- CHANGELOG-PRERELEASE.md | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 9b144dc23..7f1793397 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -17,7 +17,7 @@ The format is based on [Keep a Changelog]. ### Fixed - AnimatorOverrideController may not be proceed correctly `#567` -- Unclear behaviour if we merged meshes with and normals without that `#569` +- Unclear behaviour if we merged meshes with and without normals `#569` ### Security diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d0929aa..06abbcc7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ The format is based on [Keep a Changelog]. ### Fixed - AnimatorController with Synced can be broken `#564` - AnimatorOverrideController may not be proceed correctly `#567` -- Unclear behaviour if we merged meshes with and normals without that `#569` +- Unclear behaviour if we merged meshes with and without normals `#569` ### Security From 149d000b0dcb6fb0de4aabfb8f9d835c5bb3c422 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 22:19:03 +0900 Subject: [PATCH 5/6] chore(localization): Apply suggestions from code review Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- Localization/en.po | 4 ++-- Localization/ja.po | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Localization/en.po b/Localization/en.po index 9f7684c81..6a4e6dc25 100644 --- a/Localization/en.po +++ b/Localization/en.po @@ -274,8 +274,8 @@ msgstr "Renderers:" msgid "MergeSkinnedMesh:error:mix-normal-existence" msgstr "" -"Merging mesh with normal and without normal is not supported! " -"Please change import setting of Normals to include normals!" +"Merging both meshes with and without normal is not supported." +"Please change import setting of models to include normals!" # endregion diff --git a/Localization/ja.po b/Localization/ja.po index 50af05dc9..061804661 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -211,8 +211,8 @@ msgstr "レンダラー:" msgid "MergeSkinnedMesh:error:mix-normal-existence" msgstr "" -"法線のあるモデルとないモデルを統合するのはサポートされてません! " -"法線を含むようにモデルのインポート設定を変更してください!" +"法線があるモデルとないモデルの両方を1つに統合する操作には対応していません。" +"法線が含まれるようにモデルのインポート設定を変更してください!" # endregion From 273ea84ecb81a0d6c0d937c946d49139302bbc00 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Wed, 11 Oct 2023 22:36:58 +0900 Subject: [PATCH 6/6] chore(localization): Apply suggestions from code review Co-authored-by: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com> --- Localization/ja.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Localization/ja.po b/Localization/ja.po index 061804661..d998d4970 100644 --- a/Localization/ja.po +++ b/Localization/ja.po @@ -211,7 +211,7 @@ msgstr "レンダラー:" msgid "MergeSkinnedMesh:error:mix-normal-existence" msgstr "" -"法線があるモデルとないモデルの両方を1つに統合する操作には対応していません。" +"法線があるメッシュとないメッシュの両方を1つに統合する操作には対応していません。" "法線が含まれるようにモデルのインポート設定を変更してください!" # endregion