import toxi.geom.Vec3D; // Import import processing.opengl.*; import javax.media.opengl.*; import controlP5.*; import javax.swing.*; import SpringGUI.*; import unlekker.data.*; SpringGUI gui; //import rui.marchingCubes.*; // File IO String getFile; String setFile; String [] txtarray = null; String txt = null; boolean saveSTL = false; //MarchingCubes mc; Vec3D rotationAxis; // ControlP5 ControlP5 controlP5; Boolean bUseFill; int strokewidth = 50; void setup(){ size(1024, 600, OPENGL); Vec3D aabbMin = new Vec3D(-width/2, -height/2, -250); Vec3D aabbMax = new Vec3D(width/2, height/2, 250); Vec3D numPoints = new Vec3D(50,50,50); float isoLevel = 1; MarchingCubes(aabbMin, aabbMax, numPoints, isoLevel); rotationAxis = new Vec3D(); bUseFill = false; // // // Control Panel controlP5 = new ControlP5(this); controlP5.addSlider("strokewidth",15,150,50,40,200,20); controlP5.addButton("savefile",10,10,450,80,19); } void draw(){ background(0); lights(); if(mousePressed && mouseButton == LEFT){ Vec3D metaBallPos = new Vec3D(mouseX-(width/2), mouseY-(height/2), 0); metaBallPos.rotateX(rotationAxis.x); metaBallPos.rotateY(rotationAxis.y); addMetaBall(metaBallPos, strokewidth, 1); } if(mousePressed && mouseButton == RIGHT){ Vec3D metaBallPos = new Vec3D(mouseX-(width/2), mouseY-(height/2), 0); metaBallPos.rotateX(rotationAxis.x); metaBallPos.rotateY(rotationAxis.y); addMetaBall(metaBallPos, strokewidth, -1); } createMesh(); if(bUseFill){ fill(0,255,0); noStroke(); } else { noFill(); stroke(127); } pushMatrix(); translate(width/2, height/2, 0); rotateX(rotationAxis.x); rotateY(rotationAxis.y); // STL書き出し if(setFile != null){ beginRaw("unlekker.data.STL",setFile+".stl"); println("start :"+setFile); } renderMesh(); // STL書き出し終了 if(setFile !=null) { endRaw(); setFile = null; println("end"); } popMatrix(); } void keyPressed(){ if(key == CODED){ if(keyCode == LEFT) rotationAxis.y += 0.05; if(keyCode == RIGHT) rotationAxis.y -= 0.05; if(keyCode == UP) rotationAxis.x -= 0.05; if(keyCode == DOWN) rotationAxis.x += 0.05; } else { if(key == ' '){ bUseFill = !bUseFill; } if(key == 'r' || key == 'R'){ reset(); rotationAxis.set(0,0,0); } } } // Saveボタン public void savefile(int theValue) { setFile = setFileName(); }