Skip to content

Add a local asset viewer and reusable parts index (ASSET-375) - #4763

Open
whattheflop wants to merge 18 commits into
ItsNotRexed:mainfrom
whattheflop:feat/local-viewer-parts-index
Open

whattheflop wants to merge 18 commits into
ItsNotRexed:mainfrom
whattheflop:feat/local-viewer-parts-index

Conversation

@whattheflop

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as the local viewer catalog and ASSET-375.

What and why

  • Add a local asset catalog alongside the streamed map. Browse self-contained GLBs by category and show optional static PNG captures from first_light's translated Vulkan draw.
  • Build the catalog from local exports. Large archives can be imported in bounded windows with source/range verification, checkpoints and retained per-window manifests.
  • Persist parts, placements and material references in a reusable SQLite index. Keep unresolved and ambiguous matches visible for later assembly.

Tested

  • Windows, uv-managed CPython 3.12.13, on scratch merge tree 2def9444 against upstream 98fa503f. Six parts-index, 16 catalog, seven First Light mesh, and 40 viewer-server tests passed with three Windows server skips. All 60 Node viewer tests passed. The game-data check and git diff --check passed.
  • T3 Preview exercised GLB selection, search, category filtering, refresh, and the separate PNG view with synthetic fixtures.
  • A synthetic First Light draw on RTX 3080, NVIDIA 616.64, with Vulkan SDK and Khronos validation 1.4.363.0 verified the PNG against readback. Both shaders passed Vulkan 1.3 SPIR-V validation. The PNG and PPM RGB matched, including transparent clear pixels in the PNG.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption, including in logs or reports quoted here.

whattheflop and others added 10 commits November 23, 2026 14:12
(cherry picked from commit 387a5517297b36709635e6ac94aae2035d5e6c79)
(cherry picked from commit dbb1428e713afc39c48eb656b99e2161bcdea48b)
--window-mib exports large archives (levels.rpf by default) as consecutive
rpf9dump --start/--length windows, converts and publishes each, checkpoints
completed windows in the catalog folder and releases only that window's OBJ
staging afterwards. Defaults and the whole-file path are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit d25d5ac79107ecbd36c5cd17a26f44684eb76f8a)
…ging release

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 5c41cc963b26eff3eb9a7da3d111d4b4a3d5d627)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Index existing drawable, placement and texture exports in SQLite. Preserve scan coverage, model and texture ambiguity, and committed window GLB references for later assembly.

AI-assisted (Codex). Verified with synthetic CPU tests on Python 3.12.13.

(cherry picked from commit ae2d9b7333956c78f724be808834fcc312b8fd8c)
@Atomic258

Copy link
Copy Markdown
Contributor

Tested head 1744e1c37209ad9bceec106367ce48d47ef64679 (draft PR) in a clean worktree on Windows 11, Python 3.15.2 (C:\Python315), Node v26.13.0. No game data used; all fixtures are synthetic.

PR test files

Command Result
python -I tests/test_viewer_catalog.py 16 tests, OK
python -I tests/test_viewer_parts_index.py 6 tests, OK
python -I tests/test_first_light_mesh_draw.py 7 tests, OK
python -I tests/test_viewer_serve.py 43 tests, OK (3 skipped: two need symlink privilege — WinError 1314, one needs SIGINT to a Windows child; same skips the PR body reports)
node --test tests/test_viewer_assets.cjs 9 pass, 0 fail
node --test tests/test_viewer_streaming.cjs 51 pass, 0 fail (pre-existing suite; serve.py changed, so run for regression)

Repo checks

  • python -m compileall -q make_game.py tools tests viewer — clean.
  • git diff --check origin/main...HEAD — clean.
  • node --check on viewer/assets.js (as .mjs) — valid ESM; no innerHTML/eval, fetches are same-origin /catalog/ only.
  • python -I make_game.py --help — OK.
  • Meta/docs suites all OK: test_docs_links, test_docs_env_vars, test_docs_list_items, test_docs_repo_paths, test_docs_table_ids, test_docs_table_rows, test_docs_pr_template, test_docs_python_deps, test_check_no_game_data, test_ci_registration, test_runner_calls_all_tests, test_design_contract_rows, test_docs_design_rows, test_first_light, test_first_light_bad_json, test_first_light_harness_paths, test_first_light_stale_mesh.

One failure found — python -I tests/test_docs_cli_flags.py: FAILED (2 assertions)

