@treble-tech/mmg-js
v0.1.1
Published
MMG (mmgs surface remesher) compiled to WebAssembly with a small JavaScript API. Licensed under the GNU LGPL-3.0, the same license as MMG.
Readme
mmg-js
MMG's surface remesher (mmgs) compiled to
WebAssembly, plus a small JavaScript API for adaptive surface remeshing in the
browser, in web workers, or in Node.
import { createRemesher } from '@treble-tech/mmg-js';
const remesher = await createRemesher(); // or { wasmUrl } / { moduleOverrides: { wasmBinary } }
console.log(remesher.version); // "5.8.0"
const out = remesher.remesh(
{ vertices, triangles, triangleRefs }, // Float64Array / Uint32Array / Uint32Array
{
hmin: 0.05, hmax: 0.5, hausd: 0.01, hgrad: 1.3,
ar: 45, angle: true,
localParams: [{ ref: 2, hmin: 0.01, hmax: 0.1, hausd: 0.001 }],
sizeMap: null, // optional per-vertex target edge length
},
);
// out = { vertices, triangles, triangleRefs, edges, lowFailure }Triangle references are inherited by every child triangle and interfaces
between references are preserved, so per-region refinement survives the remesh.
@treble-tech/mmg-js/medit exposes the Medit .mesh/.sol codec and an OBJ
parser used under the hood.
Documentation: docs/USAGE.md (installation, loading the wasm with bundlers/workers, mesh format, every parameter, error handling) and docs/UPDATING_MMG.md (bumping the MMG or Emscripten version).
Package layout
| Path | What |
| --- | --- |
| src/js/ | JavaScript API (index.js) and Medit/OBJ codec (medit.js) |
| src/c/jsmmg.c | C shim exporting jsmmg_remesh, jsmmg_add_local_param, jsmmg_clear_local_params, jsmmg_version on top of libmmgs |
| third_party/mmg | Unmodified MMG sources, git submodule pinned to v5.8.0 |
| dist/mmgs.wasm, dist/mmgs.js | Compiled MMG + shim and its Emscripten loader (committed, reproducible via build/build.sh) |
| build/build.sh | Reproducible build recipe |
| docs/ | Usage guide and MMG/Emscripten upgrade procedure |
Everything in this repository is licensed under the GNU LGPL-3.0 (see below).
Building from source
git clone --recursive https://gitlab.com/treble-public/mmg-js.git
cd mmg-js
build/build.sh # uses the emscripten/emsdk:4.0.15 Docker image
npm testSet JSMMG_NO_DOCKER=1 to use an emcc/emcmake already on your PATH
(tested with emsdk 4.0.15). The script builds libmmgs.a with CMake
(-DBUILD=MMGS, Scotch/VTK/Elas off) and links it with src/c/jsmmg.c into an
ES-module loader (dist/mmgs.js) and a separate dist/mmgs.wasm.
The build is byte-reproducible for emsdk 4.0.15 regardless of checkout path
(-ffile-prefix-map): CI rebuilds dist/ and fails if it differs from what is
committed.
npm test runs the Node test suite; npm run test:ci (Node >= 22) additionally
writes a JUnit report and lcov coverage for src/js to coverage/, which CI
publishes as test and coverage reports.
Releasing
Pushing a vX.Y.Z tag that matches version in package.json runs the
publish-npm CI job after build and tests pass. It publishes
@treble-tech/mmg-js to npmjs.com with
provenance, using
the NPM_TOKEN CI/CD variable.
The job also requests a GitLab OIDC token (NPM_ID_TOKEN), which npm prefers
over NPM_TOKEN once a
trusted publisher is configured
for the package on npmjs.com (GitLab CI/CD, namespace treble-public,
project mmg-js, file .gitlab-ci.yml). After that, NPM_TOKEN can be
deleted.
npm version 0.2.0 --no-git-tag-version # bump package.json, then merge to main
git tag v0.2.0 && git push origin v0.2.0 # tag mainLicensing
The whole package -- MMG (third_party/mmg), the C shim, the JavaScript API,
the build recipe, the tests and the compiled dist/mmgs.wasm / dist/mmgs.js
-- is distributed under the GNU Lesser General Public License v3.0
(COPYING.LESSER, which supplements the GPL-3.0 text in COPYING). SPDX:
LGPL-3.0-only. Using a single license for the repository keeps the
obligations identical for every file and avoids any question about which
terms apply to the combined WebAssembly binary.
The LGPL applies to this library; applications that merely use it (via
createRemesher() and the separate mmgs.wasm file) are not required to be
open source (LGPL-3.0 §4).
When you redistribute an application that uses this package, keep mmgs.wasm
as a separate file that your users can replace (do not inline it into your own
bundle), ship COPYING and COPYING.LESSER alongside it, and point users to
this repository as the corresponding source (LGPL-3.0 §4). See
THIRD_PARTY_NOTICES.md.
