Ever want to parse STL files, but couldn’t find a fast library to read both ASCII and Binary STL files? Or you have STL files, but you want to convert it to an image, so you don’t have to load a 3D model on your webpage?

Today, we’re happy to announce Cubehero’s first open source library, stljs, a fast library for reading, writing, and rendering STL files. In the last post, we wrote about how to convert and render STL to images manually, but now, you can have stljs to do it for you.

The library allows you to read both binary and ascii STL files. It currently only writes to ascii files (but that will be added later). It is currently only for node.js, but eventually, it should be available for the browser.

The methods to read the STL files also have a progress callback, so you can process the polygons as they’re being read.

stljs = require('stljs') stljs.readFile('teapot.stl' , (err, solid, name) -> # finished parsing can now do stuff with solid , (err, polygon, name) -> # gets called on as each polygon is parsed )

But in addition, you can render STL files as PNG images, but the method depends on pov-ray being installed on your system. Then, you will be able to convert it like so:

stljs = require('stljs') stljs.imageify('teapot.stl', { width: 200, height: 100, dst: 'teapot.png' } , (err, povOutput, name) -> # done with converting the image , (err, povPolygon, name) -> # called on each polygon is processed )

If you have contributions, feel free to fork and send pull requests. Enjoy!

Host your 3D printable models on Cubehero. Have a conversation with me on twitter.