From 27bb7b631272205180bfc2108bac57cccbfebff1 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 9 Dec 2022 13:19:15 +0900 Subject: [PATCH] fix: worldUpObject of AimConstraint and LookAtConstraint is not fixed up --- .../Editor/MergeArmatureHook.cs | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs index a4429ae6..0c792dff 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs @@ -91,6 +91,22 @@ namespace nadena.dev.modular_avatar.core.editor } } + foreach (var c in avatarGameObject.transform.GetComponentsInChildren(true)) + { + if (!AddedConstraints.Contains(c)) + { + FixupAimConstraint(c); + } + } + + foreach (var c in avatarGameObject.transform.GetComponentsInChildren(true)) + { + if (!AddedConstraints.Contains(c)) + { + FixupLookAtConstraint(c); + } + } + foreach (var bone in ToDelete) UnityEngine.Object.DestroyImmediate(bone); return true; @@ -119,6 +135,38 @@ namespace nadena.dev.modular_avatar.core.editor } } + private void FixupAimConstraint(AimConstraint constraint) + { + if (constraint.worldUpObject == null) return; + if (!BoneRemappings.TryGetValue(constraint.worldUpObject, out var remap)) return; + var retarget = BoneDatabase.GetRetargetedBone(remap); + + if (retarget != null) + { + constraint.worldUpObject = retarget; + } + else + { + constraint.worldUpObject = remap; + } + } + + private void FixupLookAtConstraint(LookAtConstraint constraint) + { + if (constraint.worldUpObject == null) return; + if (!BoneRemappings.TryGetValue(constraint.worldUpObject, out var remap)) return; + var retarget = BoneDatabase.GetRetargetedBone(remap); + + if (retarget != null) + { + constraint.worldUpObject = retarget; + } + else + { + constraint.worldUpObject = remap; + } + } + private void UpdateBoneReferences(Component c, Retargetable retargetable = Retargetable.Disable) { SerializedObject so = new SerializedObject(c); @@ -397,4 +445,4 @@ namespace nadena.dev.modular_avatar.core.editor } } } -} \ No newline at end of file +}