docs/viewer_parts_index.md:6 runs the example as uv run --no-project --python 3.12.13 python -I tools/viewer_parts_index.py .... The checker joins the backtick continuation into one command, matches python -I tools/viewer_parts_index.py, then requires every --flag on the line to exist in that tool's source — --no-project and --python are uv run flags the tool doesn't have (and no tracked source mentions them). Both test_docs_name_existing_flags and test_fenced_commands_use_the_flags_of_their_tool fail on this. Other docs use plain python -I tools/x.py; writing the example that way (with the uv-managed interpreter mentioned in prose) should satisfy the checker.

Red control

  • git checkout origin/main -- viewer/serve.py → test_viewer_serve.py: 19 failures — the new catalog/asset route tests discriminate the new serve.py.
  • git checkout origin/main -- tools/first_light.py → test_first_light_mesh_draw.py: 2 failures + 2 errors — the --png tests discriminate.
  • Both files restored; suites green again, worktree clean.

Not covered

  • No GPU/Vulkan run: vk_harness, d3d12_first_light ctest and the real translated-shader PNG path need a GPU and built runtime (author reports RTX 3080 verification in the PR body).
  • No game package or rpf9dump build: the windowed archive import (--window-mib) and parts-index joins over real manifests were exercised only through the synthetic fixtures in the tests.
  • No browser smoke: serve.py was exercised only through its loopback unittest HTTP layer; the assets.html/assets.js page and the three.js CDN import were not loaded in a browser.

AI-assisted (Devin.)

@whattheflop

Copy link
Copy Markdown
Contributor Author

Thanks for the Windows verification. Confirmed that the example failed both CLI flag assertions. Updated it in 66c88956 to use the documented python -I command and moved the uv interpreter guidance into prose. The three CLI flag tests, 13 related documentation checks and five no-game-data tests pass under uv-managed CPython 3.12.13 on Windows. This is a documentation-only update. AI-assisted.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASSET-375 independent Windows CPU check at 66c8895. Repeat import of one cached retail export and placement file produced a byte-identical SQLite index and preserved all 1,438 catalog GLB hashes and timestamps. Of 75,551 placements, 1,488 joined uniquely and 74,063 remained unresolved. No ambiguous matches occurred. All 36,355 texture references were unresolved with these inputs. AI-assisted, no archive scan or GPU.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 66c8895 merged with main 594f348 on Linux WSL2 (Python 3.12.16, node 22.23.5) and native Windows 11 (Python 3.13.1, node): pass

  • Linux: test_viewer_catalog 16/16, test_viewer_parts_index 6/6, test_first_light_mesh_draw 7/7, tests/test_viewer_assets.cjs 9/9, all tests/test_docs_*.py pass. test_viewer_serve gives 141 ConnectionRefused errors (known WSL baseline).
  • Windows: test_viewer_catalog 16/16, test_viewer_parts_index 6/6, test_viewer_serve 43 OK (1 skipped), test_first_light_mesh_draw 7/7, test_viewer_assets.cjs 9/9, test_docs_cli_flags 3/3 pass.
  • Negative control (run on the previous head 1744e1c, serve.py and first_light.py unchanged since): with viewer/serve.py from main, test_viewer_serve on Windows fails 20 (catalog routes); with tools/first_light.py from main, test_first_light_mesh_draw on Linux fails 2 and errors 2 (the --png tests). The new catalog and parts_index modules have no main version to compare.
  • At 1744e1c, test_docs_cli_flags failed on --no-project/--python in docs/viewer_parts_index.md:6; the 66c8895 docs fix resolves it.
  • No other issues found in the diff.

@whattheflop

Copy link
Copy Markdown
Contributor Author

