Skip to content

Commit

Permalink
Check validity of normals of blender mesh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste Nicolet committed May 14, 2020
1 parent b15b6c5 commit 74c0f2a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librender/mesh.cpp
Expand Up @@ -204,7 +204,11 @@ MTS_VARIANT Mesh<Float, Spectrum>::Mesh(
// flat shading, use per face normals
const InputVector3f e1 = face_points[1] - face_points[0];
const InputVector3f e2 = face_points[2] - face_points[0];
normal = normalize(m_to_world.transform_affine(cross(e1, e2)));
normal = m_to_world.transform_affine(cross(e1, e2));
if(unlikely(all(normal==0.0f)))
continue; // Degenerate triangle, ignore it
else
normal = normalize(normal);
}
for (int i = 0; i < 3; i++) {
const size_t loop_index = tri_loop.tri[i];
Expand All @@ -216,8 +220,11 @@ MTS_VARIANT Mesh<Float, Spectrum>::Mesh(
Key vert_key;
if (blender::ME_SMOOTH & face.flag) {
// smooth shading, store per vertex normals
normal = InputNormal3f(vert.no[0], vert.no[1], vert.no[2]);
normal = normalize(m_to_world.transform_affine(normal));
normal = m_to_world.transform_affine(InputNormal3f(vert.no[0], vert.no[1], vert.no[2]));
if(unlikely(all(normal==0.0f)))
fail("Mesh has invalid normals!");
else
normal = normalize(normal);
vert_key.smooth = true;
} else {
// vert_key.smooth = false (default), flat shading
Expand Down

0 comments on commit 74c0f2a

Please sign in to comment.