PShape.getVertexCode() help
in
Core Library Questions
•
1 year ago
Hi all,
I'm trying to get at the paths from an svg, and having some real troubles. I can't use a library like geomeratives, because this will eventually be ported to processing.js, which doesn't really support libraries.
I'm trying to access the vertices of individual paths, so that I can manipulate them / redraw new shapes. Ultimately, I'd like to be able to also use the (undocumented) PShape.contains() function, which works fine unless you matrix transform (scale / translate etc) a shape. I'm thinking I can get around this by redrawing new shapes after the transform, and using those for the PShape.contains() call.
For now, though, I'm trying to understand what's going on behind the scenes in the getVertexCode() function - the javadoc says:
when I incorporate it into a sketch, though, I can't really figure out what's happening. Here's my code - the svg i have is just a test - a 7-point, closed squiggle from illustrator with different kinds of vertices.
first of all, it says there are 22 vertices, which don't make no damn sense, and then their codes are either 0 or 1 - i guess these might correspond to "VERTEX" and "BEZIER_VERTEX", but one of them should be a BREAK.
any and all help appreciated!
I'm trying to get at the paths from an svg, and having some real troubles. I can't use a library like geomeratives, because this will eventually be ported to processing.js, which doesn't really support libraries.
I'm trying to access the vertices of individual paths, so that I can manipulate them / redraw new shapes. Ultimately, I'd like to be able to also use the (undocumented) PShape.contains() function, which works fine unless you matrix transform (scale / translate etc) a shape. I'm thinking I can get around this by redrawing new shapes after the transform, and using those for the PShape.contains() call.
For now, though, I'm trying to understand what's going on behind the scenes in the getVertexCode() function - the javadoc says:
int |
getVertexCode(int index) One of VERTEX, BEZIER_VERTEX, CURVE_VERTEX, or BREAK. |
when I incorporate it into a sketch, though, I can't really figure out what's happening. Here's my code - the svg i have is just a test - a 7-point, closed squiggle from illustrator with different kinds of vertices.
first of all, it says there are 22 vertices, which don't make no damn sense, and then their codes are either 0 or 1 - i guess these might correspond to "VERTEX" and "BEZIER_VERTEX", but one of them should be a BREAK.
any and all help appreciated!
- PShape squiggle;
PShape[] shapes;
void setup() {
size(800, 800);
background(0);
smooth();
shapeMode(CENTER);
squiggle = loadShape("squiggle.svg");
shapes = squiggle.getChildren();
squiggle.disableStyle();
noLoop();
}
void draw() {
fill(255, 0, 0);
for (int i = 0; i < shapes.length; i++) {
int v = shapes[i].getVertexCount();
println("vertex count: " + v);
for (int j = 0; j < v; j++) {
int code = shapes[i].getVertexCode(j);
println("vertex code for vertex #" + j + ": " + code);
}
}
}
1