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 & HelpOpenGL and 3D Libraries › Triangle orientation during beginRaw / endRaw
Page Index Toggle Pages: 1
Triangle orientation during beginRaw / endRaw (Read 1695 times)
Triangle orientation during beginRaw / endRaw
May 24th, 2009, 1:20am
 
I'm looking at some classes I use for recording geometry to memory, using beginRaw / endRaw to build vertex and face lists that can then be used to redraw the geometry.

This works fine inside Processing, but if I use a stored geometry and write out to STL, every other triangle is suddenly incorrectly oriented so that the surface normal is reversed. For STL work that means the models are useless, so I'm trying to figure it out.

I suspect the reason has to do with my use of beginShape(QUAD_STRIP), since the vertices given for QUAD_STRIP do not obey the "handedness" rule. If so, is there a workaround or will I have to reconfigure my sketches to only use TRIANGLES to ensure correct handedness?
Re: Triangle orientation during beginRaw / endRaw
Reply #1 - May 24th, 2009, 2:02am
 
I've now rewritten some of my geometry building using only correctly oriented TRIANGLES, and the reversed normal problem has disappeared. I guess this confirms my suspicion. Doing things this way will be more cumbersome, but not a huge problem.

However, looking inside PGraphics3D I notice that endShapeFill() does have logic to correct the orientation of generated triangles depending on whether QUAD_STRIP, QUADS, TRIANGLE_STRIP etc. was used. Does that mean that the problem is in my code

I have added some picture documentation on Flickr showing the disparity between realtime OpenGL (top) and Meshlab (bottom):

...

...
Re: Triangle orientation during beginRaw / endRaw
Reply #2 - May 27th, 2009, 2:46pm
 
Hi Marius,

Nice to meet you here. It's nice to see that you are working on a STL library, it will be really usefull. Wink

I did a test for triangulations to see if triangles are inverted. I created a scene using my export library (superCAD is using beginRaw() triangulation) and reimported it. The scene was composed of polygons, quads, triangles... (http://anar.ch/examples/ManyForms.htm) I have a function displaying the normals. Everything is well oriented in the scene, and exported and broken into triangles (by beginRaw()).

And when reimported the normals seems to be sometimes inside, sometimes outside. I've also tested in a CAD software, and I get similar results.

I also suspect the triangulator in raw() to inverse faces.

You might use beginRecord() loop instead of beginRaw() when you extend PGraphics. This way, I think you could export quads correctly. You need to define the order by yourself.
Re: Triangle orientation during beginRaw / endRaw
Reply #3 - Jun 6th, 2009, 7:35am
 
Just figured out a fix. Turns out that if I enable GL_LIGHT_MODEL_TWO_SIDE it will render correctly in OpenGL:

Code:
gl.glLightModelf(GL.GL_LIGHT_MODEL_TWO_SIDE, 1); 



There is still a little weirdness in handling light sources, but now I'm able to switch back and forth between standard Processing and direct OpenGL code while keeping the rendering consistent.

I've posted some sketches on Flickr showing models with ~350k polygons that are rendered into memory at startup. Using pure OpenGL calls I get 15 frames/sec, using PGraphicsOpenGL normally I get only 1.2 frames/sec.
Re: Triangle orientation during beginRaw / endRaw
Reply #4 - Jun 9th, 2009, 9:33am
 
Does it slove the orientation problem for STL output?
Page Index Toggle Pages: 1