3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Warn when a particle system node's translation is ignored (#2053)
Nguyen Xuan An06a53871981c
diff --git a/changes/2053.md b/changes/2053.mdnew file mode 100644index 00000000..ff9b6ad8--- /dev/null+++ b/changes/2053.md@@ -0,0 +1 @@+- scene_inspect and scene_look warn with particle-node-transform-ignored when a particle system node is translated but emitter.position is unset, and the fix names the position to set.diff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex c8cbbdcb..2aa2e758 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -212,6 +212,7 @@ function viewProblems(record, camera, exposure, { placement = false } = {}) {if (record.scene.bakeStaleness) problems.push(...record.scene.bakeStaleness());problems.push(...textureProblems({ parts: record.scene.parts }));if (record.scene.flushLeftovers) problems.push(...record.scene.flushLeftovers());+ problems.push(...(record.scene.inspect({}).diagnostics ?? []).filter(problem => problem.kind === 'particle-node-transform-ignored'));if (exposure !== undefined) problems.push(...exposureProblems({ shares: sampleFrameShares(), exposure, environment: record.scene.environment }));return problems;}diff --git a/src/agent-particles.js b/src/agent-particles.jsindex 9ab4138d..19a64514 100644--- a/src/agent-particles.js+++ b/src/agent-particles.js@@ -528,6 +528,33 @@ function prepareHair(system, node, surfaceNode, surfaceGeometry, forces) {* Prepare the particles section. The result is a pure function of time: `sample(t)` returns the geometry of each* system node with every particle or strand placed from its seeded values, so a seek never replays earlier times.*/+function isOrigin(vector) {+ return !vector || vector.every(component => component === 0);+}++/**+ * A system node's own transform does not move its particles, only emitter.position does, so a node placed at the spark point+ * with a translation and no emitter.position births its particles at the world origin (#2053). A mesh emitter takes its place+ * from the mesh node, so it has nothing to ignore.+ */+function nodeTransformProblems(particles, recipe) {+ const nodesById = new Map(recipe.nodes.map(node => [node.id, node]));+ const reported = new Set();+ const problems = [];+ for (const system of particles.systems) {+ const node = nodesById.get(system.node);+ if (!node || reported.has(node.id) || isOrigin(node.translation) || system.emitter?.shape === 'mesh' || !isOrigin(system.emitter?.position)) continue;+ reported.add(node.id);+ const translation = Array.from(node.translation).map(component => Math.round(component * 1000) / 1000).join(', ');+ problems.push({+ kind: 'particle-node-transform-ignored', severity: 'warning', target: node.id,+ message: `Particle system node ${node.id} is translated to [${translation}], but a system node's transform does not move its particles, so they are born at the world origin.`,+ fix: `Set emitter.position to [${translation}] on the system with scene_apply set-particles, and leave the node translation at [0, 0, 0].`,+ });+ }+ return problems;+}+export function bakeAgentParticles(particles, recipe, geometries) {const nodes = new Map(recipe.nodes.map(node => [node.id, node]));const forces = { gravity: particles.gravity ?? DEFAULT_GRAVITY, wind: particles.wind ?? [0, 0, 0], fields: particles.fields ?? [] };@@ -546,6 +573,10 @@ export function bakeAgentParticles(particles, recipe, geometries) {return prepareEmitter(system, node, templates, forces, collisionSurfaceOf(system, nodes, geometries), meshSourceOf(system, nodes, geometries, systemIndex));});return Object.freeze({+ /** Warnings for a recipe that loads but does not do what its author likely meant. */+ diagnostics() {+ return nodeTransformProblems(particles, recipe);+ },sample(time) {return new Map(prepared.map(({ node, build }) => [node.id, worldToNodeLocal(build(time), nodeMatrix(node))]));},diff --git a/src/agent-scene.js b/src/agent-scene.jsindex 70258db9..a9c101d6 100644--- a/src/agent-scene.js+++ b/src/agent-scene.js@@ -2338,7 +2338,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {return result;});const resident = geometryStats(ownedGeometryRecords());- const diagnostics = [...recipeDiagnostics(state.recipe), ...closedRoomProblems(), ...staleBakeProblems(), ...(state.bakeSkipped ? [agentSceneModule('bake').bakeSkippedDiagnostic(state.bakeSkipped)] : []),...coplanarProblems()];+ const diagnostics = [...recipeDiagnostics(state.recipe), ...closedRoomProblems(), ...staleBakeProblems(), ...(state.bakeSkipped ? [agentSceneModule('bake').bakeSkippedDiagnostic(state.bakeSkipped)] : []),...coplanarProblems(), ...(state.particleSampler?.diagnostics() ?? [])];return {revision, topologyRevision,...(state.recipe.motion?.ik?.length ? { motionIk: agentSceneModule('motion').compileAgentMotion(state.recipe.motion, state.recipe).sweepIk() } : {}),diff --git a/tests/particle-node-transform.test.js b/tests/particle-node-transform.test.jsnew file mode 100644index 00000000..939926e3--- /dev/null+++ b/tests/particle-node-transform.test.js@@ -0,0 +1,38 @@+import './support/load-agent-scene-modules.mjs';+import test from 'node:test';+import assert from 'node:assert/strict';+import { createAgentScene } from '../src/agent-scene.js';++function recipeWith(nodeTranslation, system = {}) {+ const node = { id: 'sparks', geometry: 'speck', material: 'glow' };+ if (nodeTranslation) node.translation = nodeTranslation;+ return {+ format: 'crucible.scene', schemaVersion: 1,+ geometries: [{ id: 'speck', type: 'box', bevel: 0 }],+ materials: [{ id: 'glow', color: [1, 0.5, 0.1], emission: 4 }],+ nodes: [node],+ particles: { systems: [{ node: 'sparks', count: 100, rate: 30, lifetime: 2, speed: 3, ...system }] },+ };+}++function particleDiagnostics(recipe) {+ const inspection = createAgentScene(recipe).inspect({});+ return (inspection.diagnostics ?? []).filter(problem => problem.kind === 'particle-node-transform-ignored');+}++test('a translated system node without emitter.position says where its particles are born and what to set (#2053)', () => {+ const [problem] = particleDiagnostics(recipeWith([-1.5, 0.3, 0]));+ assert.equal(problem.target, 'sparks');+ assert.equal(problem.severity, 'warning');+ assert.match(problem.message, /world origin/);+ assert.match(problem.fix, /emitter\.position to \[-1\.5, 0\.3, 0\]/);+});++test('no particle diagnostic when the node sits at the origin, the emitter has a position or the emitter is a mesh', () => {+ assert.deepEqual(particleDiagnostics(recipeWith(null)), []);+ assert.deepEqual(particleDiagnostics(recipeWith([-1.5, 0.3, 0], { emitter: { shape: 'point', position: [-1.5, 0.3, 0] } })), []);+ const meshRecipe = recipeWith([2, 0, 0], { emitter: { shape: 'mesh', mesh: 'surface' } });+ meshRecipe.geometries.push({ id: 'plane', type: 'grid', segments: 2 });+ meshRecipe.nodes.push({ id: 'surface', geometry: 'plane', material: 'glow' });+ assert.deepEqual(particleDiagnostics(meshRecipe), []);+});