Skip to content

Official Codebase of 3DCodeVerse

Python

scene_frames: a lens is never "inside" a god ray — one `nonSolid`, both probes

ziyaoe6bf41a94810
diff --git a/harness/runtime_js/lib/backdrop.mjs b/harness/runtime_js/lib/backdrop.mjs
index ba06f9c8..cef3d565 100644
--- a/harness/runtime_js/lib/backdrop.mjs
+++ b/harness/runtime_js/lib/backdrop.mjs
@@ -16,6 +16,29 @@
* content everything else
*/
+/**
+ * A mesh that does not WRITE DEPTH is a volumetric pass, not matter: haze shells,
+ * god rays, light shafts, glow cards. It cannot support anything, nothing can sink
+ * into it, and overlapping it is what it is FOR.
+ *
+ * Measured on bench/out/scene_baseline (2026-09-05): every scene the generator wrote
+ * uses `depthWrite: false` 34-42 times, and two of the six cells failed
+ * `scene_placement` on nothing else — "BlackPine_5 is sunken 3.46 m into
+ * AtmosphereHaze" (MeshBasicMaterial, opacity 0.035) and "WindowSnowView/Mesh_49 and
+ * Environment/MoonlightShaft overlap 100%" (opacity 0.04, AdditiveBlending). Both
+ * scenes were correct; the gate was measuring fog.
+ *
+ * Opacity is deliberately NOT part of the rule: glass sits at 0.3-0.6 and keeps
+ * writing depth, and a greenhouse pane really is a surface. A solid wall the model
+ * mistakenly wrote `depthWrite: false` on stops being a support — a missed defect,
+ * which is the cheaper error, and one that matches how the frame actually renders.
+ */
+export function nonSolid(mesh) {
+ const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
+ const real = mats.filter(Boolean);
+ return real.length > 0 && real.every((m) => m.depthWrite === false);
+}
+
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;
diff --git a/harness/runtime_js/lib/host_metrics.mjs b/harness/runtime_js/lib/host_metrics.mjs
index 8b04c365..bfcc5d5c 100644
--- a/harness/runtime_js/lib/host_metrics.mjs
+++ b/harness/runtime_js/lib/host_metrics.mjs
@@ -3,6 +3,8 @@
* readback of the render canvas and near-geometry tests for a camera.
*/
+import { nonSolid } from './backdrop.mjs';
+
export const SAMPLE_W = 96;
export const SAMPLE_H = 54;
@@ -63,7 +65,12 @@ export function nearGeometry(scene, camera, THREE, limitM = 0.3) {
let nearest = Infinity;
let nearestName = '';
const targets = [];
- scene.traverse((o) => { if ((o.isMesh || o.isInstancedMesh) && o.visible) targets.push(o); });
+ // A volumetric pass is not something a lens can be "inside": greenhouse's
+ // `camera inside ['SunShaft_0','SunShaft_3']` (bench/out/scene_baseline, 2026-09-05)
+ // was three god-ray slabs of MeshBasicMaterial at opacity 0.075 with
+ // `depthWrite: false` — you see straight through them, which is their whole job.
+ // Same rule as the placement gate, one spelling, in backdrop.mjs.
+ scene.traverse((o) => { if ((o.isMesh || o.isInstancedMesh) && o.visible && !nonSolid(o)) targets.push(o); });
const pts = [];
for (let gy = -1; gy <= 1; gy++) for (let gx = -1; gx <= 1; gx++) pts.push([gx * 0.6, gy * 0.6]);
let hits = 0;
diff --git a/harness/runtime_js/lib/host_placement.mjs b/harness/runtime_js/lib/host_placement.mjs
index aeeb9fb8..8f58088c 100644
--- a/harness/runtime_js/lib/host_placement.mjs
+++ b/harness/runtime_js/lib/host_placement.mjs
@@ -53,7 +53,7 @@
* below, which is exactly the sunk case).
*/
-import { classifyBackdrop, GROUND_NAME_RE } from './backdrop.mjs';
+import { classifyBackdrop, GROUND_NAME_RE, nonSolid } from './backdrop.mjs';
import { geometryTriangles } from './census.mjs';
export const MAX_ASSETS = 400;
@@ -74,29 +74,6 @@ const BARY_TOL = 1e-4;
const r3 = (v) => +v.toFixed(3);
-/**
- * A mesh that does not WRITE DEPTH is a volumetric pass, not matter: haze shells,
- * god rays, light shafts, glow cards. It cannot support anything, nothing can sink
- * into it, and overlapping it is what it is FOR.
- *
- * Measured on bench/out/scene_baseline (2026-09-05): every scene the generator wrote
- * uses `depthWrite: false` 34-42 times, and two of the six cells failed
- * `scene_placement` on nothing else — "BlackPine_5 is sunken 3.46 m into
- * AtmosphereHaze" (MeshBasicMaterial, opacity 0.035) and "WindowSnowView/Mesh_49 and
- * Environment/MoonlightShaft overlap 100%" (opacity 0.04, AdditiveBlending). Both
- * scenes were correct; the gate was measuring fog.
- *
- * Opacity is deliberately NOT part of the rule: glass sits at 0.3-0.6 and keeps
- * writing depth, and a greenhouse pane really is a surface. A solid wall the model
- * mistakenly wrote `depthWrite: false` on stops being a support — a missed defect,
- * which is the cheaper error, and one that matches how the frame actually renders.
- */
-export function nonSolid(mesh) {
- const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
- const real = mats.filter(Boolean);
- return real.length > 0 && real.every((m) => m.depthWrite === false);
-}
-
/** World-space vertices + XZ triangle buckets for vertical column queries on one mesh. */
class ColumnIndex {
constructor(mesh) {
diff --git a/harness/tests/scene_runtime/test_camera_volumetric.py b/harness/tests/scene_runtime/test_camera_volumetric.py
new file mode 100644
index 00000000..5f8fc398
--- /dev/null
+++ b/harness/tests/scene_runtime/test_camera_volumetric.py
@@ -0,0 +1,78 @@
+"""A lens is never "inside" a god ray.
+
+Measured on `bench/out/scene_baseline` (2026-09-05). greenhouse's `scene_frames`
+raised, on authored cameras:
+
+ camera inside / touching geometry: inside ['SunShaft_0', 'SunShaft_3']
+ camera inside / touching geometry: inside ['SunShaft_2']
+
+`SunShaft` is three slabs of MeshBasicMaterial at opacity 0.075 with
+`depthWrite: false` and AdditiveBlending — a shaft of light through a greenhouse roof.
+Standing in one is what the shot is; you see straight through it. The near-geometry
+probe counted them because it raycast and bbox-tested every visible mesh.
+
+Same rule as the placement gate (`backdrop.nonSolid`, D54), one spelling for both.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from codeverse.config import get_settings
+from tests.scene_runtime.conftest import needs_node, run_node_json
+
+pytestmark = [pytest.mark.node, needs_node]
+
+RUNTIME_JS = get_settings().runtime_js_dir()
+
+JS = """
+import * as THREE from 'three';
+import { nearGeometry } from './lib/host_metrics.mjs';
+const solid = new THREE.MeshStandardMaterial();
+const shaftMat = new THREE.MeshBasicMaterial({
+ color: 0xfff0c0, transparent: true, opacity: 0.075,
+ depthWrite: DEPTH_WRITE, blending: THREE.AdditiveBlending, side: THREE.DoubleSide,
+});
+const scene = new THREE.Scene();
+const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60, 2, 2), solid);
+ground.name = 'Ground'; ground.rotation.x = -Math.PI / 2; scene.add(ground);
+// a shaft standing around the eye, and a real bench two metres away
+const shaft = new THREE.Mesh(new THREE.BoxGeometry(3, 5, 3), shaftMat);
+shaft.name = 'SunShaft_0'; shaft.position.set(0, 2.5, 0); scene.add(shaft);
+const bench = new THREE.Mesh(new THREE.BoxGeometry(1.6, 0.9, 0.5), solid);
+bench.name = 'Bench'; bench.position.set(0, 0.45, -3); scene.add(bench);
+scene.updateMatrixWorld(true);
+const cam = new THREE.PerspectiveCamera(50, 16 / 9, 0.1, 500);
+cam.position.set(0, 1.6, 0);
+cam.lookAt(0, 1.2, -3);
+cam.updateMatrixWorld(true);
+console.log(JSON.stringify(nearGeometry(scene, cam, THREE)));
+"""
+
+
+def _run(depth_write: str) -> dict:
+ return run_node_json(JS.replace("DEPTH_WRITE", depth_write).replace("'./lib/", f"'{RUNTIME_JS}/lib/"))
+
+
[email protected](scope="module")
+def shaft() -> dict:
+ return _run("false")
+
+
+def test_a_lens_standing_in_a_god_ray_is_not_in_geometry(shaft):
+ assert shaft["inside_mesh_bbox"] == []
+ assert shaft["camera_in_geometry"] is False
+
+
+def test_the_bench_behind_it_is_still_seen(shaft):
+ """The rule removes the shaft, not the scene: the solid thing the camera looks at
+ is still the nearest hit, at its real distance."""
+ assert shaft["nearest_hit_name"] == "Bench"
+ assert 2.0 < shaft["nearest_hit_m"] < 3.5
+
+
+def test_the_same_slab_WITH_depth_write_is_still_counted():
+ """The control: the rule is `depthWrite`, not the name or the opacity."""
+ solid_shaft = _run("true")
+ assert solid_shaft["inside_mesh_bbox"] == ["SunShaft_0"]
+ assert solid_shaft["camera_in_geometry"] is True