3D engine that AI agents drive
Make recipe bake presets fit large rooms and make fine an alias of standard
Nguyen Xuan An9f75c77dbc24
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 76069729..a69184bd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,7 @@## Unreleased+- Make the recipe bake presets bake large rooms (issue #189). A preset that does not fit the 5 million path step budget at 16 samples and 1 texel per unit now gives up bounces one at a time instead of refusing, and `bake.reduction` tells the agent what it asked for, what ran and that explicit samples, bounces and texelsPerUnit (up to 24 million path steps, 20 s inline) buy more. `temple-hall` at `standard` now bakes (16 samples, 1 bounce, 1.37 texels per unit, 0.0705 against 0.1504 unbaked with a probe). `fine` is now the same as `standard`: five samples and density mixes within the 20 s limit scored no better on the room scenes. Table in `bench/reference/README.md`.- Score the recipe bake presets against Cycles (part of issue #170, open for the frame costs). `standard` scores 0.127 to 0.159 on the three rooms (no bake 0.51), `fine` is no better, and `standard` and `fine` refuse `temple-hall`. Table in `bench/reference/README.md`.- No test asserts real elapsed time any more (issue #179): work counts and a fake clock replace stopwatches. `smoke:agent-review-close` and `smoke:film-physics` are wired; the second starts its own server.- Make every test file pass on its own, and check it in CI (issue #172). `node --test tests/agent-bake.test.js` failed 16 of 19 because `npm test` preloaded every on-demand module into each test process, so 28 files only passed through that preload. The loading path agents use was fine (`tests/agent-scene-on-demand.test.js` runs it in clean processes). Each of those files now imports `tests/support/load-agent-scene-modules.mjs` itself, `npm test` no longer preloads, and `npm run test:isolated` (`scripts/test-each-file.mjs`) runs each file in its own process, 4 at a time at below-normal priority, rerunning a failure alone once so a busy machine does not count. It runs in the `Test` workflow.diff --git a/bench/reference/README.md b/bench/reference/README.mdindex 4624a51b..969f454a 100644--- a/bench/reference/README.md+++ b/bench/reference/README.md@@ -319,23 +319,40 @@ Denoising a lower sample count (fixed 24 samples with the tracer's filter, thresDarker floor in `character` and `outdoor-hdri`: not found, but narrowed. In `outdoor-hdri` the mean display value of the bottom third (the floor) is 225.5 in Cycles, 225.4 in EEVEE, 224.8 in the rasterizer and 217.1 in the tracer, so the rasterizer agrees with Cycles and the tracer alone is darker, by 8.4 of 255 (the scene is bright, so the display curve compresses it; the linear gap is larger). A white furnace test (a diffuse floor of albedo 0.4 under a sky of radiance 1) gives 0.3955 straight down (1 percent low) and 0.588 at a grazing view with the sky reflection, so sampling the environment and the diffuse lobe is not what loses the light. What is left: the sun together with the HDRI, the clamp of 20 on bounced light (`fireflyClamp`), the grazing-angle specular and light from the other parts, none of which was isolated.-## Recipe bake presets (2026-11-02, part of issue #170)+## Recipe bake presets (2026-11-02, issues #170 and #189)-An agent names a preset (`bake: { preset }`), and `standard` and `fine` shrink to the path work budget of 5 million steps (`bake.used`, `bake.reduced`). `npm run reference -- --skip-blender --bake <ids> --bake-preset <name> --probes <ids>` bakes the way a recipe does (`normalizeAgentBake` and `bakeAgentParts`, the scene's own `bakeOptions` ignored) and scores against the Cycles renders already in `artifacts/reference`. The preset rows below carry the room probe a recipe adds with a bake; the no-bake row has none. A preset the budget refuses (the error a recipe gets) draws the scene unbaked and prints `REFUSED`. Whole frame FLIP against Cycles, RTX 3060 shared with other jobs, one run per cell, bake seconds from the harness (not an idle machine):+An agent names a preset (`bake: { preset }`). A preset shrinks to the path work budget of 5 million steps (texels x samples x bounces): samples by a fifth and texel density by a tenth, repeatedly, down to 16 samples and 1 texel per unit. A scene that still does not fit there gives up one bounce and starts again from the preset's samples and density, down to 1 bounce. A preset therefore bakes any scene the explicit limit allows, and the result says what changed: `bake.used` holds the settings that ran, `bake.reduced` is `true`, and `bake.reduction` names what the preset asked for, what ran, and that explicit samples, bounces and texelsPerUnit (up to 24 million path steps, 20 s inline) bake denser.-| Scene | No bake | draft | standard | fine |-| --- | --- | --- | --- | --- |-| `lit-interior` | 0.5055 | 0.2919, 0.5 s, 8,000 texels | 0.1270, 3.4 s, 19,360 texels | 0.1293, 3.3 s, 16,800 texels |-| `brick-room` | 0.5102 | 0.3185, 1.4 s, 37,136 texels | 0.1353, 1.8 s, 42,576 texels | 0.1382, 1.8 s, 37,136 texels |-| `metal-room` | 0.5128 | 0.3187, 0.8 s, 8,816 texels | 0.1594, 3.2 s, 15,936 texels | 0.1624, 4.6 s, 18,336 texels |-| `dark-shaft` | 0.1430 | 0.0791, 0.9 s, 28,208 texels | 0.0610, 2.3 s, 40,336 texels | 0.0603, 2.2 s, 35,664 texels |-| `temple-hall` | 0.1436 | 0.0706, 5.7 s, 285,376 texels | refused (0.1504 drawn unbaked with a probe) | refused (same) |+`npm run reference -- --skip-blender --bake <ids> --bake-preset <name> --probes <ids>` bakes the way a recipe does (`normalizeAgentBake` and `bakeAgentParts`, the scene's own `bakeOptions` ignored) and scores against the Cycles renders already in `artifacts/reference`. The preset rows carry the room probe a recipe adds with a bake; the no-bake row has none. Whole frame FLIP against Cycles, RTX 3060 shared with other jobs, one run per cell, bake seconds from the harness (not an idle machine):++| Scene | No bake | draft | standard (`fine` is the same) |+| --- | --- | --- | --- |+| `lit-interior` | 0.5055 | 0.2919, 0.5 s, 8,000 texels | 0.1270, 3.8 s, 19,360 texels (81 samples, 3 bounces, 4.86 texels per unit) |+| `brick-room` | 0.5102 | 0.3185, 1.4 s, 37,136 texels | 0.1353, 1.8 s, 42,576 texels (32 samples, 3 bounces, 3.19 texels per unit) |+| `metal-room` | 0.5128 | 0.3187, 0.8 s, 8,816 texels | 0.1594, 3.3 s, 15,936 texels (64 samples, 3 bounces, 4.37 texels per unit) |+| `dark-shaft` | 0.1430 | 0.0791, 0.9 s, 28,208 texels | 0.0610, 2.3 s, 40,336 texels |+| `temple-hall` | 0.1436 | 0.0706, 5.7 s, 285,376 texels | 0.0705, 5.7 s, 304,480 texels (16 samples, 1 bounce, 1.37 texels per unit) |++Before issue #189 `standard` and `fine` refused `temple-hall` (even 16 samples at 1 texel per unit and 3 bounces pass the budget), so a recipe got an unbaked hall at 0.1504 with a probe. Now `standard` bakes it, with one bounce, which is what `draft` does: the score matches `draft` (0.0705 against 0.0706). The scene's own tuned options score 0.0560, and reaching them takes explicit settings.What the table shows:-- `standard` is the preset to name for a room: it halves the error of `draft` on `lit-interior`, `brick-room` and `metal-room` (3 bounces against 1) and beats the default bake of "Baked rooms and the bounce count" (0.1341, 0.1412, 0.1656) on all three, for 2 to 3.5 s.-- `fine` is no better than `standard`. Its extra samples and density are cut back to the same budget (38 to 77 samples, 3.0 to 4.6 texels per unit), so it ends up within 0.003 of `standard`, slightly worse on three of five rooms, and costs the same or a little more. A recipe gains nothing by asking for it on these scenes.-- `temple-hall` (167 parts, 3 bounces) is out of reach of `standard` and `fine`: even 16 samples at 1 texel per unit pass 5 million steps, so a recipe gets the error and no bake. `draft` works (reduced to 16 samples and 1.29 texels per unit) and scores 0.0706, against 0.0560 for the scene's own tuned options. Reaching `standard` on a hall needs explicit settings within the 24 million explicit limit, or a lower budget floor; this is left open.+- `standard` halves the error of `draft` on `lit-interior`, `brick-room` and `metal-room` (3 bounces against 1) and beats the default bake of "Baked rooms and the bounce count" (0.1341, 0.1412, 0.1656) on all three, for 2 to 4 s.+- `fine` could not be made better than `standard` inside the budget, so it is an alias with the same numbers. The old `fine` (192 samples, 7 texels per unit) was cut to the same budget, so it ended within 0.003 of `standard` and slightly worse on three of five rooms (0.1293, 0.1382, 0.1624, 0.0603). Five other mixes of samples and density were scored, each asked for through `fine` and shrunk to the budget the same way:++| Asked (samples, bounces, texels per unit) | `lit-interior` | `brick-room` | `metal-room` | `dark-shaft` | `temple-hall` |+| --- | --- | --- | --- | --- | --- |+| 128, 3, 6 (`standard`) | 0.1270 | 0.1353 | 0.1594 | 0.0610 | 0.0705 |+| 192, 3, 7 (old `fine`) | 0.1293 | 0.1382 | 0.1624 | 0.0603 | not baked |+| 256, 3, 3 | 0.1363 | 0.1655 | 0.1636 | 0.0620 | 0.0718 |+| 256, 3, 4 | 0.1401 | 0.1516 | 0.1677 | 0.0606 | 0.0699 |+| 256, 3, 5 | 0.1442 | 0.1497 | 0.1746 | 0.0637 | 0.0703 |+| 64, 3, 12 | 0.1320 | 0.1436 | 0.1667 | 0.0660 | 0.0700 |+| 48, 3, 8 | 0.1208 | 0.1533 | 0.1643 | 0.0647 | 0.0700 |+| 32, 3, 12 | 0.1274 | 0.1445 | 0.1712 | 0.0660 | 0.0700 |++ More samples on fewer texels (256 samples at 3 to 5 texels per unit) lost on every room except `dark-shaft`, and more texels on fewer samples (32 to 64 samples at 8 to 12) lost on all but `lit-interior`, where `48, 3, 8` won by 0.006 and lost 0.018 to 0.004 on the other three. The `standard` mix of about 30 to 80 samples at 3 to 5 texels per unit after shrinking is the best or within 0.005 of the best on four of five rooms (not `lit-interior`), and the differences between mixes are small next to the gap to Cycles from missing indirect specular. A smoothing radius was not tried: `SMOOTH_RADIUS_TEXELS` is a constant in `src/light-bake.js` and the recipe has no field for it. Each cell is one run, so differences under about 0.005 are not separable from noise.+- The 20 s inline limit and the budget agree on large rooms: `temple-hall`, the largest scene (167 parts, 304,480 texels), bakes in 5.7 s at the budget, and the slowest cell above is 6.0 s, so the budget leaves room under the limit on this machine.- `draft` is a rough preset: one bounce leaves the lit rooms at 0.29 to 0.32, still well under the unbaked 0.51.Frame costs from the issue (a baked closed room, and the fog glow mip chain on `dark-shaft`) were not measured: `nvidia-smi` showed 14 to 48 percent utilization and 6 to 7 GB in use over 24 seconds while another worker held the GPU, so a number would be a loaded one. The ranges above in this file stay ranges.diff --git a/bench/reference/run.mjs b/bench/reference/run.mjsindex f8bec566..c9231889 100644--- a/bench/reference/run.mjs+++ b/bench/reference/run.mjs@@ -99,7 +99,7 @@ async function renderBackend(backend, serverUrl, graphics) {const background = await page.evaluate(sceneId => window.renderReferenceScene(sceneId, { describe: false, backgroundOnly: true }), id);await writeFile(`${WORK_DIRECTORY}/${id}-background.png`, Buffer.from(background.image, 'base64'));}- const bakeNote = result.bake?.report.refused ? `, bake REFUSED, drawn unbaked: ${result.bake.report.refused}` : result.bake ? `, bake ${result.bake.seconds.toFixed(1)} s, ${result.bake.report.texels} texels${result.bake.report.reduced ? ` (preset reduced to ${result.bake.report.used.samples} samples, ${result.bake.report.used.texelsPerUnit} texels per unit)` : ''}` : '';+ const bakeNote = result.bake?.report.refused ? `, bake REFUSED, drawn unbaked: ${result.bake.report.refused}` : result.bake ? `, bake ${result.bake.seconds.toFixed(1)} s, ${result.bake.report.texels} texels${result.bake.report.reduced ? ` (preset reduced to ${result.bake.report.used.samples} samples, ${result.bake.report.used.bounces} bounces, ${result.bake.report.used.texelsPerUnit} texels per unit)` : ''}` : '';const probeNote = result.probes ? `, probes ${result.probes.report.placed.length} on ${result.probes.report.partsWithProbe} parts` : '';console.log(`${id} on ${backend}: ${Math.round(performance.now() - started)} ms${bakeNote}${probeNote}`);}diff --git a/docs/light-bake.md b/docs/light-bake.mdindex d867c5ed..ddae6e3e 100644--- a/docs/light-bake.md+++ b/docs/light-bake.md@@ -34,7 +34,7 @@ Ranges are 1 to 256 samples, 1 to 3 bounces and 1 to 12 texels per unit. The bakThe unwrap gives the texel count before any ray is traced, so the work of a bake is plain arithmetic: path steps, texels x samples x bounces. It reads no clock and does not depend on machine speed, and the same recipe always resolves to the same numbers. Measured on this machine, a path step costs about 1.8 to 3.1 microseconds, in a closed 56 part room and in the 57 node demo room alike (the number of lights did not change it, so it is not counted).-- A preset (all three fields equal to `draft`, `standard` or `fine`) is scaled down until it fits 5 million path steps: samples by a fifth and texelsPerUnit by a tenth, repeatedly (samples not below 16, texelsPerUnit not below 1). That is 9 to 16 s of tracing on an idle machine, under the 20 s inline limit, and a busy machine still finishes inside the 90 s worker limit. `bake.used` shows the result and `bake.reduced` is `true`. The demo room at `standard` runs at about 64 samples instead of 16 and 2.32 before. A scene that cannot fit even 16 samples at texelsPerUnit 1 fails with a message to remove parts or lights.+- A preset (all three fields equal to `draft` or `standard`; `fine` has the same numbers as `standard`) is scaled down until it fits 5 million path steps: samples by a fifth and texelsPerUnit by a tenth, repeatedly (samples not below 16, texelsPerUnit not below 1). A hall that still does not fit at that floor gives up one bounce and starts again from the preset, down to one bounce, so a preset bakes any scene the explicit limit allows. That is 9 to 16 s of tracing on an idle machine, under the 20 s inline limit, and a busy machine still finishes inside the 90 s worker limit. `bake.used` shows the result, `bake.reduced` is `true` and `bake.reduction` says what was asked, what ran and how to ask for more (explicit settings). The demo room at `standard` runs at about 64 samples instead of 16 and 2.32 before. A scene that cannot fit even 16 samples, 1 bounce and texelsPerUnit 1 fails with a message to remove parts or lights.- Explicit `samples`, `bounces` or `texelsPerUnit` (any combination that is not exactly a preset) are never reduced. They are limited by a hard bound of 24 million path steps (about 5 times the demo room at samples 96, bounces 2, texelsPerUnit 3, which bakes in 11 to 17 s), and by the real time limit (90 s on a worker, 20 s inline). Over the bound they fail before any ray is traced and the message names what fits, for example "samples 120 or fewer with texelsPerUnit 12, or texelsPerUnit 8.61 or less with samples 256". Under the bound they run, and one that passes its limit fails with "The scene is unchanged. Try samples 128, or texelsPerUnit 3.5." (half of what was asked); the clock decides only that failure, never what is traced.A node that hosts cloth is skipped like a hair host: the cloth simulation replaces its geometry every frame, so a lightmap built on the rest geometry would not follow it (and the renderer refuses a light map on geometry without `lightUvs`, which failed every frame after t=0). Baked parts read every other material field live, so motion tracks on colour still work; the lightmap itself is fixed at the rest pose.diff --git a/skills/build-67js-scene/SKILL.md b/skills/build-67js-scene/SKILL.mdindex 1e68e4df..d1a41a81 100644--- a/skills/build-67js-scene/SKILL.md+++ b/skills/build-67js-scene/SKILL.md@@ -51,7 +51,7 @@ Use `simplify-code` and `engineering-workflows` for implementation.- Things that fall, pile up or rest on an authored mesh (dropped objects, a ball in a bowl, a trigger zone) use the recipe `physics` section: bodies on root node IDs, `shape: 'trimesh'` on a fixed body so objects follow the mesh, `sensor: true` for triggers, `layer` and `collidesWith` for masks. Seek with `motionTime` like motion, and read `physics` from `scene_inspect` (resting times, contacts, sensor events) instead of guessing from a picture. Needs the optional peer `@dimforge/rapier3d-compat`; a limp character uses `physics.ragdoll` (`{ armature }` for a recipe armature; an imported asset takes `physics: { duration, floor, ragdoll: {} }` and falls from its current pose onto a floor at world height `floor`), needs a floor body in a scene recipe, and reports `physics.ragdoll` (`lowestY`, `highestY`, `restsAtTime`); joints have no swing limits. See "Recipe physics" in the checkout's `docs/physics.md`.- Flags, curtains, capes and cloths draped over props use the recipe `cloth` section: a `grid` geometry node (flat sheet in XY, `segments` up to 64) listed in `sheets` with `pin` edges (`top`, `left`, a corner...), `wind` in m/s, and fixed `colliders` (`ball` or `box` fitted to their node). Seek with `motionTime`; a flag needs wind along its length (+x for a left pin), not across it. No peer needed, no self collision, no soft bodies. Units, defaults and limits are in `scene_capabilities` under `cloth`; see "Recipe cloth" in `docs/physics.md`.- Sparks, dust, embers, confetti and fur use the recipe `particles` section: a root node whose small low-poly geometry (a box) is the particle, in an emitter system with `seed`, `count` (at most 2000), `rate` (omit for one burst), `lifetime`, `speed`, `spread`, `drag`, `floor` and an `emitter` shape; a system with `type: "hair"` grows strands from a `surface` node. Seek with `motionTime`; the same seed and time give the same particles. The node transform does not move particles, and there is no collision beyond the floor, bounce or per-particle colour. Fields and limits are in `scene_capabilities` under `particles`; see "Recipe particles and hair" in `docs/physics.md`. Smoke, fire and browser liquid are not supported.-- A closed room, or any scene lit by point lights, is dark where the light does not reach. Add the recipe `bake` section (`{ "preset": "standard" }`, or `draft` to try fast, `fine` to finish) or the `set-bake` operation: it writes bounced light into lightmaps when the scene builds and reruns only when parts, lights, materials or the bake change. `scene_inspect` shows `bake.seconds` and `bake.skipped` (alpha, skins, morphs, procedural tags and hair or particle hosts are left as they were; patterned, textured and emissive parts are baked and keep their pattern). It bakes the rest pose and no spot or area lights. Read `docs/light-bake.md`.+- A closed room, or any scene lit by point lights, is dark where the light does not reach. Add the recipe `bake` section (`{ "preset": "standard" }`, or `draft` to try fast; `fine` is the same as `standard`) or the `set-bake` operation: it writes bounced light into lightmaps when the scene builds and reruns only when parts, lights, materials or the bake change. `scene_inspect` shows `bake.seconds` and `bake.skipped` (alpha, skins, morphs, procedural tags and hair or particle hosts are left as they were; patterned, textured and emissive parts are baked and keep their pattern). It bakes the rest pose and no spot or area lights. Read `docs/light-bake.md`.- Agent procedural animation uses `docs/agent-motion.md` from release `0.7.0`. Author recipe tracks, then seek through `sampleMotion` or MCP `motionTime`.- Agent imported character motion uses `docs/agent-character-motion.md` from release `0.8.0`. Inspect source joints before authoring local tracks.- To pick between variants, fork each with `scene_apply` and a `branch` name (the scene and revision stay put), compare them in one `scene_review` with a `branch` per shot, then keep the winner with `scene_restore` and its `branch`. Add `labels: true` to `scene_look` or `scene_review` to match node names and lint problems to what the image shows. Docs: `docs/agent-review.md`.diff --git a/src/agent-bake.js b/src/agent-bake.jsindex 4b9d9c67..56727f2c 100644--- a/src/agent-bake.js+++ b/src/agent-bake.js@@ -100,22 +100,37 @@ function scalePresetDown(settings) {* they fail up front only over the hard limit, and otherwise run until the real maxSeconds limit. A preset is scaled down* (samples by a fifth, texel density by a tenth, repeatedly) until it fits BAKE_PRESET_PATH_WORK.*/-function fitSettingsToBudget(plan, settings) {+export function fitSettingsToBudget(plan, settings) {if (!isPreset(settings)) {const pathWork = pathWorkOf(plan, settings);if (pathWork > BAKE_EXPLICIT_PATH_WORK_LIMIT) {throw new RangeError(overLimitMessage(plan, settings, pathWork));}- return { used: settings, reduced: false };+ return { used: settings, reduced: false, reduction: null };}- let used = settings;- while (pathWorkOf(plan, used) > BAKE_PRESET_PATH_WORK) {- if (used.samples <= PRESET_SAMPLES_FLOOR && used.texelsPerUnit <= BAKE_RANGES.texelsPerUnit[0]) {- throw new RangeError(`Even ${PRESET_SAMPLES_FLOOR} samples at texelsPerUnit ${BAKE_RANGES.texelsPerUnit[0]} is over the preset budget of ${BAKE_PRESET_PATH_WORK} path steps for this scene. Remove parts or lights, or lower bounces.`);+ // Samples and texel density shrink first. When the floor of both still does not fit (a large hall), a bounce is given up and+ // the density and samples start again from the preset, so the result is the largest bake that fits and never a refusal.+ // One bounce at the floor always fits a scene the explicit limit lets through, and past that the scene is too large to bake.+ for (let bounces = settings.bounces; bounces >= BAKE_RANGES.bounces[0]; bounces--) {+ let used = { ...settings, bounces };+ while (pathWorkOf(plan, used) > BAKE_PRESET_PATH_WORK && !atPresetFloor(used)) {+ used = scalePresetDown(used);+ }+ if (pathWorkOf(plan, used) <= BAKE_PRESET_PATH_WORK) {+ const reduced = used.samples !== settings.samples || used.bounces !== settings.bounces || used.texelsPerUnit !== settings.texelsPerUnit;+ return { used, reduced, reduction: reduced ? reductionMessage(settings, used) : null };}- used = scalePresetDown(used);}- return { used, reduced: used !== settings };+ throw new RangeError(`Even ${PRESET_SAMPLES_FLOOR} samples, 1 bounce and texelsPerUnit ${BAKE_RANGES.texelsPerUnit[0]} is over the preset budget of ${BAKE_PRESET_PATH_WORK} path steps for this scene. Remove parts or lights.`);+}++function atPresetFloor(settings) {+ return settings.samples <= PRESET_SAMPLES_FLOOR && settings.texelsPerUnit <= BAKE_RANGES.texelsPerUnit[0];+}++// What the agent reads in bake.reduction: what the preset asked for, what ran, and the one thing to do for more.+function reductionMessage(asked, used) {+ return `The preset asked for samples ${asked.samples}, bounces ${asked.bounces}, texelsPerUnit ${asked.texelsPerUnit}; this scene is too large for that within the preset budget of ${BAKE_PRESET_PATH_WORK} path steps, so it baked samples ${used.samples}, bounces ${used.bounces}, texelsPerUnit ${used.texelsPerUnit} (bake.used). For a denser bake pass explicit samples, bounces and texelsPerUnit, up to ${BAKE_EXPLICIT_PATH_WORK_LIMIT} path steps and ${BAKE_MAXIMUM_SECONDS} s.`;}function timeLimitMessage(error, settings) {@@ -162,7 +177,7 @@ function traceWithAdvice(plan, used) {*/export function bakeChangedParts(snapshots, lighting, settings) {const plan = planLightmaps(snapshots, lighting, { ...settings, maxSeconds: bakeSecondsLimit() });- const { used, reduced } = fitSettingsToBudget(plan, settings);+ const { used, reduced, reduction } = fitSettingsToBudget(plan, settings);const { parts, report } = traceWithAdvice(plan, used);const changed = [];parts.forEach((part, index) => {@@ -170,7 +185,7 @@ export function bakeChangedParts(snapshots, lighting, settings) {changed.push([index, part]);}});- return { changed, report, used, reduced };+ return { changed, report, used, reduced, reduction };}/**@@ -196,7 +211,7 @@ export function bakeAgentParts(parts, worldMatrices, environment, settings, genematerial: { ...part.material },generatesGeometry: generatedGeometryGenerators.get(part.name) ?? false,}));- const { changed, report, used, reduced } = runKernel('lightBake', [snapshots, lighting, settings], bakeChangedParts);+ const { changed, report, used, reduced, reduction } = runKernel('lightBake', [snapshots, lighting, settings], bakeChangedParts);// Probes see the unbaked parts, as the bake does, and are traced as a kernel of their own so a worker can take them too.const probeTrace = !settings.probes ? null: runKernel('probeTrace', [snapshots, lighting, settings.probes, { environment: lighting, maxSeconds: bakeSecondsLimit() }], traceProbes);@@ -213,6 +228,6 @@ export function bakeAgentParts(parts, worldMatrices, environment, settings, gene});// Probes are placed here, on the page, because they build maps and materials; their trace ran above.const placed = probeTrace ? placeProbes(bakedParts, probeTrace) : null;- return { parts: Object.freeze(placed ? placed.parts : bakedParts), report: { ...settings, ...(placed ? { probes: placed.report } : {}), used, reduced, texels: report.texels, rayWork: report.rayWork, seconds: report.seconds,+ return { parts: Object.freeze(placed ? placed.parts : bakedParts), report: { ...settings, ...(placed ? { probes: placed.report } : {}), used, reduced, reduction, texels: report.texels, rayWork: report.rayWork, seconds: report.seconds,bakedParts: report.parts.length, skipped: report.skipped } };}diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.jsindex b3b0a1a3..cc5bafe6 100644--- a/src/agent-scene-capabilities.js+++ b/src/agent-scene-capabilities.js@@ -92,7 +92,8 @@ export const MAXIMUM_VIDEO_SECONDS = 60;export const BAKE_PRESETS = Object.freeze({draft: Object.freeze({ samples: 32, bounces: 1, texelsPerUnit: 3 }),standard: Object.freeze({ samples: 128, bounces: 3, texelsPerUnit: 6 }),- fine: Object.freeze({ samples: 192, bounces: 3, texelsPerUnit: 7 }),+ // An alias of standard: measured on the five reference rooms, no samples and density mix within the 20 s limit scored better (bench/reference/README.md).+ fine: Object.freeze({ samples: 128, bounces: 3, texelsPerUnit: 6 }),});export const BAKE_RANGES = Object.freeze({ samples: [1, 256], bounces: [1, 3], texelsPerUnit: [1, 12] });export const BAKE_MAXIMUM_SECONDS = 20;@@ -251,7 +252,7 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({bake: Object.freeze({fields: 'preset, or samples (1-256), bounces (1-3), texelsPerUnit (1-12) over it; probes room by default, false for none, or up to 4 {position, radius?}. Same recipe, same bytes.',presets: BAKE_PRESETS,- notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit (bake.used, bake.reduced); explicit settings fail over maxPathWork or past maxSeconds. No environment map or specular. Probes (off by default): specular only, none in glTF.',+ notes: 'Bounced light from point, spot, area and key lights. Reruns when parts, lights, materials or bake change. Skips alpha, skin, morph, hair, cloth (bake.skipped). A preset shrinks to fit, never refuses (bake.used, bake.reduction); explicit settings fail over maxPathWork or past maxSeconds. No environment map or specular. Probes (off by default): specular only, none in glTF.',limits: Object.freeze({ maxSeconds: BAKE_MAXIMUM_SECONDS, workerMaxSeconds: BAKE_WORKER_MAXIMUM_SECONDS, maxPathWork: BAKE_EXPLICIT_PATH_WORK_LIMIT, maxPointLights: 8 }),}),motionLimits: Object.freeze({ maxTracks: 128, maxKeyframesPerTrack: 64, maxKeyframes: 2048, maxDuration: 30 }),diff --git a/tests/agent-bake.test.js b/tests/agent-bake.test.jsindex af5acef9..5216ef7b 100644--- a/tests/agent-bake.test.js+++ b/tests/agent-bake.test.js@@ -2,7 +2,8 @@ import './support/load-agent-scene-modules.mjs';import assert from 'node:assert/strict';import test from 'node:test';import { createAgentScene } from '../src/agent-scene.js';-import { normalizeAgentBake, bakeSecondsLimit } from '../src/agent-bake.js';+import { normalizeAgentBake, bakeSecondsLimit, fitSettingsToBudget } from '../src/agent-bake.js';+import { estimateBake } from '../src/light-bake.js';import { BAKE_PRESETS, BAKE_PRESET_PATH_WORK, BAKE_EXPLICIT_PATH_WORK_LIMIT, BAKE_MAXIMUM_SECONDS, BAKE_WORKER_MAXIMUM_SECONDS } from '../src/agent-scene-capabilities.js';function closedRoom(extra = {}) {@@ -293,3 +294,44 @@ test('a bake places a room probe unless bake.probes is false', () => {const optedOut = createAgentScene(closedRoom({ bake: { preset: 'draft', probes: false } })).inspect().bake;assert.equal(optedOut.probes, false);});++// A plan with only what the estimate reads: parts of a given area on one chart each, and one point light.+function syntheticPlan(partAreas) {+ return {+ settings: { maxResolution: 512 },+ entries: partAreas.map(area => ({ area, unwrapped: { utilization: 1 } })),+ lights: { pointLights: [{}], spotLights: [], areaLights: [], sun: false },+ };+}++function pathWork(plan, settings) {+ return estimateBake(plan, settings).texels * settings.samples * settings.bounces;+}++test('a preset on a hall too large for its floor gives up bounces before it refuses, and says what it did', () => {+ const hall = syntheticPlan(Array.from({ length: 160 }, () => 900));+ const floorWork = pathWork(hall, { ...BAKE_PRESETS.standard, samples: 16, texelsPerUnit: 1 });+ assert.ok(floorWork > BAKE_PRESET_PATH_WORK, 'the hall must not fit at the floor with every bounce');+ const { used, reduced, reduction } = fitSettingsToBudget(hall, { ...BAKE_PRESETS.standard, probes: 'room' });+ assert.equal(reduced, true);+ assert.ok(used.bounces < BAKE_PRESETS.standard.bounces);+ assert.ok(pathWork(hall, used) <= BAKE_PRESET_PATH_WORK);+ assert.match(reduction, /bounces 3/);+ assert.match(reduction, new RegExp(`bounces ${used.bounces}`));+ assert.match(reduction, /explicit samples, bounces and texelsPerUnit/);+});++test('a preset keeps its bounces when only samples and density need to shrink, and is silent when it fits', () => {+ const room = syntheticPlan(Array.from({ length: 56 }, () => 9));+ const { used, reduced, reduction } = fitSettingsToBudget(room, { ...BAKE_PRESETS.standard, probes: 'room' });+ assert.equal(reduced, true);+ assert.equal(used.bounces, BAKE_PRESETS.standard.bounces);+ assert.match(reduction, /too large/);+ const small = fitSettingsToBudget(syntheticPlan([4]), { ...BAKE_PRESETS.standard, probes: 'room' });+ assert.deepEqual([small.reduced, small.reduction], [false, null]);+});++test('a scene too large for one bounce at the floor is still refused, with the budget in the message', () => {+ const impossible = syntheticPlan(Array.from({ length: 2000 }, () => 900));+ assert.throws(() => fitSettingsToBudget(impossible, { ...BAKE_PRESETS.draft, probes: 'room' }), /preset budget/);+});