Skip to content

Commit 1707f41

Browse files
committed
preview anims without pre-loading a mesh
the anim's default skeleton will act as the loaded mesh if none was provided added links to mesh importers in the settings
1 parent e7148d8 commit 1707f41

File tree

9 files changed

+122
-45
lines changed

9 files changed

+122
-45
lines changed

CUE4Parse

FModel/Settings/UserSettings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public Hotkey NextAudio
360360
set => SetProperty(ref _nextAudio, value);
361361
}
362362

363-
private EMeshFormat _meshExportFormat = EMeshFormat.ActorX;
363+
private EMeshFormat _meshExportFormat = EMeshFormat.UEFormat;
364364
public EMeshFormat MeshExportFormat
365365
{
366366
get => _meshExportFormat;
@@ -451,6 +451,13 @@ public bool PreviewSkeletalMeshes
451451
set => SetProperty(ref _previewSkeletalMeshes, value);
452452
}
453453

454+
private bool _previewAnimations = true;
455+
public bool PreviewAnimations
456+
{
457+
get => _previewAnimations;
458+
set => SetProperty(ref _previewAnimations, value);
459+
}
460+
454461
private bool _previewMaterials = true;
455462
public bool PreviewMaterials
456463
{

FModel/ViewModels/CUE4ParseViewModel.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ public bool ModelIsOverwritingMaterial
7777
set => SetProperty(ref _modelIsOverwritingMaterial, value);
7878
}
7979

80-
private bool _modelIsWaitingAnimation;
81-
public bool ModelIsWaitingAnimation
82-
{
83-
get => _modelIsWaitingAnimation;
84-
set => SetProperty(ref _modelIsWaitingAnimation, value);
85-
}
86-
8780
public bool IsSnooperOpen => _snooper is { Exists: true, IsVisible: true };
8881
private Snooper _snooper;
8982
public Snooper SnooperViewer
@@ -868,9 +861,10 @@ public void ExtractAndScroll(CancellationToken cancellationToken, string fullPat
868861
SnooperViewer.Run();
869862
return true;
870863
}
871-
case UAnimSequenceBase when isNone && ModelIsWaitingAnimation:
864+
case UAnimSequenceBase when isNone && UserSettings.Default.PreviewAnimations || SnooperViewer.Renderer.Options.ModelIsWaitingAnimation:
872865
{
873-
SnooperViewer.Renderer.Animate(pointer.Object);
866+
// animate all animations using their specified skeleton or when we explicitly asked for a loaded model to be animated (ignoring whether we wanted to preview animations)
867+
SnooperViewer.Renderer.Animate(pointer.Object.Value);
874868
SnooperViewer.Run();
875869
return true;
876870
}

FModel/Views/SettingsView.xaml

Lines changed: 77 additions & 29 deletions
Large diffs are not rendered by default.

FModel/Views/Snooper/Animations/Skeleton.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Numerics;
55
using CUE4Parse_Conversion.Animations.PSA;
66
using CUE4Parse.UE4.Assets.Exports.Animation;
7+
using CUE4Parse.UE4.Objects.Core.Misc;
78
using FModel.Views.Snooper.Buffers;
89
using FModel.Views.Snooper.Shading;
910
using ImGuiNET;
@@ -21,6 +22,7 @@ public class Skeleton : IDisposable
2122
private readonly List<string> _breadcrumb;
2223

2324
public string Name;
25+
public FGuid Guid;
2426
public readonly Dictionary<string, Bone> BonesByLoweredName;
2527

2628
public readonly int BoneCount;

