Created
August 24, 2016 07:10
-
-
Save echophon/f33db04cb4bbcc8a00087fb7a37acbcf to your computer and use it in GitHub Desktop.
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 java.util.List; | |
| HE_Mesh mesh; | |
| HE_Mesh modifiedMesh; | |
| WB_Render render; | |
| HE_Face f; | |
| List<HE_Vertex> pool; | |
| PImage[] img; | |
| PImage tex; | |
| PVector texPos; | |
| float t; | |
| void setup(){ | |
| size(1000,1000,OPENGL); | |
| textureMode(IMAGE); | |
| textureWrap(REPEAT); | |
| colorMode(HSB,255,255,255); | |
| tex=loadImage("tex4.png"); | |
| img=new PImage[] { | |
| tex, tex, tex, tex, tex, tex | |
| }; | |
| } | |
| void draw(){ | |
| background(1); | |
| lights(); | |
| texture(tex); | |
| // hint(DISABLE_DEPTH_TEST); | |
| HEC_Archimedes creator = new HEC_Archimedes().setEdge(1000).setType(1); | |
| mesh=new HE_Mesh(creator); | |
| // mesh=new HE_Mesh(new HEC_Dual(mesh)); | |
| mesh.smooth(1); | |
| //The easiest way to create a simple modifier is by exporting all vertex coordinates, change them and | |
| //recreate the mesh with the new coordinates. Writing a full-blown implementation of a HEM_Modifier | |
| //is best done in Eclipse with full access to the code repository. | |
| //Export the faces and vertices | |
| float[][] vertices =mesh.getVerticesAsFloat(); // first index = vertex index, second index = 0..2, x,y,z coordinate | |
| int [][] faces = mesh.getFacesAsInt();// first index = face index, second index = index of vertex belonging to face | |
| //Do something with the vertices | |
| for(int i=0;i<mesh.getNumberOfVertices();i++){ | |
| vertices[i][0]*=1.2+.2*sin(HALF_PI/10*i+(frameCount*0.05) ); | |
| vertices[i][1]*=1.2+.2*sin(HALF_PI/10*i+(frameCount*0.04)); | |
| vertices[i][2]*=1.2+.2*cos(HALF_PI/10*i+(frameCount*0.03)); | |
| } | |
| //Use the exported faces and vertices as source for a HEC_FaceList | |
| HEC_FromFacelist faceList=new HEC_FromFacelist().setFaces(faces).setVertices(vertices); | |
| modifiedMesh=new HE_Mesh(faceList); | |
| translate(500,500,0); | |
| scale(1, -1, 1); | |
| rotateY(mouseX*1.0f/width*TWO_PI); | |
| rotateX(mouseY*1.0f/height*TWO_PI); | |
| HE_FaceIterator fItr=new HE_FaceIterator(modifiedMesh); | |
| while (fItr.hasNext()) { | |
| f=fItr.next(); | |
| f.setTextureId( (int)random(6) ); | |
| pool = f.getFaceVertices(); | |
| int j = 0; | |
| beginShape(); | |
| for (HE_Vertex v : pool ){ | |
| switch (j){ | |
| default: texPos = new PVector(0, 0); break; | |
| case 0: texPos = new PVector(0, 0); break; | |
| case 1: texPos = new PVector(tex.width, 0); break; | |
| case 2: texPos = new PVector(tex.width, tex.height); break; | |
| case 3: texPos = new PVector(0, tex.height); break; | |
| } | |
| HE_TextureCoordinate t =new HE_TextureCoordinate(); | |
| t.setUVW( (double)texPos.x, (double)texPos.y, 0.0); | |
| v.setUVW(t); | |
| v.hasTexture(f); | |
| fill((frameCount*j)%255,155,200); | |
| vertex(v.xf(), v.yf(), v.zf()); | |
| // curveVertex(v.xf(), v.yf(), v.zf()); | |
| // vertex(v.xf(), v.yf(), v.zf(), texPos.x, texPos.y); | |
| j++; | |
| } | |
| endShape(CLOSE); | |
| } | |
| render=new WB_Render(this); | |
| render.drawFaces(modifiedMesh, img); | |
| } | |
| void keyPressed(){ | |
| if (key=='p'){ | |
| saveFrame("image-#####.png"); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment