Fix to prevent undefined normals being generated with `add_face_normals()', from triangles with zero area.
This commit is contained in:
@@ -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];
|
||||
|
Reference in New Issue
Block a user