diff --git a/pytorch3d/structures/meshes.py b/pytorch3d/structures/meshes.py index 7998aa06..dffcb3c5 100644 --- a/pytorch3d/structures/meshes.py +++ b/pytorch3d/structures/meshes.py @@ -1263,7 +1263,10 @@ class Meshes(object): """ verts_packed = self.verts_packed() if vert_offsets_packed.shape == (3,): + update_normals = False vert_offsets_packed = vert_offsets_packed.expand_as(verts_packed) + else: + update_normals = True if vert_offsets_packed.shape != verts_packed.shape: raise ValueError("Verts offsets must have dimension (all_v, 3).") # update verts packed @@ -1284,12 +1287,12 @@ class Meshes(object): # update face areas and normals and vertex normals # only if the original attributes are computed - if any( + if update_normals and any( v is not None for v in [self._faces_areas_packed, self._faces_normals_packed] ): self._compute_face_areas_normals(refresh=True) - if self._verts_normals_packed is not None: + if update_normals and self._verts_normals_packed is not None: self._compute_vertex_normals(refresh=True) return self diff --git a/tests/test_meshes.py b/tests/test_meshes.py index 2f8a712e..7dc7a15c 100644 --- a/tests/test_meshes.py +++ b/tests/test_meshes.py @@ -486,6 +486,7 @@ class TestMeshes(TestCaseMixin, unittest.TestCase): self.assertClose( new_mesh.verts_normals_list()[i], new_mesh_naive.verts_normals_list()[i], + atol=1e-6, ) self.assertClose( new_mesh.faces_normals_list()[i], @@ -533,10 +534,14 @@ class TestMeshes(TestCaseMixin, unittest.TestCase): # check face areas, normals and vertex normals self.assertClose( - new_mesh.verts_normals_packed(), new_mesh_naive.verts_normals_packed() + new_mesh.verts_normals_packed(), + new_mesh_naive.verts_normals_packed(), + atol=1e-6, ) self.assertClose( - new_mesh.verts_normals_padded(), new_mesh_naive.verts_normals_padded() + new_mesh.verts_normals_padded(), + new_mesh_naive.verts_normals_padded(), + atol=1e-6, ) self.assertClose( new_mesh.faces_normals_packed(), new_mesh_naive.faces_normals_packed()