#!/usr/bin/env bash set -euo pipefail # Bootstrap downloader: iterates used_scenes.json and downloads each scene. # Resolve paths relative to this script SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DOWNLOAD_SCRIPT="${DOWNLOAD_SCRIPT:-${SCRIPT_DIR}/download.py}" USED_SCENES_JSON="${USED_SCENES_JSON:-${SCRIPT_DIR}/used_scenes_test.json}" # Change to used_scenes.json for full download GOOD_SCENES_DIR="${GOOD_SCENES_DIR:-${SCRIPT_DIR}/good_scenes}" usage() { echo "Usage: $0 [-o OUTPUT_DIR]" >&2 echo " -o, --output Output base dir for downloads (default: ${GOOD_SCENES_DIR})" >&2 } while [[ $# -gt 0 ]]; do case "$1" in -o|--output) GOOD_SCENES_DIR="$2"; shift 2 ;; -h|--help) usage; exit 0 ;; *) echo "Unknown argument: $1" >&2; usage; exit 1 ;; esac done if [[ ! -f "$DOWNLOAD_SCRIPT" ]]; then echo "ERROR: download script not found at $DOWNLOAD_SCRIPT" >&2 exit 1 fi if [[ ! -f "$USED_SCENES_JSON" ]]; then echo "ERROR: used scenes JSON not found at $USED_SCENES_JSON" >&2 exit 1 fi mkdir -p "$GOOD_SCENES_DIR" echo "Downloading scenes into: $GOOD_SCENES_DIR" successful_downloads=0 total_scenes=0 # Extract tab-separated batch and hash for each scene from JSON while IFS=$'\t' read -r batch hash scale; do [[ -z "$batch" || -z "$hash" ]] && continue total_scenes=$((total_scenes + 1)) # echo "Saving metric $scale to text file" # echo "$scale" > "${GOOD_SCENES_DIR}/${batch}/${hash}/metric_scale.txt" echo "Downloading scene hash=$hash (batch=$batch) ..." scene_success=true # 1) images+poses at 4K and 960P for reso in 4K 960P; do if python3 "$DOWNLOAD_SCRIPT" \ --odir "$GOOD_SCENES_DIR" \ --subset "$batch" \ --resolution "$reso" \ --file_type "images+poses" \ --hash "$hash" \ --clean_cache; then echo "Successfully downloaded images+poses ($reso) for scene $hash" else echo "Failed to download images+poses ($reso) for scene $hash" >&2 scene_success=false fi done # 2) colmap_cache (resolution arg required but not used) if python3 "$DOWNLOAD_SCRIPT" \ --odir "$GOOD_SCENES_DIR" \ --subset "$batch" \ --resolution "4K" \ --file_type "colmap_cache" \ --hash "$hash" \ --clean_cache; then echo "Successfully downloaded colmap_cache for scene $hash" else echo "Failed to download colmap_cache for scene $hash" >&2 scene_success=false fi if [[ "$scene_success" == true ]]; then echo "Successfully downloaded all assets for scene $hash" successful_downloads=$((successful_downloads + 1)) else echo "Scene $hash completed with some failures" >&2 fi done < <(python3 - "$USED_SCENES_JSON" << 'PY' import json, sys path = sys.argv[1] with open(path, 'r') as f: data = json.load(f) for s in data: batch = s.get('batch') hashv = s.get('hash') scale = s.get('scale', '1.0') if batch and hashv: print(f"{batch}\t{hashv}\t{scale}") PY ) echo "Summary: $successful_downloads/$total_scenes scenes downloaded successfully."