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

+31 -10
View File
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Numerics;
using GamePort.Assets;
using GamePort.Application;
using GamePort.Audio;
using GamePort.Platform;
using GamePort.Rendering.Vulkan;
@@ -48,7 +49,7 @@ internal static class Program
--smoke-window Test keyboard event/resize (requires --frames 6 or more)
--no-validation Disable development validation
Viewer: C toggles stored/orbit camera, arrows/WASD orbit, +/- zoom,
F11 fullscreen, Escape quit.
F11 fullscreen, Escape quit. Animation preview: 1 idle, 2 run, 3 jump, 4 scratch.
Gameplay, original animation speed/state and cutscenes remain under reconstruction.
""");
return 0;
@@ -91,18 +92,20 @@ internal static class Program
var animationPath = Option(args, "--animation");
if (args.Contains("--with-player") && scene != null)
animationPath ??= Path.Combine(Path.GetDirectoryName(scene)!, "../animations/jimstop/animation.json");
MorphAnimation? animation = null;
PreviewAnimationLibrary? animations = null;
var characterOffset = mesh.Vertices.Length;
var characterModel = Matrix4x4.Identity;
if (animationPath != null)
{
if (scene == null || originalStart == null)
throw new ArgumentException("A scene and matching GAM are required to place an animated player.");
animation = new MorphAnimation(animationPath);
mesh = animation.AppendTo(mesh);
characterModel = Matrix4x4.CreateRotationY(-originalStart.Rotation.Y * MathF.PI / 180)
* Matrix4x4.CreateTranslation(originalStart.Position);
Console.WriteLine("Original morph data loaded; playback looping/speed are preview policies.");
animations = new PreviewAnimationLibrary(animationPath);
var standingPose = AseMesh.Load(AssetPath.Resolve(root, "ASE/jimstop.ase"));
var placement = PreviewCharacterPlacement.Create(mesh, standingPose, originalStart.Position, originalStart.Rotation.Y);
characterModel = placement.Model;
mesh = animations.Current.AppendTo(mesh);
Console.WriteLine($"Preview floor correction: +{placement.VerticalCorrection:F3} Y; original GAM position remains unchanged.");
Console.WriteLine("Scene preview: 1 idle (still pose), 2 run, 3 jump, 4 scratch. Playback loop/speed are preview policies; gameplay is incomplete.");
}
Console.WriteLine($"Loaded original geometry: {mesh.Vertices.Length} vertices, {mesh.Indices.Length / 3} triangles, {mesh.Textures.Count + (scene == null ? 1 : 0)} textures.");
var fixedTimeText = Option(args, "--time");
@@ -116,7 +119,7 @@ internal static class Program
if (!headless)
{
if (!Sdl.SDL_Init(Sdl.InitVideo)) throw new InvalidOperationException(Sdl.Error);
window = Sdl.SDL_CreateWindow("Jimmy Neutron reconstruction — scene investigation", 960, 720,
window = Sdl.SDL_CreateWindow(animations?.WindowTitle ?? "Jimmy Neutron — scene preview | C camera", 960, 720,
Sdl.WindowVulkan | Sdl.WindowResizable | Sdl.WindowHighPixelDensity);
if (window == 0) { Sdl.SDL_Quit(); throw new InvalidOperationException(Sdl.Error); }
}
@@ -131,6 +134,8 @@ internal static class Program
var sawKey = false;
var didResize = false;
var clock = Stopwatch.StartNew();
var animationStarted = 0.0;
var animationSwitched = false;
double last = clock.Elapsed.TotalSeconds;
float angle = 0.6f, elevation = 0.32f;
var count = 0;
@@ -146,6 +151,12 @@ internal static class Program
keys.Add(e.Scancode);
if (smoke && e.Scancode == 79) sawKey = true;
if (e.Scancode == 41) running = false;
if (e.Repeat == 0 && animations?.Select(e.Scancode) == true)
{
animationStarted = clock.Elapsed.TotalSeconds;
animationSwitched = true;
if (!Sdl.SDL_SetWindowTitle(window, animations.WindowTitle)) throw new InvalidOperationException(Sdl.Error);
}
if (e.Scancode == 6 && e.Repeat == 0 && originalStart != null)
originalCamera = !originalCamera;
if (e.Scancode == 68 && e.Repeat == 0)
@@ -176,9 +187,9 @@ internal static class Program
? Matrix4x4.CreatePerspectiveFieldOfViewLeftHanded(0xAAA / 16384f * MathF.Tau, (float)renderer.Width / renderer.Height, 20, far)
: Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 3, (float)renderer.Width / renderer.Height, Math.Max(radius / 10000, 0.01f), radius * 20);
projection.M22 *= -1;
if (animation != null)
if (animations != null)
{
animation.Sample(fixedTime ?? (headless ? count / 60.0 : now), mesh.Vertices.AsSpan(characterOffset), characterModel);
animations.Current.Sample(fixedTime ?? (headless ? count / 60.0 : now - animationStarted), mesh.Vertices.AsSpan(characterOffset), characterModel);
renderer.UpdateVertices(mesh.Vertices);
}
renderer.Render(view * projection);
@@ -189,6 +200,11 @@ internal static class Program
var key = new Sdl.Event { Type = Sdl.KeyDown, Scancode = 79, Down = 1 };
if (!Sdl.SDL_PushEvent(ref key) || !Sdl.SDL_SetWindowSize(window, 800, 600))
throw new InvalidOperationException(Sdl.Error);
if (animations != null)
{
var cycle = new Sdl.Event { Type = Sdl.KeyDown, Scancode = 31, Down = 1 };
if (!Sdl.SDL_PushEvent(ref cycle)) throw new InvalidOperationException(Sdl.Error);
}
}
if (smoke && renderer.Width == 800 && renderer.Height == 600) didResize = true;
if (frames > 0 && count >= frames) break;
@@ -207,6 +223,11 @@ internal static class Program
{
Console.WriteLine($"SDL3 injected keyboard event received: {sawKey}; swapchain resized to 800x600: {didResize}.");
if (!sawKey || !didResize) return 2;
if (animations != null)
{
Console.WriteLine($"Animation preview switched by keyboard to {animations.Name}: {animationSwitched}; moving source samples: {animations.Current.HasVertexMotion}.");
if (!animationSwitched || !animations.Current.HasVertexMotion) return 2;
}
}
return renderer.ValidationErrors > 0 || changed == 0 ? 2 : 0;
}