Skip to main content

Module cesium

Module cesium 

Source
Expand description

Cesium heightmap-1.0 terrain tile format.

The legacy Cesium terrain format. Each tile is a regular grid of 16-bit heights (default 65 × 65, north → south, west → east) plus a 1-byte child-availability mask. Optional extensions follow: a water mask (1 byte uniform or 256 × 256 bytes), then oct-encoded per-vertex normals (2 bytes per vertex).

Specification: https://github.com/CesiumGS/cesium/wiki/heightmap-1.0

§Layout

+------------------------------------+
| u16 LE heights (size×size × 2 B)   |
+------------------------------------+
| u8 child mask                      |
+------------------------------------+
| water mask (optional, 1 or 256² B) |
+------------------------------------+
| oct normals (optional, 2 × N B)    |
+------------------------------------+

Encoded files are typically gzip-compressed; this module returns raw uncompressed bytes — compress them yourself with flate2 or similar.

§Height encoding

value = (elevation + 1000) * 5, i.e. range −1000 m … +12107 m at 0.2 m resolution. Use elevation_to_u16 / u16_to_elevation for single-sample conversion.

Structs§

ChildTileMask
Child-availability mask: one bit per quadrant indicating whether a child tile exists at the next zoom level.

Constants§

MAX_ELEVATION
Maximum elevation representable in metres.
MIN_ELEVATION
Minimum elevation representable in metres.
SCALE
Scale factor: value = (elevation - MIN_ELEVATION) * SCALE.
TILE_SIZE
Default heightmap-1.0 tile side length (Cesium streams 65 × 65 tiles).

Functions§

decode_heights
Decode little-endian u16 bytes back to a flat elevation grid.
elevation_to_u16
Encode a single elevation sample (metres) into the heightmap-1.0 u16.
encode_heights
Encode a row-major elevation grid into a freshly allocated Vec<u8>.
encode_heights_into
Encode a row-major width × height elevation grid into a caller-owned little-endian u16 byte buffer. out.len() must equal width * height * 2.
encode_heights_to
Stream-encode a width × height elevation grid as little-endian u16 bytes to a writer. Uses a 4 KiB stack buffer.
iter_heights
Lazily iterate decoded elevations from little-endian u16 bytes. Trailing odd bytes are ignored.
u16_to_elevation
Decode a heightmap-1.0 u16 back to elevation (metres).