Computing .XFile Mesh Normals

Started by
0 comments, last by uavfun 18 years, 10 months ago
Does anybody know how to compute mesh normals? I'm trying to make an automated procedure to take in mesh files and computes the mesh normal. The automated normal creator doesn't work like I need it to. I've included a basic box and need normals to be perpendicular to the main sides. If you have any idea could you please include the calculations. Thank you very much, TestBox.x ------------------------------------ xof 0303txt 0032 # Created By Joshua Mesh v0{ 8; 268.00; 365.00; 0.00;, 852.00; 363.00; 0.00;, 267.00; 354.00; 0.00;, 851.00; 352.00; 0.00;, 268.00; 365.00; 200.00;, 852.00; 363.00; 200.00;, 267.00; 354.00; 200.00;, 851.00; 352.00; 200.00;; 12; 3; 0,1,3;, 3; 0,3,2;, 3; 0,5,1;, 3; 0,4,5;, 3; 0,2,6;, 3; 0,6,4;, 3; 4,7,5;, 3; 4,6,7;, 3; 1,7,3;, 3; 1,5,7;, 3; 2,3,7;, 3; 2,7,6;; MeshTextureCoords { 8; 0.0;2.22;, 1.11;2.22;, 1.11;2.22;, 0.0;2.22;, 0.0;0.0;, 1.11;0.0;, 1.11;0.0;, 0.0;0.0;; } MeshMaterialList { 3; 12; 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2;; Material { 0.753;0.565;0.341;0.000;; 0.00; 0.00;0.00;0.00;; 0.00;0.00;0.00;; } Material { 0.000;0.004;0.000;0.000;; 0.00; 0.00;0.00;0.00;; 0.00;0.00;0.00;; } Material { 0.753;0.565;0.341;0.000;; 0.00; 0.00;0.00;0.00;; 0.00;0.00;0.00;; } } }
Advertisement
Say you have a flat polygon with vertices A, B, and C (it doesn't matter which you pick, as long as the poly is flat). You can construct two vectors v1 = A - B and v2 = B - C that are parallel to the polygon's plane but not parallel to each other. If you take their cross product, you'll get the normal of that polygon. If it comes out inside out then swap the order you do the cross product in.

For something like a box you can just use the same normal for every vertex on a face. If you wanted to make, say, a sphere, you'd blend the normals of the faces touching each vertex together, and use a different normal for each point on the sphere.

This topic is closed to new replies.

Advertisement