MeshLib is available for JavaScript as the geometry library compiled to WebAssembly. It runs both in Node.js and in the browser, and is published to npm as two packages that share an identical API: @meshinspector/meshlib (single-threaded) and @meshinspector/meshlib-mt (multi-threaded).
Before installing MeshLib SDK for JavaScript, ensure you have the following:
MeshLib runs in Node.js or in a modern browser.
You can use any JavaScript- or TypeScript-compatible editor, such as Visual Studio Code, WebStorm, or any IDE you prefer.
MeshLib ships in two flavors with an identical API:
The examples below use @meshinspector/meshlib. To use the multi-threaded build instead, install @meshinspector/meshlib-mt and change the import specifier; nothing else changes.
Install the package from npm:
In the browser you can skip npm entirely and import the module directly:
The multi-threaded package @meshinspector/meshlib-mt relies on SharedArrayBuffer, which browsers only enable on cross-origin isolated pages. The server that serves the page loading the module must send these headers:
Without them SharedArrayBuffer is unavailable and the module fails to initialize; use the single-threaded @meshinspector/meshlib package in that case.
The default export is an async factory. Await it once to get the module instance, then call MeshLib functions on it:
The package ships type definitions, so createMeshLib and the whole module API are typed with no extra setup:
Values returned from the API (meshes, bit sets, settings, result objects, and so on) hold WebAssembly memory that the JavaScript garbage collector does not reclaim, so each one must be freed explicitly.
The preferred way is JavaScript's explicit resource management: declare a handle with using and it is freed automatically when its scope ends, even if an exception is thrown.
When the number of handles is dynamic (for example built in a loop), collect them in a DisposableStack, which frees everything it holds, in reverse order, at the end of the scope:
using and DisposableStack are part of JavaScript's Explicit Resource Management, available in Node.js 24+ and current browsers. On older runtimes and browsers, call .delete() on each object when you are done instead:
You can check how MeshLib works in a browser environment with live interactive examples: https://demo.meshlib.io/
After installing MeshLib, a great way to start exploring its capabilities is through the code samples. Each of the following example pages includes a JavaScript tab:
Browse the full set on the MeshLib Code Samples page.