Skip to content

armgit / 67.js

Public Imported from GitHub
0

3D engine that AI agents drive

Balance shards by measured file time and split the agent bake tests into five files (issue #560)

Nguyen Xuan And127ca9b7090
diff --git a/scripts/shard-test-files.mjs b/scripts/shard-test-files.mjs
index 68526a89..03e15908 100644
--- a/scripts/shard-test-files.mjs
+++ b/scripts/shard-test-files.mjs
@@ -1,26 +1,70 @@
// Prints the test files of one shard, one path per line: node scripts/shard-test-files.mjs <shard 1..count> <count>
-// A file goes to the shard its name hashes to, so adding or removing a test file never moves the others. That keeps the merged
-// coverage figures steady: `node --test --test-shard` deals files out by position, and every new file would reshuffle them.
+//
+// Files listed in test-timings.json (milliseconds per file, measured on CI) are dealt out longest first, each to the shard with the
+// least time so far, which keeps every shard close to the same length. A file without a timing goes to the shard its name hashes to,
+// so adding a test file never moves another file and the merged coverage figures stay steady. Refresh the timings after a change that
+// makes tests much slower or faster: download the `timings-*.json` files from a CI run and run `node scripts/shard-test-files.mjs --merge-timings <files>`.
import { createHash } from 'node:crypto';
-import { readdirSync } from 'node:fs';
+import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
-const shard = Number(process.argv[2]);
-const count = Number(process.argv[3]);
-if (!Number.isInteger(shard) || !Number.isInteger(count) || shard < 1 || shard > count) {
- console.error('Usage: node scripts/shard-test-files.mjs <shard 1..count> <count>');
- process.exit(2);
-}
+const rootDirectory = join(import.meta.dirname, '..');
+const timingsPath = join(rootDirectory, 'test-timings.json');
-function shardOf(fileName) {
+function hashedShard(fileName, count) {
const digest = createHash('sha1').update(fileName).digest();
- return (digest.readUInt32BE(0) % count) + 1;
+ return digest.readUInt32BE(0) % count;
+}
+
+export function assignShards(fileNames, timings, count) {
+ const shardOfFile = new Map();
+ const shardTotals = new Array(count).fill(0);
+ const timed = fileNames
+ .filter(name => timings[name] !== undefined)
+ .sort((a, b) => timings[b] - timings[a] || a.localeCompare(b));
+ for (const name of timed) {
+ let lightest = 0;
+ for (let shard = 1; shard < count; shard += 1) {
+ if (shardTotals[shard] < shardTotals[lightest]) lightest = shard;
+ }
+ shardOfFile.set(name, lightest);
+ shardTotals[lightest] += timings[name];
+ }
+ for (const name of fileNames) {
+ if (timings[name] === undefined) shardOfFile.set(name, hashedShard(name, count));
+ }
+ return shardOfFile;
+}
+
+function listTestFiles() {
+ return readdirSync(join(rootDirectory, 'tests'))
+ .filter(name => name.endsWith('.test.js'))
+ .map(name => `tests/${name}`)
+ .sort();
+}
+
+function mergeTimings(paths) {
+ const merged = {};
+ for (const path of paths) Object.assign(merged, JSON.parse(readFileSync(path, 'utf8')));
+ const sorted = Object.fromEntries(Object.entries(merged).sort(([a], [b]) => a.localeCompare(b)));
+ writeFileSync(timingsPath, `${JSON.stringify(sorted, null, 2)}\n`);
+ console.log(`Wrote ${Object.keys(sorted).length} timings to test-timings.json`);
}
-const testsDirectory = join(import.meta.dirname, '..', 'tests');
-const names = readdirSync(testsDirectory)
- .filter(name => name.endsWith('.test.js'))
- .sort();
-for (const name of names) {
- if (shardOf(name) === shard) console.log(`tests/${name}`);
+if (process.argv[1] === import.meta.filename) {
+ if (process.argv[2] === '--merge-timings') {
+ mergeTimings(process.argv.slice(3));
+ } else {
+ const shard = Number(process.argv[2]);
+ const count = Number(process.argv[3]);
+ if (!Number.isInteger(shard) || !Number.isInteger(count) || shard < 1 || shard > count) {
+ console.error('Usage: node scripts/shard-test-files.mjs <shard 1..count> <count>');
+ process.exit(2);
+ }
+ const timings = JSON.parse(readFileSync(timingsPath, 'utf8'));
+ const shardOfFile = assignShards(listTestFiles(), timings, count);
+ for (const [name, assigned] of shardOfFile) {
+ if (assigned === shard - 1) console.log(name);
+ }
+ }
}
diff --git a/test-timings.json b/test-timings.json
new file mode 100644
index 00000000..538f9803
--- /dev/null
+++ b/test-timings.json
@@ -0,0 +1,240 @@
+{
+ "tests/adaptive-quality.test.js": 4,
+ "tests/agent-asset-catalog.test.js": 716,
+ "tests/agent-asset-ik.test.js": 1336,
+ "tests/agent-asset-layers.test.js": 1137,
+ "tests/agent-asset-mesh.test.js": 2680,
+ "tests/agent-asset-motion.test.js": 199,
+ "tests/agent-asset-retarget.test.js": 301,
+ "tests/agent-asset.test.js": 191,
+ "tests/agent-branches-live.test.js": 1,
+ "tests/agent-branches.test.js": 6,
+ "tests/agent-cloth-in-place.test.js": 515,
+ "tests/agent-combined-asset-limit.test.js": 218,
+ "tests/agent-drive.test.js": 635,
+ "tests/agent-floor-sky-trace.test.js": 2751,
+ "tests/agent-ground.test.js": 5,
+ "tests/agent-llms-only-check.test.js": 329,
+ "tests/agent-look-lights.test.js": 3,
+ "tests/agent-look-score.test.js": 4959,
+ "tests/agent-look.test.js": 22,
+ "tests/agent-modeling-suite.test.js": 37451,
+ "tests/agent-motion-constraints.test.js": 115,
+ "tests/agent-motion-ik-limits.test.js": 263,
+ "tests/agent-motion-ik.test.js": 118,
+ "tests/agent-motion.test.js": 54,
+ "tests/agent-object-reflections.test.js": 558,
+ "tests/agent-physics.test.js": 1697,
+ "tests/agent-preview-modules.test.js": 793,
+ "tests/agent-preview.test.js": 285,
+ "tests/agent-query-asset.test.js": 15,
+ "tests/agent-render-jobs.test.js": 1735,
+ "tests/agent-render-limits.test.js": 10,
+ "tests/agent-review.test.js": 3,
+ "tests/agent-runtime.test.js": 196,
+ "tests/agent-scene-assets.test.js": 207,
+ "tests/agent-scene-crowd.test.js": 2759,
+ "tests/agent-scene-motion.test.js": 234,
+ "tests/agent-scene-on-demand.test.js": 247,
+ "tests/agent-scene-vegetation.test.js": 3460,
+ "tests/agent-scene.test.js": 469,
+ "tests/agent-suite-aggregate.test.js": 36,
+ "tests/agent-texture-sequence.test.js": 46,
+ "tests/agent-threejs-grade.test.js": 507,
+ "tests/agent-walkmap-recipe.test.js": 68,
+ "tests/agent-walkmap.test.js": 176,
+ "tests/animation-mixer.test.js": 21,
+ "tests/animation.test.js": 83,
+ "tests/assembly.test.js": 204,
+ "tests/blender-constraints.test.js": 42,
+ "tests/blender-curve-text.test.js": 70,
+ "tests/blender-golden.test.js": 1903,
+ "tests/budget.test.js": 4,
+ "tests/cabinet-tasks.test.js": 133,
+ "tests/camera-path.test.js": 11,
+ "tests/camera.test.js": 11,
+ "tests/canvas2d.test.js": 15,
+ "tests/cascaded-shadows.test.js": 7,
+ "tests/changelog-data.test.js": 17,
+ "tests/changelog-fragments.test.js": 19,
+ "tests/closed-room.test.js": 2936,
+ "tests/cloth-blender.test.js": 1742,
+ "tests/cloth-moving.test.js": 86299,
+ "tests/cloth.test.js": 13006,
+ "tests/clutter.test.js": 2821,
+ "tests/compressed-texture.test.js": 4,
+ "tests/coplanar-overlap.test.js": 48,
+ "tests/crowd-skinning.test.js": 2770,
+ "tests/curve-text.test.js": 2146,
+ "tests/default-look.test.js": 50,
+ "tests/desk-tasks.test.js": 135,
+ "tests/docs-pages.test.js": 327,
+ "tests/easing.test.js": 37,
+ "tests/effects.test.js": 3,
+ "tests/environment.test.js": 60,
+ "tests/export-options.test.js": 5,
+ "tests/export-roundtrip.test.js": 865,
+ "tests/export.test.js": 461,
+ "tests/expression.test.js": 7,
+ "tests/file-scene-render.test.js": 12,
+ "tests/film-character.test.js": 161,
+ "tests/film-physics.test.js": 8811,
+ "tests/film-timeline.test.js": 310,
+ "tests/film.test.js": 28161,
+ "tests/floor-sky-visibility.test.js": 1089,
+ "tests/fog-bounce.test.js": 1013,
+ "tests/fog-fit.test.js": 2,
+ "tests/fog-sky-visibility.test.js": 89,
+ "tests/foliage-transmission.test.js": 1,
+ "tests/frame-diagnostics.test.js": 3,
+ "tests/gaussian-splats.test.js": 124,
+ "tests/gl-program-lost-context.test.js": 3,
+ "tests/gltf-extensions.test.js": 45,
+ "tests/gltf-meshopt.test.js": 192,
+ "tests/gltf-morph-normals-and-nan.test.js": 14,
+ "tests/gltf-morph.test.js": 35,
+ "tests/gltf-node-pose.test.js": 66,
+ "tests/gltf-optional.test.js": 24,
+ "tests/gltf-shared-textures.test.js": 55,
+ "tests/gltf-skeleton-and-bad-primitives.test.js": 35,
+ "tests/gltf-sketchfab-fallbacks.test.js": 11,
+ "tests/gltf-tolerance-clip.test.js": 30,
+ "tests/gltf-tolerance.test.js": 31,
+ "tests/gltf.test.js": 121,
+ "tests/grass.test.js": 3473,
+ "tests/ground-bounce.test.js": 20,
+ "tests/heightfield.test.js": 42,
+ "tests/input-key-guards.test.js": 3,
+ "tests/irradiance-grid.test.js": 3451,
+ "tests/kernel-offload.test.js": 43552,
+ "tests/kettle-tasks.test.js": 133,
+ "tests/large-bounds.test.js": 701,
+ "tests/layer-textures.test.js": 83,
+ "tests/light-bake-backends.test.js": 1215,
+ "tests/light-bake-texel-density.test.js": 159,
+ "tests/light-bake.test.js": 6324,
+ "tests/light-linking.test.js": 3,
+ "tests/light-shading.test.js": 3,
+ "tests/light-units.test.js": 2,
+ "tests/lighting.test.js": 14,
+ "tests/line-art-reference.test.js": 67,
+ "tests/line-art.test.js": 225,
+ "tests/live-cloth.test.js": 1708,
+ "tests/material-graph.test.js": 17892,
+ "tests/material-layer-shaders.test.js": 12,
+ "tests/material-layers.test.js": 93,
+ "tests/material-patterns.test.js": 13771,
+ "tests/material-snippet.test.js": 70,
+ "tests/mcp-environment-schema.test.js": 618,
+ "tests/mcp-node-fields.test.js": 223,
+ "tests/mcp-server-job-lock.test.js": 686,
+ "tests/mcp-tool-count.test.js": 222,
+ "tests/mcp-tools.test.js": 993,
+ "tests/mesh-bevel.test.js": 238,
+ "tests/mesh-blend.test.js": 108,
+ "tests/mesh-boolean.test.js": 417,
+ "tests/mesh-core.test.js": 295,
+ "tests/mesh-cut-tools.test.js": 101,
+ "tests/mesh-decimate.test.js": 1395,
+ "tests/mesh-deform-modifiers.test.js": 25,
+ "tests/mesh-edit.test.js": 263,
+ "tests/mesh-fields.test.js": 231,
+ "tests/mesh-generator-modifiers.test.js": 27,
+ "tests/mesh-lint-geometry.test.js": 145,
+ "tests/mesh-loopcut.test.js": 159,
+ "tests/mesh-modifiers.test.js": 145,
+ "tests/mesh-normal-modifiers.test.js": 19,
+ "tests/mesh-query.test.js": 291,
+ "tests/mesh-sculpt-shrinkwrap.test.js": 2067,
+ "tests/mesh-stack.test.js": 173,
+ "tests/mesh-subdivide.test.js": 48,
+ "tests/mesh-uv.test.js": 504,
+ "tests/model.test.js": 486,
+ "tests/modeling-parity.test.js": 94,
+ "tests/modeling.test.js": 60,
+ "tests/morph-renderer.test.js": 53,
+ "tests/morph.test.js": 10,
+ "tests/nature.test.js": 681,
+ "tests/navmesh.test.js": 750,
+ "tests/other-clients.test.js": 2640,
+ "tests/parity-ledger.test.js": 18,
+ "tests/part-relations.test.js": 726,
+ "tests/particles.test.js": 1281,
+ "tests/path-tracer-denoise-oidn.test.js": 68,
+ "tests/path-tracer-emissive-fog.test.js": 2154,
+ "tests/path-tracer-gpu-pack.test.js": 12,
+ "tests/path-tracer-light-linking.test.js": 422,
+ "tests/path-tracer-subsurface.test.js": 1336,
+ "tests/path-tracer.test.js": 3715,
+ "tests/physics-colliders.test.js": 310,
+ "tests/physics.test.js": 599,
+ "tests/preview-transition.test.js": 3,
+ "tests/ragdoll.test.js": 2107,
+ "tests/recipe-cascades-linking.test.js": 484,
+ "tests/reference-bake-regression.test.js": 3,
+ "tests/reference-baseline.test.js": 3,
+ "tests/reference-quantisation.test.js": 1,
+ "tests/reflection-probes.test.js": 4451,
+ "tests/render-culling.test.js": 108,
+ "tests/render-passes.test.js": 44,
+ "tests/render-target-memory.test.js": 7,
+ "tests/renderer-topology.test.js": 118,
+ "tests/renderer.test.js": 33,
+ "tests/replace-textured-parts-import.test.js": 16,
+ "tests/retarget.test.js": 63,
+ "tests/reversed-depth.test.js": 7,
+ "tests/rigging.test.js": 2715,
+ "tests/room-bounce.test.js": 37,
+ "tests/runtime-report.test.js": 3,
+ "tests/scene-graph.test.js": 34,
+ "tests/scene-query-obstacles.test.js": 29,
+ "tests/scene-query.test.js": 12,
+ "tests/sculpt.test.js": 30,
+ "tests/shader-features.test.js": 6,
+ "tests/shader-snippet-validator.test.js": 47,
+ "tests/shadow-depth-script.test.js": 1,
+ "tests/shadow-hardware-compare.test.js": 1,
+ "tests/shadow-light.test.js": 3,
+ "tests/showcase-port-weight.test.js": 2419,
+ "tests/shrinkwrap.test.js": 38,
+ "tests/size-budget.test.js": 21,
+ "tests/size-growth.test.js": 12538,
+ "tests/skeleton-pose-asset.test.js": 350,
+ "tests/skeleton-pose-limits.test.js": 12,
+ "tests/skeleton-pose.test.js": 42,
+ "tests/skill-mesh-recipes.test.js": 1819,
+ "tests/skinning.test.js": 11,
+ "tests/sky-visibility.test.js": 611,
+ "tests/splat.test.js": 27,
+ "tests/spume.test.js": 6,
+ "tests/studio-floor.test.js": 41,
+ "tests/subsurface.test.js": 77,
+ "tests/sun-bounce.test.js": 4196,
+ "tests/surface-attachment.test.js": 16,
+ "tests/surface.test.js": 265,
+ "tests/terrain-holes.test.js": 580,
+ "tests/terrain.test.js": 1719,
+ "tests/texture-set.test.js": 6,
+ "tests/texture-update.test.js": 4,
+ "tests/tool-cost-growth.test.js": 133,
+ "tests/tool-cost.test.js": 1,
+ "tests/tool-errors.test.js": 18,
+ "tests/tree-sky-levels.test.js": 1276,
+ "tests/triangulate.test.js": 29,
+ "tests/update-part-vertices.test.js": 3,
+ "tests/update-parts-fast-path.test.js": 6,
+ "tests/vegetation-bark-wind.test.js": 737,
+ "tests/vegetation-impostors.test.js": 6816,
+ "tests/vegetation-pop.test.js": 711,
+ "tests/vegetation.test.js": 4216,
+ "tests/vehicle-steering-lights.test.js": 98,
+ "tests/vehicle.test.js": 124,
+ "tests/version.test.js": 1,
+ "tests/view-transform.test.js": 33,
+ "tests/volumetric.test.js": 5,
+ "tests/wall-e-preview-scene.test.js": 498,
+ "tests/water-reflection.test.js": 458,
+ "tests/water-shadows-render.test.js": 1,
+ "tests/water-shadows.test.js": 24,
+ "tests/world-addon-shader-imports.test.js": 421
+}
diff --git a/tests/agent-bake-budget.test.js b/tests/agent-bake-budget.test.js
new file mode 100644
index 00000000..2654fa20
--- /dev/null
+++ b/tests/agent-bake-budget.test.js
@@ -0,0 +1,27 @@
+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 { BAKE_PRESETS, BAKE_PRESET_PATH_WORK } from '../src/agent-scene-capabilities.js';
+import { closedRoom, lightmapBytesOf, largeRoom } from './support/agent-bake-rooms.mjs';
+
+test('a preset on a 56 part room shrinks to the path work budget, finishes, and reports what it used', () => {
+ const scene = createAgentScene(largeRoom({ preset: 'standard' }));
+ const bake = scene.inspect().bake;
+ assert.equal(scene.parts.length, 56);
+ assert.equal(bake.reduced, true);
+ assert.ok(bake.used.samples < BAKE_PRESETS.standard.samples);
+ assert.ok(bake.used.texelsPerUnit < BAKE_PRESETS.standard.texelsPerUnit);
+ assert.equal(bake.used.bounces, BAKE_PRESETS.standard.bounces);
+ assert.ok(bake.texels * bake.used.samples * bake.used.bounces <= BAKE_PRESET_PATH_WORK);
+ assert.ok(Number.isFinite(bake.seconds) && bake.seconds >= 0, 'the report carries the time the bake took');
+ const again = createAgentScene(largeRoom({ preset: 'standard' }));
+ assert.deepEqual(again.inspect().bake.used, bake.used);
+ assert.deepEqual(lightmapBytesOf(again, 'floor'), lightmapBytesOf(scene, 'floor'));
+});
+
+test('a preset that already fits is not reduced', () => {
+ const bake = createAgentScene(closedRoom()).inspect().bake;
+ assert.equal(bake.reduced, false);
+ assert.deepEqual(bake.used, { ...BAKE_PRESETS.draft, probes: 'room' });
+});
diff --git a/tests/agent-bake-cloth-probes-fit.test.js b/tests/agent-bake-cloth-probes-fit.test.js
new file mode 100644
index 00000000..dbdc03ca
--- /dev/null
+++ b/tests/agent-bake-cloth-probes-fit.test.js
@@ -0,0 +1,71 @@
+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 { fitSettingsToBudget } from '../src/agent-bake.js';
+import { estimateBake } from '../src/light-bake.js';
+import { BAKE_PRESETS, BAKE_PRESET_PATH_WORK } from '../src/agent-scene-capabilities.js';
+import { closedRoom, clothRoom } from './support/agent-bake-rooms.mjs';
+
+test('a cloth sheet is skipped by the bake and still has no lightmap after a seek past t=0', () => {
+ const scene = createAgentScene(clothRoom());
+ const skipped = scene.inspect().bake.skipped.find(entry => entry.name === 'flag');
+ assert.ok(skipped);
+ assert.match(skipped.reason, /cloth/);
+ scene.sampleMotion(1);
+ const flag = scene.parts.find(part => part.name === 'flag');
+ assert.equal(flag.material.lightMap, undefined);
+ assert.equal(flag.material.emissiveMap, undefined);
+ for (const part of scene.parts) {
+ assert.ok(!part.material.lightMap || part.geometry.lightUvs, `${part.name} has a light map without lightUvs`);
+ }
+ assert.ok(scene.parts.find(part => part.name === 'floor').material.emissiveMap);
+});
+
+test('a bake places a room probe unless bake.probes is false', () => {
+ const withProbe = createAgentScene(closedRoom()).inspect().bake;
+ assert.equal(withProbe.probes.placed.length, 1);
+ const optedOut = createAgentScene(closedRoom({ bake: { preset: 'draft', probes: false } })).inspect().bake;
+ assert.equal(optedOut.probes, false);
+});
+
+
+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/);
+});
diff --git a/tests/agent-bake-limits.test.js b/tests/agent-bake-limits.test.js
new file mode 100644
index 00000000..c8c0353c
--- /dev/null
+++ b/tests/agent-bake-limits.test.js
@@ -0,0 +1,61 @@
+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 { bakeSecondsLimit } from '../src/agent-bake.js';
+import { BAKE_PRESET_PATH_WORK, BAKE_EXPLICIT_PATH_WORK_LIMIT, BAKE_MAXIMUM_SECONDS, BAKE_WORKER_MAXIMUM_SECONDS } from '../src/agent-scene-capabilities.js';
+import { largeRoom } from './support/agent-bake-rooms.mjs';
+
+test('explicit settings over the hard limit fail up front with a lower setting to try', () => {
+ const heavy = { preset: 'draft', samples: 256, bounces: 3, texelsPerUnit: 12 };
+ let message = '';
+ assert.throws(() => createAgentScene(largeRoom(heavy)), error => {
+ message = error.message;
+ return /path steps/.test(error.message) && message.includes(String(BAKE_EXPLICIT_PATH_WORK_LIMIT));
+ });
+ const fittingSamples = Number(/samples (\d+) or fewer/.exec(message)?.[1]);
+ const fittingDensity = Number(/texelsPerUnit ([\d.]+) or less/.exec(message)?.[1]);
+ assert.ok(fittingSamples >= 1 && fittingSamples < 256, message);
+ assert.ok(fittingDensity >= 1 && fittingDensity < 12, message);
+});
+
+test('explicit settings far above the preset budget run when they fit the hard limit, and are never reduced', () => {
+ const explicit = { samples: 160, bounces: 2, texelsPerUnit: 6 };
+ // A busy machine can pass the real limit here, and this test is about the settings, so the clock stands still.
+ const realNow = performance.now;
+ performance.now = () => 0;
+ try {
+ const bake = createAgentScene(largeRoom(explicit)).inspect().bake;
+ assert.equal(bake.reduced, false);
+ assert.deepEqual(bake.used, { ...explicit, probes: 'room' });
+ assert.ok(bake.texels * explicit.samples * explicit.bounces > BAKE_PRESET_PATH_WORK);
+ } finally {
+ performance.now = realNow;
+ }
+});
+
+test('an explicit bake that passes maxSeconds fails cleanly with a lower setting to try', () => {
+ const slow = { samples: 256, bounces: 3, texelsPerUnit: 4 };
+ // A fast machine finishes this bake inside the real limit, so each clock read is made to cost a second.
+ const realNow = performance.now;
+ let clockReads = 0;
+ performance.now = () => {
+ clockReads += 1;
+ return realNow.call(performance) + clockReads * 1000;
+ };
+ try {
+ assert.throws(() => createAgentScene(largeRoom(slow)), error => /maxSeconds/.test(error.message) && /Try samples 128/.test(error.message));
+ } finally {
+ performance.now = realNow;
+ }
+});
+
+test('the bake kernel carries 20 s on the page thread and 90 s inside a worker', () => {
+ assert.equal(bakeSecondsLimit(), BAKE_MAXIMUM_SECONDS);
+ globalThis.WorkerGlobalScope = Object;
+ try {
+ assert.equal(bakeSecondsLimit(), BAKE_WORKER_MAXIMUM_SECONDS);
+ } finally {
+ delete globalThis.WorkerGlobalScope;
+ }
+});
diff --git a/tests/agent-bake-materials-lights.test.js b/tests/agent-bake-materials-lights.test.js
new file mode 100644
index 00000000..f2dfa69e
--- /dev/null
+++ b/tests/agent-bake-materials-lights.test.js
@@ -0,0 +1,55 @@
+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 { closedRoom, roomLitBy, lightmapBytesOf } from './support/agent-bake-rooms.mjs';
+
+test('a brick wall keeps its pattern and receives bounced light through a light map', () => {
+ const recipe = closedRoom();
+ recipe.materials.push({ id: 'bricks', color: [1, 1, 1], roughness: 0.9, pattern: { type: 'bricks', size: 1 } });
+ recipe.nodes.find(node => node.id === 'back').material = 'bricks';
+ const scene = createAgentScene(recipe);
+ assert.deepEqual(scene.inspect().bake.skipped, []);
+ const wall = scene.parts.find(part => part.name === 'back');
+ assert.ok(wall.material.lightMap);
+ assert.ok(wall.material.map);
+ assert.ok(wall.material.boxMapScale > 0);
+ assert.equal(wall.geometry.lightUvs.length, wall.geometry.positions.length / 3 * 2);
+ const again = createAgentScene(recipe).parts.find(part => part.name === 'back');
+ assert.deepEqual(Array.from(again.material.lightMap.image.data), Array.from(wall.material.lightMap.image.data));
+});
+
+test('a node that hosts a hair system bakes without an error and is reported as skipped', () => {
+ const recipe = closedRoom({
+ geometries: [{ id: 'box', type: 'box' }, { id: 'head', type: 'sphere', segments: 12, rings: 8 }],
+ particles: { systems: [{ type: 'hair', node: 'fur', surface: 'head', seed: 5, count: 40, length: [0.1, 0.2], segments: 3 }] },
+ });
+ recipe.nodes.push({ id: 'head', geometry: 'head', material: 'white', translation: [0.5, 0.5, 0.5], scale: [0.3, 0.3, 0.3] });
+ recipe.nodes.push({ id: 'fur', geometry: 'box', material: 'white' });
+ const scene = createAgentScene(recipe);
+ const skipped = scene.inspect().bake.skipped.find(entry => entry.name === 'fur');
+ assert.ok(skipped);
+ assert.match(skipped.reason, /hair|particle/);
+ assert.ok(scene.parts.find(part => part.name === 'head').material.emissiveMap);
+ assert.equal(scene.parts.find(part => part.name === 'fur').material.emissiveMap, undefined);
+});
+
+test('a spot light that points at the floor bakes the light that bounces off it', () => {
+ const recipe = roomLitBy({ spotLights: [{ position: [0, 2.8, 0.5], direction: [0, -1, 0], angle: 0.6, intensity: 30 }] });
+ const scene = createAgentScene(recipe);
+ assert.ok(scene.parts.find(part => part.name === 'back').material.emissiveMap);
+ assert.deepEqual(lightmapBytesOf(createAgentScene(recipe), 'back'), lightmapBytesOf(scene, 'back'));
+ const withoutSpot = createAgentScene(roomLitBy({}));
+ assert.notDeepEqual(lightmapBytesOf(withoutSpot, 'back'), lightmapBytesOf(scene, 'back'));
+});
+
+test('an area light bakes bounced light on its front side only, and a changed spot or area light bakes again', () => {
+ const facingDown = roomLitBy({ areaLights: [{ position: [0, 2.9, 0], direction: [0, -1, 0], width: 1, height: 1, intensity: 20 }] });
+ const facingUp = roomLitBy({ areaLights: [{ position: [0, 2.9, 0], direction: [0, 1, 0], width: 1, height: 1, intensity: 20 }] });
+ const scene = createAgentScene(facingDown);
+ assert.ok(scene.parts.find(part => part.name === 'floor').material.emissiveMap);
+ assert.deepEqual(lightmapBytesOf(createAgentScene(facingDown), 'floor'), lightmapBytesOf(scene, 'floor'));
+ assert.notDeepEqual(lightmapBytesOf(createAgentScene(facingUp), 'floor'), lightmapBytesOf(scene, 'floor'));
+ scene.apply([{ type: 'set-environment', environment: { areaLights: [{ position: [0, 2.9, 0], direction: [0, -1, 0], width: 1, height: 1, intensity: 25 }] } }], { expectedRevision: 0 });
+ assert.equal(scene.inspect().bake.reused, false);
+});
diff --git a/tests/agent-bake.test.js b/tests/agent-bake.test.js
index 6ab98f59..f423e43a 100644
--- a/tests/agent-bake.test.js
+++ b/tests/agent-bake.test.js
@@ -2,44 +2,9 @@ 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, 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 = {}) {
- const box = (id, translation, scale, material) => ({ id, geometry: 'box', material, translation, scale });
- return {
- format: '67js.scene', schemaVersion: 1,
- geometries: [{ id: 'box', type: 'box' }],
- materials: [
- { id: 'white', color: [0.8, 0.8, 0.8], roughness: 0.9 },
- { id: 'lamp', color: [1, 1, 1], emission: 2 },
- ],
- nodes: [
- box('floor', [0, -0.05, 0], [4, 0.1, 4], 'white'),
- box('ceiling', [0, 3.05, 0], [4, 0.1, 4], 'white'),
- box('back', [0, 1.5, -2.05], [4.2, 3.2, 0.1], 'white'),
- box('front', [0, 1.5, 2.05], [4.2, 3.2, 0.1], 'white'),
- box('left', [-2.05, 1.5, 0], [0.1, 3.2, 4.2], 'white'),
- box('right', [2.05, 1.5, 0], [0.1, 3.2, 4.2], 'white'),
- box('block', [-0.7, 0.6, -0.4], [1.2, 1.2, 1.2], 'white'),
- box('bulb', [0.9, 2.5, 0.6], [0.2, 0.2, 0.2], 'lamp'),
- ],
- camera: { eye: [0, 1.5, 1.9], target: [0, 1.4, -2], fov: 70, near: 0.05, far: 20 },
- environment: { pointLights: [{ position: [0, 2.7, 0], intensity: 14, radius: 0.1 }], keyIntensity: 0, fillIntensity: 0 },
- bake: { preset: 'draft' },
- ...extra,
- };
-}
-
-function closedRoomWithoutBake() {
- const { bake, ...recipe } = closedRoom();
- return recipe;
-}
-
-function lightmapBytes(part) {
- return Buffer.from(part.material.emissiveMap.image.data ?? part.material.emissiveMap.image.bytes);
-}
+import { normalizeAgentBake } from '../src/agent-bake.js';
+import { BAKE_PRESETS } from '../src/agent-scene-capabilities.js';
+import { closedRoom, closedRoomWithoutBake, lightmapBytes } from './support/agent-bake-rooms.mjs';
test('bake presets and fields resolve to plain numbers within their ranges', () => {
assert.deepEqual(normalizeAgentBake({ preset: 'fine' }), { ...BAKE_PRESETS.fine, probes: 'room' });
@@ -121,217 +86,3 @@ test('a failed bake leaves the scene as it was', () => {
assert.equal(scene.revision, 0);
assert.equal(scene.inspect().bake.samples, BAKE_PRESETS.draft.samples);
});
-
-test('a brick wall keeps its pattern and receives bounced light through a light map', () => {
- const recipe = closedRoom();
- recipe.materials.push({ id: 'bricks', color: [1, 1, 1], roughness: 0.9, pattern: { type: 'bricks', size: 1 } });
- recipe.nodes.find(node => node.id === 'back').material = 'bricks';
- const scene = createAgentScene(recipe);
- assert.deepEqual(scene.inspect().bake.skipped, []);
- const wall = scene.parts.find(part => part.name === 'back');
- assert.ok(wall.material.lightMap);
- assert.ok(wall.material.map);
- assert.ok(wall.material.boxMapScale > 0);
- assert.equal(wall.geometry.lightUvs.length, wall.geometry.positions.length / 3 * 2);
- const again = createAgentScene(recipe).parts.find(part => part.name === 'back');
- assert.deepEqual(Array.from(again.material.lightMap.image.data), Array.from(wall.material.lightMap.image.data));
-});
-
-test('a node that hosts a hair system bakes without an error and is reported as skipped', () => {
- const recipe = closedRoom({
- geometries: [{ id: 'box', type: 'box' }, { id: 'head', type: 'sphere', segments: 12, rings: 8 }],
- particles: { systems: [{ type: 'hair', node: 'fur', surface: 'head', seed: 5, count: 40, length: [0.1, 0.2], segments: 3 }] },
- });
- recipe.nodes.push({ id: 'head', geometry: 'head', material: 'white', translation: [0.5, 0.5, 0.5], scale: [0.3, 0.3, 0.3] });
- recipe.nodes.push({ id: 'fur', geometry: 'box', material: 'white' });
- const scene = createAgentScene(recipe);
- const skipped = scene.inspect().bake.skipped.find(entry => entry.name === 'fur');
- assert.ok(skipped);
- assert.match(skipped.reason, /hair|particle/);
- assert.ok(scene.parts.find(part => part.name === 'head').material.emissiveMap);
- assert.equal(scene.parts.find(part => part.name === 'fur').material.emissiveMap, undefined);
-});
-
-function roomLitBy(environment) {
- return closedRoom({ environment: { ...environment, keyIntensity: 0, fillIntensity: 0 } });
-}
-
-function lightmapBytesOf(scene, name) {
- return lightmapBytes(scene.parts.find(part => part.name === name));
-}
-
-test('a spot light that points at the floor bakes the light that bounces off it', () => {
- const recipe = roomLitBy({ spotLights: [{ position: [0, 2.8, 0.5], direction: [0, -1, 0], angle: 0.6, intensity: 30 }] });
- const scene = createAgentScene(recipe);
- assert.ok(scene.parts.find(part => part.name === 'back').material.emissiveMap);
- assert.deepEqual(lightmapBytesOf(createAgentScene(recipe), 'back'), lightmapBytesOf(scene, 'back'));
- const withoutSpot = createAgentScene(roomLitBy({}));
- assert.notDeepEqual(lightmapBytesOf(withoutSpot, 'back'), lightmapBytesOf(scene, 'back'));
-});
-
-test('an area light bakes bounced light on its front side only, and a changed spot or area light bakes again', () => {
- const facingDown = roomLitBy({ areaLights: [{ position: [0, 2.9, 0], direction: [0, -1, 0], width: 1, height: 1, intensity: 20 }] });
- const facingUp = roomLitBy({ areaLights: [{ position: [0, 2.9, 0], direction: [0, 1, 0], width: 1, height: 1, intensity: 20 }] });
- const scene = createAgentScene(facingDown);
- assert.ok(scene.parts.find(part => part.name === 'floor').material.emissiveMap);
- assert.deepEqual(lightmapBytesOf(createAgentScene(facingDown), 'floor'), lightmapBytesOf(scene, 'floor'));
- assert.notDeepEqual(lightmapBytesOf(createAgentScene(facingUp), 'floor'), lightmapBytesOf(scene, 'floor'));
- scene.apply([{ type: 'set-environment', environment: { areaLights: [{ position: [0, 2.9, 0], direction: [0, -1, 0], width: 1, height: 1, intensity: 25 }] } }], { expectedRevision: 0 });
- assert.equal(scene.inspect().bake.reused, false);
-});
-
-function largeRoom(bake) {
- const recipe = closedRoom({ bake });
- recipe.environment.spotLights = [{ position: [0, 2.8, 0], direction: [0, -1, 0], angle: 1, intensity: 20 }];
- for (let index = 0; index < 48; index++) {
- const column = index % 8;
- const row = Math.floor(index / 8);
- recipe.nodes.push({ id: `crate-${index}`, geometry: 'box', material: 'white', translation: [-1.75 + column * 0.5, 0.3, -1.7 + row * 0.6], scale: [0.4, 0.6, 0.4] });
- }
- return recipe;
-}
-
-test('a preset on a 56 part room shrinks to the path work budget, finishes, and reports what it used', () => {
- const scene = createAgentScene(largeRoom({ preset: 'standard' }));
- const bake = scene.inspect().bake;
- assert.equal(scene.parts.length, 56);
- assert.equal(bake.reduced, true);
- assert.ok(bake.used.samples < BAKE_PRESETS.standard.samples);
- assert.ok(bake.used.texelsPerUnit < BAKE_PRESETS.standard.texelsPerUnit);
- assert.equal(bake.used.bounces, BAKE_PRESETS.standard.bounces);
- assert.ok(bake.texels * bake.used.samples * bake.used.bounces <= BAKE_PRESET_PATH_WORK);
- assert.ok(Number.isFinite(bake.seconds) && bake.seconds >= 0, 'the report carries the time the bake took');
- const again = createAgentScene(largeRoom({ preset: 'standard' }));
- assert.deepEqual(again.inspect().bake.used, bake.used);
- assert.deepEqual(lightmapBytesOf(again, 'floor'), lightmapBytesOf(scene, 'floor'));
-});
-
-test('a preset that already fits is not reduced', () => {
- const bake = createAgentScene(closedRoom()).inspect().bake;
- assert.equal(bake.reduced, false);
- assert.deepEqual(bake.used, { ...BAKE_PRESETS.draft, probes: 'room' });
-});
-
-test('explicit settings over the hard limit fail up front with a lower setting to try', () => {
- const heavy = { preset: 'draft', samples: 256, bounces: 3, texelsPerUnit: 12 };
- let message = '';
- assert.throws(() => createAgentScene(largeRoom(heavy)), error => {
- message = error.message;
- return /path steps/.test(error.message) && message.includes(String(BAKE_EXPLICIT_PATH_WORK_LIMIT));
- });
- const fittingSamples = Number(/samples (\d+) or fewer/.exec(message)?.[1]);
- const fittingDensity = Number(/texelsPerUnit ([\d.]+) or less/.exec(message)?.[1]);
- assert.ok(fittingSamples >= 1 && fittingSamples < 256, message);
- assert.ok(fittingDensity >= 1 && fittingDensity < 12, message);
-});
-
-test('explicit settings far above the preset budget run when they fit the hard limit, and are never reduced', () => {
- const explicit = { samples: 160, bounces: 2, texelsPerUnit: 6 };
- // A busy machine can pass the real limit here, and this test is about the settings, so the clock stands still.
- const realNow = performance.now;
- performance.now = () => 0;
- try {
- const bake = createAgentScene(largeRoom(explicit)).inspect().bake;
- assert.equal(bake.reduced, false);
- assert.deepEqual(bake.used, { ...explicit, probes: 'room' });
- assert.ok(bake.texels * explicit.samples * explicit.bounces > BAKE_PRESET_PATH_WORK);
- } finally {
- performance.now = realNow;
- }
-});
-
-test('an explicit bake that passes maxSeconds fails cleanly with a lower setting to try', () => {
- const slow = { samples: 256, bounces: 3, texelsPerUnit: 4 };
- // A fast machine finishes this bake inside the real limit, so each clock read is made to cost a second.
- const realNow = performance.now;
- let clockReads = 0;
- performance.now = () => {
- clockReads += 1;
- return realNow.call(performance) + clockReads * 1000;
- };
- try {
- assert.throws(() => createAgentScene(largeRoom(slow)), error => /maxSeconds/.test(error.message) && /Try samples 128/.test(error.message));
- } finally {
- performance.now = realNow;
- }
-});
-
-test('the bake kernel carries 20 s on the page thread and 90 s inside a worker', () => {
- assert.equal(bakeSecondsLimit(), BAKE_MAXIMUM_SECONDS);
- globalThis.WorkerGlobalScope = Object;
- try {
- assert.equal(bakeSecondsLimit(), BAKE_WORKER_MAXIMUM_SECONDS);
- } finally {
- delete globalThis.WorkerGlobalScope;
- }
-});
-
-function clothRoom() {
- const recipe = closedRoom({ cloth: { duration: 2, sheets: [{ node: 'flag', pin: ['top'] }] } });
- recipe.geometries.push({ id: 'sheet', type: 'grid', segments: 8 });
- recipe.nodes.push({ id: 'flag', geometry: 'sheet', material: 'white', translation: [0.5, 2, 0], scale: [1, 1, 1] });
- return recipe;
-}
-
-test('a cloth sheet is skipped by the bake and still has no lightmap after a seek past t=0', () => {
- const scene = createAgentScene(clothRoom());
- const skipped = scene.inspect().bake.skipped.find(entry => entry.name === 'flag');
- assert.ok(skipped);
- assert.match(skipped.reason, /cloth/);
- scene.sampleMotion(1);
- const flag = scene.parts.find(part => part.name === 'flag');
- assert.equal(flag.material.lightMap, undefined);
- assert.equal(flag.material.emissiveMap, undefined);
- for (const part of scene.parts) {
- assert.ok(!part.material.lightMap || part.geometry.lightUvs, `${part.name} has a light map without lightUvs`);
- }
- assert.ok(scene.parts.find(part => part.name === 'floor').material.emissiveMap);
-});
-
-test('a bake places a room probe unless bake.probes is false', () => {
- const withProbe = createAgentScene(closedRoom()).inspect().bake;
- assert.equal(withProbe.probes.placed.length, 1);
- 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/);
-});
diff --git a/tests/shard-test-files.test.js b/tests/shard-test-files.test.js
new file mode 100644
index 00000000..6f0ca200
--- /dev/null
+++ b/tests/shard-test-files.test.js
@@ -0,0 +1,22 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { assignShards } from '../scripts/shard-test-files.mjs';
+
+const timings = { 'tests/a.test.js': 90, 'tests/b.test.js': 60, 'tests/c.test.js': 50, 'tests/d.test.js': 40, 'tests/e.test.js': 10 };
+const names = Object.keys(timings);
+
+test('timed files are dealt longest first to the lightest shard', () => {
+ const shards = assignShards(names, timings, 2);
+ const total = shard => names.filter(name => shards.get(name) === shard).reduce((sum, name) => sum + timings[name], 0);
+ assert.equal(total(0), 130);
+ assert.equal(total(1), 120);
+ assert.deepEqual(assignShards(names, timings, 2), shards);
+});
+
+test('a file without a timing lands in one shard and moves no other file', () => {
+ const before = assignShards(names, timings, 3);
+ const after = assignShards([...names, 'tests/new.test.js'], timings, 3);
+ assert.equal(after.size, names.length + 1);
+ for (const name of names) assert.equal(after.get(name), before.get(name));
+ assert.ok(after.get('tests/new.test.js') >= 0 && after.get('tests/new.test.js') < 3);
+});
diff --git a/tests/support/agent-bake-rooms.mjs b/tests/support/agent-bake-rooms.mjs
new file mode 100644
index 00000000..e0ac7c74
--- /dev/null
+++ b/tests/support/agent-bake-rooms.mjs
@@ -0,0 +1,62 @@
+// Rooms shared by the agent-bake test files.
+
+export function closedRoom(extra = {}) {
+ const box = (id, translation, scale, material) => ({ id, geometry: 'box', material, translation, scale });
+ return {
+ format: '67js.scene', schemaVersion: 1,
+ geometries: [{ id: 'box', type: 'box' }],
+ materials: [
+ { id: 'white', color: [0.8, 0.8, 0.8], roughness: 0.9 },
+ { id: 'lamp', color: [1, 1, 1], emission: 2 },
+ ],
+ nodes: [
+ box('floor', [0, -0.05, 0], [4, 0.1, 4], 'white'),
+ box('ceiling', [0, 3.05, 0], [4, 0.1, 4], 'white'),
+ box('back', [0, 1.5, -2.05], [4.2, 3.2, 0.1], 'white'),
+ box('front', [0, 1.5, 2.05], [4.2, 3.2, 0.1], 'white'),
+ box('left', [-2.05, 1.5, 0], [0.1, 3.2, 4.2], 'white'),
+ box('right', [2.05, 1.5, 0], [0.1, 3.2, 4.2], 'white'),
+ box('block', [-0.7, 0.6, -0.4], [1.2, 1.2, 1.2], 'white'),
+ box('bulb', [0.9, 2.5, 0.6], [0.2, 0.2, 0.2], 'lamp'),
+ ],
+ camera: { eye: [0, 1.5, 1.9], target: [0, 1.4, -2], fov: 70, near: 0.05, far: 20 },
+ environment: { pointLights: [{ position: [0, 2.7, 0], intensity: 14, radius: 0.1 }], keyIntensity: 0, fillIntensity: 0 },
+ bake: { preset: 'draft' },
+ ...extra,
+ };
+}
+
+export function closedRoomWithoutBake() {
+ const { bake, ...recipe } = closedRoom();
+ return recipe;
+}
+
+export function lightmapBytes(part) {
+ return Buffer.from(part.material.emissiveMap.image.data ?? part.material.emissiveMap.image.bytes);
+}
+
+export function roomLitBy(environment) {
+ return closedRoom({ environment: { ...environment, keyIntensity: 0, fillIntensity: 0 } });
+}
+
+export function lightmapBytesOf(scene, name) {
+ return lightmapBytes(scene.parts.find(part => part.name === name));
+}
+
+export function largeRoom(bake) {
+ const recipe = closedRoom({ bake });
+ recipe.environment.spotLights = [{ position: [0, 2.8, 0], direction: [0, -1, 0], angle: 1, intensity: 20 }];
+ for (let index = 0; index < 48; index++) {
+ const column = index % 8;
+ const row = Math.floor(index / 8);
+ recipe.nodes.push({ id: `crate-${index}`, geometry: 'box', material: 'white', translation: [-1.75 + column * 0.5, 0.3, -1.7 + row * 0.6], scale: [0.4, 0.6, 0.4] });
+ }
+ return recipe;
+}
+
+export function clothRoom() {
+ const recipe = closedRoom({ cloth: { duration: 2, sheets: [{ node: 'flag', pin: ['top'] }] } });
+ recipe.geometries.push({ id: 'sheet', type: 'grid', segments: 8 });
+ recipe.nodes.push({ id: 'flag', geometry: 'sheet', material: 'white', translation: [0.5, 2, 0], scale: [1, 1, 1] });
+ return recipe;
+}