Skip to content

navmesh_nodes: count the polygon flag bits under the lane-graph nodes - #3834

Open
kotorvr wants to merge 4 commits into
ItsNotRexed:mainfrom
kotorvr:asset-navmesh-node-flags
Open

kotorvr wants to merge 4 commits into
ItsNotRexed:mainfrom
kotorvr:asset-navmesh-node-flags

Conversation

@kotorvr

@kotorvr kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim: #3574 (comment) (new ASSET item, no ID assigned yet).

What and why

docs/navmesh.md lists the navmesh polygon flag bits as open ("Remaining unknowns", item 4). It also says of two road/pavement labels read in another project that "neither meaning is confirmed". The repository already has what is needed to test such a label without looking at a picture: the lane graph in levels.rpf (tools/world_lights_paths.py) gives every road node a world position, and a navmesh tile gives polygons with positions and flags.

tools/navmesh_nodes.py puts the two together. For each node it finds the polygon of the node's 128 m tile that contains the node in plan view and is closest in height, and counts the bits of that polygon's +0x18 and +0x28 words. Beside that it sums the plan area of the polygons carrying each bit over the same tiles, and for the two +0x18 bits that most nodes stand on (8 and 13) it counts the four combinations. The output is counts only.

Measured (my own 1.0.2.1 copy, all of navmeshes.rpf and levels.rpf)

  • 63,808 lane-graph nodes read, 63,806 with a finite position; 63,802 lie over a polygon and 63,793 have one within 3 m above or below. The height difference is 0.032 m at the median, 0.095 m at p90 and 0.28 m at p99. That confirms the vertex decoding the tool uses, tile minimum + u16 / 65535 * tile extent, which the doc did not state.
  • 6,970 static tiles hold a node: 77,880,896 polygons with three or more vertices, 120.2 km2 of plan area, 0 tiles unreadable.
