Files
GeoData/geodata_to_unity.py

86 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""CLI entrypoint to export GeoData assets for Unity."""
from __future__ import annotations
import argparse
import os
import sys
from typing import Iterable
from geodata_pipeline.config import Config, DEFAULT_CONFIG_PATH, ensure_default_config
from geodata_pipeline.heightmaps import export_heightmaps
from geodata_pipeline.orthophotos import export_orthophotos
from geodata_pipeline.setup_helpers import ensure_directories, materialize_archives
def parse_args(argv: Iterable[str] | None = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Export GeoData assets for Unity.")
parser.add_argument(
"--config",
default=DEFAULT_CONFIG_PATH,
help="Path to config JSON (created on --setup if missing).",
)
parser.add_argument(
"--export",
choices=["heightmap", "textures", "all"],
default="all",
help="Which assets to export.",
)
parser.add_argument("--raw-dgm1-path", dest="raw_dgm1_path", help="Override raw DGM1 directory.")
parser.add_argument("--raw-dop20-path", dest="raw_dop20_path", help="Override raw DOP20 JP2 directory.")
parser.add_argument(
"--build-from-archive",
action="store_true",
help="Populate raw inputs from archives (unzips zips, leaves dop20 filelist in archive).",
)
parser.add_argument(
"--setup",
action="store_true",
help="Create default directory structure and config if missing; does not export.",
)
parser.add_argument(
"--force-vrt",
action="store_true",
help="Rebuild VRTs even if present (useful after moving raw data).",
)
return parser.parse_args(argv)
def load_config(args: argparse.Namespace) -> Config:
if args.setup:
cfg = Config.default()
cfg.save(args.config)
return cfg.with_overrides(raw_dgm1_path=args.raw_dgm1_path, raw_dop20_path=args.raw_dop20_path)
if os.path.exists(args.config):
cfg = Config.load(args.config)
else:
cfg = Config.default()
cfg.save(args.config)
return cfg.with_overrides(raw_dgm1_path=args.raw_dgm1_path, raw_dop20_path=args.raw_dop20_path)
def main(argv: Iterable[str] | None = None) -> int:
args = parse_args(argv)
cfg = load_config(args)
if args.setup:
ensure_directories(cfg)
print(f"Directories ensured. Config at {args.config}.")
if args.export is None:
return 0
if args.build_from_archive:
materialize_archives(cfg)
exit_codes = []
if args.export in ("heightmap", "all"):
exit_codes.append(export_heightmaps(cfg, force_vrt=args.force_vrt))
if args.export in ("textures", "all"):
exit_codes.append(export_orthophotos(cfg, force_vrt=args.force_vrt))
return max(exit_codes) if exit_codes else 0
if __name__ == "__main__":
sys.exit(main())