From fcdf0ee19acc81889b318e8ce11d60b9e1810a94 Mon Sep 17 00:00:00 2001 From: krypto5863 <29824718+krypto5863@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:40:13 -0500 Subject: [PATCH 1/2] Fixes https://github.com/ManlyMarco/ABMX/issues/58 --- Shared/Core/BoneController.cs | 51 ++++++++++++++++++++++++++++++++++- Shared/Core/BoneModifier.cs | 6 +++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Shared/Core/BoneController.cs b/Shared/Core/BoneController.cs index ddb58b1..6e245f3 100644 --- a/Shared/Core/BoneController.cs +++ b/Shared/Core/BoneController.cs @@ -509,7 +509,6 @@ private void LateUpdate() } private readonly Dictionary> _effectsToUpdate = new Dictionary>(); - private void ApplyEffects() { foreach (var kv in _effectsToUpdate) @@ -655,7 +654,21 @@ private IEnumerator CollectBaselineCo() ModifiersFillInTransforms(); foreach (var modifier in ModifierDict.Values.SelectMany(x => x)) + { + var dynamicBoneEnabled = false; + + if (modifier.DynamicBone?.enabled == true) + { + dynamicBoneEnabled = true; + modifier.DynamicBone.enabled = false; + } + modifier.CollectBaseline(); + if (dynamicBoneEnabled) + { + modifier.DynamicBone.enabled = true; + } + } yield return CoroutineUtils.WaitForEndOfFrame; @@ -939,6 +952,41 @@ private GameObject FindBone(string name, GameObject rootObject, bool noRetry = f return boneObj; } + /// + /// Finds the dynamic bone that is targeting the bone of the given name in the given location. Currently only supporting accessories. + /// + /// + /// + /// + public DynamicBone FindDynamicBone(string name, BoneLocation location) + { + if (location < BoneLocation.Accessory) + { + return null; + } + + var accId = location - BoneLocation.Accessory; + var rootObj = _ctrl.objAccessory.SafeGet(accId); + + foreach (var dynamicBone in rootObj.GetComponents()) + { + if (dynamicBone.m_Root.name.Equals(name)) + { + return dynamicBone; + } + + foreach (var child in dynamicBone.m_Root.GetComponentsInChildren()) + { + if (child.name.Equals(name)) + { + return dynamicBone; + } + } + } + + return null; + } + /// /// Get a dictionary of all bones and their names in a given location. /// @@ -990,6 +1038,7 @@ public bool AssignBone(BoneModifier modifier) var boneFound = bone != null; modifier.BoneTransform = boneFound ? bone.transform : null; modifier.BoneLocation = loc; + modifier.DynamicBone = FindDynamicBone(modifier.BoneName, modifier.BoneLocation); return boneFound; } diff --git a/Shared/Core/BoneModifier.cs b/Shared/Core/BoneModifier.cs index 54cf701..58509c5 100644 --- a/Shared/Core/BoneModifier.cs +++ b/Shared/Core/BoneModifier.cs @@ -99,6 +99,12 @@ public BoneModifier(string boneName, BoneModifierData[] coordinateModifiers, Bon [IgnoreMember] public Transform BoneTransform { get; internal set; } + /// + /// DynamicBone component that targets this transform, if any. + /// + [IgnoreMember] + public DynamicBone DynamicBone { get; internal set; } + /// /// Actual modifier values, split for different coordinates if required /// From 05db34c6640ab5317d16f7c21515f1d6b462b7f9 Mon Sep 17 00:00:00 2001 From: krypto5863 <29824718+krypto5863@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:47:42 -0500 Subject: [PATCH 2/2] Made DynamicBone prop purely internal. --- Shared/Core/BoneModifier.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shared/Core/BoneModifier.cs b/Shared/Core/BoneModifier.cs index 58509c5..d5d456d 100644 --- a/Shared/Core/BoneModifier.cs +++ b/Shared/Core/BoneModifier.cs @@ -103,7 +103,7 @@ public BoneModifier(string boneName, BoneModifierData[] coordinateModifiers, Bon /// DynamicBone component that targets this transform, if any. /// [IgnoreMember] - public DynamicBone DynamicBone { get; internal set; } + internal DynamicBone DynamicBone { get; set; } /// /// Actual modifier values, split for different coordinates if required