Fix profile flickering, only reset root position if it was edited

This commit is contained in:
RisaDev
2024-11-21 20:27:00 +03:00
parent ebe7086238
commit f09218013d

View File

@@ -7,6 +7,7 @@ using CustomizePlus.Armatures.Events;
using CustomizePlus.Core.Data; using CustomizePlus.Core.Data;
using CustomizePlus.Core.Extensions; using CustomizePlus.Core.Extensions;
using CustomizePlus.Game.Services; using CustomizePlus.Game.Services;
using CustomizePlus.GameData.Data;
using CustomizePlus.GameData.Extensions; using CustomizePlus.GameData.Extensions;
using CustomizePlus.GameData.Services; using CustomizePlus.GameData.Services;
using CustomizePlus.Profiles; using CustomizePlus.Profiles;
@@ -138,9 +139,12 @@ public unsafe sealed class ArmatureManager : IDisposable
_logger.Debug($"Removing armature {armature} because {kvPair.Key.IncognitoDebug()} is gone"); _logger.Debug($"Removing armature {armature} because {kvPair.Key.IncognitoDebug()} is gone");
RemoveArmature(armature, ArmatureChanged.DeletionReason.Gone); RemoveArmature(armature, ArmatureChanged.DeletionReason.Gone);
//Reset root translation if(actorData.Objects != null)
foreach (var obj in actorData.Objects) {
ApplyRootTranslation(null, obj); //Reset root translation
foreach (var obj in actorData.Objects)
ApplyRootTranslation(armature, obj, true);
}
continue; continue;
} }
@@ -185,9 +189,12 @@ public unsafe sealed class ArmatureManager : IDisposable
_logger.Debug($"Removing armature {armature} because it doesn't have any active profiles"); _logger.Debug($"Removing armature {armature} because it doesn't have any active profiles");
RemoveArmature(armature, ArmatureChanged.DeletionReason.NoActiveProfiles); RemoveArmature(armature, ArmatureChanged.DeletionReason.NoActiveProfiles);
//Reset root translation if (obj.Value.Objects != null)
foreach (var actor in obj.Value.Objects) {
ApplyRootTranslation(null, actor); //Reset root translation
foreach (var actor in obj.Value.Objects)
ApplyRootTranslation(armature, actor, true);
}
continue; continue;
} }
@@ -325,9 +332,9 @@ public unsafe sealed class ArmatureManager : IDisposable
} }
/// <summary> /// <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> /// </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 //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 //So for now let's assume we don't need to check for that
@@ -337,16 +344,16 @@ public unsafe sealed class ArmatureManager : IDisposable
var cBase = actor.Model.AsCharacterBase; var cBase = actor.Model.AsCharacterBase;
if (cBase != null) 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; cBase->DrawObject.Object.Position = actor.AsObject->Position;
return; return;
} }
var rootBoneTransform = arm.GetAppliedBoneTransform("n_root");
if (rootBoneTransform == null)
return;
if (rootBoneTransform.Translation.X == 0 && if (rootBoneTransform.Translation.X == 0 &&
rootBoneTransform.Translation.Y == 0 && rootBoneTransform.Translation.Y == 0 &&
rootBoneTransform.Translation.Z == 0) rootBoneTransform.Translation.Z == 0)