Expand description
Encoder and decoder for Cesium quantized-mesh-1.0 terrain format.
This crate provides encoding and decoding functionality for the quantized-mesh terrain format used by CesiumJS for efficient 3D terrain streaming.
For the legacy heightmap-1.0 format see
terrain_codec::heightmap::cesium.
§References
- Format specification: https://github.com/CesiumGS/quantized-mesh
§Example
use quantized_mesh::{
QuantizedMeshEncoder, QuantizedMeshHeader, QuantizedVertices,
EdgeIndices, TileBounds,
};
// Create header with tile metadata
let header = QuantizedMeshHeader {
center: [0.0, 0.0, 6378137.0],
min_height: 0.0,
max_height: 100.0,
bounding_sphere_center: [0.0, 0.0, 6378137.0],
bounding_sphere_radius: 1000.0,
horizon_occlusion_point: [0.0, 0.0, 1.0],
};
// Create vertices (simple 2-triangle mesh)
let vertices = QuantizedVertices {
u: vec![0, 32767, 0, 32767],
v: vec![0, 0, 32767, 32767],
height: vec![0, 0, 0, 0],
};
// Triangle indices (2 triangles)
let indices = vec![0, 1, 2, 1, 3, 2];
// Edge indices
let edge_indices = EdgeIndices {
west: vec![0, 2],
south: vec![0, 1],
east: vec![1, 3],
north: vec![2, 3],
};
// Encode to quantized-mesh format
let encoder = QuantizedMeshEncoder::new(header, vertices, indices, edge_indices);
let data = encoder.encode();Modules§
- coords
- Coordinate transformations and geodetic constants.
Structs§
- Available
Range - Tile availability range for metadata extension.
- Decoded
Extensions - Decoded extensions from quantized-mesh format.
- Decoded
Mesh - Fully owned decoded quantized-mesh data.
- Edge
Indices - Edge indices for skirt generation.
- Encode
Options - Options for encoding quantized mesh.
- Extensions
View - Extensions viewed as borrowed slices into the source buffer.
- High
Water Mark Iter - Iterator that applies inverse high-water-mark decoding to an inner
iterator of raw
u32codes. - Quantized
Mesh Encoder - Quantized mesh encoder.
- Quantized
Mesh Header - Quantized mesh header (88 bytes).
- Quantized
Mesh View - Zero-copy view over a parsed quantized-mesh stream.
- Quantized
Vertices - Quantized vertex data.
- Tile
Bounds - Tile bounds in geographic coordinates (degrees).
- Tile
Metadata - Metadata for quantized-mesh extension.
- Zigzag
Delta Iter - Iterator that applies inverse zigzag-delta decoding to a stream of raw
little-endian u16 bytes, yielding decoded
u16values.
Enums§
- Decode
Error - Error type for quantized-mesh decoding.
- Extension
Id - Extension IDs for quantized-mesh format.
- Indices
View - Triangle / edge indices viewed as borrowed bytes.
- RawIndex
Iter - Iterator over raw little-endian-encoded indices (u16 or u32) yielding
u32. - Water
Mask - Water mask data.
- Water
Mask View - Water mask viewed as borrowed bytes.
Constants§
- QUANTIZED_
MAX - Maximum value for quantized coordinates (2^15 - 1).
Functions§
- decompress_
gzip - Decompress a gzip-compressed quantized-mesh blob. Returns the input unchanged (copied) if it isn’t gzip.
- is_gzip
- Check if
datastarts with the gzip magic number. - iter_
oct_ normals - Iterator over oct-encoded normals (2 bytes each), yielding
[f32; 3]. - oct_
decode_ normal - Decode oct-encoded normal to unit vector.
- oct_
encode_ normal - Oct-encode a unit normal vector to 2 bytes.
- zigzag_
decode - Decode a zig-zag encoded value.
- zigzag_
encode - Encode a value using zig-zag encoding.
Type Aliases§
- Decode
Result - Result type for quantized-mesh decoding.