Skip to content

Commit

Permalink
Fix profile flickering, only reset root position if it was edited
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Nov 21, 2024
1 parent ebe7086 commit f092180
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions CustomizePlus/Armatures/Services/ArmatureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using CustomizePlus.Core.Data;
using CustomizePlus.Core.Extensions;
using CustomizePlus.Game.Services;
using CustomizePlus.GameData.Data;
using CustomizePlus.GameData.Extensions;
using CustomizePlus.GameData.Services;
using CustomizePlus.Profiles;
Expand Down Expand Up @@ -138,9 +139,12 @@ private void RefreshArmatures()
_logger.Debug($"Removing armature {armature} because {kvPair.Key.IncognitoDebug()} is gone");
RemoveArmature(armature, ArmatureChanged.DeletionReason.Gone);

//Reset root translation
foreach (var obj in actorData.Objects)
ApplyRootTranslation(null, obj);
if(actorData.Objects != null)
{
//Reset root translation
foreach (var obj in actorData.Objects)
ApplyRootTranslation(armature, obj, true);
}

continue;
}
Expand Down Expand Up @@ -185,9 +189,12 @@ private void RefreshArmatures()
_logger.Debug($"Removing armature {armature} because it doesn't have any active profiles");
RemoveArmature(armature, ArmatureChanged.DeletionReason.NoActiveProfiles);

//Reset root translation
foreach (var actor in obj.Value.Objects)
ApplyRootTranslation(null, actor);
if (obj.Value.Objects != null)
{
//Reset root translation
foreach (var actor in obj.Value.Objects)
ApplyRootTranslation(armature, actor, true);
}

continue;
}
Expand Down Expand Up @@ -325,9 +332,9 @@ private void ApplyPiecewiseTransformation(Armature armature, Actor actor, ActorI
}

/// <summary>
/// Apply root bone translation. If null armature is passed then position is reset.
/// Apply root bone translation. If reset = true then this will only reset translation if it was edited in supplied armature.
/// </summary>
private void ApplyRootTranslation(Armature? arm, Actor actor)
private void ApplyRootTranslation(Armature arm, Actor actor, bool reset = false)
{
//I'm honestly not sure if we should or even can check if cBase->DrawObject or cBase->DrawObject.Object is a valid object
//So for now let's assume we don't need to check for that
Expand All @@ -337,16 +344,16 @@ private void ApplyRootTranslation(Armature? arm, Actor actor)
var cBase = actor.Model.AsCharacterBase;
if (cBase != null)
{
if(arm == null)
var rootBoneTransform = arm.GetAppliedBoneTransform("n_root");
if (rootBoneTransform == null)
return;

if (reset)
{
cBase->DrawObject.Object.Position = actor.AsObject->Position;
return;
}

var rootBoneTransform = arm.GetAppliedBoneTransform("n_root");
if (rootBoneTransform == null)
return;

if (rootBoneTransform.Translation.X == 0 &&
rootBoneTransform.Translation.Y == 0 &&
rootBoneTransform.Translation.Z == 0)
Expand Down

0 comments on commit f092180

Please sign in to comment.