From 0b704d0971d4a8ee4ccda5f302321643a8687904 Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Wed, 7 Apr 2021 13:21:55 -0700 Subject: [PATCH] workspace: Upgrade tinyobjloader to latest commit (#14866) Correct unit test based on tinyobj impl changes --- .../test/obj_to_surface_mesh_test.cc | 52 +++++++++++++------ tools/workspace/tinyobjloader/repository.bzl | 4 +- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/geometry/proximity/test/obj_to_surface_mesh_test.cc b/geometry/proximity/test/obj_to_surface_mesh_test.cc index e3da1bea572f..742a8fd07a80 100644 --- a/geometry/proximity/test/obj_to_surface_mesh_test.cc +++ b/geometry/proximity/test/obj_to_surface_mesh_test.cc @@ -100,26 +100,46 @@ GTEST_TEST(ObjToSurfaceMeshTest, ReadObjToSurfaceMesh) { EXPECT_EQ(expect_vertices[i], surface.vertex(SurfaceVertexIndex(i)).r_MV()); } - // This test relies on the specific content of the file quad_cube.obj. The - // last section of quad_cube.obj describes the six square faces of the cube. - // We expect that each square is subdivided into two triangles. Note that - // vertex indices in the file quad_cube.obj are from 1 to 8, but tinyobj - // has vertex indices from 0 to 7. We assume that tinyobj subdivides a - // polygon into a triangle fan around the first vertex; polygon ABCDE... - // becomes triangles ABC, ACD, ADE, etc. + // TODO(SeanCurtis-TRI) Devise a formulation of this that is less sensitive + // to the details of the triangulation algorithm. + // This test is brittle. It depends on: + // - the exact construction of quad faces in quad_cube.obj. + // - the algorithm that tinyobj uses to triangulate n-gons into triangles. + // While we have 100% control over the former, we have no control over the + // latter. History has shown that the algorithm changes. In the past, it + // would create a fan around the *first* declared vertex, this current + // encoding creates a fan around the second. In other words, it's the + // difference between the following two triangulations + // + // ┌───┐ ┌───┐ + // │╲ │ │ ╱│ + // │ ╲ │ │ ╱ │ + // │ ╲│ │╱ │ + // └───┘ └───┘ + // + // This test may fail with subsequent updates to the triangulation algorithm. int expect_faces[12][3] { - {0, 1, 2}, {0, 2, 3}, // face 1 2 3 4 in quad_cube.obj - {4, 7, 6}, {4, 6, 5}, // face 5 8 7 6 in quad_cube.obj - {0, 4, 5}, {0, 5, 1}, // face 1 5 6 2 in quad_cube.obj - {1, 5, 6}, {1, 6, 2}, // face 2 6 7 3 in quad_cube.obj - {2, 6, 7}, {2, 7, 3}, // face 3 7 8 4 in quad_cube.obj - {4, 0, 3}, {4, 3, 7} // face 5 1 4 8 in quad_cube.obj + {0, 1, 3}, {1, 2, 3}, // face 1 2 3 4 in quad_cube.obj + {4, 7, 5}, {7, 6, 5}, // face 5 8 7 6 in quad_cube.obj + {0, 4, 1}, {4, 5, 1}, // face 1 5 6 2 in quad_cube.obj + {1, 5, 2}, {5, 6, 2}, // face 2 6 7 3 in quad_cube.obj + {2, 6, 3}, {6, 7, 3}, // face 3 7 8 4 in quad_cube.obj + {4, 0, 7}, {0, 3, 7} // face 5 1 4 8 in quad_cube.obj }; - auto face_equal = [](const SurfaceFace& f, const SurfaceFace& g) -> bool { - return std::make_tuple(f.vertex(0), f.vertex(1), f.vertex(2)) == - std::make_tuple(g.vertex(0), g.vertex(1), g.vertex(2)); + auto face_equal = [](const SurfaceFace& f, + const SurfaceFace& g) -> ::testing::AssertionResult { + const auto f_indices = + std::make_tuple(f.vertex(0), f.vertex(1), f.vertex(2)); + const auto g_indices = + std::make_tuple(g.vertex(0), g.vertex(1), g.vertex(2)); + if (f_indices == g_indices) return ::testing::AssertionSuccess(); + return ::testing::AssertionFailure() + << "\n Expected: " << f.vertex(0) << ", " << f.vertex(1) << ", " + << f.vertex(2) << "\n Found: " << g.vertex(0) << ", " << g.vertex(1) + << ", " << g.vertex(2); }; + for (int i = 0; i < 12; ++i) { EXPECT_TRUE(face_equal(SurfaceFace(expect_faces[i]), surface.element(SurfaceFaceIndex(i)))); diff --git a/tools/workspace/tinyobjloader/repository.bzl b/tools/workspace/tinyobjloader/repository.bzl index 60f38d7b1404..4736d6e77866 100644 --- a/tools/workspace/tinyobjloader/repository.bzl +++ b/tools/workspace/tinyobjloader/repository.bzl @@ -8,8 +8,8 @@ def tinyobjloader_repository( github_archive( name = name, repository = "tinyobjloader/tinyobjloader", - commit = "9173980d1de273b17eba5e10eb189e8b4be89425", - sha256 = "fe06bf462bf386ea7f6bf34f94c78099c849df348d4a6df681707fba5b5b643c", # noqa + commit = "15bc2685b51612748bcfdb820bb4d42087a7dce1", + sha256 = "a5a4b72db1799621567e156853e92215d07a21b3d84098990e0dd79645cce647", # noqa build_file = "@drake//tools/workspace/tinyobjloader:package.BUILD.bazel", # noqa mirrors = mirrors, patches = [