3D engine that AI agents drive
Prove kernels run on the worker in Chrome and measure the main thread
Nguyen Xuan Anf9889702b4c6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex da74e028..1b6395b4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,7 +2,7 @@## Unreleased-- Run the heavy scene kernels on a worker in the MCP preview (part of issue #38; the Chrome long-task measurement and the live edit path are not done). The light bake, the cloth solver, `uv_unwrap` and pattern textures are pure functions of their input, so `runKernel` in the new `src/kernel-offload.js` computes them inline as before, or, inside `buildWithKernels`, throws `KernelDeferred`, lets a module worker (`kernel-worker.js`, a package entry like the path tracer's) compute the result, caches it by a hash of the input bytes and runs the synchronous build again. The preview builds `scene_create` that way when the page has `Worker`; Node and every other caller keep the synchronous path and the same bytes (a test builds one scene cold in a separate process both ways and compares a digest of geometry, textures and the bake report). A worker error comes back with its class and message, a worker that cannot start or dies leaves the job to the inline path, and an `AbortSignal` ends the build and the worker. Measured in Node on the demo recipe: the `uv_unwrap` stack takes 3.6 s, the draft light bake 7.5 s and the standard bake passes the 20 s limit on this machine, cloth at the 10 s limit takes 3.4 s, a 1024 pattern takes 1 to 7 s, a boolean 0.12 s. Total build time does not fall (the kernels run one after another); the page stays free. `scene_apply` edits still run on the main thread. Core did not grow (`entry:core`, `lit-box` unchanged); the lazy entries rose by about 900 bytes gzip.+- Run the heavy scene kernels on a worker in the MCP preview (part of issue #38; edits after creation still run on the main thread). The light bake, the cloth solver, `uv_unwrap` and pattern textures are pure functions of their input, so `runKernel` in the new `src/kernel-offload.js` computes them inline as before, or, inside `buildWithKernels`, throws `KernelDeferred`, lets a module worker (`kernel-worker.js`, a package entry like the path tracer's) compute the result, caches it by a hash of the input bytes and runs the synchronous build again. The preview builds `scene_create` that way when the page has `Worker`; Node and every other caller keep the synchronous path and the same bytes (a test builds one scene cold in a separate process both ways and compares a digest of geometry, textures and the bake report). A worker error comes back with its class and message, a worker that cannot start or dies leaves the job to the inline path, and an `AbortSignal` ends the build and the worker. Measured in Node on the demo recipe: the `uv_unwrap` stack takes 3.6 s, the draft light bake 7.5 s and the standard bake passes the 20 s limit on this machine, cloth at the 10 s limit takes 3.4 s, a 1024 pattern takes 1 to 7 s, a boolean 0.12 s. Measured in headless Chrome on the GPU backend with the demo room recipe (`tests/fixtures/demo-room.recipe.json`, 9 kernels): the longest stretch the page was unresponsive during `scene_create` fell from 11.8 and 11.9 s to 1.6 s with workers (two runs each), while the build took 12.3 and 12.5 s instead of 10.9 and 11.0 s, because the kernels run one after another and the build reruns after each. `scene_inspect` now reports `kernels`: how many kernels a worker served and how many ran inline, each fallback with its reason (also a `67js kernel fallback` line on stderr when a page that has `Worker` falls back), the build time and the longest block; `npm run smoke:kernel-workers` installs the package, runs the demo room and fails unless kernels ran on the worker with no fallback. The `longtask` observer saw nothing in either mode because the browser does not count work run by a remote-debugging call, so the block is measured with a 20 ms timer. `scene_apply` edits still run on the main thread. Core did not grow (`entry:core`, `lit-box` unchanged); the lazy entries rose by about 900 bytes gzip.- Add ragdolls (part of issue #96): `physics.ragdoll` in a recipe with armatures and `physics` in an asset recipe (`set-physics`) bind a capsule body to every bone or joint and play the fall back as the pose of those bones, the same bytes for the same seek. New `src/ragdoll.js`, loaded with the physics code only. New suite task `robot-ragdoll`. The lazy budgets of `agent-scene+lazy` and `agent-asset+lazy` rise by 100 and 800 bytes gzip for it; the core entries did not grow from this. Joints have no swing limits yet.- Add terrain holes and a recipe `terrain` geometry (part of issue #64; layers beyond four and the navmesh are not built). `createTerrain({ holes: [{ center: [x, z], radius }] })` leaves no surface where a cell centre is inside a circle, and `terrain.isHole(x, z)` answers for a point; without `holes` the seeded meshes are byte-identical (a digest test). A recipe geometry `{ type: "terrain", size, resolution, seed, amplitude, holes }` builds one seeded ground mesh with the same holes; it loads on demand through the new `terrain` module (core did not grow), the tool schema entry is one line with the fields in `scene_capabilities` `terrain`, and the schema total budget did not change (scene_create and scene_apply rose by a few hundred bytes, mesh_edit fell by the same amount). New suite task `terrain-hole-walk` (ground with a 3 m opening and a walker that has to go around it) with the checks `groundRelief` and `walkPath`. Measured: Haiku passed it 2 of 2 (9 and 6 tool calls, $0.29 in all) and both exported recipes used the `terrain` geometry; there was no control run without the feature, so this shows agents find it, not how many could do without.- Bake patterned, textured and emissive parts, and skip hair hosts (part of issue #128). A recipe `bake` used to skip every part with a pattern, a map or emission (31 parts, the floor and every wall, in the demo room) and failed `scene_create` with "Textured geometry requires UV channel 0" on a node that hosts hair. Those parts now keep `uvs` and their look and take the bounced light through a new `lightMap` material slot on a second UV set (`geometry.lightUvs`); the fragment shader adds `color * (1 - metallic) * lightMap * lightMapScale`, so a brick pattern tints its own bounced light. Hair and particle host nodes are skipped and listed in `report.skipped`. The shader branch compiles out of scenes with no light map; the renderer carries about 650 bytes of gzip for it in `entry:core` (see `docs/light-bake.md` for the measured sizes). GLB export writes `TEXCOORD_1` and the light map as the emissive texture (an approximation: glTF has no light map slot). The path tracer ignores baked maps by design. New reference scene `brick-room` (a recipe-built closed brick room).diff --git a/docs/parity.md b/docs/parity.mdindex 543b8de2..7d0a5dc7 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -240,7 +240,7 @@ The goal also needs this work, and no page in the Blender manual covers it.| --- | --- | --- | --- || Parity evidence | partial | This ledger exists. The Blender comparisons do not. | #24, #25, #26 || Bundle size | partial | `npm run size` checks a budget for each entry, and the package has a 1 MiB limit. three.js is gone from the library; only the benchmark page imports it. | #27, #33, #34, #35, #36 |-| Runtime speed | partial | `bench/runtime` compares 8 scenes, and three.js wins most of the 7 older ones. Frustum culling per part and per instance group is on by default, `lods` from `generateGeometryLods` pick a level per instance by pixel error (`docs/culling-lod.md`), and `createGpuTimer` plus `createAdaptiveResolution` give live viewers GPU timing and a bounded resolution scale. On `large-outdoor` 67js is 1.55 ms against 6.0 ms for three.js on an RTX 3060. Part of #37: recipes have no way to declare `lods` yet and shadow passes are not culled. Part of #38: the MCP preview builds `scene_create` with the light bake, cloth, `uv_unwrap` and pattern kernels on a worker (`src/kernel-offload.js`); `scene_apply` edits, the browser site and the Chrome long-task measurement are not done. | #28, #37, #38, #74 |+| Runtime speed | partial | `bench/runtime` compares 8 scenes, and three.js wins most of the 7 older ones. Frustum culling per part and per instance group is on by default, `lods` from `generateGeometryLods` pick a level per instance by pixel error (`docs/culling-lod.md`), and `createGpuTimer` plus `createAdaptiveResolution` give live viewers GPU timing and a bounded resolution scale. On `large-outdoor` 67js is 1.55 ms against 6.0 ms for three.js on an RTX 3060. Part of #37: recipes have no way to declare `lods` yet and shadow passes are not culled. Part of #38: the MCP preview builds `scene_create` with the light bake, cloth, `uv_unwrap` and pattern kernels on a worker (`src/kernel-offload.js`); `scene_apply` edits, the browser site are not done. Measured in Chrome: longest unresponsive stretch of `scene_create` on the demo room 11.8 s to 1.6 s, build time 10.9 s to 12.4 s. | #28, #37, #38, #74 || Agent measurement | partial | A task suite runs on one model and reads recipes only. | #29, #30, #31, #69 || Pull request checks | partial | The `Test` workflow reports a status and does not block a merge. | #32 || Relations between parts | partial | The agent version of snapping: node `relations` (`attach`, `gap`, `flush`, `align`, `centered`) over world bounds or a tagged region, solved again on every edit, cycles rejected. Tests in [part-relations](../tests/part-relations.test.js); suite tasks `kettle-resize` and `desk-resize` with plain twins (no gain in calls measured on Sonnet). No snapping to edges or vertices, no relation on the part's own tagged region. | #44 |diff --git a/package.json b/package.jsonindex b2cb18c6..513db24d 100644--- a/package.json+++ b/package.json@@ -100,6 +100,7 @@"mcp": "node bin/67js-mcp.mjs","smoke:mcp": "node scripts/smoke-mcp.mjs","smoke:mcp-package": "node scripts/smoke-mcp-package.mjs",+ "smoke:kernel-workers": "node scripts/smoke-kernel-workers.mjs","smoke:agent-topology": "node scripts/smoke-agent-topology.mjs","smoke:agent-look": "node scripts/smoke-agent-look.mjs","smoke:agent-assets": "node scripts/smoke-agent-assets.mjs",diff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex 07110c6b..ac3cae3f 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -1,4 +1,4 @@-import { buildWithKernels, kernelWorkersAvailable } from '../src/kernel-offload.js';+import { buildWithKernels, kernelWorkersAvailable, kernelStats, resetKernelStats } from '../src/kernel-offload.js';import { createAgentScene, loadAllAgentSceneModules, allAgentSceneModulesLoaded, needsMeshBooleans, loadMeshBooleans, meshBooleansLoaded, setManifoldModuleLoader, needsPhysics, loadPhysicsEngine, physicsEngineLoaded, setPhysicsModuleLoader } from '../src/agent-scene.js';import { Renderer67 } from '../src/renderer.js';import { installCameraEffects } from '../src/camera-effects.js';@@ -244,6 +244,53 @@ function afterMeshBooleans(value, run) {// Heavy kernels (light bake, cloth, uv_unwrap, pattern textures) compute on a worker while the page stays responsive;// the scene is built from the same bytes as on one thread. Reading each part's maps here makes pattern bakes run in the// same pass, so the renderer later finds them baked.+// Where the work ran, for scene_inspect: kernels served by the worker and run inline (with the reason for any+// fallback), the time of the last scene build, and the longest main-thread task the browser reported since then.+// Long tasks are those over 50 ms, so 0 means none that long.+const longTaskObserver = typeof PerformanceObserver === 'function' && PerformanceObserver.supportedEntryTypes?.includes('longtask')+ ? new PerformanceObserver(() => {})+ : null;+longTaskObserver?.observe({ type: 'longtask' });+const buildReport = { buildMilliseconds: 0, longestBlockMilliseconds: 0, longestLongTaskMilliseconds: 0, longTasks: 0 };++// The long task API skips work run by a remote-debugging call, so a timer also measures how long the page stayed+// unresponsive: the longest delay of a 20 ms tick is the longest stretch the main thread was busy.+const HEARTBEAT_MILLISECONDS = 20;+let lastHeartbeat = performance.now();+setInterval(() => {+ const now = performance.now();+ buildReport.longestBlockMilliseconds = Math.max(buildReport.longestBlockMilliseconds, Math.round(now - lastHeartbeat - HEARTBEAT_MILLISECONDS));+ lastHeartbeat = now;+}, HEARTBEAT_MILLISECONDS);++function drainLongTasks() {+ for (const entry of longTaskObserver?.takeRecords() ?? []) {+ buildReport.longTasks++;+ buildReport.longestLongTaskMilliseconds = Math.max(buildReport.longestLongTaskMilliseconds, Math.round(entry.duration));+ }+}++function startBuildReport() {+ drainLongTasks();+ Object.assign(buildReport, { buildMilliseconds: 0, longestBlockMilliseconds: 0, longestLongTaskMilliseconds: 0, longTasks: 0 });+ lastHeartbeat = performance.now();+ resetKernelStats();+}++function finishBuildReport(startedAt) {+ buildReport.buildMilliseconds = Math.round(performance.now() - startedAt);+}++function kernelReport() {+ drainLongTasks();+ return { ...kernelStats(), ...buildReport };+}++// The runtime can switch workers off (createAgentRuntime kernelWorkers: false) to measure what they buy.+function useKernelWorkers() {+ return kernelWorkersAvailable() && globalThis.__67jsKernelWorkers !== 'off';+}+function buildSceneOffMainThread(recipe) {return buildWithKernels(() => {const scene = createAgentScene(recipe);@@ -501,10 +548,17 @@ window.__agentPreview = {create(input) {if (active) throw new Error('Dispose the current scene before creating another.');return afterMeshBooleans(input.recipe, () => {- if (!kernelWorkersAvailable()) {- return createPreview(createAgentScene(input.recipe), input);+ startBuildReport();+ const startedAt = performance.now();+ if (!useKernelWorkers()) {+ const scene = createAgentScene(input.recipe);+ finishBuildReport(startedAt);+ return createPreview(scene, input);}- return buildSceneOffMainThread(input.recipe).then(scene => createPreview(scene, input));+ return buildSceneOffMainThread(input.recipe).then(scene => {+ finishBuildReport(startedAt);+ return createPreview(scene, input);+ });});},async createAsset(input) {@@ -529,7 +583,7 @@ window.__agentPreview = {}},inspect({ sessionId, ...options }) {- return { sessionId, ...requireSession(sessionId).scene.inspect(options) };+ return { sessionId, ...requireSession(sessionId).scene.inspect(options), kernels: kernelReport() };},inspectMeshes({ sessionId, ...options }) {const scene = requireSession(sessionId).scene;diff --git a/scripts/agent-runtime.mjs b/scripts/agent-runtime.mjsindex 45dbdfce..5aea0b2e 100644--- a/scripts/agent-runtime.mjs+++ b/scripts/agent-runtime.mjs@@ -44,7 +44,7 @@ const VENDOR_FILES = Object.freeze({'/vendor/rapier.js': { resolve: require => join(dirname(require.resolve('@dimforge/rapier3d-compat')), 'rapier.mjs'), type: 'application/javascript; charset=utf-8' },});-export function createAgentRuntime({ backend = 'gpu', browser: browserPath, memory = 192, assets: assetRoot,+export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', browser: browserPath, memory = 192, assets: assetRoot,jobs: jobRoot, ffmpeg = 'ffmpeg', audio: audioRoot,previewUrl = new URL(/* @vite-ignore */ '../build/mcp/preview.js', import.meta.url) } = {}) {if (!['gpu', 'cpu'].includes(backend)) {@@ -233,6 +233,13 @@ export function createAgentRuntime({ backend = 'gpu', browser: browserPath, memoreturn url.origin === origin ? route.continue() : route.abort();});page.setDefaultTimeout(15000);+ if (!kernelWorkers) {+ await page.addInitScript(() => { globalThis.__67jsKernelWorkers = 'off'; });+ }+ // A kernel that fell back to the main thread says so on the page console; keep that note in the server's stderr.+ page.on?.('console', message => {+ if (message.text().startsWith('67js kernel fallback')) console.error(message.text());+ });await page.goto(origin);await page.waitForFunction(() => Boolean(window.__agentPreview));phase = 'ready';diff --git a/scripts/smoke-kernel-workers.mjs b/scripts/smoke-kernel-workers.mjsnew file mode 100644index 00000000..2cb6086a--- /dev/null+++ b/scripts/smoke-kernel-workers.mjs@@ -0,0 +1,61 @@+import assert from 'node:assert/strict';+import { cp, mkdtemp, readFile, writeFile } from 'node:fs/promises';+import { spawnSync } from 'node:child_process';+import { constants, setPriority, tmpdir } from 'node:os';+import { resolve, dirname, join } from 'node:path';+import { performance } from 'node:perf_hooks';+import { Client } from '@modelcontextprotocol/client';+import { PatientStdioClientTransport } from './patient-stdio-transport.mjs';++// Proves the heavy scene kernels run on a worker in Chrome, from the installed package: the worker file ships and+// resolves, scene_create sends kernels to it, and none fell back to the main thread. A failing worker falls back+// silently, so the preview counts both (scene_inspect kernels) and this smoke reads the counts.+// Usage: node scripts/smoke-kernel-workers.mjs [--backend cpu|gpu] [recipe.json]++setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);+const backendIndex = process.argv.indexOf('--backend');+const backend = backendIndex === -1 ? 'gpu' : process.argv[backendIndex + 1];+const recipePath = process.argv.slice(2).find((argument, index, all) => argument.endsWith('.json') && all[index - 1] !== '--backend')+ ?? 'tests/fixtures/demo-room.recipe.json';+const recipe = JSON.parse(await readFile(recipePath, 'utf8'));+const metadata = JSON.parse(await readFile('package.json', 'utf8'));+const consumer = await mkdtemp(join(tmpdir(), '67js-kernel-consumer-'));+await writeFile(join(consumer, 'package.json'), JSON.stringify({ private: true, type: 'module' }));++const npmCli = process.env.npm_execpath ?? resolve(dirname(process.execPath), 'node_modules/npm/bin/npm-cli.js');+function npm(argumentsValue) {+ const result = spawnSync(process.execPath, [npmCli, ...argumentsValue], { cwd: consumer, windowsHide: true, encoding: 'utf8' });+ assert.equal(result.status, 0, result.stderr);+ return result.stdout;+}+const packResult = JSON.parse(npm(['pack', process.cwd(), '--ignore-scripts', '--json', '--pack-destination', consumer]));+const packed = Array.isArray(packResult) ? packResult[0] : packResult[metadata.name];+assert.ok(packed.files.some(file => file.path === 'build/kernel-worker.js'), 'The package must ship build/kernel-worker.js.');+const archive = join(consumer, packed.filename).replaceAll('\\', '/');+npm(['install', `67js@file:${archive}`, '--offline', '--omit=dev', '--ignore-scripts', '--no-audit', '--no-fund']);+// The demo recipe has boolean edits, which need the optional peer manifold-3d beside the package, as a user installs it.+await cp(resolve('node_modules/manifold-3d'), join(consumer, 'node_modules', 'manifold-3d'), { recursive: true });+const cli = join(consumer, 'node_modules', '67js', 'bin', '67js-mcp.mjs');++const transport = new PatientStdioClientTransport({ command: process.execPath, args: [cli, '--backend', backend, '--memory', '192'], cwd: consumer, stderr: 'pipe' });+let diagnostics = '';+transport.stderr.on('data', chunk => { diagnostics += chunk.toString(); });+const client = new Client({ name: '67js-kernel-worker-proof', version: '1' }, { versionNegotiation: { mode: 'legacy', probe: { timeoutMs: 180000 } } });+try {+ await client.connect(transport, { timeout: 180000 });+ const startedAt = performance.now();+ const created = await client.callTool({ name: 'scene_create', arguments: { recipe } }, { timeout: 280000 });+ assert.equal(created.isError, undefined, created.content?.find(item => item.type === 'text')?.text);+ const createMilliseconds = Math.round(performance.now() - startedAt);+ const sessionId = created.structuredContent.sessionId;+ const inspected = await client.callTool({ name: 'scene_inspect', arguments: { sessionId } }, { timeout: 60000 });+ const { kernels } = inspected.structuredContent;+ assert.ok(kernels, 'scene_inspect must report kernels.');+ assert.ok(kernels.worker > 0, `Kernels must run on the worker; counts: ${JSON.stringify(kernels)}`);+ assert.deepEqual(kernels.fallbacks, [], `No kernel may fall back to the main thread: ${JSON.stringify(kernels.fallbacks)}`);+ assert.doesNotMatch(diagnostics, /kernel fallback/);+ await client.callTool({ name: 'scene_dispose', arguments: { sessionId } }, { timeout: 60000 });+ console.log(JSON.stringify({ backend, createMilliseconds, kernels }));+} finally {+ await client.close();+}diff --git a/src/kernel-offload.js b/src/kernel-offload.jsindex 246be83b..5c997d20 100644--- a/src/kernel-offload.js+++ b/src/kernel-offload.js@@ -18,6 +18,37 @@ const RECONSTRUCTED_ERRORS = { RangeError, TypeError, SyntaxError, ReferenceErroconst MAXIMUM_DEFERRALS = 256;let activeSession = null;+let workerStartFailure = null;++// What ran where, since the last reset: a kernel served by a worker, a kernel computed inline, and why a kernel that+// should have gone to a worker did not. A silent fallback would otherwise look the same as success.+const MAXIMUM_RECORDED_FALLBACKS = 16;+const statistics = { worker: 0, inline: 0, fallbacks: [] };++/** Counts of kernels served by a worker and run inline, with the reason for each fallback. */+export function kernelStats() {+ return { worker: statistics.worker, inline: statistics.inline, fallbacks: statistics.fallbacks.map(fallback => ({ ...fallback })) };+}++export function resetKernelStats() {+ statistics.worker = 0;+ statistics.inline = 0;+ statistics.fallbacks = [];+}++function recordFallback(kernel, reason) {+ if (statistics.fallbacks.length < MAXIMUM_RECORDED_FALLBACKS) {+ statistics.fallbacks.push({ kernel, reason });+ }+ if (kernelWorkersAvailable()) {+ console.warn(`67js kernel fallback: ${kernel} ran inline (${reason}).`);+ }+}++function computeInline(compute, args) {+ statistics.inline++;+ return compute(...args);+}/** Thrown by `runKernel` inside a session when a kernel's result has to be computed on the worker first. */export class KernelDeferred {@@ -68,6 +99,11 @@ function mixValue(hasher, value) {mixBytes(hasher, new Uint8Array(value.buffer, value.byteOffset, value.byteLength));return true;}+ // Browsers hold pattern textures as ImageData, which a worker clones as it is.+ if (typeof ImageData === 'function' && value instanceof ImageData) {+ mixText(hasher, `ImageData:${value.width}x${value.height}:${value.colorSpace};`);+ return mixValue(hasher, value.data);+ }if (Array.isArray(value)) {mixText(hasher, `[${value.length}:`);return value.every(item => mixValue(hasher, item));@@ -97,11 +133,15 @@ export function kernelKey(name, args) {*/export function runKernel(name, args, compute) {if (!activeSession) {- return compute(...args);+ return computeInline(compute, args);}const key = kernelKey(name, args);- if (key === null || activeSession.inlineAll || activeSession.inlineKeys.has(key)) {- return compute(...args);+ if (key === null) {+ recordFallback(name, 'its input is not plain data');+ return computeInline(compute, args);+ }+ if (activeSession.inlineAll || activeSession.inlineKeys.has(key)) {+ return computeInline(compute, args);}if (activeSession.results.has(key)) {const entry = activeSession.results.get(key);@@ -183,7 +223,10 @@ export async function buildWithKernels(build, { createWorker = defaultWorkerFactactiveSession = null;session.deferrals++;// A build whose inputs change on every run would never find its cached result; computing inline ends the loop.- session.inlineAll = session.deferrals > MAXIMUM_DEFERRALS;+ if (session.deferrals > MAXIMUM_DEFERRALS && !session.inlineAll) {+ session.inlineAll = true;+ recordFallback(error.job.name, 'the build asked for more kernels than any scene holds');+ }worker ??= createWorkerOrNull(createWorker);await computeOnWorker(session, worker, error.job, signal);} finally {@@ -198,7 +241,8 @@ export async function buildWithKernels(build, { createWorker = defaultWorkerFactfunction createWorkerOrNull(createWorker) {try {return createWorker();- } catch {+ } catch (error) {+ workerStartFailure = error.message;return null;}}@@ -208,6 +252,7 @@ function createWorkerOrNull(createWorker) {async function computeOnWorker(session, worker, job, signal) {if (!worker) {session.inlineKeys.add(job.key);+ recordFallback(job.name, `the worker could not start: ${workerStartFailure}`);return;}let answer;@@ -218,7 +263,9 @@ async function computeOnWorker(session, worker, job, signal) {throw error;}session.inlineKeys.add(job.key);+ recordFallback(job.name, `the worker failed: ${error.message}`);return;}+ statistics.worker++;session.results.set(job.key, answer.error ? { thrown: rebuildError(answer.error) } : { value: answer.value });}diff --git a/tests/fixtures/demo-room.recipe.json b/tests/fixtures/demo-room.recipe.jsonnew file mode 100644index 00000000..3a9a4079--- /dev/null+++ b/tests/fixtures/demo-room.recipe.json@@ -0,0 +1 @@+{"format":"67js.scene","schemaVersion":1,"geometries":[{"id":"box","type":"box","bevel":0.02},{"id":"sharp-box","type":"box","bevel":0},{"id":"ball","type":"sphere","segments":32,"rings":20},{"id":"lowball","type":"sphere","segments":10,"rings":6},{"id":"speck","type":"sphere","segments":6,"rings":4},{"id":"strand","type":"box","bevel":0},{"id":"rod","type":"cylinder","segments":32},{"id":"banner","type":"grid","segments":32},{"id":"sign-text","type":"text","text":"67js","size":1.5,"depth":0.18,"align":"center","curveSegments":10},{"id":"neon","type":"curve","radius":0.04,"resolution":20,"radialSegments":12,"points":[[3.1,0.64,-2.84],[3.3,1.1,-2.86],[2.95,1.8,-2.86],[2.4,2.3,-2.86],[2.1,2.55,-2.85],[1.95,2.62,-2.85]]},{"id":"column","type":"mesh","base":{"type":"extrude","depth":1.2,"steps":40,"bevel":0,"contour":[[0.1,0.26],[-0.1,0.26],[-0.1,0.1],[-0.26,0.1],[-0.26,-0.1],[-0.1,-0.1],[-0.1,-0.26],[0.1,-0.26],[0.1,-0.1],[0.26,-0.1],[0.26,0.1],[0.1,0.1]]},"stack":[{"op":"simple_deform","mode":"twist","axis":"z","angle":200}]},{"id":"cushion","type":"mesh","base":{"type":"box","bevel":0},"stack":[{"op":"subdivide","levels":3}]},{"id":"organiser","type":"mesh","base":{"type":"box","bevel":0.03},"edits":[{"op":"boolean","operation":"difference","name":"porthole","cutter":{"type":"cylinder","segments":40},"scale":[0.3,2,0.3],"rotation":[0.70710678,0,0,0.70710678]}]}],"materials":[{"id":"bricks","color":[1,1,1],"roughness":1,"pattern":{"type":"bricks","size":1.5,"count":6,"bump":1.8,"seed":4,"colors":[[0.08,0.03,0.025],[0.3,0.11,0.07],[0.2,0.17,0.15]]}},{"id":"plaster","color":[0.15,0.55,0.75],"roughness":1,"pattern":{"type":"concrete","size":2,"bump":0.5,"seed":9}},{"id":"floorwood","color":[1,1,1],"roughness":0.55,"pattern":{"type":"planks","size":1.3,"count":5,"bump":0.9,"seed":3,"colors":[[0.05,0.03,0.02],[0.2,0.11,0.065]]}},{"id":"beamwood","color":[0.8,0.7,0.65],"roughness":0.85,"pattern":{"type":"wood","size":0.7,"bump":0.5,"axis":"x"}},{"id":"benchwood","color":[1,1,1],"roughness":0.7,"pattern":{"type":"planks","size":0.9,"count":4,"bump":0.8,"seed":8,"colors":[[0.14,0.07,0.035],[0.4,0.21,0.1]]}},{"id":"board","color":[0.025,0.035,0.07],"roughness":0.55},{"id":"gold","color":[1,0.68,0.2],"metallic":1,"roughness":0.28,"emission":0.2,"emissiveColor":[1,0.55,0.1]},{"id":"brass","color":[0.65,0.45,0.2],"metallic":1,"roughness":0.4},{"id":"neon","color":[0.1,0.9,1],"emission":3.5,"emissiveColor":[0.1,0.85,1]},{"id":"plug","color":[0.03,0.03,0.035],"roughness":0.35},{"id":"steel","color":[0.38,0.4,0.45],"metallic":1,"roughness":0.32},{"id":"iron","color":[0.1,0.1,0.12],"metallic":1,"roughness":0.5},{"id":"stump","color":[0.7,0.55,0.45],"roughness":0.9,"pattern":{"type":"wood","size":0.5,"bump":0.7,"axis":"y"}},{"id":"rug","color":[0.42,0.45,0.45],"roughness":1,"pattern":{"type":"fabric","size":0.25,"bump":0.7,"colors":[[0.04,0.12,0.14],[0.55,0.3,0.08]]}},{"id":"plum","color":[0.4,0.07,0.2],"roughness":0.95},{"id":"teal","color":[0.03,0.4,0.38],"metallic":0.3,"roughness":0.3},{"id":"cloth","color":[0.55,0.5,0.5],"roughness":0.95,"doubleSided":true,"pattern":{"type":"fabric","size":0.18,"bump":0.9,"colors":[[0.25,0.02,0.04],[0.7,0.12,0.08]]}},{"id":"beachball","color":[0.9,0.62,0.1],"roughness":0.4},{"id":"glass","color":[0.85,0.95,1],"roughness":0.02,"transmission":1,"thickness":0.2,"ior":1.5},{"id":"ember","color":[1,0.55,0.12],"emission":6,"emissiveColor":[1,0.5,0.1]},{"id":"fur","color":[0.85,0.5,0.22],"roughness":1},{"id":"fur-tips","color":[0.95,0.72,0.42],"roughness":1},{"id":"furbase","color":[0.55,0.3,0.14],"roughness":1},{"id":"white","color":[0.9,0.9,0.88],"roughness":0.25},{"id":"black","color":[0.015,0.015,0.02],"roughness":0.15},{"id":"window","color":[0.05,0.15,0.5],"emission":0.9,"emissiveColor":[0.12,0.3,1]},{"id":"bulb","color":[1,0.8,0.5],"emission":6,"emissiveColor":[1,0.75,0.4]},{"id":"shade","color":[0.1,0.3,0.28],"roughness":0.5,"metallic":0.5},{"id":"ground","color":[0.03,0.025,0.035],"roughness":1},{"id":"plaster-warm","color":[0.85,0.32,0.14],"roughness":1,"pattern":{"type":"concrete","size":2,"bump":0.5,"seed":9}}],"nodes":[{"id":"floor","geometry":"box","material":"floorwood","translation":[0,-0.1,0.2],"scale":[9,0.2,6.2]},{"id":"ground","geometry":"sharp-box","material":"ground","translation":[0,-0.7,0],"scale":[60,1,60]},{"id":"back-wall","geometry":"sharp-box","material":"bricks","translation":[0,1.95,-3],"scale":[9.4,3.9,0.2]},{"id":"left-wall","geometry":"sharp-box","material":"plaster","translation":[-4.6,1.95,0.2],"scale":[0.2,3.9,6.2]},{"id":"right-wall","geometry":"sharp-box","material":"plaster-warm","translation":[4.6,1.95,0.2],"scale":[0.2,3.9,6.2]},{"id":"ceiling","geometry":"sharp-box","material":"beamwood","translation":[0,3.95,0.2],"scale":[9.4,0.1,6.2]},{"id":"beam-back","geometry":"box","material":"beamwood","translation":[0,3.72,-2.3],"scale":[9,0.24,0.3]},{"id":"beam-middle","geometry":"box","material":"beamwood","translation":[0,3.72,-0.4],"scale":[9,0.24,0.3]},{"id":"beam-front","geometry":"box","material":"beamwood","translation":[0,3.72,1.6],"scale":[9,0.24,0.3]},{"id":"window-pane","geometry":"sharp-box","material":"window","translation":[-4.47,2.3,-0.7],"scale":[0.03,1.3,1.1]},{"id":"window-top","geometry":"box","material":"beamwood","translation":[-4.44,2.98,-0.7],"scale":[0.1,0.1,1.3]},{"id":"window-bottom","geometry":"box","material":"beamwood","translation":[-4.44,1.62,-0.7],"scale":[0.14,0.1,1.3]},{"id":"window-left","geometry":"box","material":"beamwood","translation":[-4.44,2.3,-1.3],"scale":[0.1,1.4,0.1]},{"id":"window-right","geometry":"box","material":"beamwood","translation":[-4.44,2.3,-0.1],"scale":[0.1,1.4,0.1]},{"id":"window-bar","geometry":"box","material":"beamwood","translation":[-4.44,2.3,-0.7],"scale":[0.08,1.3,0.06]},{"id":"sign-frame","geometry":"box","material":"brass","translation":[0,2.75,-2.88],"scale":[4,2.1,0.08]},{"id":"sign-board","geometry":"box","material":"board","translation":[0,2.75,-2.84],"scale":[3.8,1.9,0.1]},{"id":"sign","geometry":"sign-text","material":"gold","translation":[0,2.34,-2.7]},{"id":"socket","geometry":"box","material":"iron","translation":[3.1,0.5,-2.86],"scale":[0.22,0.22,0.06]},{"id":"plug","geometry":"box","material":"plug","translation":[3.1,0.6,-2.82],"scale":[0.1,0.16,0.08]},{"id":"neon","geometry":"neon","material":"neon"},{"id":"bench-top","geometry":"box","material":"benchwood","translation":[0,0.85,-2.35],"scale":[3.6,0.1,1]},{"id":"bench-shelf","geometry":"box","material":"benchwood","translation":[0,0.3,-2.35],"scale":[3.3,0.06,0.8]},{"id":"leg-1","geometry":"box","material":"benchwood","translation":[-1.7,0.4,-1.95],"scale":[0.12,0.8,0.12]},{"id":"leg-2","geometry":"box","material":"benchwood","translation":[1.7,0.4,-1.95],"scale":[0.12,0.8,0.12]},{"id":"leg-3","geometry":"box","material":"benchwood","translation":[-1.7,0.4,-2.75],"scale":[0.12,0.8,0.12]},{"id":"leg-4","geometry":"box","material":"benchwood","translation":[1.7,0.4,-2.75],"scale":[0.12,0.8,0.12]},{"id":"cushion","geometry":"cushion","material":"plum","translation":[0,1.03,-2.3],"scale":[0.95,0.32,0.8]},{"id":"creature","geometry":"ball","material":"furbase","translation":[0,1.36,-2.3],"scale":[0.3,0.29,0.3]},{"id":"fur","geometry":"strand","material":"fur"},{"id":"fur-tips","geometry":"strand","material":"fur-tips"},{"id":"eye-left","geometry":"ball","material":"white","translation":[-0.1,1.42,-2.03],"scale":[0.075,0.075,0.075]},{"id":"eye-right","geometry":"ball","material":"white","translation":[0.1,1.42,-2.03],"scale":[0.075,0.075,0.075]},{"id":"pupil-left","geometry":"lowball","material":"black","translation":[-0.1,1.42,-1.96],"scale":[0.04,0.04,0.04]},{"id":"pupil-right","geometry":"lowball","material":"black","translation":[0.1,1.42,-1.96],"scale":[0.04,0.04,0.04]},{"id":"organiser","geometry":"organiser","material":"benchwood","translation":[1.2,1.1,-2.35],"scale":[0.4,0.4,0.4]},{"id":"bench-marble","geometry":"ball","material":"glass","translation":[1.65,1,-2.2],"scale":[0.1,0.1,0.1]},{"id":"lamp-base","geometry":"rod","material":"iron","translation":[-1.3,0.93,-2.3],"scale":[0.14,0.04,0.14]},{"id":"lamp-arm","geometry":"rod","material":"iron","translation":[-1.3,1.17,-2.3],"scale":[0.015,0.45,0.015]},{"id":"lamp-shade","geometry":"ball","material":"shade","translation":[-1.3,1.42,-2.3],"scale":[0.15,0.09,0.15]},{"id":"lamp-bulb","geometry":"ball","material":"bulb","translation":[-1.3,1.34,-2.3],"scale":[0.06,0.06,0.06]},{"id":"column","geometry":"column","material":"teal","translation":[-2.8,0,-2.3],"scale":[1,1,1],"rotation":[-0.70710678,0,0,0.70710678]},{"id":"column-marble","geometry":"ball","material":"glass","translation":[-2.8,1.33,-2.3],"scale":[0.13,0.13,0.13]},{"id":"pole","geometry":"rod","material":"brass","translation":[-3.35,3.32,-2.72],"scale":[0.035,1.5,0.035],"rotation":[0,0,0.70710678,0.70710678]},{"id":"pole-end-left","geometry":"ball","material":"brass","translation":[-4.1,3.32,-2.72],"scale":[0.06,0.06,0.06]},{"id":"pole-end-right","geometry":"ball","material":"brass","translation":[-2.6,3.32,-2.72],"scale":[0.06,0.06,0.06]},{"id":"banner","geometry":"banner","material":"cloth","translation":[-3.35,1.97,-2.7],"scale":[1.3,2.7,1]},{"id":"banner-ball","geometry":"ball","material":"beachball","translation":[-3.35,0.35,-2.58],"scale":[0.35,0.35,0.35]},{"id":"stump","geometry":"rod","material":"stump","translation":[2,0.22,-0.8],"scale":[0.36,0.44,0.36]},{"id":"anvil-waist","geometry":"box","material":"iron","translation":[2,0.52,-0.8],"scale":[0.2,0.16,0.16]},{"id":"anvil-top","geometry":"box","material":"steel","translation":[2,0.65,-0.8],"scale":[0.56,0.1,0.26]},{"id":"sparks","geometry":"speck","material":"ember"},{"id":"rug","geometry":"sharp-box","material":"rug","translation":[0.1,0.012,-0.6],"scale":[3.8,0.024,2.6]},{"id":"pendant","translation":[2.7,3.6,-1.4]},{"id":"pendant-cord","geometry":"rod","material":"iron","translation":[0,-0.4,0],"scale":[0.012,0.8,0.012],"parent":"pendant"},{"id":"pendant-shade","geometry":"ball","material":"shade","translation":[0,-0.9,0],"scale":[0.28,0.2,0.28],"parent":"pendant"},{"id":"pendant-bulb","geometry":"ball","material":"bulb","translation":[0,-0.95,0],"scale":[0.1,0.1,0.1],"parent":"pendant"}],"camera":{"eye":[1.4,2.1,7],"target":[0,1.6,-2],"fov":50},"environment":{"setup":"sunset","environmentIntensity":0.08,"keyIntensity":0.35,"keyColor":[1,0.6,0.35],"fillIntensity":0.03,"lightDirection":[0.4,0.7,0.9],"fogDensity":0,"pointLights":[{"position":[2.7,2.65,-1.4],"color":[1,0.72,0.4],"intensity":14,"radius":0.1,"range":7},{"position":[-1.3,1.3,-2.2],"color":[1,0.7,0.4],"intensity":4,"radius":0.08,"range":4},{"position":[2,1,-0.7],"color":[1,0.5,0.15],"intensity":6,"radius":0.1,"range":3.5},{"position":[2.6,1.5,-2.5],"color":[0.1,0.8,1],"intensity":3.5,"radius":0.1,"range":3.5},{"position":[3.1,0.8,-2.4],"color":[0.1,0.8,1],"intensity":1.5,"radius":0.05,"range":1.6},{"position":[-3.9,2.3,-0.7],"color":[0.45,0.62,1],"intensity":7,"radius":0.25,"range":8}],"spotLights":[{"position":[1.6,3.4,3],"direction":[-1.5,-2,-5.3],"angle":0.5,"penumbra":0.7,"color":[1,0.72,0.45],"intensity":120,"castShadow":true},{"position":[0.2,3.55,-0.6],"direction":[0,-0.5,-1],"angle":0.55,"penumbra":0.7,"color":[1,0.78,0.5],"intensity":28},{"position":[4,2.4,2.6],"direction":[-1,-0.35,-1],"angle":0.7,"penumbra":0.8,"color":[0.4,0.55,1],"intensity":30}],"areaLights":[{"position":[-4.2,2.3,-0.7],"direction":[1,-0.1,0.1],"up":[0,1,0],"width":1.1,"height":1.3,"color":[0.4,0.55,1],"intensity":45}]},"effects":{"exposure":1,"saturation":0.9,"contrast":1.1,"vignette":0.3,"ambientOcclusion":0.6,"ambientOcclusionRadius":0.7,"bloom":{"strength":0.15,"threshold":1,"radius":0.5}},"shadow":{"target":[0,1.2,-1.2],"extent":5,"distance":9,"far":20},"particles":{"wind":[0.3,0,0],"systems":[{"node":"sparks","seed":7,"count":1100,"rate":100,"lifetime":[1,1.9],"speed":[1.6,3.2],"spread":42,"size":0.03,"drag":0.25,"floor":0,"scale":"shrink","emitter":{"shape":"disc","position":[2,0.74,-0.8],"radius":0.06}},{"type":"hair","node":"fur","surface":"creature","seed":5,"count":1900,"length":[0.05,0.1],"segments":4,"width":0.012,"droop":0.6,"lean":0.2,"sway":0.02,"swayRate":0.6},{"type":"hair","node":"fur-tips","surface":"creature","seed":11,"count":1000,"length":[0.07,0.12],"segments":4,"width":0.01,"droop":0.7,"lean":0.25,"sway":0.025,"swayRate":0.5}]},"motion":{"duration":12,"loop":false,"tracks":[{"kind":"camera","property":"eye","interpolation":"LINEAR","keyframes":[{"time":0,"value":[1.4,2.1,7]},{"time":4.39,"value":[0.5,1.95,5.5]},{"time":4.4,"value":[-1.5,1.7,2.2]},{"time":7.99,"value":[0.2,1.75,1.7]},{"time":8,"value":[3.9,0.35,2.8]},{"time":12,"value":[3,0.42,2]}]},{"kind":"camera","property":"target","interpolation":"LINEAR","keyframes":[{"time":0,"value":[0,1.6,-2]},{"time":4.39,"value":[0,1.7,-2]},{"time":4.4,"value":[0.2,1.8,-2.5]},{"time":7.99,"value":[0.1,1.9,-2.5]},{"time":8,"value":[0.3,1.5,-2.3]},{"time":12,"value":[0.1,1.55,-2.3]}]},{"kind":"camera","property":"fov","interpolation":"LINEAR","keyframes":[{"time":0,"value":50},{"time":4.39,"value":50},{"time":4.4,"value":42},{"time":7.99,"value":42},{"time":8,"value":55},{"time":12,"value":55}]},{"kind":"node","id":"pendant","property":"rotation","interpolation":"SMOOTH","keyframes":[{"time":0,"value":[0,0,0.02617694830787315,0.9996573249755573]},{"time":1.5,"value":[0,0,-0.02617694830787315,0.9996573249755573]},{"time":3,"value":[0,0,0.02617694830787315,0.9996573249755573]},{"time":4.5,"value":[0,0,-0.02617694830787315,0.9996573249755573]},{"time":6,"value":[0,0,0.02617694830787315,0.9996573249755573]},{"time":7.5,"value":[0,0,-0.02617694830787315,0.9996573249755573]},{"time":9,"value":[0,0,0.02617694830787315,0.9996573249755573]},{"time":10.5,"value":[0,0,-0.02617694830787315,0.9996573249755573]},{"time":12,"value":[0,0,0.02617694830787315,0.9996573249755573]}]}]},"timeline":{"shots":[{"name":"wide","duration":4.4},{"name":"sign-close","duration":3.6},{"name":"sparks-low","duration":4,"dip":0.9}]},"bake":{"preset":"draft","samples":96,"bounces":2,"texelsPerUnit":3}}\ No newline at end of filediff --git a/tests/support/preview-harness.mjs b/tests/support/preview-harness.mjsindex de1a8792..b869b69f 100644--- a/tests/support/preview-harness.mjs+++ b/tests/support/preview-harness.mjs@@ -68,6 +68,7 @@ export function previewHarness() {needsMeshBooleans, loadMeshBooleans, meshBooleansLoaded, loadAllAgentSceneModules, allAgentSceneModulesLoaded,// The VM has no Worker, as in Node: builds stay synchronous, the way the preview falls back without workers.buildWithKernels: build => build(), kernelWorkersAvailable: () => false,+ kernelStats: () => ({ worker: 0, inline: 0, fallbacks: [] }), resetKernelStats: () => {}, performance, setInterval: () => 0,// The harness loads Manifold from node_modules directly, so the preview's served-file loader is ignored.setManifoldModuleLoader: () => {},needsPhysics, loadPhysicsEngine, physicsEngineLoaded, setPhysicsModuleLoader: () => {},