zeux /meshoptimizer

Mesh optimization library that makes meshes smaller and faster to render

★ 8,777⑂ 751👁 132▤ 25
C++Created 2016-09-09meshoptimizer.org/
8,777
stars
+0+4+271
751
forks
132
watchers
–
prs
–
issues
25
releases
–
discussions

README

🐇 meshoptimizer    

 Purpose

When a GPU renders triangle meshes, various stages of the GPU pipeline have to process vertex and index data. The efficiency of these stages depends on the data you feed to them; this library provides algorithms to help optimize meshes for these stages, as well as algorithms to reduce the mesh complexity and storage overhead.

The library provides a C and C++ interface for all algorithms; you can use it from C/C++ or from other languages via FFI (such as P/Invoke). If you want to use this library from Rust, you should use meshopt crate. JavaScript interface for some algorithms is available through meshoptimizer.js.

Two companion projects are developed and distributed alongside the library: gltfpack, a command-line tool that automatically optimizes glTF files, and clusterlod.h, a single-header C/C++ library for continuous level of detail using clustered simplification.

 Installing

meshoptimizer is hosted on GitHub; you can download the latest release using git:


git clone -b v1.3 https://github.com/zeux/meshoptimizer.git


Alternatively you can download the .zip archive from GitHub.

The library is also available as a Linux package in several distributions (ArchLinux, Debian, FreeBSD, Nix, Ubuntu), as well as a Vcpkg port (see installation instructions) and a Conan package.

gltfpack is available as a pre-built binary on Releases page or via npm package. Native binaries are recommended since they are more efficient and support texture compression.

 Building

meshoptimizer is distributed as a C/C++ header (src/meshoptimizer.h) and a set of C++ source files (src/.cpp). To include it in your project, you can use one of two options:

 Use CMake to build the library (either as a standalone project or as part of your project)
 Add source files to your project's build system

The source files are organized in such a way that you don't need to change your build-system settings, and you only need to add the source files for the algorithms you use. They should build without warnings or special compilation options on all major compilers. If you prefer amalgamated builds, you can also concatenate the source files into a single .cpp file and build that instead.

To use meshoptimizer functions, simply include the header meshoptimizer.h; the library source is C++, but the header is C-compatible.

 Core pipeline

When optimizing a mesh, to maximize rendering efficiency you should typically feed it through a set of optimizations (the order is important!):

1. Indexing
2. Vertex cache optimization
3. (optional) Overdraw optimization
4. Vertex fetch optimization
5. Vertex quantization
6. Index filtering
7. (optional) Shadow indexing

 Indexing

Most algorithms in this library assume that a mesh has a vertex buffer and an index buffer. For algorithms to work well and also for GPU to render your mesh efficiently, the vertex buffer has to have no redundant vertices; you can generate an index buffer from an unindexed vertex buffer or 

Snapshot: 2026-11-04T14:00:00Z · Data license Apache-2.0 · JSON