DXF normals

That normals are not fine…
In the top-left quarter of the sphere are fine, but apart from that it’s all messy!

Something’s happening!
My Handed-cube vertex seems like they where in clock wise order (but looking from which point???).
Now the light works fine on the cube, and is doing well on the sphere too, but the sphere is still messy.
Question is: why, since i load it in the same way as the cube?

Ok, is that supossed to be a perfect sphere, cause it looks like a sphere on one side and the other looks like one but after world war 2.

If it is a perfect sphere I take my comments back…
Post some code for your normal computations…

My Handed-cube vertex seems like they where in clock wise order (but looking from which point???).

The CW and CCW stuff is not relative a point in space, but from a direction relative the face itself. A triangle’s vertices are in CCW order if they are seen in CCW order when looking at the triangle’s front face. Looking at the back side will give you a different winding order. Take a piece of paper, make three points in CCW order and look at from the front side (the side on which you drew the points). Flip (not rotate) the paper, and you are looking at the back side. You will also see that the point are now in CW order instead.

So, CW/CCW is relative the front face (generally the face the normal is pointing out from) of the triangle, not a point in space.

Well, if CCW order is as seeing it from the front face, my hand-made cube vertexes are in CCW order.

I ended up with the following:
if I calculate the normals so that my hand-made cube is displayed well, using
glFrontFace(GL_CW)
and normals calculated as (v0-v1)x(v2-v1),
the sphere is better but still has parts with normals inverted, a head model I downloaded from the net is displayed well, but many other models have the back side of the faces lighted instead of the front ones.

If I calculate normals so that my hand-made cube has the back side of the faces lighted, using
“glFrontFace(GL_CCW)”
and normals calculated as (v0-v1)x(v1-v2),
all the models that were previously lighted wrong are lighted well, but the sphere and the head are not.

I’m going nuts…
By the way if I give three point a,b,c, with GL_TRIANGLES how are they painted?In a picture in the openGL programming guide (addison-wesley) the indexes are in lcockwise order!

Default is counterclockwise for front faces.
Best to do is enable GL_CULL_FACE, since then only front faces are drawn and assuming that averaged only 50% of your models faces are visible you gain some speed not drawing the back faces. And of course you see if the order of your tris is correct, too. If your models don’t show up correct with backfaceculling enabled forget about lighting and fix your order problems first.
I do not know how dxf stores it’s vertices but it seems like the format does not care about any special order (or there is something wrong in your loading routine).
So you have to make sure that all vertices are in the correct order for opengl (or debug your loading routine).
I just took a look at some dxf description (i never used this format) and I found an interesting sentence:
‘vertices CAN be order either clockwise or anticlockwise’
So you see that just loading your vertices is not enough for what you try to achieve. It depends on the dxf file if the vertices are ordered or not. So in your loading routine you have to take care of ordering yourself. Perhaps dxf is not the best format to work with, at least from what I have read I don’t like it.

Think you have some work to do now .

Originally posted by Pody:


I calculated the normals for each triangle (V0-V1)x(V1-V2):some trangles are rendered well,but others have the normals inverted.
What am i doing wrong?
Bye

If you are calculating the normal with those subtractions then I think they are probably wrong, you need to have the vectors pointing the same way:

(v0-v1)x(v2-v1)

Then you have them both pointing outward from v1. You can do it with any point, but your vectors must point in the same direction.

-Mezz

Yep, if I don’t solve these problems today, i think i’m givin’ up with that damn DXF (throwing away weeks of work ).
Now i’m doing some experiments with my hand-made DXF-cube: if i set CCW order,inside faces are lighted. Ok, but if i reverse the sign of the normals shouldn’t it be ok?
It is not! It is rendered in the same way!
If I change order to CW it goes well.
What the $#&%!!!
It seems openGL doesn’t care of the sign of the normal, but only if the order is set to CCW or CW

Correction: if I invert the sign of the normals, the faces are lit in the same way (inside), but with the light positioned in the opposite point.

Ok, f%$# the DXf.
I go with another format.
Any suggetion? 3DS?

Why not design your own model format and then write an exporter from a modeler?

You can get the 3DS MAX SDK and write quite simple exporters with it, if you don’t try for stuff like bones etc.

Alternatively, perhaps Quake2’s models (.md2) as they are quite easy to work with.

-Mezz

Thanks, but for now I think I’ll use the DXF files that work well.
I spent many days working on DXF, and I don’t want to begin from zero again.

Originally posted by Pody:
Thanks, but for now I think I’ll use the DXF files that work well.
I spent many days working on DXF, and I don’t want to begin from zero again.

Yea, the file format is not the problem, it only stored the vertices in what ever the way your DXF writer/reader rutine do. The adventage with DXF is they are ease to read/write, they are TXT file and severals CAD program can suport it. The disventage is that it mostly store just the vertices, but it lack other info like texturing data, etc.

Like the guys above said, disable the lights, disable the normals, enable the cullface and draw your model, check if all face in your model are rendered well.

For making all things go well all your faces model should have to be defined in the same direction, that is from counter clock wise or anti-counter close wise, this have to be done when your model was ORIGINAL drawn.

I suspect that you downloaded your teapot DXF model from Internet, or you are drawing your self the model using a CAD program. if so then most probably is that when the model was drawn in the CAD, some faces are defined in close-wise and some in anti-close wise, this is very comun when one is drawing in CAD tools. This not matter when you have the cull-face disabled cose all faces are rendered from both sides (back and front) so your model always can be see correctly, however when the cull-face is enabled or when the normalized is used then defining what faces are back and what faces are front is very important and relevant.

good luck.

tp.

Ok, so it’s not my fault if some polygons are reversed!

thanks for the explanation!
Bye
Luca

In fact, for example, i exported in DXF a face from 3ds Max, and my program renders it very well!