processing4 icon indicating copy to clipboard operation
processing4 copied to clipboard

PShape.setFill() no longer works

Open cacheflowe opened this issue 2 years ago • 2 comments

This used to work in Processing 3.x, but no longer works in recent Processing 4 versions.

Here's a complete sketch. In Processing 3.x and up to 4.0.b2, we see the box updates to random vertex colors. Since Processing 4.0.b4 (or maybe beta 3), it doesn't have an effect.

PShape shape;
  
public void setup() {
  size(640, 360, P3D);
  shape = createShape(BOX, 100, 100, 100).getTessellation();
  updateFill();
}

public void updateFill() {
  int numVerts = shape.getVertexCount();
  for (int i = 0; i < numVerts; i++) {
    shape.setFill(i, color(random(255), random(255), random(255)));
  }
}

public void draw() {
  background(0);
  translate(width/2, height/2, 0);
  rotateY(frameCount * 0.01);
  shape(shape);
}

cacheflowe avatar Feb 23 '23 19:02 cacheflowe

Ok, probably just need to do a git bisect to track down the change that caused it to break. I think this was around the time that there were some updates to fix up how tessellation and shapes were behaving. @codeanticode may have an idea.

benfry avatar Feb 23 '23 22:02 benfry

The box has two children (don't know why). If you use the setFill on the first child it works.

PShape shape;
  
public void setup() {
  size(640, 360, P3D);
  shape = createShape(BOX, 100, 100, 100).getTessellation();
  updateFill(shape.getChild(0));
}

public void updateFill(PShape shape) {
  
  int numVerts = shape.getVertexCount();
  for (int i = 0; i < numVerts; i++) {
    shape.setFill(i, color(random(255), random(255), random(255)));
  }
}

public void draw() {
  background(0);
  translate(width/2, height/2, 0);
  rotateY(frameCount * 0.01);
  shape(shape);
}

clankill3r avatar May 26 '24 08:05 clankill3r