From 18f0d3a772d36bb2de0d103438588b7bb3e649ed Mon Sep 17 00:00:00 2001 From: 4sval Date: Tue, 7 Mar 2023 02:48:03 +0100 Subject: [PATCH] additive ref pose type --- CUE4Parse | 2 +- FModel/MainWindow.xaml.cs | 7 +++++ FModel/Views/Snooper/Animations/Animation.cs | 2 +- FModel/Views/Snooper/Animations/Sequence.cs | 2 +- FModel/Views/Snooper/Animations/Skeleton.cs | 13 ++------- FModel/Views/Snooper/Renderer.cs | 30 ++++++++++++-------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index 0a7c62d7..55d34868 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 0a7c62d751d6ea91bc12fd59c6541cc01a04cb01 +Subproject commit 55d34868df2cd33aa4daf6815076f36921492471 diff --git a/FModel/MainWindow.xaml.cs b/FModel/MainWindow.xaml.cs index eababa1b..eec22ac6 100644 --- a/FModel/MainWindow.xaml.cs +++ b/FModel/MainWindow.xaml.cs @@ -76,6 +76,13 @@ public partial class MainWindow _discordHandler.Initialize(_applicationView.CUE4Parse.Provider.GameName); #if DEBUG + // await _threadWorkerView.Begin(cancellationToken => + // _applicationView.CUE4Parse.Extract(cancellationToken, + // "ShooterGame/Content/Characters/_Core/3P/Models/TP_Core_NewMale_Skelmesh.uasset")); + // await _threadWorkerView.Begin(cancellationToken => + // _applicationView.CUE4Parse.Extract(cancellationToken, + // "Game/Characters/_Core/3P/Anims/TP_Core_SprintAddN_UB.uasset")); + // await _threadWorkerView.Begin(cancellationToken => // _applicationView.CUE4Parse.Extract(cancellationToken, // "ShooterGame/Content/Characters/Guide/S0/1P/Models/FP_Guide_S0_Skelmesh.uasset")); diff --git a/FModel/Views/Snooper/Animations/Animation.cs b/FModel/Views/Snooper/Animations/Animation.cs index fec58844..d87d7fe1 100644 --- a/FModel/Views/Snooper/Animations/Animation.cs +++ b/FModel/Views/Snooper/Animations/Animation.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using CUE4Parse_Conversion.Animations; +using CUE4Parse_Conversion.Animations.PSA; using CUE4Parse.UE4.Assets.Exports; using CUE4Parse.UE4.Objects.Core.Misc; using CUE4Parse.Utils; diff --git a/FModel/Views/Snooper/Animations/Sequence.cs b/FModel/Views/Snooper/Animations/Sequence.cs index c4554750..b0668be5 100644 --- a/FModel/Views/Snooper/Animations/Sequence.cs +++ b/FModel/Views/Snooper/Animations/Sequence.cs @@ -1,5 +1,5 @@ using System.Numerics; -using CUE4Parse_Conversion.Animations; +using CUE4Parse_Conversion.Animations.PSA; using CUE4Parse.Utils; using ImGuiNET; diff --git a/FModel/Views/Snooper/Animations/Skeleton.cs b/FModel/Views/Snooper/Animations/Skeleton.cs index 9abc45bf..a5263eed 100644 --- a/FModel/Views/Snooper/Animations/Skeleton.cs +++ b/FModel/Views/Snooper/Animations/Skeleton.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Numerics; -using CUE4Parse_Conversion.Animations; +using CUE4Parse_Conversion.Animations.PSA; using CUE4Parse.UE4.Assets.Exports.Animation; using CUE4Parse.UE4.Objects.Core.Math; using FModel.Views.Snooper.Buffers; @@ -68,7 +68,6 @@ public class Skeleton : IDisposable boneTransform.Relation = parentTransform.Matrix; Matrix4x4.Invert(boneTransform.Matrix, out var inverted); - BonesTransformByIndex[boneIndices.BoneIndex] = boneTransform; _invertedBonesMatrix[boneIndices.BoneIndex] = inverted; } @@ -109,9 +108,7 @@ public class Skeleton : IDisposable var bonePosition = originalTransform.Position; var boneScale = originalTransform.Scale; - sequence.Tracks[trackedBoneIndex].GetBonePosition(frame, sequence.NumFrames, false, ref bonePosition, ref boneOrientation); - if (frame < sequence.Tracks[trackedBoneIndex].KeyScale.Length) - boneScale = sequence.Tracks[trackedBoneIndex].KeyScale[frame]; + sequence.Tracks[trackedBoneIndex].GetBoneTransform(frame, sequence.NumFrames, ref boneOrientation, ref bonePosition, ref boneScale); switch (anim.BoneModes[trackedBoneIndex]) { @@ -166,15 +163,11 @@ public class Skeleton : IDisposable } } - // revert FixRotationKeys - if (trackedBoneIndex > 0) boneOrientation.Conjugate(); - bonePosition *= Constants.SCALE_DOWN_RATIO; - _animatedBonesTransform[s][boneIndices.BoneIndex][frame] = new Transform { Relation = boneIndices.IsParentTracked ? _animatedBonesTransform[s][boneIndices.TrackedParentBoneIndex][frame].Matrix : originalTransform.Relation, Rotation = boneOrientation, - Position = rotationOnly ? originalTransform.Position : bonePosition, + Position = rotationOnly ? originalTransform.Position : bonePosition * Constants.SCALE_DOWN_RATIO, Scale = sequence.bAdditive ? FVector.OneVector : boneScale }; } diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index 530cff30..d6319af2 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -111,7 +111,7 @@ public class Renderer : IDisposable float maxElapsedTime; switch (anim) { - case UAnimSequence animSequence when /*!animSequence.IsValidAdditive() && */animSequence.Skeleton.TryLoad(out USkeleton skeleton): + case UAnimSequence animSequence when !animSequence.IsValidAdditive() && animSequence.Skeleton.TryLoad(out USkeleton skeleton): { var animSet = skeleton.ConvertAnims(animSequence); var animation = new Animation(animSequence, animSet, guid); @@ -120,19 +120,26 @@ public class Renderer : IDisposable Options.AddAnimation(animation); break; } - /*case UAnimSequence additiveAnimSequence when additiveAnimSequence.IsValidAdditive() && additiveAnimSequence.Skeleton.TryLoad(out USkeleton additiveSkeleton): + case UAnimSequence additiveAnimSequence when additiveAnimSequence.IsValidAdditive() && additiveAnimSequence.Skeleton.TryLoad(out USkeleton additiveSkeleton): { var reference = additiveAnimSequence.RefPoseSeq?.Load(); - var referenceSkeleton = reference.Skeleton.Load(); + var referenceSkeleton = reference?.Skeleton.Load() ?? additiveSkeleton; var additiveAnimSet = additiveSkeleton.ConvertAnims(additiveAnimSequence); var referenceAnimSet = referenceSkeleton.ConvertAnims(reference); - var additivePoses = FAnimationRuntime.LoadAsPoses(additiveAnimSet, additiveSkeleton); - var referencePoses = FAnimationRuntime.LoadAsPoses(referenceAnimSet, referenceSkeleton, additiveAnimSet.Sequences[0].NumFrames, additiveAnimSequence.RefFrameIndex); + FCompactPose[] additivePoses = FAnimationRuntime.LoadAsPoses(additiveAnimSet); + FCompactPose[] referencePoses = additiveAnimSequence.RefPoseType switch + { + EAdditiveBasePoseType.ABPT_RefPose => FAnimationRuntime.LoadRestAsPoses(additiveAnimSet), + // EAdditiveBasePoseType.ABPT_AnimScaled => FAnimationRuntime.LoadAsPoses(referenceAnimSet), + EAdditiveBasePoseType.ABPT_AnimFrame => FAnimationRuntime.LoadAsPoses(referenceAnimSet, additiveAnimSequence.RefFrameIndex), + EAdditiveBasePoseType.ABPT_LocalAnimFrame => FAnimationRuntime.LoadAsPoses(additiveAnimSet, additiveAnimSequence.RefFrameIndex), + _ => throw new NotImplementedException() + }; var animSeq = additiveAnimSet.Sequences[0]; - animSeq.OriginalSequence = referenceAnimSet.Sequences[0].OriginalSequence; + if (reference != null) animSeq.OriginalSequence = referenceAnimSet.Sequences[0].OriginalSequence; animSeq.Tracks = new List(additivePoses[0].Bones.Length); for (int i = 0; i < additivePoses[0].Bones.Length; i++) { @@ -140,10 +147,10 @@ public class Renderer : IDisposable } //loop trough each Pose/Frame and add the output to the empty tracks - for (var index = 0; index < additivePoses.Length; index++) + for (var frameIndex = 0; frameIndex < additivePoses.Length; frameIndex++) { - var addPose = additivePoses[index]; - var refPose = referencePoses[index]; + var addPose = additivePoses[frameIndex]; + var refPose = (FCompactPose)referencePoses[additiveAnimSequence.RefFrameIndex].Clone(); switch (additiveAnimSequence.AdditiveAnimType) { case EAdditiveAnimationType.AAT_LocalSpaceBase: @@ -154,8 +161,7 @@ public class Renderer : IDisposable break; } - refPose.Processed = true; - refPose.AddToTracks(animSeq.Tracks); + refPose.AddToTracks(animSeq.Tracks, frameIndex); } var animation = new Animation(additiveAnimSequence, additiveAnimSet, guid); @@ -163,7 +169,7 @@ public class Renderer : IDisposable model.Skeleton.Animate(additiveAnimSet, AnimateWithRotationOnly); Options.AddAnimation(animation); break; - }*/ + } case UAnimMontage animMontage when animMontage.Skeleton.TryLoad(out USkeleton skeleton): { var animSet = skeleton.ConvertAnims(animMontage);