def test_import_with_material(self, scene_paths, out_dir, hetero_subsets_materials_mesh_path): """Test that imports materials from mesh with subsets""" out_path = os.path.join(out_dir, 'homogenized_materials.usda') mesh = usd.import_mesh(hetero_subsets_materials_mesh_path, scene_path='/Root', heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_naive_homogenize, with_materials=False) assert mesh.materials is None assert mesh.materials_order is None mesh = usd.import_mesh(hetero_subsets_materials_mesh_path, scene_path='/Root', heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_naive_homogenize, with_materials=True) assert mesh.materials is not None assert mesh.materials_order is not None
def test_export_only_face_uvs(self, out_dir, mesh): out_path = os.path.join(out_dir, 'only_uvs.usda') usd.export_mesh(out_path, uvs=mesh.uvs, face_uvs_idx=mesh.face_uvs_idx) mesh_in = usd.import_mesh(out_path) assert torch.allclose(mesh_in.uvs.view(-1, 2), mesh.uvs.view(-1, 2)) assert torch.equal(mesh_in.face_uvs_idx.view(-1), mesh.face_uvs_idx.view(-1))
def test_export_only_face_normals(self, out_dir, mesh): out_path = os.path.join(out_dir, 'only_normals.usda') usd.export_mesh(out_path, face_normals=mesh.vertex_normals[mesh.face_normals]) mesh_in = usd.import_mesh(out_path) assert torch.allclose( mesh_in.face_normals.view(-1, 3), mesh.vertex_normals[mesh.face_normals].view(-1, 3))
def test_import_single_flattened(self, scene_paths, out_dir, mesh, mesh_alt): """Will flatten all meshes in USD into a single mesh.""" out_path = os.path.join(out_dir, self.file_name) mesh_in = usd.import_mesh(out_path) assert len(mesh_in.vertices) == (len(mesh.vertices) + len(mesh_alt.vertices)) assert len(mesh_in.faces) == (len(mesh.faces) + len(mesh_alt.faces))
def test_import_st_no_indices_facevarying(self, out_dir, mesh): out_path = os.path.join(out_dir, 'st_no_indices_face_varying.usda') uvs = torch.rand((mesh.faces.size(0) * mesh.faces.size(1), 2)) scene_path = '/World/mesh_0' usd.export_mesh(out_path, scene_path=scene_path, vertices=mesh.vertices, faces=mesh.faces, uvs=uvs) # check that interpolation was set correctly to 'faceVarying' stage = Usd.Stage.Open(out_path) pv = UsdGeom.Mesh(stage.GetPrimAtPath(scene_path)).GetPrimvar('st') assert pv.GetInterpolation() == 'faceVarying' mesh_in = usd.import_mesh(out_path) assert torch.allclose(mesh_in.uvs, uvs)
def test_import_hetero_homogenize_import_mesh(self, scene_paths, out_dir, hetero_mesh_path): """Test that imports homogeneous mesh when importing heterogeneous mesh with naive homogenize handler""" # TODO(jlafleche) Render meshes before/after homogenize operation out_path = os.path.join(out_dir, 'homogenized.usda') mesh = usd.import_mesh(hetero_mesh_path, scene_path='/Root', heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_naive_homogenize) usd.export_mesh(out_path, '/World/Rocket', vertices=mesh.vertices, faces=mesh.faces) # Confirm we now have a triangle mesh assert mesh.faces.size(1) == 3 # Confirm exported USD matches golden file golden = os.path.join(out_dir, '../../../../samples/golden/rocket_homogenized.usda') assert open(golden).read() == open(out_path).read()
def test_import_material_subsets(self, scene_paths, out_dir, hetero_subsets_materials_mesh_path): """Test that imports materials from mesh with subsets""" out_path = os.path.join(out_dir, 'homogenized_materials.usda') mesh = usd.import_mesh(hetero_subsets_materials_mesh_path, scene_path='/Root', heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_naive_homogenize, with_materials=True) usd.export_mesh(out_path, '/World/Rocket', vertices=mesh.vertices, faces=mesh.faces, materials_order=mesh.materials_order, materials=mesh.materials, uvs=mesh.uvs) # Confirm we now have a triangle mesh assert mesh.faces.size(1) == 3 # Confirm exported USD matches golden file golden = os.path.join(out_dir, '../../../../samples/golden/rocket_homogenized_materials.usda') assert open(golden).read() == open(out_path).read()
def test_import_st_indices_facevarying(self, out_dir, mesh): out_path = os.path.join(out_dir, 'st_indices.usda') uvs = torch.rand((100, 2)) scene_path = '/World/mesh_0' face_uvs_idx = (torch.rand(mesh.faces.shape[:2]) * 99).long() usd.export_mesh(out_path, scene_path=scene_path, vertices=mesh.vertices, faces=mesh.faces, uvs=uvs, face_uvs_idx=face_uvs_idx) # check that interpolation was set correctly to 'vertex' stage = Usd.Stage.Open(out_path) pv = UsdGeom.Mesh(stage.GetPrimAtPath(scene_path)).GetPrimvar('st') assert pv.GetInterpolation() == 'faceVarying' mesh_in = usd.import_mesh(out_path) assert torch.allclose(mesh_in.uvs, uvs) assert torch.equal(mesh_in.face_uvs_idx, face_uvs_idx)
def test_export_only_faces(self, out_dir, mesh): out_path = os.path.join(out_dir, 'only_faces.usda') usd.export_mesh(out_path, faces=mesh.faces) mesh_in = usd.import_mesh(out_path) assert torch.allclose(mesh_in.faces, mesh.faces)
def test_export_only_face_uvs(self, out_dir, mesh): out_path = os.path.join(out_dir, 'only_uvs.usda') usd.export_mesh(out_path, vertices=mesh.vertices, faces=mesh.faces, uvs=mesh.uvs) mesh_in = usd.import_mesh(out_path) assert torch.allclose(mesh_in.uvs.view(-1, 2), mesh.uvs.view(-1, 2))
def test_import_hetero_empty_import_mesh(self, scene_paths, out_dir, hetero_mesh_path): """Test that imports empty mesh when importing heterogeneous mesh with empty handler""" mesh = usd.import_mesh(hetero_mesh_path, scene_path='/Root', heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_empty) assert len(mesh[0]) == 0
def test_import_hetero_fail_import_mesh(self, scene_paths, out_dir, hetero_mesh_path): """Test that import fails when importing heterogeneous mesh without handler""" with pytest.raises(usd.NonHomogeneousMeshError): usd.import_mesh(file_path=hetero_mesh_path, scene_path='/Root')