Introducing stljs, a fast library to read, write, and render STL files

a coffee cup STL

Render STL files

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')

  , (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.

Tagged with: , , ,
Posted in announcement, code
5 comments on “Introducing stljs, a fast library to read, write, and render STL files
  1. […] Update: We’ve now wrapped this up into a library called stljs, which lets you read, write, and render STL files without having to do it by hand.  […]

  2. […] emails, calculating a score, updating information from a remote source, or in the case of Cubehero, rendering 3D models as images (among other […]

  3. Very nice!
    To use the povray, it only has to be installed and executable as ‘povray’ ?

  4. pervez says:

    I have installed pov-ray on ubuntu system and follow all the steps which is shown on your blog, but i can’t understand where should I put that code block which is starts from ‘stljs = require(‘stljs’)…..’ and how to run it, I tried to put that code on index.js and then run node index.js but it didn’t show any result. Please reply me asap…. thanks.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: