Topic : Reordering Face Vertex Indices
Author : Paul Nettle
Page : 1

Properly Reordering Face Vertex Indices (y/z swap)
by Paul Nettle


What
The purpose of this WWH is to explain how to properly re-order the face indices of triangular polygon patches when the Y/Z is swapped.

Why
Some 3D modellers (3DS for example) swap the Y and Z components of the vertex locations.

Simply swapping them can potentially cause the face normal to be inverted, if the faces are required to be in clockwise or counter-clockwise order.

How
There is a strange thing called a 3DS file that is a bit of a mystery to many. One thing I've found is that you need to swap the Y/Z components of any 3D coodinate (lights, verticies, camera location and target, etc...).

This poses a problem with the face normals since the order of the face indicies makes the difference between a face properly oriented (the face's normal facing outward) or not (the face's normal facing inward).

The "fix" is simple (do all of this in floating point for best accuracy).

First, calculate the normal of the original face using the actual values from the 3ds file (without the verticies' Y/Z swapped). This is done using the cross-product method.

Normalize it (make it a unit vector).

Swap the DY and DZ components of this normal.

Save it off into "RealNorm"

Now, you need to make a new face by swapping the Y/Z components of the verticies that make up this face. Unfortunately, you need to do this, and it re-arranges the proper clock-wise order of the verticies, messing up your nice outward-facing normal. Here's how to fix it:

With your new face, calculate it's normal, and normalize it (just like before).

If the "RealNorm" and this normal are identical, then use that vertex order (currently A,B,C -- the default)

If not, try each of the following orders until you find one that is the same (there WILL be one):

A,C,B
B,A,C
B,C,A
C,A,B
C,B,A


When you find a vertex order that produces the proper normal, you have found the proper vertex orientation order.



Page : 1