Skip to content

Commit 66aaa12

Browse files
committed
Added TessUpdate demo
1 parent 68bf8e4 commit 66aaa12

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// TessUpdate, by Andres Colubri
2+
// The begin/endTessallation API in Processing 4
3+
// enables dynamic modification of PShape objects.
4+
5+
PShape group;
6+
7+
int numBoxes = 100000;
8+
float boxSize = 2;
9+
10+
PMatrix3D mat = new PMatrix3D();
11+
12+
int fcount, lastm;
13+
float frate;
14+
int fint = 3;
15+
16+
void setup() {
17+
size(600, 600, P3D);
18+
noSmooth();
19+
20+
noStroke();
21+
group = createShape(GROUP);
22+
23+
for (int i = 0; i < numBoxes; i++) {
24+
PShape s = createShape(BOX, boxSize, boxSize, boxSize);
25+
s.setFill(#F5CB40);
26+
s.translate(random(-width/2, width/2), random(-height/2, height/2), random(-1000, 1000));
27+
group.addChild(s);
28+
}
29+
}
30+
31+
void draw() {
32+
background(0);
33+
lights();
34+
PVector v = new PVector();
35+
36+
// PShape.set*() calls between beginTessellation() and endTessellation
37+
// will modify the tessellated geometry directly, so this should result
38+
// better performance for shapes that change dynamically during drawing
39+
group.beginTessellation(TRIANGLES);
40+
// getChildCount() returns number of vertices in the tessellated geometry,
41+
// which could be different from the original number of vertices in the shape.
42+
for (int ci = 0; ci < group.getChildCount(); ci++) {
43+
PShape child = group.getChild(ci);
44+
float rx = random(-1, 1);
45+
float ry = random(-1, 1);
46+
float rz = random(-1, 1);
47+
for (int vi = 0; vi < child.getVertexCount(); vi++) {
48+
child.getVertex(vi, v);
49+
v.x += rx;
50+
v.y += ry;
51+
v.z += rz;
52+
child.setVertex(vi, v.x, v.y, v.z);
53+
}
54+
}
55+
group.endTessellation();
56+
57+
translate(width/2, height/2, 0);
58+
rotateY(frameCount * 0.001);
59+
rotateX(frameCount * 0.001);
60+
shape(group);
61+
62+
String txt = String.format("FPS: %6.2fps", frameRate);
63+
surface.setTitle(txt);
64+
}

0 commit comments

Comments
 (0)