I'm a bit mystified by PGraphics3D. I've already written a STL export lib, and now I'm trying to write a hack that will use a PGraphics3D subclass as a way to render geometry to memory.
Even though the export works in a basic way, it's generating strange coordinates that don't match the setup of the screen. A vertex I know is <0,0,0> becomes <-512.0,-384.0,-665.10754>, which seems related to screen size since that's <-width/2,-height/2,...>.
It's almost as though the vertices haven't been transformed by the transformation matrix.
I could of course just re-align the objects by calculating the center point etc, but I feel like it would be more useful to try to understand how PGraphics3D works.
The piece of code that takes care of saving the data can be seen below. Am I mistaken in using vertex[X][Y][Z]? I've tried using VX, MX etc, but they look worse. My code is very close to RawDXF, so I can't be that far off.
Is there some form of camera initialization that should happen before I start outputting triangles?
Code: public void vertex(float x, float y, float z) {
float vertex[] = vertices[vertexCount];
vertex[X] = x; // note: not mx, my, mz like PGraphics3
vertex[Y] = y;
vertex[Z] = z;
vertexCount++;
if ((shape == TRIANGLES) && (vertexCount == 3)) {
writeTriangle();
}
}