Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Converts an ndarray of voxels into an ascii STL file suitable for 3D printing or other 3D applications.

You can also smooth the voxel volumes using various isosurface smoothing algorithms such as marching cubes or surface nets.

STL files don't support color data, sorry.


npm install ndarray-stl

How it works

This will work with any voxel data, but I built it to work with another app I made called Voxel Builder. One of the users of named burgzt took a 3D Mario designed by Mikola Lysenko and made a copy in the builder app:


When you export your creation from Voxel Builder you get a PNG file with the voxel data magically encoded inside. That means you can upload the PNG photo of your creation into any app that knows how to extract it (such as the WebGl powered voxel-critter) and you can then fully view edit your 3D in that app.

For example, this image has encoded voxel data hidden inside:


In the ndarray-stl demo I load the mario image (or any PNG url, you can specify one in the address bar), read the voxel data from the PNG and then generate an STL file from the voxels using ndarray-stl. You can also generate a smoothed voxel model. STL files can then be loaded into programs like MakerWare and 3D printed!


The above shows three STL files loaded into MakerWare: unsmoothed, smoothed with surface nets and smoothed with marching cubes.


Here are the 3 variations of Mario printed out by @vladikoff at the Mozilla San Francisco office. You can view more photos from his print here. Thanks, Vlad!

Mikola Lysenko, the original designer of the 3D mario, has a Shapeways store where you can order a full color mario printed in sandstone and have it shipped to you.


Mikola also wrote a post about the process of creating the 3D mario based on 2D sprites.

At this point in time there are over 400 creations that have been made with Voxel Builder. Any of them can be loaded into the ndarray-stl demo. Here are some good ones:


see demo.js for example usage

var stl = require('ndarray-stl')

require the module

stl(voxels, options)

voxels has to be a 3d ndarray. returns an ascii stl string.

options an object with these defaults:

  "smooth": false,
  "method": "surfaceNets",
  "faceFormat": false

You can set smooth to true and pick a smoothing method, available methods are surfaceNets, marchingCubes or marchingTetrahedra.

To change the face format that gets serialized into the STL you can specify a faceFormat, e.g.:

function (f) {
  var backwardsWindedFaceVertices = [f[2], f[1], f[0]]
  return rotateVertices(v) {
    return [v[0], -v[2], v[1]]