WWH - Properly Reordering Face Vertex Indices (y/z swap)
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.
[size="5"]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.
[size="5"]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.
[size="5"]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.
Related Tutorials
Procedural Generation of 2D Tile Maps in Games
The article explains how to build a procedural 2D cave map generator using cellular automata. It covers map representat…
Localizing A Game Into French — Which Variant Should You Choose?
So, you’re making an awesome indie game, and now you’re thinking about localizing it into French? Great idea! There ar…
How Long Does It Take To Localize An Indie Game?
So you’re planning on localizing your indie game, but you’re not sure how much time to schedule in. While the timing o…
Creating game videos: best practices and pitfalls to avoid
Game video production: practical tips on how to create a game trailer or teaser that you can be proud of. Give your aud…
Adopting CI/CD: How Midwinter Entertainment iterates at speed with the help of IMS
Game development was once like one long sprint: a huge effort until you reached the finish line — at which point you co…
GameDev.net
5 Things to Consider When Making a Video to Promote Your App or Game
How can you show an app or game in your video in a way that attracts new users? Let’s take a look at what to go by when…
Discussion
More from Paul Nettle
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion