From 90d00f1b2be4b2f2c5eec40dd10894b2a449fbdf Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Tue, 24 May 2022 01:40:22 -0700 Subject: [PATCH] PLY heterogenous faces fix Summary: PLY with mixture of triangle and quadrilateral faces was failing. Reviewed By: gkioxari Differential Revision: D36592981 fbshipit-source-id: 5373edb2f38389ac646a75fd2e1fa7300eb8d054 --- pytorch3d/io/ply_io.py | 2 +- tests/test_io_ply.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pytorch3d/io/ply_io.py b/pytorch3d/io/ply_io.py index 77cd8fbc..5ec7f662 100644 --- a/pytorch3d/io/ply_io.py +++ b/pytorch3d/io/ply_io.py @@ -1043,7 +1043,7 @@ def _load_ply(f, *, path_manager: PathManager) -> _PlyData: faces = torch.LongTensor(np.vstack(face_arrays).astype(np.int64)) else: face_list = [] - for face_item in face: + for (face_item,) in face: if face_item.ndim != 1: raise ValueError("Bad face data.") if face_item.shape[0] < 3: diff --git a/tests/test_io_ply.py b/tests/test_io_ply.py index 8297765e..98394a34 100644 --- a/tests/test_io_ply.py +++ b/tests/test_io_ply.py @@ -195,6 +195,15 @@ class TestMeshPlyIO(TestCaseMixin, unittest.TestCase): ): io.load_mesh(f3.name) + def test_heterogenous_verts_per_face(self): + # The cube but where one face is pentagon not square. + text = CUBE_PLY_LINES.copy() + text[-1] = "5 3 7 4 0 1" + stream = StringIO("\n".join(text)) + verts, faces = load_ply(stream) + self.assertEqual(verts.shape, (8, 3)) + self.assertEqual(faces.shape, (13, 3)) + def test_save_too_many_colors(self): verts = torch.tensor( [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]], dtype=torch.float32