OBJ: fixed some faces wrongly skipped in invalid face validation logic (#104593)

The logic for looping over imported OBJ faces and checking whether any
of them are "invalid" (duplicate vertices) was wrongly skipping
validation of the next face right after some invalid face. It
was the previously invalid face, moving the last into its place,
but then the loop was incrementing the face index and that just-moved
face was not properly validated.

Fixes #104593 - importing attached obj file (which contains some faces
that have duplicate indices). Added test coverage with a much smaller
obj file.
This commit is contained in:
Aras Pranckevicius 2023-02-14 21:49:03 +02:00
parent e1a29b58bb
commit db2eaa5c86
2 changed files with 11 additions and 0 deletions

@ -86,6 +86,7 @@ void MeshFromGeometry::fixup_invalid_faces()
/* Skip and remove faces that have fewer than 3 corners. */
mesh_geometry_.total_loops_ -= curr_face.corner_count_;
mesh_geometry_.face_elements_.remove_and_reorder(face_idx);
--face_idx;
continue;
}
@ -128,6 +129,7 @@ void MeshFromGeometry::fixup_invalid_faces()
/* Remove the invalid face. */
mesh_geometry_.total_loops_ -= curr_face.corner_count_;
mesh_geometry_.face_elements_.remove_and_reorder(face_idx);
--face_idx;
Vector<Vector<int>> new_faces = fixup_invalid_polygon(global_vertices_.vertices, face_verts);

@ -486,6 +486,15 @@ TEST_F(obj_importer_test, import_faces_invalid_or_with_holes)
import_and_check("faces_invalid_or_with_holes.obj", expect, std::size(expect), 0);
}
TEST_F(obj_importer_test, import_invalid_faces)
{
Expectation expect[] = {
{"OBCube", OB_MESH, 8, 12, 6, 24, float3(1, 1, -1), float3(-1, 1, 1)},
{"OBTheMesh", OB_MESH, 5, 3, 1, 3, float3(-2, 0, -2), float3(0, 2, 0)},
};
import_and_check("invalid_faces.obj", expect, std::size(expect), 0);
}
TEST_F(obj_importer_test, import_invalid_indices)
{
Expectation expect[] = {