Skip to content

Commit 4a1f176

Browse files
bottlerfacebook-github-bot
authored andcommitted
fix _num_faces_per_mesh in join_batch
Summary: As reported in #1100, _num_faces_per_mesh was changing in the source mesh in join_batch. This affects both TexturesUV and TexturesAtlas Reviewed By: nikhilaravi Differential Revision: D34643675 fbshipit-source-id: d67bdaca7278f18a76cfb15ba59d0ea85575bd36
1 parent 16d0aa8 commit 4a1f176

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pytorch3d/renderer/mesh/textures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def join_batch(self, textures: List["TexturesAtlas"]) -> "TexturesAtlas":
569569

570570
atlas_list = []
571571
atlas_list += self.atlas_list()
572-
num_faces_per_mesh = self._num_faces_per_mesh
572+
num_faces_per_mesh = self._num_faces_per_mesh.copy()
573573
for tex in textures:
574574
atlas_list += tex.atlas_list()
575575
num_faces_per_mesh += tex._num_faces_per_mesh
@@ -1073,7 +1073,7 @@ def join_batch(self, textures: List["TexturesUV"]) -> "TexturesUV":
10731073
faces_uvs_list += self.faces_uvs_list()
10741074
verts_uvs_list += self.verts_uvs_list()
10751075
maps_list += self.maps_list()
1076-
num_faces_per_mesh = self._num_faces_per_mesh
1076+
num_faces_per_mesh = self._num_faces_per_mesh.copy()
10771077
for tex in textures:
10781078
verts_uvs_list += tex.verts_uvs_list()
10791079
faces_uvs_list += tex.faces_uvs_list()

tests/test_render_meshes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,12 @@ def test_join_uvs_simple(self):
793793
faces_uvs=torch.arange(150).reshape(1, 50, 3),
794794
verts_uvs=torch.rand(1, 150, 2) * 0.2 + 0.3,
795795
)
796+
self.assertEqual(a._num_faces_per_mesh, [100])
797+
self.assertEqual(b._num_faces_per_mesh, [50])
796798
c = a.join_batch([b]).join_scene()
799+
self.assertEqual(a._num_faces_per_mesh, [100])
800+
self.assertEqual(b._num_faces_per_mesh, [50])
801+
self.assertEqual(c._num_faces_per_mesh, [150])
797802

798803
color = c.faces_verts_textures_packed()
799804
color1 = color[:100, :, 0].flatten()
@@ -904,7 +909,12 @@ def test_join_atlas(self):
904909
textures2 = TexturesAtlas(atlas=[atlas2])
905910
mesh1 = Meshes(verts=[verts], faces=[faces], textures=textures1)
906911
mesh2 = Meshes(verts=[verts_shifted1], faces=[faces], textures=textures2)
912+
self.assertEqual(textures1._num_faces_per_mesh, [len(faces)])
913+
self.assertEqual(textures2._num_faces_per_mesh, [len(faces)])
907914
mesh_joined = join_meshes_as_scene([mesh1, mesh2])
915+
self.assertEqual(textures1._num_faces_per_mesh, [len(faces)])
916+
self.assertEqual(textures2._num_faces_per_mesh, [len(faces)])
917+
self.assertEqual(mesh_joined.textures._num_faces_per_mesh, [len(faces) * 2])
908918

909919
R, T = look_at_view_transform(18, 0, 0)
910920
cameras = FoVPerspectiveCameras(device=device, R=R, T=T)

0 commit comments

Comments
 (0)