pub struct ChunkGenerator { /* private fields */ }Expand description
Deterministic terrain generator for one VoxelWorld.
Constructed once from the world’s seed and chunk dimensions; generate
produces the block array for any chunk on demand.
Implementations§
Source§impl ChunkGenerator
impl ChunkGenerator
Sourcepub fn new(seed: u64, chunk_blocks: [u32; 3], palette_len: u32) -> Self
pub fn new(seed: u64, chunk_blocks: [u32; 3], palette_len: u32) -> Self
A generator for a world with the given seed, chunk dimensions, and
palette length.
By the VoxelWorld palette convention index 0 is air, 1 the surface
block, and 2 (when the palette has it) the subsurface block; a
shorter palette falls back to index 1 for subsurface.
Sourcepub fn generate(&self, coord: ChunkCoord) -> Vec<u32>
pub fn generate(&self, coord: ChunkCoord) -> Vec<u32>
Generate the dense block array for chunk coord.
The result has length dx*dy*dz with the layout
index = x + y*dx + z*dx*dy, exactly what the voxel mesher expects.
A column is solid up to its noise-derived surface height and air above.
Sourcepub fn surface_height_world(&self, wx: i32, wz: i32) -> i32
pub fn surface_height_world(&self, wx: i32, wz: i32) -> i32
Surface block height (topmost solid block index) of the column at world
block coordinate (wx, wz), clamped to [0, chunk_height-1].
Public so the distant-chunk impostor mesher can sample the terrain
surface on a coarse grid without paying for a full dense block array.
Because it keys on world coordinates (like generate),
two impostor chunks sample identical heights along their shared edge, so
their coarse surfaces meet watertight.
Sourcepub fn surface_palette_index(&self) -> u32
pub fn surface_palette_index(&self) -> u32
Palette index of the surface (topmost) block: 1 when the palette has
a dedicated surface block, else 0. The impostor mesher uses it to pick
the surface block’s atlas UVs so impostors texture like the full chunks.