Skip to content

3D engine that AI agents drive

Give a placed asset's clip its own timeline (#2261)

Nguyen Xuan And796246ae96c
diff --git a/changes/2261.md b/changes/2261.md
new file mode 100644
index 00000000..0ff2138a
--- /dev/null
+++ b/changes/2261.md
@@ -0,0 +1 @@
+- A scene that places an asset clip plays it from `settings.animation` or a default-length render, with no motion track (#2261)
diff --git a/changes/2261.size.md b/changes/2261.size.md
new file mode 100644
index 00000000..c08c7d95
--- /dev/null
+++ b/changes/2261.size.md
@@ -0,0 +1,2 @@
+- scene:agent-scene+lazy: a placed asset clip gets its own timeline (clip lengths for render settings, a clearer empty-motion error), 159 bytes gzip, so a scene with an imported animation renders without a dummy motion track.
+- goal:agent-scene: the same change adds 22 bytes gzip to the core, a one-line scene method that lists the lengths of placed clips for the render job.
diff --git a/docs/agent-motion.md b/docs/agent-motion.md
index b1c8f331..ee80c0dd 100644
--- a/docs/agent-motion.md
+++ b/docs/agent-motion.md
@@ -461,7 +461,7 @@ A body node takes its pose from the recording. A node cannot have a body and a m
## Bounds and checks
The controller accepts durations between 0.1 and 30 seconds.
-A motion requires at least one track or driver (or an IK solver, constraint, layer, spring or drive); `tracks` can be left out of a motion made of drivers alone.
+A motion requires at least one track or driver (or an IK solver, constraint, layer, spring or drive); `tracks` can be left out of a motion made of drivers alone. An empty `tracks` array is refused. A placed `asset.clip` does not need a motion: it plays on scene time when a render job sets `settings.motion` (see agent-render-jobs).
It can contain at most 128 tracks, 64 keys per track, and 2048 keys in total.
Values and tangents must remain finite at Float32 precision.
The scene integration must also enforce its total recipe byte budget.
diff --git a/docs/agent-render-jobs.md b/docs/agent-render-jobs.md
index ea900b5e..86623ff6 100644
--- a/docs/agent-render-jobs.md
+++ b/docs/agent-render-jobs.md
@@ -321,6 +321,7 @@ The defaults are 24 fps and one second.
Images sample `animation.start` without requiring the default duration to fit the clip.
Stills and videos require the entire requested animation range to fit the selected clip.
A scene with no clips rejects `settings.animation` with an error that says so; drop `animation` or add a clip first.
+A scene recipe that places clips (`asset.clip`) counts as having them, one per placement in placement order, each as long as it needs to play once (its `start` plus its length at its `speed`). They play on scene time, the clock of `motion`, so no motion track is needed: `settings.animation { clip, start }` is the same as `settings.motion { start }`, and sending both is an error. A video or stills job with one of them and no `duration` runs as long as the longest placed clip, counted from `start`. A clip loops or holds on its own `asset.clip.loop`, so the render may run longer than one pass.
Renderer time defaults to `{ start: 0, rate: 1 }` and remains separate from animation sampling.
`progress(update)` accepts monotonic `frames` and a `maximumPendingFrames` value of zero or one.
diff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.js
index 3f5462fc..1d2dfef6 100644
--- a/scripts/agent-preview-browser.js
+++ b/scripts/agent-preview-browser.js
@@ -1004,7 +1004,7 @@ window.__agentPreview = {
const record = requireSession(sessionId);
if (record.scene.revision !== expectedRevision) throw new Error(staleRevisionMessage('render snapshot', expectedRevision, record.scene.revision));
return { sourceRevision: record.scene.revision, recipe: record.scene.exportRecipe(),
- clips: record.asset?.animations.map(clip => ({ duration: clip.duration })) ?? [] };
+ clips: record.asset ? record.asset.animations.map(clip => ({ duration: clip.duration })) : record.scene.placedClipEnds().map(duration => ({ duration })) };
},
suspend({ sessionId }) {
const record = lookupSession(sessionId);
diff --git a/scripts/agent-render-jobs.mjs b/scripts/agent-render-jobs.mjs
index ca493d79..12becfa4 100644
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@ -100,6 +100,19 @@ function bakedPhysicsDuration(recipe) {
return durations.length ? Math.max(...durations) : undefined;
}
+/** A scene that places clips plays them on scene time, so a film of one runs as long as its longest clip, counted from the start. */
+function placedClipDefaultDuration(input, clips, recipe, bakeSeconds) {
+ const asked = input.motion ?? input.animation;
+ if (!placesSceneClips(recipe, clips) || recipe.motion || bakeSeconds || input.kind === 'image' || !asked) return undefined;
+ const longest = Math.max(...clips.map(clip => clip.duration));
+ return Math.min(MAXIMUM_VIDEO_SECONDS, Math.max(0.1, longest - (Number(asked.start) || 0)));
+}
+
+/** In a scene recipe the snapshot clips are the placed asset clips, one per placement, each as long as it needs to play once. */
+function placesSceneClips(recipe, clips) {
+ return recipe?.format === 'crucible.scene' && clips.length > 0;
+}
+
function playsPhysics(recipe) {
return Boolean(recipe?.physics || recipe?.cloth || recipe?.particles);
}
@@ -128,7 +141,8 @@ function settingsFrom(input, clips = [], recipe) {
// A physics-only film runs as long as its bake, counted from the motion start.
const bakeSeconds = recipe?.format === 'crucible.scene' && !recipe.motion ? bakedPhysicsDuration(recipe) : undefined;
const bakeDefault = bakeSeconds && input.kind !== 'image' && input.motion ? Math.max(0.1, bakeSeconds - (Number(input.motion.start) || 0)) : undefined;
- const defaultDuration = timelineStart === undefined || input.kind === 'image' ? bakeDefault ?? 1 : filmTimelineDuration(recipe.timeline) - timelineStart;
+ const clipDefault = placedClipDefaultDuration(input, clips, recipe, bakeSeconds);
+ const defaultDuration = timelineStart === undefined || input.kind === 'image' ? bakeDefault ?? clipDefault ?? 1 : filmTimelineDuration(recipe.timeline) - timelineStart;
const framesAsked = stillsFrameCountFrom(input);
// A stills job that sets frames samples the motion clock every 1 / fps seconds, like a video; its duration is the span of those samples.
const duration = framesAsked === undefined
@@ -184,8 +198,14 @@ function settingsFrom(input, clips = [], recipe) {
if (clips.length === 0) throw new RangeError('animation needs an animation clip, and this scene has none. Drop animation from the settings, or add a clip to the scene first.');
const clip = boundedNumber(input.animation.clip, 0, clips.length - 1, 'clip', true);
const start = boundedNumber(input.animation.start ?? 0, 0, clips[clip].duration, 'animation start');
- if (input.kind !== 'image' && start + duration > clips[clip].duration) throw new RangeError('Animation range exceeds the selected clip duration.');
- result.animation = { clip, start };
+ if (placesSceneClips(recipe, clips)) {
+ // Placed clips play on scene time, the clock of motion, and loop or hold on their own settings: animation.start is the motion start.
+ if (input.motion !== undefined) throw new TypeError('Send either motion or animation for a scene that places clips: both set the scene time the clips play on. Keep motion.start.');
+ result.motion = { start };
+ } else {
+ if (input.kind !== 'image' && start + duration > clips[clip].duration) throw new RangeError('Animation range exceeds the selected clip duration.');
+ result.animation = { clip, start };
+ }
}
if (input.rendererTime !== undefined) {
objectKeys(input.rendererTime, ['start', 'rate'], 'rendererTime');
diff --git a/src/agent-motion.js b/src/agent-motion.js
index 732e206c..a073fe53 100644
--- a/src/agent-motion.js
+++ b/src/agent-motion.js
@@ -528,7 +528,10 @@ export function normalizeAgentMotion(input, recipe) {
const inputTracks = input.tracks ?? [];
denseArray(inputTracks, 128, 'Motion tracks');
if (!inputTracks.length && !input.layers?.length && !input.ik?.length && !input.springs && !input.constraints?.length && !input.drivers?.length && !drive) {
- throw invalidField('motion', input, 'at least one track or driver (or an IK solver, constraint, layer, spring or drive), such as { "duration": 1, "tracks": [...] } or { "duration": 1, "drivers": [...] }; use null to clear it');
+ const placedClipHint = (recipe.nodes ?? []).some(node => node.asset?.clip)
+ ? '. A placed asset.clip needs no motion: leave motion out, and a render job plays the clip with settings.motion { "start": 0 } or settings.animation'
+ : '';
+ throw invalidField('motion', input, `at least one track or driver (or an IK solver, constraint, layer, spring or drive), such as { "duration": 1, "tracks": [...] } or { "duration": 1, "drivers": [...] }; use null to clear it${placedClipHint}`);
}
const nodes = new Set((recipe.nodes ?? []).map(node => node.id));
// A material track may also name the id of an asset.materials override, which gives a placed asset's material a handle.
diff --git a/src/agent-scene-assets.js b/src/agent-scene-assets.js
index ecaca450..e06dcadf 100644
--- a/src/agent-scene-assets.js
+++ b/src/agent-scene-assets.js
@@ -400,6 +400,16 @@ export function clipTimeAt(clip, duration, time) {
return clip.loop ? elapsed % duration : Math.min(elapsed, duration);
}
+/**
+ * Scene seconds at which each placed clip finishes one pass, in placement order: its start plus its length at its speed.
+ * A render job reads these as the lengths of the scene's clips, so a scene that places a clip has a timeline of its own.
+ */
+export function placedClipEnds(runtime) {
+ return runtime.placements
+ .filter(record => record.clip)
+ .map(record => record.clip.start + record.asset.animations[record.clip.index].duration / record.clip.speed);
+}
+
/**
* 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.
diff --git a/src/agent-scene.js b/src/agent-scene.js
index c274d27a..23b1568f 100644
--- a/src/agent-scene.js
+++ b/src/agent-scene.js
@@ -2114,6 +2114,10 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {
get motionTime() {
return state.motionTime;
},
+ /** Seconds each placed asset clip needs to play once, in placement order: the clips a render job can play on scene time. */
+ placedClipEnds() {
+ return state.assetRuntime.animators.length ? agentSceneModule('assets').placedClipEnds(state.assetRuntime) : [];
+ },
sequenceTextures() {
return state.sequences;
},
diff --git a/tests/agent-scene-assets.test.js b/tests/agent-scene-assets.test.js
index a7b5274c..0f3825ae 100644
--- a/tests/agent-scene-assets.test.js
+++ b/tests/agent-scene-assets.test.js
@@ -4,6 +4,7 @@ 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 { normalizeJobSettings } from '../scripts/agent-render-jobs.mjs';
import { skinnedStripAsset } from './fixtures/skinned-strip.js';
const ASSET_ID = 'ab'.repeat(32);
@@ -135,3 +136,34 @@ test('an asset that is not in the pool is refused by id, and the 16 distinct ass
scene.provideAssets(pool);
assert.throws(() => scene.apply(many, { expectedRevision: scene.revision }), /at most 512 assets, 16 different ones/);
});
+
+test('a placed clip gives the scene a timeline: render settings play it with no motion track (#2261)', async () => {
+ const nodes = [{ id: 'walker', asset: { id: ASSET_ID, clip: { index: 0, start: 0.5, speed: 2 } } }, { id: 'still', asset: { id: ASSET_ID } }];
+ const scene = createAgentScene(recipe(nodes), {}, { assets: await loadedAssets(3) });
+ assert.equal(scene.exportRecipe().motion, undefined, 'the recipe has no motion track');
+ const clipLength = scene.inspect().assets[0].clips[0].duration;
+ const clipEnds = scene.placedClipEnds();
+ assert.deepEqual(clipEnds, [0.5 + clipLength / 2]);
+ const joints = id => Array.from(scene.parts.find(part => part.name === `${id}/0`).skin.jointMatrices);
+ const first = joints('walker');
+ const settings = { kind: 'video', width: 64, height: 64, fps: 4 };
+ const clips = clipEnds.map(duration => ({ duration }));
+ const sceneRecipe = scene.exportRecipe();
+ const played = normalizeJobSettings({ ...settings, animation: { clip: 0, start: 0 } }, clips, sceneRecipe);
+ assert.deepEqual(played.motion, { start: 0 });
+ assert.equal(played.animation, undefined);
+ assert.equal(played.duration, clipEnds[0], 'a video with no duration runs as long as the placed clip');
+ scene.sampleMotion(played.motion.start + 0.75);
+ const later = joints('walker');
+ assert.notDeepEqual(later, first, 'the clip pose changes over the render time');
+ assert.throws(() => normalizeJobSettings({ ...settings, animation: { clip: 0 }, motion: { start: 0 } }, clips, sceneRecipe), /either motion or animation/);
+ assert.throws(() => normalizeJobSettings({ ...settings, animation: { clip: 0 } }, [], sceneRecipe), /this scene has none/);
+ assert.equal(normalizeJobSettings(settings, clips, sceneRecipe).duration, 1, 'a scene that plays no clip keeps the one second default');
+ assert.deepEqual(createAgentScene(recipe([]), {}).placedClipEnds(), []);
+});
+
+test('an empty motion on a scene that places a clip says how to play the clip', async () => {
+ const nodes = [{ id: 'walker', asset: { id: ASSET_ID, clip: { index: 0 } } }];
+ const scene = createAgentScene(recipe(nodes), {}, { assets: await loadedAssets(2) });
+ assert.throws(() => scene.apply([{ type: 'set-motion', motion: { duration: 1, tracks: [] } }], { expectedRevision: 0 }), /needs no motion: leave motion out/);
+});