{"id":25656,"library":"greedy-mesher","title":"greedy-mesher","description":"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.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"git://github.com/mikolalysenko/greedy-mesher","tags":["javascript","greedy","mesh","compiler","voxel","geometry","ndarray"],"install":[{"cmd":"npm install greedy-mesher","lang":"bash","label":"npm"},{"cmd":"yarn add greedy-mesher","lang":"bash","label":"yarn"},{"cmd":"pnpm add greedy-mesher","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Processes ndarray data structures, also used in examples","package":"ndarray","optional":false},{"reason":"Example usage to pack nested arrays into ndarray","package":"ndarray-pack","optional":true}],"imports":[{"note":"The library is CommonJS-only; no ESM export. Use require().","wrong":"import compileMesher from 'greedy-mesher'","symbol":"default","correct":"const compileMesher = require('greedy-mesher')"},{"note":"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.","wrong":"const mesher = require('greedy-mesher')({ order: [0,1] })","symbol":"Mesher options","correct":"const mesher = compileMesher({ order: [1,0], extraArgs: 0, ... })"},{"note":"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).","wrong":"const result = mesher(array)","symbol":"Mesher call","correct":"mesher(array, arg1, arg2, ...)"}],"quickstart":{"code":"const compileMesher = require('greedy-mesher');\nconst ndarrayPack = require('ndarray-pack');\n\nconst mesher = compileMesher({\n  extraArgs: 1,\n  order: [1, 0],\n  append: function(lo_x, lo_y, hi_x, hi_y, val, result) {\n    result.push([[lo_x, lo_y], [hi_x, hi_y]]);\n  }\n});\n\nconst input = ndarrayPack([\n  [0, 2, 0, 0],\n  [0, 1, 1, 0],\n  [0, 1, 1, 0],\n  [0, 0, 0, 0]\n]);\n\nconst result = [];\nmesher(input, result);\nconsole.log(result);\n// Output:\n// [ [ [ 1, 0 ], [ 2, 1 ] ], [ [ 1, 1 ], [ 3, 3 ] ] ]","lang":"javascript","description":"Creates a custom mesher for a 2D ndarray, merging adjacent equal voxels (excluding 0) and appending rectangles."},"warnings":[{"fix":"Ensure order.length equals ndarray dimension.","message":"The order array must have length equal to the number of dimensions of the input ndarray; otherwise, the generated code will be incorrect or crash.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Design append to match the permutation given in order.","message":"The append closure receives coordinates in the order specified by 'order', not the original axis order.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set useGetter: true when passing an ndarray.","message":"If '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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"N/A","message":"No breaking changes known; minor version bumps are unlikely.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Provide an order array with length equal to the number of dimensions of the input ndarray.","cause":"Order array not provided or has wrong length.","error":"TypeError: Cannot read properties of undefined (reading 'length')"},{"fix":"Add an 'append' function to the options object.","cause":"The 'append' option is required but not provided in options.","error":"ReferenceError: append is not defined"},{"fix":"Set useGetter: true in the options when passing an ndarray.","cause":"Using an ndarray without setting useGetter: true.","error":"TypeError: array.get is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}