We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm having issues manipulating the points in an SVG loaded through PShape. getVertexCount() and getVertex() both work on a rectangle drawn within Processing, but they fail on an external SVG. The SVG in question is a simple rectangle for testing purposes.
Here's the simple test I ran:
PShape rectangle;
PShape file;
void setup() {
size(800,600,P2D);
rectangle = createShape(RECT,width/2-50,100,100,50);
file = loadShape("file.svg");
println(rectangle.getVertexCount());
println(file.getVertexCount());
println();
println(rectangle.getVertex(0));
//println(file.getVertex(0));
}
void draw() {
background(50);
shape(rectangle);
shape(file);
}
The output I get is correct for the rectangle (4, and a vertex), but wrong for the SVG (0 and a null pointer exception when it's not commented out).
Is this a known issue or am I doing something incredibly stupid somewhere? I've tried with the latest version of processing, both 32 and 64 bit, as well as the previous version in 64 bit. I have the same problem with all. I'm running Windows 7 x64.
Thanks in advance. :)
Answers
First remark: playing with your code and a simple random SVG file I had at hand (generated from my P8gGraphicsSVG library from a simple rectangle shape), I noticed that a shape loaded in P2D mode is a PShapeOpenGL instead of a PShapeSVG. I don't know if it makes a practical difference, but it is interesting to know...
So I commented out the
rectangle
code and I experimented a bit more.You have to know that most SVG files have a complex structure, grouping elements inside g tags (groups). So often you have to dig deeper. For example, for my file, I had to do:
For the record, the file (made by drawing a simple rect() with a big stroke width) is: