Jump to content
  • Advertisement
  • 08/23/99 09:53 PM
    Sign in to follow this  

    WWH - Properly Reordering Face Vertex Indices (y/z swap)

    Graphics and GPU Programming

    Myopic Rhino
    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


    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.


    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.


    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):

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

      Report Article
    Sign in to follow this  

    User Feedback

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!