Terrain module · writer API
QuantizedMeshWriter
Encode loaders.gl mesh or Mesh Arrow table data as compact quantized mesh terrain tiles for tile-based terrain delivery.
What it writes
Put a terrain surface into a tile-ready encoding.
QuantizedMeshWriter normalizes mesh input, quantizes positions within bounds, and writes the core terrain header, vertices, indices, and edge structures expected by quantized mesh readers.
Input
Mesh or Mesh Arrow table
Output
Binary `.terrain` quantized mesh
Geometry
Triangle-list positions and indices
Control
Bounds and quantization options
Detailed guide
QuantizedMeshWriter reference
The sections below document usage, input normalization, output structure, and writer options.
The QuantizedMeshWriter writes Mesh or Mesh Arrow table terrain data as quantized mesh binary data.
| Writer | Characteristic |
|---|---|
| File Format | Quantized Mesh |
| Data Format | Mesh Arrow table, Mesh |
| File Extension | .terrain |
| File Type | Binary |
| MIME Type | application/vnd.quantized-mesh |
| Supported APIs | encode, encodeSync |
Usage
import {encode} from '@loaders.gl/core';
import type {Mesh, MeshArrowTable} from '@loaders.gl/core/schema';
import {QuantizedMeshWriter} from '@loaders.gl/raster/terrain';
declare const terrainMesh: Mesh | MeshArrowTable;
const arrayBuffer = await encode(terrainMesh, QuantizedMeshWriter, {
'quantized-mesh': {
bounds: [0, 0, 1, 1]
}
});
Data Format
QuantizedMeshWriter accepts Mesh Arrow tables and legacy Mesh objects. Legacy Mesh input is normalized through the Mesh Arrow table conversion path before quantized mesh binary data is encoded.
The writer requires triangle-list mesh data with a POSITION attribute. It writes the quantized mesh core header, vertex arrays, triangle indices, and empty edge-index lists.
Options
| Option | Type | Default | Description |
|---|---|---|---|
quantized-mesh.bounds | [number, number, number, number] | Mesh XY bounding box | Bounds used to map x/y positions to quantized u/v coordinates, in [minX, minY, maxX, maxY]. |