Fix 3D model decoding: dictionaries, vertex axis order, fake MODEL entries, external textures #7

Manually merged
github merged 1 commit from gh-pr/7/head into gh-pr/7/base 2026-11-27 02:30:51 +00:00
Owner

@⁠Ahmet-Dedeler on GitHub · 2026-11-20 22:01 UTC · original
Ahmet-Dedeler:fix/model-decoding → main · +984 −232 · 4 files · 1 commits · merged 2026-11-21 07:55 UTC

Ran into a few model bugs while browsing the Xbox build, mostly in levels.rpf. All four are fixed here.

1. Drawable dictionaries were merged into one mesh

Some .#dr entries are actually a pgDictionary of drawables: hashes at +0x20, drawable pointers at +0x30. The decoder fell back to "All" geometry and merged everything, so independent models got stacked at the origin. Example: bk_02_road_str_slod.#dr is 8 separate Brickell SLOD blocks (317 geoms).

Now each entry is decoded on its own (LOD0) and laid out on a grid. There's a part picker in the viewer to isolate one. OBJ export writes one o group per drawable, and an isolated part exports re-centred.

2. Vertex position axis order (+0x6C)

The u32 at vertex-buffer header +0x6C says which axis lives in the 16-bit position slot:

value slots hold
0 (z, y, x)
1 (z, x, y)
2 (x, y, z)

Only mode 2 was handled, so roughly 30% of geometries rendered rotated (towers lying on their side). I verified the mapping against drawable bboxes on ~1.6k geometries across 150 models: 191/193, 310/311 and 1104/1118 fit. A few geometries carry other values and look like a different vertex layout; those keep the old read.

3. Fake MODEL entries in the scanner

Metadata containers and mid-resource chunks were listed as MODEL because they contain a *.#dr string. Opening them failed with "No RAGE9 meshlet geometries". The scanner now:

  • rejects chunks that start with a grmGeometry (+0x60 == 0x1601)
  • validates BlockMap chunk counts instead of clamping them
  • requires real meshlet geometry before listing an entry

The scan cache is bumped to v9 so stale entries aren't reused. That means one full rescan after updating.

4. External .ttpf textures

Shader texture references are resolved to the external texture archives through their 64-bit hashes. The index is built once per dump root and decodes are cached. You get per-geometry materials, plus vehicle paint detection with colour presets. cheetah2_hi resolves 15/35 materials + paint, and the Brickell SLODs resolve 286/317.

Tests

Two regression tests, which only run when PERCYSTAR_LEVELS_RPF points at levels.rpf from the Xbox dump. Everything else passes as before, and there are no new warnings.

Independent of the sort PR; they touch different parts of main.rs and merge cleanly together.

Same note as the other one: I know PRs are invite only per the license, so close it if you'd rather not take it. Happy to split it up or change anything.

🤖 Generated with Claude Code

**@⁠Ahmet-Dedeler** on GitHub · 2026-11-20 22:01 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/7) `Ahmet-Dedeler:fix/model-decoding` → `main` · +984 −232 · 4 files · 1 commits · merged 2026-11-21 07:55 UTC Ran into a few model bugs while browsing the Xbox build, mostly in `levels.rpf`. All four are fixed here. ### 1. Drawable dictionaries were merged into one mesh Some `.#dr` entries are actually a pgDictionary of drawables: hashes at `+0x20`, drawable pointers at `+0x30`. The decoder fell back to "All" geometry and merged everything, so independent models got stacked at the origin. Example: `bk_02_road_str_slod.#dr` is 8 separate Brickell SLOD blocks (317 geoms). Now each entry is decoded on its own (LOD0) and laid out on a grid. There's a part picker in the viewer to isolate one. OBJ export writes one `o` group per drawable, and an isolated part exports re-centred. ### 2. Vertex position axis order (`+0x6C`) The u32 at vertex-buffer header `+0x6C` says which axis lives in the 16-bit position slot: | value | slots hold | |---|---| | 0 | (z, y, x) | | 1 | (z, x, y) | | 2 | (x, y, z) | Only mode 2 was handled, so roughly 30% of geometries rendered rotated (towers lying on their side). I verified the mapping against drawable bboxes on ~1.6k geometries across 150 models: 191/193, 310/311 and 1104/1118 fit. A few geometries carry other values and look like a different vertex layout; those keep the old read. ### 3. Fake MODEL entries in the scanner Metadata containers and mid-resource chunks were listed as MODEL because they contain a `*.#dr` string. Opening them failed with "No RAGE9 meshlet geometries". The scanner now: - rejects chunks that start with a grmGeometry (`+0x60 == 0x1601`) - validates BlockMap chunk counts instead of clamping them - requires real meshlet geometry before listing an entry The scan cache is bumped to `v9` so stale entries aren't reused. That means one full rescan after updating. ### 4. External `.ttpf` textures Shader texture references are resolved to the external texture archives through their 64-bit hashes. The index is built once per dump root and decodes are cached. You get per-geometry materials, plus vehicle paint detection with colour presets. `cheetah2_hi` resolves 15/35 materials + paint, and the Brickell SLODs resolve 286/317. ### Tests Two regression tests, which only run when `PERCYSTAR_LEVELS_RPF` points at `levels.rpf` from the Xbox dump. Everything else passes as before, and there are no new warnings. Independent of the sort PR; they touch different parts of `main.rs` and merge cleanly together. Same note as the other one: I know PRs are invite only per the license, so close it if you'd rather not take it. Happy to split it up or change anything. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Drawable dictionaries: resources whose root is a pgDictionary of drawables
(hash array at +0x20, drawable array at +0x30) were merged into one mesh,
stacking independent models at the origin (e.g. bk_02_road_str_slod.#dr is
8 Brickell SLOD blocks). Each entry is now decoded on its own (LOD0), laid
out on a grid, and selectable from a part picker in the viewer. OBJ export
writes one group per drawable; an isolated part exports re-centred.

Vertex axis order: the u32 at vertex-buffer header +0x6C says which axis
sits in the 16-bit position slot. 0 -> (z,y,x), 1 -> (z,x,y), 2 -> (x,y,z).
Only mode 2 was handled, so ~30% of geometries rendered rotated (towers on
their side). Verified against drawable bboxes on ~1.6k geometries.

Scanner: reject mid-resource virtual chunks that start with a grmGeometry,
validate BlockMap chunk counts instead of clamping, and require real
meshlet geometry before listing an entry as MODEL. This removes the
metadata containers that showed up as large MODEL entries and failed with
"No RAGE9 meshlet geometries". Scan cache bumped to v9 so old entries are
not reused.

Textures: resolve shader texture references to external .ttpf archives via
their 64-bit hashes (index built once per dump root, decodes cached), with
per-geometry materials and vehicle paint detection plus colour presets.

Tests: two regression tests that run when PERCYSTAR_LEVELS_RPF points at
levels.rpf from the Xbox dump.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Gemini <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:30:49 +00:00
github manually merged commit 705dd76600 into gh-pr/7/base 2026-11-27 02:30:51 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-20 22:01 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-20 22:01 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/7#pullrequestreview-5999971909) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠rpatty-dev on GitHub · 2026-11-21 08:03 UTC · original

Merged and shipped in v1.3.1! Huge improvement having drawable dictionary grid splitting, +0x6C vertex axis permutation, mid-resource geometry filtering (scan_cache_v9), and external .ttpf hash material + car paint resolution. Thank you @⁠Ahmet-Dedeler!

**@⁠rpatty-dev** on GitHub · 2026-11-21 08:03 UTC · [original](https://github.com/rpatty-dev/PercyStar/pull/7#issuecomment-7059654259) Merged and shipped in [v1.3.1](https://github.com/rpatty-dev/PercyStar/releases/tag/v1.3.1)! Huge improvement having drawable dictionary grid splitting, +0x6C vertex axis permutation, mid-resource geometry filtering (scan_cache_v9), and external .ttpf hash material + car paint resolution. Thank you @⁠Ahmet-Dedeler!
This discussion has been locked. Commenting is limited to contributors.
No description provided.