Thanks for getting back to me @micycle! I tried using GROUP. Maybe my syntax is wonky, because when I do that, my intersected geometry seems to disappear
If you have a few minutes, I’ve attached a sample sketch for reference. There’s a render
method and a renderGroup
method. In both cases, providing CLOSE
as an arg in endShape
will break things. Somehow Processing doesn’t seem to play nice with PGS_ShapeBoolean.intersect
. Totally possible that I’m doing something wrong…
int radius = 70;
float[][] pts = {
{130, 330, 130, 143, 270, 172, 270, 330},
{130, 331, 130, 148, 270, 180, 270, 331},
{130, 332, 130, 154, 270, 188, 270, 332},
{130, 333, 130, 160, 270, 197, 270, 333},
{130, 334, 130, 169, 270, 206, 270, 334},
{130, 335, 130, 178, 270, 214, 270, 335},
{130, 336, 130, 187, 270, 223, 270, 336},
{130, 337, 130, 197, 270, 230, 270, 337}
};
void setup() {
size(400, 400);
noLoop();
}
void draw() {
background(0);
// Intersects multiple shapes only if endShape
// is not provided with the CLOSE arg
render(-80, 0);
// When running renderGroup, intersected
// geometry does not seem to be there
renderGroup(80, 0);
}
void render(int x, int y) {
PVector loc = new PVector(width / 2 + x, height / 2 + y);
PShape s = createShape(ELLIPSE, loc.x, loc.y, 2 * radius, 2 * radius);
s.setFill(0);
s.setStroke(255);
PShape fillyFill = createShape();
for (int j = 0; j < pts.length; j++) {
fillyFill.setFill(0);
fillyFill.setStroke(255);
float[] points = pts[j];
float p0x = points[0];
float p0y = points[1];
float pNx = points[points.length - 2];
float pNy = points[points.length - 1];
fillyFill.beginShape();
fillyFill.vertex(p0x + x, p0y + y);
for (int i = 0; i < points.length / 2 - 2; i++) {
float px = points[2 * i + 2];
float py = points[2 * i + 3];
fillyFill.vertex(px + x, py + y);
}
fillyFill.vertex(pNx + x, pNy + y);
//fillyFill.endShape(CLOSE); // <- THIS DOES NOT WORK :(
fillyFill.endShape();
}
PShape f1 = PGS_ShapeBoolean.intersect(s, fillyFill);
PGS_Conversion.setAllFillColor(f1, color(0));
PGS_Conversion.setAllStrokeColor(f1, color(255, 127, 0), 1);
shape(s);
shape(f1);
}
void renderGroup(int x, int y) {
PVector loc = new PVector(width / 2 + x, height / 2 + y);
PShape s = createShape(ELLIPSE, loc.x, loc.y, 2 * radius, 2 * radius);
s.setFill(0);
s.setStroke(255);
PShape fillyFill = createShape(GROUP);
for (int j = 0; j < pts.length; j++) {
PShape temp = createShape();
temp.setFill(0);
temp.setStroke(255);
float[] points = pts[j];
float p0x = points[0];
float p0y = points[1];
float pNx = points[points.length - 2];
float pNy = points[points.length - 1];
temp.beginShape();
temp.vertex(p0x + x, p0y + y);
for (int i = 0; i < points.length / 2 - 2; i++) {
float px = points[2 * i + 2];
float py = points[2 * i + 3];
temp.vertex(px + x, py + y);
}
temp.vertex(pNx + x, pNy + y);
//temp.endShape(CLOSE); // <- THIS DOES NOT WORK
temp.endShape();
fillyFill.addChild(temp);
}
// Intersect the shape layer and the hatching layer
PShape f1 = PGS_ShapeBoolean.intersect(s, fillyFill);
// Set the color of the new hatching layer
PGS_Conversion.setAllFillColor(f1, color(0));
PGS_Conversion.setAllStrokeColor(f1, color(255, 127, 0), 1);
shape(s);
shape(f1);
}