View Full Version : Problems with normals
03-27-2009, 04:48 AM
Hi I'm reading in models exported from 3DS Max (.ase file) and I'm also exporting the normal data from max in the same file. I read the normals in, hold them in an array and define the normals before each vertex of each triangle is drawn. What I end up with looks like this:
The normals are obviously working but they aren't oriented/lined up correctly or something? Has anyone seen this before or can offer any advice?
03-27-2009, 08:50 AM
That is quite a redefinition of "obviously working" :)
Try with a very basic simple solid such as a cube, and trace carefully your import of normals, from the file to the triangle drawn.
You have to understand that a vertex may have different normals, one for each triangle it belongs to, to display correct hard edges.
03-28-2009, 10:32 AM
1. since the coordinate system used in 3DSMAX is different from that in OpenGL, we should do some necessary convert work to the normals( as well as the vertex position )
2. the normals exported by 3DS are defined per-triangle, that means every three verts on the same face have the same normal vector. To avoid inconsistent shade change across the edge, we'd better blend the normals of the adjacent verts to get a smooth surface, that is, calculate their average.
3. assure the light sources are set correctly and properly.
03-30-2009, 10:56 AM
Thanks for your replies guys. :)
I guess that my problem is to do with each vertex having a different normal value for each facet that it's a member of. At the moment I'm storing the normal values in an 4D array like this:
Object - Facets in the object - Vertices in the facet - (X,Y,Z) Normal values per vertex
So I think that if a vertex has more than one normal value then it would be over-written in the array as the data is read in.
How can I adapt my code design to accommodate more than one normal value per vertex? Add another dimension to the array?
With regards to the other points, the light should be working fine, and the coordinate system is rotated to be like Max's (ie Y is swapped with Z - a 90 deg rotation about the X axis) so I dont think that they are the problem.
Thanks for your assistance!
03-30-2009, 12:57 PM
A 4D (or even 5D) array is totally not appropriate. Different objects have different vertex count.
Better way would be to have array holding 1 pointer to each object.
An object is this case would be a struct having a pointer to an array of faces, each holding the id or pointer of the vertex. Separately, for each vertex id, store its position and normal.
03-31-2009, 09:13 AM
Well I simplified things and swapped to Flat shading using just one normal per facet and everything is working nicely.
The next thing is to average all the vertex normals to get smooth shading working.
When i mentioned before about using arrays, I'm using array pointers and calloc (in standard C) to make the arrays dynamically sized, which seems to be working nicely.
So just wanted to say thanks for all your help & insight!
03-31-2009, 10:07 AM
No problem with arrays. But you talked about 4 and 5 D arrays, which is wrong.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.