Toxi mesh - deleting mesh faces
in
Contributed Library Questions
•
10 months ago
Hi,
The skecth is about a mesh which is transformed using additive waves method.
I am having a problem with mesh faces. Of course, I don't know the toxi.mesh library very well.
Maybe there i function similar to clear mesh?
After all I want to get the result of the mesh where some faces are deleted in certain rows and colums according to the picture below?
Please help me:)
The skecth is about a mesh which is transformed using additive waves method.
I am having a problem with mesh faces. Of course, I don't know the toxi.mesh library very well.
Maybe there i function similar to clear mesh?
After all I want to get the result of the mesh where some faces are deleted in certain rows and colums according to the picture below?
Please help me:)
import processing.core.PApplet;
import peasy.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.ToxiclibsSupport;
import controlP5.*;
PeasyCam cam;
Grid myGrid;
TriangleMesh mesh;
ToxiclibsSupport gfx;
void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 100);
myGrid = new Grid(101, 31, 10, 10);
mesh = new TriangleMesh("meshy");
gfx = new ToxiclibsSupport(this);
}
void draw() {
background(0);
lights();
mesh.clear();
stroke(255);
strokeWeight(1);
noFill();
rect(0, 0, 1000, 300);
myGrid.run();
//noStroke();
stroke(100);
fill(255);
gfx.mesh(mesh);
}
void keyPressed() {
if (key == 'E') {
mesh.saveAsSTL(sketchPath(mesh.name + ".stl"));
}
}
GRID CLASS
class Grid {
int cols;
int rows;
float scaleX;
float scaleY;
Pt [][] allPts;
Grid( int _cols, int _rows, float _scaleX, float _scaleY){
cols = _cols;
rows = _rows;
scaleX = _scaleX;
scaleY = _scaleY;
allPts = new Pt[cols][rows];
for(int i = 0; i<cols; i++){
for(int j = 0; j<rows; j++){
Vec3D v = new Vec3D (i*scaleX,j*scaleY,0);
allPts[i][j] = new Pt(this, v, i, j);
}
}
}
void run(){
runPoints();
}
void runPoints(){
for(int i = 0; i<cols; i++){
for(int j = 0; j<rows; j++){
allPts[i][j].run();
}
}
}
}
Pt CLASS
- class Pt {
Vec3D loc;
int idX;
int idY;
Grid parent;
float waveValue;
float [] freq1;
float [] phase1;
float [] freq2;
float [] phase2;
Pt( Grid _parent, Vec3D _loc, int _idX, int _idY){
loc = _loc;
idX = _idX;
idY = _idY;
parent = _parent;
freq1 = new float[3];
phase1 = new float[3];
freq2 = new float[3];
phase2 = new float[3];
//loc.z = p5.random(20);
}
void run(){
display();
drawConnections();
calcWave();
}
void calcWave(){
freq1[0] = 10;
freq1[1] = 30;
freq1[2] = map(mouseX, 0, 600, 0, 100);
phase1[0] = 10;
phase1[1] = 20;
phase1[2] = 30;
freq2[0] = 3;
freq2[1] = map(mouseY, 0, 600, 0, 100);
freq2[2] = 30;
phase2[0] = 10;
phase2[1] = 1;
phase2[2] = 5;
//freq1 = p5.map(p5.mouseX, 0, 600, 0, 20);
//phase1 = p5.map(p5.mouseY, 0, 600, 0, 20);
waveValue = 0;
for (int i = 0; i<3;i++){
waveValue += PApplet.sin(idY/freq1[i]+phase1[i])*PApplet.sin(idX/freq2[i]+phase2[i]);
}
waveValue*=50;
loc.z = waveValue;
}
void drawConnections(){
if (idX<parent.cols-1 && idY<parent.rows-1 ){
// Vec3D me = parent.allPts[idX][idY].loc; = loc
Vec3D neRight = parent.allPts[idX+1][idY].loc.copy();
Vec3D neDown = parent.allPts[idX][idY+1].loc.copy();
Vec3D neDiag = parent.allPts[idX+1][idY+1].loc.copy();
mesh.addFace(loc, neRight, neDiag);
mesh.addFace( neDiag,neDown,loc);
}
}
void display(){
stroke(0,255,0);
strokeWeight(1);
point(loc.x, loc.y,loc.z);
}
}
1