#!/usr/bin/env python3 """Capture matched baseline and c=6 near-LOD views for each owner stratum.""" from __future__ import annotations import json import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l91/captures" DATA = ROOT / "Standalone/data/owner_world.json" BINARY = ROOT / "Saved/Linux/l91/bin/VoxelForgeCoreHeadless-l91-clang19" CAPTURE = ROOT / "Saved/Linux/l91/bin/VoxelForgeOffscreenCapture-l91-clang19" STRATA = { "S0": (8.0, 16.0, -372.2626953125), "FI": (25.8369140625, 3.19921875, -737.0), "TN": (19.166015625, -14.2001953125, -753.3740234375), "S3": (-20.0625, -5.068359375, -900.353515625), } def export(stratum: str, floor: float) -> dict: name = f"{stratum.lower()}-c{floor:g}" scene = OUT / f"{name}.vfmesh" log = OUT / f"{name}-export.log" camera = ",".join(f"{value:.12f}" for value in STRATA[stratum]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "env", "VOXELFORGE_L81_PASSAGE_BOUND_PADDING_VOXELS=0", f"VOXELFORGE_L91_PASSAGE_SOURCE_FLOOR_VOXELS={floor:g}", "timeout", "1740s", str(BINARY), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=8", "--clip-radius=3", "--max-clip-level=8", "--max-level=2", f"--camera={camera}", "--capture-skip-walkability", "--mesh-coverage", f"--mesh-export={scene}", ] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1750) return {"name": name, "stratum": stratum, "floor_vox": floor, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "scene": str(scene.relative_to(ROOT)), "log": str(log.relative_to(ROOT)), "scene_bytes": scene.stat().st_size if scene.exists() else 0} def render(stratum: str, floor: float) -> dict: name = f"{stratum.lower()}-c{floor:g}" scene = OUT / f"{name}.vfmesh" image = OUT / f"{name}.png" log = OUT / f"{name}-capture.log" x, y, z = STRATA[stratum] command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(CAPTURE), str(scene), str(image), "--size=1600x900", "--fov-deg=90", f"--camera-m={x:.12g},{y:.12g},{z:.12g}", "--yaw-deg=0", "--pitch-deg=0", "--shade=readable", "--height-tint=on", ] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1750) return {"name": name, "stratum": stratum, "floor_vox": floor, "exit_code": result.returncode, "wall_s": round(time.monotonic() - started, 3), "image": str(image.relative_to(ROOT)), "log": str(log.relative_to(ROOT)), "image_bytes": image.stat().st_size if image.exists() else 0} def main() -> int: OUT.mkdir(parents=True, exist_ok=True) rows = [] for stratum in STRATA: for floor in (0.0, 6.0): row = export(stratum, floor) rows.append(row) if row["exit_code"] != 0 or row["scene_bytes"] == 0: break row = render(stratum, floor) rows.append(row) if row["exit_code"] != 0 or row["image_bytes"] == 0: break if rows[-1]["exit_code"] != 0: break (OUT / "summary.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") print("[L91CaptureSummary] " + json.dumps(rows, sort_keys=True), flush=True) return 0 if len(rows) == 16 and all(row["exit_code"] == 0 for row in rows) else 1 if __name__ == "__main__": raise SystemExit(main())