Computing Face Normals
 
 
 

A face normal is a vector that defines which way a face is pointing. The direction that the normal points represents the front, or outer surface of the face. To compute the face normal of a face in a mesh you simply take the cross product of two edge vectors of the face. The following code shows how this is done using the 3ds Max API. It loops through each face in a mesh and stores the computed face normal in a table of Point3s named fnorms. At the end of the code, the DebugPrint() API is used to display each normal in the table to the debug window of the VC++ IDE.

void Utility::ComputeFaceNormals(Mesh *mesh)
{
   Face *face;; 
   Point3 *verts;
   Point3 v0, v1, v2;
   Tab<Point3> fnorms;
 
   // Compute face (surface) normals for the mesh
   face = mesh->faces; 
   verts = mesh->verts;
   fnorms.SetCount(mesh->getNumFaces());
   for (int i = 0; i < mesh->getNumFaces(); i++, face++)
   {
     v0 = verts[face->v[0]];
     v1 = verts[face->v[1]];
     v2 = verts[face->v[2]];
     fnorms[i] = (v1-v0)^(v2-v1);
     fnorms[i] = Normalize(fnorms[i]);
   }
 
   // Display the normals in the debug window of the VC++ IDE
   DebugPrint("\n\nFace Normals ---";);
 
   for (i = 0; i < fnorms.Count(); i++)
   {
     DebugPrint("\nFaceNormal[%d]=(%.1f, %.1f, %.1f)",
     i, fnorms[i].x, fnorms[i].y, fnorms[i].z);
   }
   DebugPrint("\n\n");
}

As a side note on face normals -- If you take the length of a face normal vector (for example using the Point3::Length() method), you get a quantity equal to twice the surface area of that face.