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§
- Child
Tile Mask - 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 × heightelevation grid into a caller-owned little-endian u16 byte buffer.out.len()must equalwidth * height * 2. - encode_
heights_ to - Stream-encode a
width × heightelevation 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).