Beispiel #1
0
    def test_get_authored_time_samples_untimed(self, out_dir, mesh, voxelgrid):
        out_path = os.path.join(out_dir, 'untimed.usda')
        usd.export_voxelgrid(file_path=out_path, voxelgrid=voxelgrid, scene_path='/World/voxelgrid')
        usd.export_mesh(out_path, scene_path='/World/meshes', vertices=mesh.vertices, faces=mesh.faces)

        times = usd.get_authored_time_samples(out_path)
        assert times == []
Beispiel #2
0
 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))
Beispiel #3
0
    def test_get_authored_time_samples_timed(self, out_dir, mesh, voxelgrid,
                                             pointcloud):
        out_path = os.path.join(out_dir, 'timed.usda')
        usd.export_voxelgrid(file_path=out_path,
                             voxelgrid=voxelgrid,
                             scene_path='/World/voxelgrid')
        times = usd.get_authored_time_samples(out_path)
        assert times == []

        usd.export_voxelgrid(file_path=out_path,
                             voxelgrid=voxelgrid,
                             scene_path='/World/voxelgrid',
                             time=1)
        times = usd.get_authored_time_samples(out_path)
        assert times == [1]

        usd.export_mesh(out_path,
                        scene_path='/World/meshes',
                        vertices=mesh.vertices,
                        faces=mesh.faces,
                        time=20)
        usd.export_mesh(out_path,
                        scene_path='/World/meshes',
                        vertices=mesh.vertices,
                        faces=None,
                        time=250)
        times = usd.get_authored_time_samples(out_path)
        assert times == [1, 20, 250]

        usd.export_pointcloud(out_path, pointcloud)
Beispiel #4
0
 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))
Beispiel #5
0
def save_kitchen_set_dataset(meshes, out_dir):
    for i, m in enumerate(meshes):
        out_path = os.path.join(out_dir, f'mesh_{i}.usd')
        usd.export_mesh(
            file_path=out_path,
            vertices=m.vertices[..., [0, 2, 1]],    # flipping Y and Z to make models Y-up
            faces=m.faces
        )
Beispiel #6
0
    def test_import_st_no_indices_uniform(self, out_dir, mesh):
        out_path = os.path.join(out_dir, 'st_no_indices_face_uniform.usda')
        uvs = torch.rand((mesh.faces.size(0), 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 'uniform'
        stage = Usd.Stage.Open(out_path)
        pv = UsdGeom.Mesh(stage.GetPrimAtPath(scene_path)).GetPrimvar('st')
        assert pv.GetInterpolation() == 'uniform'
Beispiel #7
0
    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)
Beispiel #8
0
    def test_import_hetero_homogenize(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_meshes(hetero_mesh_path, ['/Root'],
                                 heterogeneous_mesh_handler=usd.heterogeneous_mesh_handler_naive_homogenize)
        usd.export_mesh(out_path, '/World/Rocket', vertices=mesh[0].vertices, faces=mesh[0].faces)

        # Confirm we now have a triangle mesh
        assert mesh[0].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()
Beispiel #9
0
    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()
Beispiel #10
0
    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)
Beispiel #11
0
    def test_export_single(self, scene_paths, out_dir, mesh):
        out_path = os.path.join(out_dir, f'single_{self.file_name}')

        # Export a mesh
        stage = usd.export_mesh(out_path, scene_paths[0], mesh.vertices, mesh.faces)

        # Confirm exported USD matches golden file
        golden = os.path.join(out_dir, os.pardir, os.pardir, os.pardir,
                              os.pardir, 'samples/golden/mesh.usda')
        assert open(golden).read() == open(out_path).read()
Beispiel #12
0
 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)
Beispiel #13
0
 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))