Official Codebase of 3DCodeVerse
Python
scene placement: the gate accepts what the boot-time settle accepts, from one placement_words.json
gaoypengd71e139294ac
diff --git a/harness/codeverse3d/spatial/scene_placement.py b/harness/codeverse3d/spatial/scene_placement.pyindex f47a5f15..b77c82b6 100644--- a/harness/codeverse3d/spatial/scene_placement.py+++ b/harness/codeverse3d/spatial/scene_placement.py@@ -24,7 +24,6 @@ posts 0.97 m into the pond bed — a naive "> 0.10 m" rule flagged all of themfrom __future__ import annotationsimport functools-import jsonimport loggingfrom collections.abc import Sequencefrom typing import Any@@ -45,7 +44,6 @@ FLOATING_OUTDOOR_M, FLOATING_INDOOR_M = 0.05, 0.02FLOATING_ERROR_M, FLOATING_ERROR_COUNT = 0.15, 3 # this high, or more than this many, → ERRORSUNK_M, SUNK_ERROR_M = 0.10, 0.30SUNK_ERROR_FRAC = 0.25 # an ERROR burial must also swallow this fraction of the height-PARTIAL_OK_FRAC, PARTIAL_OK_ERROR_FRAC = 0.50, 0.75 # rocks / posts / bushes: WARN past half, ERROR past 3/4OVERLAP_WARN, OVERLAP_ERROR = 0.20, 0.60MAX_FINDINGS_PER_KIND = 8@@ -54,17 +52,27 @@ INDOOR_WORDS = frozenset({"attic", "basement", "bathroom", "bedroom", "cabin", "cellar", "chamber", "classroom", "cockpit", "corridor", "garage", "hall", "hut", "indoor","indoors", "inside", "interior", "kitchen", "lab", "laboratory", "library", "lobby", "office", "room", "studio", "tent", "warehouse", "workshop",})-#: name words exempt from "sunken" — BELOW ground by definition (``buried_ok``) or normally-#: driven / grown in, sunken only past half their height (``partial_ok``). ONE list, shared with-#: the boot-time settle (``host_placement.settleScene``): ``runtime_js/lib/placement_words.json``.+#: What counts as seated, ONE file shared with the boot-time settle (``host_placement.settleScene``),+#: so the gate never reports what the settle deliberately leaves (audit 2026-09-24 N27): name words+#: exempt from "sunken" — below ground by definition (``buried_ok``), following the terrain+#: (``slope_ok``), or driven / grown in up to ``partial_ok_frac`` of their height (``partial_ok``).+#: The settle's other acceptance — a floating asset that touches a neighbour is mounted on it — is+#: ``AssetRow.attached`` here.PLACEMENT_WORDS = "placement_words.json"+class _SeatedWords(BaseModel):+ model_config = ConfigDict(extra="ignore", frozen=True)++ buried_ok: frozenset[str]+ slope_ok: frozenset[str]+ partial_ok: frozenset[str]+ partial_ok_frac: float++@functools.cache-def _exempt_words() -> tuple[frozenset[str], frozenset[str]]:- """``(buried_ok, partial_ok)`` from :data:`PLACEMENT_WORDS`."""- d = json.loads((runtime_js_dir() / "lib" / PLACEMENT_WORDS).read_text(encoding="utf-8"))- return frozenset(d["buried_ok"]), frozenset(d["partial_ok"])+def _seated_words() -> _SeatedWords:+ return _SeatedWords.model_validate_json((runtime_js_dir() / "lib" / PLACEMENT_WORDS).read_text(encoding="utf-8"))def _nums(v: object) -> list[float] | None:@@ -182,15 +190,14 @@ def _sunk_severity(row: AssetRow) -> Severity | None:"""WARN / ERROR / None for a buried foot, honouring height fraction and name words."""if row.sunk_m <= 0 or row.on_water:return None- words = _words(row.name)- buried_ok, partial_ok = _exempt_words()- if words & buried_ok:+ words, seated = _words(row.name), _seated_words()+ if words & (seated.buried_ok | seated.slope_ok):return Nonefrac = row.sunk_m / row.height if row.height > 1e-6 else 1.0- if words & partial_ok:- if frac > PARTIAL_OK_ERROR_FRAC and row.sunk_m > SUNK_ERROR_M:- return Severity.ERROR- return Severity.WARN if frac > PARTIAL_OK_FRAC else None+ if words & seated.partial_ok:+ if frac <= seated.partial_ok_frac:+ return None+ return Severity.ERROR if row.sunk_m > SUNK_ERROR_M else Severity.WARNif row.sunk_m > SUNK_ERROR_M and frac > SUNK_ERROR_FRAC:return Severity.ERRORreturn Severity.WARN if row.sunk_m > SUNK_M else None@@ -210,14 +217,12 @@ def _asset_findings(rows: list[AssetRow], *, floating_m: float, ground_y: floatgap = row.ground_gap_mif gap is None or row.on_water or row.sunk_m > 0 or gap <= CONTACT_M:continue+ if row.attached: # mounted on what it touches: the settle leaves it, so does the gate+ continuesupport = _support_label(row, ground_y)- if gap > floating_m and row.attached:- out.append(_f(Severity.WARN, f"{q} is floating {gap:.2f} m above {support}, but its bbox touches {', '.join(row.attached[:3])}",- target=q, hint=f"fine if {q} is mounted on {row.attached[0]}; otherwise lower it by {gap:.2f} m onto {support}",- kind="floating", gap_m=gap, attached=row.attached[:3], zone=row.zone))- elif gap > floating_m:+ if gap > floating_m:floating.append((row, gap))- elif not row.attached:+ else:out.append(_f(Severity.WARN, f"{q} is unsupported: hovers {gap:.2f} m above {support} and touches nothing", target=q,hint=f"lower {q} by {gap:.2f} m onto {support}, or attach it to a neighbour; "f"if it is meant to hang free set {row.name}.userData.placement = 'free'",diff --git a/harness/runtime_js/lib/host_placement.mjs b/harness/runtime_js/lib/host_placement.mjsindex 21802d24..d996858d 100644--- a/harness/runtime_js/lib/host_placement.mjs+++ b/harness/runtime_js/lib/host_placement.mjs@@ -501,22 +501,24 @@ export function placementTable(scene, THREE, opts = {}) {// support. The zone code keeps its wrong constant; every frame anyone sees or judges// is seated. The moves are returned and carried in the census, so nothing is silent.//-// Deliberately conservative, mirroring the python gate's exemptions-// (codeverse3d/spatial/scene_placement.py; the name words are ONE list both read,-// placement_words.json):+// Deliberately conservative. What it accepts as seated, the python gate exempts too+// (codeverse3d/spatial/scene_placement.py; the words and the partial fraction are ONE+// file both read, placement_words.json):// · exempt assets (free / backdrop / enclosure / instanced) are never touched// · a foot in the water is a boat / jetty: never touched// · BURIED-ok names (basin, trench, pool…) are below ground by definition-// · PARTIAL-ok names (rocks, posts, trees…) may bury half their height; only a-// burial past 3/4 height is pulled up, and only to the 40 % embed that reads-// as "grown in", never to the surface+// · SLOPE-ok names (stairs, ramps, paths, terraces…) follow the terrain+// · PARTIAL-ok names (rocks, posts, trees…) may bury up to partial_ok_frac of their+// height; a deeper burial is pulled up only to the 40 % embed that reads as+// "grown in", never to the surface// · a floating asset that TOUCHES another asset may be mounted on it: skipped+// (Not accepted, only not auto-fixed — the gate still reports them: the slope guard+// below, a move beyond SETTLE_MAX_MOVE_M, a burial under SUNK_M at its shallowest column.)// · normal sunken assets keep a 4 cm embed (the zone recipes ask for 3-5 cm)const SETTLE_EMBED_M = 0.04;const SETTLE_PARTIAL_FRAC = 0.40;const SETTLE_MAX_MOVE_M = 6;const SETTLE_SEAT_EPS_M = 0.005;-const SLOPE_CONFORMAL_RE = /\b(stairs?|stairways?|staircases?|steps?|ramps?|walkways?|paths?|roads?|terraces?|platforms?)\b/i;/** Measure every placed asset once, then translate the clearly mis-seated ones onto* their support. Returns `{count, moves}`; mutates object positions (world-space dy@@ -524,7 +526,8 @@ const SLOPE_CONFORMAL_RE = /\b(stairs?|stairways?|staircases?|steps?|ramps?|walk* `placement_words.json` (the gate's own list: the host fetches it, a test reads it). */export function settleScene(scene, THREE, opts = {}) {if (!opts.words) throw new Error('settleScene needs opts.words (runtime_js/lib/placement_words.json)');- const buriedOk = new Set(opts.words.buried_ok), partialOk = new Set(opts.words.partial_ok);+ const buriedOk = new Set(opts.words.buried_ok), slopeOk = new Set(opts.words.slope_ok);+ const partialOk = new Set(opts.words.partial_ok), partialFrac = opts.words.partial_ok_frac;const { groundY, indices, assets, owner } = survey(scene, opts);const checked = assets.filter((a) => !a.exempt);const moves = [];@@ -533,11 +536,11 @@ export function settleScene(scene, THREE, opts = {}) {if (Date.now() - t0 > TIME_BUDGET_MS) break;const { columns, best, sunk, water, minSunk, anyRest } = probeFeet(a, indices, owner, groundY);if (!columns || water) continue;- const name = nameText(a.name), words = nameWords(a.name);+ const words = nameWords(a.name);const height = Math.max(a.max[1] - a.min[1], 1e-6);let dy = 0, why = '';if (sunk && sunk.sunk > 0) {- if (words.some((w) => buriedOk.has(w)) || SLOPE_CONFORMAL_RE.test(name)) continue;+ if (words.some((w) => buriedOk.has(w) || slopeOk.has(w))) continue;// Slope guard (2026-08-30): a structure following a hillside is "deeply sunk" at// its uphill columns while its downhill columns rest — lifting by the DEEPEST// burial strands the low end in the air. Measured on t36_santorini: six@@ -546,7 +549,7 @@ export function settleScene(scene, THREE, opts = {}) {if (anyRest || minSunk < Math.max(SUNK_M, 0.5 * sunk.sunk)) continue;const frac = minSunk / height;if (words.some((w) => partialOk.has(w))) {- if (frac <= 0.75) continue; // grown / driven in: fine+ if (frac <= partialFrac) continue; // grown / driven in: finedy = minSunk - SETTLE_PARTIAL_FRAC * height; // pull up to a 40 % embedwhy = 'sunken_partial';} else if (minSunk > SUNK_M) {diff --git a/harness/runtime_js/lib/placement_words.json b/harness/runtime_js/lib/placement_words.jsonindex f3ca58dd..f7461859 100644--- a/harness/runtime_js/lib/placement_words.json+++ b/harness/runtime_js/lib/placement_words.json@@ -1,14 +1,23 @@{"_comment": [- "Name words the scene placement rules exempt from 'sunken' (one home, review 2 C5):",- "codeverse3d/spatial/scene_placement.py (the gate) and runtime_js/lib/host_placement.mjs (the boot-time settle) both read this file.",+ "What the scene placement rules accept as seated (one home, review 2 C5; audit 2026-09-24 N27):",+ "codeverse3d/spatial/scene_placement.py (the gate) and runtime_js/lib/host_placement.mjs (the boot-time settle) both read this file,",+ "so the gate never reports what the settle deliberately leaves.",+ "buried_ok: below ground by definition. slope_ok: follows the terrain, so sunk uphill by construction.",+ "partial_ok: driven / grown in, fine up to partial_ok_frac of its height buried.","A name matches when one of its to_snake words is listed; list plurals explicitly."],+ "partial_ok_frac": 0.75,"buried_ok": ["basin", "bed", "canal", "cave", "cellar", "crater", "ditch", "drain", "foundation", "foundations","grave", "graves", "gutter", "hole", "holes", "lakebed", "moat", "pit", "pits", "pool", "pools","riverbed", "trench", "trenches", "tunnel", "tunnels", "well", "wells"],+ "slope_ok": [+ "path", "paths", "platform", "platforms", "ramp", "ramps", "road", "roads", "stair", "stairs",+ "staircase", "staircases", "stairway", "stairways", "step", "steps", "terrace", "terraces",+ "walkway", "walkways"+ ],"partial_ok": ["boulder", "boulders", "bridge", "bridges", "bush", "bushes", "cliff", "cliffs", "dock", "docks","dune", "dunes", "fence", "fences", "flower", "flowers", "grass", "hill", "hills", "jetties",diff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.pyindex 2367837a..91f1fb02 100644--- a/harness/tests/scene_gates/test_placement.py+++ b/harness/tests/scene_gates/test_placement.py@@ -5,6 +5,8 @@ from __future__ import annotationsimport jsonfrom types import SimpleNamespace+import pytest+from codeverse3d.contracts.artifacts import BuildResult, Severityfrom codeverse3d.contracts.common import Languagefrom codeverse3d.contracts.plan import AssetPlan, BBox, CameraPlan, ScenePlan, ZonePlan@@ -48,11 +50,16 @@ def test_floating_severity_by_gap_then_by_count():assert all(f.severity == Severity.ERROR for f in _by_kind(many, "floating")) and not many.passed-def test_floating_but_attached_is_only_a_warning():- r = placement_findings(_table(_row("Sign", gap=0.9, attached=("Post",))))- (f,) = _by_kind(r, "floating")- assert f.severity == Severity.WARN and "touches Post" in f.message and "mounted on Post" in f.fix_hint- assert r.passed[email protected]("row", [+ _row("Sign", gap=0.9, attached=("Post",)), # mounted on what it touches+ _row("Rock", sunk=0.6, into="Terrain", h=1.0), # partial-ok, 60 % buried+ _row("GardenStairways", sunk=1.3, into="Terrain", h=2.0), # slope-ok: sunk uphill by construction+])+def test_the_gate_accepts_what_the_settle_leaves(row):+ """Audit 2026-09-24 N27: the settle left these (placement_words.json + the touching rule) and the+ gate then reported them every round. One file now says what is seated."""+ r = placement_findings(_table(row))+ assert [f for f in r.findings if f.severity != Severity.INFO] == []def test_indoor_tolerance_is_tighter():diff --git a/harness/tests/scene_runtime/test_placement_census.py b/harness/tests/scene_runtime/test_placement_census.pyindex 935c7f55..bd6dd480 100644--- a/harness/tests/scene_runtime/test_placement_census.py+++ b/harness/tests/scene_runtime/test_placement_census.py@@ -122,6 +122,7 @@ zone.add(box('Boat', 2, 0.6, 0.8, -20, 0.0, -20)); // foot at pondconst rock = box('Rock', 1, 1.2, 1, 8, -0.6, -8); zone.add(rock); // half-buried rock: partial-ok, frac 0.5 <= 0.75const upper = box('UpperGround', 8, 1, 8, 9, 0, 20); env.add(upper); // an uphill terrace: slab y 0..1, top face at y=1const aqueduct = box('Aqueduct', 6, 0.5, 1, 5, 0.4, 20); zone.add(aqueduct); // spans flat ground -> terrace: downhill col floats, uphill col sunk 0.6+zone.add(box('GardenStairs', 2, 1, 1, 0, -0.5, -8)); // sunk 0.5 at every column: slope-ok, leftconst shelf = box('Shelf', 1, 0.1, 0.4, 12, 1.2, 0); // floating but TOUCHING the wallconst wall = box('Wall', 0.2, 2.5, 3, 12.5, 0, 0); zone.add(wall); zone.add(shelf);shelf.position.x = 12.35; // AABBs meet the wall's@@ -153,6 +154,7 @@ def test_settle_leaves_exempt_water_partial_and_mounted_alone(settled):# rests / floats low while another is buried 0.6 m in the terrace. Columns# disagree, so settle must refuse (the santorini stairway lesson).assert "Aqueduct" not in touched+ assert "GardenStairs" not in touched # slope-ok word (placement_words.json), the gate's list too (N27)after = {a["name"]: a for a in settled["after"]["assets"]}assert after["Bird"]["exempt"] == "free" # tagged free: untouchedassert after["Boat"]["supported"] # on water: untouched