Small follow-up in ee259056. A paused or failed catalog run previously left complete: false, so the Assets page kept saying “Building catalog” and polling after exit. The revision records whether the snapshot is final, labels incomplete snapshots “Partial catalog,” and leaves manual Refresh enabled. On a synthetic pause, missing archive, and exporter error, the final snapshots stopped polling. Intermediate snapshots still poll. Legacy incomplete manifests remain readable. If a writer stops before publishing a final snapshot, the page may still poll the most recent checkpoint, which it labels as the last update. The 61 Node viewer tests passed, along with 80 Python tests and three platform skips on uv CPython 3.12.13. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested ee259056f merged with main 3faac557b on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.

  • Linux: test_viewer_catalog 16, test_viewer_parts_index 6, test_first_light_mesh_draw 7 OK, test_viewer_assets.cjs 10 and test_viewer_streaming.cjs 51 OK, the other test_first_light* files and all tests/test_docs_*.py OK. tests/test_viewer_serve.py cannot bind a loopback socket in my WSL2 sandbox, so it did not run there.
  • Windows: tests/test_viewer_serve.py 43 tests, OK (1 skipped).
  • Negative control: with main's tools/first_light.py, test_first_light_mesh_draw has 2 failures and 2 errors. On Windows the same swap leaves test_viewer_serve.py at 43 OK, so that file does not exercise the first_light change; the serve route changes are covered by it only as a pass/no-regression check.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested on Windows Server 2022, CPython 3.13.12: partial

  • node tests/test_viewer_assets.cjs -> 10 passed, 0 failed
  • python -I tests/test_viewer_catalog.py -> FAILED (failures=1, errors=1): test_release_only_removes_exact_owned_window_folder raises OSError: refusing to delete ... not an owned window staging folder; test_exports_missing_selected_archives_in_order_then_reuses_them fails
  • python -I tests/test_viewer_parts_index.py -> FAILED (failures=2)

The failures look like the same Windows path-resolution class as test_fuzzer_work_isolation on main (8.3 short temp paths like ADMINI~1 not comparing equal to the long form) - worth checking with the resolved-path comparison that #4805 uses.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@whattheflop

Copy link
Copy Markdown
Contributor Author

Merged round-44 main 561b65a8 into this branch at 298c43ce. The first_light.py overlap preserves upstream’s camera validation and defaults and this PR’s opt-in PNG output. The catalog option and both Windows stdout guards remain in place. The diff against main is still limited to the original 15 PR paths.

Windows, uv CPython 3.12.13 and Node 24. The catalog passed 16/16, parts index 6/6, stdout guard 4/4, docs 33/33, server 40 with 3 Windows skips, and First Light 60 with 8 skips. Viewer Assets and Studio passed 13/13. Streaming passed 56/57. The same camera-speed fixture fails on pinned main with ReferenceError: AbortController is not defined, and the tracker already has a claim for it. AI-assisted, synthetic inputs only.

@whattheflop

Copy link
Copy Markdown
Contributor Author

I reproduced all four Windows Server review failures using a real NTFS 8.3 alias for a disposable temporary directory. Fixed in 0e4f3d13. The catalog fixture compared a canonical archive path to its short parent and passed a short staging path directly to the helper. Two parts-index assertions expected unresolved paths where the database stores resolved paths. Only the two test files changed. Production path ownership and deletion checks are unchanged.

With uv CPython 3.12.13 on Windows, catalog 16/16 and parts index 6/6 passed with both the default temp path and an actual short alias. Server passed 40 with 3 Windows skips, docs 33/33, and stdout checks 4/4. CPython 3.13 was unavailable on this machine. AI-assisted, synthetic inputs.

@shipped-it

Copy link
Copy Markdown

Tested 0e4f3d1328 on Linux (Arch, /usr/bin/python3 3.14.8, CPU-only, no game files): compileall -q make_game.py tools tests clean; first_light_mesh_draw 8 + viewer_catalog 16 + parts_index 6 + viewer_serve 43 OK; docs 33 OK; scripts/check_no_game_data.py clean on all changed files. VERDICT: pass. AI-assisted (omp coding assistant).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0e4f3d1 merged with main 8575d36 on Linux WSL2 (Python 3.12.16 -I, node 22): pass
Real merge was clean (docs/first_light.md and tools/first_light.py auto-merged). Ran test_viewer_catalog (16 OK), test_viewer_parts_index (6 OK), test_first_light_mesh_draw (8 OK) and node tests/test_viewer_assets.cjs (10/10 pass).
Negative control: with tools/first_light.py and viewer/serve.py reverted to main, test_first_light_mesh_draw fails (2 failures, 2 errors). The new viewer_catalog and viewer_parts_index modules and their tests are new files, so there is no main version to revert.
Not run: tests/test_viewer_serve.py errors here (119 errors, ConnectionRefusedError) because loopback TCP is refused in this WSL session; it needs native Windows, so I make no claim about it.

@whattheflop

Copy link
Copy Markdown
Contributor Author

