Fix to prevent undefined normals being generated with `add_face_normals()', from triangles with zero area.

This commit is contained in:
Stuart Broadfoot
2013-01-01 19:44:09 +00:00
parent 247c7078bc
commit 178a877a95
2 changed files with 19 additions and 5 deletions

View File

@@ -178,7 +178,12 @@ void Mesh::add_face_normals()
float3 v1 = verts_ptr[t.v[1]];
float3 v2 = verts_ptr[t.v[2]];
fN[i] = normalize(cross(v1 - v0, v2 - v0));
float3 norm = cross(v1 - v0, v2 - v0);
float normlen = len(norm);
if(normlen == 0.0f)
fN[i] = make_float3(0.0f, 0.0f, 0.0f);
else
fN[i] = norm / normlen;
if(flip)
fN[i] = -fN[i];