OpenSCAD Polyhedron Tools
npm install openscad-poly-tools

This library is still in development (pre 1.0.0) and may change significantly between minor versions.
Once it reaches 1.0.0 all breaking changes will use a major revision number, as dictated by semver.
convert.html. As of 0.10.0, the library supports converting STL to OpenSCAD on NodeJS.
#### load(filename)
Load an STL as an object for manipulation, using the stl package.
Returns a Promise.
``javascript`
myModelPromise = osPoly.load('./test.stl');
// Promise chaining example
osPoly.load('./example.stl')
.then(model => osPoly.center(model, 'x'));
#### format(model, [moduleIndex])
Convert an object into a string equivalent of an OpenSCAD document as a step before saving.
Supports an optional index to allow multiple objects to save into a file.
`javascript`
osPoly.format(myModel);
#### save(filename, model)
Save the object as an OpenSCAD file. Currently supports only a single object.
Returns a Promise.
`javascript`
savePromise = osPoly.save('./example.scad', myModel);
#### process(stlFile, scadFile)
Import an STL file, simplify it, and export an OpenSCAD document.
This provides my most common workflow as a single command.
`javascript`
osPoly.process('./example.stl', './example.scad');
// Chaining example
osPoly.process('./example.stl', './example.scad')
.then(() => console.log('Success'), e => console.log(e));
#### reportDuplicatePercentage(model)
Give the percentage of duplicates in the array of points. No changes are made.
`javascript`
osPoly.reportDuplicatePercentage(myModel);
#### simplify(model)
Eliminate duplicate points in the model's points array and re-map the indices in the faces to match.
`javascript`
osPoly.simplify(myModel);
`javascript`
osPoly.center(myModel, 'x')
#### moveToOrigin(model, axis, [moveTop])
Move the lowest or highest point on an axis to the origin.
`javascript`
osPoly.moveToOrigin(myModel, 'z')
#### translate(model, vector)
Shift the model along one or more axes.
`javascript`
osPoly.translate(myModel, { x: 10, y: -2, z: 0.25 });
#### filterForMatch(model, predicate)
Get only the faces of the model which have points matching the predicate.
NOTE: This is not the same as a Boolean operation in OpenSCAD. Any faces that have points eliminated by the predicate will be removed, not modified.
`javascript`
osPoly.filterForMatch(myModel, (point) => point.x > 0);
#### removeDeadPoints(model)
Eliminate any dead points and correct the indices of the faces to match.
`javascript`
osPoly.removeDeadPoints(myModel);
Nearly all functions take a model, which is an object with arrays of points and faces.
`javascript`
myModel = {
points: [],
faces: [],
};
Where an axis is specified, the library should accept the string 'x', 'y', or 'z'; or their0
index , 1, or 2`, respectively.
The original objects passed in are not modified.
In some cases, the returned points and faces may reference the same original arrays.
This library is developed on Node 9.x, and is tested against 8.x.
It uses functionality not available on previous releases.
If you would like to use it with an earlier version of NodeJS, please open an issue on GitHub.