From 2ad42a9103b841fde5e310aff52322668f05ebf6 Mon Sep 17 00:00:00 2001 From: nekobako Date: Sat, 23 Sep 2023 13:53:01 +0900 Subject: [PATCH 1/3] chore: remove unused bone references just after reading mesh --- Editor/Processors/SkinnedMeshes/MeshInfo2.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs index 3d611e710..aeaa0451f 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs @@ -65,6 +65,8 @@ public MeshInfo2(SkinnedMeshRenderer renderer) var bones = renderer.bones; for (var i = 0; i < bones.Length && i < Bones.Count; i++) Bones[i].Transform = bones[i]; + Optimize(); + AssertInvariantContract("SkinnedMeshRenderer"); }); } From 59e2dffa056b652ceac6c1454c5cd08d2f6958fb Mon Sep 17 00:00:00 2001 From: nekobako Date: Sat, 23 Sep 2023 14:19:38 +0900 Subject: [PATCH 2/3] docs(changelog): Remove unused bone references --- CHANGELOG-PRERELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index 96c97ab1b..0b6469582 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog]. ### Removed ### Fixed +- Remove unused bone references [`#498`](https://github.com/anatawa12/AvatarOptimizer/pull/498) ### Security From fc31517da982891dc41fb4aec214cf22eb71cecd Mon Sep 17 00:00:00 2001 From: nekobako Date: Sat, 23 Sep 2023 17:32:41 +0900 Subject: [PATCH 3/3] chore: extract MeshInfo2.RemoveUnusedBones() from MeshInfo2.Optimize() --- Editor/Processors/SkinnedMeshes/MeshInfo2.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs index aeaa0451f..215cd1061 100644 --- a/Editor/Processors/SkinnedMeshes/MeshInfo2.cs +++ b/Editor/Processors/SkinnedMeshes/MeshInfo2.cs @@ -65,7 +65,7 @@ public MeshInfo2(SkinnedMeshRenderer renderer) var bones = renderer.bones; for (var i = 0; i < bones.Length && i < Bones.Count; i++) Bones[i].Transform = bones[i]; - Optimize(); + RemoveUnusedBones(); AssertInvariantContract("SkinnedMeshRenderer"); }); @@ -268,6 +268,11 @@ public void Clear() } public void Optimize() + { + RemoveUnusedBones(); + } + + private void RemoveUnusedBones() { // GC Bones var usedBones = new HashSet();