Skip to content

Official Codebase of 3DCodeVerse

Python

scene gates: fog that ends inside the plan is warned (fog_short); the typed interior flag replaces the setting-word inference at its four call sites

gaoypeng16aa0f66f19e
diff --git a/harness/codeverse/spatial/scene_placement.py b/harness/codeverse/spatial/scene_placement.py
index bb997add..36c99869 100644
--- a/harness/codeverse/spatial/scene_placement.py
+++ b/harness/codeverse/spatial/scene_placement.py
@@ -143,10 +143,18 @@ def _words(name: str) -> set[str]:
def infer_indoor(text: str) -> bool:
- """Does the plan's setting / environment text say the scene is indoors?"""
+ """Does the plan's setting / environment text say the scene is indoors? (The word
+ list is the fallback for a plan written before ``ScenePlan.interior`` existed; the
+ typed flag wins — :func:`is_interior`.)"""
return bool(_words(text) & INDOOR_WORDS)
+def is_interior(plan: Any) -> bool:
+ """The plan's typed ``interior`` flag (D69) when it says so, else the setting text."""
+ flag = plan.get("interior") if isinstance(plan, dict) else getattr(plan, "interior", None)
+ return bool(flag) or infer_indoor(setting_text(plan))
+
+
def _f(sev: Severity, msg: str, *, target: str, hint: str = "", kind: str, **data: Any) -> GateFinding:
return GateFinding(gate=GATE, severity=sev, target=target, message=msg, fix_hint=hint, data={"kind": kind, **data})
@@ -280,6 +288,9 @@ def placement_findings(table: dict[str, Any] | PlacementTable, *, indoor: bool =
#: every placed asset's name, zone and bbox. These checks are pure functions of the
#: census + the plan; their ERRORs route into refine with the zone as the target.
SCALE_WARN, SCALE_ERROR = 2.5, 4.0
+#: linear fog must reach past the plan's far side (fog far >= this many plan spans); exp fog
+#: must not dissolve it (1/density >= span / this)
+FOG_FAR_MIN_SPANS, FOG_DENSITY_MAX_PER_SPAN = 2.0, 1.5
BOUNDS_MARGIN_MIN_M = 2.0
#: a zone whose census instance count is under this fraction of its L2 layout budget is
#: underdressed. Measured on scene_final_v1 (n=19): flat_ground 12 / undressed 11 /
@@ -404,10 +415,30 @@ def contract_findings(census: dict[str, Any] | None, plan: Any,
out.append(_f(Severity.ERROR, "scene.background is not set (renders on the raw clear colour)",
target="env", kind="no_background",
hint="in buildEnv set scene.background to the sky colour or sky texture the plan names"))
+ # -- fog that ends inside the world: measured 2026-09-08 over eleven exterior runs, every
+ # one with fog far >= 2 x the plan span scored >= 0.60 and the three at 1.4-1.6 x scored
+ # 0.42-0.60 with "no aerial perspective", "world edge", "backdrop floating in the sky" —
+ # past fog far the land is the background colour while the unfogged sky stays sharp
+ fog = census.get("fog")
+ pb = _plan_bounds(plan)
+ if isinstance(fog, dict) and pb and not is_interior(plan):
+ span = max(pb[1][0] - pb[0][0], pb[1][2] - pb[0][2])
+ far, density = fog.get("far"), fog.get("density")
+ short = ""
+ if isinstance(far, int | float) and span > 0 and far < FOG_FAR_MIN_SPANS * span:
+ short = f"fog far {far:g} m ends inside the plan's {span:g} m world ({far / span:.1f}x)"
+ elif isinstance(density, int | float) and span > 0 and density > FOG_DENSITY_MAX_PER_SPAN / span:
+ short = f"fog density {density:g} dissolves the plan's {span:g} m world within {1 / density:.0f} m"
+ if short:
+ out.append(_f(Severity.WARN, short + " — past it the land is the background colour while the unfogged sky "
+ "stays sharp: a world edge and backdrops floating in the sky",
+ target="env", kind="fog_short", fog=fog, plan_span_m=round(span, 1),
+ hint=f"fog far >= {FOG_FAR_MIN_SPANS:g} x the plan span (the starter's shell fog is scaled to it: "
+ "keep `scene.fog = shell.fog`, or lengthen yours) and let the horizon ridge / outskirts close the world"))
# -- backdrop ring: outdoor worlds must have geometry past the play area
bounds = _plan_bounds(plan)
groups = census.get("groups")
- if bounds and isinstance(groups, list) and not infer_indoor(setting_text(plan)):
+ if bounds and isinstance(groups, list) and not is_interior(plan):
lo, hi = bounds
cx, cz = (lo[0] + hi[0]) / 2, (lo[2] + hi[2]) / 2
half = max(hi[0] - lo[0], hi[2] - lo[2]) / 2
@@ -534,7 +565,7 @@ def check_placement(ws: Workspace, *, indoor: bool | None = None, force_probe: b
t0 = time.time()
census = placement_census(ws, force_probe=force_probe, timeout_s=timeout_s)
if indoor is None:
- indoor = infer_indoor(setting_text(read_json_or_none(ws.plan_path)))
+ indoor = is_interior(read_json_or_none(ws.plan_path))
return placement_findings(census.get("placement") or {}, indoor=indoor, duration_ms=int((time.time() - t0) * 1000))
@@ -547,7 +578,7 @@ def placement_gate_safe(census: dict[str, Any] | None, *, plan: Any = None,
table = (census or {}).get("placement")
if not isinstance(table, dict):
return None
- report = placement_findings(table, indoor=infer_indoor(setting_text(plan)))
+ report = placement_findings(table, indoor=is_interior(plan))
extra = _cap_per_kind(contract_findings(census, plan, layouts=layouts, unavailable=unavailable))
if extra:
findings = report.findings + extra
diff --git a/harness/codeverse/spatial/tools.py b/harness/codeverse/spatial/tools.py
index cb786651..c80bcf45 100644
--- a/harness/codeverse/spatial/tools.py
+++ b/harness/codeverse/spatial/tools.py
@@ -54,10 +54,9 @@ from codeverse.spatial.probes import check_shaders, probe_scene
from codeverse.spatial.registry import NoArgs, Observation, ToolContext, ToolUsageError, tool
from codeverse.spatial.render_scene import read_metrics, render_scene
from codeverse.spatial.scene_placement import (
- infer_indoor,
+ is_interior,
placement_findings,
placement_table_text,
- setting_text,
)
from codeverse.spatial.scene_placement import placement_census as _placement_census
from codeverse.spatial.sections import cross_section as _cross_section
@@ -627,7 +626,7 @@ def check_placement(ctx: ToolContext, args: CheckPlacementArgs) -> Observation:
indoor = False
if ctx.workspace.plan_path.is_file():
try:
- indoor = infer_indoor(setting_text(load_plan(ctx.workspace.plan_path)))
+ indoor = is_interior(load_plan(ctx.workspace.plan_path))
except ToolUsageError:
indoor = False
table = census.get("placement") or {}
diff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.py
index edc3453e..996cdaec 100644
--- a/harness/tests/scene_gates/test_placement.py
+++ b/harness/tests/scene_gates/test_placement.py
@@ -235,6 +235,33 @@ def test_a_wrapper_of_instances_is_scale_checked_as_one_instance():
assert scale[0].data["fix_hint"].startswith("scale each picket_fence") if "fix_hint" in scale[0].data else True
+def test_the_typed_interior_flag_wins_over_the_setting_words():
+ """D69's `interior` is the plan's word; the setting-text inference stays for plans
+ written before it existed."""
+ from codeverse.spatial.scene_placement import is_interior
+
+ assert is_interior({"setting": "a mountain meadow at dawn", "interior": True})
+ assert not is_interior({"setting": "a mountain meadow at dawn", "interior": False})
+ assert is_interior({"setting": "a cosy cabin interior at dusk"}) # no flag: the words decide
+ assert is_interior(_contract_plan().model_copy(update={"interior": True}))
+
+
+def test_fog_that_ends_inside_the_plan_is_warned_for_exteriors_only():
+ """Measured 2026-09-08 over eleven exterior runs: fog far >= 2 x the plan span scored
+ >= 0.60, the three at 1.4-1.6 x scored 0.42-0.60 with 'world edge' verdicts."""
+ plan = _contract_plan() # 40 m bounds
+ census = {"fog": {"type": "Fog", "near": 18, "far": 50, "density": None}, "background": "#aabbcc",
+ "placement": _table(_row("Lantern", h=0.6), _row("Bench", h=0.9), _row("BenchB", zone="House", h=0.9))}
+ short = [f for f in placement_gate_safe(census, plan=plan).findings if f.data.get("kind") == "fog_short"]
+ assert len(short) == 1 and short[0].severity == Severity.WARN and "50 m ends inside the plan's 40 m world (1.2x)" in short[0].message
+ census["fog"] = {"type": "Fog", "near": 30, "far": 90, "density": None} # 2.25 x: fine
+ assert not [f for f in placement_gate_safe(census, plan=plan).findings if f.data.get("kind") == "fog_short"]
+ census["fog"] = {"type": "FogExp2", "near": None, "far": None, "density": 0.06} # dissolves within ~17 m
+ assert [f for f in placement_gate_safe(census, plan=plan).findings if f.data.get("kind") == "fog_short"]
+ inside = plan.model_copy(update={"interior": True}) # a room has no horizon
+ assert not [f for f in placement_gate_safe(census, plan=inside).findings if f.data.get("kind") == "fog_short"]
+
+
def test_contract_checks_stay_quiet_on_a_dressed_in_bounds_scene():
census = {"fog": {"type": "Fog", "near": 10, "far": 60}, "background": "#aabbcc",
"placement": _table(_row("Lantern_3", h=0.6), _row("Bench", h=0.9),