mirror of
https://github.com/4sval/FModel.git
synced 2026-06-22 16:00:17 -05:00
play anim sequences consecutively
This commit is contained in:
parent
70d4791b5b
commit
1ca18c3958
|
|
@ -1 +1 @@
|
|||
Subproject commit e69c4c17cac920a0be25e531562c5cda9e482628
|
||||
Subproject commit 8f70ce981ed65ee9dcb4948905a58da2f3730a82
|
||||
|
|
@ -81,9 +81,9 @@ public partial class MainWindow
|
|||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
_applicationView.CUE4Parse.Extract(cancellationToken,
|
||||
"MoonMan/Content/DeliverUsTheMoon/Characters/Astronaut/AM_ControllingASE.uasset"));
|
||||
// await _threadWorkerView.Begin(cancellationToken =>
|
||||
// _applicationView.CUE4Parse.Extract(cancellationToken,
|
||||
// "Hk_project/Content/Animation/CAT/Jump/CAT_JUMP_L050_H-050.uasset"));
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
_applicationView.CUE4Parse.Extract(cancellationToken,
|
||||
"MoonMan/Content/DeliverUsTheMoon/Characters/Astronaut/AM_OxygenHub_Enter.uasset"));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,18 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using CUE4Parse_Conversion.Animations;
|
||||
using CUE4Parse.Utils;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace FModel.Views.Snooper.Models.Animations;
|
||||
|
||||
public class Animation : IDisposable
|
||||
{
|
||||
public float ElapsedTime;
|
||||
|
||||
public int CurrentSequence;
|
||||
public readonly Sequence[] Sequences;
|
||||
public int SequencesCount => Sequences.Length;
|
||||
|
||||
public Animation()
|
||||
{
|
||||
ElapsedTime = 0;
|
||||
Sequences = Array.Empty<Sequence>();
|
||||
}
|
||||
|
||||
|
|
@ -31,8 +27,7 @@ public class Animation : IDisposable
|
|||
|
||||
public void Update(float deltaSeconds)
|
||||
{
|
||||
ElapsedTime += deltaSeconds / Sequences[CurrentSequence].TimePerFrame;
|
||||
Sequences[CurrentSequence].Frame = ElapsedTime.FloorToInt() % Sequences[CurrentSequence].MaxFrame;
|
||||
Sequences[CurrentSequence].Update(deltaSeconds);
|
||||
}
|
||||
|
||||
public Matrix4x4 InterpolateBoneTransform(int trackIndex)
|
||||
|
|
@ -41,11 +36,24 @@ public class Animation : IDisposable
|
|||
return Sequences[CurrentSequence].BonesTransform[trackIndex][Sequences[CurrentSequence].Frame].Matrix;
|
||||
}
|
||||
|
||||
public void CheckForNextSequence()
|
||||
{
|
||||
if (Sequences[CurrentSequence].ElapsedTime > Sequences[CurrentSequence].EndPos)
|
||||
{
|
||||
Sequences[CurrentSequence].ElapsedTime = 0;
|
||||
Sequences[CurrentSequence].Frame = 0;
|
||||
CurrentSequence++;
|
||||
}
|
||||
|
||||
if (CurrentSequence >= SequencesCount)
|
||||
{
|
||||
CurrentSequence = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void ImGuiTimeline()
|
||||
{
|
||||
ImGui.BeginDisabled(SequencesCount < 2);
|
||||
ImGui.DragInt("Sequence", ref CurrentSequence, 1, 0, Sequences.Length - 1, Sequences[CurrentSequence].Name);
|
||||
ImGui.EndDisabled();
|
||||
ImGui.Text($"{Sequences[CurrentSequence].Name} > {(CurrentSequence < SequencesCount - 1 ? Sequences[CurrentSequence + 1].Name : Sequences[0].Name)}");
|
||||
ImGui.Text($"Frame: {Sequences[CurrentSequence].Frame}/{Sequences[CurrentSequence].MaxFrame}");
|
||||
ImGui.Text($"FPS: {Sequences[CurrentSequence].FramesPerSecond}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,37 @@
|
|||
using System;
|
||||
using CUE4Parse_Conversion.Animations;
|
||||
using CUE4Parse.Utils;
|
||||
|
||||
namespace FModel.Views.Snooper.Models.Animations;
|
||||
|
||||
public class Sequence : IDisposable
|
||||
{
|
||||
public int Frame;
|
||||
public float ElapsedTime;
|
||||
public readonly string Name;
|
||||
public readonly int MaxFrame;
|
||||
public readonly float FramesPerSecond;
|
||||
public readonly float StartPos;
|
||||
public readonly float AnimStartTime;
|
||||
public readonly float AnimEndTime;
|
||||
public readonly int LoopingCount;
|
||||
|
||||
public float TimePerFrame => 1.0f / FramesPerSecond;
|
||||
public float EndPos => AnimEndTime / TimePerFrame;
|
||||
|
||||
public readonly Transform[][] BonesTransform;
|
||||
|
||||
public Sequence(CAnimSequence sequence, Skeleton skeleton, bool rotationOnly)
|
||||
{
|
||||
Frame = 0;
|
||||
ElapsedTime = 0.0f;
|
||||
Name = sequence.Name;
|
||||
MaxFrame = sequence.NumFrames;
|
||||
MaxFrame = sequence.NumFrames - 1;
|
||||
FramesPerSecond = sequence.Rate;
|
||||
StartPos = sequence.StartPos;
|
||||
AnimStartTime = sequence.AnimStartTime;
|
||||
AnimEndTime = sequence.AnimEndTime;
|
||||
LoopingCount = sequence.LoopingCount;
|
||||
|
||||
BonesTransform = new Transform[skeleton.BonesTransformByIndex.Count][];
|
||||
for (int trackIndex = 0; trackIndex < skeleton.UnrealSkeleton.ReferenceSkeleton.FinalRefBoneInfo.Length; trackIndex++)
|
||||
|
|
@ -30,14 +42,14 @@ public class Sequence : IDisposable
|
|||
|
||||
var originalTransform = skeleton.BonesTransformByIndex[boneIndices.Index];
|
||||
|
||||
BonesTransform[boneIndices.Index] = new Transform[MaxFrame];
|
||||
BonesTransform[boneIndices.Index] = new Transform[sequence.NumFrames];
|
||||
for (int frame = 0; frame < BonesTransform[boneIndices.Index].Length; frame++)
|
||||
{
|
||||
var boneOrientation = originalTransform.Rotation;
|
||||
var bonePosition = originalTransform.Position;
|
||||
var boneScale = originalTransform.Scale;
|
||||
|
||||
sequence.Tracks[trackIndex].GetBonePosition(frame, MaxFrame, false, ref bonePosition, ref boneOrientation);
|
||||
sequence.Tracks[trackIndex].GetBonePosition(frame, sequence.NumFrames, false, ref bonePosition, ref boneOrientation);
|
||||
if (frame < sequence.Tracks[trackIndex].KeyScale.Length)
|
||||
boneScale = sequence.Tracks[trackIndex].KeyScale[frame];
|
||||
|
||||
|
|
@ -69,6 +81,12 @@ public class Sequence : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
public void Update(float deltaSeconds)
|
||||
{
|
||||
ElapsedTime += deltaSeconds / TimePerFrame;
|
||||
Frame = Math.Min(ElapsedTime.FloorToInt(), MaxFrame);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ public class Skeleton : IDisposable
|
|||
|
||||
shader.SetUniform($"uFinalBonesMatrix[{boneIndex}]", invertMatrix * Anim.InterpolateBoneTransform(boneIndex));
|
||||
}
|
||||
if (update) Anim.CheckForNextSequence();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user