Favicon of meshoptimizer

meshoptimizer

meshoptimizer is a C/C++ library that reduces mesh triangle count, improves GPU cache locality, and compresses vertex and index buffers.

meshoptimizer website screenshot
meshoptimizer GitHub repository preview

meshoptimizer is a C/C++ library of algorithms that make triangle meshes smaller and faster to render on a GPU. When a GPU processes vertex and index data, the efficiency of each pipeline stage depends heavily on how that data is organized; meshoptimizer provides algorithms to reorder and compress mesh data for those stages, plus algorithms to reduce triangle count and overall storage overhead. The library exposes a C-compatible header (meshoptimizer.h) with C++ source files, and is also usable from Rust via the meshopt crate or from JavaScript via the meshoptimizer.js npm package.

Key features

  • Vertex cache optimization: meshopt_optimizeVertexCache reorders triangles for GPU post-vertex-shader cache locality, with meshopt_optimizeVertexCacheFifo as a roughly 2x faster alternative tuned for fixed-size FIFO caches.
  • Overdraw and vertex fetch optimization: reduces pixel shader overdraw across viewing directions and reorders vertex buffer memory layout to cut cache misses during rendering.
  • Mesh simplification: meshopt_simplify reduces triangle count while tracking a normalized deviation error against a target, and meshopt_simplifySloppy collapses topology-independent detail for more aggressive LODs.
  • Meshlet and cluster generation: meshopt_buildMeshlets, meshopt_buildMeshletsSpatial, and cluster partitioning build GPU mesh-shader-ready clusters for both rasterization and ray tracing, including NVIDIA cluster acceleration structures.
  • Vertex and index compression: lossless meshopt_encodeVertexBuffer / meshopt_encodeIndexBuffer codecs shrink buffers for storage or transmission, and are the basis of the glTF EXT_meshopt_compression extension.
  • Vertex filters: octahedral, quaternion, exponential, and color filters compress normals, tangents, rotations, and RGBA colors ahead of encoding, decoding at 5-10 GB/s on modern desktop CPUs.
  • Point cloud clustering: meshopt_spatialClusterPoints splits point clouds into fixed-size spatial clusters for parallel processing or mesh/compute shader rendering.

How it works

meshoptimizer is applied as a pipeline where order matters: indexing (deduplicating vertices into a vertex and index buffer), vertex cache optimization, optional overdraw optimization, vertex fetch optimization, vertex quantization, index filtering to drop degenerate or duplicate triangles, and optional shadow indexing for depth-only passes. Simplification and meshlet generation typically run after this core pipeline, on already-indexed data. Every function operates on plain vertex/index buffers, so the library has no dependency on any particular renderer or math library.

Tech stack

The library is distributed as src/meshoptimizer.h plus src/*.cpp, buildable with CMake or by adding the source files directly to an existing build system; only the algorithms you call need to be compiled in. It ships as a package for ArchLinux, Debian, FreeBSD, Nix, and Ubuntu, and is available through vcpkg and Conan. The companion gltfpack command-line tool automatically optimizes glTF files and is distributed as a prebuilt binary or npm package, while clusterlod.h provides a single-header implementation of continuous level of detail using clustered simplification.

Categories:

Tags:

Frequently asked questions

Share:

Stars
8.1K
Forks
709
Last commit
21 hours ago
Repository age
10 years
License
MIT
Self-hosted
No
Activity score
77/100
View Repository
Ad
Favicon

 

  
 

Similar to meshoptimizer

Favicon

 

  
 
Favicon

 

  
 
Favicon