toxiclibs texturedMesh
-
for (int y = 0, idx = 0; y < DIMY; y++) {
for (int x = 0; x < DIMX; x++) {
VerletParticle3D p = new VerletParticle3D(x * SPACE, y * SPACE,
0);
physics.addParticle(p);
if (x == 0 || x == DIMX - 1 || y == 0 || y == DIMY - 1) {
p.lock();
// println(p.toString());
}
if (x > 0) {
VerletSpring3D s = new VerletSpring3D(p,
physics.particles.get(idx - 1), SPRING_REST,
SPRING_STRENGTH);
physics.addSpring(s);
}
if (y > 0) {
VerletSpring3D s = new VerletSpring3D(p,
physics.particles.get(idx - DIMX), SPRING_REST,
SPRING_STRENGTH);
physics.addSpring(s);
}
idx++;
}
}
mesh = new TriangleMesh();
for (int y = 0; y < DIMX - 1; y++) {
for (int x = 0; x < DIMX - 1; x++) {
int i = y * DIMX + x;
VerletParticle3D a = physics.particles.get(i);
VerletParticle3D b = physics.particles.get(i + 1);
VerletParticle3D c = physics.particles.get(i + 1 + DIMX);
VerletParticle3D d = physics.particles.get(i + DIMX);
mesh.addFace(a, d, c);
mesh.addFace(a, c, b);
}
}
textureMode(NORMAL);
gfx.texturedMesh(mesh, tex, false);