From 3bed8b8527fe6b5e34e7327ac34abb4039bb1c71 Mon Sep 17 00:00:00 2001 From: bd_ Date: Mon, 19 Jun 2023 20:11:18 +0900 Subject: [PATCH] fix: retain bones ending in "end" Closes: #332 --- .../EditModeTests/GameObjectGC/GameObjectGC.cs | 18 ++++++++++++++++++ .../OptimizationPasses/GCGameObjectsPass.cs | 12 +++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Assets/_ModularAvatar/EditModeTests/GameObjectGC/GameObjectGC.cs b/Assets/_ModularAvatar/EditModeTests/GameObjectGC/GameObjectGC.cs index a0610df8..18cb685e 100644 --- a/Assets/_ModularAvatar/EditModeTests/GameObjectGC/GameObjectGC.cs +++ b/Assets/_ModularAvatar/EditModeTests/GameObjectGC/GameObjectGC.cs @@ -22,4 +22,22 @@ public class GameObjectGC : TestBase Assert.NotNull(animator.GetBoneTransform(HumanBodyBones.Chest)); Assert.True(fake_humanoid.transform.Find("Body") == null); } + + [Test] + public void RetainEndBones() + { + var fake_humanoid = CreatePrefab("FakeHumanoid.prefab"); + var avdesc = fake_humanoid.GetComponent(); + + var bone1 = CreateChild(fake_humanoid, "bone1"); + var bone2 = CreateChild(bone1, "bone2.end"); + var bone3 = CreateChild(fake_humanoid, "bone2"); + + new GCGameObjectsPass(new BuildContext(avdesc), fake_humanoid).OnPreprocessAvatar(); + AvatarProcessor.ProcessAvatar(fake_humanoid); + + Assert.True(bone1 != null); + Assert.True(bone2 != null); + Assert.True(bone3 == null); + } } \ No newline at end of file diff --git a/Packages/nadena.dev.modular-avatar/Editor/OptimizationPasses/GCGameObjectsPass.cs b/Packages/nadena.dev.modular-avatar/Editor/OptimizationPasses/GCGameObjectsPass.cs index 61e4d1aa..e715f8d0 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/OptimizationPasses/GCGameObjectsPass.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/OptimizationPasses/GCGameObjectsPass.cs @@ -89,6 +89,16 @@ namespace nadena.dev.modular_avatar.core.editor } } } + + // https://github.com/bdunderscore/modular-avatar/issues/332 + // Retain transforms with names ending in "end" as these might be used for VRM spring bones + foreach (Transform t in _root.GetComponentsInChildren()) + { + if (t.name.ToLower().EndsWith("end")) + { + MarkObject(t.gameObject); + } + } } private void MarkPhysBone(VRCPhysBone pb) @@ -186,4 +196,4 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} +} \ No newline at end of file