AI-assisted Windows retest after merging upstream dde82f2 into 67b006f. The single argument-parsing conflict retained the upstream coverage range check and both PNG guards. On uv CPython 3.12.13, catalog (16), parts index (6), First Light mesh (8), and ordinary viewer routes (4) passed. Both coverage boundaries passed and all eight invalid CLI combinations were rejected. On Node 24, Assets (10) and Studio (9) passed. Broader streaming, stdout and docs checks reproduced their baseline failures on the same upstream revision.

@NiHuShu

NiHuShu commented Nov 23, 2026

Copy link
Copy Markdown

AI-assisted independent Linux check of 67b006fe679460236f60786c432f29da45ce248c. CachyOS x86-64, CPython 3.14.10. CPU only; GPU not used. python -I tests/test_viewer_parts_index.py passed 6/6, zero skips.

I also ran python -I tools/viewer_parts_index.py --out <tmp>/db/parts.sqlite --models <synthetic-manifest> while the database had a read-only SQLite transaction open. Alternated 41-model and 137-model manifests for 15 successful replacements. The pinned reader saw its original 41 models after every replacement. A separate loop opened 939 fresh read-only connections: 485 saw the complete 41-row generation, 454 saw the complete 137-row generation, with no partial results or SQLite errors. The final fresh reader saw 137 rows and PRAGMA integrity_check returned ok.

As a failure control, a malformed synthetic manifest exited 2; the digest of the last successful database stayed identical and the output directory contained only parts.sqlite. This exercises replacement with live readers on Linux.

@whattheflop

Copy link
Copy Markdown
Contributor Author

Windows counterpart to the Linux replacement check above, AI-assisted. At 67b006fe with uv CPython 3.12.13 and SQLite 3.53.1, the parts-index suite passed 6/6. With a read-only SQLite transaction holding the live database open, six alternating 41/137-model rebuilds exited 2 with one WinError 5 diagnostic and empty stdout. Each preserved the prior digest and row count, passed integrity_check, and left no staging files. Closing the reader and retrying in each case published the complete new generation. Malformed input also preserved the digest. Docs-only commit 405c874a records the Windows recovery step.

@isfcrctfs isfcrctfs left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the new tools and the server changes, then ran the touched suites:
tests/test_viewer_serve.py, tests/test_viewer_catalog.py, tests/test_viewer_parts_index.py,
tests/test_first_light_mesh_draw.py and node tests/test_viewer_assets.cjs - all pass.

The new local-HTTP surface is guarded properly. viewer/serve.py still binds 127.0.0.1 only and keeps the Host
allow-list, and /catalog/ goes through safe_catalog_path + _safe_root_path: unquote(errors="strict"), no backslash
or control characters, no trailing dot or space, no empty/./../:/reserved-device segments, the resolved real path must
stay under the catalog root with the same extension, and catalog.json must be the literal, non-symlinked path. send_head
is the enforcement point so HEAD is covered; translate_path returns the same resolved path (the tests assert the two
agree); handle() now swallows the three broken-connection errors a cancelled chunk download causes.

Adversarial check of the guard. I called safe_catalog_path/safe_world_path directly with 28 payloads - ../,
..%2f, %2e%2e, sub/../../, %00, CRLF, C:, C:%5C, ::$DATA, NUL.glb, trailing . and space, //etc/passwd,
%2Fetc%2Fpasswd, a .gif, a symlink out of the root, a symlinked directory, a plain directory, and the legitimate names.
Every hostile form returned None; only the four legitimate names resolved.

Write safety. viewer_catalog.py invokes the exporter with an argument list (no shell), refuses an --out/--work
that overlaps the checkout or any input root, and routes every write through safe_destination + atomic_write.
viewer_parts_index.py refuses an --out inside the repo or any input root, and replaces the database only on success.
assets.js has no innerHTML/eval; catalog paths are validated per segment then URL-encoded, and fetches use
redirect: "error", so a GLB cannot pull a sidecar. Doc claims I checked against the code hold: --exports and
<work>/assets discovery, the per-archive headroom table, the window staging/checkpoint flow, retain_window's
manifest-then-catalog-map.json ordering and digest, and the "no failed rows in a checkpointed window" rule.

No defect found. One pre-existing note, not from this PR: assets.html loads three from cdn.jsdelivr.net through an
import map, exactly as index.html already does, so the local viewer still needs network for the 3D view.

AI-assisted

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 405c874a)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.