Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(assets): game-ready LOD meshes for the forest plants
gltfpack 1.3 decimates the photogrammetry sources to LOD0 under 15k
triangles, plus LOD1, LOD2, and a KTX2 cross billboard. The commands
and output SHA-256 live in the manifest. The huge source buffers stay
build inputs.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 16, 2026
commit 2d71d002cf940808e8f42e62828d5e810bd4c016
32 changes: 32 additions & 0 deletions assets/terrain/polyhaven/pine_forest/build_game_lod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""Offline LOD build for the forest opening plants.

Pinned tool: gltfpack 1.3
url: https://github.com/zeux/meshoptimizer/releases/download/v1.3/gltfpack-ubuntu.zip
zip sha256: 0666d9dc40d60fe5b9a45f3fc24f8e6ca87112974bd5de9ca57152aa13d06017
binary sha256: 595441045457bf3d069ec14fa807b1034d324db003bd66ac6377977cc11e7da3

The photogrammetry .bin buffers are build inputs. They are not committed.
Download each next to its 1k glTF, then run, from that directory:

gltfpack -i <id>_1k.gltf -o <id>_lod0.glb -sa -si <lod0> -tc -vp 14 -vt 12 -vn 8
gltfpack -i <id>_1k.gltf -o <id>_lod1.glb -sa -si <lod1> -tc -vp 14 -vt 12 -vn 8
gltfpack -i <id>_1k.gltf -o <id>_lod2.glb -sa -si <lod2> -tc -vp 14 -vt 12 -vn 8

-sa is required. A 1% error cap cannot reach 15k triangles from these
sources. -tc writes KTX2. Two runs of this binary write identical bytes.

Ratios (target triangles / source triangles):

pine_tree_01 17182252 tris lod0 0.000873 lod1 0.000291 lod2 0.000087
tree_small_02 2062487 tris lod0 0.007273 lod1 0.002424 lod2 0.000727
island_tree_01 1599403 tris lod0 0.009378 lod1 0.003126 lod2 0.000938
dry_branches_medium_01 16803 tris lod0 0.892697 lod1 0.297565 lod2 0.089271

The billboard is a two-quad cross (4 triangles) written by this repo's
generator and packed with:

gltfpack -i billboard.gltf -o <id>_billboard.glb -tc -vp 14 -vt 12 -vn 8

Outputs live in game/ and their SHA-256 is in manifest.json.
"""
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
192 changes: 188 additions & 4 deletions assets/terrain/polyhaven/pine_forest/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,52 @@
"url": "https://dl.polyhaven.org/file/ph-assets/Models/gltf/1k/tree_small_02/tree_small_02.bin",
"note": "Photogrammetry mesh buffer. Not vendored; the public repo keeps the glTF and 1k maps."
}
]
],
"game_ready": {
"tool": "gltfpack",
"tool_version": "1.3",
"tool_url": "https://github.com/zeux/meshoptimizer/releases/download/v1.3/gltfpack-ubuntu.zip",
"tool_zip_sha256": "0666d9dc40d60fe5b9a45f3fc24f8e6ca87112974bd5de9ca57152aa13d06017",
"tool_binary_sha256": "595441045457bf3d069ec14fa807b1034d324db003bd66ac6377977cc11e7da3",
"command": "gltfpack -i <source.gltf> -o <out.glb> -sa -si <ratio> -tc -vp 14 -vt 12 -vn 8",
"source_tris": 2062487,
"lod0_triangle_budget": 15000,
"note": "Aggressive simplify (-sa) is required to reach the budget from the photogrammetry source. Output glb is byte-identical across two runs of this binary. Billboard is a two-quad cross packed with the same flags from a generated glTF.",
"lods": [
{
"level": "lod0",
"path": "assets/terrain/polyhaven/pine_forest/game/tree_small_02_lod0.glb",
"bytes": 2231640,
"sha256": "385cc89d4c334d8f854e15f02e071ef3967d7a80585920b7917f78ce0506dd5c",
"ratio": "0.007273",
"textures": "KTX2"
},
{
"level": "lod1",
"path": "assets/terrain/polyhaven/pine_forest/game/tree_small_02_lod1.glb",
"bytes": 1949176,
"sha256": "38324c8540206159d9ba346ac73cd26af4b09ac164a7a1c6eaba316e59967365",
"ratio": "0.002424",
"textures": "KTX2"
},
{
"level": "lod2",
"path": "assets/terrain/polyhaven/pine_forest/game/tree_small_02_lod2.glb",
"bytes": 1831300,
"sha256": "fc82a090bef0d359f2ba60be128984bfc02782ccf4cbc4865270143fe0fb6c95",
"ratio": "0.000727",
"textures": "KTX2"
},
{
"level": "billboard",
"path": "assets/terrain/polyhaven/pine_forest/game/tree_small_02_billboard.glb",
"bytes": 127032,
"sha256": "db5162691c21c0c599c1bad2f556caf3af07688913c2d0a927e35f24e8d88642",
"ratio": null,
"textures": "KTX2"
}
]
}
},
{
"role": "island_tree",
Expand Down Expand Up @@ -574,7 +619,52 @@
"url": "https://dl.polyhaven.org/file/ph-assets/Models/gltf/1k/island_tree_01/island_tree_01.bin",
"note": "Photogrammetry mesh buffer. Not vendored; the public repo keeps the glTF and 1k maps."
}
]
],
"game_ready": {
"tool": "gltfpack",
"tool_version": "1.3",
"tool_url": "https://github.com/zeux/meshoptimizer/releases/download/v1.3/gltfpack-ubuntu.zip",
"tool_zip_sha256": "0666d9dc40d60fe5b9a45f3fc24f8e6ca87112974bd5de9ca57152aa13d06017",
"tool_binary_sha256": "595441045457bf3d069ec14fa807b1034d324db003bd66ac6377977cc11e7da3",
"command": "gltfpack -i <source.gltf> -o <out.glb> -sa -si <ratio> -tc -vp 14 -vt 12 -vn 8",
"source_tris": 1599403,
"lod0_triangle_budget": 15000,
"note": "Aggressive simplify (-sa) is required to reach the budget from the photogrammetry source. Output glb is byte-identical across two runs of this binary. Billboard is a two-quad cross packed with the same flags from a generated glTF.",
"lods": [
{
"level": "lod0",
"path": "assets/terrain/polyhaven/pine_forest/game/island_tree_01_lod0.glb",
"bytes": 2360548,
"sha256": "5431981b08a19627dc6ed84a1875ffe129f5ca09615eeeef51e6f77b816fed7b",
"ratio": "0.009378",
"textures": "KTX2"
},
{
"level": "lod1",
"path": "assets/terrain/polyhaven/pine_forest/game/island_tree_01_lod1.glb",
"bytes": 1943724,
"sha256": "195ba618db38f3f8496ca29bb9884e410e1af53000d423769a8c7f562677bf28",
"ratio": "0.003126",
"textures": "KTX2"
},
{
"level": "lod2",
"path": "assets/terrain/polyhaven/pine_forest/game/island_tree_01_lod2.glb",
"bytes": 1802596,
"sha256": "03b871782411c1ac5765fde7fcc442ff1d7c560e5eafdbe6cee7e8e68f8b2f0e",
"ratio": "0.000938",
"textures": "KTX2"
},
{
"level": "billboard",
"path": "assets/terrain/polyhaven/pine_forest/game/island_tree_01_billboard.glb",
"bytes": 79980,
"sha256": "0c8e4778dc65017169ef3b804533365918197cf56a93eaa748adca02db0130bd",
"ratio": null,
"textures": "KTX2"
}
]
}
},
{
"role": "dead_branches",
Expand Down Expand Up @@ -621,7 +711,52 @@
"sha256": "62f5205bfec599000bb7a430e003bbada939bc8d7976a7d3ab7709fd5893413c",
"url": "https://dl.polyhaven.org/file/ph-assets/Models/jpg/1k/dry_branches_medium_01/dry_branches_medium_01_nor_gl_1k.jpg"
}
]
],
"game_ready": {
"tool": "gltfpack",
"tool_version": "1.3",
"tool_url": "https://github.com/zeux/meshoptimizer/releases/download/v1.3/gltfpack-ubuntu.zip",
"tool_zip_sha256": "0666d9dc40d60fe5b9a45f3fc24f8e6ca87112974bd5de9ca57152aa13d06017",
"tool_binary_sha256": "595441045457bf3d069ec14fa807b1034d324db003bd66ac6377977cc11e7da3",
"command": "gltfpack -i <source.gltf> -o <out.glb> -sa -si <ratio> -tc -vp 14 -vt 12 -vn 8",
"source_tris": 16803,
"lod0_triangle_budget": 15000,
"note": "Aggressive simplify (-sa) is required to reach the budget from the photogrammetry source. Output glb is byte-identical across two runs of this binary. Billboard is a two-quad cross packed with the same flags from a generated glTF.",
"lods": [
{
"level": "lod0",
"path": "assets/terrain/polyhaven/pine_forest/game/dry_branches_medium_01_lod0.glb",
"bytes": 948816,
"sha256": "45d778f667dba73312005c23e2ab395334e832a514a3b22e657b26d764411a04",
"ratio": "0.892697",
"textures": "KTX2"
},
{
"level": "lod1",
"path": "assets/terrain/polyhaven/pine_forest/game/dry_branches_medium_01_lod1.glb",
"bytes": 799552,
"sha256": "01d17ab7687cc903ed59d073067c5ef21ca77a1c42064a7f0ea54cd5c72542cc",
"ratio": "0.297565",
"textures": "KTX2"
},
{
"level": "lod2",
"path": "assets/terrain/polyhaven/pine_forest/game/dry_branches_medium_01_lod2.glb",
"bytes": 734508,
"sha256": "cc82cd06b5e019da4478286e544f9cc5f7e2bafe2e67fd3c09be6d7599becc1f",
"ratio": "0.089271",
"textures": "KTX2"
},
{
"level": "billboard",
"path": "assets/terrain/polyhaven/pine_forest/game/dry_branches_medium_01_billboard.glb",
"bytes": 227224,
"sha256": "9df747badf96a3f16417a4f663d2d9990a3e591ecd2ae687e48bc59d89961b2d",
"ratio": null,
"textures": "KTX2"
}
]
}
},
{
"role": "conifer",
Expand Down Expand Up @@ -734,7 +869,52 @@
"url": "https://dl.polyhaven.org/file/ph-assets/Models/gltf/1k/pine_tree_01/pine_tree_01.bin",
"note": "Photogrammetry mesh buffer. Not vendored; the public repo keeps the glTF and 1k maps."
}
]
],
"game_ready": {
"tool": "gltfpack",
"tool_version": "1.3",
"tool_url": "https://github.com/zeux/meshoptimizer/releases/download/v1.3/gltfpack-ubuntu.zip",
"tool_zip_sha256": "0666d9dc40d60fe5b9a45f3fc24f8e6ca87112974bd5de9ca57152aa13d06017",
"tool_binary_sha256": "595441045457bf3d069ec14fa807b1034d324db003bd66ac6377977cc11e7da3",
"command": "gltfpack -i <source.gltf> -o <out.glb> -sa -si <ratio> -tc -vp 14 -vt 12 -vn 8",
"source_tris": 17182252,
"lod0_triangle_budget": 15000,
"note": "Aggressive simplify (-sa) is required to reach the budget from the photogrammetry source. Output glb is byte-identical across two runs of this binary. Billboard is a two-quad cross packed with the same flags from a generated glTF.",
"lods": [
{
"level": "lod0",
"path": "assets/terrain/polyhaven/pine_forest/game/pine_tree_01_lod0.glb",
"bytes": 2763864,
"sha256": "b7859193a3947236e4af006a53ed7ea3b2ba8124143516576deea4f524e39d4f",
"ratio": "0.000873",
"textures": "KTX2"
},
{
"level": "lod1",
"path": "assets/terrain/polyhaven/pine_forest/game/pine_tree_01_lod1.glb",
"bytes": 2541664,
"sha256": "73f5aff419db6222b3543bd95f17f89b3041ce51708fdccf663e28305ac1395a",
"ratio": "0.000291",
"textures": "KTX2"
},
{
"level": "lod2",
"path": "assets/terrain/polyhaven/pine_forest/game/pine_tree_01_lod2.glb",
"bytes": 2457040,
"sha256": "b6a7d03323cc4ce788bf7d12990d7e06c7d9ce009f58be69c80d5bab5b5c9cc4",
"ratio": "0.000087",
"textures": "KTX2"
},
{
"level": "billboard",
"path": "assets/terrain/polyhaven/pine_forest/game/pine_tree_01_billboard.glb",
"bytes": 171908,
"sha256": "9700a461851f270c61672eb6a806fd37e49810134a4e436fd6bc855203426a6b",
"ratio": null,
"textures": "KTX2"
}
]
}
},
{
"role": "opening_sky_ibl",
Expand Down Expand Up @@ -814,5 +994,9 @@
"source_url": "https://polyhaven.com/a/pine_tree_01",
"license": "CC0",
"license_url": "https://polyhaven.com/license"
},
"game_lod_pipeline": {
"script": "assets/terrain/polyhaven/pine_forest/build_game_lod.py",
"gltfpack": "1.3"
}
}
42 changes: 42 additions & 0 deletions astraweave-terrain/tests/worldgen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ use std::path::PathBuf;
use astraweave_terrain::column_gen::worldgen_record;
use sha2::{Digest, Sha256};

fn glb_triangles(bytes: &[u8]) -> usize {
assert_eq!(&bytes[0..4], b"glTF");
let json_len = u32::from_le_bytes(bytes[12..16].try_into().unwrap()) as usize;
let json: serde_json::Value =
serde_json::from_slice(&bytes[20..20 + json_len]).expect("glb json");
let accessors = json["accessors"].as_array().expect("accessors");
json["meshes"]
.as_array()
.expect("meshes")
.iter()
.flat_map(|mesh| mesh["primitives"].as_array().into_iter().flatten())
.map(|prim| {
let index = prim["indices"].as_u64().expect("indices") as usize;
accessors[index]["count"].as_u64().expect("count") as usize / 3
})
.sum()
}

fn sha256_hex(bytes: &[u8]) -> String {
let digest = Sha256::digest(bytes);
let mut hex = String::with_capacity(digest.len() * 2);
Expand Down Expand Up @@ -99,6 +117,30 @@ fn pine_forest_manifest_matches_downloaded_bytes() {
assert_eq!(file["sha256"].as_str().unwrap().len(), 64);
}
}
if let Some(lods) = asset
.get("game_ready")
.and_then(|ready| ready.get("lods"))
.and_then(|value| value.as_array())
{
assert_eq!(
asset["game_ready"]["tool_version"].as_str(),
Some("1.3"),
"{role} gltfpack pin"
);
for lod in lods {
let rel = lod["path"].as_str().expect("lod path");
let bytes = std::fs::read(repo.join(rel)).expect(rel);
assert_eq!(sha256_hex(&bytes), lod["sha256"].as_str().unwrap(), "{rel}");
let level = lod["level"].as_str().unwrap();
let tris = glb_triangles(&bytes);
if level == "lod0" {
assert!(tris <= 15_000, "{rel} has {tris} triangles");
}
if level == "billboard" {
assert_eq!(tris, 4, "{rel} cross billboard");
}
}
}
}
for required in [
"forest_floor",
Expand Down
19 changes: 19 additions & 0 deletions docs/current/TERRAIN_SCATTER_ARCHAEOLOGY.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,22 @@ Acceptance: opening census test still has trees, no palms, an empty dirt road. A
For each row in the table that says “or”: the change either adds a non-test caller and a test, or deletes the file. `astraweave-pcg` is the first of these. `clipmap_terrain.rs` is a delete.

Acceptance: `rg` for each deleted type is empty. `cargo test -p astraweave-terrain --lib` passes. The determinism workflow stays required for `worldgen_columns`.

---

## 14. Done and remaining (2026-10-14)

| Item | Status |
|---|---|
| P1 mesher, edge-keyed `vertex_cache`, byte-identity regression | Done |
| P2 `worldgen_columns` required in `determinism-replay.yml` | Done |
| P2 sorted foliage upload, `SimRng` yaw quanta, editor zone seed is `terrain_seed()` | Done |
| P0 integer columns, dirt road, forest opening, no palms in the opening | Done |
| P3 scatter LOD and instancing. 2009 props, 727 kept, 1.54 ms CPU | Done on CPU. RTX 4060 Ti frame time is still unmeasured: this host has no Vulkan device |
| P4 dig (`E`) and place (`R`) on density 0/1 voxels, save/replay | Done. `aravath_runtime` lib tests cover dig, place, and the replay golden `fd303f2adf402881` |
| Game-ready scatter meshes | Done. `gltfpack` 1.3, command in `build_game_lod.py` and `manifest.json`. LOD0 is under 15k triangles (`pine_tree_01` 14,790). LOD1, LOD2, and a 4-triangle KTX2 cross billboard are committed with SHA-256. The 949 MB source buffer stays a build input |
| Greybox still draws KayKit | Remaining. `load_colored` reads vertex colors and ignores images. The new glbs are textured KTX2. Swapping them in without a texture bind would draw flat white trees. That bind is U3, with the render agent’s IBL bind of `spruit_sunrise` (PR #216) |
| U1 `ColumnStream` and deletion of the unused heightmap streamer | Not started |
| U2 integer height as the only saved editor ground, erosion bake | Not started |
| U3 editor scatter reads `prop_at`, voxel materials sample the manifest, GPU frame time | Not started |
| U4 wire or delete `astraweave-pcg`, clipmap, GPU erosion, Phase 10 leftovers | Not started |