HE_MESH Tutorial (3)
HE_MESH,難しいイメージだったけど,やっていくとわかることもある.
– All classes prefixed by HE_ specify core classes for accessing specific data concerning our mesh.
– All classes prefixed by HEC_ specify creators for creating & configuring the basic geometric shapes.
– All classes prefixed by HEM_ specify modifiers for applying a number of modifications to our shapes.
– All classes prefixed by WB specify a multitude of math and rendering possibilities.
つまり接頭辞で
- HE_がつくもの:メッシュに関するクラス
- HEC_がつくもの:クリエイター(基本図形)に関するクラス
- HEM_がつくもの:モディフィア(変形)に関するクラス
- WB_がつくもの:計算とレンダリングに関するクラス
というようなことのようだ.見当がつくとコードを書くのが楽.
進めて,STLのエクスポートまで出来た.パラメータに関してはよくわかっていない部分も多々あるが,Processingのコードでつくった形状を3Dプリント出来るようになった.
ライブラリ
- PeasyCam
- ControlP5
- HE_Mesh
上記ライブラリをContribution Managerで検索してインストールする
コード
import controlP5.*; import peasy.*; import peasy.org.apache.commons.math.*; import peasy.org.apache.commons.math.geometry.*; import wblut.geom.*; import wblut.hemesh.*; import wblut.core.*; import wblut.math.*; import wblut.nurbs.*; import wblut.processing.*; HE_Mesh mesh; WB_Render3D render; HEC_Cube creator; PeasyCam cam; ControlP5 cp5; float HEC_setEdge; float HEM_ChamferCorners_setDistance; float HEM_ChamferEdges_setDistance; // setup関数 : 初回1度だけ実行される void setup() { size(960, 540, P3D); // ウィンドウサイズを960px,540pxに colorMode(HSB, 360, 100, 100); // HSBでの色指定にする cam = new PeasyCam(this, 500); cp5 = new ControlP5(this); cp5.addSlider("HEC_setEdge").setRange(50, 500).setValue(200).setPosition(20, 20); cp5.addSlider("HEM_ChamferCorners_setDistance").setRange(1, 100).setValue(20).setPosition(20, 40); cp5.addSlider("HEM_ChamferEdges_setDistance").setRange(1, 100).setValue(5).setPosition(20, 60); cp5.addButton("button").setLabel("Export STL").setPosition(20, 80); cp5.setAutoDraw(false); create(); } // draw関数 : setup関数実行後繰り返し実行される void draw() { background(0, 0, 0); cam.beginHUD(); directionalLight(0, 0, 100, 1, 1, -1); directionalLight(0, 0, 50, -1, -1, 1); cp5.draw(); cam.endHUD(); stroke(220, 80, 100); strokeWeight(3); noFill(); render.drawEdges(mesh); } void create() { creator = new HEC_Cube(); creator.setEdge(HEC_setEdge).setCenter(0, 0, 0).setZAxis(1, 1, 1).setZAngle(PI/4); //creator.setWidthSegments(4).setHeightSegments(4).setDepthSegments(4); mesh = new HE_Mesh(creator); HEM_ChamferCorners chamfer = new HEM_ChamferCorners().setDistance(HEM_ChamferCorners_setDistance); HEM_ChamferEdges edges = new HEM_ChamferEdges().setDistance(HEM_ChamferEdges_setDistance); mesh.modify(chamfer); mesh.modify(edges); render = new WB_Render3D(this); } void controlEvent(ControlEvent event) { create(); } void button() { mesh.triangulate(); HET_Export.saveToSTL(mesh, sketchPath("export_stl"), "test"); }