Official Codebase of 3DCodeVerse
Python
drawableBox spans an InstancedMesh's instances, so census and coverage classify scatter from one box
gaoypeng39b3889f9b89
diff --git a/harness/runtime_js/lib/backdrop.mjs b/harness/runtime_js/lib/backdrop.mjsindex 584c8e66..a7cbf9a4 100644--- a/harness/runtime_js/lib/backdrop.mjs+++ b/harness/runtime_js/lib/backdrop.mjs@@ -39,11 +39,14 @@ export function nonSolid(mesh) {return real.length > 0 && real.every((m) => m.depthWrite === false);}-/** World-space AABB of a drawable (a fresh THREE.Box3), or null when it has none. */+/** World-space AABB of a drawable (a fresh THREE.Box3), or null when it has none. An+ * InstancedMesh's box spans every instance (three's own `InstancedMesh.boundingBox`), not the+ * prototype's: 40 cloud puffs over 3 km are a 3 km box, whoever asks. */export function drawableBox(o, THREE) {if (!o.geometry) return null;if (!o.geometry.boundingBox) o.geometry.computeBoundingBox();- const gb = o.geometry.boundingBox;+ if (o.isInstancedMesh && !o.boundingBox) o.computeBoundingBox();+ const gb = o.isInstancedMesh ? o.boundingBox : o.geometry.boundingBox;if (!gb || gb.isEmpty()) return null;const box = new THREE.Box3().copy(gb).applyMatrix4(o.matrixWorld);return box.isEmpty() ? null : box;diff --git a/harness/runtime_js/lib/host_census.mjs b/harness/runtime_js/lib/host_census.mjsindex a8786c9c..8022a609 100644--- a/harness/runtime_js/lib/host_census.mjs+++ b/harness/runtime_js/lib/host_census.mjs@@ -78,23 +78,17 @@ function walkGroup(root, THREE) {if (o.isMesh) tris += triCount(o.geometry) * count;const mats = Array.isArray(o.material) ? o.material : [o.material];if (mats.some((m) => isCustomShader(m, THREE))) custom += 1;- let mb = drawableBox(o, THREE);+ const mb = drawableBox(o, THREE); // an InstancedMesh's box spans its instancesif (!mb) return;- if (o.isInstancedMesh) {- const gb = o.geometry.boundingBox;- mb = new THREE.Box3();+ if (o.isInstancedMesh) { // each instance is a placed copy of its familyconst m = new THREE.Matrix4();- const n = Math.min(o.count, 4096);- for (let i = 0; i < n; i++) {+ for (let i = 0, n = Math.min(o.count, 4096); i < n; i++) {o.getMatrixAt(i, m);- tmp.copy(gb).applyMatrix4(m).applyMatrix4(o.matrixWorld);- mb.union(tmp);- copy(o.name || 'instances', tmp);+ copy(o.name || 'instances', tmp.copy(o.geometry.boundingBox).applyMatrix4(m).applyMatrix4(o.matrixWorld));}} else {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 herekinds[kind] += 1;boxAll.union(mb);diff --git a/harness/tests/scene_runtime/test_backdrop.py b/harness/tests/scene_runtime/test_backdrop.pyindex 245582f0..948107d9 100644--- a/harness/tests/scene_runtime/test_backdrop.py+++ b/harness/tests/scene_runtime/test_backdrop.py@@ -105,3 +105,26 @@ console.log(JSON.stringify({{ split: names.map(splitInstance), words: names.map(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+++def test_instanced_scatter_is_one_box_for_census_and_coverage():+ """Audit 2026-09-24 N28: 40 cloud puffs over 3 km were `sky` to the census (its own+ per-instance box) and `content` to coverage (`drawableBox` = one 10 m puff)."""+ got = run_node_json(f"""+import * as THREE from 'three';+import {{ classifyBackdrop, drawableBox }} from '{RUNTIME_JS}/lib/backdrop.mjs';+import {{ sceneCensus }} from '{RUNTIME_JS}/lib/host_census.mjs';+const scene = new THREE.Scene(), sky = new THREE.Group(), village = new THREE.Group();+sky.name = 'Sky'; village.name = 'Village'; scene.add(sky, village);+const inst = new THREE.InstancedMesh(new THREE.SphereGeometry(5), new THREE.MeshStandardMaterial(), 40);+inst.name = 'Clouds'; sky.add(inst);+const m = new THREE.Matrix4();+for (let i = 0; i < 40; i++) {{ m.makeTranslation(-1500 + i * 75, 200, (i % 5) * 300 - 600); inst.setMatrixAt(i, m); }}+const house = new THREE.Mesh(new THREE.BoxGeometry(10, 6, 8), new THREE.MeshStandardMaterial()); village.add(house);+scene.updateMatrixWorld(true);+const census = sceneCensus(scene, THREE);+const box = drawableBox(inst, THREE);+console.log(JSON.stringify({{ census: census.groups.find((g) => g.name === 'Sky').kind,+ coverage: classifyBackdrop(inst, box, 10), span: box.max.x - box.min.x }}));+""")+ assert got == {"census": "sky", "coverage": "sky", "span": 2935}, got