Official Codebase of 3DCodeVerse
Python
scene drivers: camera repair is observable — census row + per-view rider
gaoypeng0d5b2937af00
diff --git a/harness/runtime_js/lib/scene_host.mjs b/harness/runtime_js/lib/scene_host.mjsindex 1dc82580..1e94ca54 100644--- a/harness/runtime_js/lib/scene_host.mjs+++ b/harness/runtime_js/lib/scene_host.mjs@@ -411,7 +411,16 @@ function renderAt(spec, t) {state.scene.fog = savedFog;}const ms = Math.round(performance.now() - t0);- return { dataUrl: state.canvas.toDataURL('image/png'), ms, sim_time: state.simTime };+ // the camera actually used: differs from spec.position when camera repair fired+ return { dataUrl: state.canvas.toDataURL('image/png'), ms, sim_time: state.simTime,+ position: [cam.position.x, cam.position.y, cam.position.z] };+}++/** Repairs performed so far ({name, moved_back_m, moved_up_m, ...} per camera).+ * Repair fires lazily on the first build of each camera, so drivers read this+ * AFTER their render evaluations to stitch census.camera_repair (review-3 S5). */+function cameraRepairs() {+ return state.cameraRepairs.slice();}/**@@ -493,6 +502,7 @@ window.__c3v = {boot,renderAt,cameraChecks,+ cameraRepairs,compileAll,census,placement,diff --git a/harness/runtime_js/probe_scene.mjs b/harness/runtime_js/probe_scene.mjsindex f25db37b..957bfbfa 100644--- a/harness/runtime_js/probe_scene.mjs+++ b/harness/runtime_js/probe_scene.mjs@@ -100,6 +100,10 @@ async function main() {}const frame = await page.evaluate(() => { const c = window.__c3v.cameras()[0]; return window.__c3v.cameraChecks(c); });result.first_camera = frame;+ // the render/check exercises above may have repaired a camera AFTER the census+ // was captured: stitch it back so census.camera_repair is observable (review-3 S5)+ 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);}diff --git a/harness/runtime_js/render_scene.mjs b/harness/runtime_js/render_scene.mjsindex c0b07aba..9631d8b7 100644--- a/harness/runtime_js/render_scene.mjs+++ b/harness/runtime_js/render_scene.mjs@@ -110,7 +110,10 @@ async function main() {const r = await page.evaluate((spec, tt) => window.__c3v.renderAt(spec, tt), c, t);const file = `${c.name}_${tag(t)}.png`;dataUrlToPng(r.dataUrl, outFile(outDir, file));- metrics.views.push({ name: c.name, kind: c.kind, path: file, time_s: t, position: c.position, lookAt: c.lookAt, fov: c.fov, render_ms: r.ms });+ const view = { name: c.name, kind: c.kind, path: file, time_s: t, position: c.position, lookAt: c.lookAt, fov: c.fov, render_ms: r.ms };+ // position stays the AUTHORED camera; when repair moved the lens, record where the pixels really came from+ if (r.position && c.position && r.position.some((v, i) => Math.abs(v - c.position[i]) > 1e-6)) view.repaired_position = r.position;+ metrics.views.push(view);} catch (e) { sceneErr(`render failed for '${c.name}' at t=${t}`, e); }}}@@ -119,6 +122,12 @@ async function main() {try { metrics.fps = await page.evaluate((s) => window.__c3v.fps(s), fpsSec); }catch (e) { sceneErr('fps measurement failed', e); }}+ // repair fires lazily on each camera's first build, i.e. AFTER the census above+ // was captured: re-read it here so census.camera_repair is observable (review-3 S5)+ try {+ const reps = await page.evaluate(() => window.__c3v.cameraRepairs());+ if (reps.length && metrics.census) metrics.census.camera_repair = reps;+ } catch (e) { sceneErr('camera repair readback failed', e); }metrics.shader_errors = (await page.evaluate(() => window.__c3v.shaderErrors())).map(({ _key, ...e }) => e);metrics.update_errors = await page.evaluate(() => window.__c3v.updateErrors());Object.assign(metrics, errorSummary(host.errors, boot));diff --git a/harness/tests/scene_runtime/test_render_scene.py b/harness/tests/scene_runtime/test_render_scene.pyindex 266f2e40..90492399 100644--- a/harness/tests/scene_runtime/test_render_scene.py+++ b/harness/tests/scene_runtime/test_render_scene.py@@ -2,6 +2,7 @@from __future__ import annotations+import jsonfrom pathlib import Pathimport pytest@@ -97,6 +98,54 @@ def test_camera_in_geometry_is_detected(starter_ws, monkeypatch):m = read_metrics(out)chk = m["camera_checks"][0]assert chk["camera_in_geometry"] is True+ # repair off → everything renders from the AUTHORED camera and no repair is recorded+ assert "camera_repair" not in (m.get("census") or {})+ assert all("repaired_position" not in v for v in m["views"])+++@needs_browser+def test_camera_repair_is_observable_in_census_and_views(starter_ws, monkeypatch):+ """Review-3 S5 (V8): with the default-ON repair, a buried camera leaves a+ census.camera_repair row and the view records where the pixels really came+ from — repair used to fire AFTER census capture and vanish."""+ monkeypatch.delenv("CV3D_CAMERA_REPAIR", raising=False)+ cams = [CameraPlan(name="buried", position=(12.0, 2.0, -2.0), look_at=(12.0, 2.0, -10.0), fov=50)] # inside the windmill tower+ out = starter_ws.renders_dir(2)+ render_scene(starter_ws, out, cameras=cams, orbit=False, times=(0.0,), fps_seconds=0, sheet=False)+ m = read_metrics(out)+ reps = (m.get("census") or {}).get("camera_repair")+ assert reps and reps[0]["name"] == "buried" and reps[0]["moved_back_m"] + reps[0]["moved_up_m"] > 0+ view = next(v for v in m["views"] if v["name"] == "buried")+ assert view["position"] == [12.0, 2.0, -2.0] # authored camera stays the record+ assert view.get("repaired_position") and view["repaired_position"] != view["position"]+ assert m["camera_checks"][0]["camera_in_geometry"] is False # the effective camera is clear+++@needs_node+def test_camera_repair_telemetry_survives_the_python_reader(fake_runtime, ws, tmp_path):+ """The python side keeps metrics-only telemetry intact: census.camera_repair and+ per-view repaired_position stay readable, RenderView keeps the authored camera."""+ (fake_runtime / "render_scene.mjs").write_text(FAKE_DRIVER.replace(+ "const metrics = {",+ "for (const v of views) v.repaired_position = [1, 2.6, 4.1];\nconst metrics = {",+ ).replace(+ "census: { totals: { meshes: 1 } }",+ "census: { totals: { meshes: 1 }, camera_repair: [{ name: 'authored_a', moved_back_m: 1.1, moved_up_m: 0.6, inside_before: ['BarCounter'] }] }",+ ).replace(+ "fs.writeFileSync(path.join(out, 'metrics.json'), JSON.stringify(metrics));",+ "fs.writeFileSync(path.join(out, 'metrics.json'), JSON.stringify(metrics));\nfs.writeFileSync(path.join(out, 'views.json'), JSON.stringify(views));",+ ))+ out = tmp_path / "out"+ rs = render_scene(ws, out, cameras=[CameraPlan(name="cam_a", position=(1, 2, 3), look_at=(0, 0, 0), fov=45)],+ orbit=False, times=(0.0,), sheet=False)+ assert rs.views[0].camera_position == (1.0, 2.0, 3.0)+ m = read_metrics(out)+ assert m["census"]["camera_repair"][0]["name"] == "authored_a"+ assert m["views"][0]["repaired_position"] == [1, 2.6, 4.1]+ # the judge-flag rewrite of views.json must not strip the telemetry rider+ entries = json.loads((out / "views.json").read_text())+ assert entries[0]["repaired_position"] == [1, 2.6, 4.1] and "judge" in entries[0]@needs_node