npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@meshinspector/meshlib

v3.2.0-85

Published

MeshLib geometry library compiled to WebAssembly (single-threaded), with the complete API generated from the C++ headers.

Readme

@meshinspector/meshlib

MeshLib geometry library compiled to WebAssembly, with the complete MeshLib API generated from the C++ headers (the same way as the Python, C#, Rust and Java bindings), as ES modules with TypeScript declarations.

This package ships the single-threaded build. The multi-threaded build is @meshinspector/meshlib-mt, with an identical API.

  • Source: https://github.com/MeshInspector/MeshLib
  • Documentation: https://meshlib.io/documentation/index.html

Requirements

  • Node.js >= 21 (>= 24 for using), or a current browser.

Install

npm install @meshinspector/meshlib

Usage

Import the package as a namespace, initialize it once (this downloads and instantiates the wasm), then the whole MeshLib API is there: the classes of the MR namespace at the top level, the nested namespaces (MeshLoad, MeshSave, MeshBuilder, ...) as namespace objects.

using requires Node.js 24+ or a current browser. On older runtimes, call .delete() instead — see Memory management.

import * as ml from '@meshinspector/meshlib';

await ml.init();

// Build a cube (side 2) from raw geometry.
const positions = new Float32Array([
  -1, -1, -1,   1, -1, -1,   1, 1, -1,   -1, 1, -1,
  -1, -1,  1,   1, -1,  1,   1, 1,  1,   -1, 1,  1,
]);
const indices = new Uint32Array([
  0, 2, 1,  0, 3, 2,  4, 5, 6,  4, 6, 7,  0, 1, 5,  0, 5, 4,
  3, 6, 2,  3, 7, 6,  0, 4, 7,  0, 7, 3,  1, 2, 6,  1, 6, 5,
]);

using coords = ml.VertCoords.fromArray(positions);
using tris = ml.Triangulation.fromArray(indices);
using mesh = ml.Mesh.fromTriangles(coords, tris);

console.log('volume =', mesh.volume()); // ~8

// Any MeshLib function: a boolean with a sphere, then the result back as typed arrays.
using sphere = ml.makeUVSphere(1.5, 32, 32);
using result = ml.boolean(mesh, sphere, ml.BooleanOperation.Intersection);
console.log('intersection volume =', result.mesh.volume());
const outPositions = result.mesh.points.toArray();                  // Float32Array, x y z per vertex
const outIndices = result.mesh.topology.getTriangulation().toArray(); // Int32Array, 3 vertex ids per triangle

The API follows the C++ one: see the C++ reference, the same classes, functions, parameters and defaults. What's different:

  • Fields are properties (settings.maxError = 0.05, mesh.topology), overloads are resolved by the argument types, std::string results are strings, Expected results are unwrapped (an error throws UnexpectedResultException), C++ exceptions throw CppException.
  • Parameters with defaults can be omitted or passed as null; std::function parameters (progress callbacks) take a plain JS function. In @meshinspector/meshlib-mt it can only run on the thread that called init(), so a callback that MeshLib calls from its worker threads aborts the module (DecimateSettings.preCollapse with subdivideParts > 1, the data of a FunctionVolume in marchingCubes()): keep subdivideParts = 1 when passing decimation callbacks, or use this package. Progress callbacks are safe.
  • The contiguous containers (VertCoords, Triangulation, std::vectors, ...) have toArray(), view(), setFromArray() and fromArray() for typed arrays.
  • Every .d.mts carries the doc comments of the C++ API, so editors show them.

Memory management

Values returned from the API (meshes, bit sets, settings, result objects, ...) hold WebAssembly memory. They are freed when the JavaScript garbage collector collects them, but it does so late and unpredictably, so free the large ones explicitly: declare them with using, or call .delete().

using mesh = ml.makeUVSphere(1, 64, 64);
// ... use mesh; it is freed at the end of this scope
const mesh = ml.makeUVSphere(1, 64, 64);
// ... use mesh
mesh.delete();

References into other objects (mesh.points, mesh.topology) don't own anything and keep their owner alive. Objects don't keep alive what they reference: a MeshPart points at its mesh (and face region), so declare those with using or .delete() them after the last use of the part, rather than passing a temporary like ml.makeCube(...).

Node.js and the browser

init() picks the Node build of the module (with access to the real file system, so MeshLoad and MeshSave work with paths) under Node.js, and the browser build everywhere else. In the browser, file functions see the module's in-memory file system (ml.ffi.M.FS); load files with fetch and pass the bytes through it.

Use from CDN

In the browser you can skip npm entirely and import the module directly:

// latest release
import * as ml from 'https://js.meshlib.io/meshlib/index.mjs';

// or pin a release — v1.2.3.456 is an example tag, not a real one
import * as ml from 'https://js.meshlib.io/[email protected]/index.mjs';

To pin, take a real tag from the releases page: it has a leading v and four components, and is not the npm version — the tag v1.2.3.456 would be npm 1.2.3-456. The unpinned index.mjs re-exports the latest pinned release, which holds the module files themselves: the bindings bundled into one index.mjs, the Emscripten glue MeshLibC2.mjs and the wasm.

Using with bundlers

The package is a few dozen ES modules plus the wasm sidecar. Vite and webpack 5 resolve the .wasm from the module and emit it as an asset, so a plain import needs no configuration. For other bundlers, import the wasm as an asset URL and hand it to the loader via locateFile:

import * as ml from '@meshinspector/meshlib';
import wasmUrl from '@meshinspector/meshlib/MeshLibC2.wasm';

await ml.init( { locateFile: () => wasmUrl } );

The options of init() go to the Emscripten module factory (locateFile, print, printErr, ...).

TypeScript

The package ships type definitions for the whole API:

import * as ml from '@meshinspector/meshlib';

await ml.init();
const mesh: ml.Mesh = ml.makeUVSphere(1, 32, 32);
const settings = new ml.DecimateSettings();
settings.maxError = 0.05;
const result: ml.DecimateResult = ml.decimateMesh(mesh, settings);
mesh.delete();

Also make sure to add "type": "module" to your package.json.

Migrating from the 3.x packages

The packages up to 3.1.x shipped a hand-written Embind module with a part of the API. That module is still published, as @meshinspector/meshlib-light: to keep the old API, switch to it, replacing meshlib with meshlib-light in the package and file names (meshlib-light.mjs, meshlib-light.wasm). This package has a different, generated API:

  • The default export (import createMeshLib, const ml = await createMeshLib()) became a namespace import and an init() call: import * as ml from '@meshinspector/meshlib'; await ml.init();.
  • On the CDN the entry point is index.mjs instead of meshlib.mjs.
  • The classes, functions and fields now follow the C++ API one to one (the same names, parameters and defaults as in the C++ reference), so the hand-written helpers of the old module have no direct counterparts: look up the C++ function instead.
  • Objects are still freed with .delete() (or using), and the typed-array conversions are toArray()/view()/fromArray().