Repository navigation
world_build: whole-city placements with shared geometry and LOD chunk sets - #1316
Merged
Merged
Conversation
…sets --placements used to copy a model's geometry into every placement and keep all copies until chunking (ItsNotRexed#1183 review: 22 GB for a 700 m box). Now each model's OBJ is parsed once into a packed cache file, each chunk stores every model it uses once, and the placements are instance transforms: EXT_mesh_gpu_instancing by default (three.js GLTFLoader reads it), one plain glTF node per placement with --instancing nodes, or the old baked copies with --instancing bake. Chunks are written as soon as they are built; with --jobs N, packing and chunk writing run in N processes, at most 4N jobs in flight. Memory is about 100 bytes per placement plus the models of the chunks being written. Every instance TRS has a positive determinant. A negative XY scale is folded into the rotation; a negative Z scale draws a mirrored copy of the mesh (glTF Y negated, winding reversed). Zero-scale placements are counted as degenerate_scale. iter_placements streams the rows load_placements selects, with the same checks (load_placements is unchanged). --lod-sets builds one chunk set per lodLevel tier (c_<tier>_<x>_<z>, with the tier and grid cell in each chunk record) and writes lod_bands to world.json: a camera-distance band per tier from the entities' median childLodDist/lodDist. The viewer loads a tiered chunk while the horizontal distance to its cell is in the band (32 m slack before unloading), so each cell shows one tier; worlds without lod_bands stream as before, and the manifest check rejects unknown tiers, unordered bands and missing cells. glb_writer: pack_primitive and _MaterialTable are factored out of build_glb (output unchanged), plus build_instanced_glb / write_instanced_glb and instance_bounds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on levels.rpf: 1,549,343 HD/ORPHAN_HD placements in 2,940 chunks (21 min) and all 1,669,771 placements in 12,340 tiered chunks (33 min), every chunk checked structurally and samples parsed by three r160's GLTFLoader; the LOD-tier medians and bands; what the viewer loads with and without bands; the pin vs ItsNotRexed#8/ItsNotRexed#10 model coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 22, 2026
whattheflop
reviewed
Nov 22, 2026
whattheflop
left a comment
Contributor
There was a problem hiding this comment.
AI-assisted independent Windows verification of ace75cfb584aa42481170a4a6493d25a37573635 and its direct parent 99a40c54b185b0b47968f77c6ed070d2de9dbbdc. The tip changes documentation only.
- On Windows 11 x64 with uv-managed CPython 3.12.13, I ran the real
python -I tools/world_build.pyentry point from a scratch path with spaces. A two-OBJ fixture exercised both process-pool phases with nativespawn.--jobs 1and--jobs 2produced byte-identicalworld.jsonand 2/2 GLBs for the default build (5 placements, 60 drawn triangles, 36 stored), and byte-identicalworld.jsonand 4/4 GLBs with--lod-sets(7 placements, 84 drawn triangles, 60 stored). The output digests also matched across the two commits. - For the default GPU-instancing mode and
--instancing nodes, decoding the GLBs and applying their transforms yielded 60/60 matching world-space triangles with winding preserved against--instancing bake. Both chunk bounds and counts matched in each comparison, including a placement with negative XY and Z scales. All 15 selected synthetic Python tests and all 3 synthetic Node 24.16.0 checks passed at each commit. These were CPU-side checks. - One wording discrepancy from the viewer probe. For a single cell with HD [0, 130) and LOD [130, 450), I completed both synthetic loads while moving from 129 m to 150 m. Both objects were attached to the scene at 150 m, and HD detached at 162 m. The 32 m slack keeps the outgoing tier visible after the incoming tier attaches, so the "each cell shows one tier" wording should account for that overlap. Viewer streaming code · World docs
Contributor
Author
|
CI note: |
Contributor
|
Tested ace75cf on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass, and it answers the concern I raised on #1183.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1183 (merged), as promised there in reply to @kapitche's review: #1183 (comment). Item 1 of #1006 (comment) (status: #1006 (comment); coordination is now in #1218).
What and why
#1183 copied a model's geometry into every placement and kept every copy until chunking: 22 GB for one 700 m box, so a whole city didn't fit. This PR makes
world_build.py --placementsbuild the whole oflevels.rpfwith bounded memory, and adds per-tier LOD chunk sets that the viewer switches by distance.--instancing gpu, the new default with--placements):EXT_mesh_gpu_instancing(inextensionsRequired); three.js'sGLTFLoader, which the viewer uses, buildsInstancedMeshes from them.--instancing nodeswrites one plain glTF node per placement instead.--instancing bakekeeps world_build: place models at their map placements (--placements) #1183's output.--jobs Npacks models and writes chunks in N processes, with at most 4·N jobs in flight.scaleXYis folded into the rotation as a 180° turn about Z.scaleZdraws a mirrored copy of the mesh (glTF Y negated, winding reversed), so the winding is right in every loader.degenerate_scale.--lod-sets: one chunk set perlodLeveltier (c_<tier>_<x>_<z>), each chunk with itslodtier and gridcell.world.jsongetslod_bands, a camera-distance band per tier measured from the entities: a tier starts at its medianchildLodDistand ends where the next coarser tier starts; the coarsest tier ends at its medianlodDist, and ORPHAN_HD runs from 0 to its medianlodDist.lod_bandsstream as before.lodDistandparentIndexlinks are not used, because entity rows don't say which map file they came from.glb_writer:pack_primitiveand_MaterialTableare factored out ofbuild_glb. Output is byte-identical: 70 real models compared, with and without materials.build_instanced_glb/write_instanced_glb/instance_bounds.Results on the whole of
levels.rpfMeasured on the 1.0.2.1 package, Linux with 88 cores,
--no-textures, 256 m chunks. Models were exported with rpf9-explorer at Leonida's pin (917e9b9) and with breadbbbb/rpf9-explorer#8 and #10 applied.world_index --entities-out, 24 windows)--jobs 16bake: 5 min, 22 GB peak.gpu: 35 s, 1.93 GB for all 17 processes; same chunks and trianglesgpu,--jobs 40--lod-sets,--jobs 24lod_bands: 180 M triangles, 3.1 GB; without, at the 1,400 m radius: 1,060 M triangles, 16.3 GBChecks:
min/maxequal to the data;world.json(1,549,343 and 7,311,221,858).GLTFLoader, the viewer's loader, run under Node, parses 65 city chunks: 60 random and the 5 largest, including a 926 MB one. Each buildsInstancedMeshes with exactlyworld.json's triangles, and bounds inside the chunk's.Not verified or limited:
--chunk-sizehelps a browser there.scaleZ, so the mirrored path is covered by the synthetic tests only.--jobs, not with the map (38 GB at 40 jobs, 30 GB at 24).Built on main c0ac5fd, which includes #1272 (@73N1X).
load_placementsis unchanged, and the new streamingiter_placementsapplies the same row checks, #1272's included. A test feeds both the same good and malformed rows and checks they return the same rows and counts.Tested
Linux, Python 3.11 (
python -I), Node 22, on main c0ac5fd:tests/test_world_instancing.py(new, 23 tests):instance_bounds; GPU and node GLBs; mirrored meshes (indices and positions);--instancing bake;--jobs 2(processes) giving byte-identical chunks to--jobs 1;iter_placementsagainstload_placements.node --test tests/test_viewer_streaming.cjs: 35 pass, 5 of them new (manifest checks for tiers, bands and cells; one tier per cell by distance; slack before unloading).test_world_place.py,test_world_build.py,test_glb_writer.py,test_glb_writer_buffers.py,test_glb_atomic.py,test_world_index.py,test_world_names.py,test_world_census.py,test_world_index_three_streams.py,test_file_mode.py,test_ttpf_assets.py,test_bad_input_errors.py,test_limit_window.py,test_restofworld_index.py,test_viewer_serve.py, andpython -m compileall tools tests.build_glboutput is byte-identical before and after the refactor: 70 real models, with and without materials.AI-assisted (Claude Code). CPU only, Linux; Node 22 for the viewer tests. The game data was read from a local copy; no game data is in this PR.
🤖 Generated with Claude Code