From db2eaa5c8603c27b73248aa78d263cfab917c0a8 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Tue, 14 Feb 2023 21:49:03 +0200 Subject: [PATCH] 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. --- .../blender/io/wavefront_obj/importer/obj_import_mesh.cc | 2 ++ .../blender/io/wavefront_obj/tests/obj_importer_tests.cc | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 3c9d5663a43..aa89be9780c 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -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> new_faces = fixup_invalid_polygon(global_vertices_.vertices, face_verts); diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index b2ba10a7abd..62998a51d76 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -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[] = {