Toxiclibs explorations: 3D sketching app


Anyone who follows the developments around Processing, knows about the infamous toxiclibs. These are libraries for adding more and far more powerful functionalities to processing than ever before! The Toxiclibs website contains a bunch of these examples, which all demonstrate a particular part of the libraries. As the name suggests, the toxiclibs aren’t just one, but are a bunch of different libraries, most of them in the area of mesh generation.

After some googling, I found this example at GuruBlog; how to create a tentacle using processing and toxiclibs. He created a sketch that generated a 3D model of a tentacle and generated an stl file from it that was ready for 3D printing. I liked the idea of simple 3D model generation and sending it to a 3D printer right away, but why did it have to be a tentacle?

So to explore the possibilities of 3D modelling using toxiclibs, I started working on a sketch of my own. I started out with using the volumetric brush ( the same tool as the other guy used) to draw a cube, and let it rotate around a few axes.

3Dcube made using Toxiclibs

Next, I started out with creating an app that would let you draw up a complete 3D model, using the volumetric brush. This was more complicated, since it required me to map my X and Y mouse coordinates in a 3D space. After lots of sines and cosines I stuck with some sort of random navigation method, which actually is quite fun to play around with. The typical drawing I make looks like this.. So you might know a useful application for such kinds of 3D models, then please let me know!

Processing sketch running my clickBrush app


I will think about improving the navigational system and maybe even adding features as increasing and decreasing brush size, to make even more fancy drawings. I hope to gain access to a 3D printer somewhere in the near future so I can actually verify the stl files ToxciLibs creates.

Source Code

/* ------------------------
ClickBrush sketch by Pepf
22nd of January 2012

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

ToxiclibsSupport gfx;
TriangleMesh mesh;
VolumetricBrush brush;
VolumetricSpace volume;
IsoSurface surface;
float yRot=0;
float xRot=0;
PFont myFont;
float mapY, mapX,xPos,yPos,zPos;

void setup() {
  gfx = new ToxiclibsSupport(this);
  volume = new VolumetricSpaceArray( new Vec3D(600,600,600), 50, 50, 50 );
  surface = new ArrayIsoSurface( volume );
  mesh = new TriangleMesh();

  brush = new RoundBrush( volume, 50 );

  myFont = createFont("Arial", 16);

  surface.computeSurfaceMesh( mesh, .1 );

void draw() {
    //important stuff first
    xPos = mapX*cos(yRot);
    yPos = mapX*sin(yRot);
    zPos = -mapY*sin(xRot);

    translate( width/2, height/2, 0);
    rotateY( yRot);
    rotateX( xRot);
    gfx.mesh( mesh );
    text("X:" + xRot + " - Y:" + yRot, 5,20);
    text("Xpos: " + xPos +"\n"+
        "Ypos: " + yPos + "\n"+
        "Zpos: " + zPos,5,80);

void mouseClicked() {
  brush.drawAtAbsolutePos( new Vec3D(xPos,yPos,zPos),0.2);
  surface.computeSurfaceMesh( mesh, .1 );
void mouseMoved() {
 mapY = map(mouseY,0,height,-(height/2),height/2);
 mapX = map(mouseX,0,width,-(width/2),width/2);
void keyPressed() {
  if (key==CODED) {
  if (keyCode==LEFT) {
  if (keyCode==RIGHT) {
  if (keyCode==UP) {
  if (keyCode==DOWN) {
  if (key=='s') {
    mesh.saveAsSTL( sketchPath( "model.stl" ));