View Full Version : Wrong face orientation in my Object viewer

01-11-2004, 09:28 AM
this is my first post on the forum. I'm currently trying to do a 3D viewing software and I'm new to OpenGL.

I'm currently trying to render Maya|Wavefront objects. Their face orentation vary from one object to another from clockwise to counter-clockwise and it also seems that some have their normal inverted relative to the face orientation (I mean for example that the polygons are ccw oriented but the normal point toward the cw face - this is I think because they come from MAC). Anyway, setting glFrontFace accordingly to the polygon orientation isn't enough : some objects render correctly others are black (showing their back face) and for some others I see the faces from the inside (inverted normals).
So, what is the way to determine the orientation order of my polygons knowing their normal vector ? And what should I set in the OpenGL engine (glFrontFace or else) to fix this ?

I might have not been clear enough has it was a long explanation, should it be best if I post pictures ?
Thank in advance

01-11-2004, 09:37 AM
There's two ways to solve your problem. One is quick and dirty but may be acceptable as you're working on an object viewer and probably don't have to maintain 70+ FPS. Switch off backface culling. A single call to glDisable(GL_CULL_FACE) will render any face regardless of the orientation.

The other way is to recalculate the winding and normal vectors but I know too little about the mathematical operations involved with this to give you a good answer here. I'm sure there are people online here that know much more than me about this.

[This message has been edited by magichand (edited 01-11-2004).]

01-11-2004, 01:11 PM
Thank for your reply magichand, unfortunately efficiency matters for the kind of viewer I'm doing. This problem drives me mad. I've been working on this for a week. It's true I'm a newbie with OpenGL.

What really drives me mad is that for some objects I have the following:
< == user position
| == polygon face
-> == polygon normal

user mesh object
< |-> <-|

Those normals are obviously inverted. How can this be ? If I determine polygon winding according to the normal direction this case will give me a wrong render.

01-12-2004, 08:36 AM
A lot modeler apps are too lame to get a consistent winding, especially while exporting meshes.
Maya itself is one of the nicest apps, but who knows on what the .obj files were based upon. I think CAD apps are the worst offenders, e.g. mirrored halves of models inverted etc.
What you need is a mesh cleaning algorithm which starts with a correct face and uses the connecting information to flip winding and normals to the correct order and face.
Uhh, fun!

[This message has been edited by Relic (edited 01-12-2004).]

01-12-2004, 08:57 AM
Milkshape is good for you it can chance orientation of whole object or part of it

01-12-2004, 09:36 AM
I think the problem comes from me, not from the mesh objects.
As for the vextexes normal assume they have been created with a left handed coordinate system then there direction is the opposite of my viewer's one.
What I need to know is how to detect such inverted objects. A real nightmare. I spent the whole morhing on this.

01-13-2004, 07:20 AM
It's ok now I found the reason why. The problem came from my lightnings. I didn't understand what happened but I just changed the lights and all is ok now.