Skip to content

Official Codebase of 3DCodeVerse

Python

scene: the assembler's fitted cameras stand on the side sunRig lights, framed inside the plan bounds

gaoypeng68343c27935e
diff --git a/harness/codeverse3d/languages/scene_threejs/__init__.py b/harness/codeverse3d/languages/scene_threejs/__init__.py
index abfc606d..832dfc20 100644
--- a/harness/codeverse3d/languages/scene_threejs/__init__.py
+++ b/harness/codeverse3d/languages/scene_threejs/__init__.py
@@ -510,12 +510,15 @@ def probe_zone_modules(ws: Workspace, *, timeout_s: float = 90.0, sun_azimuth_de
zones = zone_files(ws)
probe_path = ws.root / PROBE_REL
probe_path.write_text(_probe_module(zones, glb_assets(ws)))
- from codeverse3d.spatial.render_scene import probe_env_args
+ from codeverse3d.spatial.render_scene import _bounds_json, plan_bounds, probe_env_args
args = ["--ws", str(ws.root), "--scene", PROBE_REL, "--timeout-ms", str(int(timeout_s * 1000))]
args += probe_env_args() # the zone probe sees the same settle/repair/exposure world as the renders
if sun_azimuth_deg is not None:
args += ["--sun-azimuth", str(sun_azimuth_deg)]
+ # the overview is framed like the render rig's: inside the plan's bounds
+ if (bounds := plan_bounds(ws)) is not None:
+ args += ["--bounds", _bounds_json(bounds)]
try:
res = run_scene_script("probe_scene.mjs", args, timeout_s=timeout_s + 20)
finally:
diff --git a/harness/runtime_js/probe_scene.mjs b/harness/runtime_js/probe_scene.mjs
index a253bca7..f3e98e13 100644
--- a/harness/runtime_js/probe_scene.mjs
+++ b/harness/runtime_js/probe_scene.mjs
@@ -6,7 +6,7 @@
* console/page/shader errors. No screenshots.
*
* node probe_scene.mjs --ws <ws> [--scene src/scene.js] [--gpu auto] [--timeout-ms 60000] [--out probe.json]
- * [--compile] [--shaders-out report.json] [--sun-azimuth 60]
+ * [--compile] [--shaders-out report.json] [--sun-azimuth 60] [--bounds '{"min":[..],"max":[..]}'|none]
*
* `--compile` additionally runs the full shader preflight (static GLSL audits +
* force-compile of every material, lib/shader_report.mjs) on the SAME booted
@@ -17,12 +17,15 @@
* the single owner of camera-fit math) from the measured census: an overview
* of the content bounds plus one eye-level camera per top-level group, all
* standing on the sun side — `fitted_cameras: {azimuth, overview, zones}`.
+ * The azimuth is `sunRig`'s (x-first: 0 = +X, 90 = +Z), converted here to orbit.mjs's
+ * z-first angle; `--bounds` (the plan's) guards the overview framing exactly as
+ * render_scene.mjs does, so a 400 m instanced meadow cannot shrink the content to a speck.
* The scene assembler (assemble.py) converts these into its CameraPlans.
* Last stdout line = JSON {ok, boot, census, console_errors, shader_errors, ...}.
*/
import path from 'node:path';
-import { armWatchdog, fail, finish, parseCli, writeJson } from './lib/cli.mjs';
+import { armWatchdog, fail, finish, parseCli, readJsonArg, writeJson } from './lib/cli.mjs';
import { createTimeoutMs, errorSummary, openHost } from './lib/host_page.mjs';
import { fitOverviewCamera, fitZoneCamera, framingBox } from './lib/orbit.mjs';
import { compileIntoReport, staticShaderReport } from './lib/shader_report.mjs';
@@ -38,17 +41,22 @@ const args = parseCli({
ws: {}, out: {}, gpu: { default: process.env.C3D_RENDER_GPU || 'auto' }, 'timeout-ms': { default: '60000' },
scene: { default: 'src/scene.js' },
compile: { type: 'boolean', default: false }, 'shaders-out': { default: '' }, 'sun-azimuth': { default: '' },
+ bounds: { default: 'none' },
});
-/** Harness-fitted camera specs from the census: overview + one per group. */
-function fitCameras(census, azimuth) {
+/** Harness-fitted camera specs from the census: overview + one per group, on the side
+ * `sunRig({azimuth})` lights. sunRig's sun is x-first — (cos A, ·, sin A) — and
+ * orbitDirection z-first — (sin B, ·, cos B) — so the same side is B = 90 − A (they agree
+ * only at 45°; at 135° the "sun-side" camera stood exactly opposite the sun). */
+function fitCameras(census, azimuth, bounds) {
const groundY = census.ground_y;
- const box = framingBox(census, null);
- const overview = box ? fitOverviewCamera(box, { azimuth, elevation: 30, groundY }) : null;
+ const orbitAz = 90 - azimuth;
+ const box = framingBox(census, bounds);
+ const overview = box ? fitOverviewCamera(box, { azimuth: orbitAz, elevation: 30, groundY }) : null;
const zones = [];
for (const g of census.groups || []) {
if (!g.bbox || g.kind === 'sky' || g.kind === 'empty' || g.kind === 'light') continue;
- zones.push({ group: g.name, ...fitZoneCamera(g.bbox, { azimuth, floor: groundY }) });
+ zones.push({ group: g.name, ...fitZoneCamera(g.bbox, { azimuth: orbitAz, floor: groundY }) });
}
return { azimuth, overview, zones };
}
@@ -109,7 +117,8 @@ async function main() {
const reps = await page.evaluate(() => window.__c3v.cameraRepairs());
if (reps.length) result.census.camera_repair = reps;
const sunAz = parseFloat(args['sun-azimuth']);
- if (Number.isFinite(sunAz)) result.fitted_cameras = fitCameras(result.census, sunAz);
+ const bounds = args.bounds !== 'none' ? readJsonArg(args.bounds, 'bounds') : null;
+ if (Number.isFinite(sunAz)) result.fitted_cameras = fitCameras(result.census, sunAz, bounds);
}
// Probe truth is snapshotted BEFORE any forced compile: the probe gate sees
// exactly what a standalone probe would; the preflight below sees everything.
diff --git a/harness/tests/scene_runtime/test_assemble.py b/harness/tests/scene_runtime/test_assemble.py
index b8fcbce3..a8b90292 100644
--- a/harness/tests/scene_runtime/test_assemble.py
+++ b/harness/tests/scene_runtime/test_assemble.py
@@ -124,3 +124,40 @@ def test_assemble_probes_each_zone_excludes_the_broken_and_boots(starter_ws):
probe = probe_scene(starter_ws)
assert probe.gate.passed, [(f.target, f.message) for f in probe.gate.findings]
assert "Orchard" in {g["name"] for g in probe.census.get("groups", [])}
+
+
+@needs_browser
+def test_fitted_overview_faces_the_lit_side_inside_the_plan_bounds(tmp_ws):
+ """Regressions (audit 2026-09-24 N8, N9): the assembler's fitted cameras stand on the side
+ `sunRig({azimuth})` lights — at 135° they stood exactly opposite the sun — and the overview
+ is framed inside the plan bounds like the render rig's, not around a 400 m meadow (549 m out)."""
+ import json
+
+ from codeverse3d.languages.scene_threejs import probe_zone_modules
+
+ (tmp_ws.src / "env.js").write_text("export const SUN_AZIMUTH_DEG = 135;\nexport function buildEnv() { return {}; }\n")
+ zones = tmp_ws.src / "zones"
+ zones.mkdir()
+ (zones / "cottage.js").write_text(
+ "import * as THREE from 'three';\n"
+ "export function build() {\n"
+ " const m = new THREE.Mesh(new THREE.BoxGeometry(16, 7, 12), new THREE.MeshStandardMaterial());\n"
+ " m.position.y = 3.5; m.name = 'Cottage'; const g = new THREE.Group(); g.add(m); return g;\n"
+ "}\n")
+ (zones / "meadow.js").write_text( # an instanced scatter 400 m wide
+ "import * as THREE from 'three';\n"
+ "export function build() {\n"
+ " const im = new THREE.InstancedMesh(new THREE.BoxGeometry(0.3, 1.2, 0.3), new THREE.MeshStandardMaterial(), 64);\n"
+ " const m = new THREE.Matrix4();\n"
+ " for (let i = 0; i < 64; i++) im.setMatrixAt(i, m.makeTranslation(-200 + (i % 8) * 400 / 7, 0.6, -200 + Math.floor(i / 8) * 400 / 7));\n"
+ " im.name = 'Grass'; const g = new THREE.Group(); g.add(im); return g;\n"
+ "}\n")
+ tmp_ws.plan_path.write_text(json.dumps({"bounds": {"center": [0, 7.5, 0], "extents": [60, 15, 60]}}))
+ report = probe_zone_modules(tmp_ws, sun_azimuth_deg=sun_azimuth(tmp_ws))
+ ov = report.camera_specs["overview"]
+ view = [p - q for p, q in zip(ov["position"], ov["lookAt"], strict=True)]
+ sun = (math.cos(math.radians(135)), math.sin(math.radians(135))) # sunRig's (x, z)
+ cos = (view[0] * sun[0] + view[2] * sun[1]) / math.hypot(view[0], view[2])
+ assert cos > 0.99, (ov, cos)
+ assert math.dist(ov["position"], ov["lookAt"]) < 100, ov