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 - Gzip compression/decompression (auto-detected)
- Extensions support:
- Oct-encoded vertex normals
- Water mask
- 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
use QuantizedMeshDecoder;
// 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;
// Access decoded data
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