Registry / data / greedy-mesher

greedy-mesher

JSON →
library1.0.3jsnpmunverified

A flexible system for generating greedy meshes of ndarrays, version 1.0.3. It compiles a custom mesher function based on provided options like order, skip, merge, and append closures. Unlike hardcoded greedy meshing algorithms, this package allows full control over traversal order and voxel merging logic. The library is optimized for ndarray data structures and is commonly used in voxel-based graphics and geometry processing. The release cadence is archival; no updates since 2013. Key differentiators: runtime code generation, customizable merging criteria, and support for arbitrary dimensions.

npm install greedy-mesher
INSTALL
IMPORT
SIG · GREEDY-MESHER
G
greedy-mesher
datajavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const compileMesher = require('greedy-mesher')
import compileMesher from 'greedy-mesher'
The library is CommonJS-only; no ESM export. Use require().
Mesher options
const mesher = compileMesher({ order: [1,0], extraArgs: 0, ... })
const mesher = require('greedy-mesher')({ order: [0,1] })
The order array dimensionally matches the ndarray's shape; must have length equal to number of dimensions. Extra args default to 0 if not specified.
Mesher call
mesher(array, arg1, arg2, ...)
const result = mesher(array)
The mesher function appends to an array passed as the last argument? Actually, signature: let result = mesher(array, arg1, arg2, ...). The returned result is the last argument's value? Final arg is the results array. Example: mesher(array, result).

Creates a custom mesher for a 2D ndarray, merging adjacent equal voxels (excluding 0) and appending rectangles.

const compileMesher = require('greedy-mesher'); const ndarrayPack = require('ndarray-pack'); const mesher = compileMesher({ extraArgs: 1, order: [1, 0], append: function(lo_x, lo_y, hi_x, hi_y, val, result) { result.push([[lo_x, lo_y], [hi_x, hi_y]]); } }); const input = ndarrayPack([ [0, 2, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0] ]); const result = []; mesher(input, result); console.log(result); // Output: // [ [ [ 1, 0 ], [ 2, 1 ] ], [ [ 1, 1 ], [ 3, 3 ] ] ]
Debug
Known issues
gotchaThe order array must have length equal to the number of dimensions of the input ndarray; otherwise, the generated code will be incorrect or crash.
fix
Ensure order.length equals ndarray dimension.
affects: >=1.0.0
gotchaThe append closure receives coordinates in the order specified by 'order', not the original axis order.
fix
Design append to match the permutation given in order.
affects: >=1.0.0
gotchaIf 'useGetter' is not set, the mesher assumes the array is a native typed array; for ndarrays, set useGetter: true or the generated code will fail.
fix
Set useGetter: true when passing an ndarray.
affects: >=1.0.0
breakingNo breaking changes known; minor version bumps are unlikely.
fix
N/A
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'length')
Order array not provided or has wrong length.
fix
Provide an order array with length equal to the number of dimensions of the input ndarray.
ReferenceError: append is not defined
The 'append' option is required but not provided in options.
fix
Add an 'append' function to the options object.
TypeError: array.get is not a function
Using an ndarray without setting useGetter: true.
fix
Set useGetter: true in the options when passing an ndarray.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
ndarrayrequiredProcesses ndarray data structures, also used in examples
ndarray-packoptionalExample usage to pack nested arrays into ndarray
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
greedy-mesher — npm install greedy-mesher · libregistry