Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.core.*;
- import wblut.hemesh.*;
- import wblut.geom.*;
- import wblut.processing.*;
- import peasy.*;
- import controlP5.*;
- import java.util.*;
- PeasyCam cam;
- WB_Render render;
- HE_Mesh mesh;
- HE_Selection selection;
- ControlP5 cp5;
- boolean facesOn = true;
- boolean edgesOn = true;
- boolean normalsOn = true;
- List<List<WB_Coord>> paths1;
- void setup() {
- size(1000, 500, P3D);
- cam = new PeasyCam(this, 5000);
- surface.setLocation(displayWidth + 10, 10);
- perspective(PI/4, width/height, 1, 100000);
- render = new WB_Render(this);
- colorMode(HSB, 100);
- //HEC_Creator creator = new HEC_Box().setSize(200, 5000, 5000);
- HEC_Creator creator = new HEC_Grid(3, 1, 500, 5000);
- mesh = new HE_Mesh(creator);
- selection = mesh.selectAllVertices();
- //mesh.modify(new HEM_MidEdgeSplit());
- cp5 = new ControlP5(this);
- cp5.addToggle("facesOn").setPosition(10, 10).setSize(37, 20).setMode(ControlP5.SWITCH);
- cp5.addToggle("edgesOn").setPosition(57, 10).setSize(37, 20).setMode(ControlP5.SWITCH);
- cp5.addToggle("normalsOn").setPosition(104, 10).setSize(37, 20).setMode(ControlP5.SWITCH);
- cp5.addButton("moveGaussian").setPosition(10, 60).setSize(80, 20);
- cp5.addButton("catmullSubdivide").setPosition(10, 90).setSize(80, 20);
- cp5.addButton("mirror").setPosition(10, 120).setSize(80, 20);
- cp5.setAutoDraw(false);
- setMeshColor();
- }
- void draw() {
- background(0);
- lights();
- fill(100);
- noStroke();
- if (facesOn) render.drawFaces(mesh);
- if (facesOn) stroke(0);
- else stroke(100);
- if (edgesOn) render.drawEdges(mesh);
- stroke(#FFEA00);
- if (normalsOn) render.drawVertexNormals(selection, 5);
- cam.beginHUD();
- cp5.draw();
- drawScale();
- cam.endHUD();
- /*
- WB_Point origin = new WB_Point(0, 0, 0);
- WB_Point camera = new WB_Point(cam.getPosition()[0], cam.getPosition()[1], cam.getPosition()[2]);
- WB_Plane sectionPln = new WB_Plane(origin, camera);
- paths1 = HET_Contours.contoursAsPaths(mesh, sectionPln);
- for (List<WB_Coord> pts : paths1) {
- WB_PolyLine pl = new WB_PolyLine(pts);
- push();
- stroke(100, 100, 100);
- render.drawPolyLine(pl);
- pop();
- }*/
- }
- void drawScale() {
- push();
- translate(width-130, 10);
- for (int i = 0; i < 120; i++) {
- stroke(map(i, 0, 120, 10, 100), 100, 100);
- line(i, 0, i, 20);
- }
- pop();
- }
- void keyPressed() {
- if (key == 'y') {
- selection = HET_MeshOp.splitFacesMidEdge(mesh);
- }
- if (key == 'x') {
- selection = HET_MeshOp.splitFacesMidEdge(mesh);
- }
- if (key == 'w') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(10);
- p.addSelf(n);
- }
- }
- if (key == 's') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(-10);
- p.addSelf(n);
- }
- }
- if (key == 'q') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(100);
- p.addSelf(n);
- }
- }
- if (key == 'a') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(-100);
- p.addSelf(n);
- }
- }
- if (key == 'e') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(1);
- p.addSelf(n);
- }
- }
- if (key == 'd') {
- HE_VertexIterator vi = selection.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- n.mulSelf(-1);
- p.addSelf(n);
- }
- }
- if (key == 'i') {
- selection = selection.invertVertices();
- }
- if(key == 'c') {
- mesh.deleteFaces(mesh.selectRandomFaces(0.1));
- }
- setMeshColor();
- }
- void setMeshColor() {
- HE_VertexIterator vi = mesh.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- color col = color(map(sin((float)v.getScalarMeanCurvature()), -1, 1, 10, 100), 100, 100);
- //println(v.getScalarGaussianCurvature());
- v.setColor(col);
- }
- }
- float sigmoid(float x) {
- return 1/(1+exp(-x));
- }
- void moveGaussian() {
- //selection = HET_MeshOp.splitFacesMidEdge(mesh);
- HE_VertexIterator vi = mesh.vItr();
- while (vi.hasNext()) {
- HE_Vertex v = vi.next();
- WB_Vector n = v.getVertexNormal();
- WB_Point p = v.getPosition();
- float scalar = sigmoid((float)v.getScalarMeanCurvature());
- scalar -= 0.5;
- scalar *= 50;
- n.mulSelf(scalar);
- p.addSelf(n);
- }
- setMeshColor();
- }
- void catmullSubdivide() {
- mesh.subdivide(new HES_CatmullClark());
- }
- void mirror() {
- HEM_Mirror m = new HEM_Mirror().setPlane(0, 0, 0, random(-1, 1), random(-1, 1), random(-1, 1)).setOffset(10).setReverse(false);
- mesh.modify(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement