Decode the whole-world height map (sixng heightmap) #145

Manually merged
github merged 1 commit from gh-pr/145/head into gh-pr/145/base 2026-11-26 20:13:13 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 12:46 UTC · original
holdmysocks:claude/world-heightmap → master · +374 −0 · 4 files · 1 commits · merged 2026-11-24 13:04 UTC

Linear: SIX-96

What

  • sixng-core::heightmap decodes the MHIU whole-world height maps in common.rpf.
  • sixng heightmap [common] [-o <dir>] [--preview] [--map 0|1] [--check <map bake dir>] writes these files to <out>/heightmap/:
    • heightmap.png: 16-bit greyscale, north up; 0..65535 spans min z..max z.
    • heightmap.json: world box, metres per pixel, height scale, sea value and the formula to recover metres.
    • hillshade.png (with --preview): a hill-shaded RGB preview.
  • --check compares the heights with the map bake's 8 m collision top-surface grid (heights_8m.bin) and reports the statistics.
  • README: a status row, a CLI line and a format note. There are unit tests on a synthetic map.

Format (verified against the data)

  • Header, 0x2C bytes:
    • magic MHIU
    • u16 version (1)
    • u16 width (2048)
    • u32 rows (2048)
    • 6 × f32 world box: -13000, -9000, -50 to 7000, 11000, 500
    • u32 count of the bytes after the header (row table plus samples)
    • u8 fill value 0x17 (sea, -0.39 m)
    • 3 bytes of unknown meaning, which differ between the copies
  • Row table: 8 bytes per row (u16 first column, u16 count, i32 offset). The offset is biased by -first, so column x is samples[offset + x]. The counts add up to the sample bytes exactly.
  • Row 0 is the south edge. One pixel is 9.77 m. Height is min_z + v × 550/255, so one step is 2.16 m.
  • There are two copies, at 0x144000 and 0x16e000, on the same grid. They are not a min/max pair:
    • 892 K shared samples are equal and 139 K differ by +1 step.
    • Some land exists in only one copy: 30 K samples in the second, 9 K in the first.
    • The command defaults to the copy with the most stored samples (the second). We do not know what sets them apart in game.
  • It is a surface map: city blocks show up.

Checked numbers

The reference is the collision top-surface grid from the map bake (8 m cells). The difference is height map minus collision, in metres.

Copy Land samples Median diff Median |diff| p90 |diff| Within 3 m Within 10 m Sea over land > 5 m
1 (0x16e000, default) 752,201 -1.94 1.99 5.91 72 % 96 % 26,051
0 (0x144000) 749,933 -1.80 1.84 7.11 75 % 94 % 41,768

Correlation with collision (sampled): 0.993 for copy 1 and 0.974 for copy 0. A least-squares fit gives z ≈ 2.17·v - 47.6, close to the header scale of 2.157·v - 50.

Spot points (copy 1):

Place x, y Height map Collision Diff
highest sample -3435, 6347 400.8 402.0 -1.2
south -2500, -4000 3.9 4.2 -0.3
inland -1500, 2000 1.8 4.8 -3.0
west -4500, 0 12.5 15.1 -2.5
hills -3500, 4500 36.3 40.7 -4.4
north-east 500, 3000 -0.4 (sea) -2.8 +2.4
city -1000, -1500 -0.4 (sea) 11.9 -12.3 (a structure over water)

The height map sits about one quantisation step below the collision top. That is expected, because the collision also counts roofs, bridges and props. As a far-field terrain or hillshade source it is good to about ±2 m. It is too coarse to locate ground holes smaller than about 10 m.

Not done

  • Map 2D hillshade layer: not added. Map 2D already draws a hill-shaded terrain layer from collision at 2 m, so this one would add little there. Its better uses are far-field terrain in Map 3D and a reference for ground holes.
**@⁠holdmysocks** on GitHub · 2026-11-24 12:46 UTC · [original](https://github.com/holdmysocks/SixNG/pull/145) `holdmysocks:claude/world-heightmap` → `master` · +374 −0 · 4 files · 1 commits · merged 2026-11-24 13:04 UTC Linear: SIX-96 ## What - `sixng-core::heightmap` decodes the `MHIU` whole-world height maps in `common.rpf`. - `sixng heightmap [common] [-o <dir>] [--preview] [--map 0|1] [--check <map bake dir>]` writes these files to `<out>/heightmap/`: - `heightmap.png`: 16-bit greyscale, north up; 0..65535 spans min z..max z. - `heightmap.json`: world box, metres per pixel, height scale, sea value and the formula to recover metres. - `hillshade.png` (with `--preview`): a hill-shaded RGB preview. - `--check` compares the heights with the map bake's 8 m collision top-surface grid (`heights_8m.bin`) and reports the statistics. - README: a status row, a CLI line and a format note. There are unit tests on a synthetic map. ## Format (verified against the data) - Header, 0x2C bytes: - magic `MHIU` - u16 version (1) - u16 width (2048) - u32 rows (2048) - 6 × f32 world box: -13000, -9000, -50 to 7000, 11000, 500 - u32 count of the bytes after the header (row table plus samples) - u8 fill value 0x17 (sea, -0.39 m) - 3 bytes of unknown meaning, which differ between the copies - Row table: 8 bytes per row (u16 first column, u16 count, i32 offset). The offset is biased by -first, so column x is `samples[offset + x]`. The counts add up to the sample bytes exactly. - Row 0 is the south edge. One pixel is 9.77 m. Height is `min_z + v × 550/255`, so one step is 2.16 m. - There are two copies, at 0x144000 and 0x16e000, on the same grid. They are not a min/max pair: - 892 K shared samples are equal and 139 K differ by +1 step. - Some land exists in only one copy: 30 K samples in the second, 9 K in the first. - The command defaults to the copy with the most stored samples (the second). We do not know what sets them apart in game. - It is a surface map: city blocks show up. ## Checked numbers The reference is the collision top-surface grid from the map bake (8 m cells). The difference is height map minus collision, in metres. | Copy | Land samples | Median diff | Median \|diff\| | p90 \|diff\| | Within 3 m | Within 10 m | Sea over land > 5 m | |---|---|---|---|---|---|---|---| | 1 (0x16e000, default) | 752,201 | -1.94 | 1.99 | 5.91 | 72 % | 96 % | 26,051 | | 0 (0x144000) | 749,933 | -1.80 | 1.84 | 7.11 | 75 % | 94 % | 41,768 | Correlation with collision (sampled): 0.993 for copy 1 and 0.974 for copy 0. A least-squares fit gives z ≈ 2.17·v - 47.6, close to the header scale of 2.157·v - 50. Spot points (copy 1): | Place | x, y | Height map | Collision | Diff | |---|---|---|---|---| | highest sample | -3435, 6347 | 400.8 | 402.0 | -1.2 | | south | -2500, -4000 | 3.9 | 4.2 | -0.3 | | inland | -1500, 2000 | 1.8 | 4.8 | -3.0 | | west | -4500, 0 | 12.5 | 15.1 | -2.5 | | hills | -3500, 4500 | 36.3 | 40.7 | -4.4 | | north-east | 500, 3000 | -0.4 (sea) | -2.8 | +2.4 | | city | -1000, -1500 | -0.4 (sea) | 11.9 | -12.3 (a structure over water) | The height map sits about one quantisation step below the collision top. That is expected, because the collision also counts roofs, bridges and props. As a far-field terrain or hillshade source it is good to about ±2 m. It is too coarse to locate ground holes smaller than about 10 m. ## Not done - Map 2D hillshade layer: not added. Map 2D already draws a hill-shaded terrain layer from collision at 2 m, so this one would add little there. Its better uses are far-field terrain in Map 3D and a reference for ground holes.
common.rpf holds two MHIU height maps: 2048 x 2048 u8 samples over
X -13000..7000, Y -9000..11000, Z -50..500, stored as one run per row.
The new heightmap module decodes them, and `sixng heightmap` writes a
16-bit greyscale PNG (north up), heightmap.json with the world box, metres
per pixel and height scale, and an optional hill-shaded preview. --check
compares the heights with the map bake's collision height grid.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:13:12 +00:00
github manually merged commit 4d29c99e3c into gh-pr/145/base 2026-11-26 20:13:13 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.