Skip to content

3D engine that AI agents drive

Commit the Lone Monk and Barbershop default cameras (#2158)

Nguyen Xuan An4b82cf6a629c
diff --git a/bench/scene-frames/camera-overrides.json b/bench/scene-frames/camera-overrides.json
new file mode 100644
index 00000000..69a53a76
--- /dev/null
+++ b/bench/scene-frames/camera-overrides.json
@@ -0,0 +1,4 @@
+{
+ "monk": { "eye": [14, 1.6, -14], "target": [20, 1.8, -19.5] },
+ "barbershop": { "eye": [1.2, 1.6, -9.2], "target": [3.0, 1.0, -4.5] }
+}
diff --git a/bench/scene-frames/camera-overrides.mjs b/bench/scene-frames/camera-overrides.mjs
new file mode 100644
index 00000000..670c3538
--- /dev/null
+++ b/bench/scene-frames/camera-overrides.mjs
@@ -0,0 +1,36 @@
+// Committed default cameras for the benchmark scenes that are generated locally from Blender demo files
+// (scripts/blender-demo-to-glb.py), whose own camera renders a flat frame (#2158). camera-overrides.json maps a scene name
+// to the eye and target that show the scene; the sweep applies it to scene.json before it renders.
+import { existsSync, readFileSync, writeFileSync } from 'node:fs';
+import { basename } from 'node:path';
+
+const OVERRIDES_URL = new URL('./camera-overrides.json', import.meta.url);
+
+export function loadCameraOverrides(overridesUrl = OVERRIDES_URL) {
+ return JSON.parse(readFileSync(overridesUrl, 'utf8'));
+}
+
+function assertPoint(sceneName, field, point) {
+ const valid = Array.isArray(point) && point.length === 3 && point.every(Number.isFinite);
+ if (!valid) throw new Error(`Camera override "${sceneName}" needs ${field} as three finite numbers [x, y, z], got ${JSON.stringify(point)}.`);
+}
+
+// Returns the scene description with the override's eye and target, or the same description when the scene has no override.
+export function applyCameraOverride(sceneName, description, overrides) {
+ const override = overrides[sceneName];
+ if (override === undefined) return description;
+ assertPoint(sceneName, 'eye', override.eye);
+ assertPoint(sceneName, 'target', override.target);
+ return { ...description, eye: [...override.eye], target: [...override.target] };
+}
+
+// Rewrites <directory>/scene.json in place and returns true when the override changed it.
+export function applyCameraOverrideToDirectory(directory, overrides = loadCameraOverrides()) {
+ const scenePath = `${directory}/scene.json`;
+ if (!existsSync(scenePath)) throw new Error(`No scene.json in ${directory}. Pass a scene directory generated by scripts/blender-demo-to-glb.py.`);
+ const description = JSON.parse(readFileSync(scenePath, 'utf8'));
+ const updated = applyCameraOverride(description.id ?? basename(directory), description, overrides);
+ if (updated === description) return false;
+ writeFileSync(scenePath, `${JSON.stringify(updated, null, 2)}\n`);
+ return true;
+}
diff --git a/bench/scene-frames/check-default-cameras.mjs b/bench/scene-frames/check-default-cameras.mjs
index 96cb147d..be53a417 100644
--- a/bench/scene-frames/check-default-cameras.mjs
+++ b/bench/scene-frames/check-default-cameras.mjs
@@ -1,5 +1,6 @@
// Renders each scene file's own camera small and fails when a frame is nearly one colour:
// node bench/scene-frames/check-default-cameras.mjs <scene-directory>[,<scene-directory>...] [--width 320] [--height 180]
+// A committed override in camera-overrides.json replaces the eye and target of scenes whose exported camera is flat (#2158).
// A scene directory holds scene.json, scene.glb and sky.hdr (see bench/glaze-passes/run.mjs). Exit code 1 lists the flat scenes.
import { spawnSync } from 'node:child_process';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
@@ -7,11 +8,13 @@ import { tmpdir } from 'node:os';
import { basename, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { decodePng } from '../agent-modeling/png-check.mjs';
+import { applyCameraOverrideToDirectory } from './camera-overrides.mjs';
import { MINIMUM_MEAN_LUMINANCE_STEP, meanLuminanceStep } from './uniform-frame.mjs';
const RENDER_MEDIA = fileURLToPath(new URL('../../scripts/render-media.mjs', import.meta.url));
function renderDefaultCamera(directory, width, height) {
+ applyCameraOverrideToDirectory(directory);
const work = mkdtempSync(join(tmpdir(), 'scene-frame-'));
try {
const output = join(work, 'frame.png');
diff --git a/docs/culling-lod.md b/docs/culling-lod.md
index 8f2015a9..4b46b96f 100644
--- a/docs/culling-lod.md
+++ b/docs/culling-lod.md
@@ -62,4 +62,4 @@ A scan with about one triangle per pixel or more is shaded once per sample at ne
A scene file (`scene.json`, rendered by `scripts/render-media.mjs --scene file`) gets the same levels by default; `"renderer": { "denseLods": false }` keeps every triangle of a dense scan. With the option on, `partsForRendererOptions` in `src/dense-lods.js` calls `addLodsToDenseParts` at the canvas size and pixel ratio before the renderer is built (#1163).
-`npm run bench:scene-frames -- <scene directory> [<scene directory>...]` renders each scene file's own camera at 320 by 180 and exits 1 when the frame is nearly one colour (mean luminance step between neighbouring pixels under 1 of 255). A camera behind a wall gave Lone Monk a white frame that no timing or RMSE could use (0.32 flat; the other benchmark scenes measure 2.4 to 7.8), and the same check flags the Barbershop scene (#2158). The detector is `bench/scene-frames/uniform-frame.mjs`.
+`npm run bench:scene-frames -- <scene directory> [<scene directory>...]` renders each scene file's own camera at 320 by 180 and exits 1 when the frame is nearly one colour (mean luminance step between neighbouring pixels under 1 of 255). A camera behind a wall gave Lone Monk a white frame that no timing or RMSE could use (0.32 flat; the other benchmark scenes measure 2.4 to 7.8), and the same check flags the Barbershop scene (#2158). The detector is `bench/scene-frames/uniform-frame.mjs`. The scene directories are generated locally and are not in git, so the cameras that fix both scenes are committed in `bench/scene-frames/camera-overrides.json` (scene name to `eye` and `target`); the sweep writes them into each directory's `scene.json` before it renders.
diff --git a/scripts/blender-demo-to-glb.py b/scripts/blender-demo-to-glb.py
index 244556c4..63016251 100644
--- a/scripts/blender-demo-to-glb.py
+++ b/scripts/blender-demo-to-glb.py
@@ -11,6 +11,9 @@ Then render the GLB with a scene.json (glb, hdri, eye [2.5764, 1.0945, 4.4658],
node scripts/render-media.mjs --kind image --scene file --config <outputDirectory>/scene.json --width 1600 --height 900 --output hero.png
+The Lone Monk and Barbershop exports have flat Blender cameras; their eye and target are committed in bench/scene-frames/camera-overrides.json
+and written into scene.json by `npm run bench:scene-frames -- <outputDirectory>` (#2158).
+
Old demo scenes shade with Cycles-only Diffuse, Glossy and Glass nodes, which the glTF exporter skips. This script puts a
Principled BSDF in their place first (base colour or the first image texture upstream of the Diffuse colour, roughness, metal for
a lone Glossy, a soft alpha for Glass), so colours and textures survive. It is an approximation, not a Cycles match.
diff --git a/scripts/render-media.mjs b/scripts/render-media.mjs
index 33c6ce0c..0a4f7d83 100644
--- a/scripts/render-media.mjs
+++ b/scripts/render-media.mjs
@@ -51,6 +51,8 @@ export function renderEncoderOptions({ ffmpeg, output, fps, captureFormat, width
}
const AUDIO_LENGTH_TOLERANCE_SECONDS = 0.05;
+// A large file scene such as the Barbershop benchmark takes about a minute to load when other jobs share the machine (#2158).
+const SCENE_READY_TIMEOUT_MILLISECONDS = 240000;
/** Decodes the audio stream of a finished file and throws when there is none or, given the picture length, when its length is off. */
export async function assertOutputHasAudio(ffmpeg, output, expectedSeconds) {
@@ -222,7 +224,7 @@ export async function renderMedia(values = process.argv.slice(2)) {
});
}
await page.goto(`http://127.0.0.1:${serverPort}/${route}?${query}`);
- await page.waitForFunction((mode) => window.__fileSceneError || window.__scene?.renderer || (mode === 'film' ? window.__filmReady : mode === 'nature' ? window.__nature?.renderer : mode === 'object' ? window.__studio?.renderer : false), scene, { timeout: 60000 });
+ await page.waitForFunction((mode) => window.__fileSceneError || window.__scene?.renderer || (mode === 'film' ? window.__filmReady : mode === 'nature' ? window.__nature?.renderer : mode === 'object' ? window.__studio?.renderer : false), scene, { timeout: SCENE_READY_TIMEOUT_MILLISECONDS });
const fileSceneError = await page.evaluate(() => window.__fileSceneError);
if (fileSceneError) throw new Error(`Scene file failed to load: ${fileSceneError}`);
if (options.asset) {
diff --git a/tests/camera-overrides.test.js b/tests/camera-overrides.test.js
new file mode 100644
index 00000000..93034a92
--- /dev/null
+++ b/tests/camera-overrides.test.js
@@ -0,0 +1,49 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { applyCameraOverride, applyCameraOverrideToDirectory, loadCameraOverrides } from '../bench/scene-frames/camera-overrides.mjs';
+
+const FLAT_CAMERA = { id: 'monk', glb: 'scene.glb', eye: [0, 1, 0], target: [0, 1, 1], frame: { fov: 50 } };
+
+test('the committed overrides give Lone Monk the courtyard camera and Barbershop a camera of its own', () => {
+ const overrides = loadCameraOverrides();
+ assert.deepEqual(overrides.monk.eye, [14, 1.6, -14]);
+ assert.deepEqual(overrides.monk.target, [20, 1.8, -19.5]);
+ assert.equal(overrides.barbershop.eye.length, 3);
+ assert.equal(overrides.barbershop.target.length, 3);
+});
+
+test('an override replaces eye and target and keeps every other field', () => {
+ const updated = applyCameraOverride('monk', FLAT_CAMERA, { monk: { eye: [14, 1.6, -14], target: [20, 1.8, -19.5] } });
+ assert.deepEqual(updated.eye, [14, 1.6, -14]);
+ assert.deepEqual(updated.target, [20, 1.8, -19.5]);
+ assert.equal(updated.glb, 'scene.glb');
+ assert.deepEqual(updated.frame, { fov: 50 });
+});
+
+test('a scene with no override is returned as it is', () => {
+ assert.equal(applyCameraOverride('classroom', FLAT_CAMERA, { monk: { eye: [1, 1, 1], target: [2, 2, 2] } }), FLAT_CAMERA);
+});
+
+test('a malformed override throws an error that names the scene and the field', () => {
+ assert.throws(() => applyCameraOverride('monk', FLAT_CAMERA, { monk: { eye: [1, 2], target: [0, 0, 0] } }), /"monk" needs eye as three finite numbers/);
+});
+
+test('a generated scene directory gets the committed camera written into scene.json', () => {
+ const directory = mkdtempSync(join(tmpdir(), 'camera-override-'));
+ try {
+ writeFileSync(join(directory, 'scene.json'), JSON.stringify(FLAT_CAMERA));
+ assert.equal(applyCameraOverrideToDirectory(directory, loadCameraOverrides()), true);
+ const written = JSON.parse(readFileSync(join(directory, 'scene.json'), 'utf8'));
+ assert.deepEqual(written.eye, loadCameraOverrides().monk.eye);
+ assert.equal(applyCameraOverrideToDirectory(directory, {}), false);
+ } finally {
+ rmSync(directory, { recursive: true, force: true });
+ }
+});
+
+test('a directory without scene.json says what to pass instead', () => {
+ assert.throws(() => applyCameraOverrideToDirectory(join(tmpdir(), 'no-such-scene-directory'), {}), /generated by scripts\/blender-demo-to-glb\.py/);
+});