Image To STL using toxiclibs

edited June 2015 in Library Questions

Hi, I already have been working with volume/isosurface classes but I can't figure out why this code does not work. the image is black over white. any advice will be apreciated. kind regards. ! dx

import toxi.processing.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.volume.*;


PImage image;

Vec3D worldSize;
VolumetricSpace volume;
VolumetricBrush brush;
TriangleMesh mesh;
IsoSurface surface; 
ToxiclibsSupport gfx;

float th = 0.1;

void setup() {
  size(800, 600, P3D);
  gfx = new ToxiclibsSupport(this);

  image = loadImage("051-black.png");

  worldSize = new Vec3D(image.width, image.height, 2);
  volume = new VolumetricSpaceArray(worldSize, image.width, image.height, 2);
  brush = new BoxBrush(volume,0.05);

  for (int y = 0; y < image.height; y ++) {
    for (int x = 0; x < image.width; x ++) {
      if (0 == (image.pixels[y * image.width + x] & 0xff)) {
        for (int z = 0; z < 2; z++) {
          Vec3D v = new Vec3D(x, y, z);
          brush.drawAtGridPos(x,y,z, 0.5f);
        }
      }
    }
  }

  volume.closeSides();
  surface = new ArrayIsoSurface(volume);
  mesh = new TriangleMesh();
}

void draw() {  
  background(127);  
  fill(255);
  gfx.mesh(mesh);
}

void computeMesh() {
  surface.reset();
  surface.computeSurfaceMesh(mesh, th); 
  println("th: " + th + " faces: " + mesh.getNumFaces());
}

void keyPressed() {
  if (key == ' ') {
    computeMesh();
  }

  if (key == 'e') {
    mesh.saveAsSTL(sketchPath("test.stl"), true);
    exit();
  }
}

Answers

  • Maybe because you're not calling image.loadPixels() before accessing the pixels?

  • No. that was because of VolumetricSpaceArray MUST be at least 3 voxels depth in the Z axis. I already ask toxi on the issue tracker but I think he is not working on this lib anymore. thanks for answer.

Sign In or Register to comment.