Word Bit Nodes on it (of 63,793) Polygons Share of plan area
+0x18 13 (0x2000) 57,559 (90.2%) 3,357,132 12.0%
+0x18 8 (0x100) 58,528 (91.7%) 251,917 2.6%
+0x18 12 (0x1000) 787 (1.2%) 18,746,182 33.6%
+0x18 19 (0x80000, the doc's water candidate) 3,980 (6.2%) 3,263,052 23.6%
+0x18 27 (0x8000000) 5,526 (8.7%) 2,489,161 3.2%
+0x28 17 (0x20000) 21,246 (33.3%) 1,083,157 4.7%
+0x28 18 (0x40000) 4,520 (7.1%) 280,763 1.6%

No other bit has more than 5% of the nodes (the next is +0x18 bit 3 at 4.7%). Bits 8 and 13 in combination:

+0x18 bits 8 and 13 Nodes Polygons Area
both 57,181 (89.6%) 236,753 2.5%
bit 8 only 1,347 (2.1%) 15,164 0.1%
bit 13 only 378 (0.6%) 3,120,379 9.5%
neither 4,887 (7.7%) 74,508,600 87.8%

What this shows:

  • Nine in ten lane nodes stand on polygons that carry both bit 8 and bit 13.
  • Bit 13 without bit 8 covers almost four times as much area with almost no node on it.
  • Bit 12 is clearly away from the lanes.
  • The two bits the doc attributed to 6stars (+0x18 bit 27, +0x28 bit 17) are not under most lane nodes.

It does not show which bit, or which combination, means road surface. The doc records the counts and leaves that open.

Where the lead came from

holdmysocks/SixNG, crates/sixng-core/src/navmesh.rs at commit 0619601 (GPL-3.0), labels polygon +0x18 bit 0x2000 "road surface, checked visually" and states the same vertex formula. I measured both with this repository's own readers; no code, table or comment is taken from it. The vertex formula is confirmed. The label is consistent with the count (road surface could be wider than the driven lanes) but not settled by it. docs/related_projects.md gets a SixNG entry saying exactly that.

Change

  • tools/navmesh_nodes.py (new, standard library, python -I).
    • Functions: tile_geometry, the point-in-polygon and area helpers, pair_key, tally_tile / summarize and cross_check.
    • CLI: navmesh_nodes.py <navmeshes.rpf> <levels.rpf> [--out] [--jobs] [--max-dz].
    • It imports navmesh_decode (stream walk, split arrays) and world_lights_paths (node positions); neither is changed.
  • tests/test_navmesh_nodes.py (new, 14 tests): synthetic tiles from the builder in tests/test_navmesh_decode.py with vertices and flags filled in, and a synthetic lane graph from tests/test_world_lights_paths.py.
  • docs/navmesh.md: a section "Polygon flags under the lane graph" with both tables and the method. The 6stars sentence and unknowns item 4 are updated, and the tool and its test are added to "Tools".
  • docs/related_projects.md: SixNG entry (link, licence, the two facts with file and commit, what was re-measured).

Tests

No game files, no GPU (CPU only, Windows 11, Python 3.13.7):

  • python -I tests/test_navmesh_nodes.py: 14 pass. These are new tests of a new tool, so there is nothing for them to fail against on main, where the module does not exist. They cover:
    • the vertex scale, including the exact far corner at u16 65535;
    • two levels over the same ground, where the closest height wins;
    • a node over no polygon, and a node in a tile the archive lacks;
    • dynamic and unreadable tiles, --max-dz 0 and 10, and an empty node list;
    • the four combinations of bits 8 and 13;
    • the CLI's refusals: missing files, --jobs 0, negative or NaN --max-dz, --out on an input or a folder, a file that is not an archive. Each gives exit code 2 without a traceback and leaves the inputs unchanged.
  • Also OK: python -I tests/test_navmesh_decode.py, tests/test_world_lights_paths.py, the four tests/test_docs_*.py and tests/test_text_write_line_endings.py. python -m compileall -q make_game.py tools tests: clean.
  • Both tables are the tool's own output on the package (--jobs 6, about 35 minutes), run from a byte-identical copy of the committed file. I ran the package twice: first with the tool as in the first commit, then with the same tool plus the combination counter. The combination table comes from the second run, and every number the first run produced was identical in the second.

Overlap

Not ASSET-281 (+0xB8 records) or ASSET-287 (grid keys). Trial merges with open PRs that touch docs/navmesh.md:

AI-assisted (Claude Code). No game data: synthetic bytes in the tests, counts and field layouts in the docs.

🤖 Generated with Claude Code

kotorvr and others added 3 commits November 22, 2026 21:28
docs/navmesh.md left the polygon flag bits open and two road/pavement
labels from another project unconfirmed. tools/navmesh_nodes.py puts
every lane-graph node of levels.rpf on the navmesh polygon under it and
counts that polygon's +0x18 and +0x28 bits next to the plan area each
bit covers.

On one 1.0.2.1 package 63,793 of 63,806 nodes have a polygon within 3 m
(median 0.03 m), which confirms vertex = tile minimum + u16 / 65535 *
extent; 90.2% of them stand on a polygon with +0x18 bit 13, which covers
12.0% of the area: road surface, as SixNG labels it from a visual check.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… measured

The first version called +0x18 bit 13 road surface. The count cannot
tell it from bit 8: both lie under about nine in ten lane nodes. The
tool now also counts the four combinations of the two bits (both, only
one, neither) for nodes and area: 89.6% of the nodes stand on polygons
with both bits, which cover 2.5% of the area, and bit 13 alone covers
9.5% with 0.6% of the nodes. The doc reports that, keeps SixNG's label
as its visual reading, and leaves which bit means road surface open.
docs/related_projects.md gets a SixNG entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested b3e1fae on Windows, CPython 3.14.7, CPU only (no GPU, no game files).

python -m pytest -q tests/test_navmesh_nodes.py tests/test_navmesh_decode.py (venv with the pinned tests/requirements.txt): 27 passed, 11 subtests passed. The tool is new, so there is no merge-base control.

One case, reproduced: an archive whose data offset points past the end of the file is accepted and reported as a successful scan of nothing.

import sys, pathlib, struct, subprocess
sys.path.insert(0, "tests")
import test_navmesh_nodes as t
c = t.ArchiveTest()
c.setUp()
try:
    pathlib.Path(c.navmeshes).write_bytes(b"9FPR" + struct.pack("<I", 64))
    p = subprocess.run([sys.executable, "-I", t.TOOL, c.navmeshes, c.levels], capture_output=True, text=True)
    print(p.returncode, p.stderr, p.stdout[:160])
finally:
    c.tearDown()

Run from the repository root. The 8-byte archive says its data starts at byte 64. Actual: exit 0, empty stderr, and a JSON report with area_m2 0 (the archive walk does zero iterations). Expected: exit 2 with a line naming the invalid data start, so a truncated or wrong file is not counted as "no nodes". Checking 8 <= data_start <= file size before the walk would do it.

AI-assisted.

@kacper-serewis

Copy link
Copy Markdown
Contributor

The local 1.0.2.1 export reproduced 63,808 lane records and 63,806 finite positions. On 30 node-bearing tiles, all 459 matched nodes had the same flag and cutoff classification using mean vertex height and triangle-interpolated height. Independent projected areas agreed within 0.000001 square metres per flag combination across 390,422 polygons. Please name the mean-vertex-height approximation in the distance description: on a slope it can differ from surface height at the node. Overlapping surfaces count separately in summed plan area. The bounded sample does not verify all archive totals. AI-assisted, CPU only.

@eyyun

eyyun commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Reviewed and tested 471ba1c1 on Windows 11 (Python 3.13, CPU):

  • python -I tests/test_navmesh_nodes.py -v: 14/14 pass (1.21s).
  • python -I tests/test_text_write_line_endings.py: 2/2 pass.
  • Verified the vertex formula lo + u16 / 65535.0 * ext and the +0x18/+0x28 flag offsets against tools/navmesh_decode.py and the 0x00010015 polygon layout.

Two small non-blocking notes:

  1. _same_file (tools/navmesh_nodes.py:273-277): When --out does not exist yet (e.g. --out NAVMESHES.RPF on a case-insensitive macOS APFS volume where os.path.samefile raises OSError and os.path.normcase does not fold case), _same_file falls back to os.path.normcase(os.path.abspath(...)). Using from report_paths import same_report_path handles both existing and non-existent paths across Windows and case-insensitive macOS volumes.
  2. Stacked static tiles in tally_tile (tools/navmesh_nodes.py:139-180): Because 27,482 static tiles sit on 24,480 unique (sx, sy) sectors (940 sectors have 2 to 40 stacked tiles sharing u32@0xC8), tally["best"][n] selects one best polygon per node across all stacked tiles of the sector while tally["polygons"] and tally["area"] sum over every tile at that sector (tiles_with_nodes = 6,970 vs tiles_named_by_nodes). The distinction between tiles_named_by_nodes and tiles_with_nodes in the JSON output makes that clear.

AI-assisted.

…oximations

Review on ItsNotRexed#3834: an archive whose data offset pointed past its end was
scanned as an empty archive (exit 0). The tool now refuses a data start
outside 8..file size with exit 2. --out is compared with the inputs
through report_paths.same_report_path, as the other tools do. The
docstring and docs/navmesh.md now say that a polygon's height is the
mean of its vertex heights, and that surfaces above one another (a
bridge, stacked tiles of one sector) each add their plan area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all three addressed in 2b71db44 (on top of b3e1faec).

  • @shdann: reproduced. The tool now refuses a data start outside 8 .. file size: exit 2 with a line naming the start and the file size, and no report. New test test_cli_refuses_a_data_start_outside_the_archive covers starts of 64 and 4 in an 8-byte archive; it fails on b3e1faec and passes now.
  • @kacper-serewis: the docstring and docs/navmesh.md now say that a polygon's height is the mean of its vertex heights, not the surface height under the node, and that the 3 m cutoff absorbs the difference on a slope. They also say that surfaces above one another each add their own plan area. Thanks for the independent check on 30 tiles and 390,422 polygons.
  • @eyyun: --out is now compared with both inputs through report_paths.same_report_path, and the local helper is gone; the refusal test gained a ./-spelled alias of an input. On stacked tiles: yes, tiles_named_by_nodes (5,503 sector ids) and tiles_with_nodes (6,970 tiles) differ for that reason. The doc now names stacked tiles in the plan-area sentence. A node's best polygon is chosen across all tiles of its sector, which is intended.

tests/test_navmesh_nodes.py 15/15; the tests/test_docs_*.py checks and the line-endings test pass; compileall clean. These changes do not alter the counts on real data: the new check only rejects bad headers, the --out check is CLI-only, and the rest is text, so I did not rerun the 35-minute package pass. Trial merge with current main is clean. AI-assisted (Claude Code).

@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.

At 2b71db4 the mean-height calculation is described correctly. Please qualify the remaining claim that 3 m absorbs the difference on slopes. In a synthetic 16 m rise over 32 m, a node on the ramp was 7 m from the vertex mean and was excluded. Adding a flat surface at 3 m instead assigned its flags. The bounded retail comparison found no observed disagreement among its 459 matched nodes.

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.

4 participants