Skip to content

Official Codebase of 3DCodeVerse

Python

spatial: check_placement returns the round's scene_placement verdict

gaoypeng5ba1fab1f91e
diff --git a/harness/codeverse3d/spatial/scene_placement.py b/harness/codeverse3d/spatial/scene_placement.py
index d754a526..4fd82a54 100644
--- a/harness/codeverse3d/spatial/scene_placement.py
+++ b/harness/codeverse3d/spatial/scene_placement.py
@@ -591,6 +591,24 @@ def setting_text(plan: Any) -> str:
return " ".join(str(getattr(plan, k, "") or "") for k in ("setting", "environment", "title"))
+def placement_gate(ws: Workspace, census: dict[str, Any] | None, plan: Any) -> GateReport | None:
+ """THE ``scene_placement`` verdict: the round's gate (``ScenePipeline.gates``) and the
+ ``check_placement`` tool both return it, on the same inputs — the census, the plan and
+ what the run's stages recorded in the workspace (the L2 zone layouts, the assets the
+ asset stage could not build). Until 2026-09-22 the tool reported
+ :func:`placement_findings` alone, so it never showed the plan checks (fog, backdrop,
+ zone contents, scale, bounds, density) the round then failed on."""
+ assets = _stage_result(ws, "assets")
+ unavailable = [name for name, r in assets.items() if isinstance(r, dict) and not r.get("ok", True)]
+ return placement_gate_safe(census, plan=plan, layouts=_stage_result(ws, "layouts"), unavailable=unavailable)
+
+
+def _stage_result(ws: Workspace, name: str) -> dict[str, Any]:
+ """A cached stage's result (``orchestrator.StageRunner`` writes ``stages/<name>.json``), ``{}`` when absent."""
+ res = (read_json_or_none(ws.stages / f"{name}.json") or {}).get("result")
+ return res if isinstance(res, dict) else {}
+
+
def placement_gate_safe(census: dict[str, Any] | None, *, plan: Any = None,
layouts: dict[str, Any] | None = None, unavailable: Sequence[str] = ()) -> GateReport | None:
"""Round-gate entry: ``None`` when the census has no placement table (scene did not
diff --git a/harness/codeverse3d/spatial/tools.py b/harness/codeverse3d/spatial/tools.py
index 1221fd66..e719979a 100644
--- a/harness/codeverse3d/spatial/tools.py
+++ b/harness/codeverse3d/spatial/tools.py
@@ -43,12 +43,8 @@ from codeverse3d.spatial.observe import (
from codeverse3d.spatial.probes import check_shaders, probe_scene
from codeverse3d.spatial.registry import NoArgs, Observation, ToolContext, ToolUsageError, tool
from codeverse3d.spatial.render_scene import read_metrics, render_scene
-from codeverse3d.spatial.scene_placement import (
- is_interior,
- placement_findings,
- placement_table_text,
-)
from codeverse3d.spatial.scene_placement import placement_census as _placement_census
+from codeverse3d.spatial.scene_placement import placement_gate, placement_table_text
from codeverse3d.spatial.sections import cross_section as _cross_section
from codeverse3d.spatial.sheet import contact_sheet
from codeverse3d.spatial.silhouette import compare_silhouette as _compare_silhouette
@@ -531,24 +527,26 @@ class CheckPlacementArgs(BaseModel):
@tool("check_placement", CheckPlacementArgs,
- "Deterministic placement check of the last build (scene only): per placed asset the gap from its feet to what is "
- "under them, burial depth, water, contacts, plus 3-D interpenetrations between assets — findings read "
- "'floating / sunken / unsupported / interpenetration' with 'lower X by 0.23 m onto Terrain' hints. Reads the "
- "census of the last build/scene_probe; rebuild=true probes again. Tag a deliberately airborne thing with "
- "obj.userData.placement = 'free'.",
+ "The round's scene_placement gate on the last build (scene only): per placed asset the gap from its feet to what "
+ "is under them, burial depth, water, contacts, plus 3-D interpenetrations between assets — findings read "
+ "'floating / sunken / unsupported / interpenetration' with 'lower X by 0.23 m onto Terrain' hints — and the "
+ "plan checks (fog, backdrop, zone contents, scale, bounds). Reads the census of the last build/scene_probe; "
+ "rebuild=true probes again. Tag a deliberately airborne thing with obj.userData.placement = 'free'.",
languages=(Language.SCENE_THREEJS.value,), cost_hint="fast")
def check_placement(ctx: ToolContext, args: CheckPlacementArgs) -> Observation:
- census = _placement_census(ctx.workspace, force_probe=args.rebuild)
- indoor = False
- if ctx.workspace.plan_path.is_file():
+ ws = ctx.workspace
+ census = _placement_census(ws, force_probe=args.rebuild)
+ plan = None
+ if ws.plan_path.is_file():
try:
- indoor = is_interior(load_plan(ctx.workspace.plan_path))
+ plan = load_plan(ws.plan_path)
except ToolUsageError:
- indoor = False
- table = census.get("placement") or {}
- report = placement_findings(table, indoor=indoor)
+ plan = None
+ report = placement_gate(ws, census, plan)
+ if report is None:
+ return Observation.error("check_placement: the census carries no placement table")
obs = gate_observation(report, title="placement check")
- return obs.model_copy(update={"text": truncate(obs.text + "\n\n" + placement_table_text(table))})
+ return obs.model_copy(update={"text": truncate(obs.text + "\n\n" + placement_table_text(census["placement"]))})
# ===================================================================== graphics
diff --git a/harness/codeverse3d/tracks/scene.py b/harness/codeverse3d/tracks/scene.py
index b9881535..9d2d5d42 100644
--- a/harness/codeverse3d/tracks/scene.py
+++ b/harness/codeverse3d/tracks/scene.py
@@ -46,6 +46,7 @@ from codeverse3d.proc import fan_out
from codeverse3d.prompts import render
from codeverse3d.spatial.frame_motion import motion_text_for
from codeverse3d.spatial.render_scene import perf_detail
+from codeverse3d.spatial.scene_placement import placement_gate
from codeverse3d.texturing.plan import texture_pack_prompt
from codeverse3d.tracks import skills_hook
from codeverse3d.tracks.common import RunContext, generate_for, single_shot_ctx
@@ -101,23 +102,13 @@ class ScenePipeline:
return None
def gates(self, ctx: RunContext, round_index: int, build: BuildResult, measurement: Measurement | None) -> list[GateReport]:
- out: list[GateReport] = []
# scene_placement (2026-08-26): floating / sunken / unsupported / interpenetrating assets from
# the probe census's placement table — the first deterministic placement gate on this track
- # (before it, the scene_v1 floating_part cap could never fire). Advisory instrumentation:
- # a failure is a WARN finding, never an exception, so it cannot kill a round.
- try:
- from codeverse3d.spatial.scene_placement import placement_gate_safe
-
- placement = placement_gate_safe(build.census, plan=ctx.plan, layouts=ctx.extra.get("layouts"),
- unavailable=[n for n, r in (ctx.extra.get("assets") or {}).items() if not getattr(r, "ok", True)])
- except Exception as e: # noqa: BLE001
- log.warning("scene placement gate unavailable: %s", e)
- placement = GateReport(gate="scene_placement", passed=True, findings=[GateFinding(
- gate="scene_placement", severity=Severity.WARN, target="scene", message=f"placement probe failed: {e}"[:400])])
- if placement is not None:
- out.append(placement)
- return out
+ # (before it, the scene_v1 floating_part cap could never fire) — plus the plan checks. The
+ # check_placement tool returns the same verdict. Advisory instrumentation: a failure is a
+ # WARN finding, never an exception, so it cannot kill a round.
+ placement = placement_gate(ctx.ws, build.census, ctx.plan)
+ return [placement] if placement is not None else []
def render(self, ctx: RunContext, round_index: int, build: BuildResult, measurement: Measurement | None) -> RenderSet:
r = ctx.settings.render
diff --git a/harness/docs/ARCHITECTURE.md b/harness/docs/ARCHITECTURE.md
index 161df361..111bb665 100644
--- a/harness/docs/ARCHITECTURE.md
+++ b/harness/docs/ARCHITECTURE.md
@@ -124,7 +124,8 @@ codeverse3d/
spatial/ node.py, render.py, observe.py, tool_common.py (shared tool plumbing),
render_scene.py (judge view subset, content-fitted orbit),
frame_metrics.py (scene_frames gate), frame_motion.py (measured inter-frame motion),
- scene_placement.py (scene_placement gate + check_placement tool: floating / sunken /
+ scene_placement.py (scene_placement gate = the check_placement tool's verdict,
+ placement_gate(ws, census, plan) for both: floating / sunken /
unsupported / interpenetration per placed asset from the probe census's placement
table, runtime_js/lib/host_placement.mjs; added 2026-08-26),
gl_render.py (GlHost), frame_stats.py (gl_frames),
diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.md
index 85e97b75..f6fe617d 100644
--- a/harness/docs/INTERFACES.md
+++ b/harness/docs/INTERFACES.md
@@ -321,11 +321,13 @@ from codeverse3d.spatial.contract import check_contract # frame of fix
from codeverse3d.spatial.measure import measure_glb, world_transform, node_name_findings # (Δ 2026-08-30) world frames are composed
# by walking the graph's edge matrices (trimesh's get() dropped a root pivot's rotation); a GLB with duplicate / unnamed nodes
# lands a finding in Measurement.extra["findings"] — trimesh re-parents renamed nodes and the numbers are approximate
-from codeverse3d.spatial.scene_placement import placement_findings, placement_gate_safe, placement_census, placement_table_text
+from codeverse3d.spatial.scene_placement import placement_findings, placement_gate, placement_gate_safe, placement_census, placement_table_text
placement_findings(table, *, indoor=False) -> GateReport # gate "scene_placement"; data.kind ∈ floating | sunken |
# unsupported | interpenetration | summary | probe_failed; target "Zone/Asset" (routes to src/zones/<zone>.js);
# messages carry the scene_v1 floating_part cap words; reads artifacts/census.json["placement"] (host_placement.mjs)
-placement_gate_safe(census, *, plan=None, layouts=None, unavailable=()) -> GateReport | None # round gate: None without a table, WARN on failure, never raises; `unavailable` = assets the stage could not build (not "missing planned contents")
+placement_gate(ws, census, plan) -> GateReport | None # THE verdict (Δ 2026-09-22): ScenePipeline.gates and the check_placement
+ # tool both return it — placement_gate_safe fed the zone layouts and the unbuilt assets from ws/stages/{layouts,assets}.json
+placement_gate_safe(census, *, plan=None, layouts=None, unavailable=()) -> GateReport | None # the pure core: None without a table, WARN on failure, never raises; `unavailable` = assets the stage could not build (not "missing planned contents")
from codeverse3d.spatial.scene_placement import setting_text # (plan: dict | model) -> the indoor/outdoor setting line
from codeverse3d.spatial.silhouette import compare_silhouette # the reference gate + compare_reference's IoU (no tool of its own)
from codeverse3d.spatial.sections import judge_slices, SliceManifest, JUDGE_SLICE_PLANES # (D48)
diff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.py
index 6d218004..15c18428 100644
--- a/harness/tests/scene_gates/test_placement.py
+++ b/harness/tests/scene_gates/test_placement.py
@@ -148,9 +148,11 @@ def test_error_findings_become_zone_routed_refine_tasks_one_per_asset():
assert all(t.kind == f"gate:{GATE}" and "lower " in t.instruction for t in tasks)
-def test_pipeline_gates_are_placement_alone_and_never_raise():
+def test_pipeline_gates_are_placement_alone_and_never_raise(tmp_path):
+ from codeverse3d.workspace import Workspace
+
plan = _plan()
- ctx = SimpleNamespace(runtime=SimpleNamespace(), plan=plan, extra={})
+ ctx = SimpleNamespace(runtime=SimpleNamespace(), plan=plan, extra={}, ws=Workspace(tmp_path / "run").create())
build = BuildResult(ok=True, language="scene_threejs", census={"totals": {"meshes": 3}, "placement": _table(_row("Lantern", gap=0.3))})
gates = ScenePipeline().gates(ctx, 0, build, None)
assert [g.gate for g in gates] == [GATE] and not gates[-1].passed
@@ -177,6 +179,30 @@ def test_check_placement_reads_the_last_census_and_the_table_text(tmp_path):
assert "Yard/Lantern | +0.300 | Ground | 0.000 | - | - | -" in text and "Yard/Rock | +0.000 | Ground | 0.300 | Terrain" in text
+def test_check_placement_returns_the_round_gates_verdict(tmp_path):
+ """One verdict: the tool reads the same census, plan and stage records the round gate does,
+ so the plan checks it used to leave out (fog, zone contents, ...) are in it, and an asset
+ the asset stage could not build is not "missing" in either (2026-09-22)."""
+ from codeverse3d.spatial.registry import ToolContext, get_tool
+ from codeverse3d.workspace import Workspace
+
+ ws = Workspace(tmp_path / "run").create()
+ census = {"totals": {}, "fog": None, "placement": _table(_row("Lantern", gap=0.3))}
+ (ws.artifacts / "census.json").write_text(json.dumps(census))
+ plan = _contract_plan()
+ ws.plan_path.write_text(plan.model_dump_json())
+ ws.stages.mkdir(parents=True, exist_ok=True)
+ (ws.stages / "assets.json").write_text(json.dumps(
+ {"stage": "assets", "inputs_hash": "h", "result": {"Bench": {"name": "Bench", "kind": "threejs", "ok": False}}}))
+ obs = get_tool("check_placement").call(ToolContext(workspace=ws, language=Language.SCENE_THREEJS.value), {})
+ gate = ScenePipeline().gates(SimpleNamespace(ws=ws, plan=plan, extra={}), 0,
+ BuildResult(ok=True, language="scene_threejs", census=census), None)[0]
+ assert not obs.ok and not gate.passed and obs.numbers["errors"] == len(gate.errors)
+ assert all(f.message in obs.text for f in gate.errors)
+ kinds = {f.data.get("kind") for f in gate.findings}
+ assert {"floating", "no_fog", "zone_empty"} <= kinds and "missing_content" not in kinds # Bench was never built
+
+
# --------------------------------------------------------------------- plan-aware contract checks
def _contract_plan() -> ScenePlan:
bb = BBox(center=(0, 0, 0), extents=(40, 8, 40))