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

The purpose of a WWH is to expand one's knowledge on a topic they already understand, but need a reference, a refresher course, or to simply extend what they already know about the topic.

WWH is the quick tutor. Just the [W]hat, [W]hy and [H]ow

WWHProperly reordering face vertex indices (y/z swap)
Text version1.0
Written byPaul Nettle (midnight@grafix3d.tzo.com)
Last ModifiedMay 18, 1997
PrerequisitesGeneral polygon manipulation

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.

  1. Normalize it (make it a unit vector).

  2. Swap the DY and DZ components of this normal.

  3. Save it off into "RealNorm"

  4. 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:

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

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

    3. 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

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

Discuss this article in the forums


Date this article was posted to GameDev.net: 8/23/1999
(Note that this date does not necessarily correspond to the date the article was written)

See Also:
WWH Series

© 1999-2011 Gamedev.net. All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!