Skip to content

Official Codebase of 3DCodeVerse

Python

placement: one exempt-word list, runtime_js/lib/placement_words.json, read by the gate and the settle

gaoypeng9a644f9b4083
diff --git a/harness/codeverse3d/spatial/scene_placement.py b/harness/codeverse3d/spatial/scene_placement.py
index c43f7fd6..f47a5f15 100644
--- a/harness/codeverse3d/spatial/scene_placement.py
+++ b/harness/codeverse3d/spatial/scene_placement.py
@@ -23,6 +23,8 @@ posts 0.97 m into the pond bed — a naive "> 0.10 m" rule flagged all of them
from __future__ import annotations
+import functools
+import json
import logging
from collections.abc import Sequence
from typing import Any
@@ -32,6 +34,7 @@ from pydantic import BaseModel, ConfigDict, Field
from codeverse3d.contracts.artifacts import GateFinding, GateReport, Severity
from codeverse3d.conventions import to_snake
from codeverse3d.proc import read_json_or_none
+from codeverse3d.spatial.node import runtime_js_dir
from codeverse3d.workspace import Workspace
log = logging.getLogger(__name__)
@@ -51,18 +54,17 @@ 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",
})
-#: things that are BELOW ground by definition: never "sunken"
-BURIED_OK_WORDS = frozenset({
- "basin", "bed", "canal", "cave", "cellar", "crater", "ditch", "drain", "foundation", "foundations", "grave", "gutter", "hole", "lakebed", "moat",
- "pit", "pool", "riverbed", "trench", "tunnel", "well",
-})
-#: things normally driven or grown into the ground: sunken only past half their height
-PARTIAL_OK_WORDS = frozenset({
- "boulder", "boulders", "bridge", "bush", "bushes", "cliff", "cliffs", "dock", "dune", "dunes", "fence", "fences", "flower", "flowers", "grass",
- "hill", "hills", "jetty", "log", "logs", "mound", "mounds", "outcrop", "pebble", "pebbles", "pier", "pile", "piles", "plant", "plants", "pole",
- "poles", "post", "posts", "reed", "reeds", "rock", "rocks", "root", "roots", "shrub", "shrubs", "stake", "stakes", "stone", "stones", "stump",
- "stumps", "tree", "trees", "trunk", "trunks", "tuft", "tufts",
-})
+#: 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``.
+PLACEMENT_WORDS = "placement_words.json"
+
+
+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 _nums(v: object) -> list[float] | None:
@@ -181,10 +183,11 @@ def _sunk_severity(row: AssetRow) -> Severity | None:
if row.sunk_m <= 0 or row.on_water:
return None
words = _words(row.name)
- if words & BURIED_OK_WORDS:
+ buried_ok, partial_ok = _exempt_words()
+ if words & buried_ok:
return None
frac = row.sunk_m / row.height if row.height > 1e-6 else 1.0
- if words & PARTIAL_OK_WORDS:
+ 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
diff --git a/harness/runtime_js/lib/host_placement.mjs b/harness/runtime_js/lib/host_placement.mjs
index ad5fa5c7..e0fb8d14 100644
--- a/harness/runtime_js/lib/host_placement.mjs
+++ b/harness/runtime_js/lib/host_placement.mjs
@@ -505,7 +505,8 @@ export function placementTable(scene, THREE, opts = {}) {
// 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 — keep the two in sync):
+// (codeverse3d/spatial/scene_placement.py; the name words are ONE list 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
@@ -518,14 +519,23 @@ 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 BURIED_OK_RE = /\b(basin|bed|canal|cave|cellar|crater|ditch|drain|foundations?|graves?|gutter|holes?|lakebed|moat|pits?|pools?|riverbed|trench(es)?|tunnels?|wells?)\b/i;
const SLOPE_CONFORMAL_RE = /\b(stairs?|stairways?|staircases?|steps?|ramps?|walkways?|paths?|roads?|terraces?|platforms?)\b/i;
-const PARTIAL_OK_RE = /\b(boulders?|bridges?|bush(es)?|cliffs?|docks?|dunes?|fences?|flowers?|grass|hills?|jett(y|ies)|logs?|mounds?|outcrops?|pebbles?|piers?|piles?|plants?|poles?|posts?|reeds?|rocks?|roots?|shrubs?|stakes?|stones?|stumps?|trees?|trunks?|tufts?)\b/i;
+
+/** The words of python's `conventions.to_snake(name)` (digits-only words dropped) — the
+ * tokenisation the placement gate matches `placement_words.json` with. */
+function nameWords(name) {
+ return String(name || '').replace(/[^0-9A-Za-z]+/g, ' ')
+ .replace(/(?<=[a-z0-9])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/g, ' ')
+ .toLowerCase().split(' ').filter((w) => w && !/^\d+$/.test(w));
+}
/** Measure every placed asset once, then translate the clearly mis-seated ones onto
* their support. Returns `{count, moves}`; mutates object positions (world-space dy
- * applied through each parent's frame) and leaves matrices updated. */
+ * applied through each parent's frame) and leaves matrices updated. `opts.words` is
+ * `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 { groundY, indices, assets, owner } = survey(scene, opts);
const checked = assets.filter((a) => !a.exempt);
const moves = [];
@@ -534,11 +544,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 = spaced(a.name);
+ const name = spaced(a.name), 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 (BURIED_OK_RE.test(name) || SLOPE_CONFORMAL_RE.test(name)) continue;
+ if (words.some((w) => buriedOk.has(w)) || SLOPE_CONFORMAL_RE.test(name)) 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 +556,7 @@ export function settleScene(scene, THREE, opts = {}) {
// Settle only what is sunk at EVERY column, and lift by the SHALLOWEST burial.
if (anyRest || minSunk < Math.max(SUNK_M, 0.5 * sunk.sunk)) continue;
const frac = minSunk / height;
- if (PARTIAL_OK_RE.test(name)) {
+ if (words.some((w) => partialOk.has(w))) {
if (frac <= 0.75) continue; // grown / driven in: fine
dy = minSunk - SETTLE_PARTIAL_FRAC * height; // pull up to a 40 % embed
why = 'sunken_partial';
diff --git a/harness/runtime_js/lib/placement_words.json b/harness/runtime_js/lib/placement_words.json
new file mode 100644
index 00000000..f3ca58dd
--- /dev/null
+++ b/harness/runtime_js/lib/placement_words.json
@@ -0,0 +1,20 @@
+{
+ "_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.",
+ "A name matches when one of its to_snake words is listed; list plurals explicitly."
+ ],
+ "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"
+ ],
+ "partial_ok": [
+ "boulder", "boulders", "bridge", "bridges", "bush", "bushes", "cliff", "cliffs", "dock", "docks",
+ "dune", "dunes", "fence", "fences", "flower", "flowers", "grass", "hill", "hills", "jetties",
+ "jetty", "log", "logs", "mound", "mounds", "outcrop", "outcrops", "pebble", "pebbles", "pier",
+ "piers", "pile", "piles", "plant", "plants", "pole", "poles", "post", "posts", "reed", "reeds",
+ "rock", "rocks", "root", "roots", "shrub", "shrubs", "stake", "stakes", "stone", "stones", "stump",
+ "stumps", "tree", "trees", "trunk", "trunks", "tuft", "tufts"
+ ]
+}
diff --git a/harness/runtime_js/lib/scene_host.mjs b/harness/runtime_js/lib/scene_host.mjs
index f794daf6..c79c2d38 100644
--- a/harness/runtime_js/lib/scene_host.mjs
+++ b/harness/runtime_js/lib/scene_host.mjs
@@ -315,7 +315,8 @@ async function boot(opts) {
info.stage = 'settle';
try {
const c0 = sceneCensus(state.scene, THREE);
- state.settleInfo = settleScene(state.scene, THREE, { groundY: c0.ground_y, contentBox: c0.content_bbox });
+ const words = await (await fetch(new URL('./placement_words.json', import.meta.url))).json();
+ state.settleInfo = settleScene(state.scene, THREE, { groundY: c0.ground_y, contentBox: c0.content_bbox, words });
} catch (e) {
state.settleInfo = { count: 0, moves: [], error: String((e && e.message) || e).slice(0, 300) };
}
diff --git a/harness/tests/scene_gates/test_placement.py b/harness/tests/scene_gates/test_placement.py
index 3ed422da..2367837a 100644
--- a/harness/tests/scene_gates/test_placement.py
+++ b/harness/tests/scene_gates/test_placement.py
@@ -71,6 +71,8 @@ def test_sunken_thresholds_height_fraction_and_name_words():
_row("Rock", sunk=0.45, into="Terrain", h=1.2), # starter-scene rock: 37 % buried is fine
_row("Boulder", sunk=0.8, into="Terrain", h=1.0), # 80 % buried → ERROR even for a rock
_row("PondBasin", sunk=1.4, into="Terrain", h=1.2), # dug in by definition
+ _row("OldWells", sunk=0.5, into="Terrain", h=1.0), # plurals too (the settle's rule; was ERROR here)
+ _row("SeaReefOutcrops", sunk=0.45, into="Terrain", h=1.0), # partial-ok plural: 45 % buried is fine
_row("Jetty", sunk=0.97, into="Terrain", h=1.1, water=True), # posts in the pond bed
))
sev = {f.target: f.severity for f in _by_kind(r, "sunken")}
diff --git a/harness/tests/scene_runtime/test_placement_census.py b/harness/tests/scene_runtime/test_placement_census.py
index 4a8800dd..935c7f55 100644
--- a/harness/tests/scene_runtime/test_placement_census.py
+++ b/harness/tests/scene_runtime/test_placement_census.py
@@ -104,7 +104,9 @@ def test_no_false_positives_on_legitimate_placements(table):
SETTLE_JS = """
import * as THREE from 'three';
+import fs from 'node:fs';
import { settleScene, placementTable } from './lib/host_placement.mjs';
+const words = JSON.parse(fs.readFileSync('./lib/placement_words.json', 'utf8'));
const mat = new THREE.MeshStandardMaterial();
const box = (name, sx, sy, sz, x, y, z) => { const m = new THREE.Mesh(new THREE.BoxGeometry(sx, sy, sz), mat); m.name = name; m.position.set(x, y + sy / 2, z); return m; };
const scene = new THREE.Scene();
@@ -124,7 +126,7 @@ const shelf = box('Shelf', 1, 0.1, 0.4, 12, 1.2, 0); // floating but
const 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
scene.updateMatrixWorld(true);
-const settle = settleScene(scene, THREE, { groundY: 0 });
+const settle = settleScene(scene, THREE, { groundY: 0, words });
const after = placementTable(scene, THREE, { groundY: 0 });
console.log(JSON.stringify({ settle, after: { assets: after.assets.map((a) => ({ name: a.name, gap: a.ground_gap_m, sunk: a.sunk_m, supported: a.supported, exempt: a.exempt })) } }));
"""