Files
NODEDC_MISSION_CORE/simulation/ai-polygon/infrastructure_sources.py
T
DCCONSTRUCTIONS f48411f8fe feat(simulation): integrate infrastructure jobs and semantic scene editing
Integrate infrastructure preparation and qualified map delivery with local scenes. Add semantic editing, object provenance, survey caching and operator scene tools.
2026-10-29 09:10:01 +03:00

68 lines
2.8 KiB
Python

"""Read-only source resolution. Analysis never copies or downloads a scene."""
import hashlib
import json
from pathlib import Path
def checksum(path, pulse=lambda: None):
h = hashlib.sha256()
with path.open("rb") as stream:
for block in iter(lambda: stream.read(8 * 1024**2), b""):
h.update(block)
pulse()
return h.hexdigest()
def resolve_sources(world, state, pulse=lambda: None):
"""Reuse the simulator's verified complete-scene artifact, including its frame.
Missing assets are a producer/preparation error, never permission to clone a
Gaussian Pipeline package into the mapping job. No mkdir or file writes here.
"""
root = (Path(state) / "project-packages" / world["sha256"]).resolve()
terrain_path = root / "terrain.json"
if not terrain_path.is_file():
raise ValueError("Worker has no prepared shared scene; prepare this location first")
terrain = json.loads(terrain_path.read_text(encoding="utf-8"))
if (
terrain.get("source_sha256") != world["sha256"]
or terrain.get("source_collider_sha256") != world["collider_sha256"]
or terrain.get("collision_rotation") != world["local_scene"]["collision_rotation"]
):
raise ValueError("Shared scene calibration or collider changed")
collider = root / (world["collider_sha256"] + ".decoded.glb")
metadata = json.loads(collider.with_suffix(".json").read_text(encoding="utf-8"))
if (
metadata["source_sha256"] != world["collider_sha256"]
or checksum(collider, pulse) != metadata["sha256"]
):
raise ValueError("Shared collider checksum mismatch")
candidates = []
for path in root.glob("*.json"):
if path == terrain_path or path.name.endswith(".decoded.json"):
continue
row = json.loads(path.read_text(encoding="utf-8"))
source = path.with_suffix(".ply")
if (
row.get("source_sha256") == world["sha256"]
and row.get("coverage") == "complete-source"
and row.get("spatially_cropped") is False
and source.is_file()
):
candidates.append((row.get("lod", 0), source, row))
if not candidates:
raise ValueError("Worker has no verified complete shared Gaussian representation")
# Preserve the best representation already present. No new LOD conversion.
lod, source, receipt = sorted(candidates, key=lambda c: c[0])[0]
if source.is_symlink() or collider.is_symlink() or checksum(source, pulse) != receipt["sha256"]:
raise ValueError("Shared Gaussian source changed")
return root, dict(
ply=source.name,
sha256=receipt["sha256"],
lod=lod,
world_sha256=world["sha256"],
collider_sha256=world["collider_sha256"],
source_to_world=[[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]],
)