3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Guard downstream game asset scans (#2623)
Veeramanikandanr48ec645ccba253
diff --git a/changes/2623.md b/changes/2623.mdindex bc5ddab6..50868c5e 100644--- a/changes/2623.md+++ b/changes/2623.md@@ -1 +1 @@-- The initial placed-asset scan now skips a malformed `nodes` list, a null node or a non-list `game.npcs`, so the recipe validator names the field instead of a raw `TypeError` (#2623)+- The placed-asset scans now skip a malformed `nodes` list, a null node or a non-list `game.npcs`, so validation names the field before any asset load instead of a raw `TypeError` (#2623)diff --git a/docs/game.md b/docs/game.mdindex 1e5edfea..2ba38564 100644--- a/docs/game.md+++ b/docs/game.md@@ -118,7 +118,7 @@ The `puzzle` sample of `scripts/smoke-game-web.mjs` is two plank crates, two mar- An NPC needs `rootMotion` and a number parameter `speed`. Its path follower sets `speed`, so idle, walk and run blend; it moves by the root motion, turns at corners and stops at the last of up to 256 `[x, z]` waypoints, where `speed` returns to 0. `cruiseSpeed` is 2.2 by default; `yaw` and `footOffset` work as for the player. Each NPC node is separate from the player and the other NPCs.- Root travel along +Z works as written; for clips whose root travels -Z set `rootMotion.facing` to `"-z"`.-A wrong field is refused with its path and the values to use, for example `player.animation.clips.walk.tracks[0].target names "Ghost", which is not a child node of the character`. `window.__game.animation` and `window.__game.npcs` expose the graphs. A malformed `nodes` or `npcs` table is skipped by the initial asset scan so validation can name the field.+A wrong field is refused with its path and the values to use, for example `player.animation.clips.walk.tracks[0].target names "Ghost", which is not a child node of the character`. `window.__game.animation` and `window.__game.npcs` expose the graphs. A malformed `nodes` or `npcs` table is skipped by the placed-asset scan so validation can name the field before any asset load.### A placed characterdiff --git a/src/agent-scene-assets.js b/src/agent-scene-assets.jsindex 896713dd..a0619b4a 100644--- a/src/agent-scene-assets.js+++ b/src/agent-scene-assets.js@@ -183,7 +183,9 @@ export function visitPlacements(value, visit, depth = 0) {const placement = value.asset;if (placement && typeof placement === 'object') visit(placement);for (const [key, child] of Object.entries(value)) {- if (key !== 'asset') visitPlacements(child, visit, depth + 1);+ if (key === 'asset') continue;+ if ((key === 'nodes' || key === 'npcs') && !Array.isArray(child)) continue;+ visitPlacements(child, visit, depth + 1);}}diff --git a/src/game-assets.js b/src/game-assets.jsindex 59f2cfed..91531500 100644--- a/src/game-assets.js+++ b/src/game-assets.js@@ -11,7 +11,8 @@ const ASSET_ID = /^[a-f0-9]{64}$/;/** The ids of every catalog asset the game needs: the placed ones and the sources of its animation clips. */export function gameAssetIds(recipe) {const ids = new Set(recipeAssetNeeds(recipe).map(need => need.id));- const animations = [recipe.game?.player?.animation, ...(recipe.game?.npcs ?? []).map(npc => npc.animation)];+ const npcs = Array.isArray(recipe.game?.npcs) ? recipe.game.npcs : [];+ const animations = [recipe.game?.player?.animation, ...npcs.map(npc => npc?.animation)];for (const animation of animations) {for (const clip of Object.values(animation?.clips ?? {})) {const id = clip?.from?.asset;diff --git a/tests/agent-scene-assets.test.js b/tests/agent-scene-assets.test.jsindex c7d6cec6..7cba9bbc 100644--- a/tests/agent-scene-assets.test.js+++ b/tests/agent-scene-assets.test.js@@ -3,6 +3,7 @@ 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 { gameAssetIds } from '../src/game-assets.js';import { groupParts } from '../src/renderer.js';import { normalizeJobSettings } from '../scripts/agent-render-jobs.mjs';import { skinnedStripAsset } from './fixtures/skinned-strip.js';@@ -75,9 +76,15 @@ test('material overrides name the source material and stay shared between placem});test('recipeAssetNeeds skips a malformed node list, null node and non-list npcs (#2623)', () => {+ const asset = { id: ASSET_ID };assert.deepEqual(recipeAssetNeeds({ nodes: {} }), []);assert.deepEqual(recipeAssetNeeds({ nodes: [null] }), []);assert.deepEqual(recipeAssetNeeds({ game: { npcs: {} } }), []);+ assert.deepEqual(recipeAssetNeeds({ nodes: { asset } }), []);+ assert.deepEqual(recipeAssetNeeds({ game: { npcs: { asset } } }), []);+ assert.deepEqual(recipeAssetNeeds({ nodes: [{ asset }], game: { npcs: { asset } } }), [{ id: ASSET_ID, copies: 1 }]);+ assert.deepEqual(gameAssetIds({ game: { npcs: {} } }), []);+ assert.deepEqual(gameAssetIds({ game: { npcs: [null] } }), []);});test('a placed clip plays on its own time offset and a seek gives the same frame', async () => {