Skip to content

Commit

Permalink
fix _num_faces_per_mesh in join_batch
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bottler authored and facebook-github-bot committed Mar 9, 2022
1 parent 16d0aa8 commit 4a1f176
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pytorch3d/renderer/mesh/textures.py
Expand Up @@ -569,7 +569,7 @@ def join_batch(self, textures: List["TexturesAtlas"]) -> "TexturesAtlas":

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
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def join_batch(self, textures: List["TexturesUV"]) -> "TexturesUV":
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()
Expand Down
10 changes: 10 additions & 0 deletions tests/test_render_meshes.py
Expand Up @@ -793,7 +793,12 @@ def test_join_uvs_simple(self):
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()
Expand Down Expand Up @@ -904,7 +909,12 @@ def test_join_atlas(self):
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)
Expand Down

0 comments on commit 4a1f176

Please sign in to comment.