I’m not sure there are many built-in examples of this. Look under Topics / Textures
. Only the sphere example builds a PShape with texture coordinates I think.
IIRC there’s an issue where you can’t change the texture for the shape later. I think I managed this by using a PGraphics as the texture and drawing video, etc. into that first if you need it to update.
eduzal
September 16, 2019, 5:40pm
22
yes. i was reaaly whinkin about sending a PGraph for the shader, so i can do whatever i want inside it.
If I’m thinking of the same issue, there was a recent discussion about using s.getTessellation()
as a workaround for this.
Terribly sorry, should have actually shared it from my test sketch – perhaps I forgot the return type? Anyhow,
Replace this line:
// roundRect.setTexture(textBoxPGraphics);
roundRect = addTextureUV(roundRect, textBoxPGraphics);
… and add THIS function:
/**
* https://github.com/processing/processing/issues/2508#issuecomment-50774212
*/
PShape addTextureUV(PShape s, PImage img) {
PShape s2 = s.getTessellation(); // github.com/processing/processing/issues/2508#issuecomment-52296723
s2.s…
eduzal
September 18, 2019, 12:14am
24
i’m figuring out that the issue is not with the PShape itself, it’s with the PGraphics itself.
i’ve dumped all the PShapes, commented color sampling, using ‘live’ vector data and the problem is still the same. it starts with 9.5 fps and keeps dropping to 0.3. it looks like it’s in a giant loop that’s redrawing the vector data all over.
it’s funny cause when i draw them out of PGraph it runs smoothly
main thread
ArrayList<Brick> bricks;
PGraphics pg;
int w=2400;
int h=1920;
void setup() {
size(600, 480, P2D);
smooth();
colorMode(HSB, 360, 100, 100);
println("building PGraphics");
pg=createGraphics(w, h, P2D);
println("building bricks");
bricks=new ArrayList<Brick>();
buildBrick();
}
void draw() {
background(32);
pg.beginDraw();
pg.background(0);
for (Brick b : bricks) {
//b.update();
b.display();
}
pg.endDraw();
image(pg, 0, 0, width, height);
fill(0, 100, 100);
textSize(20);
text(frameRate, 10, 30);
}
void buildBrick() {
original=loadShape("SVG_OUT_03.svg");
original.disableStyle();
int numChild=original.getChildCount();
println(numChild);
for (int i=0; i<numChild; i++) {
PShape tempFace=original.getChild(i);
int numBricks=tempFace.getChildCount();
println("face: "+i+" bricks:"+numBricks);
for (int j=0; j<numBricks; j++) {
PShape temp=tempFace.getChild(j);
int vCount=temp.getVertexCount();
ArrayList<PVector> tempVertex=new ArrayList<PVector>();
for (int k=0; k<vCount; k++) {
PVector pv=temp.getVertex(k);
tempVertex.add(pv);
}
bricks.add(new Brick(tempVertex));
}
}
}
the brick object
class Brick {
ArrayList<PVector> vertices;
PVector center;
int centerX, centerY;
color c;
int loc;
int hue=0, sat=0, bright=100;
int alpha=0;
Brick(ArrayList<PVector> v) {
vertices=v;
center=new PVector();
c=color(0, 0, 100);
getCentroid();
}
void getCentroid() {
for (PVector p : vertices) {
centerX+=p.x;
centerY+=p.y;
}
centerX/=vertices.size();
centerY/=vertices.size();
loc=int(centerX+centerY*pg.width);
}
void update() {
bright=colorMap.get(this);
}
void display() {
pg.beginDraw();
pg.beginShape();
//pg.fill(hue, sat, bright);
pg.noFill();
pg.strokeWeight(1);
pg.stroke(255);
//pg.noStroke();
for (PVector p : vertices) {
pg.vertex(p.x, p.y);
}
pg.endShape(CLOSE);
pg.strokeWeight(4);
pg.stroke(255);
pg.fill(c);
pg.ellipse(center.x, center.y, 4, 1);
pg.endDraw();
}
}
I just noticed what might be an obvious problem. You’re calling pg.beginDraw()
and pg.endDraw()
in every brick display. Just do this once in your main draw method.
1 Like
eduzal
September 18, 2019, 5:09pm
26
this works, it’s faster, but still loosing performance after 60 cycles.