Fix texture atlas for objs which only have material properties

Summary:
Fix for GitHub issue #381.

The example mesh provided in the issue only had material properties but no texture image. The current implementation of texture atlassing generated an atlas using both the material properties and the texture image but only worked if there was a texture image and associated vertex uv coordinates. I have now modified the texture atlas creation so that it doesn't require an image and can work with materials which only have material properties.

Reviewed By: gkioxari

Differential Revision: D24153068

fbshipit-source-id: 63e9d325db09a84b336b83369d5342ce588a9932
This commit is contained in:
Nikhila Ravi
2020-10-07 12:52:16 -07:00
committed by Facebook GitHub Bot
parent 5d65a0cf8c
commit f5383a7e5a
5 changed files with 87 additions and 37 deletions

View File

@@ -0,0 +1,7 @@
# Material Count: 1
newmtl material_1
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.500000 0.000000 0.000000
Ks 0.500000 0.500000 0.500000

View File

@@ -0,0 +1,10 @@
mtllib model.mtl
v 0.1 0.2 0.3
v 0.2 0.3 0.4
v 0.3 0.4 0.5
v 0.4 0.5 0.6
usemtl material_1
f 1 2 3
f 1 2 4

View File

@@ -559,6 +559,35 @@ class TestMeshObjIO(TestCaseMixin, unittest.TestCase):
self.assertTrue(aux.normals is None)
self.assertTrue(aux.verts_uvs is None)
def test_load_obj_mlt_no_image(self):
DATA_DIR = Path(__file__).resolve().parent / "data"
obj_filename = "obj_mtl_no_image/model.obj"
filename = os.path.join(DATA_DIR, obj_filename)
R = 8
verts, faces, aux = load_obj(
filename,
load_textures=True,
create_texture_atlas=True,
texture_atlas_size=R,
texture_wrap=None,
)
expected_verts = torch.tensor(
[[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [0.3, 0.4, 0.5], [0.4, 0.5, 0.6]],
dtype=torch.float32,
)
expected_faces = torch.tensor([[0, 1, 2], [0, 1, 3]], dtype=torch.int64)
self.assertTrue(torch.allclose(verts, expected_verts))
self.assertTrue(torch.allclose(faces.verts_idx, expected_faces))
# Check that the material diffuse color has been assigned to all the
# values in the texture atlas.
expected_atlas = torch.tensor([0.5, 0.0, 0.0], dtype=torch.float32)
expected_atlas = expected_atlas[None, None, None, :].expand(2, R, R, -1)
self.assertTrue(torch.allclose(aux.texture_atlas, expected_atlas))
self.assertEquals(len(aux.material_colors.keys()), 1)
self.assertEquals(list(aux.material_colors.keys()), ["material_1"])
def test_load_obj_missing_texture(self):
DATA_DIR = Path(__file__).resolve().parent / "data"
obj_filename = "missing_files_obj/model.obj"