3D engine that AI agents drive
Place catalog GLB assets inside recipe scenes
Nguyen Xuan An07afe0d2fbda
diff --git a/bench/size/budgets.json b/bench/size/budgets.jsonindex 459b421b..05a216c8 100644--- a/bench/size/budgets.json+++ b/bench/size/budgets.json@@ -34,10 +34,10 @@"entry:ground-bounce": 9460,"entry:path-tracer": 15960,"entry:texture-set": 900,- "entry:agent-scene": 80770,- "entry:agent-scene+lazy": 263350,- "entry:agent-asset": 112170,- "entry:agent-asset+lazy": 274720,+ "entry:agent-scene": 81721,+ "entry:agent-scene+lazy": 267519,+ "entry:agent-asset": 113141,+ "entry:agent-asset+lazy": 278908,"entry:hdri": 3300,"entry:camera-effects": 8600,"entry:water-reflection": 26580,@@ -49,7 +49,7 @@"scene:lit-box": 65870,"scene:gltf-box": 90150,"scene:gltf-box+lazy": 93480,- "scene:agent-scene": 109670,- "scene:agent-scene+lazy": 292250+ "scene:agent-scene": 110599,+ "scene:agent-scene+lazy": 296396}}diff --git a/bench/tool-cost-budgets.json b/bench/tool-cost-budgets.jsonindex 0ff57b3c..ac8817ef 100644--- a/bench/tool-cost-budgets.json+++ b/bench/tool-cost-budgets.json@@ -1,16 +1,16 @@{- "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 650 total and 80 for scene_apply for clip layers, bone masks and retargeting through MCP; raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references; trimmed after the render-passes merge: material graph, depth of field, motion blur and passes details moved to scene_capabilities, budgets set to the measured value plus 0.5% (total 188267, scene_capabilities result 5167); raised by 95 for scene_apply and 690 for the scene_capabilities result for node relations; curve and text geometry entries shortened to a pointer at scene_capabilities curveText, budgets set to the measured value plus 0.5% (total 189468, scene_capabilities result 6399); then six modifier ops (weld, triangulate, edge_split, smooth, simple_deform, cast) added as one compact schema entry with details in scene_capabilities meshModifiers, entry and mesh_stack description shortened: total 190382 (budget unchanged at 190420), mesh_edit 34216 (budget 34220), scene_capabilities result 7042 (budget 7050); mesh_stack 11682 (budget 11690); after merging imported mesh topology with the modifier ops: raised the total to 190480 (measured 190471), mesh_edit to 34300 (measured 34293) and the scene_capabilities result to 7520 (measured 7512) for imported mesh edits; then cloth (recipe cloth, set-cloth, grid geometry) added with the total unchanged at 190480 (measured 189159): physics descriptions shortened and set-physics now takes the same record reference as set-motion, scene_create raised to 62150 and scene_apply lowered to 44130, scene_capabilities result raised to 8190 (measured 8176) for the cloth details; then particles and hair (recipe `particles`, set-particles) added with the total unchanged at 190480 (measured 189642, scene_create raised to 62350 and scene_apply to 44370 for the recipe particles reference and set-particles): the section is one record reference described in scene_capabilities, so the scene_capabilities result rose to 9570 (measured 9523) for the particle and hair fields; after merging the film timeline (recipe timeline, set-timeline) with particles: total 190719 (budget 190730), scene_create 62464, scene_apply 44620, scene_capabilities result 9902; then the path tracer renderer setting (drop z.int bounds, integers still checked by the job validator): total raised to 190830 (measured 190818); after merging the render limits and light bake with the path tracer: measured total 190013, scene_create raised to 62680 (measured 62667), scene_apply to 44860 (measured 44852) and the scene_capabilities result to 10620 (measured 10613) for the bake section and job size limits; then material layers anisotropy and iridescence (issue #51): the 16 layer fields take one short line each in the schema and their ranges and notes moved to scene_capabilities scene.materialLayers, so the scene_capabilities result rose to 12230 (measured 12168); then the worker bake limit added workerMaxSeconds to the bake limits (result 13361, budget raised to 13370); then the sculpt and shrinkwrap mesh edits (issue #47) with the total unchanged at 190830 (measured 190612): the face rule and tag prefix descriptions shortened (the face rule text repeats in every select field), so mesh_edit rose to 33980 (measured 33960) and mesh_stack fell to 11030 (measured 11014), and the scene_capabilities result rose to 13350 (measured 13338) for the meshSculpt notes; then recipe light links and shadow cascades (issue #52): environment fields added to the shared environment schema with the total unchanged at 190830 (measured 190507) by shortening its descriptions, and the scene_capabilities result raised to 13870 (measured 13865) for lightLinking and shadowCascades; then the nine remaining modifiers (issue #42: screw, skin, wireframe, lattice, curve, hook, wave, weighted_normal, smooth_by_angle) added their notes to meshModifiers and a free modifier record replaced the modifier schema entry, so the schemas shrank and the scene_capabilities result rose to 15900 (measured 15814); path query of scene_inspect (issue #64): one record field of 205 bytes in the scene_inspect schema (total 190732, within its budget) and the navigation notes in scene_capabilities, so the result rose to 14500 (measured 14494); reflection probes (issue #55): the bake.probes line, and the scene_capabilities result raised to 16600 (measured 16541) after merging with main; volumeFog shadowAmbient (issue #165): scene_create raised to 62945 (measured 62940) and scene_apply to 45040 (measured 45037); keyframe easing (issue #286): one easing string field in each of the motion track schemas, scene_create raised to 63450 (measured 63444) and the total to 191000 (measured 190994); glTF import line gltfImport (issue #280): the scene_capabilities result raised to 16701 (measured 16681)",- "schemaTotalBytes": 191040,+ "measured": "2026-10-31, from scripts/measure-tool-cost.mjs; raised by 800 total and 150 for scene_apply for branch and labels fields (no new tool); raised by 650 total and 80 for scene_apply for clip layers, bone masks and retargeting through MCP; raised by 20 for scene_create and 20 for the scene_capabilities result after merging the expression language with the material graph; was 373388 schema bytes before shared IDs and recipe references; trimmed after the render-passes merge: material graph, depth of field, motion blur and passes details moved to scene_capabilities, budgets set to the measured value plus 0.5% (total 188267, scene_capabilities result 5167); raised by 95 for scene_apply and 690 for the scene_capabilities result for node relations; curve and text geometry entries shortened to a pointer at scene_capabilities curveText, budgets set to the measured value plus 0.5% (total 189468, scene_capabilities result 6399); then six modifier ops (weld, triangulate, edge_split, smooth, simple_deform, cast) added as one compact schema entry with details in scene_capabilities meshModifiers, entry and mesh_stack description shortened: total 190382 (budget unchanged at 190420), mesh_edit 34216 (budget 34220), scene_capabilities result 7042 (budget 7050); mesh_stack 11682 (budget 11690); after merging imported mesh topology with the modifier ops: raised the total to 190480 (measured 190471), mesh_edit to 34300 (measured 34293) and the scene_capabilities result to 7520 (measured 7512) for imported mesh edits; then cloth (recipe cloth, set-cloth, grid geometry) added with the total unchanged at 190480 (measured 189159): physics descriptions shortened and set-physics now takes the same record reference as set-motion, scene_create raised to 62150 and scene_apply lowered to 44130, scene_capabilities result raised to 8190 (measured 8176) for the cloth details; then particles and hair (recipe `particles`, set-particles) added with the total unchanged at 190480 (measured 189642, scene_create raised to 62350 and scene_apply to 44370 for the recipe particles reference and set-particles): the section is one record reference described in scene_capabilities, so the scene_capabilities result rose to 9570 (measured 9523) for the particle and hair fields; after merging the film timeline (recipe timeline, set-timeline) with particles: total 190719 (budget 190730), scene_create 62464, scene_apply 44620, scene_capabilities result 9902; then the path tracer renderer setting (drop z.int bounds, integers still checked by the job validator): total raised to 190830 (measured 190818); after merging the render limits and light bake with the path tracer: measured total 190013, scene_create raised to 62680 (measured 62667), scene_apply to 44860 (measured 44852) and the scene_capabilities result to 10620 (measured 10613) for the bake section and job size limits; then material layers anisotropy and iridescence (issue #51): the 16 layer fields take one short line each in the schema and their ranges and notes moved to scene_capabilities scene.materialLayers, so the scene_capabilities result rose to 12230 (measured 12168); then the worker bake limit added workerMaxSeconds to the bake limits (result 13361, budget raised to 13370); then the sculpt and shrinkwrap mesh edits (issue #47) with the total unchanged at 190830 (measured 190612): the face rule and tag prefix descriptions shortened (the face rule text repeats in every select field), so mesh_edit rose to 33980 (measured 33960) and mesh_stack fell to 11030 (measured 11014), and the scene_capabilities result rose to 13350 (measured 13338) for the meshSculpt notes; then recipe light links and shadow cascades (issue #52): environment fields added to the shared environment schema with the total unchanged at 190830 (measured 190507) by shortening its descriptions, and the scene_capabilities result raised to 13870 (measured 13865) for lightLinking and shadowCascades; then the nine remaining modifiers (issue #42: screw, skin, wireframe, lattice, curve, hook, wave, weighted_normal, smooth_by_angle) added their notes to meshModifiers and a free modifier record replaced the modifier schema entry, so the schemas shrank and the scene_capabilities result rose to 15900 (measured 15814); path query of scene_inspect (issue #64): one record field of 205 bytes in the scene_inspect schema (total 190732, within its budget) and the navigation notes in scene_capabilities, so the result rose to 14500 (measured 14494); reflection probes (issue #55): the bake.probes line, and the scene_capabilities result raised to 16600 (measured 16541) after merging with main; volumeFog shadowAmbient (issue #165): scene_create raised to 62945 (measured 62940) and scene_apply to 45040 (measured 45037); keyframe easing (issue #286): one easing string field in each of the motion track schemas, scene_create raised to 63450 (measured 63444) and the total to 191000 (measured 190994); glTF import line gltfImport (issue #280): the scene_capabilities result raised to 16701 (measured 16681); placed catalog assets (issue #320): one record field asset on nodes and the placedAssets note in scene_capabilities: total raised to 191570 (measured 191560), scene_create to 63700 (measured 63688), scene_apply to 45330 (measured 45320), the scene_capabilities result to 17430 (measured 17419)",+ "schemaTotalBytes": 191570,"schemaToolBytes": {- "scene_create": 63450,- "scene_apply": 45040,+ "scene_create": 63700,+ "scene_apply": 45330,"mesh_edit": 33980,"scene_create_asset": 19310,"mesh_stack": 11030},"schemaOtherToolBytes": 4000,"resultBytes": {- "scene_capabilities": 16701,+ "scene_capabilities": 17430,"scene_create": 1400,"scene_inspect": 1400,"mesh_inspect": 1200,diff --git a/changes/320.md b/changes/320.mdnew file mode 100644index 00000000..94f978ef--- /dev/null+++ b/changes/320.md@@ -0,0 +1 @@+- Place catalog GLB assets inside recipe scenes with a node `asset` field (issue #320): terrain, lights, procedural meshes and many imported models share one scene. Copies of an asset share geometry and materials and draw as one batch, materials override by source name, a placed clip plays from its own start time and seeks to the same frame, and `scene_inspect` reports each placement's id, bounds and clips. Render jobs do not draw placed assets yet; `docs/mcp.md` gives the command that bundles a Poly Haven glTF folder into a GLB.diff --git a/docs/agent-scene.md b/docs/agent-scene.mdindex 68db6046..b8813ed4 100644--- a/docs/agent-scene.md+++ b/docs/agent-scene.md@@ -239,6 +239,23 @@ dropped. `yaw` turns each instance randomly about up, `alignToNormal` (surface ois a random uniform `[min, max]`. At most 2048 candidate points per node, and the scene's node limit still applies.The group's own scale applies to the spacing and the points, because they are in its space.+### Placed catalog assets++A node with an `asset` field places a GLB from the `--assets` catalog inside the recipe, so one scene holds terrain, lights, procedural meshes and imported models (`scene_create_asset` opens one asset alone). The node is a group: its transform places the asset, and its parts become generated child nodes named `<node>/<part index>` that `scene_inspect` and `scene_export_recipe` leave out.++```json+{ "id": "tree-1", "translation": [4, 0, -2], "asset": { "id": "<64 hex asset id>",+ "materials": [{ "name": "Leaves", "color": [0.2, 0.5, 0.1] }],+ "clip": { "index": 0, "start": 0.5, "speed": 1, "loop": true } } }+```++- `id` is an id from `scene_asset_catalog`. `materials` override source materials by glTF material name (`color`, `metallic`, `roughness`, `opacity`, `emission`, `emissiveColor`); `scene_inspect` lists the names. Placements with the same overrides share one material.+- Placements of the same asset share geometry and materials, so they draw as one instanced batch per material (`drawBatches` in the render status stays flat as copies are added). Skins and morphs keep working.+- `clip` plays that clip, held at its first frame until scene time `start`, then at `speed`, looping unless `loop` is false. Each placement that plays a clip gets a decoded copy of its own (its geometry is not shared), because a pose is state of one decoded asset. A seek gives the same frame as playing to that time. `set-motion` tracks still move the node itself, so a walking figure is a clip plus a motion track on the same node.+- Bounds: 512 placements, 16 different assets, 16 placements playing a clip, and `maxNodes` for the generated parts. Placed geometry does not count against `maxVertices`; each asset keeps the decoder limits of the catalog.+- `scene_inspect` adds `assets`: per placement the asset id, part count, world bounds, clips (index, name, duration), material names and the playing clip.+- Not yet: render jobs refuse a scene with placed assets (`scene_look` draws them), and a scene created without any placed asset cannot add the first one with `scene_apply`.+### Relations between partsA mesh node can list `relations` that place it against other mesh nodes, so a resized body keeps its handle where itdiff --git a/docs/mcp.md b/docs/mcp.mdindex f491a851..a85f8571 100644--- a/docs/mcp.md+++ b/docs/mcp.md@@ -60,6 +60,7 @@ Using Node directly also avoids shell-specific npm launcher behavior in MCP clieThe asset catalog reads regular files directly inside that directory, with limits of 64 files and 16 MiB per file.Asset IDs bind file contents through SHA-256. Changed files require a runtime restart before they receive refreshed IDs.Catalog imports retain supported textures, skins, morphs and animation clips.+The catalog takes self-contained GLB only. Poly Haven and similar sites ship a glTF folder (`.gltf`, `.bin` and textures): bundle it first with one command, then put the result in the catalog directory: `npx @gltf-transform/cli copy tree_01_1k.gltf tree_01.glb`. A recipe places a catalog asset with an `asset` node field (see [the scene guide](agent-scene.md#placed-catalog-assets)).These launch options remain outside tool arguments.The process runs below normal priority to reduce interference with other work.diff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex 9006d5ad..5049cd2b 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -13,6 +13,7 @@ import { agentGroundPlacement, createAgentGround, placeAgentGround, FLOOR_COLORimport { groundBounceEnvironment } from '../src/ground-bounce.js';import { createAgentAssetScene } from '../src/agent-asset.js';import { parseGltf } from '../src/gltf.js';+import { assetCopyKey, recipeAssetNeeds } from '../src/agent-scene-assets.js';import { exportGlb } from '../src/export.js';import { weightTracksFromGltfAnimation } from '../src/export-skeleton.js';import { clipFromGltfAnimation } from '../src/skeleton-pose.js';@@ -252,7 +253,7 @@ function previousCameraFor(record, motionTime) {return previousCamera;}-function createPreview(scene, { sessionId, memoryBudgetMiB, backend }, asset) {+function createPreview(scene, { sessionId, memoryBudgetMiB, backend }, asset, placedAssets) {if (active) {throw new Error('Dispose the current scene before creating another.');}@@ -260,7 +261,7 @@ function createPreview(scene, { sessionId, memoryBudgetMiB, backend }, asset) {let renderer;try {renderer = initializeRenderer(scene, { memoryBudgetMiB, backend });- const record = { scene, renderer, asset, sessionId, options: { memoryBudgetMiB, backend },+ const record = { scene, renderer, asset, placedAssets, sessionId, options: { memoryBudgetMiB, backend },checkpoints: new Map(), branches: createBranchStore(), rendererTopology: scene.topologyRevision, rendererTextured: hasPatternTextures(scene.parts) };draw(record);const result = status(record);@@ -284,6 +285,36 @@ setPhysicsModuleLoader(() => import(/* @vite-ignore */ new URL('/vendor/rapier.j// The preview bundle is one file, so the on-demand scene modules load together on the first call and later calls stay// synchronous. The boolean engine is WebAssembly and loads asynchronously, once, only for calls that need it.+function decodeBase64(data) {+ if (typeof Uint8Array.fromBase64 === 'function') {+ return Uint8Array.fromBase64(data);+ }+ const binary = atob(data);+ const bytes = new Uint8Array(binary.length);+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);+ return bytes;+}++const ASSET_DECODE_LIMITS = { maxBytes: 16 * 1024 * 1024, maxVertices: 250000, maxParts: 4096, maxTexturePixels: 4194304, maxJoints: 1024 };++function disposePlacedAssets(pool) {+ for (const asset of pool?.values() ?? []) asset.dispose();+ pool?.clear();+}++// A recipe that places catalog assets arrives with their bytes, keyed by asset id. Copy 0 serves every still placement and+// each placement that plays a clip takes a copy of its own, since a pose is state of one decoded asset.+async function loadPlacedAssets(pool, value, assetData) {+ for (const { id, copies } of recipeAssetNeeds(value)) {+ for (let copy = 0; copy < copies; copy++) {+ const key = assetCopyKey(id, copy);+ if (pool.has(key)) continue;+ if (!assetData?.[id]) throw new Error(`Asset ${id.slice(0, 12)} was not supplied. Check asset_catalog for its id.`);+ pool.set(key, await parseGltf(decodeBase64(assetData[id]).buffer, ASSET_DECODE_LIMITS));+ }+ }+}+function afterMeshBooleans(value, run) {if (!allAgentSceneModulesLoaded()) return loadAllAgentSceneModules().then(() => afterMeshBooleans(value, run));const loads = [];@@ -631,8 +662,27 @@ window.__agentPreview = {tracedFeatures = undefined;return { data: encodeTracedPng(toneMapToRgba8(pixels, width, height), width, height) };},+ async createWithAssets(input) {+ const pool = new Map();+ try {+ await loadAllAgentSceneModules();+ await loadPlacedAssets(pool, input.recipe, input.assetData);+ // Placed assets are decoded on this thread, so the scene is built here and not on the kernel worker.+ return await afterMeshBooleans(input.recipe, () => {+ startBuildReport();+ const startedAt = performance.now();+ const scene = createAgentScene(input.recipe, {}, { assets: pool });+ finishBuildReport(startedAt);+ return createPreview(scene, input, undefined, pool);+ });+ } catch (error) {+ disposePlacedAssets(pool);+ throw error;+ }+ },create(input) {if (active) throw new Error('Dispose the current scene before creating another.');+ if (recipeAssetNeeds(input.recipe).length) return this.createWithAssets(input);return afterMeshBooleans(input.recipe, () => {startBuildReport();const startedAt = performance.now();@@ -649,14 +699,7 @@ window.__agentPreview = {},async createAsset(input) {if (active) throw new Error('Dispose the current scene before creating another.');- let bytes;- if (typeof Uint8Array.fromBase64 === 'function') {- bytes = Uint8Array.fromBase64(input.data);- } else {- const binary = atob(input.data);- bytes = new Uint8Array(binary.length);- for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);- }+ const bytes = decodeBase64(input.data);let asset;try {// Labels, mesh reports and motion read the on-demand modules on any asset, not only one with mesh edits.@@ -680,6 +723,16 @@ window.__agentPreview = {return { sessionId, ...scene.inspectMeshes(options) };},apply(input) {+ if (recipeAssetNeeds(input.operations).length) return this.applyWithAssets(input);+ return afterMeshBooleans(input.operations, () => this.applyLoaded(input));+ },+ async applyWithAssets(input) {+ const record = requireSession(input.sessionId);+ if (!record.placedAssets) {+ throw new Error('This scene was created without placed assets. Recreate it with an asset node in scene_create, then add more.');+ }+ await loadAllAgentSceneModules();+ await loadPlacedAssets(record.placedAssets, input.operations, input.assetData);return afterMeshBooleans(input.operations, () => this.applyLoaded(input));},applyLoaded({ sessionId, operations, expectedRevision }) {@@ -817,6 +870,7 @@ window.__agentPreview = {record.renderer?.dispose();} finally {record.asset?.dispose();+ disposePlacedAssets(record.placedAssets);}record.checkpoints.clear();record.branches.clear();diff --git a/scripts/agent-runtime.mjs b/scripts/agent-runtime.mjsindex c057a035..2f9c38f9 100644--- a/scripts/agent-runtime.mjs+++ b/scripts/agent-runtime.mjs@@ -10,6 +10,7 @@ import { AGENT_SCENE_CAPABILITIES, AGENT_SCENE_DEFAULT_LIMITS, RENDER_PASS_NAMESimport { PATH_TRACER_CAPABILITIES } from '../src/path-tracer-capabilities.js';import { chooseDenoiser, finishWithOidn } from './agent-path-trace-denoise.mjs';import { createAgentAssetCatalog } from './agent-asset-catalog.mjs';+import { recipeAssetNeeds } from '../src/agent-scene-assets.js';import { createAgentRenderJobs, EXPORT_DIRECTORY_NAME } from './agent-render-jobs.mjs';import { createFrameEncoder } from './frame-encoder.mjs';import { audioInputArguments, createAudioLibrary, measureStreamSeconds } from './job-audio.mjs';@@ -129,6 +130,14 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', browreturn catalogPromise;}+ /** Bytes of the catalog assets a recipe or edit list places, base64 by asset id, for the page that decodes them. */+ async function placedAssetData(value) {+ const needs = recipeAssetNeeds(value);+ if (!needs.length) return {};+ const entries = await Promise.all(needs.map(async ({ id }) => [id, (await (await catalog()).read(id)).toString('base64')]));+ return { assetData: Object.fromEntries(entries) };+ }+function enqueue(task) {if (closing || phase === 'closing' || phase === 'closed' || phase === 'failed') {return Promise.reject(new Error(`The agent runtime is ${phase}.`));@@ -525,7 +534,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow}await boot();const sessionId = randomUUID();- const result = await evaluate('create', { recipe, sessionId, memoryBudgetMiB: memory, backend }, page, recipe?.bake ? BAKE_EVALUATION_TIMEOUT_MS : EVALUATION_TIMEOUT_MS);+ const result = await evaluate('create', { recipe, sessionId, memoryBudgetMiB: memory, backend, ...(await placedAssetData(recipe)) }, page, recipe?.bake ? BAKE_EVALUATION_TIMEOUT_MS : EVALUATION_TIMEOUT_MS);activeSessionId = sessionId;activeSceneHasBake = Boolean(recipe?.bake);return result;@@ -572,7 +581,7 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow}const bakeAfter = bakeAfterOperations(input.operations);const rebakes = activeSceneHasBake || bakeAfter === true;- const applied = await invoke('apply', input, rebakes ? BAKE_EVALUATION_TIMEOUT_MS : EVALUATION_TIMEOUT_MS);+ const applied = await invoke('apply', { ...input, ...(await placedAssetData(input.operations)) }, rebakes ? BAKE_EVALUATION_TIMEOUT_MS : EVALUATION_TIMEOUT_MS);activeSceneHasBake = bakeAfter ?? activeSceneHasBake;return applied;});@@ -679,7 +688,8 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', browprivateSessionId = randomUUID();await reviewEvaluate(branchRecipe || !assetBytes ? 'create' : 'createAsset', { sessionId: privateSessionId,recipe: branchRecipe ? branchRecipe.recipe : snapshot.recipe, memoryBudgetMiB: memory, backend,- ...(!branchRecipe && assetBytes ? { data: assetBytes.toString('base64') } : {}) });+ ...(!branchRecipe && assetBytes ? { data: assetBytes.toString('base64') } : {}),+ ...(!assetBytes ? await placedAssetData(branchRecipe ? branchRecipe.recipe : snapshot.recipe) : {}) });privateCreated = true;for (const index of group.shotIndexes) {const rendered = await reviewEvaluate('reviewShot', { sessionId: privateSessionId, shot: settings.shots[index], index,@@ -783,6 +793,9 @@ export function createAgentRuntime({ kernelWorkers = true, backend = 'gpu', brow}const snapshot = await invoke('snapshot', { sessionId, expectedRevision });const assetBytes = snapshot.recipe.format === '67js.asset' ? await (await catalog()).read(snapshot.recipe.assetId) : undefined;+ if (recipeAssetNeeds(snapshot.recipe).length) {+ throw new Error('Render jobs do not yet render scenes that place catalog assets. Use scene_look for stills of this scene.');+ }phase = 'rendering';try {return await controller.submit({ sourceRevision: snapshot.sourceRevision,diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjsindex 71659f8d..d2522d7c 100644--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@ -28,8 +28,10 @@ const skinSpec = z.strictObject({maxDistance: positive.optional().describe('Metres from the nearest bone beyond which a vertex counts as unweighted in scene_inspect rig. Defaults to a quarter of the rig size.'),}).describe('Bind this mesh node to an armature with automatic weights: each vertex follows its nearest bones, by distance to the bone segments. Needs the armature at rest where the mesh is.');const relationList = z.array(z.record(z.string(), z.unknown())).max(8).describe('Relations against other mesh nodes; fields in scene_capabilities relations. [] removes them.').meta({ id: 'Relations' });+const placedAsset = z.record(z.string(), z.unknown()).describe('Catalog GLB placed at this group node: {id,materials,clip}; see scene_capabilities placedAssets.').meta({ id: 'PlacedAsset' });const nodeFields = {relations: relationList.optional(),+ asset: placedAsset.optional(),skin: skinSpec.optional(),label: z.string().max(256).optional().describe('Human-readable label. Identity remains the node ID.'),parent: identifier.nullable().optional().describe('Parent node ID, or null for a root. Local transforms stay unchanged.'),diff --git a/scripts/smoke-agent-scene-assets.mjs b/scripts/smoke-agent-scene-assets.mjsnew file mode 100644index 00000000..7ba95e95--- /dev/null+++ b/scripts/smoke-agent-scene-assets.mjs@@ -0,0 +1,78 @@+// Through MCP on the CPU backend: a recipe with terrain, two different catalog GLBs and ten copies of one of them,+// one of which plays a clip. Checks the draw batches, the inspected assets and that a seek reproduces its frame.+import assert from 'node:assert/strict';+import { mkdir, readFile, writeFile } from 'node:fs/promises';+import { constants, setPriority } from 'node:os';+import { resolve } from 'node:path';+import { Client } from '@modelcontextprotocol/client';+import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';+import { createTexturedRigFixture } from './agent-asset-fixture.mjs';++setPriority(0, constants.priority.PRIORITY_BELOW_NORMAL);+await mkdir('artifacts/scene-assets-proof', { recursive: true });+await writeFile('artifacts/scene-assets-proof/wall-e.glb', await readFile('public/wall-e.glb'));+await writeFile('artifacts/scene-assets-proof/textured-rig.glb', await createTexturedRigFixture());+const transport = new StdioClientTransport({ command: process.execPath,+ args: [resolve('scripts/mcp-server.mjs'), '--backend', 'cpu', '--memory', '192', '--assets', resolve('artifacts/scene-assets-proof')],+ stderr: 'pipe', cwd: process.cwd(),+});+let diagnostics = '';+transport.stderr.on('data', chunk => { diagnostics += chunk.toString(); });+const client = new Client({ name: '67js-scene-assets-proof', version: '1' }, {+ versionNegotiation: { mode: { pin: '2026-07-28' }, probe: { timeoutMs: 180000 } },+});+async function call(name, argumentsValue = {}) {+ const result = await client.callTool({ name, arguments: argumentsValue }, { timeout: 180000 });+ assert.equal(result.isError, undefined, result.content?.find(item => item.type === 'text')?.text);+ return result;+}+async function look(sessionId, label, motionTime) {+ const result = await call('scene_look', { sessionId, width: 768, height: 512, ...(motionTime === undefined ? {} : { motionTime }) });+ const bytes = Buffer.from(result.content.find(item => item.type === 'image').data, 'base64');+ await writeFile(`artifacts/scene-assets-${label}.png`, bytes);+ return bytes;+}+try {+ await client.connect(transport, { timeout: 180000 });+ assert.equal((await client.listTools()).tools.length, 22);+ const catalog = (await call('scene_asset_catalog')).structuredContent;+ const robot = catalog.assets.find(asset => asset.name === 'wall-e.glb').assetId;+ const rig = catalog.assets.find(asset => asset.name === 'textured-rig.glb').assetId;+ const copies = Array.from({ length: 10 }, (_, index) => ({+ id: `rig-${index}`, translation: [index * 1.5 - 7, 0, 2],+ asset: index === 4 ? { id: rig, clip: { index: 0, start: 0.25 } } : { id: rig },+ }));+ const created = (await call('scene_create', { recipe: {+ format: '67js.scene', schemaVersion: 1,+ geometries: [{ id: 'hills', type: 'terrain', size: 30, resolution: 48, amplitude: 0.4 }],+ materials: [{ id: 'grass', color: [0.25, 0.45, 0.2], roughness: 0.9 }],+ nodes: [+ { id: 'ground', geometry: 'hills', material: 'grass', translation: [0, -0.5, 0] },+ { id: 'robot', translation: [0, 0, -3], asset: { id: robot } },+ ...copies,+ ],+ camera: { eye: [0, 6, 14], target: [0, 1, 0], fov: 45 },+ } })).structuredContent;+ const sessionId = created.sessionId;+ const batches = created.render.drawBatches;+ const inspection = (await call('scene_inspect', { sessionId })).structuredContent;+ assert.equal(inspection.assets.length, 11);+ assert.equal(inspection.assets.filter(placement => placement.assetId === rig).length, 10);+ assert.ok(inspection.assets.every(placement => placement.bounds.max[1] > placement.bounds.min[1]));+ const first = await look(sessionId, 'start', 0);+ const later = await look(sessionId, 'later', 1.1);+ assert.notDeepEqual(first, later, 'the placed clip changes the frame');+ assert.deepEqual(await look(sessionId, 'later-again', 1.1), later, 'a seek reproduces its frame');+ assert.deepEqual(await look(sessionId, 'start-again', 0), first);+ const exported = (await call('scene_export_recipe', { sessionId })).structuredContent;+ assert.equal(exported.recipe.nodes.length, 12);+ await call('scene_dispose', { sessionId });+ const report = { backend: 'cpu', placements: 11, drawBatches: batches, seekExact: true };+ await writeFile('artifacts/scene-assets-cpu.json', JSON.stringify(report, null, 2));+ console.log(JSON.stringify(report));+} catch (error) {+ console.error(diagnostics);+ throw error;+} finally {+ await client.close();+}diff --git a/src/agent-scene-assets.js b/src/agent-scene-assets.jsnew file mode 100644index 00000000..b11a0a0c--- /dev/null+++ b/src/agent-scene-assets.js@@ -0,0 +1,305 @@+import { mat4 } from 'gl-matrix';++// Placing decoded glTF assets inside a procedural recipe scene. A node with an `asset` field is a group: the scene+// turns each mesh part of the asset into a generated child node, so terrain, lights, procedural meshes and any number of+// placed assets share one graph, one set of lights and one renderer. Every placement of the same asset uses the same+// geometry and the same material objects, so the renderer draws the copies as one instanced batch per material.+// A placement with a `clip` gets its own decoded copy (an "instance" above 0), because a pose is state of one decoded asset.++export const ASSET_PLACEMENT_LIMITS = Object.freeze({ maxPlacements: 512, maxAssets: 16, maxAnimatedPlacements: 16, maxOverrides: 32 });++const ASSET_ID = /^[a-f0-9]{64}$/;+const PLACEMENT_FIELDS = ['id', 'materials', 'clip'];+const CLIP_FIELDS = ['index', 'start', 'speed', 'loop'];+const COLOR_FIELDS = ['color', 'emissiveColor'];+const UNIT_FIELDS = ['metallic', 'roughness', 'opacity'];+const OVERRIDE_FIELDS = ['name', ...COLOR_FIELDS, ...UNIT_FIELDS, 'emission'];++function knownKeys(value, allowed, label) {+ if (!value || typeof value !== 'object' || Array.isArray(value)) {+ throw new TypeError(`${label} must be an object.`);+ }+ for (const key of Object.keys(value)) {+ if (!allowed.includes(key)) {+ throw new TypeError(`Unknown ${label} field: ${key}. Allowed fields: ${allowed.join(', ')}.`);+ }+ }+}++function colorVector(value, label) {+ if (!Array.isArray(value) || value.length !== 3 || value.some(component => !Number.isFinite(component) || component < 0)) {+ throw new RangeError(`${label} must be three finite non-negative linear RGB numbers.`);+ }+ return [...value];+}++function normalizeMaterialOverride(override) {+ knownKeys(override, OVERRIDE_FIELDS, 'asset material override');+ if (typeof override.name !== 'string' || !override.name || override.name.length > 256) {+ throw new TypeError('An asset material override needs the source material name. scene_inspect lists the names under assets.');+ }+ const result = { name: override.name };+ for (const field of COLOR_FIELDS) {+ if (override[field] !== undefined) result[field] = colorVector(override[field], field);+ }+ for (const field of UNIT_FIELDS) {+ if (override[field] !== undefined) {+ if (!Number.isFinite(override[field]) || override[field] < 0 || override[field] > 1) {+ throw new RangeError(`${field} must be a number from 0 to 1.`);+ }+ result[field] = override[field];+ }+ }+ if (override.emission !== undefined) {+ if (!Number.isFinite(override.emission) || override.emission < 0) {+ throw new RangeError('emission must be a finite non-negative number.');+ }+ result.emission = override.emission;+ }+ return result;+}++/** Validate the `asset` field of a node. Returns the canonical form kept in the recipe. */+export function normalizeAssetPlacement(value) {+ knownKeys(value, PLACEMENT_FIELDS, 'asset placement');+ if (typeof value.id !== 'string' || !ASSET_ID.test(value.id.toLowerCase())) {+ throw new TypeError('asset id must be the 64 hexadecimal characters of a catalog asset id; asset_catalog lists them.');+ }+ const result = { id: value.id.toLowerCase() };+ if (value.materials !== undefined) {+ if (!Array.isArray(value.materials) || value.materials.length > ASSET_PLACEMENT_LIMITS.maxOverrides) {+ throw new RangeError(`asset materials must list at most ${ASSET_PLACEMENT_LIMITS.maxOverrides} overrides.`);+ }+ const overrides = value.materials.map(normalizeMaterialOverride);+ if (new Set(overrides.map(override => override.name)).size !== overrides.length) {+ throw new RangeError('asset material overrides must name distinct source materials.');+ }+ result.materials = overrides;+ }+ if (value.clip !== undefined) {+ knownKeys(value.clip, CLIP_FIELDS, 'asset clip');+ const { index, start = 0, speed = 1, loop = true } = value.clip;+ if (!Number.isInteger(index) || index < 0) throw new RangeError('asset clip index must be a non-negative integer.');+ if (!Number.isFinite(start) || start < 0 || start > 3600) throw new RangeError('asset clip start must be seconds from 0 to 3600.');+ if (!Number.isFinite(speed) || speed <= 0 || speed > 16) throw new RangeError('asset clip speed must be above 0 and at most 16.');+ if (typeof loop !== 'boolean') throw new TypeError('asset clip loop must be boolean.');+ result.clip = { index, start, speed, loop };+ }+ return result;+}++function collectPlacements(value, found, depth = 0) {+ if (!value || typeof value !== 'object' || depth > 8) return;+ if (Array.isArray(value)) {+ for (const item of value) collectPlacements(item, found, depth + 1);+ return;+ }+ const placement = value.asset;+ if (placement && typeof placement === 'object' && typeof placement.id === 'string' && ASSET_ID.test(placement.id.toLowerCase())) {+ found.push(placement);+ }+ for (const [key, child] of Object.entries(value)) {+ if (key !== 'asset') collectPlacements(child, found, depth + 1);+ }+}++/**+ * The catalog assets a recipe (or a list of edit operations) places: `{ id, copies }` where `copies` is how many decoded+ * copies the host should load. Copy 0 serves every unanimated placement; each placement with a clip takes its own copy.+ */+export function recipeAssetNeeds(value) {+ const placements = [];+ collectPlacements(value, placements);+ const needs = new Map();+ for (const placement of placements) {+ const id = placement.id.toLowerCase();+ const need = needs.get(id) ?? { id, copies: 1 };+ if (placement.clip) need.copies++;+ needs.set(id, need);+ }+ return [...needs.values()];+}++export function assetCopyKey(id, copy) {+ return `${id}:${copy}`;+}++function jsonMaterial(source) {+ const result = {};+ for (const [field, value] of Object.entries(source)) {+ if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean') {+ result[field] = value;+ } else if (Array.isArray(value) && value.every(entry => typeof entry === 'number')) {+ result[field] = [...value];+ }+ }+ return result;+}++function overrideFields(override) {+ const fields = {};+ for (const field of [...COLOR_FIELDS, ...UNIT_FIELDS, 'emission']) {+ if (override?.[field] !== undefined) fields[field] = override[field];+ }+ return fields;+}++function materialOutput(source, fields) {+ const output = { ...source };+ for (const [field, value] of Object.entries(fields)) {+ output[field] = Array.isArray(value) ? Object.freeze([...value]) : value;+ }+ if (fields.emission !== undefined && fields.emission > 0 && !output.emissiveColor?.some(component => component > 0)) {+ output.emissiveColor = Object.freeze([1, 1, 1]);+ }+ return Object.freeze(output);+}++/**+ * Generate the geometries, materials and child nodes of every placement into a normalized recipe, in place.+ * `assets` maps assetCopyKey(id, copy) to a decoded parseGltf asset. Returns what the scene keeps outside the recipe JSON.+ */+export function expandAssetPlacements(recipe, assets, limits, outputCache = new Map()) {+ const placed = recipe.nodes.filter(node => node.asset);+ const runtime = { placements: [], geometryParts: new Map(), materialOutputs: new Map(), partExtras: new Map(), animators: [] };+ if (!placed.length) return runtime;+ if (!assets) {+ throw new Error('This recipe places catalog assets, which a host loads and decodes first. Pass them as the assets option of createAgentScene; MCP does this for scene_create.');+ }+ const distinct = new Set(placed.map(node => node.asset.id));+ const animated = placed.filter(node => node.asset.clip);+ if (placed.length > ASSET_PLACEMENT_LIMITS.maxPlacements || distinct.size > ASSET_PLACEMENT_LIMITS.maxAssets ||+ animated.length > ASSET_PLACEMENT_LIMITS.maxAnimatedPlacements) {+ throw new RangeError(`A scene places at most ${ASSET_PLACEMENT_LIMITS.maxPlacements} assets, ${ASSET_PLACEMENT_LIMITS.maxAssets} different ones, ${ASSET_PLACEMENT_LIMITS.maxAnimatedPlacements} of them playing a clip; this recipe places ${placed.length}, ${distinct.size} and ${animated.length}.`);+ }+ const copyCounter = new Map();+ const geometryIds = new Set();+ const materialIds = new Map();+ const generatedNodes = [];+ for (const node of placed) {+ const { id: assetId, materials: overrides = [], clip } = node.asset;+ let copy = 0;+ if (clip) {+ copy = (copyCounter.get(assetId) ?? 0) + 1;+ copyCounter.set(assetId, copy);+ }+ const asset = assets.get(assetCopyKey(assetId, copy));+ if (!asset) {+ throw new Error(`Asset ${assetId.slice(0, 12)} copy ${copy} is not loaded. The host loads it before createAgentScene or apply.`);+ }+ if (clip && !asset.animations[clip.index]) {+ throw new RangeError(`Node ${node.id}: asset ${assetId.slice(0, 12)} has ${asset.animations.length} clips, so clip index ${clip.index} does not exist. scene_inspect lists them under assets.`);+ }+ const materialNames = new Set(asset.parts.map(part => part.material.name).filter(Boolean));+ for (const override of overrides) {+ if (!materialNames.has(override.name)) {+ throw new RangeError(`Node ${node.id}: asset has no material named ${JSON.stringify(override.name)}. Names: ${[...materialNames].slice(0, 16).map(name => JSON.stringify(name)).join(', ') || 'none, the asset materials are unnamed'}.`);+ }+ }+ const overrideByName = new Map(overrides.map(override => [override.name, override]));+ const materialIndexes = new Map();+ const partNodeIds = [];+ asset.parts.forEach((part, index) => {+ const geometryId = `asset:${assetId.slice(0, 12)}:${copy}:${index}`;+ if (!geometryIds.has(geometryId)) {+ geometryIds.add(geometryId);+ recipe.geometries.push({ id: geometryId, type: 'asset', assetId, copy, part: index });+ runtime.geometryParts.set(geometryId, part.geometry);+ }+ if (!materialIndexes.has(part.material)) materialIndexes.set(part.material, materialIndexes.size);+ const fields = overrideFields(overrideByName.get(part.material.name));+ const materialKey = `asset:${assetId.slice(0, 12)}:${copy}:${materialIndexes.get(part.material)}:${JSON.stringify(fields)}`;+ if (!materialIds.has(materialKey)) {+ materialIds.set(materialKey, materialKey);+ recipe.materials.push({ id: materialKey, ...jsonMaterial(part.material), ...fields, assetSource: true });+ // The same output object across stages keeps the renderer's batches and the parts' identity stable.+ if (outputCache.get(materialKey)?.source !== part.material) {+ outputCache.set(materialKey, { source: part.material, output: materialOutput(part.material, fields) });+ }+ runtime.materialOutputs.set(materialKey, outputCache.get(materialKey).output);+ }+ const partNodeId = `${node.id}/${index}`;+ partNodeIds.push(partNodeId);+ generatedNodes.push({+ id: partNodeId, parent: node.id, label: String(part.name ?? partNodeId).slice(0, 256),+ translation: [0, 0, 0], rotation: [0, 0, 0, 1], scale: [1, 1, 1],+ geometry: geometryId, material: materialKey, assetPart: { placement: node.id, index, matrix: Array.from(part.matrix) },+ });+ runtime.partExtras.set(partNodeId, {+ ...(part.skin ? { skin: part.skin } : {}), ...(part.morph ? { morph: part.morph } : {}),+ ...(part.castShadow !== undefined ? { castShadow: part.castShadow } : {}),+ });+ });+ const record = { node: node.id, assetId, copy, asset, partNodeIds, clip: clip ?? null };+ runtime.placements.push(record);+ if (clip) runtime.animators.push(record);+ }+ if (recipe.nodes.length + generatedNodes.length > limits.maxNodes) {+ throw new RangeError(`Placed assets expand to ${generatedNodes.length} part nodes, which with the ${recipe.nodes.length} authored nodes exceeds maxNodes ${limits.maxNodes}. Place fewer copies or simpler assets.`);+ }+ recipe.nodes.push(...generatedNodes);+ return runtime;+}++/** The time inside a clip for a scene time: held at the first frame before `start`, then looped or held at the end. */+export function clipTimeAt(clip, duration, time) {+ const elapsed = Math.max(0, ((time ?? 0) - clip.start) * clip.speed);+ if (duration <= 0) return 0;+ return clip.loop ? elapsed % duration : Math.min(elapsed, duration);+}++/**+ * Pose every animated placement at a scene time. Returns the world matrix of each part node and a commit/discard pair;+ * the pose is staged first so a failure leaves every asset where it was.+ */+export function stageAssetClips(runtime, graph, time) {+ const transactions = [];+ const matrices = new Map();+ try {+ for (const record of runtime.animators) {+ const duration = record.asset.animations[record.clip.index].duration;+ const transaction = record.asset.stagePose({ animation: { clip: record.clip.index, time: clipTimeAt(record.clip, duration, time) }, nodeOverrides: [] });+ transactions.push(transaction);+ const placement = graph.getNode(record.node).worldMatrix;+ record.partNodeIds.forEach((id, index) => {+ matrices.set(id, mat4.multiply(new Float32Array(16), placement, transaction.parts[index].matrix));+ });+ }+ } catch (error) {+ for (const transaction of transactions) transaction.discard();+ throw error;+ }+ return {+ matrices,+ commit() {+ for (const transaction of transactions) transaction.commit();+ },+ };+}++/** What scene_inspect reports for each placement: the asset id, its world bounds, its clips and material names. */+export function describeAssetPlacements(runtime, graph, geometryBounds) {+ return runtime.placements.map(record => {+ const minimum = [Infinity, Infinity, Infinity];+ const maximum = [-Infinity, -Infinity, -Infinity];+ for (const id of record.partNodeIds) {+ const node = graph.getNode(id);+ const bounds = geometryBounds(node.geometry);+ for (let corner = 0; corner < 8; corner++) {+ const point = [0, 1, 2].map(axis => (corner & (1 << axis) ? bounds.max[axis] : bounds.min[axis]));+ for (let axis = 0; axis < 3; axis++) {+ const value = node.worldMatrix[axis] * point[0] + node.worldMatrix[4 + axis] * point[1] + node.worldMatrix[8 + axis] * point[2] + node.worldMatrix[12 + axis];+ minimum[axis] = Math.min(minimum[axis], value);+ maximum[axis] = Math.max(maximum[axis], value);+ }+ }+ }+ return {+ node: record.node, assetId: record.assetId, parts: record.partNodeIds.length,+ bounds: { min: minimum, max: maximum },+ clips: record.asset.animations.map((animation, index) => ({ index, name: animation.name ?? `clip ${index}`, duration: animation.duration })),+ materials: [...new Set(record.asset.parts.map(part => part.material.name).filter(Boolean))],+ ...(record.clip ? { playing: record.clip } : {}),+ };+ });+}diff --git a/src/agent-scene-capabilities.js b/src/agent-scene-capabilities.jsindex 5b5bcb88..4e6dff6e 100644--- a/src/agent-scene-capabilities.js+++ b/src/agent-scene-capabilities.js@@ -153,6 +153,7 @@ export const AGENT_SCENE_CAPABILITIES = Object.freeze({format: '67js.scene', schemaVersion: 1,geometryTypes: Object.freeze(['box', 'cylinder', 'sphere', 'torus', 'lathe', 'extrude', 'tube', 'curve', 'text', 'grid', 'terrain', 'mesh']),terrain: 'One mesh, x and z from -size/2 to size/2, hills about y = 0. size 40 m (1-2000), resolution 64 cells (2-256), seed 1, amplitude 1 m (0-200), holes up to 16 of {center:[x,z],radius} with no surface inside; radius a few cells or more.',+ placedAssets: 'Node field asset:{id,materials?,clip?} turns a group node into a catalog GLB (id from asset_catalog; scene_create_asset is one asset alone). Its transform places it. materials:[{name,color,metallic,roughness,opacity,emission,emissiveColor}] override source materials by name. clip:{index,start=0,speed=1,loop=true} plays that clip from scene time start, on a decoded copy of its own; scene_apply set-motion tracks move the node as usual and scene time seeks the clip. Copies of one asset share geometry and materials and draw as one batch. scene_inspect assets lists id, bounds, clips and material names. At most 512 placements, 16 assets, 16 playing a clip. Render jobs do not draw placed assets yet; scene_look does.',navigation: 'scene_inspect path:{ground,from:[x,z],to:[x,z]} returns a route over the ground node around its holes, steep slopes and the nodes in avoid:[ids] (box footprints), as keyframes [{time,value:[x,y,z]}] for a node translation track with interpolation LINEAR. radius 0.3 m is how far the walker position stays from holes and avoided nodes; maxSlope 40 degrees; cellSize defaults to radius; give seconds for the whole walk or speed (1.4 m/s); lift raises y, such as half the walker height. Ground and avoided nodes are read at their authored pose. Errors name an unwalkable start or goal, or one that cannot be reached.',meshEdits: Object.freeze({ operations: Object.freeze(Object.keys(MESH_EDIT_OPERATIONS)), maxEdits: MAX_MESH_EDITS }),meshStack: Object.freeze({ operations: STACK_OPERATIONS, maxNodes: MAX_STACK_NODES }),diff --git a/src/agent-scene-modules.js b/src/agent-scene-modules.jsindex 7f6a43eb..c6f2948c 100644--- a/src/agent-scene-modules.js+++ b/src/agent-scene-modules.js@@ -21,6 +21,7 @@ const MODULE_LOADERS = {navigation: () => import('./agent-navigation.js'),lightLinking: () => import('./light-linking.js'),cascades: () => import('./cascaded-shadows.js'),+ assets: () => import('./agent-scene-assets.js'),};const loadedModules = {};@@ -49,6 +50,7 @@ const MODULE_MARKERS = {navigation: [],lightLinking: ['"affects"', '"keyAffects"'],cascades: ['"shadowCascades"'],+ assets: ['"asset":{'],};/** Whether a recipe, operation list or edit list contains a boolean edit, which needs loadMeshBooleans() first. */diff --git a/src/agent-scene.js b/src/agent-scene.jsindex 3bc1912b..c36b045b 100644--- a/src/agent-scene.js+++ b/src/agent-scene.js@@ -22,7 +22,7 @@ const MAX_MESH_REPORTS = 16;// Terrain meshes carry one more float for each vertex (sky visibility) than the 56 bytes the budget estimates.const TERRAIN_SKY_VISIBILITY_BYTES = 4;const CAMERA_DEFAULTS = Object.freeze({ eye: [4, 3, 5], target: [0, 0, 0], up: [0, 1, 0], fov: 45, near: 0.1, far: 1000 });-const NODE_FIELDS = ['translation', 'rotation', 'scale', 'parent', 'label', 'geometry', 'material', 'skin', 'relations'];+const NODE_FIELDS = ['translation', 'rotation', 'scale', 'parent', 'label', 'geometry', 'material', 'skin', 'relations', 'asset'];const MATERIAL_FIELDS = ['color', 'metallic', 'roughness', 'emission', 'emissiveColor', 'opacity', 'alphaMode', 'doubleSided', 'pattern', ...MATERIAL_LAYER_FIELDS];const PATTERN_TEXTURE_FIELDS = ['map', 'normalMap', 'metallicRoughnessMap', 'emissiveMap', 'boxMapScale', 'boxMapAxis'];const CAMERA_FIELDS = Object.keys(CAMERA_DEFAULTS);@@ -283,6 +283,12 @@ function nodeFrom(value) {identifier(value.geometry);identifier(value.material);}+ if (value.asset !== undefined) {+ if (value.geometry !== undefined || value.skin !== undefined) {+ throw new TypeError(`Node ${value.id}: a node that places an asset is a group; drop geometry, material and skin.`);+ }+ result.asset = agentSceneModule('assets').normalizeAssetPlacement(value.asset);+ }if (value.skin !== undefined) {if (value.geometry === undefined) {throw new TypeError('Only mesh nodes can have a skin.');@@ -501,7 +507,7 @@ function compile(recipe, geometries, localBounds, limits) {throw new RangeError(`Node ${node.id} uses ${geometries.has(node.geometry) ? `material ${node.material}` : `geometry ${node.geometry}`}, which does not exist. Add it to the recipe, or point the node at one of: ${(geometries.has(node.geometry) ? [...materials.keys()] : [...geometries.keys()]).join(', ')}.`);}return { name: node.id, parent: node.parent,- matrix: mat4.fromRotationTranslationScale(mat4.create(), node.rotation, node.translation, node.scale),+ matrix: node.assetPart ? mat4.clone(node.assetPart.matrix) : mat4.fromRotationTranslationScale(mat4.create(), node.rotation, node.translation, node.scale),geometry: geometries.get(node.geometry), material: materials.get(node.material) };}), limits);validateGraph(graph, localBounds);@@ -646,8 +652,12 @@ function normalizeRecipe(input, limits) {throw new RangeError('Expected 67js.scene schemaVersion 1.');}// A scene with no mesh, or whose nodes all take the default material, has nothing to list: absent means empty.+ // Placed assets generate their own geometries, materials and part nodes each time; an exported or checkpointed recipe may still carry them.recipe.geometries ??= [];recipe.materials ??= [];+ if (Array.isArray(recipe.geometries)) recipe.geometries = recipe.geometries.filter(geometry => geometry?.type !== 'asset');+ if (Array.isArray(recipe.materials)) recipe.materials = recipe.materials.filter(material => !material?.assetSource);+ if (Array.isArray(recipe.nodes)) recipe.nodes = recipe.nodes.filter(node => !node?.assetPart);recipe.geometries = resources(recipe.geometries, limits.maxGeometries, 'geometries', value => {geometryEstimate(value);const definition = { id: value.id, type: value.type };@@ -768,6 +778,14 @@ function immutableMaterial(snapshot) {return Object.freeze(snapshot);}+const NO_ASSETS = Object.freeze({ placements: [], animators: [], geometryParts: new Map(), materialOutputs: new Map(), partExtras: new Map() });++// A placed asset's material is the decoded one, shared by every placement that uses the same overrides.+function assetMaterialHandle(snapshot, output, ...candidates) {+ const reusable = candidates.find(handle => handle?.output === output);+ return reusable ?? { holder: { snapshot }, output };+}+function retainedMatrices(parts) {for (const part of parts) {if (part.matrix.length !== 16 || part.matrix.byteLength !== 64) {@@ -808,6 +826,10 @@ function stagePose(stagedState, time) {if (Array.from(scale).some(component => !Number.isFinite(Math.fround(component)) || Math.fround(component) <= 0)) {throw new RangeError('Motion scale must remain positive at Float32 precision.');}+ if (node.assetPart) {+ graph.getNode(node.id).localMatrix.set(node.assetPart.matrix);+ continue;+ }mat4.fromRotationTranslationScale(graph.getNode(node.id).localMatrix, rotation, translation, scale);}graph.update();@@ -831,7 +853,10 @@ function stagePose(stagedState, time) {}const camera = sampled?.camera ? cameraPoseFrom(sampled.camera) : stagedState.recipe.camera;retainedMatrices(stagedState.parts);- return { graph, materialUpdates, camera, time, clothGeometries: sampledGeometries(stagedState, time) };+ const clothGeometries = sampledGeometries(stagedState, time);+ // Staged last: a pose pending on a decoded asset must be committed or discarded, so nothing above may throw after it.+ const assetClips = stagedState.assetRuntime.animators.length ? agentSceneModule('assets').stageAssetClips(stagedState.assetRuntime, graph, time) : null;+ return { graph, materialUpdates, camera, time, clothGeometries, assetClips };}// Cloth and particles replace the geometry of their own nodes at a sampled time; no node belongs to both.@@ -866,6 +891,13 @@ function publishPose(stagedState, pose) {update.holder.snapshot = update.snapshot;}publishSkinPoses(stagedState.skinStages);+ if (pose.assetClips) {+ pose.assetClips.commit();+ for (const part of stagedState.restParts) {+ const matrix = pose.assetClips.matrices.get(part.name);+ if (matrix) Float32Array.prototype.set.call(part.matrix, matrix);+ }+ }stagedState.renderCamera = pose.camera;stagedState.motionTime = pose.time;const nextParts = partsWithCloth(stagedState.restParts, pose.clothGeometries);@@ -874,6 +906,15 @@ function publishPose(stagedState, pose) {return partsChanged;}+// The recipe an agent wrote: without the geometries, materials and part nodes that placed assets generate.+function authoredRecipe(recipe) {+ const authored = structuredClone(recipe);+ authored.nodes = authored.nodes.filter(node => !node.assetPart);+ authored.geometries = authored.geometries.filter(geometry => geometry.type !== 'asset');+ authored.materials = authored.materials.filter(material => !material.assetSource);+ return authored;+}+function removeNode(candidate, operation) {knownKeys(operation, ['type', 'id', 'recursive'], 'operation');identifier(operation.id);@@ -910,8 +951,9 @@ function removeNode(candidate, operation) {}/** A bounded CPU authoring session. Render adapters must treat geometry as immutable. */-export function createAgentScene(input, inputLimits = {}) {+export function createAgentScene(input, inputLimits = {}, options = {}) {const limits = resolveLimits(inputLimits);+ const assetOutputCache = new Map();let state = null;let revision = 0;let topologyRevision = 0;@@ -965,6 +1007,9 @@ export function createAgentScene(input, inputLimits = {}) {function stage(inputRecipe, preferred = null, removedNodes = new Set(), removedMaterials = new Set()) {const recipe = normalizeRecipe(inputRecipe, limits);+ const assetRuntime = recipe.nodes.some(node => node.asset)+ ? agentSceneModule('assets').expandAssetPlacements(recipe, options.assets, limits, assetOutputCache)+ : NO_ASSETS;if (state) {retainedMatrices(state.parts);}@@ -979,7 +1024,7 @@ export function createAgentScene(input, inputLimits = {}) {const activeRecord = state?.geometryRecords.get(definition.id);const existing = [preferredRecord, activeRecord, availableRecords.get(signature)].find(record => record?.signature === signature);- return { definition, signature, existing, estimatedVertices: geometryEstimate(definition) };+ return { definition, signature, existing, estimatedVertices: definition.type === 'asset' ? 0 : geometryEstimate(definition) };});const residentStats = geometryStats(ownedRecords);const pendingPlans = plans.filter(plan => !plan.existing);@@ -1002,7 +1047,11 @@ export function createAgentScene(input, inputLimits = {}) {const geometryRecords = new Map();for (const plan of plans) {let record = plan.existing;- if (!record) {+ if (!record && plan.definition.type === 'asset') {+ // A decoded asset geometry is shared by every placement. Its size is bounded by the asset decoder, not by this scene's budget.+ const geometry = assetRuntime.geometryParts.get(plan.definition.id);+ record = Object.freeze({ signature: plan.signature, geometry, bounds: boundsFor(geometry, mat4.create()), vertices: 0, geometryBytes: 0, estimatedVertices: 0 });+ } else if (!record) {const geometry = Object.freeze(generateGeometry(plan.definition, Math.min(limits.maxVertices, 1_000_000)));const geometryBytes = Object.values(geometry).reduce((total, array) => total + array.byteLength, 0);const vertices = geometry.positions.length / 3;@@ -1039,7 +1088,8 @@ export function createAgentScene(input, inputLimits = {}) {const activeHandle = removedMaterials.has(material.id) ? null : state?.materialHandles.get(material.id);// The renderer keeps tag, blending, opacity and sidedness per batch, so a handle is reused only when all match.const existing = [preferredHandle, activeHandle].find(handle => handle && batchSignature(handle.holder.snapshot) === batchSignature(material));- const handle = existing ?? materialHandle(snapshot);+ const assetOutput = assetRuntime.materialOutputs.get(material.id);+ const handle = assetOutput ? assetMaterialHandle(snapshot, assetOutput, preferredHandle, activeHandle) : existing ?? materialHandle(snapshot);materialHandles.set(material.id, handle);}const activeParts = new Map(state?.sourceRestParts.map(part => [part.name, part]) ?? []);@@ -1048,13 +1098,15 @@ export function createAgentScene(input, inputLimits = {}) {const binding = skinBindings.get(node.id);const geometry = binding?.geometry ?? geometries.get(node.geometry);const material = materialHandles.get(node.material).output;+ const assetExtras = assetRuntime.partExtras.get(node.id);const activePart = removedNodes.has(node.id) ? null : activeParts.get(node.id);const existing = [activePart, preferredParts.get(node.id)]- .find(part => part?.geometry === geometry && part.material === material && part.skin === binding?.skin);+ .find(part => part?.geometry === geometry && part.material === material && part.skin === (assetExtras?.skin ?? binding?.skin) && part.morph === assetExtras?.morph);return existing ?? Object.freeze({name: node.id, geometry, material,matrix: new Float32Array(graph.getNode(node.id).worldMatrix),...(binding ? { skin: binding.skin } : {}),+ ...assetExtras,});});retainedMatrices(nextParts);@@ -1075,6 +1127,7 @@ export function createAgentScene(input, inputLimits = {}) {topologyChanged: Boolean(state && (restParts !== state.restParts || state.parts !== state.restParts)),stats: geometryStats(geometryRecords.values()),};+ stagedState.assetRuntime = assetRuntime;stagedState.localBounds = localBounds;stagedState.skinBindings = skinBindings;stagedState.skinStages = createSkinStages(skinBindings);@@ -1082,7 +1135,7 @@ export function createAgentScene(input, inputLimits = {}) {stagedState.physicsSampler = stagePhysics(recipe, geometryRecords);stagedState.clothSampler = stageCloth(recipe, geometryRecords);stagedState.particleSampler = stageParticles(recipe, geometryRecords);- const animated = Boolean(stagedState.motionSampler || stagedState.physicsSampler || stagedState.clothSampler || stagedState.particleSampler);+ const animated = Boolean(stagedState.motionSampler || stagedState.physicsSampler || stagedState.clothSampler || stagedState.particleSampler || assetRuntime.animators.length);stagedState.poseGraph = animated ? compile(recipe, geometries, localBounds, limits) : null;stagedState.initialPose = stagePose(stagedState, animated ? 0 : null);return stagedState;@@ -1243,8 +1296,8 @@ export function createAgentScene(input, inputLimits = {}) {if (time !== null && (!Number.isFinite(time) || time < 0 || time > 3600)) {throw new RangeError('Motion time must be null or within zero and 3600 seconds.');}- if (time !== null && !state.motionSampler && !state.physicsSampler && !state.clothSampler && !state.particleSampler) {- throw new RangeError('This procedural recipe has no motion, physics, cloth or particles.');+ if (time !== null && !state.motionSampler && !state.physicsSampler && !state.clothSampler && !state.particleSampler && !state.assetRuntime.animators.length) {+ throw new RangeError('This procedural recipe has no motion, physics, cloth, particles or placed asset clip.');}if (publishPose(state, stagePose(state, time))) {topologyRevision++;@@ -1261,7 +1314,7 @@ export function createAgentScene(input, inputLimits = {}) {return structuredClone(state.recipe.shadow);},exportRecipe() {- return structuredClone(state.recipe);+ return authoredRecipe(state.recipe);},/** Bone nodes at rest and a clip baked from motion, as `exportGlb` options. Leaves the pose where it was. */rigExport(options = {}) {@@ -1278,7 +1331,7 @@ export function createAgentScene(input, inputLimits = {}) {throw new RangeError('operations must contain 1 to maxOperations commands.');}const operations = copiedJson(inputOperations, limits.maxRecipeBytes);- const candidate = structuredClone(state.recipe);+ const candidate = authoredRecipe(state.recipe);const removedNodes = new Set();const removedMaterials = new Set();for (const operation of operations) {@@ -1474,7 +1527,7 @@ export function createAgentScene(input, inputLimits = {}) {if (options.ids !== undefined && (!Array.isArray(options.ids) || options.ids.length > limits.maxNodes)) {throw new RangeError('Inspection IDs exceed maxNodes.');}- const selected = options.ids === undefined ? state.recipe.nodes : options.ids.map(id => {+ const selected = options.ids === undefined ? state.recipe.nodes.filter(node => !node.assetPart) : options.ids.map(id => {identifier(id);const node = state.recipe.nodes.find(value => value.id === id);if (!node) {@@ -1504,6 +1557,7 @@ export function createAgentScene(input, inputLimits = {}) {physics: state.physicsSampler ? state.physicsSampler.report() : null,...(state.clothSampler ? { cloth: state.clothSampler.report() } : {}),...(state.particleSampler ? { particles: state.particleSampler.report() } : {}),+ ...(state.assetRuntime.placements.length ? { assets: agentSceneModule('assets').describeAssetPlacements(state.assetRuntime, state.graph, geometry => state.localBounds.get(geometry)) } : {}),...(state.bakeReport ? { bake: state.bakeReport } : {}),...(state.reflectionReport ? { reflections: state.reflectionReport } : {}),...(state.recipe.armatures ? { rig: rigReport(state.recipe, state.skinBindings) } : {}),@@ -1554,7 +1608,7 @@ export function createAgentScene(input, inputLimits = {}) {}const handle = Object.freeze({});checkpoints.set(handle, {- recipe: structuredClone(state.recipe),+ recipe: authoredRecipe(state.recipe),geometryRecords: new Map(state.geometryRecords),materialHandles: new Map(state.materialHandles),restParts: state.restParts,diff --git a/src/gltf.js b/src/gltf.jsindex 971da74b..39a648b8 100644--- a/src/gltf.js+++ b/src/gltf.js@@ -926,6 +926,8 @@ function convertMaterial(source, limits, maps, definition = {}) {normalScale: [definition.normalTexture?.scale ?? 1, definition.normalTexture?.scale ?? 1],occlusionStrength: source.aoMapIntensity,};+ // Recipe scenes override a placed asset's materials by this source name.+ if (typeof definition.name === 'string' && definition.name) material.name = definition.name.slice(0, 256);material.alphaMode = GLTF_ALPHA_MODES[definition.alphaMode ?? 'OPAQUE'];material.alphaCutoff = definition.alphaCutoff ?? 0.5;material.opacity = definition.pbrMetallicRoughness?.baseColorFactor?.[3] ?? 1;diff --git a/tests/agent-scene-assets.test.js b/tests/agent-scene-assets.test.jsnew file mode 100644index 00000000..50c8fe7f--- /dev/null+++ b/tests/agent-scene-assets.test.js@@ -0,0 +1,115 @@+import test from 'node:test';+import assert from 'node:assert/strict';+import { parseGltf } from '../src/gltf.js';+import { createAgentScene, loadAllAgentSceneModules } from '../src/agent-scene.js';+import { assetCopyKey, recipeAssetNeeds } from '../src/agent-scene-assets.js';+import { groupParts } from '../src/renderer.js';+import { skinnedStripAsset } from './fixtures/skinned-strip.js';++const ASSET_ID = 'ab'.repeat(32);+const OTHER_ID = 'cd'.repeat(32);++await loadAllAgentSceneModules();++async function strip(withName = true) {+ return parseGltf(skinnedStripAsset(document => {+ if (withName) document.materials[0].name = 'Skin';+ }));+}++async function loadedAssets(copies = 1) {+ const assets = new Map();+ for (const id of [ASSET_ID, OTHER_ID]) {+ for (let copy = 0; copy < copies; copy++) assets.set(assetCopyKey(id, copy), await strip());+ }+ return assets;+}++function recipe(nodes) {+ return {+ format: '67js.scene', schemaVersion: 1,+ geometries: [{ id: 'ground', type: 'box' }],+ materials: [{ id: 'grass', color: [0.2, 0.5, 0.2] }],+ nodes: [{ id: 'floor', geometry: 'ground', material: 'grass', scale: [20, 0.1, 20] }, ...nodes],+ };+}++test('ten placements of one asset share geometry, material and a draw batch', async () => {+ const nodes = Array.from({ length: 10 }, (_, index) => ({ id: `tree-${index}`, translation: [index * 2, 0, 0], asset: { id: ASSET_ID } }));+ nodes.push({ id: 'other', asset: { id: OTHER_ID } });+ const scene = createAgentScene(recipe(nodes), {}, { assets: await loadedAssets() });+ const placed = scene.parts.filter(part => part.name.startsWith('tree-'));+ assert.equal(placed.length, 10);+ assert.equal(new Set(placed.map(part => part.geometry)).size, 1);+ assert.equal(new Set(placed.map(part => part.material)).size, 1);+ assert.equal(new Set(placed.map(part => part.skin)).size, 1);+ assert.equal(placed[3].matrix[12], 6 + 1, 'the placement translation composes with the asset part matrix');+ const batches = groupParts(scene.parts);+ assert.equal(batches.length, 3, 'ground, ten copies, and the other asset');+ assert.equal(batches.find(batch => batch.length === 10).length, 10);+ const report = scene.inspect({ includeBounds: true });+ assert.equal(report.assets.length, 11);+ assert.equal(report.assets[0].assetId, ASSET_ID);+ assert.deepEqual(report.assets[0].clips.map(clip => clip.name), ['Bend', 'Move']);+ assert.deepEqual(report.assets[0].materials, ['Skin']);+ assert.ok(report.assets[0].bounds.max[1] > report.assets[0].bounds.min[1]);+ assert.equal(report.nodes.length, 12, 'generated part nodes stay out of the node list');+ assert.equal(scene.exportRecipe().nodes.length, 12);+ assert.equal(scene.exportRecipe().geometries.length, 1);+});++test('material overrides name the source material and stay shared between placements', async () => {+ const nodes = [+ { id: 'red-a', asset: { id: ASSET_ID, materials: [{ name: 'Skin', color: [1, 0, 0] }] } },+ { id: 'red-b', asset: { id: ASSET_ID, materials: [{ name: 'Skin', color: [1, 0, 0] }] } },+ { id: 'plain', asset: { id: ASSET_ID } },+ ];+ const scene = createAgentScene(recipe(nodes), {}, { assets: await loadedAssets() });+ const material = id => scene.parts.find(part => part.name === `${id}/0`).material;+ assert.deepEqual(Array.from(material('red-a').color), [1, 0, 0]);+ assert.equal(material('red-a'), material('red-b'));+ assert.notEqual(material('red-a'), material('plain'));+ assert.throws(() => createAgentScene(recipe([{ id: 'bad', asset: { id: ASSET_ID, materials: [{ name: 'Nope', color: [1, 0, 0] }] } }]), {}, { assets: new Map([[assetCopyKey(ASSET_ID, 0), null]]) }), /not loaded/);+ await assert.rejects(async () => createAgentScene(recipe([{ id: 'bad', asset: { id: ASSET_ID, materials: [{ name: 'Nope', color: [1, 0, 0] }] } }]), {}, { assets: await loadedAssets() }), /no material named "Nope"/);+});++test('a placed clip plays on its own time offset and a seek gives the same frame', async () => {+ const nodes = [+ { id: 'walker', translation: [3, 0, 0], asset: { id: ASSET_ID, clip: { index: 0, start: 0.5 } } },+ { id: 'late', asset: { id: ASSET_ID, clip: { index: 0, start: 2 } } },+ { id: 'still', asset: { id: ASSET_ID } },+ ];+ const needs = recipeAssetNeeds(recipe(nodes));+ assert.deepEqual(needs, [{ id: ASSET_ID, copies: 3 }]);+ const scene = createAgentScene(recipe(nodes), {}, { assets: await loadedAssets(3) });+ const joints = id => Array.from(scene.parts.find(part => part.name === `${id}/0`).skin.jointMatrices);+ const restJoints = joints('still');+ assert.deepEqual(joints('walker'), restJoints, 'before its start the clip holds its first frame');+ scene.sampleMotion(1);+ const walkerAtOne = joints('walker');+ assert.notDeepEqual(walkerAtOne, restJoints);+ assert.deepEqual(joints('late'), restJoints, 'the later placement has not started');+ assert.deepEqual(joints('still'), restJoints);+ scene.sampleMotion(0);+ scene.sampleMotion(1);+ assert.deepEqual(joints('walker'), walkerAtOne);+ assert.equal(scene.parts.find(part => part.name === 'walker/0').matrix[12], 3 + 1);+});++test('placements are bounded and need their assets', async () => {+ const many = Array.from({ length: 513 }, (_, index) => ({ id: `n${index}`, asset: { id: ASSET_ID } }));+ assert.throws(() => createAgentScene(recipe(many), {}, { assets: new Map() }), /at most 512/);+ assert.throws(() => createAgentScene(recipe([{ id: 'x', asset: { id: ASSET_ID } }])), /places catalog assets/);+ assert.throws(() => createAgentScene(recipe([{ id: 'x', geometry: 'ground', material: 'grass', asset: { id: ASSET_ID } }]), {}, { assets: new Map() }), /group/);+ assert.throws(() => createAgentScene(recipe([{ id: 'x', asset: { id: 'short' } }]), {}, { assets: new Map() }), /64 hexadecimal/);+});++test('apply can add and remove placed assets', async () => {+ const scene = createAgentScene(recipe([]), {}, { assets: await loadedAssets() });+ scene.apply([{ type: 'add-node', node: { id: 'late-tree', translation: [2, 0, 0], asset: { id: ASSET_ID } } }], { expectedRevision: 0 });+ assert.equal(scene.parts.filter(part => part.name.startsWith('late-tree')).length, 1);+ scene.apply([{ type: 'set-node', id: 'late-tree', translation: [5, 0, 0] }], { expectedRevision: 1 });+ assert.equal(scene.parts.find(part => part.name === 'late-tree/0').matrix[12], 6);+ scene.apply([{ type: 'remove-node', id: 'late-tree' }], { expectedRevision: 2 });+ assert.equal(scene.parts.filter(part => part.name.startsWith('late-tree')).length, 0);+});diff --git a/tests/support/preview-harness.mjs b/tests/support/preview-harness.mjsindex 0422eecd..0dd031da 100644--- a/tests/support/preview-harness.mjs+++ b/tests/support/preview-harness.mjs@@ -7,6 +7,7 @@ import { resolveAgentShadow, agentEnvironmentMap } from '../../src/agent-look.jsimport { agentSceneModule } from '../../src/agent-scene-modules.js';import { createAgentAssetScene } from '../../src/agent-asset.js';import { parseGltf } from '../../src/gltf.js';+import { assetCopyKey, recipeAssetNeeds } from '../../src/agent-scene-assets.js';import { BRANCH_LIMITS, createBranchStore, printableLabel } from '../../src/agent-branches.js';import { sessionProblem } from '../../src/agent-errors.js';@@ -73,7 +74,7 @@ export function previewHarness() {// The harness loads Manifold from node_modules directly, so the preview's served-file loader is ignored.setManifoldModuleLoader: () => {},needsPhysics, loadPhysicsEngine, physicsEngineLoaded, setPhysicsModuleLoader: () => {},- parseGltf, Uint8Array, atob, sessionProblem,+ parseGltf, Uint8Array, atob, sessionProblem, assetCopyKey, recipeAssetNeeds,applyProjection, mat4, resolveAgentShadow, agentEnvironmentMap, agentSceneModule, BRANCH_LIMITS, createBranchStore, printableLabel,Renderer67: FaultInjectedRenderer, skyOpenness: () => 1, fogSkyVisibility: () => null,// The fault-injected renderer has no floor part; the automatic floor is covered by agent-ground.test.js and the live smokes.