From fd59c3e91015cb4586842899fd23092d62e4b8c7 Mon Sep 17 00:00:00 2001 From: Reina_Sakiria <99442371+ReinaS-64892@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:41:20 +0900 Subject: [PATCH] fix: MA MergeArmature forget to retaining the root bone. (#1355) * fix: forget to retaining the root bone * chore: fix test --------- Co-authored-by: bd_ --- Editor/MergeArmatureHook.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Editor/MergeArmatureHook.cs b/Editor/MergeArmatureHook.cs index cd0d05cc..e9896fdb 100644 --- a/Editor/MergeArmatureHook.cs +++ b/Editor/MergeArmatureHook.cs @@ -1,4 +1,4 @@ -/* +/* * MIT License * * Copyright (c) 2022 bd_ @@ -116,6 +116,24 @@ namespace nadena.dev.modular_avatar.core.editor { RetainBoneReferences(c as Component); } + + foreach (var smr in avatarGameObject.transform.GetComponentsInChildren(true)) + { + // If the root bone has been offset, or has a different sign for its scale, we need to retain it. + // see https://github.com/bdunderscore/modular-avatar/pull/1355 + // (we avoid retaining otherwise to avoid excess bone transforms) + + if (smr.rootBone == null || smr.rootBone.parent == null) continue; + + var root = smr.rootBone; + var parent = root.parent; + + if ((parent.position - root.position).sqrMagnitude > 0.000001f + || Vector3.Dot(parent.localScale.normalized, root.localScale.normalized) < 0.9999f) + { + BoneDatabase.RetainMergedBone(smr.rootBone); + } + } new RetargetMeshes().OnPreprocessAvatar(avatarGameObject, BoneDatabase, PathMappings); }