meshoptimizer, the mesh optimization library, through C++23 modules.
English · 简体中文 · Upstream · Releases · mcpp · Index
The upstream API is unchanged: every meshopt_* function, struct, enum and
enumerator of <meshoptimizer.h> is the upstream global, the header's C++
overloads over index types included (unsigned short indices work as they do
with the header). The whole library — indexing, vertex cache / overdraw /
vertex fetch optimization, simplification, meshlets, spatial ordering, the
vertex, index and meshlet codecs — is vendored byte for byte from the 1.3
release and built with the package; nothing else is linked.
The library is built with -ffp-contract=off and without fast math, so the
same input gives the same output bit for bit on every platform: with the
platform's own default arm64 fuses a multiply and an add into one rounding
and the meshlets of a scattered 48 × 48 sheet differ from x86-64's (from
1.3.1; 1.3 kept the platform's default).
import mcpplibs.mwrap.meshoptimizer;: the whole API (118 names: 9 types, 20 enumerators, 89 functions), re-exporting the one belowimport mcpplibs.mwrap.meshoptimizer.macros;:MESHOPTIMIZER_VERSIONinmcpplibs::mwrap::meshoptimizer::macros
More Modules API -> upstream's README, which documents every function
mcpp new lod --template mcpplibs.mwrap.meshoptimizer@1.3.1
cd lod
mcpp runThe default template indexes a grid of quads, orders it for the vertex cache and simplifies it to a tenth of its triangles.
[dependencies]
mcpplibs.mwrap.meshoptimizer = "1.3.1"import std;
import mcpplibs.mwrap.meshoptimizer;
int main() {
std::vector<float> positions = /* x y z … */ {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0};
std::vector<unsigned int> indices{0, 1, 2, 0, 2, 3};
meshopt_optimizeVertexCache(indices.data(), indices.data(), indices.size(), positions.size() / 3);
std::vector<unsigned int> fewer(indices.size());
const std::size_t kept = meshopt_simplify(fewer.data(), indices.data(), indices.size(), positions.data(), positions.size() / 3, 3 * sizeof(float), 3, 0.05f);
std::println("{} of {} indices kept", kept, indices.size());
}A named module cannot export a macro. MESHOPTIMIZER_VERSION (1030 for 1.3) is
inline constexpr int under its original name:
namespace macros = mcpplibs::mwrap::meshoptimizer::macros;
static_assert(macros::MESHOPTIMIZER_VERSION >= 1030);The header's other macros (MESHOPTIMIZER_API, MESHOPTIMIZER_EXPERIMENTAL,
MESHOPTIMIZER_ALLOC_CALLCONV) decorate its own declarations; a consumer does
not spell them. A translation unit that also includes <meshoptimizer.h> (add
upstream/meshoptimizer/src to its include path) sees the same entities; while
the header's macro is defined it expands inside the qualified name too
(tests/header_mix_test.cpp shows the order and push_macro).
- Wrapped: the library (
src/), every public name.meshopt_IndexAdapter, the header's helper for its own templates, is not exported. - The functions upstream marks experimental (
MESHOPTIMIZER_EXPERIMENTAL) are exported as they are; their signatures may change with upstream. - Not here: gltfpack, the JavaScript and Rust bindings, the demo.
- The custom allocator (
meshopt_setAllocator) is process-wide, as upstream's.
mcpp test: indexing, vertex cache order, simplification, meshlets and their bounds, both codecs' round trips, the short-index overloads, header mixing, the macro mapping.python3 tools/check_exports.py:src/meshoptimizer.cppmis exactly whattools/surface.pyderives from the header; nomeshopt_*name of the header is left out.python3 tools/test_template.py:mcpp newfrom an installed copy, a strict build, and a run of the generated project.- CI: Linux (GCC 16, LLVM 23), macOS and Windows (LLVM 23).
The wrapper is Apache-2.0 (mcpp-community). meshoptimizer is MIT, © Arseny
Kapoulkine; its README and license are kept in upstream/meshoptimizer/ and
deployed with a program's licenses. Provenance: upstream/documents.json.