FModel/Views/Snooper/Models/SkeletalModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public SkeletalModel(USkeletalMesh export, CSkeletalMesh skeletalMesh, Transform
3636
if (export.Skeleton.TryLoad(out USkeleton skeleton))
3737
{
3838
Skeleton.Name = skeleton.Name;
39+
Skeleton.Guid = skeleton.Guid;
3940
// Skeleton.Merge(skeleton.ReferenceSkeleton);
4041
sockets.AddRange(skeleton.Sockets);
4142
}
@@ -116,15 +117,18 @@ public SkeletalModel(USkeleton export, FBox box) : base(export)
116117
AddInstance(Transform.Identity);
117118

118119
Box = box * Constants.SCALE_DOWN_RATIO;
119-
Morphs = new List<Morph>();
120+
Morphs = [];
120121
Skeleton = new Skeleton(export.ReferenceSkeleton);
121122
Skeleton.Name = export.Name;
123+
Skeleton.Guid = export.Guid;
122124

123125
for (int i = 0; i < export.Sockets.Length; i++)
124126
{
125127
if (export.Sockets[i].Load<USkeletalMeshSocket>() is not { } socket) continue;
126128
Sockets.Add(new Socket(socket));
127129
}
130+
131+
IsVisible = true;
128132
}
129133

130134
public override void Setup(Options options)

FModel/Views/Snooper/Options.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace FModel.Views.Snooper;
1616
public class Options
1717
{
1818
public FGuid SelectedModel { get; private set; }
19+
public bool ModelIsWaitingAnimation { get; private set; }
1920
public int SelectedSection { get; private set; }
2021
public int SelectedMorph { get; private set; }
2122
public int SelectedAnimation{ get; private set; }
@@ -238,7 +239,7 @@ public void SwapMaterial(bool value)
238239

239240
public void AnimateMesh(bool value)
240241
{
241-
Services.ApplicationService.ApplicationView.CUE4Parse.ModelIsWaitingAnimation = value;
242+
ModelIsWaitingAnimation = value;
242243
}
243244

244245
public void ResetModelsLightsAnimations()

FModel/Views/Snooper/Renderer.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,28 @@ public void Swap(UMaterialInstance unrealMaterial)
119119
Application.Current.Dispatcher.Invoke(() => model.Materials[section.MaterialIndex].Setup(Options, model.UvCount));
120120
}
121121

122-
public void Animate(Lazy<UObject> anim) => Animate(anim.Value, Options.SelectedModel);
122+
public void Animate(UObject anim)
123+
{
124+
if (!Options.ModelIsWaitingAnimation)
125+
{
126+
if (anim is UAnimSequenceBase animBase)
127+
{
128+
/*if (Options.TryGetModel(out var selected) &&
129+
selected is SkeletalModel { IsVisible: true } skeletalModel &&
130+
skeletalModel.Skeleton.Guid == animBase.SkeletonGuid)
131+
{
132+
// do nothing, selected model has the correct skeleton for this animation
133+
}
134+
else */if (animBase.Skeleton.TryLoad(out USkeleton skeleton))
135+
{
136+
LoadSkeleton(skeleton);
137+
}
138+
}
139+
else return; // should never end here
140+
}
141+
142+
Animate(anim, Options.SelectedModel);
143+
}
123144
private void Animate(UObject anim, FGuid guid)
124145
{
125146
if (anim is not UAnimSequenceBase animBase || !animBase.Skeleton.TryLoad(out USkeleton skeleton) ||
@@ -285,7 +306,7 @@ public void Update(Snooper wnd, float deltaSeconds)
285306
animation.TimeCalculation(Options.Tracker.ElapsedTime);
286307
foreach (var guid in animation.AttachedModels)
287308
{
288-
if (Options.Models[guid] is not SkeletalModel skeletalModel) continue;
309+
if (!Options.TryGetModel(guid, out var m) || m is not SkeletalModel skeletalModel) continue;
289310
skeletalModel.Skeleton.UpdateAnimationMatrices(animation, AnimateWithRotationOnly);
290311
}
291312
}

FModel/Views/Snooper/Snooper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public unsafe void WindowShouldClose(bool value, bool clear)
4444
{
4545
if (clear)
4646
{
47-
Renderer.CameraOp.Speed = 0;
47+
Renderer.CameraOp.Speed = 1f;
4848
Renderer.Save();
4949
}
5050

0 commit comments

Comments
 (0)