What is @mapbox/martini?
@mapbox/martini is a JavaScript library for generating adaptive meshes for terrain rendering. It is designed to work with digital elevation models (DEMs) and can create efficient, level-of-detail (LOD) meshes that are suitable for real-time rendering in 3D applications.
What are @mapbox/martini's main functionalities?
Generating a Terrain Mesh
This feature allows you to generate a terrain mesh from a digital elevation model (DEM). The code sample demonstrates how to create a Martini instance, initialize a terrain tile with elevation data, and generate a mesh with a specified error threshold.
const Martini = require('@mapbox/martini');
const DEM = new Float32Array([/* elevation data */]);
const tileSize = 256;
const martini = new Martini(tileSize + 1);
const terrain = martini.createTile(DEM);
const mesh = terrain.getMesh(10); // 10 is the error threshold
console.log(mesh);
Getting Terrain Errors
This feature allows you to retrieve the error values for each vertex in the terrain mesh. The code sample shows how to create a Martini instance, initialize a terrain tile with elevation data, and get the error values.
const Martini = require('@mapbox/martini');
const DEM = new Float32Array([/* elevation data */]);
const tileSize = 256;
const martini = new Martini(tileSize + 1);
const terrain = martini.createTile(DEM);
const errors = terrain.getErrors();
console.log(errors);
Simplifying a Mesh
This feature allows you to simplify an existing terrain mesh by increasing the error threshold. The code sample demonstrates how to generate an initial mesh and then create a simplified version of it by using a higher error threshold.
const Martini = require('@mapbox/martini');
const DEM = new Float32Array([/* elevation data */]);
const tileSize = 256;
const martini = new Martini(tileSize + 1);
const terrain = martini.createTile(DEM);
const mesh = terrain.getMesh(10); // initial mesh
const simplifiedMesh = terrain.getMesh(20); // simplified mesh with higher error threshold
console.log(simplifiedMesh);
Other packages similar to @mapbox/martini
three-geo
three-geo is a library for generating 3D terrain meshes using Three.js and Mapbox. It provides higher-level abstractions for working with terrain data and integrates directly with Three.js for rendering. Compared to @mapbox/martini, three-geo offers more built-in functionality for rendering and visualization but may be less flexible for custom mesh generation.
MARTINI

MARTINI stands for Mapbox's Awesome Right-Triangulated Irregular Networks, Improved.
It's an experimental JavaScript library for real-time terrain mesh generation from height data. Given a (2k+1) × (2k+1) terrain grid, it generates a hierarchy of triangular meshes of varying level of detail in milliseconds. A work in progress.
See the algorithm in action and read more about how it works in this interactive Observable notebook.
Based on the paper "Right-Triangulated Irregular Networks" by Will Evans et. al. (1997).

Example
const martini = new Martini(257);
const tile = martini.createTile(terrain);
const mesh = tile.getMesh(10);
Install
npm install @mapbox/martini