My first comment is that averaging 3D vectors is an ill defined operation. It really doesn't work 100% as you might expect. But it can be useful. My second comment is that generating smooth geometric normals for a polygonal mesh is also problematic. There isn't really a good definition of how that should be done.
For an extreme example, average and normalize the three normals (1,0,0), (-1,0,0) and (0,1,0) and you get (0,1,0), which is probably not what you'd want.
That said, if you want to make a picture in which a polygonal mesh
appears to be smooth, a good (i.e. fast) way to do this is to approximate the normal at the corners of each polygon and interpolate those as you do colors and texture coordinates. That's how the majority of 3D graphics today works.
Anim8or computes vertex normals like this:
1) Compute a geometric normal for the polygon by computing all of the individual corner's normals.
2) Pick the one with the angle closest to 90 degrees of all corners. This is the "Face Normal" that you are accessing in the script.
3) Compute "Smooth Groups" for all faces in a mesh. These are faces that are adjoined by solid angles less than or equal to the "Smooth Angle" of the mesh. This is a fairly complex computation because you first need to compute the connectedness of the faces and then propagate smooth group id's across it.
4) For each vertex of each polygon, average all the normals of any faces common to that vertex that are in the same smooth group. (Yes, I know I said that the average isn't well defined, but it's the best fast way to do this that I know of
)
A better way to do step #4 might be to weight each normal by the magnitude of the angle of it's corner of the polygon. That way narrow corners won't get as much weight as wider ones which could eliminate some of the artifacts. Someday I'll get time to look into this
Raxx: GetFaceNormal returns the result of step 4. So you are averaging the
vertex normals which does not yield the value of the
face normals. Unfortunately, at this time ASL does not have a function to return the face normal but I'll add one.