Created
September 7, 2014 06:20
-
-
Save anonymous/f2df5cb722801163b8e3 to your computer and use it in GitHub Desktop.
197.117 Toxiclibs example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import Toxiclibs libraries | |
import toxi.geom.*; | |
import toxi.geom.mesh.*; | |
import toxi.volume.*; | |
import toxi.processing.*; | |
ToxiclibsSupport gfx; | |
TriangleMesh mesh; | |
VolumetricSpace volume; | |
void setup() { | |
size(500,500,P3D); | |
gfx = new ToxiclibsSupport(this); | |
//This line creates the 3d space that you can operate in. | |
//The first parameter: new Vec3D(200,200,200) sets the area to be 200x200x200 units | |
//The next three parameters: 50,50,50 set the resolution of the 3d space. | |
volume = new VolumetricSpaceArray(new Vec3D(200,200,200), 50,50,50); | |
IsoSurface surface = new ArrayIsoSurface(volume); | |
mesh = new TriangleMesh(); | |
/* | |
// Draw a single cube | |
VolumetricBrush brush = new BoxBrush(volume, 25.0); | |
brush.drawAtAbsolutePos( new Vec3D(0,0,0), 1 ); | |
*/ | |
/* | |
// Draw a sphere | |
VolumetricBrush brush = new RoundBrush(volume, 25.0); | |
brush.drawAtAbsolutePos( new Vec3D(0,0,0), 1 ); | |
*/ | |
// Draw a 10x10x10 cube of cubes | |
VolumetricBrush brush = new BoxBrush(volume, 5.0); | |
for(int i = 0; i < 10; i++){ | |
for(int j = 0; j < 10; j++){ | |
for(int k = 0; k < 10; k++){ | |
brush.drawAtAbsolutePos(new Vec3D((i*10)-50 +random(3), (j*10)-50+random(3), (k*10)-50+random(3)), 1 ); | |
} | |
} | |
} | |
// Below code handles the mesh computation | |
volume.closeSides(); | |
surface.reset(); | |
surface.computeSurfaceMesh(mesh, 0.5); // Second parameter is surface iso value, aka: blobbiness.Try values between 0 - 1. | |
} | |
void draw() { | |
background(0); | |
lights(); | |
translate( width/2, height/2, 0); | |
rotateY( frameCount * 0.005 ); // Rotate the mesh so we can see it | |
scale(2); | |
fill(118,255,74); // Colour the mesh (only used in procepssing) | |
noStroke(); | |
beginShape(TRIANGLES); | |
gfx.mesh( mesh ); | |
endShape(); | |
} | |
// Save when 'p' key is pressed. Goes into sketch folder. | |
void keyPressed() { | |
if (key=='p') { | |
mesh.saveAsSTL( sketchPath( "toxic_output.stl" )); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment