As a part of my master thesis on MSc Adaptive Architecture and Computation, a library PGCode3D for Processing was created that analyses 3d geometry and outputs G-Code file for a 2,5 or 3 axis CNC milling machine fabrication. It is based on depth buffer analysis and uses genetic algorithm for tool path optimisation, however a basic algorithm incorporated in the library already outputs resonable tool trajectory.
In order to get the library to work you need to specify up to two tool diameters – for roughiing and finishing phases, output file name and material thickness (if not specified the whole model will be exported as one file not as part files if needed). There is also a function for altering the default parameters of spindle speed, feed rate, layer maximum thickness and offser above material.
More detailed description comming soon. Here is the link were you can download the library with some sample codes, but it has not yet been tested much, so any bugs and suggestions are welcome.
http://www.sharefile.org/showfile-1851/pgcode3d.zip
You can test output path in any CNC simmulation software. I used Predator Virtual CNC and CNCSimulator.
Sample code:
import PGCode3D.*;
G_code_export gc;
void setup()
{
size(200, 200, P3D); // both P3D and OpenGL are supported
gc = new G_code_export (this,6,3,”cnc_code_nowe”,200);
//T01 – 6mm, T02 – 3mm, material thickness – 20 cm
background(255);
stroke(255);
fill(0);
}
void draw()
{
ortho(); // use ortho for the cprrect geometry to be exported
translate(width/2, height/2);
pushMatrix();
rotateY(PI/6);
rotateX(PI/6);
translate(width/2, height/2,-height/2);
box(30);
popMatrix();
gc.print_data(); //println the model data
if(keyPressed){
gc.change_settings(5,3000,150,3);
// 5-offset above material, 3000 – spindle speed, 150 – feed rate, 3 – layer thickness
gc.optimise_path(1000); //optimise throughout 1000 generation
gc.export(); //will println “generated” when the view analysis is completed and “file written” for the complete export
exit();
}
}