Allow setting verts_normals on Meshes

Summary: Add ability to set the vertex normals when creating a Meshes, so that the pluggable loaders can return them from a file.

Reviewed By: nikhilaravi

Differential Revision: D27765258

fbshipit-source-id: b5ddaa00de3707f636f94d9f74d1da12ecce0608
This commit is contained in:
Jeremy Reizenstein
2021-05-04 05:35:24 -07:00
committed by Facebook GitHub Bot
parent 502f15aca7
commit 2bbca5f2a7
3 changed files with 68 additions and 5 deletions

View File

@@ -223,7 +223,7 @@ class TestMeshNormalConsistency(unittest.TestCase):
Test Mesh Normal Consistency for a mesh known to have no
intersecting faces.
"""
verts = torch.rand(1, 6, 2)
verts = torch.rand(1, 6, 3)
faces = torch.arange(6).reshape(1, 2, 3)
meshes = Meshes(verts=verts, faces=faces)
out = mesh_normal_consistency(meshes)

View File

@@ -1138,6 +1138,20 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
self.assertEqual(meshes.faces_normals_padded().shape[0], 0)
self.assertEqual(meshes.faces_normals_list(), [])
def test_assigned_normals(self):
verts = torch.rand(2, 6, 3)
faces = torch.randint(6, size=(2, 4, 3))
for verts_normals in [list(verts.unbind(0)), verts]:
yes_normals = Meshes(
verts=verts.clone(), faces=faces, verts_normals=verts_normals
)
self.assertClose(yes_normals.verts_normals_padded(), verts)
yes_normals.offset_verts_(torch.FloatTensor([1, 2, 3]))
self.assertClose(yes_normals.verts_normals_padded(), verts)
yes_normals.offset_verts_(torch.FloatTensor([1, 2, 3]).expand(12, 3))
self.assertFalse(torch.allclose(yes_normals.verts_normals_padded(), verts))
def test_compute_faces_areas_cpu_cuda(self):
num_meshes = 10
max_v = 100