// Digital Material Cube 002 // FabLab Japan // Hiroya Tanaka // Import //import processing.opengl.*; //import javax.media.opengl.*; import controlP5.*; import javax.swing.*; import SpringGUI.*; import unlekker.data.*; SpringGUI gui; // File IO String getFile; String setFile; String [] txtarray = null; String txt = null; boolean saveSTL = false; // Import Mesh Library import toxi.geom.*; import toxi.geom.mesh.*; import toxi.geom.mesh.subdiv.*; import toxi.processing.*; import toxi.util.*; import toxi.volume.*; ToxiclibsSupport gfx; WETriangleMesh mesh; // Field int FIELD_SIZE = 50; int FIELD_STEP = 10; // Camera float expo = 1; float rotx, roty; float rate = 0.01; // Resolution of Box public int resolution = 1; public int transparency = 0; float ratio = 0; // ControlP5 ControlP5 controlP5; Textfield tfUserName; // テキストフィールド String txts = ""; // Text PFont font; long time; void setup() { size(640, 480, P3D); controlP5 = new ControlP5(this); controlP5.addSlider("transparency",0,100,10,65,200,20); controlP5.addSlider("resolution",1,48,10,40,200,20); controlP5.addButton("savefile",10,10,450,80,19); } void draw() { background(0); // PGraphicsOpenGL pgl = (PGraphicsOpenGL)g; // Lighting ambientLight(150, 150, 150); directionalLight(255,255,255,-1,0,0); pointLight(160, 160, 160, mouseX, mouseY, 200); spotLight(100, 100, 100, mouseX, mouseY, 200, 0, 0, -1, PI, 2); // Camera if (getFile == null && setFile == null) { if (mousePressed) { rotx = rotx + (mouseY - pmouseY) * rate; roty = roty + (mouseX - pmouseX) * rate; } } else { rotx = 0; roty = 0; expo = 1; } //Text font = createFont("Meiryo", 12); textFont(font); fill(255,255,255); text("02 Transparency", 10, 25); // Zoom In and Out if (keyPressed && keyCode==UP) { expo = expo + 0.01; } if (keyPressed && keyCode==DOWN) { expo = expo - 0.01; } // フレームの描画 pushStyle(); translate(320,240,200); rotateX(rotx); rotateY(roty); scale(expo); stroke(255, 255, 255, 20); FIELD_STEP = FIELD_SIZE*2/resolution; for(int k = 1; k<=resolution; k = k + 1) { for(int j = 1; j<=resolution; j = j + 1) { for(int i = 1; i<=resolution; i = i + 1) { // x float x = -FIELD_SIZE + FIELD_STEP*(i - 1); float xx = -FIELD_SIZE + FIELD_STEP*(i); float realx = (x + xx)/2; // y float y = -FIELD_SIZE + FIELD_STEP*(j - 1); float yy = -FIELD_SIZE + FIELD_STEP*(j); float realy = (y + yy)/2; // z float z = -FIELD_SIZE + FIELD_STEP*(k - 1); float zz = -FIELD_SIZE + FIELD_STEP*(k); float realz = (z + zz)/2; pushMatrix(); translate(realx,realy,realz); noFill(); box(FIELD_STEP,FIELD_STEP,FIELD_STEP ); popMatrix(); } } } popStyle(); // ボクセルの描画 // STL書き出し if(setFile != null) { beginRaw("unlekker.data.STL",setFile+".stl"); println("start :"+setFile); } pushStyle(); noStroke(); noFill(); int len = txts.length(); int l = 0; FIELD_STEP = FIELD_SIZE*2/resolution; for(int k = 1; k<=resolution; k = k + 1) { for(int j = 1; j<=resolution; j = j + 1) { for(int i = 1; i<=resolution; i = i + 1) { //x float x = -FIELD_SIZE + FIELD_STEP*(i - 1); float xx = -FIELD_SIZE + FIELD_STEP*(i); float realx = (x + xx)/2; //y float y = -FIELD_SIZE + FIELD_STEP*(j - 1); float yy = -FIELD_SIZE + FIELD_STEP*(j); float realy = (y + yy)/2; //z float z = -FIELD_SIZE + FIELD_STEP*(k - 1); float zz = -FIELD_SIZE + FIELD_STEP*(k); float realz = (z + zz)/2; pushMatrix(); translate(realx,realy,realz); l = l + transparency; if ( l>=100 ) { fill(200,200,200); box(FIELD_STEP,FIELD_STEP,FIELD_STEP); l = l - 100; } popMatrix(); } } } popStyle(); // STL書き出し終了 if(setFile !=null) { endRaw(); setFile = null; println("end"); } // α合成を有効にする // GL gl = pgl.beginGL(); // gl.glEnable(GL.GL_BLEND); // gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // gl.glDisable(GL.GL_DEPTH_TEST); // pgl.endGL(); // GUI コンポーネント描画のための設定 camera(); // gl = pgl.beginGL(); // gl.glDisable(GL.GL_DEPTH_TEST); // 深度テストを無効化 // gl.glEnable(GL.GL_BLEND); // gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // pgl.endGL(); } // テキストが入力された際にコールバックされるメソッド public synchronized void textfield(String txt) { txts = txt; } // Saveボタン public void savefile(int theValue) { setFile = setFileName(); }