Skip to content

3D engine that AI agents drive

Accept the morph motion track in scene_create (#2128)

Nguyen Xuan An34881697c589
diff --git a/changes/2128.md b/changes/2128.md
new file mode 100644
index 00000000..11a089f0
--- /dev/null
+++ b/changes/2128.md
@@ -0,0 +1 @@
+- `scene_create` accepts the `morph` motion track that `set-motion` and docs/mesh.md document, and its kind list now comes from the backend (#2128).
diff --git a/scripts/mcp-server.mjs b/scripts/mcp-server.mjs
index c92fb7d4..848272ec 100644
--- a/scripts/mcp-server.mjs
+++ b/scripts/mcp-server.mjs
@@ -1,4 +1,5 @@
import { answerCapabilities, MAX_TOPICS_PER_CALL } from './capabilities-topics.mjs';
+import { MOTION_TRACK_KINDS } from '../src/agent-motion.js';
import { BRANCH_NAME_PATTERN } from '../src/agent-branches.js';
import { TEXTURE_SEQUENCE_LIMITS } from '../src/texture-sequence-limits.js';
import { readEnvironmentVariable } from '../src/environment-variable.js';
@@ -624,9 +625,11 @@ const motionTrackProperties = {
node: ['translation', 'rotation', 'scale'],
material: ['color', 'emissiveColor', 'emission', 'metallic', 'roughness'],
camera: ['eye', 'target', 'fov', 'roll'],
+ morph: ['weight'],
geometry: ['oceanTime'],
};
-const motionTrackKinds = [...Object.keys(motionTrackProperties), 'light', 'sun', 'environment', 'effects'];
+// The backend's list, so scene_create and set-motion accept the same kinds.
+const motionTrackKinds = MOTION_TRACK_KINDS;
const motionTrackFields = ['kind', 'id', 'property', 'interpolation', 'keyframes', 'extrapolation', 'modifiers'];
// A union reports only "Invalid input"; name the field and the allowed ones the way set-motion does.
function motionTrackUnionMessage(issue) {
@@ -662,6 +665,7 @@ const motion = z.strictObject({
motionTrack('camera', 'target', vector3, vector3),
motionTrack('camera', 'fov', finite.gt(0).lt(180), finite),
motionTrack('camera', 'roll', finite, finite),
+ motionTrack('morph', 'weight', unit, finite),
motionTrack('geometry', 'oceanTime', finite.min(-1e6).max(1e6), finite),
lookTrack,
], { error: motionTrackUnionMessage })).max(128).optional().describe('Keyframe tracks; leave out for a motion made only of drivers, ik or constraints.'),
diff --git a/src/agent-motion.js b/src/agent-motion.js
index c3988406..81e7f1ce 100644
--- a/src/agent-motion.js
+++ b/src/agent-motion.js
@@ -38,6 +38,8 @@ const PROPERTIES = {
// distortionStrength and flashIntensity are gains from 0 to 1 on every source of the distortion and flash steps.
effects: { exposure: 1, focusDistance: 1, distortionStrength: 1, flashIntensity: 1 },
};
+// Every kind a motion track may have; the MCP schema and its error message take this list so they cannot drift from the backend.
+export const MOTION_TRACK_KINDS = Object.freeze(Object.keys(PROPERTIES));
// Kinds with one target in the scene, so a track names no ID.
const SINGLETON_KINDS = new Set(['camera', 'sun', 'environment', 'effects']);
const LOOK_KINDS = new Set(['light', 'sun', 'environment', 'effects']);
diff --git a/tests/mcp-recipe-round-trip.test.js b/tests/mcp-recipe-round-trip.test.js
index 254f6f0b..96eb9751 100644
--- a/tests/mcp-recipe-round-trip.test.js
+++ b/tests/mcp-recipe-round-trip.test.js
@@ -5,6 +5,7 @@ import { Client } from '@modelcontextprotocol/client';
import { InMemoryTransport } from '@modelcontextprotocol/server';
import { createAgentMcpServer } from '../scripts/mcp-server.mjs';
import { walkerRecipe } from '../bench/agent-modeling/walker.mjs';
+import { MOTION_TRACK_KINDS } from '../src/agent-motion.js';
import { createAgentScene, loadPhysicsEngine, AGENT_SCENE_CAPABILITIES } from '../src/agent-scene.js';
await loadPhysicsEngine();
@@ -51,7 +52,7 @@ async function withRoundTripClient(use) {
await server.connect(serverTransport);
await client.connect(clientTransport);
try {
- return await use(client);
+ return await use(client, () => scene);
} finally {
await client.close();
await server.close();
@@ -188,7 +189,7 @@ test('scene_create names the valid kinds and properties for a motion track with
const keyframes = [{ time: 0, value: [0, 0, 0] }];
const createdWith = track => call(client, 'scene_create', { recipe: oneBoxRecipe({ motion: { duration: 1, tracks: [track] } }) });
const missingKind = await createdWith({ id: 'a', property: 'translation', keyframes });
- assert.match(missingKind.text, /needs kind \(node, material, camera, geometry, light, sun, environment, effects\)/);
+ assert.match(missingKind.text, /needs kind \(node, material, camera, morph, geometry, light, sun, environment, effects\)/);
const wrongKind = await createdWith({ kind: 'sky', id: 'a', property: 'translation', keyframes });
assert.match(wrongKind.text, /Unknown motion track kind: "sky"\. Kinds: node, material/);
const wrongProperty = await createdWith({ kind: 'node', id: 'a', property: 'bogus', keyframes });
@@ -196,6 +197,38 @@ test('scene_create names the valid kinds and properties for a motion track with
});
});
+function morphTrackRecipe() {
+ return {
+ format: 'crucible.scene', schemaVersion: 1,
+ geometries: [{ id: 'face', type: 'mesh', base: { type: 'box', bevel: 0, subdivisions: 2 }, shapeKeys: [{ name: 'lift', offsets: [{ select: { tag: 'top' }, offset: [0, 0.5, 0] }] }] }],
+ materials: [{ id: 'skin' }],
+ nodes: [{ id: 'head', geometry: 'face', material: 'skin' }],
+ camera: { eye: [3, 2, 4], target: [0, 0.5, 0], fov: 45 },
+ motion: { duration: 2, tracks: [{ kind: 'morph', id: 'lift', property: 'weight', keyframes: [{ time: 0, value: 0 }, { time: 1, value: 1 }] }] },
+ };
+}
+
+test('scene_create accepts a morph motion track and the shape key weight animates', async () => {
+ await withRoundTripClient(async (client, currentScene) => {
+ const created = await call(client, 'scene_create', { recipe: morphTrackRecipe() });
+ assert.notEqual(created.isError, true, created.text);
+ const weightAt = time => {
+ currentScene().sampleMotion(time);
+ return Array.from(currentScene().parts.find(part => part.morph).morph.weights)[0];
+ };
+ assert.equal(weightAt(0), 0);
+ assert.equal(weightAt(1), 1);
+ });
+});
+
+test('scene_create takes every motion track kind the backend lists', async () => {
+ assert.deepEqual([...MOTION_TRACK_KINDS], ['node', 'material', 'camera', 'morph', 'geometry', 'light', 'sun', 'environment', 'effects']);
+ await withRoundTripClient(async client => {
+ const wrongKind = await call(client, 'scene_create', { recipe: oneBoxRecipe({ motion: { duration: 1, tracks: [{ kind: 'sky', id: 'a', property: 'x', keyframes: [{ time: 0, value: 0 }] }] } }) });
+ assert.match(wrongKind.text, new RegExp(`Kinds: ${MOTION_TRACK_KINDS.join(', ')}\.`));
+ });
+});
+
const MODIFIER_EXAMPLES = [
{ type: 'cycles', before: 'mirror', after: 'offset', beforeCount: 2, afterCount: 3 },
{ type: 'stepped', step: 0.2, offset: 0.05 },