Official Codebase of 3DCodeVerse
Python
scene: opt-in auto-exposure — one bounded scene-wide stop, like picking ISO
gaoypeng803c69ffdb2c
diff --git a/harness/codeverse/spatial/probes.py b/harness/codeverse/spatial/probes.pyindex 740565ed..4595f2e9 100644--- a/harness/codeverse/spatial/probes.py+++ b/harness/codeverse/spatial/probes.py@@ -74,6 +74,8 @@ def probe_scene(ws: Workspace, *, timeout_s: float = 60.0, write_census: bool =args.append("--no-settle")if os.environ.get("CV3D_CAMERA_REPAIR") == "1": # opt-in: repair plan cameras stuck in geometryargs.append("--camera-repair")+ if os.environ.get("CV3D_AUTO_EXPOSURE") == "1": # opt-in: bounded scene-wide exposure into the healthy band+ args.append("--auto-exposure")res = run_scene_script("probe_scene.mjs", args, timeout_s=timeout_s + 20)except SceneRenderError as e:findings.append(_f(gate, Severity.ERROR, f"scene probe could not run: {e}", target="src/scene.js",diff --git a/harness/codeverse/spatial/render_scene.py b/harness/codeverse/spatial/render_scene.pyindex d5a79e71..2046075e 100644--- a/harness/codeverse/spatial/render_scene.py+++ b/harness/codeverse/spatial/render_scene.py@@ -144,6 +144,8 @@ def render_scene(args.append("--no-settle")if os.environ.get("CV3D_CAMERA_REPAIR") == "1": # opt-in: repair plan cameras stuck in geometryargs.append("--camera-repair")+ if os.environ.get("CV3D_AUTO_EXPOSURE") == "1": # opt-in: bounded scene-wide exposure into the healthy band+ args.append("--auto-exposure")driver_error = ""try:res = run_scene_script("render_scene.mjs", args, timeout_s=tmo + 30)diff --git a/harness/runtime_js/lib/host_page.mjs b/harness/runtime_js/lib/host_page.mjsindex 51ab16cb..02caa02a 100644--- a/harness/runtime_js/lib/host_page.mjs+++ b/harness/runtime_js/lib/host_page.mjs@@ -55,7 +55,7 @@ export function requestFailureLine(url, base, hasResponse, errorText) {* Open the host for workspace `wsRoot`.* @returns {Promise<{page, browser, base, gpu, renderer, errors, boot, close}>}*/-export async function openHost(wsRoot, { width = 1024, height = 576, gpu = 'auto', logDepth = false, sceneRel = 'src/scene.js', createSceneTimeoutMs = 0, settle = true, cameraRepair = false } = {}) {+export async function openHost(wsRoot, { width = 1024, height = 576, gpu = 'auto', logDepth = false, sceneRel = 'src/scene.js', createSceneTimeoutMs = 0, settle = true, cameraRepair = false, autoExposure = false } = {}) {wsRoot = path.resolve(wsRoot);if (!fs.existsSync(path.join(wsRoot, sceneRel))) {throw new Error(`missing ${sceneRel} in workspace ${wsRoot}`);@@ -101,7 +101,7 @@ export async function openHost(wsRoot, { width = 1024, height = 576, gpu = 'autoawait page.waitForFunction('window.__c3v_ready === true', { timeout: 60000 });const boot = await page.evaluate((o) => window.__c3v.boot(o),- { sceneUrl: `/${sceneRel}`, width, height, logDepth, createSceneTimeoutMs, settle, cameraRepair },+ { sceneUrl: `/${sceneRel}`, width, height, logDepth, createSceneTimeoutMs, settle, cameraRepair, autoExposure },);const close = async () => {// page first, then release: a SHARED browser (connect-first reuse) must getdiff --git a/harness/runtime_js/lib/scene_host.mjs b/harness/runtime_js/lib/scene_host.mjsindex b575fe11..1dc82580 100644--- a/harness/runtime_js/lib/scene_host.mjs+++ b/harness/runtime_js/lib/scene_host.mjs@@ -50,6 +50,8 @@ const state = {cameraRepair: false,cameraRepairs: [],repairedSpecs: new Map(),+ autoExposure: false,+ autoExposureInfo: null,};/**@@ -175,6 +177,8 @@ async function boot(opts) {state.cameraRepair = !!opts.cameraRepair;state.cameraRepairs = [];state.repairedSpecs = new Map();+ state.autoExposure = !!opts.autoExposure;+ state.autoExposureInfo = null;state.width = opts.width || 1024;state.height = opts.height || 576;window.requestAnimationFrame = () => { state.rafCalls += 1; return 0; };@@ -246,6 +250,33 @@ async function boot(opts) {}info.settled = state.settleInfo.count;}++ // auto-exposure (opt-in, --auto-exposure): one scene-wide bounded exposure, like a+ // photographer picking ISO once. fv_izakaya_night sat at mean_lum 0.07 for three+ // rounds with the 'frame too dark' ERROR in every refine prompt and nobody fixed it;+ // the frame gate's healthy band is 0.12..0.35. Factor clamped to [0.5, 3.0] so a+ // deliberately moody scene is brightened, never rewritten; recorded in the census.+ if (opts.autoExposure && state.cameras.length) {+ info.stage = 'auto_exposure';+ try {+ const probeCam = () => buildCameraRaw(state.cameras[0]);+ const lum = () => { renderOnce(probeCam()); return frameStats(state.canvas).mean_lum; };+ const before = lum();+ let factor = 1;+ let after = before;+ for (let i = 0; i < 4 && (after < 0.10 || after > 0.45); i++) {+ const step = after < 0.10 ? 1.6 : 0.7;+ const next = Math.min(3.0, Math.max(0.5, factor * step));+ if (next === factor) break;+ factor = next;+ state.renderer.toneMappingExposure = factor;+ after = lum();+ }+ if (factor !== 1) state.autoExposureInfo = { factor: +factor.toFixed(2), lum_before: before, lum_after: after };+ } catch (e) {+ state.hostWarnings.push(`auto-exposure failed: ${String((e && e.message) || e).slice(0, 200)}`);+ }+ }state.booted = true;info.ok = cameras.length > 0;info.stage = 'ready';@@ -450,6 +481,7 @@ function census() {c.glb_assets = glbUsage(state.scene);if (state.settleInfo) c.settle = state.settleInfo;if (state.cameraRepairs.length) c.camera_repair = state.cameraRepairs.slice();+ if (state.autoExposureInfo) c.auto_exposure = state.autoExposureInfo;state.contentBox = c.content_bbox;state.fullBox = c.bbox;c.cameras = state.cameras.length;diff --git a/harness/runtime_js/probe_scene.mjs b/harness/runtime_js/probe_scene.mjsindex 036fef52..2fc77f43 100644--- a/harness/runtime_js/probe_scene.mjs+++ b/harness/runtime_js/probe_scene.mjs@@ -58,6 +58,7 @@ async function main() {createSceneTimeoutMs: createTimeoutMs(args['create-timeout-ms'], timeoutMs),settle: !args['no-settle'],cameraRepair: !!args['camera-repair'],+ autoExposure: !!args['auto-exposure'],});} catch (e) {return fail(`host failed: ${e.message}`);diff --git a/harness/runtime_js/render_scene.mjs b/harness/runtime_js/render_scene.mjsindex 4511ca13..03312fae 100644--- a/harness/runtime_js/render_scene.mjs+++ b/harness/runtime_js/render_scene.mjs@@ -55,6 +55,7 @@ async function main() {createSceneTimeoutMs: createTimeoutMs(args['create-timeout-ms'], timeoutMs),settle: !args['no-settle'],cameraRepair: !!args['camera-repair'],+ autoExposure: !!args['auto-exposure'],});} catch (e) {return fail(`host failed: ${e.message}`);