We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Subclassing PGraphics3D and exporting geometry
Page Index Toggle Pages: 1
Subclassing PGraphics3D and exporting geometry (Read 755 times)
Subclassing PGraphics3D and exporting geometry
Sep 8th, 2007, 4:56pm
 
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();
}
}
Re: Subclassing PGraphics3D and exporting geometry
Reply #1 - Sep 9th, 2007, 3:13pm
 
why not use the same method as RawDXF along with beginRaw()?

other than that...

the [X] and [Y] values will be translated to screen space, [Z] is in zbuffer space.

VX/Y/Z need to be divided by VW to work properly (see the "if raw != null" block inside PGraphics3D).

MX/Y/Z are the coordinates originally passed in (see vertex() inside PGraphics3D).
Page Index Toggle Pages: 1