Skip to content

Official Codebase of 3DCodeVerse

Python

JS name rules: one splitInstance (= conventions.split_instance) and one nameWords (= to_snake's words)

gaoypengf6302555a12f
diff --git a/harness/runtime_js/lib/backdrop.mjs b/harness/runtime_js/lib/backdrop.mjs
index 2e31a14f..584c8e66 100644
--- a/harness/runtime_js/lib/backdrop.mjs
+++ b/harness/runtime_js/lib/backdrop.mjs
@@ -49,6 +49,25 @@ export function drawableBox(o, THREE) {
return box.isEmpty() ? null : box;
}
+/** python's `conventions._INSTANCE_RE`: `Leg_2` / `Rock.003` / `Fence-1` → ['Leg', '2']; a name with no
+ * instance suffix (`Leg2`, `Cart_800006`) → [name, '']. THE instance rule on the JS side (tests pin the two). */
+const INSTANCE_RE = /^(.+?)[_.-](\d{1,3})$/;
+export function splitInstance(name) {
+ const m = INSTANCE_RE.exec(String(name || ''));
+ return m ? [m[1], m[2]] : [String(name || ''), ''];
+}
+
+/** The words of python's `conventions.to_snake(name)`, digits-only words dropped: `LEDStairs` →
+ * ['led', 'stairs']. THE name tokeniser every JS word rule (sky, ground, water, placement) reads. */
+export 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));
+}
+
+/** `nameWords` as one string, for the word regexes: 'HDRISky' → 'hdri sky'. */
+export function nameText(name) { return nameWords(name).join(' '); }
+
export const SKY_NAME_RE = /\b(sky|skydome|skybox|stars|clouds?|sun|moon|atmosphere)\b/i;
export const GROUND_NAME_RE = /\b(ground|terrain|floor|water|ocean|sea|lake|river|plane|sand|grass|land)\b/i;
@@ -62,8 +81,7 @@ export function classifyBackdrop(obj, box, contentSpan = 0) {
// Generated scene names normally use PascalCase / snake_case. Word boundaries
// alone missed PlanetSkyBackdrop and SkyAtmosphereBand0, framing the sky as a
// building. Keep the same vocabulary and shape rules for every naming style.
- const name = (obj.name || (obj.parent && obj.parent.name) || '')
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ');
+ const name = nameText(obj.name || (obj.parent && obj.parent.name) || '');
const sx = box.max.x - box.min.x, sy = box.max.y - box.min.y, sz = box.max.z - box.min.z;
const span = Math.max(sx, sz);
// sunRig's MoonDisc can be only five metres wide in a compact worldShell, but
diff --git a/harness/runtime_js/lib/host_census.mjs b/harness/runtime_js/lib/host_census.mjs
index d8e1b616..a8786c9c 100644
--- a/harness/runtime_js/lib/host_census.mjs
+++ b/harness/runtime_js/lib/host_census.mjs
@@ -6,7 +6,7 @@
* overlap statistics. Returns plain JSON.
*/
-import { classifyBackdrop, drawableBox } from './backdrop.mjs';
+import { classifyBackdrop, drawableBox, splitInstance } from './backdrop.mjs';
import { geometryTriangles as triCount, geometryInstances } from './census.mjs';
import { placementTable } from './host_placement.mjs';
@@ -92,7 +92,7 @@ function walkGroup(root, THREE) {
copy(o.name || 'instances', tmp);
}
} else {
- copy((o.name || '').replace(/[_.]\d+$/, '') || 'meshes', mb);
+ copy(splitInstance(o.name)[0] || 'meshes', mb);
}
if (mb.isEmpty()) return;
const kind = classifyBackdrop(o, mb); // shared rules (lib/backdrop.mjs); no content bbox yet here
diff --git a/harness/runtime_js/lib/host_metrics.mjs b/harness/runtime_js/lib/host_metrics.mjs
index 784529c4..da80cb8f 100644
--- a/harness/runtime_js/lib/host_metrics.mjs
+++ b/harness/runtime_js/lib/host_metrics.mjs
@@ -3,7 +3,7 @@
* readback of the render canvas and near-geometry tests for a camera.
*/
-import { GROUND_NAME_RE, classifyBackdrop, nonSolid, drawableBox } from './backdrop.mjs';
+import { GROUND_NAME_RE, classifyBackdrop, nonSolid, drawableBox, nameText } from './backdrop.mjs';
export const SAMPLE_W = 96;
export const SAMPLE_H = 54;
@@ -90,7 +90,7 @@ export const TERRAIN_SPAN_M = 40;
/** Does the name carry a ground word? CamelCase split first: `HeadlandTerrain` is a terrain. */
export function groundNamed(name) {
- return GROUND_NAME_RE.test(String(name || '').replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' '));
+ return GROUND_NAME_RE.test(nameText(name));
}
/**
diff --git a/harness/runtime_js/lib/host_placement.mjs b/harness/runtime_js/lib/host_placement.mjs
index e0fb8d14..21802d24 100644
--- a/harness/runtime_js/lib/host_placement.mjs
+++ b/harness/runtime_js/lib/host_placement.mjs
@@ -54,7 +54,7 @@
* below, which is exactly the sunk case).
*/
-import { classifyBackdrop, GROUND_NAME_RE, nonSolid } from './backdrop.mjs';
+import { classifyBackdrop, GROUND_NAME_RE, nonSolid, nameText, nameWords, splitInstance } from './backdrop.mjs';
import { geometryTriangles } from './census.mjs';
export const MAX_ASSETS = 400;
@@ -107,7 +107,7 @@ class ColumnIndex {
this.grid = null;
this.kind = this.empty ? 'content' : classifyBackdrop(mesh, { min: { x: minx, y: miny, z: minz }, max: { x: maxx, y: maxy, z: maxz } });
this.water = isWaterLike(mesh);
- this.groundLike = this.kind === 'ground' || GROUND_NAME_RE.test(spaced(mesh.name)) || GROUND_NAME_RE.test(spaced(nearestName(mesh)));
+ this.groundLike = this.kind === 'ground' || GROUND_NAME_RE.test(nameText(mesh.name)) || GROUND_NAME_RE.test(nameText(nearestName(mesh)));
}
get empty() { return this.count === 0 || this.tris === 0 || !Number.isFinite(this.min[0]); }
@@ -194,10 +194,7 @@ function nearestName(obj) {
return obj.type || 'mesh';
}
-/** 'PondWater' / 'pond_water' → 'Pond Water' so the shared word regexes see the words. */
-function spaced(name) { return String(name || '').replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_\-.]+/g, ' '); }
-
-function isWaterLike(mesh) { return !!mesh && (WATER_RE.test(spaced(mesh.name)) || WATER_RE.test(spaced(materialNames(mesh))) || WATER_RE.test(spaced(nearestName(mesh)))); }
+function isWaterLike(mesh) { return !!mesh && (WATER_RE.test(nameText(mesh.name)) || WATER_RE.test(nameText(materialNames(mesh))) || WATER_RE.test(nameText(nearestName(mesh)))); }
/**
* Every visible, non-instanced Mesh with a position attribute → ColumnIndex (skipping
@@ -251,7 +248,7 @@ function collectAssets(scene, indices, volumetrics, contentBox) {
if (!o.visible) return;
// one slot per FAMILY (Planter_3 / Planter.003 → Planter): the by-name check matches on
// the plan's word, and 30 numbered props must not push the hero behind them past the cap
- const family = o.name ? o.name.replace(/[_.]\d+$/, '') : '';
+ const family = o.name ? splitInstance(o.name)[0] : '';
if (o !== child && family && inner.length < MAX_INNER_NAMES && !inner.includes(family)) inner.push(family);
if (o.isInstancedMesh) instanced += 1;
else if (indices.has(o)) {
@@ -259,7 +256,7 @@ function collectAssets(scene, indices, volumetrics, contentBox) {
meshes.push(ci);
for (let m = o; m && m !== child; m = m.parent) {
if (!m.name) continue;
- const fam = m.name.replace(/[_.]\d+$/, '');
+ const fam = splitInstance(m.name)[0];
if (!members.has(fam)) members.set(fam, new Map());
const box = members.get(fam).get(m) || [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
for (let k = 0; k < 3; k++) { box[0][k] = Math.min(box[0][k], ci.min[k]); box[1][k] = Math.max(box[1][k], ci.max[k]); }
@@ -291,7 +288,7 @@ function collectAssets(scene, indices, volumetrics, contentBox) {
// a ground / floor / water surface is what things sit ON, whatever its size
if (ci.kind !== 'content' || ci.groundLike || ci.water) backdrop += 1;
}
- if (backdrop === meshes.length || GROUND_NAME_RE.test(spaced(a.name)) || WATER_RE.test(spaced(a.name))) a.exempt = 'backdrop';
+ if (backdrop === meshes.length || GROUND_NAME_RE.test(nameText(a.name)) || WATER_RE.test(nameText(a.name))) a.exempt = 'backdrop';
else if (contentBox && enclosesContent(a, contentBox)) a.exempt = 'enclosure';
}
assets.push(a);
@@ -521,14 +518,6 @@ 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;
-/** 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. `opts.words` is
@@ -544,7 +533,7 @@ 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), words = nameWords(a.name);
+ const name = nameText(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) {
diff --git a/harness/tests/scene_runtime/test_backdrop.py b/harness/tests/scene_runtime/test_backdrop.py
index 538039af..245582f0 100644
--- a/harness/tests/scene_runtime/test_backdrop.py
+++ b/harness/tests/scene_runtime/test_backdrop.py
@@ -31,6 +31,8 @@ CASES = [
("SkyAtmosphereBand0", [90, 4, 90], False, 0, "sky"),
("MoonLamp", [1, 1, 1], False, 0, "content"), # a solid prop remains content
("SkyScraper", [25, 200, 25], False, 0, "content"), # the size guard still matters
+ ("HDRISky", [400, 200, 400], False, 0, "sky"), # acronym names split like to_snake (N5)
+ ("GPUTerrain", [30, 1.0, 30], False, 0, "ground"),
]
@@ -83,3 +85,23 @@ console.log(JSON.stringify({{ content: census.content_bbox, all: census.bbox, fr
assert got["content"]["max"] == [15, 20, 20]
assert got["framed"] == got["content"]
assert got["all"]["min"][0] < -270 # background geometry is retained and still counted
+
+
+#: names on both sides of every JS name rule: acronyms, instance separators, long numeric ids
+NAMES = ["Leg_2", "Rock.003", "Fence-1", "Leg2", "DonkeyCart_800006", "Leg_", "Planter_12", "LEDStairs",
+ "HDRISky", "UVGround", "GPUTerrain", "PondWater", "pond_water", "SkyAtmosphereBand0", "TV-Stand.2", ""]
+
+
+def test_js_name_rules_mirror_conventions():
+ """Audit 2026-09-24 N3/N5: `splitInstance` IS `conventions.split_instance` and `nameWords` IS
+ `to_snake`'s words — the census/placement copies split `Fence-1` and `LEDStairs` otherwise."""
+ from codeverse3d.conventions import split_instance, to_snake
+
+ got = run_node_json(f"""
+import {{ splitInstance, nameWords }} from '{RUNTIME_JS}/lib/backdrop.mjs';
+const names = {json.dumps(NAMES)};
+console.log(JSON.stringify({{ split: names.map(splitInstance), words: names.map(nameWords) }}));
+""")
+ assert got["split"] == [list(split_instance(n)) for n in NAMES]
+ snake_words = [[w for w in to_snake(n).split("_") if not w.isdigit()] if n else [] for n in NAMES]
+ assert got["words"] == snake_words
diff --git a/harness/tests/scene_runtime/test_placement_inner_families.py b/harness/tests/scene_runtime/test_placement_inner_families.py
index 68d638f9..4d0acc0a 100644
--- a/harness/tests/scene_runtime/test_placement_inner_families.py
+++ b/harness/tests/scene_runtime/test_placement_inner_families.py
@@ -45,16 +45,19 @@ console.log(JSON.stringify({{ cap: MAX_INNER_NAMES, inner: row.inner, hasHero: r
assert len(got["inner"]) <= got["cap"]
-def test_a_wrapper_of_scattered_instances_reports_the_instance_size():
[email protected]("sep", ["", "_", "-"])
+def test_a_wrapper_of_scattered_instances_reports_the_instance_size(sep: str):
"""`families`: twelve 2.2 m fence panels along a 15 m path are one row ('PicketFences');
the row's bbox is the run, `families.PicketFence` is the panel (loop 9 lighthouse,
- 2026-09-07: the scale check read 14.7 m against the plan's 2.4 m panel)."""
+ 2026-09-07: the scale check read 14.7 m against the plan's 2.4 m panel). Numbered
+ panels (`PicketFence-3`) are one family by `conventions.split_instance` (audit
+ 2026-09-24 N3: the JS copy of the rule missed the hyphen)."""
body = f"""
import * as THREE from 'three';
import {{ sceneCensus }} from '{RUNTIME_JS}/lib/host_census.mjs';
const solid = new THREE.MeshStandardMaterial();
const panel = (i) => {{
- const g = new THREE.Group(); g.name = 'PicketFence';
+ const g = new THREE.Group(); g.name = 'PicketFence' + ('{sep}' ? '{sep}' + i : '');
for (let p = 0; p < 6; p++) {{ const m = new THREE.Mesh(new THREE.BoxGeometry(0.08, 1.2, 0.03), solid); m.name = 'Picket_' + p; m.position.set(-1.0 + p * 0.4, 0.6, 0); g.add(m); }}
const rail = new THREE.Mesh(new THREE.BoxGeometry(2.2, 0.06, 0.03), solid); rail.name = 'Rail'; rail.position.set(0, 0.9, 0); g.add(rail);
g.position.set(0, 0, i * 1.25); return g;