Files
GeoData/geodata_to_unity.py

84 lines
2.7 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(
"--use-archive",
action="store_true",
help="Populate raw inputs from archives (unzips zips, copies dop20 filelist).",
)
parser.add_argument(
"--setup",
action="store_true",
help="Create default directory structure and config if missing; still runs export unless --export is omitted.",
)
parser.add_argument(
"--no-export",
action="store_true",
help="Only run setup/archive prep without exporting.",
)
return parser.parse_args(argv)
def load_config(args: argparse.Namespace) -> Config:
if args.setup and not os.path.exists(args.config):
cfg = ensure_default_config(args.config)
else:
cfg = ensure_default_config(args.config) if os.path.exists(args.config) else Config.default()
if not os.path.exists(args.config):
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.use_archive:
materialize_archives(cfg)
if args.no_export:
return 0
exit_codes = []
if args.export in ("heightmap", "all"):
exit_codes.append(export_heightmaps(cfg))
if args.export in ("textures", "all"):
exit_codes.append(export_orthophotos(cfg))
return max(exit_codes) if exit_codes else 0
if __name__ == "__main__":
sys.exit(main())