Vertex border visible
in
Contributed Library Questions
•
2 years ago
Hi,
I've been playing with a little interactive fabric simulation code, trying to texture it with a loaded image.
I managed to do it with vertex, the only problem is a can see the borders of each triangle (as a white line).
I looked at some samples where the texturing was done the same way ,
like this flafSim sketch,
the texture there seems smooth with no borders.
here is my code , I use a 600X600 jpg pic , and the
physics lib
thanks
///////////
import traer.physics.*;
PImage flag;
ParticleSystem physics;
Particle[][] particles;
//Ball ball1,ball2,ball3,ball4;
int gridSize = 20;
float SPRING_STRENGTH = 0.2;
float SPRING_DAMPING = 0.1;
void setup()
{
size(800, 600,P3D);
smooth();
// fill(0);
noFill();
flag = loadImage("cal_pro_271.jpg");
physics = new ParticleSystem(0.03, 0.01);
particles = new Particle[gridSize][gridSize];
float gridStepX = (float) ((width / 2) / gridSize);
float gridStepY = (float) ((height / 2) / gridSize);
for (int i = 0; i < gridSize; i++)
{
for (int j = 0; j < gridSize; j++)
{
particles[i][j] = physics.makeParticle(0.2, j * gridStepX + (width / 8), i * gridStepY + 20, 0.0);
if (j > 0)
{
physics.makeSpring(particles[i][j - 1], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, gridStepX);
}
}
}
for (int j = 0; j < gridSize; j++)
{
for (int i = 1; i < gridSize; i++)
{
physics.makeSpring(particles[i - 1][j], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, gridStepY);
}
}
particles[0][0].makeFixed();
particles[0][gridSize - 1].makeFixed();
}
void draw()
{
noFill();
noStroke();
physics.tick();
if (mousePressed)
{
if (mouseButton == LEFT)
{
particles[0][gridSize - 1].position().set(mouseX, mouseY, 0);
particles[0][gridSize - 1].velocity().clear();
}
else if (mouseButton == RIGHT)
{
particles[0][0].position().set(mouseX, mouseY, 0);
particles[0][0].velocity().clear();
}
}
int elementWidth=20;
float xtweek = 1.02;
float ytweek = 1.05;
//fill(255,0,0);
background(255);
for (int j = 0; j < gridSize-1; j++)
{
beginShape(TRIANGLE_STRIP);
texture(flag);
for (int i = 0; i < gridSize; i++)
{
vertex(particles[i][j].position().x(), particles[i][j].position().y(),particles[i][j].position().z(), (elementWidth*i*xtweek), (elementWidth*j*ytweek));
vertex(particles[i][j+1].position().x(), particles[i][j+1].position().y(),particles[i][j+1].position().z(), elementWidth*i*xtweek, elementWidth*(j+1)*ytweek);
}
endShape();
}
/*
for (int i = 0; i < gridSize; i++)
{
beginShape();
curveVertex(particles[i][0].position().x(), particles[i][0].position().y());
for (int j = 0; j < gridSize; j++)
{
curveVertex(particles[i][j].position().x(), particles[i][j].position().y());
}
curveVertex(particles[i][gridSize - 1].position().x(), particles[i][gridSize - 1].position().y());
endShape();
}
for (int j = 0; j < gridSize; j++)
{
beginShape();
curveVertex(particles[0][j].position().x(), particles[0][j].position().y());
for (int i = 0; i < gridSize; i++)
{
curveVertex(particles[i][j].position().x(), particles[i][j].position().y());
}
curveVertex(particles[gridSize - 1][j].position().x(), particles[gridSize - 1][j].position().y());
endShape();
}
*/
}
void mouseReleased()
{
particles[0][gridSize - 1].velocity().set( (mouseX - pmouseX), (mouseY - pmouseY), 0 );
}
1