quantized-mesh
Encoder and decoder for Cesium quantized-mesh-1.0 terrain format in Rust.
Features
- Full quantized-mesh-1.0 format support
- Encoding and decoding with
io::Read/io::Writesupport - Zero-copy decoding via [
QuantizedMeshView<'a>] — borrows the input bytes and exposes vertex/index streams as lazy iterators, with no intermediateVecallocations - Streaming encoder —
encode_to_with_optionswrites each section directly to aWritetarget via a small stack buffer, skipping the intermediateVec<u16>/Vec<u32>encoded buffers - Gzip compression/decompression (auto-detected)
- Extensions support:
- Oct-encoded vertex normals
- Water mask (borrowed
&[u8; 65536]view, or owned) - Metadata (tile availability)
- Coordinate transformations (geodetic to/from ECEF)
Installation
Add to your Cargo.toml:
[]
= "0.1"
Usage
Encoding
use ;
// Create header from tile bounds
let bounds = new;
let header = from_bounds;
// Create vertices (quantized to 0-32767 range)
let vertices = QuantizedVertices ;
// Triangle indices
let indices = vec!;
// Extract edge indices from vertices
let edge_indices = from_vertices;
// Create encoder
let encoder = new;
// Encode to Vec<u8>
let data = encoder.encode;
// Or encode with options (compression, extensions)
let data = encoder.encode_with_options;
// Or encode directly to a writer (e.g., file)
use File;
let file = create.unwrap;
encoder.encode_to_with_options.unwrap;
Decoding
Two flavours are available — pick based on whether you need owned Vecs
or are OK with lazy borrowed iterators.
Zero-copy view (QuantizedMeshView<'a>): borrows the input bytes and
lazily decodes zigzag-delta vertex streams and high-water-mark indices,
allocating nothing for the bulk data.
use QuantizedMeshView;
let data: & = &;
let view = parse.unwrap;
println!;
for in view.iter_u.zip
for tri in view.indices.iter..chunks
Owned mesh (DecodedMesh): convenience wrapper that handles gzip
auto-detection and materialises every section into Vecs.
use DecodedMesh;
// Decode from byte slice (auto-detects gzip)
let data: & = &;
let mesh = decode.unwrap;
// Or decode from a reader (e.g., file)
use File;
let file = open.unwrap;
let mesh = decode_from.unwrap;
println!;
println!;
println!;
With Extensions
use ;
// Encode with vertex normals
let normals: = vec!;
let options = EncodeOptions ;
let data = encoder.encode_with_options;
// Decode and access extensions
let mesh = decode.unwrap;
if let Some = mesh.extensions.normals
Coordinate Transformations
use ;
// Convert longitude/latitude/height to ECEF
let ecef = geodetic_to_ecef; // Tokyo
// Convert ECEF back to geodetic
let = ecef_to_geodetic;
Format Overview
The quantized-mesh format consists of:
- Header (88 bytes): Tile center, height range, bounding sphere, horizon occlusion point
- Vertex Data: Delta-encoded and zigzag-encoded u/v/height coordinates
- Index Data: High-water mark encoded triangle indices
- Edge Indices: Vertices on tile edges for seamless stitching
- Extensions (optional): Normals, water mask, metadata
License
MIT OR Apache-2.0