Fix tree warp and CityJSON handling
This commit is contained in:
@@ -8,10 +8,10 @@ from pathlib import Path
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
DEFAULT_RAW_DIR = Path("raw/citygml/lod2")
|
||||
DEFAULT_CITYJSON_DIR = Path("work/cityjson")
|
||||
DEFAULT_CITYJSON_TRI_DIR = Path("work/cityjson_tri")
|
||||
DEFAULT_CITYJSON_SPLIT_DIR = Path("work/cityjson_split")
|
||||
DEFAULT_GLB_DIR = Path("export_unity/buildings_glb")
|
||||
DEFAULT_CITYJSON_DIR = Path("work/cityjson_lod2")
|
||||
DEFAULT_CITYJSON_TRI_DIR = Path("work/cityjson_lod2/tri")
|
||||
DEFAULT_CITYJSON_SPLIT_DIR = Path("work/cityjson_lod2/split")
|
||||
DEFAULT_GLB_DIR = Path("export_unity/buildings_tiles")
|
||||
DEFAULT_GLB_SPLIT_DIR = Path("export_unity/buildings_glb_split")
|
||||
DEFAULT_TILE_INDEX = Path("export_unity/tile_index.csv")
|
||||
|
||||
@@ -53,7 +53,7 @@ def parse_args(argv: Iterable[str] | None = None) -> argparse.Namespace:
|
||||
"--split-dir",
|
||||
type=Path,
|
||||
default=DEFAULT_CITYJSON_SPLIT_DIR,
|
||||
help="Directory containing split CityJSON files (roof/wall).",
|
||||
help="Directory containing split CityJSON files (roof/wall). Optional; skipped unless --check-split.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--glb-dir",
|
||||
@@ -65,7 +65,7 @@ def parse_args(argv: Iterable[str] | None = None) -> argparse.Namespace:
|
||||
"--glb-split-dir",
|
||||
type=Path,
|
||||
default=DEFAULT_GLB_SPLIT_DIR,
|
||||
help="Directory containing split GLB exports.",
|
||||
help="Directory containing split GLB exports. Optional; skipped unless --check-split.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--tile-index",
|
||||
@@ -73,17 +73,34 @@ def parse_args(argv: Iterable[str] | None = None) -> argparse.Namespace:
|
||||
default=DEFAULT_TILE_INDEX,
|
||||
help="Path to the tile_index.csv placement manifest.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--check-split",
|
||||
action="store_true",
|
||||
help="Also verify split roof/wall CityJSON and GLB outputs (current pipeline does not emit them by default).",
|
||||
)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
|
||||
def discover_tiles(raw_dir: Path, provided: Sequence[str] | None) -> list[str]:
|
||||
def discover_tiles(raw_dir: Path, provided: Sequence[str] | None, tile_index: Path | None) -> list[str]:
|
||||
if provided:
|
||||
return sorted(set(provided))
|
||||
|
||||
if not raw_dir.exists():
|
||||
return []
|
||||
if tile_index and tile_index.exists():
|
||||
try:
|
||||
import csv
|
||||
|
||||
return sorted(path.stem for path in raw_dir.glob("LoD2_*.gml"))
|
||||
with tile_index.open(newline="", encoding="utf-8") as handle:
|
||||
reader = csv.DictReader(handle)
|
||||
tiles = [row["tile_id"] for row in reader if "tile_id" in row and row.get("tile_id")]
|
||||
if tiles:
|
||||
return sorted(set(tiles))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if raw_dir.exists():
|
||||
return sorted(path.stem for path in raw_dir.glob("LoD2_*.gml"))
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def path_exists(path: Path) -> bool:
|
||||
@@ -123,13 +140,14 @@ def verify_cityjson(tile_ids: Sequence[str], args: argparse.Namespace) -> list[s
|
||||
if missing_tri:
|
||||
issues.append(summarize_missing("clean + triangulated CityJSON exports", missing_tri))
|
||||
|
||||
missing_roof = collect_missing(tile_ids, args.split_dir, "{tile_id}.roof.city.json")
|
||||
if missing_roof:
|
||||
issues.append(summarize_missing("split roof CityJSON exports", missing_roof))
|
||||
if args.check_split:
|
||||
missing_roof = collect_missing(tile_ids, args.split_dir, "{tile_id}.roof.city.json")
|
||||
if missing_roof:
|
||||
issues.append(summarize_missing("split roof CityJSON exports", missing_roof))
|
||||
|
||||
missing_wall = collect_missing(tile_ids, args.split_dir, "{tile_id}.wall.city.json")
|
||||
if missing_wall:
|
||||
issues.append(summarize_missing("split wall CityJSON exports", missing_wall))
|
||||
missing_wall = collect_missing(tile_ids, args.split_dir, "{tile_id}.wall.city.json")
|
||||
if missing_wall:
|
||||
issues.append(summarize_missing("split wall CityJSON exports", missing_wall))
|
||||
|
||||
return issues
|
||||
|
||||
@@ -140,20 +158,21 @@ def verify_glb(tile_ids: Sequence[str], args: argparse.Namespace) -> list[str]:
|
||||
if missing_base:
|
||||
issues.append(summarize_missing("base GLB exports", missing_base))
|
||||
|
||||
missing_roof = collect_missing(tile_ids, args.glb_split_dir, "{tile_id}_roof.glb")
|
||||
if missing_roof:
|
||||
issues.append(summarize_missing("split roof GLB exports", missing_roof))
|
||||
if args.check_split:
|
||||
missing_roof = collect_missing(tile_ids, args.glb_split_dir, "{tile_id}_roof.glb")
|
||||
if missing_roof:
|
||||
issues.append(summarize_missing("split roof GLB exports", missing_roof))
|
||||
|
||||
missing_wall = collect_missing(tile_ids, args.glb_split_dir, "{tile_id}_wall.glb")
|
||||
if missing_wall:
|
||||
issues.append(summarize_missing("split wall GLB exports", missing_wall))
|
||||
missing_wall = collect_missing(tile_ids, args.glb_split_dir, "{tile_id}_wall.glb")
|
||||
if missing_wall:
|
||||
issues.append(summarize_missing("split wall GLB exports", missing_wall))
|
||||
|
||||
return issues
|
||||
|
||||
|
||||
def main(argv: Iterable[str] | None = None) -> int:
|
||||
args = parse_args(argv)
|
||||
tile_ids = discover_tiles(args.raw_dir, args.tiles)
|
||||
tile_ids = discover_tiles(args.raw_dir, args.tiles, args.tile_index)
|
||||
if not tile_ids:
|
||||
print("No tile IDs found. Add LoD2 GML files or pass --tiles.", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user