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
This commit is contained in:
Jeremy Reizenstein 2022-05-24 01:40:22 -07:00 committed by Facebook GitHub Bot
parent d27ef14ec7
commit 90d00f1b2b
2 changed files with 10 additions and 1 deletions

View File

@ -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:

View File

@ -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