Correct preview ground placement and expose original animation clips

This commit is contained in:
UnixNight committed 2026-10-23 18:12:54 -04:00
1 parent 670adb4795
commit 37fa18094f
22 files changed
+398 -33

No files matched your search

@@ -0,0 +1,45 @@
using GamePort.Assets;
namespace GamePort.Application;
/// <summary>Explicit animation inspection; does not simulate player actions.</summary>
public sealed class PreviewAnimationLibrary
{
private readonly Dictionary<uint, (string Name, MorphAnimation Animation)> choices = [];
public MorphAnimation Current { get; private set; }
public string Name { get; private set; }
public string WindowTitle => $"Jimmy Neutron — scene preview | {Name}{(Current.HasVertexMotion ? "" : " (still pose)")} | 1 idle, 2 run, 3 jump, 4 scratch | C camera";
public PreviewAnimationLibrary(string manifest)
{
Current = new MorphAnimation(manifest);
Name = Path.GetFileName(Path.GetDirectoryName(Path.GetFullPath(manifest)))!;
var parent = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(manifest)!, ".."));
foreach (var (scancode, folder, label) in new[]
{
(30u, "jimstop", "Idle"), (31u, "jimrun", "Run cycle"),
(32u, "jimjump", "Jump cycle"), (33u, "jimscratch", "Scratch cycle")
})
{
var path = Path.Combine(parent, folder, "animation.json");
if (!File.Exists(path)) continue;
var clip = Path.GetFullPath(path) == Path.GetFullPath(manifest) ? Current : new MorphAnimation(path);
if (clip.Base.Vertices.Length != Current.Base.Vertices.Length
|| !clip.Base.Indices.SequenceEqual(Current.Base.Indices)
|| !clip.Base.Vertices.Select(v => v.Uv).SequenceEqual(Current.Base.Vertices.Select(v => v.Uv))
|| clip.Texture.Width != Current.Texture.Width || clip.Texture.Height != Current.Texture.Height
|| !clip.Texture.Rgba.SequenceEqual(Current.Texture.Rgba))
throw new InvalidDataException($"Animation family mismatch: {path}");
choices[scancode] = (label, clip);
if (ReferenceEquals(clip, Current)) Name = label;
}
}
public bool Select(uint scancode)
{
if (!choices.TryGetValue(scancode, out var clip)) return false;
Current = clip.Animation;
Name = clip.Name;
return true;
}
}