Created
May 21, 2019 04:35
-
-
Save echophon/aa014baf4d969a8395fd25fd20a0d50f to your computer and use it in GitHub Desktop.
hemesh_layout
This file contains hidden or 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 wblut.math.*; | |
import wblut.processing.*; | |
import wblut.core.*; | |
import wblut.hemesh.*; | |
import wblut.geom.*; | |
import hype.*; | |
import hype.extended.behavior.HOscillator; | |
HDrawablePool pool, pool2; | |
HE_Mesh mesh, mesh2; | |
WB_Render render; | |
int vertexCount; | |
int faceCount; | |
float [][] vertices; | |
int [][] faces; | |
boolean meshToggle, meshToggle2; | |
void setup() { | |
size(800, 800, OPENGL); | |
H.init(this).background(#202020).use3D(true); | |
// create a mesh, any mesh will do | |
HEC_Archimedes creator =new HEC_Archimedes().setEdge(200).setType(6); | |
mesh =new HE_Mesh(creator); | |
//mesh.smooth(); | |
// add an inverted mesh- HEC_Dual exchanges face centers with vertices | |
// mesh2 = new HE_Mesh(new HEC_Dual(mesh2)); | |
HEC_Archimedes creator2 =new HEC_Archimedes().setEdge(100).setType(9); | |
mesh2 =new HE_Mesh(creator2); | |
// create a render object to use in our draw loop | |
render =new WB_Render(this); | |
//export the vertex information | |
vertices =mesh.getVerticesAsFloat(); // returns a two dimensional array- first index = vertex index, second index = 0..2 indicates if x,y, or z coordinate | |
vertexCount =mesh.getNumberOfVertices(); | |
//use the vertex information with a pool | |
//preferably wrap it in a HLayout somehow | |
pool = new HDrawablePool(vertexCount); //set to the mesh list | |
pool.autoAddToStage() | |
.add(new HBox()) | |
.onCreate ( | |
new HCallback() { | |
public void run(Object obj) { | |
int i = pool.currentIndex(); | |
HDrawable d = (HDrawable) obj; | |
d | |
.strokeWeight(1) | |
.stroke(#999999) | |
.fill(#202020) | |
// .anchorAt(H.CENTER) | |
// use the vertex information to set x,y,z | |
.x(vertices[i][0]) | |
.y(vertices[i][1]) | |
.z(vertices[i][2]) | |
// .loc(random(width),random(height)) | |
.size(20) | |
; | |
new HOscillator().target(d).property(H.SIZE).range(20,5).currentStep(i); | |
} | |
} | |
) | |
.requestAll() | |
; | |
//export the vertex information | |
vertices =mesh2.getVerticesAsFloat(); // first index = vertex index, second index = 0..2, x,y,z coordinate | |
vertexCount =mesh2.getNumberOfVertices(); | |
pool2 = new HDrawablePool(vertexCount); //set to the mesh list | |
pool2.autoAddToStage() | |
.add(new HBox()) | |
.onCreate ( | |
new HCallback() { | |
public void run(Object obj) { | |
int i = pool2.currentIndex(); | |
HDrawable d = (HDrawable) obj; | |
d | |
.strokeWeight(1) | |
.stroke(#999999) | |
.fill(#F9F9F9) | |
// .anchorAt(H.CENTER) | |
// use the vertex information to set x,y,z | |
.x(vertices[i][0]) | |
.y(vertices[i][1]) | |
.z(vertices[i][2]) | |
// .loc(random(width),random(height)) | |
.size(20) | |
; | |
new HOscillator().target(d).property(H.SIZE).range(20,5).currentStep(i*4); | |
new HOscillator().target(d).property(H.DROTATIONX).range(-1,1).currentStep(i); | |
new HOscillator().target(d).property(H.DROTATIONY).range(-1,1).speed(0.1).currentStep(i); | |
} | |
} | |
) | |
.requestAll() | |
; | |
} | |
void draw() { | |
// background(255); | |
directionalLight(255, 255, 255, 1, 1, -1); | |
directionalLight(127, 127, 127, -1, -1, 1); | |
translate(400, 400, 100); | |
rotateY(mouseX*1.0f/width*TWO_PI); | |
rotateX(mouseY*1.0f/height*TWO_PI); | |
H.drawStage(); | |
if (meshToggle){ | |
stroke(125); | |
strokeWeight(2); | |
render.drawEdges(mesh); | |
noStroke(); | |
// render.drawFaces(mesh); | |
} | |
if (meshToggle2){ | |
stroke(255); | |
strokeWeight(2); | |
render.drawEdges(mesh2); | |
noStroke(); | |
// render.drawFaces(mesh2); | |
} | |
} | |
void keyPressed(){ | |
if (key == 'p'){ | |
saveFrame("image-#####.png"); | |
} | |
if (key == '1'){ | |
meshToggle = !meshToggle; | |
} | |
if (key == '2'){ | |
meshToggle2 = !meshToggle2; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment