diff --git a/README.md b/README.md index 5e202ec..16d6275 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ using C#/.NET 10, Silk.NET.Vulkan (Vulkan 1.3), and SDL3. Original files remain untouched in `../Original`. There are no Git remotes or runtime online services. **Current milestone: recovered original assets, a native rendered lab scene with -an animated Jimmy preview, and Linux/Windows investigation packages. Full +selectable Jimmy animation previews, and Linux/Windows investigation packages. Full playable gameplay has not been reconstructed.** Controls, collision, introductory cutscenes, interactions, progression and saves still require implementation and comparison. See [progress](docs/progress.md) and [compatibility](docs/compatibility.md). @@ -25,6 +25,11 @@ The default scene is the original secret lab (LV1B) with its recorded start came Press **C** to switch between stored and inspection cameras; arrows/WASD orbit, plus/minus zoom, F11 toggles fullscreen, Escape quits. These are investigation controls. Original gameplay controls are documented in `docs/analysis/gameplay.md`. +The default idle asset is a still pose: its two original samples are identical. +Press **1** for idle, **2** for the run animation, **3** for the jump animation, +or **4** for the scratch animation. These preview cycles do not control movement. +The player mesh is raised onto visible floor geometry for preview; exact original +actor/collision transforms remain under investigation. GAM positions are unchanged. Without a prepared scene, the app previews the original Jimmy base model. Headless verification on a machine with Vulkan 1.3 (Mesa lavapipe works): @@ -69,8 +74,9 @@ Packages are local directories `dist/linux-x64` and `dist/win-x64`. Run `launch-scene.sh` or `launch-scene.cmd`; append `--headless --frames 1` for a render smoke test. They include the .NET runtime, SDL3 native library, SPIR-V, original asset copies, prepared lab/Jimmy resources, audio and limitations. -Windows cross-publishing and preliminary headless Wine64 rendering are verified; -native Windows execution is **unverified**. +Windows cross-publishing and preliminary headless Wine64 rendering are verified. +A user reported initial native Windows rendering; this floor/animation update +still needs native Windows retesting. Full native Windows functionality is unverified. These are investigation packages, not a finished game release. `scripts/test.sh` runs 20 Python regressions, native C# data/algorithm checks, diff --git a/docs/analysis/assets.md b/docs/analysis/assets.md index afa4a53..6dea4ca 100644 --- a/docs/analysis/assets.md +++ b/docs/analysis/assets.md @@ -39,7 +39,7 @@ Preparation produces ignored local files below `artifacts/extracted/`: - `VR01/scene.json`: 240 expanded vertices, 80 triangles, 7 textures. - Texture `.rgba` files plus PNG previews, preserving material ID links. - `sounds/`, `musicjimmyshouse/`, `musicneighborhood/`: exact embedded WAV bytes. -- `animations/{jimstop,jimrun,jimjump}/`: original morph samples and manifests. +- `animations/{jimstop,jimrun,jimjump,jimscratch}/`: original morph samples and manifests. - `animations/jimycarl.rgba`: original normal Jimmy atlas, 256 x 256 indexed PNG decoded to RGBA. Individual archive recovery: @@ -103,6 +103,9 @@ Jimmy uses 426 source vertices and 814 faces. `jimstop.ase` has two samples, `jimrun.ASE` five, and `jimjump.ASE` three, all with file scene speed 10 FPS and 480 ticks/frame. These establish asset sample timing, not state-specific playback speed or loop policy in gameplay code. +The two jimstop vertex samples are identical: there is no idle motion to play. +The scratch file has three distinct samples at ticks0/960/1920. Preview clip keys +expose source motion explicitly instead of labeling the default idle as animated. The EXE stores `jimyshock.png` at file offset `0xef0c8`, followed by `jimstop.ase` at `0xef0d8`. **Primary integration corrected an early inference from string diff --git a/docs/architecture.md b/docs/architecture.md index e84d6d1..7dbc86e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -35,6 +35,13 @@ collision/task system has been silently inserted. The main program remains a scene investigation runtime; future simulation must be a separate stateful module with recovered timing, input, collision, triggers and progression. +Application/PreviewCharacterPlacement and PreviewAnimationLibrary keep inspection +policies separate from gameplay fragments. Ground contact is a model-only offset +derived once from visible surfaces and the standing bind pose, with raw source +placement preserved. Clip selection displays actual still/moving state and does +not simulate walking/jumping actions. These policies need replacement/integration +as original controller, actor transforms and state behavior are recovered. + Subsystem implementation and validated ownership are documented in `infrastructure.md`, `analysis/graphics.md` and `rendering.md` as they become available. Persistent docs distinguish planned architecture from verified behavior. diff --git a/docs/compatibility.md b/docs/compatibility.md index 58fa895..7143a07 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -10,12 +10,15 @@ separate evidence categories. **The game is not fully reconstructed/playable yet | OMT recovery | All100 archives audited | 2155meshes,2183materials,1614textures,875RIFF, zero failures | | C# original loaders | Linux runtime | All128 PNG /254 ASE base meshes; morph/base UV tests | | .NET10 Linux build | Pass, zero warnings/errors | Local SDK10.0.402/runtime10.0.13 | -| Windows x64 publish | Pass | Correct PE32+ app and SDL3.dll; native execution untested | +| Windows x64 publish | Pass | Correct PE32+ app and SDL3.dll; initial native rendering user-reported | | Windows package under Wine64 | Preliminary headless pass | Two frames, exit0; fixed-time readback identical to Linux on lavapipe; validation disabled | +| Corrected Windows preview under Wine64 | Preliminary window pass | Six frames, key2 animation switch, resize800x600, exit0; validation disabled | | Linux self-contained package | Native run verified | Two headless frames without SDK/source/originals mounted | | Vulkan1.3 lab | llvmpipe + GTX1070 | Real indexed/textured/depth frame/readback; validation enabled, zero errors | | Original camera/projection | Data/math integrated | GAM camera, recovered FOV/clips; startup/follow behavior not compared | | Jimmy normal texture / morph | Native preview verified | Correct atlas slot0, base topology/UV retained; state speed/loop unverified | +| Standing preview placement | Corrected / Linux tested | +38.503Y from actual visible floor/base soles; exact original actor transform unresolved | +| Idle/run/jump/scratch preview | Linux keyboard + GPU tests | Default idle samples identical; 1/2/3/4 select clips; run image changes across frames | | Null-material visibility | Binary rule implemented/tested | Original DX renderer skips null pointers; proxy geometry retained | | SDL3 presentation/input | Linux Xvfb + GTX1070 | Six frames; injected keyboard event received | | Swapchain resize | Linux tested | 960x720 ->800x600, zero validation errors | @@ -26,7 +29,7 @@ separate evidence categories. **The game is not fully reconstructed/playable yet | Intro/task/entity/gameplay loop | Incomplete | GAM data recovery is not task execution or gameplay | | Menus/AI/combat/progression/saves | Incomplete | Required future work | | Original execution | Attempted under isolated Wine11 | Window created, GL/Vulkan rendering unusable; no reference comparison | -| Native Windows functionality | Unverified | Requires local Windows installation or VM | +| Native Windows functionality | Partially user-reported | Initial window/3D frame displayed; corrected build/input/audio/resize still unverified natively | Generated evidence: artifacts/final-tests.log, test-level1b.ppm, test-player.ppm, resize-input.ppm, package-linux.ppm, extracted/audit.json and reference*/ logs. diff --git a/docs/decisions.md b/docs/decisions.md index b27f6f5..c033479 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -17,3 +17,10 @@ Shared runtime/format changes must be coordinated. No external coordination. 7. **Honest compatibility.** Build, headless Vulkan frame, SDL presentation, gameplay fidelity and native Windows execution are separate evidence categories. +8. **Preview ground contact and idle clarity.** User testing exposed floor overlap + and a misleading animated-default description. Original idle vertices are + identical; do not invent idle motion. Expose moving source clips explicitly. + Until original actor transforms/collision settling are recovered, apply one + model-only floor correction derived from standing soles and visible geometry, + with explicit preview labeling and regression tests. Preserve GAM/ASE data and + per-frame morph displacement; this is not the original collision algorithm. diff --git a/docs/infrastructure.md b/docs/infrastructure.md index 29207b9..cfee5ca 100644 --- a/docs/infrastructure.md +++ b/docs/infrastructure.md @@ -43,12 +43,15 @@ animation state/render sorting are incomplete. See rendering.md for evidence. - Recovered 11,025 Hz mono WAV: dummy-device SDL3 stream consumed 10,752 bytes in 500 ms. Physical speaker output, positional mixing and original timing are unverified. -- Linux/Windows self-contained cross-publishing succeeds. Native Windows execution - remains unverified; Wine reference testing is a separate investigation path. +- Linux/Windows self-contained cross-publishing succeeds. Initial Windows rendering + is user-reported; broader native functionality remains unverified. Wine reference + testing is a separate investigation path. - Preliminary Windows-package Wine64 check: standalone .NET10 executable rendered two frames, exit0, with byte-identical PPM to Linux on the same software driver. Validation was disabled for this Wine test; SDL window/input/audio and native Windows drivers remain untested. See reference-testing.md for exact scope. +- Corrected Windows preview also passes a six-frame Wine64 window/input/animation + selection/resize smoke (validation disabled). Native Windows retest is pending. ## Scope limits @@ -56,10 +59,13 @@ This is an investigation/runtime foundation, not complete reconstructed gameplay Original collisions, task/trigger execution, introductory cutscene, inventory, combat, enemies, progression, save/load, original mouse/control behavior and remaining scenes are incomplete. Player rendering at the original startpoint is -an animated preview; its interpolation loop/speed are not a recovered state machine. +an animation inspection preview; default idle samples are identical. Keys1/2/3/4 +select original clips. Preview floor correction is separate from original physics; +its transform and interpolation loop/speed are not a recovered state machine. Packages include local copies of asset directories (ASE/png/gam/omt), original font PNGs/NewGame/readme, lab/Jimmy scene resources, recovered music, .NET runtime, SDL3, SPIR-V and these limitations. Legacy EXEs/DLLs, old user save slots, tool caches and analysis databases are not runtime dependencies. Vulkan drivers remain -platform prerequisites. No claim of native Windows runtime validation is made. +platform prerequisites. Initial native Windows rendering is user-reported; the +corrected preview and broader native Windows functionality remain unverified. diff --git a/docs/progress.md b/docs/progress.md index 2af3a8d..2c4c143 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -4,6 +4,30 @@ asset recovery toolchain and a native original-scene/animation investigation runtime with local Linux/Windows packages. No completed playable-scene claim. +## Latest user-reported preview fix + +The user ran the Windows build and observed a static Jimmy partially inside the +lab floor. This verifies initial Windows startup/rendering by user report, with +OS/GPU/version/input/audio details unspecified. Updated native Windows testing +remains pending. + +Both issues were reproduced from actual assets: jimstop has two byte-identical +vertex poses, and its minimum local Y=-64.6165 plus GAM Y=26.6619 places the soles +at -37.9546 while the original visible floor is near Y=0.5486. Calling the default +an animated idle was inaccurate. The idle stays faithful to its still source pose; +1/2/3/4 now explicitly select idle/run/jump/scratch previews and the window title +states the mode/controls. A source-data-based preview correction of +38.503 Y +places the standing model on visible floor triangles, leaving GAM data unchanged. +This is an explicit preview policy, not the recovered game collision solver. + +Tests verify real lab grounding, ceiling/invisible-proxy rejection, still idle and +moving clips, automatic animation advance in actual GPU readbacks, and SDL keyboard +switching to a run cycle. Khronos validation reports zero errors on llvmpipe and +GTX1070. Source assets remain unchanged. See rendering.md for evidence/scope. +The rebuilt Windows package additionally passed an isolated Wine64 window test: +six frames, animation key2 selected moving source samples, resize800x600, exit0. +Validation was disabled in that Wine test; corrected native Windows retest is pending. + ## Verified - Full `../prompt.MD` specification read; originals preserved and local Git initialized. @@ -30,10 +54,10 @@ runtime with local Linux/Windows packages. No completed playable-scene claim. - SDL3 recovered WAV stream consumes bytes on dummy device. Speaker output untested. - Self-contained linux-x64/win-x64 packages built under dist/. Linux package also renders inside a separate filesystem namespace with no SDK/project/original - directory mounted. Windows native execution remains unverified. + directory mounted. Initial Windows rendering is now user-reported as noted above. - Windows x64 package also renders two headless frames under isolated Wine64, exit0, without source/SDK/originals mounted. Its fixed-time PPM is byte-identical - to the Linux package on the same lavapipe driver. Native Windows remains untested; + to the Linux package on the same lavapipe driver (checkpoint670adb4). Broader native Windows remains untested; Wine test did not enable validation or exercise SDL window/audio/input. - Official Wine11 original-copy runs attempted in isolated filesystem/network namespaces. Both GL and Vulkan backends produce unusable frames; details below. diff --git a/docs/reference-testing.md b/docs/reference-testing.md index 3fdfd45..81461c7 100644 --- a/docs/reference-testing.md +++ b/docs/reference-testing.md @@ -50,7 +50,7 @@ resources and rendered two offscreen frames through lavapipe, exiting0. This tes disabled Vulkan validation and **does not** establish Windows-driver validation, SDL window/audio/input functionality or native Windows compatibility. -At fixed morph time0.05, its PPM GPU readback is byte-identical to the native Linux +At checkpoint670adb4 and fixed morph time0.05, its PPM GPU readback was byte-identical to the native Linux package readback (SHA-256 `c30bcbc95d00ce104b146cc46c84e9a9d50849bf0b0bf33c027a402bb46e47c4`). Both use the same software Vulkan driver. This establishes consistency between those two package executions, not fidelity to the original game. @@ -59,3 +59,11 @@ An initial harness configuration disabled mscoree for the legacy game and thereb prevented Wine from loading the port's IL-only System.Runtime.dll. Port mode now uses Wine's built-in mscoree, correcting the test environment; no app workaround or Mono runtime is required. Logs/readback are in artifacts/windows-smoke/. + +After the user-reported floor/idle issue, the rebuilt Windows package also passed +`python3 tools/recon/reference_capture.py --port-window --seconds 12`: six windowed +frames, preview correction+38.503Y, injected key2 switched to Run cycle, and +960x720->800x600 resize succeeded, exit0. This Wine test disabled validation; Linux +tests separately enabled Khronos validation and reported zero errors. The latest +artifacts/windows-smoke contains that updated window test, superseding the earlier +headless capture. Native Windows retesting is still pending. diff --git a/docs/rendering.md b/docs/rendering.md index 416c6f9..6bb3c30 100644 --- a/docs/rendering.md +++ b/docs/rendering.md @@ -44,3 +44,46 @@ unverified. This is not a complete animation/gameplay reconstruction. GPU readback evidence: `artifacts/test-level1b.ppm`, `artifacts/test-player.ppm`, `artifacts/jimmy-normal.ppm`, `artifacts/resize-input.ppm` (generated/ignored). No original reference image equivalence or pixel-perfect claim is made. + +## Standing preview floor overlap and static idle + +User report: Windows displays Jimmy partly inside the floor and no apparent motion. +The default jimstop source samples (TIMEVALUE0/480) contain identical vertex +positions. The earlier description of an animated default was incorrect. They +remain a still idle pose; explicit keys1/2/3/4 select idle/run/jump/scratch previews, +with clip identity and controls shown in the SDL window title. Playback is an +inspection feature; movement/controller/state-machine gameplay is still missing. + +The original standing base minimum Y is -64.6165. Simply adding GAM STARTEXP Y +26.6619 puts the lowest soles at -37.9546, below the visible lab floor near0.5486. +The previous screenshot review missed that intersection. PreviewCharacterPlacement +now derives one upward model-only offset from standing-base vertices and visible +floor triangles beneath the original root. It excludes overhead/steep surfaces and +unrendered proxies. The original GAM root, raw ASE vertices, scale, camera and +animation deformation remain unchanged. The resulting LV1B correction is +38.503Y. +This is a documented preview placement policy pending original actor transform and +collision settling recovery; it is not evidence that the original game uses it. +It is computed once from the standing base, so animated jumps are not resnapped +to the floor on every frame. + +C# regressions cover the actual lab, flat-floor contact, ceilings, excluded proxy +draws, missing floors and clip selection. Native GPU run captures at0 and0.1 seconds +differ; a seven-frame automatic advance matches the fixed0.1-second capture byte +for byte. SDL6-frame smoke switches to Run cycle by injected key2 and resizes, +with zero validation errors. Generated evidence: artifacts/placement-*.ppm and +placement-tests.log. Native Windows user retesting of this update remains pending. + +Read-only original-DLL probe: tools/binary/omt_shape_probe.c, built with local +i686-w64-mingw32-gcc, calls the supplied OMT ASE converter in a copied installation +inside the reference sandbox. In non-animation conversion mode0 it emits426 +vertices and identical base coordinate bounds, confirming the raw data diagnosis +for that mode. The game uses conversion mode2, so the probe does not establish +the original actor origin/scale. Reproduce: + +```sh +i686-w64-mingw32-gcc -O0 tools/binary/omt_shape_probe.c -o artifacts/binary/omt_shape_probe.exe -static-libgcc +python3 tools/recon/reference_capture.py --asset-probe --seconds 12 +``` + +Output is under artifacts/asset-probe; no original directory is mounted/writable +in the probe namespace. The converter operates only on copied bytes/in-memory objects. diff --git a/docs/tasks.md b/docs/tasks.md index fba513d..688a9a4 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -17,6 +17,8 @@ - [x] Packaged Linux runtime isolated from SDK/source/originals; renders successfully. - [x] Preliminary Wine64 Windows-package render; exact fixed-time readback matches Linux. - [x] Isolated copied-original Wine attempts; actual failures documented. +- [x] Correct preview floor overlap, identify still idle, add explicit animation inspection controls/tests. +- [ ] Retest corrected Windows build natively; initial rendering is user-reported. ## Next implementation priorities @@ -24,6 +26,8 @@ playable. Trace `0x479D20` past displacement integration, shared collision call via interface slot0x130 in `0x462520`, and object collision caches. Retain invisible/null-material geometry; its exact collision masks remain unresolved. + Recover original actor/model pivot, scale and spawn settling: the preview now + uses a floor-derived model offset, which must be replaced with proven behavior. 2. Finish airborne state table at `0x437F90` (jump at `0x4383B3`, extra acceleration `0x438148`, held predicate `0x42A730`, mode dispatch `0x437A8C`). Gravity is -800, queued impulse550, but normal jump states add gravity*1.33-gravity; avoid the @@ -48,7 +52,7 @@ - [ ] Pickups, score/health, gadgets/inventory, combat/AI, all levels and transitions. - [ ] Original menus, cutscenes, dialogue/voice and state-dependent rendering. - [ ] Save/load schema and configuration persistence; NewGame reference is not save support. -- [ ] Native Windows execution/input/audio/resize/driver testing (cross-build already passes). +- [ ] Full native Windows input/audio/resize/driver testing (initial rendering is user-reported). - [ ] Fidelity regression references, remaining discrepancies and actual release candidate. ## Repeatable commands diff --git a/scripts/package.sh b/scripts/package.sh index 9a0e7a5..d2db94c 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -27,13 +27,16 @@ Append --headless --frames 2 to render without a window, or --screenshot lab.ppm to save GPU readback. A Vulkan 1.3 graphics driver/loader is required. This package includes the .NET runtime, SDL3, shaders and local asset copies. -The default shows the original lab and an animated Jimmy preview at its recorded -startpoint. C switches stored/orbit camera; arrows/WASD orbit, +/- zoom, F11 -fullscreen, Escape quit. These are investigation controls. +The default shows the original lab and Jimmy's still idle pose, grounded on the +visible floor for preview. Press 1 for idle, 2 for a running animation cycle, +3 for a jump animation cycle, or 4 for a scratch animation cycle. C switches +stored/orbit camera; arrows/WASD orbit, +/- zoom, F11 fullscreen, Escape quit. +These are investigation controls; animation selection does not move the player. This is not the finished playable game. Original collision, controller, intro, interactions, progression, AI and saves remain incomplete. Animation loop/speed -are preview policies. Native Windows execution has not been verified. +and grounding are preview policies. A user verified initial rendering on Windows; +this corrected build still needs native Windows retesting. See BUILD-AND-LIMITATIONS.md, COMPATIBILITY.md and docs/ for evidence and remaining work. SOURCE-README.md describes development from the separate source repository. diff --git a/scripts/test.sh b/scripts/test.sh index 20a823f..ecedaa1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,6 +9,13 @@ dotnet run --no-build -- --verify-assets --assets ../Original python3 tools/extractors/omt.py ../Original/omt/level1b.omt --scene --output artifacts/extracted/level1b dotnet run --no-build -- --headless --assets ../Original --scene artifacts/extracted/level1b/scene.json --level gam/level1b.gam --original-camera --screenshot artifacts/test-level1b.ppm dotnet run --no-build -- --headless --with-player --time 0.05 --screenshot artifacts/test-player.ppm +dotnet run --no-build -- --headless --animation artifacts/extracted/animations/jimrun/animation.json --time 0 --screenshot artifacts/test-run-start.ppm +dotnet run --no-build -- --headless --animation artifacts/extracted/animations/jimrun/animation.json --frames 7 --screenshot artifacts/test-run-advanced.ppm +python3 - <<'PY' +from pathlib import Path +assert Path('artifacts/test-run-start.ppm').read_bytes() != Path('artifacts/test-run-advanced.ppm').read_bytes(), 'Animation did not advance in GPU readback' +print('PASS: original run preview advances across rendered frames') +PY SDL_AUDIODRIVER=dummy dotnet run --no-build -- --audio-smoke artifacts/extracted/sounds/Wave_00000001_save.wav python3 tools/recon/inventory.py ../Original --verify docs/original-manifest.json if [[ "${NEUTRON_WINDOW_TEST:-0}" == 1 ]]; then diff --git a/src/GamePort/Application/PreviewAnimationLibrary.cs b/src/GamePort/Application/PreviewAnimationLibrary.cs new file mode 100644 index 0000000..cc297f5 --- /dev/null +++ b/src/GamePort/Application/PreviewAnimationLibrary.cs @@ -0,0 +1,45 @@ +using GamePort.Assets; + +namespace GamePort.Application; + +/// Explicit animation inspection; does not simulate player actions. +public sealed class PreviewAnimationLibrary +{ + private readonly Dictionary 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; + } +} diff --git a/src/GamePort/Application/PreviewCharacterPlacement.cs b/src/GamePort/Application/PreviewCharacterPlacement.cs new file mode 100644 index 0000000..b957661 --- /dev/null +++ b/src/GamePort/Application/PreviewCharacterPlacement.cs @@ -0,0 +1,75 @@ +using System.Numerics; +using GamePort.Assets; + +namespace GamePort.Application; + +/// +/// Prevents the inspection character penetrating visible floor geometry. +/// This is preview placement, not the original game's unrecovered collision solver. +/// A single correction from the standing bind pose preserves animation displacement. +/// +public sealed record PreviewCharacterPlacement(Vector3 SourcePosition, Vector3 Position, + Matrix4x4 Model, float? FloorAtOrigin) +{ + public float VerticalCorrection => Position.Y - SourcePosition.Y; + + public static PreviewCharacterPlacement Create(Mesh scene, Mesh standingPose, + Vector3 position, float yawDegrees) + { + var rotation = Matrix4x4.CreateRotationY(-yawDegrees * MathF.PI / 180); + var surfaces = FloorSurfaces(scene, position.Y); + var floor = HeightAt(surfaces, position.X, position.Z, position.Y); + var correction = 0f; + // Use the standing base, never a moving frame: grounding each frame would + // cancel the original jump animation and introduce foot-height jitter. + foreach (var local in standingPose.Vertices.Select(v => v.Position).Distinct()) + { + var world = Vector3.Transform(local, rotation) + position; + if (HeightAt(surfaces, world.X, world.Z, position.Y) is { } height) + correction = MathF.Max(correction, height - world.Y); + } + var corrected = position + new Vector3(0, correction, 0); + return new PreviewCharacterPlacement(position, corrected, + rotation * Matrix4x4.CreateTranslation(corrected), floor); + } + + private readonly record struct Triangle(Vector3 A, Vector3 B, Vector3 C, float Denominator); + + private static List FloorSurfaces(Mesh scene, float maximumHeight) + { + var surfaces = new List(); + var draws = scene.HasExplicitDraws ? scene.Draws + : [new MeshDraw(0, (uint)scene.Indices.Length, -1)]; + foreach (var draw in draws) + for (var i = draw.FirstIndex; i + 2 < draw.FirstIndex + draw.IndexCount; i += 3) + { + var a = scene.Vertices[scene.Indices[i]].Position; + var b = scene.Vertices[scene.Indices[i + 1]].Position; + var c = scene.Vertices[scene.Indices[i + 2]].Position; + // Exclude ceiling geometry and steep/vertical surfaces. Retained + // invisible proxy geometry is not treated as proven collision data. + if (MathF.Min(a.Y, MathF.Min(b.Y, c.Y)) > maximumHeight) continue; + var normal = Vector3.Cross(b - a, c - a); + if (normal.LengthSquared() < 0.000001f || MathF.Abs(normal.Y) < normal.Length() * 0.5f) continue; + var denominator = (b.Z - c.Z) * (a.X - c.X) + (c.X - b.X) * (a.Z - c.Z); + if (MathF.Abs(denominator) > 0.000001f) + surfaces.Add(new Triangle(a, b, c, denominator)); + } + return surfaces; + } + + private static float? HeightAt(List surfaces, float x, float z, float maximumHeight) + { + float? highest = null; + foreach (var t in surfaces) + { + var u = ((t.B.Z - t.C.Z) * (x - t.C.X) + (t.C.X - t.B.X) * (z - t.C.Z)) / t.Denominator; + var v = ((t.C.Z - t.A.Z) * (x - t.C.X) + (t.A.X - t.C.X) * (z - t.C.Z)) / t.Denominator; + if (u < -0.00001f || v < -0.00001f || u + v > 1.00001f) continue; + var y = u * t.A.Y + v * t.B.Y + (1 - u - v) * t.C.Y; + if (y > maximumHeight) continue; + if (highest == null || y > highest.Value) highest = y; + } + return highest; + } +} diff --git a/src/GamePort/Assets/MorphAnimation.cs b/src/GamePort/Assets/MorphAnimation.cs index c4acff3..58c71d7 100644 --- a/src/GamePort/Assets/MorphAnimation.cs +++ b/src/GamePort/Assets/MorphAnimation.cs @@ -9,6 +9,7 @@ public sealed class MorphAnimation public Mesh Base { get; } public PngImage Texture { get; } public double SampleInterval { get; } + public bool HasVertexMotion { get; } private readonly Mesh[] frames; public MorphAnimation(string manifestPath) @@ -31,6 +32,7 @@ public sealed class MorphAnimation for (var i = 0; i < Base.Vertices.Length; i++) if (frames.Any(f => f.Vertices[i].Uv != Base.Vertices[i].Uv)) throw new InvalidDataException("Morph sample UV differs from base"); + HasVertexMotion = frames.Any(f => f.Vertices.Where((v, i) => v.Position != Base.Vertices[i].Position).Any()); SampleInterval = frames.Length > 1 ? (samples[1].GetProperty("time").GetDouble() - samples[0].GetProperty("time").GetDouble()) / ticks / fps : 1 / fps; diff --git a/src/GamePort/Platform/Sdl.cs b/src/GamePort/Platform/Sdl.cs index 7b669fb..8de7d67 100644 --- a/src/GamePort/Platform/Sdl.cs +++ b/src/GamePort/Platform/Sdl.cs @@ -36,6 +36,7 @@ internal static unsafe class Sdl public static string Error=>Marshal.PtrToStringUTF8(SDL_GetError())??"SDL error"; [DllImport(Library,CallingConvention=CallingConvention.Cdecl)] public static extern nint SDL_CreateWindow([MarshalAs(UnmanagedType.LPUTF8Str)]string title,int w,int h,ulong flags); [DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_DestroyWindow(nint window); + [DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetWindowTitle(nint window,[MarshalAs(UnmanagedType.LPUTF8Str)]string title); [DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_PollEvent(out Event e); [DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern byte** SDL_Vulkan_GetInstanceExtensions(out uint count); [DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_Vulkan_CreateSurface(nint window,nint instance,void* allocator,out ulong surface); diff --git a/src/GamePort/Program.cs b/src/GamePort/Program.cs index d0074f3..6ea8406 100644 --- a/src/GamePort/Program.cs +++ b/src/GamePort/Program.cs @@ -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; } diff --git a/tests/GamePort.DataTests/GamePort.DataTests.csproj b/tests/GamePort.DataTests/GamePort.DataTests.csproj index 9e82f1a..a5a16c6 100644 --- a/tests/GamePort.DataTests/GamePort.DataTests.csproj +++ b/tests/GamePort.DataTests/GamePort.DataTests.csproj @@ -15,5 +15,7 @@ + + diff --git a/tests/GamePort.DataTests/Program.cs b/tests/GamePort.DataTests/Program.cs index 2b8b00b..b777dae 100644 --- a/tests/GamePort.DataTests/Program.cs +++ b/tests/GamePort.DataTests/Program.cs @@ -1,4 +1,5 @@ using GamePort.Assets; +using GamePort.Application; using GamePort.Game; using System.Numerics; @@ -78,6 +79,40 @@ Require(combined.Indices.Length == scene.Indices.Length + 2442 && combined.Textu Require(combined.Indices.All(i => i < combined.Vertices.Length), "Combined scene contains invalid index"); Console.WriteLine("PASS: null-material visibility, case-insensitive ASE, original morph interpolation/base UV, and scene/character merge."); +var start = initial.FindStart()!; +var placement = PreviewCharacterPlacement.Create(scene, baseMesh, start.Position, start.Rotation.Y); +Require(placement.FloorAtOrigin is > 0.5f and < 0.6f, "Wrong original lab floor selected (ceiling/proxy?)"); +Require(placement.VerticalCorrection is > 38 and < 40, "Original lab floor penetration was not corrected"); +Require(placement.SourcePosition == start.Position && placement.Position.X == start.Position.X + && placement.Position.Z == start.Position.Z, "Preview grounding changed the original GAM data or horizontal position"); +var correctedSole = baseMesh.Vertices.Min(v => Vector3.Transform(v.Position, placement.Model).Y); +Require(correctedSole >= placement.FloorAtOrigin!.Value - 0.05f, "Standing soles still penetrate the lab floor"); + +Mesh FlatFloors(bool drawProxy) +{ + var vertices = new List(); + foreach (var y in new[] { 10f, 25f, 500f }) + foreach (var p in new[] { new Vector3(-500,y,-500),new Vector3(500,y,-500),new Vector3(500,y,500), + new Vector3(-500,y,-500),new Vector3(500,y,500),new Vector3(-500,y,500) }) + vertices.Add(new MeshVertex(p, Vector2.Zero, Vector3.One)); + return new Mesh(vertices.ToArray(), Enumerable.Range(0, vertices.Count).Select(i => (uint)i).ToArray()) + { HasExplicitDraws = true, Draws = drawProxy ? [new MeshDraw(0, 18, -1)] : [new MeshDraw(0, 6, -1), new MeshDraw(12, 6, -1)] }; +} +var flat = PreviewCharacterPlacement.Create(FlatFloors(false), baseMesh, new Vector3(0,30,0), 0); +Require(flat.FloorAtOrigin == 10, "Invisible proxy or overhead ceiling selected as preview floor"); +Require(MathF.Abs(baseMesh.Vertices.Min(v => Vector3.Transform(v.Position, flat.Model).Y) - 10) < 0.001f, + "Standing model does not rest on actual visible floor"); +var raised = PreviewCharacterPlacement.Create(FlatFloors(true), baseMesh, new Vector3(0,30,0), 0); +Require(raised.FloorAtOrigin == 25, "Nearest visible floor below origin was not selected"); +var noFloor = PreviewCharacterPlacement.Create(new Mesh([], []), baseMesh, start.Position, 0); +Require(noFloor.VerticalCorrection == 0 && noFloor.FloorAtOrigin == null, "Missing floor caused an invented world offset"); +var clips = new PreviewAnimationLibrary(Path.Combine(project, "artifacts/extracted/animations/jimstop/animation.json")); +Require(!clips.Current.HasVertexMotion, "Supplied idle unexpectedly has vertex motion"); +foreach (var key in new[] { 31u, 32u, 33u }) + Require(clips.Select(key) && clips.Current.HasVertexMotion, "Animation preview key did not select moving original samples"); +Require(clips.Select(30) && !clips.Current.HasVertexMotion, "Idle selection did not restore original still pose"); +Console.WriteLine($"PASS: original lab grounding (+{placement.VerticalCorrection:F3} Y), ceiling/proxy rejection, and explicit idle/run/jump/scratch selection."); + static void Require(bool condition, string message) { if (!condition) throw new Exception(message); diff --git a/tools/binary/omt_shape_probe.c b/tools/binary/omt_shape_probe.c new file mode 100644 index 0000000..07b9c56 --- /dev/null +++ b/tools/binary/omt_shape_probe.c @@ -0,0 +1,44 @@ +/* Run only inside the isolated reference namespace. No original file is written. */ +#include +#include +#include +#include +#include +#define OMT_THISCALL __attribute__((thiscall)) +typedef void *(OMT_THISCALL *ctor0)(void *); +typedef void (OMT_THISCALL *writefn)(void *, void *, unsigned); +typedef void (OMT_THISCALL *seekfn)(void *, unsigned, short); +typedef void *(OMT_THISCALL *converterctor)(void *, void *, void *); +typedef void (OMT_THISCALL *convertfn)(void *); +static FARPROC required(HMODULE h, const char *name) { + FARPROC p=GetProcAddress(h,name); + if(!p){fprintf(stderr,"Missing export: %s\n",name);exit(2);} return p; +} +int main(int argc,char **argv) { + setbuf(stdout,NULL); + const char *input=argc>1?argv[1]:"ASE\\jimstop.ase"; + FILE *f=fopen(input,"rb");if(!f){perror(input);return 2;} + fseek(f,0,SEEK_END);long length=ftell(f);rewind(f); + char *data=malloc(length);if(fread(data,1,length,f)!=(size_t)length)return 2;fclose(f); + HMODULE h=LoadLibraryA("Z:\\work\\game\\OMT2.dll"); + if(!h){fprintf(stderr,"LoadLibrary OMT error %lu\n",GetLastError());return 2;} + unsigned char *stream=calloc(1,8192),*shape=calloc(1,8192),*converter=calloc(1,8192); + ((ctor0)required(h,"??0OMediaMemStream@@QAE@XZ"))(stream); + ((writefn)required(h,"?write@OMediaStream@@UAEXPAXK@Z"))(stream,data,length); + ((seekfn)required(h,"?setposition@OMediaStream@@UAEXKF@Z"))(stream,0,0); + ((ctor0)required(h,"??0OMedia3DShape@@QAE@XZ"))(shape); + *(int*)required(h,"?obj_conv_mode@OMedia3DShapeConverter@@1W4omt_3DObjectConvertMode@@A")=0; + *(int*)required(h,"?anim_conv_mode@OMedia3DShapeConverter@@1W4omt_3DAnimConvertMode@@A")=0; + ((converterctor)required(h,"??0OMediaASEConverter@@QAE@PAVOMediaStreamOperators@@PAVOMedia3DShape@@@Z"))(converter,stream,shape); + puts("CONVERT_BEGIN"); + ((convertfn)required(h,"?convert@OMediaASEConverter@@UAEXXZ"))(converter); + float *begin=*(float**)(shape+0x68),*end=*(float**)(shape+0x6c); + intptr_t bytes=(intptr_t)end-(intptr_t)begin; + if(!begin || bytes<=0 || bytes%16 || bytes>16000000){fputs("Unexpected shape layout\n",stderr);return 3;} + printf("VERTICES %ld\n",(long)bytes/16); + float lo[3]={FLT_MAX,FLT_MAX,FLT_MAX},hi[3]={-FLT_MAX,-FLT_MAX,-FLT_MAX}; + for(float *p=begin;phi[i])hi[i]=p[i];}} + printf("MIN %.9g %.9g %.9g\nMAX %.9g %.9g %.9g\n",lo[0],lo[1],lo[2],hi[0],hi[1],hi[2]); + for(int i=0;i<3 && begin+i*4