Does anyone know of a fast routine to make
all the normals of a model point the same
way. i.e. all point outward or all inward

Thanks in advance

What exactly are you trying to do ?

Just loop through all your polygons, and calculate the crossproduct of the two vectors building the polygon.

Like this.

p = p2 - p1
q = p3 - p2

n.x = p.y * q.z - p.z * q.y;
n.y = p.z * q.x - p.x * q.z;
n.z = p.x * q.y - p.y * q.x;

p1 is first point in your triangle, p2 is second and p3 is third
n is your normal.

And what do you mean by fast? Planing to recalculate the normal each frame?

For proper vertex lighting you’ll also want to scale down the resulting vector (the vector n in Bob’s equation above) so that it’s of unit length.

A couple of thoughts:

  1. If you don’t mind processing your model data as a separate step, download Admesh from somewhere. It will verify normals.
  2. If all you have is a single surface and you only care about consistency (all in, or all out, but you don’t care which) then you can pick one facet and follow it’s edges around to neighboring facets and make sure that the orientations are all consistent. This is much, much easier if you are using some sort of topological data structure such as a winged-edge or quad-edge.
  3. This is a little bit of a hack, but I’m sure it can be made to work. You need a good, fast ray intersection algorithm or this is agonizingly slow. Compute a normal, offest a point from the facet in the direction of the normal, use the ray intersection test to determine if that point is inside or outside the model (i.e. count intersections with an arbirtary ray originating from the point in question, even # == outside, odd # == inside) and flip the normal as necessary.
    You can use one test as described in #3 in conjunction with each surface of the model to get the method of #2 to yield absolute inside or outside orientations.

After I wrote that I realized that I was being a little silly with #2 up there. If you’re using a winged-edge or quad-edge(half-edge, whatever) then consistent orientation is guaranteed as long as you built the data structure right in the first place. Guess I should think more before I speak .

[This message has been edited by Rob (edited 08-23-2000).]