Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
PShape array index out of bounds when using P3D (PShapeOpenGL.java) #4773
When trying to edit a PShape childs vertex using the setVertex(index, int, int) method , this ArrayIndexOutOfBoundsException: 2 occurs at line 1667 of the file PShapeOpenGL.java : "if (is3D) vertices[index][Z] = z;"
It will not throw this problem if you use a different renderer because it's not 3D.
To replicate, load an svg file that has one or more children. Set renderer to P3d. Load the svg, get a child, try to edit the vertex using setVertex(index, int, int), and the error will occur.
As a result of this, one cannot change the vertices of a pshape usign p3d. So when the children are loaded, they will be offset according ot however they are on the sheet. In order to fix to get an absolute position, one has to calculate the centroid of the points, and while displaying the shape, offset the drawing by the centroid amount. shape(pShape, mouseX -c.x, mouseY-c.y); where c is the centroid for that particular shape. This is what one would have to do if doing p3d. if using regular renderer, centroid still needs to be calculated, but setvertex can be called to actually subract the centroid from all the vertices. SetVertex needs to be fixed for p3d