File size: 2,806 Bytes
44e46d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
'''
Download specific Objaverse meshes given their UUIDs.

Installation:
    pip install trimesh==4.5.3 objaverse==0.1.7 meshcat==0.0.12 webdataset==0.2.111

Usage:
    python download_objaverse.py --uuid_list /path_to_dataset/splits/franka/valid_scenes.json --output_dir /tmp/objs
'''
import argparse
import json
import os
import shutil
from objaverse import load_objects
from pathlib import Path
from dataset import load_uuid_list

def download_objaverse_meshes(uuids: list[str], output_dir: str):
    """
    Download specific Objaverse meshes given their UUIDs.
    
    Args:
        uuid_list_path (str): Path to JSON file containing list of UUIDs
        output_dir (str): Directory where meshes will be saved
    """
    # Create output directory if it doesn't exist
    os.makedirs(output_dir, exist_ok=True)
        
    print(f"Found {len(uuids)} UUIDs to download")
    
    # Download objects using Objaverse
    objects = load_objects(uids=uuids)

    map_uuid_to_path = {}
    
    # Save each object to the output directory
    for uuid in uuids:
        try:
            # Get the object path from Objaverse
            obj_path = objects[uuid]
            
            if obj_path is None:
                print(f"Failed to download object {uuid}")
                continue
                
            # Create destination path
            dest_path = os.path.join(output_dir, os.path.basename(obj_path))
            
            shutil.copy2(obj_path, dest_path)
            
            print(f"Successfully downloaded and saved object {uuid}, saved to {dest_path}")
            map_uuid_to_path[uuid] = dest_path

            os.remove(obj_path)
            json.dump(map_uuid_to_path, open(os.path.join(output_dir, "map_uuid_to_path.json"), "w"))
            
        except Exception as e:
            print(f"Error processing object {uuid}: {e}")
    
    print("Download complete!")

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("--uuid_list", type=str, help="Path to UUID list or Json. This can be the split json file from the GraspGen dataset")
    parser.add_argument("--output_dir", type=str, help="Path to output directory")
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()
    uuid_list = load_uuid_list(args.uuid_list)
    download_objaverse_meshes(uuid_list, args.output_dir)