From bfe614a4d48e7af2511303613e9d29242e472177 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Mon, 25 Nov 2024 22:32:46 +0300 Subject: [PATCH] Fix character flashing in gpose when root bone is edited (disables position edits application in gpose) --- CustomizePlus/Armatures/Data/Armature.cs | 3 ++- .../Armatures/Services/ArmatureManager.cs | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CustomizePlus/Armatures/Data/Armature.cs b/CustomizePlus/Armatures/Data/Armature.cs index f898a1a..6e88246 100644 --- a/CustomizePlus/Armatures/Data/Armature.cs +++ b/CustomizePlus/Armatures/Data/Armature.cs @@ -175,8 +175,9 @@ public bool IsSkeletonUpdated(CharacterBase* cBase) var newPose = cBase->Skeleton->PartialSkeletons[i].GetHavokPose(Constants.TruePoseIndex); if (newPose != null - && newPose->Skeleton->Bones.Length != _partialSkeletons[i].Length) //todo: same length but different bone names (fucking hair) + && newPose->Skeleton->Bones.Length != _partialSkeletons[i].Length) return true; + //todo: compare bones for hair partial skeleton [2] } } diff --git a/CustomizePlus/Armatures/Services/ArmatureManager.cs b/CustomizePlus/Armatures/Services/ArmatureManager.cs index 18855e5..cdb3c1b 100644 --- a/CustomizePlus/Armatures/Services/ArmatureManager.cs +++ b/CustomizePlus/Armatures/Services/ArmatureManager.cs @@ -7,15 +7,13 @@ using CustomizePlus.Core.Data; using CustomizePlus.Core.Extensions; using CustomizePlus.Game.Services; -using CustomizePlus.GameData.Data; +using CustomizePlus.Game.Services.GPose; using CustomizePlus.GameData.Extensions; -using CustomizePlus.GameData.Services; using CustomizePlus.Profiles; using CustomizePlus.Profiles.Data; using CustomizePlus.Profiles.Events; using CustomizePlus.Templates.Events; using Dalamud.Plugin.Services; -using Lumina.Excel.Sheets; using OtterGui.Classes; using OtterGui.Log; using Penumbra.GameData.Actors; @@ -36,6 +34,7 @@ public unsafe sealed class ArmatureManager : IDisposable private readonly FrameworkManager _framework; private readonly ObjectManager _objectManager; private readonly ActorManager _actorManager; + private readonly GPoseService _gposeService; private readonly ArmatureChanged _event; /// @@ -56,6 +55,7 @@ public ArmatureManager( FrameworkManager framework, ObjectManager objectManager, ActorManager actorManager, + GPoseService gposeService, ArmatureChanged @event) { _profileManager = profileManager; @@ -67,6 +67,7 @@ public ArmatureManager( _framework = framework; _objectManager = objectManager; _actorManager = actorManager; + _gposeService = gposeService; _event = @event; _templateChangedEvent.Subscribe(OnTemplateChange, TemplateChanged.Priority.ArmatureManager); @@ -221,9 +222,16 @@ private unsafe void ApplyArmatureTransforms() ApplyPiecewiseTransformation(armature, actor, armature.ActorIdentifier); if (!_objectMovementFlagsArr[actor.AsObject->ObjectIndex]) - ApplyRootTranslation(armature, actor); + { + //todo: ApplyRootTranslation causes character flashing in gpose + //research if this can be fixed without breaking this functionality + if (_gposeService.IsInGPose) + continue; - _objectMovementFlagsArr[actor.AsObject->ObjectIndex] = false; + ApplyRootTranslation(armature, actor); + } + else + _objectMovementFlagsArr[actor.AsObject->ObjectIndex] = false; } } } @@ -337,8 +345,10 @@ private void ApplyRootTranslation(Armature arm, Actor actor, bool reset = false) var cBase = actor.Model.AsCharacterBase; if (cBase != null) { + //warn: hotpath for characters with n_root edits. IsApproximately might have some performance hit. var rootBoneTransform = arm.GetAppliedBoneTransform("n_root"); - if (rootBoneTransform == null) + if (rootBoneTransform == null || + rootBoneTransform.Translation.IsApproximately(Vector3.Zero, 0.00001f)) return; if (reset)