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). To see it running in the browser before you install anything, open demo.meshlib.io — the live demo is built on the multi-threaded package.
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; in Node.js nothing else changes. In the browser the page must additionally be cross-origin isolated.
Install the package from npm and enable ES module support in your project:
In the browser you can skip npm entirely and import the module directly:
The multi-threaded build cannot be imported straight from the CDN, because the browser refuses to run a worker script from another origin, so pass the fetched module to the factory as a Blob and its worker pool starts from a same-origin blob: URL:
In the browser the multi-threaded build additionally requires the page to be cross-origin isolated.
Vite 8 and webpack 5 resolve meshlib.wasm from the module and emit it as an asset, so a plain import needs no configuration. For other bundlers, such as esbuild or Rollup, import the wasm as an asset URL and hand it to the loader via locateFile:
The bundler must treat .wasm files as static assets, so that the import resolves to the URL of the emitted file; the option is usually called an asset or file loader. For example:
MeshLib is a WebAssembly build of the full geometry library, so a browser downloads roughly 11 MB of wasm, about 3 MB gzipped over the wire, before the first geometry call. @meshinspector/meshlib-mt is the same order of magnitude.
Two consequences for a browser application:
If the geometry is not needed on first paint, load the module lazily instead of at the top level, so the wasm download does not block startup:
This section applies to browsers only. In Node.js the multi-threaded build needs no headers, flags, or extra configuration.
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 crossOriginIsolated is false, SharedArrayBuffer is unavailable, and createMeshLib() never resolves.
For a Vite dev server, set the headers in vite.config.js (whatever hosts the production build must send them too; vite-plugin-cross-origin-isolation can stamp them for vite preview):
Where you cannot set response headers at all — GitHub Pages and similar static hosting — the usual workaround is a coi-serviceworker-style shim: a service worker that re-serves the page with the two headers and reloads it once. MeshLib's own interactive demo is hosted exactly this way.
So on a page that is not cross-origin isolated you have three options: send the headers, install the service-worker shim, or use the single-threaded @meshinspector/meshlib package, which has no such requirement.
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 minimal 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.