Description
Created by: hx2A
Description
The PShape.setVertex() method can update a PShape's geometry and will alter the filled regions but it does not alter the edges. The edges become fixed the first time it is drawn.
This works as expected for the JAVA2D renderer but does not work for P2D or P3D.
Expected Behavior
When I use PShape.setVertex() in a P2D or P3D sketch, I'd like it work the same as does for JAVA2D.
Current Behavior
For a P3D sketch, the line does not change from as it is the first time it is drawn. For a P2D sketch the line does change but is not being drawn correctly.
Steps to Reproduce
- Run this code:
PShape test;
void setup() {
size(500, 500, JAVA2D);
stroke(255, 0, 0);
strokeWeight(15);
fill(255);
test = createShape();
test.beginShape();
for (int i = 0; i < 10; ++i) {
test.vertex(0, 0);
}
test.endShape();
frameRate(5);
}
void draw() {
background(128);
for (int i = 0; i < 10; ++i) {
test.setVertex(i, random(width), random(height));
}
shape(test);
}
Observe how the red line is getting updated for every frame and is always drawn in the right location.
-
Change the renderer to
P3D
. You will see that the red line does not change from one frame to the next. -
Change the renderer to
P2D
. The red line does change from one frame to the next but is not being drawn correctly. It is hard to describe this in words.
Your Environment
- Processing version: 4.0.1
- Operating System and OS version: Linux Ubuntu
Possible Causes / Solutions
In the example above, the PShape object is created with all vertices at 0, 0
. The first time draw()
is called the setVertex()
method is called to change the values, and those new values are being used to draw the shape. Therefore, the setVertex()
method is doing its job for the first frame. For later frames, only the filled region changes.
I believe this has something to do with the tesselation process and edges or strokes in PShape? It seems it is supposed to update the tesselated geometry when setVertex()
is called, and it does do this for the filled regions but not the edges. I know that Processing has an inGeo
for input geometry and and separate tesselated geometry that gets sent to OpenGL for renderering. The tesselated geometry is getting refreshed for only the filled regions.
If you can spot a work-around for this that triggers the necessary geometry update, I'd greatly appreciate it. I know I can create a new shape in draw() but for my use case, which has a lot more than 10 vertices, I want to re-use one PShape object.