diff --git a/pytorch3d/renderer/mesh/textures.py b/pytorch3d/renderer/mesh/textures.py index c9f4308f..d0bbe82f 100644 --- a/pytorch3d/renderer/mesh/textures.py +++ b/pytorch3d/renderer/mesh/textures.py @@ -569,7 +569,7 @@ class TexturesAtlas(TexturesBase): atlas_list = [] atlas_list += self.atlas_list() - num_faces_per_mesh = self._num_faces_per_mesh + num_faces_per_mesh = self._num_faces_per_mesh.copy() for tex in textures: atlas_list += tex.atlas_list() num_faces_per_mesh += tex._num_faces_per_mesh @@ -1073,7 +1073,7 @@ class TexturesUV(TexturesBase): faces_uvs_list += self.faces_uvs_list() verts_uvs_list += self.verts_uvs_list() maps_list += self.maps_list() - num_faces_per_mesh = self._num_faces_per_mesh + num_faces_per_mesh = self._num_faces_per_mesh.copy() for tex in textures: verts_uvs_list += tex.verts_uvs_list() faces_uvs_list += tex.faces_uvs_list() diff --git a/tests/test_render_meshes.py b/tests/test_render_meshes.py index e8b757c1..ff6c8bf4 100644 --- a/tests/test_render_meshes.py +++ b/tests/test_render_meshes.py @@ -793,7 +793,12 @@ class TestRenderMeshes(TestCaseMixin, unittest.TestCase): faces_uvs=torch.arange(150).reshape(1, 50, 3), verts_uvs=torch.rand(1, 150, 2) * 0.2 + 0.3, ) + self.assertEqual(a._num_faces_per_mesh, [100]) + self.assertEqual(b._num_faces_per_mesh, [50]) c = a.join_batch([b]).join_scene() + self.assertEqual(a._num_faces_per_mesh, [100]) + self.assertEqual(b._num_faces_per_mesh, [50]) + self.assertEqual(c._num_faces_per_mesh, [150]) color = c.faces_verts_textures_packed() color1 = color[:100, :, 0].flatten() @@ -904,7 +909,12 @@ class TestRenderMeshes(TestCaseMixin, unittest.TestCase): textures2 = TexturesAtlas(atlas=[atlas2]) mesh1 = Meshes(verts=[verts], faces=[faces], textures=textures1) mesh2 = Meshes(verts=[verts_shifted1], faces=[faces], textures=textures2) + self.assertEqual(textures1._num_faces_per_mesh, [len(faces)]) + self.assertEqual(textures2._num_faces_per_mesh, [len(faces)]) mesh_joined = join_meshes_as_scene([mesh1, mesh2]) + self.assertEqual(textures1._num_faces_per_mesh, [len(faces)]) + self.assertEqual(textures2._num_faces_per_mesh, [len(faces)]) + self.assertEqual(mesh_joined.textures._num_faces_per_mesh, [len(faces) * 2]) R, T = look_at_view_transform(18, 0, 0) cameras = FoVPerspectiveCameras(device=device, R=R, T=T)