Skip to content

Commit

Permalink
Fix character flashing in gpose when root bone is edited (disables po…
Browse files Browse the repository at this point in the history
…sition edits application in gpose)
  • Loading branch information
RisaDev committed Nov 25, 2024
1 parent 9fbcf68 commit bfe614a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CustomizePlus/Armatures/Data/Armature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

Expand Down
22 changes: 16 additions & 6 deletions CustomizePlus/Armatures/Services/ArmatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/// <summary>
Expand All @@ -56,6 +55,7 @@ public ArmatureManager(
FrameworkManager framework,
ObjectManager objectManager,
ActorManager actorManager,
GPoseService gposeService,
ArmatureChanged @event)
{
_profileManager = profileManager;
Expand All @@ -67,6 +67,7 @@ public ArmatureManager(
_framework = framework;
_objectManager = objectManager;
_actorManager = actorManager;
_gposeService = gposeService;
_event = @event;

_templateChangedEvent.Subscribe(OnTemplateChange, TemplateChanged.Priority.ArmatureManager);
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bfe614a

Please sign in to comment.