3D engine that AI agents drive
Clip strips: start, scale, repeat, fades, extend and blend mode on motion layers (#693)
Nguyen Xuan An587a8468edd8
diff --git a/changes/693.md b/changes/693.mdnew file mode 100644index 00000000..befba728--- /dev/null+++ b/changes/693.md@@ -0,0 +1 @@+- Clip layers on an imported asset take a `strip` with start, scale, repeat, blend in and out, extend and blend mode, so a walk repeated three times can crossfade into an idle (#693)diff --git a/changes/693.size.md b/changes/693.size.mdnew file mode 100644index 00000000..8bdfd30e--- /dev/null+++ b/changes/693.size.md@@ -0,0 +1 @@+- scene:agent-scene+lazy: clip strips (start, scale, repeat, fades, extend, add) are an animation capability the lead approved; they cost 701 bytes gzip in the lazy asset path and no tool schema bytesdiff --git a/docs/agent-motion.md b/docs/agent-motion.mdindex 36c5e9d6..b248d8e5 100644--- a/docs/agent-motion.md+++ b/docs/agent-motion.md@@ -152,6 +152,7 @@ each blending over the pose so far, before tracks and IK:| `additive`, `reference` | Add the clip's change from `reference` seconds instead of replacing the pose || `bones` | Retarget by name: `{ "UpperArmR": "node-20" }` makes the clip's track for `UpperArmR` move that node of this asset. Up to 64 entries; the clip must have the track || `morph` | `false` leaves morph weights alone. Default: the clip's morph tracks play |+| `strip` | Places the clip on the timeline in place of `speed`, `offset` and `loop`: `{ start, scale, repeat, end, blendIn, blendOut, extend, blend }`. `{ "repeat": 3 }` plays three cycles; an overlapping strip with `blendIn` crossfades. See [clip strips](animation-mixer.md#clip-strips) |```json"motion": { "duration": 2, "loop": true, "layers": [diff --git a/docs/animation-mixer.md b/docs/animation-mixer.mdindex b3502088..b9270f9f 100644--- a/docs/animation-mixer.md+++ b/docs/animation-mixer.md@@ -80,6 +80,33 @@ Mixer matrices must be affine transforms with positive scale and no shear.Tracked material properties must start in their valid domains. Missing emission defaults to zero.The mixer owns registered properties during playback, so external writes do not change its captured base pose.+## Clip strips++A recipe's `motion.layers` entry for an imported asset takes a `strip`, which places its clip on the motion timeline as an animation editor does. The mixer class above works on rigid parts; strips work on the skeleton and morph weights of an asset, through the same layers.++| Field | Meaning |+| --- | --- |+| `start` | Motion time in seconds where the strip begins, -600 to 600, default 0 |+| `scale` | Stretches the clip in time: 2 plays it at half speed. 0.05 to 20, default 1 |+| `repeat` | Cycles of the stretched clip, 0.05 to 100, fractions allowed, default 1. The strip ends at `start + clip duration * scale * repeat` |+| `end` | Instead of `repeat`: the time the strip stops, which sets a fractional repeat. Give one of the two |+| `blendIn`, `blendOut` | Linear fade of the weight over this many seconds at the start and the end. Together at most the strip's length |+| `extend` | What the strip does outside its span: `nothing` (default), `hold` (first pose before, last pose after) or `holdForward` (last pose after only). A hold keeps the weight the strip has at that end, so a strip with `blendOut` fades away and stays gone |+| `blend` | `replace` (default) blends over the pose below by the weight; `add` adds the clip's change from its `reference` time, like `additive` |++The strip's fade multiplies the layer's `weight`. The strip owns the timing, so a layer with a `strip` takes no `speed`, `offset` or `loop`. Each cycle plays the clip from its first to its last pose, and the clip holds its ends. Layers apply in order, so a later strip blends over an earlier one.++To crossfade, overlap two strips: the later one has a `blendIn` equal to the overlap, and the earlier one ends when the fade is complete, with no `blendOut`. A walk repeated three times, then fading into an idle:++```json+"layers": [+ { "clip": 10, "strip": { "repeat": 3 } },+ { "clip": 2, "strip": { "start": 2.375, "blendIn": 0.5 } }+]+```++Sampling is a pure function of the time, so a seek equals playing. A motion holds at most 8 layers, so at most 8 strips. Every field is bounded and refused with its path and the range to pass. In code, a skeleton pose layer takes a `clipTime(time)` function beside its `weight(time)` function for the same effect ([skeleton pose](skeleton-pose.md)).+## API design choice| Shape | Evaluation | Tradeoff |diff --git a/src/agent-asset.js b/src/agent-asset.jsindex 64bcb7e3..d72d5bb2 100644--- a/src/agent-asset.js+++ b/src/agent-asset.js@@ -6,6 +6,7 @@ import { fitPerspectiveDistance } from './camera.js';import { validateSkinGeometry, validateSkinPose } from './skinning.js';import { validateMorphGeometry, validateMorphTransform } from './morph.js';import * as agentMotion from './agent-motion.js';+import { compileClipStrip } from './clip-strip.js';import { clipLayerContextFromAsset, retargetSourceFromAsset } from './agent-clip-layers.js';import { retargetAssetClip, retargetReport } from './agent-retarget.js';import { createFootLock } from './foot-lock.js';@@ -592,16 +593,29 @@ export function createAgentAssetScene(asset, inputRecipe, { sources } = {}) {return [...byPart].map(([part, weights]) => ({ part, weights }));}+ /**+ * A strip times its layer: the fade envelope multiplies the layer's weight and the strip maps motion time to clip+ * time. The clip holds its ends, since the strip does the repeating.+ */+ function stripTiming(layer) {+ if (!layer.strip) return { loop: layer.loop !== false, timing: {} };+ const duration = layer.from ? clipLayerContext.external.get(layer.from.asset).clips[layer.from.clip].duration : asset.animations[layer.clip].duration;+ const compiled = compileClipStrip(layer.strip, duration);+ const base = layer.weight ?? 1;+ return { loop: false, timing: { weight: time => base * compiled.weight(time), clipTime: compiled.clipTime } };+ }+/** Layers of the motion as definitions for the pose code: decoded clips, renamed by `bones`, with their morph tracks. */function layerDefinitions(layers) {return layers.map(layer => {- const loop = layer.loop !== false;- if (layer.from) return { clip: retargetedLayerClip(layer, loop), weight: layer.weight, speed: layer.speed, offset: layer.offset, additive: layer.additive, reference: layer.reference, mask: layer.mask };+ const { loop, timing } = stripTiming(layer);+ const common = { weight: layer.weight, speed: layer.speed, offset: layer.offset, additive: layer.additive, reference: layer.reference, mask: layer.mask, ...timing };+ if (layer.from) return { clip: retargetedLayerClip(layer, loop), ...common };const animation = asset.animations[layer.clip];return {clip: clipFromGltfAnimation(animation, { loop, rename: layer.bones }),...(layer.morph === false ? {} : { morphs: morphClipFromGltfAnimation(animation, { loop }) }),- weight: layer.weight, speed: layer.speed, offset: layer.offset, additive: layer.additive, reference: layer.reference, mask: layer.mask,+ ...common,};});}diff --git a/src/agent-clip-layers.js b/src/agent-clip-layers.jsindex 79155a6c..4f52bef2 100644--- a/src/agent-clip-layers.js+++ b/src/agent-clip-layers.js@@ -1,6 +1,7 @@import { bounded, denseArray, knownKeys } from './motion-validation.js';import { retargetReport } from './agent-retarget.js';import { invalidField } from './field-error.js';+import { STRIP_BLENDS, STRIP_EXTENDS } from './clip-strip.js';// Clip layers for an imported asset's motion: play clips the file ships, blend them over each other, and limit each to// some bones. Agent input is untrusted plain data, so everything here is named, bounded and checked against the asset.@@ -11,6 +12,11 @@ const MAX_BONE_MAP_ENTRIES = 64;const MAX_NAME_LENGTH = 128;const MAX_LAYER_SPEED = 8;const MAX_LAYER_OFFSET = 30;+const MAX_STRIP_TIME = 600;+const MIN_STRIP_SCALE = 0.05;+const MAX_STRIP_SCALE = 20;+const MIN_STRIP_REPEAT = 0.05;+const MAX_STRIP_REPEAT = 100;/*** What the layers are checked against: `clips` (`{ duration, targets }` per clip, the node names its tracks move) and@@ -94,10 +100,52 @@ function normalizedSource(input, context, label, path) {return { from: { asset: input.asset.toLowerCase(), clip: input.clip }, clip };}+function oneOf(value, allowed, path) {+ if (!allowed.includes(value)) throw invalidField(path, value, `one of ${allowed.join(', ')}`);+ return value;+}++/**+ * A strip places the layer's clip on the motion timeline. `end` and `repeat` both say how long it plays, so one at+ * most; `end` becomes a (maybe fractional) repeat count of the stretched clip.+ */+function normalizedStrip(input, layer, clip, position) {+ const label = `Motion layer ${position} strip`;+ const path = `motion.layers[${position}].strip`;+ knownKeys(input, ['start', 'end', 'scale', 'repeat', 'blendIn', 'blendOut', 'extend', 'blend'], label);+ for (const field of ['speed', 'offset', 'loop']) {+ if (layer[field] !== undefined) throw invalidField(`motion.layers[${position}].${field}`, layer[field], 'a field left out, since a strip times the clip with its own start, scale and repeat');+ }+ if (!(clip.duration > 0)) throw invalidField(`${path}`, input, 'a field left out, since this clip has no length to place');+ if (input.end !== undefined && input.repeat !== undefined) throw invalidField(`${path}.end`, input.end, 'end or repeat, not both: end stops the strip at a time, repeat counts its cycles');+ const strip = {+ start: bounded(input.start ?? 0, -MAX_STRIP_TIME, MAX_STRIP_TIME, `${label} start`),+ scale: bounded(input.scale ?? 1, MIN_STRIP_SCALE, MAX_STRIP_SCALE, `${label} scale`),+ };+ if (input.end !== undefined) {+ const end = bounded(input.end, -MAX_STRIP_TIME, MAX_STRIP_TIME, `${label} end`);+ if (end <= strip.start) throw invalidField(`${path}.end`, end, `a time after start ${strip.start}`);+ strip.repeat = (end - strip.start) / (clip.duration * strip.scale);+ } else {+ strip.repeat = input.repeat ?? 1;+ }+ bounded(strip.repeat, MIN_STRIP_REPEAT, MAX_STRIP_REPEAT, input.end !== undefined ? `${label} end (as ${strip.repeat} repeats of the clip)` : `${label} repeat`);+ const length = clip.duration * strip.scale * strip.repeat;+ strip.blendIn = bounded(input.blendIn ?? 0, 0, length, `${label} blendIn`);+ strip.blendOut = bounded(input.blendOut ?? 0, 0, length, `${label} blendOut`);+ if (strip.blendIn + strip.blendOut > length) {+ throw invalidField(`${path}.blendOut`, strip.blendOut, `at most ${length - strip.blendIn} seconds, since blendIn ${strip.blendIn} and blendOut share the strip's ${length} seconds`);+ }+ strip.extend = oneOf(input.extend ?? 'nothing', STRIP_EXTENDS, `${path}.extend`);+ strip.blend = oneOf(input.blend ?? 'replace', STRIP_BLENDS, `${path}.blend`);+ if (strip.blend === 'add' && layer.additive === false) throw invalidField(`motion.layers[${position}].additive`, false, 'a field left out, since strip blend "add" makes the layer additive');+ return strip;+}+function normalizedLayer(input, position, context, resolveNode) {const label = `Motion layer ${position}`;const path = `motion.layers[${position}]`;- knownKeys(input, ['clip', 'from', 'scale', 'rootMotion', 'loop', 'weight', 'speed', 'offset', 'additive', 'reference', 'mask', 'bones', 'morph'], label);+ knownKeys(input, ['clip', 'from', 'scale', 'rootMotion', 'loop', 'weight', 'speed', 'offset', 'additive', 'reference', 'mask', 'bones', 'morph', 'strip'], label);const layer = {};let clip;if (input.from !== undefined) {@@ -125,6 +173,10 @@ function normalizedLayer(input, position, context, resolveNode) {if (input.speed !== undefined) layer.speed = bounded(input.speed, 0.05, MAX_LAYER_SPEED, `${label} speed`);if (input.offset !== undefined) layer.offset = bounded(input.offset, -MAX_LAYER_OFFSET, MAX_LAYER_OFFSET, `${label} offset`);if (input.reference !== undefined) layer.reference = bounded(input.reference, 0, clip.duration, `${label} reference`);+ if (input.strip !== undefined) {+ layer.strip = normalizedStrip(input.strip, layer, clip, position);+ if (layer.strip.blend === 'add') layer.additive = true;+ }if (input.mask !== undefined) layer.mask = normalizedMask(input.mask, resolveNode, position);if (input.bones !== undefined) layer.bones = normalizedBoneMap(input.bones, clip, resolveNode, position);return layer;diff --git a/src/clip-strip.js b/src/clip-strip.jsnew file mode 100644index 00000000..b9fce4c6--- /dev/null+++ b/src/clip-strip.js@@ -0,0 +1,40 @@+// A clip strip places a clip on the motion's timeline the way an animation editor's strip does: where it starts, how+// stretched and repeated it is, how it fades in and out, and what it does before and after. The compiled strip is two+// pure functions of time, so a seek equals playing.++export const STRIP_EXTENDS = Object.freeze(['nothing', 'hold', 'holdForward']);+export const STRIP_BLENDS = Object.freeze(['replace', 'add']);++/** The seconds a normalized strip covers: the clip length stretched by `scale` and repeated `repeat` times. */+export function stripLength(strip, clipDuration) {+ return clipDuration * strip.scale * strip.repeat;+}++function ramp(distance, blend) {+ return blend > 0 ? Math.min(1, Math.max(0, distance / blend)) : 1;+}++/**+ * `strip`: `{ start, scale, repeat, blendIn, blendOut, extend }`, already validated. Returns `weight(time)`, the fade+ * envelope from 0 to 1, and `clipTime(time)`, the time inside the clip. Each repeat plays the clip from 0 to its+ * duration; the end of a cycle reads the clip's last pose, the start of the next reads its first.+ */+export function compileClipStrip(strip, clipDuration) {+ const length = stripLength(strip, clipDuration);+ const end = strip.start + length;+ const playedSpan = clipDuration * strip.repeat;++ function weight(time) {+ if (time < strip.start) return strip.extend === 'hold' ? ramp(0, strip.blendIn) : 0;+ if (time > end) return strip.extend === 'nothing' ? 0 : ramp(0, strip.blendOut);+ return Math.min(ramp(time - strip.start, strip.blendIn), ramp(end - time, strip.blendOut));+ }++ function clipTime(time) {+ const played = Math.min(playedSpan, Math.max(0, (time - strip.start) / strip.scale));+ if (played === 0) return 0;+ return played - clipDuration * (Math.ceil(played / clipDuration) - 1);+ }++ return { weight, clipTime, end };+}diff --git a/src/skeleton-pose.js b/src/skeleton-pose.jsindex 29a909d0..3b6f29c5 100644--- a/src/skeleton-pose.js+++ b/src/skeleton-pose.js@@ -87,8 +87,9 @@ function createLayer(definition, position, prepared, resolveJoint) {const speed = definition.speed ?? 1;const offset = definition.offset ?? 0;if (!Number.isFinite(speed) || !Number.isFinite(offset)) throw new RangeError(`${label} speed and offset must be finite.`);+ if (definition.clipTime !== undefined && typeof definition.clipTime !== 'function') throw new TypeError(`${label} clipTime must be a function from motion time to clip time.`);return {- label, sampler, bindings, additive, references, speed, offset,+ label, sampler, bindings, additive, references, speed, offset, clipTime: definition.clipTime,weight: weightFunction(definition.weight ?? 1, `${label} weight`),mask: maskWeights(prepared, resolveJoint, definition.mask),};@@ -104,10 +105,17 @@ function applyAdditiveRotation(rotation, sample, reference, weight) {quat.normalize(rotation, quat.multiply(rotation, rotation, scratchDelta));}+/** Clip time of a layer: its `clipTime(time)` when it has one (a strip), else `time * speed + offset`. */+function layerClipTime(layer, time) {+ const clipTime = layer.clipTime ? layer.clipTime(time) : time * layer.speed + layer.offset;+ if (!Number.isFinite(clipTime)) throw new RangeError(`${layer.label} clip time must be finite at time ${time}.`);+ return clipTime;+}+function applyLayer(layer, time, localRotations, localTranslations) {const layerWeight = checkedWeight(layer.weight, time, `${layer.label} weight`);if (layerWeight === 0) return;- layer.sampler.sample(time * layer.speed + layer.offset);+ layer.sampler.sample(layerClipTime(layer, time));layer.bindings.forEach((binding, slot) => {const weight = layerWeight * layer.mask[binding.index];if (weight === 0) return;@@ -807,7 +815,8 @@ function createMorphLayers(asset, nodes, layers, rig) {}return {morphs: layer.morphs, partIndices, mask, owners, additive: layer.additive === true,- speed: layer.speed ?? 1, offset: layer.offset ?? 0, weight: weightFunction(layer.weight ?? 1, 'Morph layer weight'),+ speed: layer.speed ?? 1, offset: layer.offset ?? 0, clipTime: layer.clipTime, label: 'Morph layer',+ weight: weightFunction(layer.weight ?? 1, 'Morph layer weight'),reference: layer.reference ?? 0,};});@@ -819,7 +828,7 @@ function evaluateMorphLayers(morphLayers, time) {for (const layer of morphLayers) {const layerWeight = checkedWeight(layer.weight, time, 'Morph layer weight');if (layerWeight === 0) continue;- const layerTime = time * layer.speed + layer.offset;+ const layerTime = layerClipTime(layer, time);for (const track of layer.morphs.tracks) {const sampled = Array.from(track.interpolant.evaluate(morphClipTime(layer.morphs, layerTime)));const reference = layer.additive ? Array.from(track.interpolant.evaluate(morphClipTime(layer.morphs, layer.reference))) : null;diff --git a/tests/clip-strips.test.js b/tests/clip-strips.test.jsnew file mode 100644index 00000000..62fd872b--- /dev/null+++ b/tests/clip-strips.test.js@@ -0,0 +1,166 @@+import assert from 'node:assert/strict';+import { readFileSync } from 'node:fs';+import test from 'node:test';+import { parseGltf } from '../src/gltf.js';+import { createAgentAssetScene } from '../src/agent-asset.js';+import { compileClipStrip } from '../src/clip-strip.js';++// Strips on the real RobotExpressive clips: Walking (0.958 s) and Idle (3.333 s). Each strip is checked against the+// same pose made with plain layers, so only the timing and the fade are under test.+const bytes = readFileSync(new URL('./fixtures/RobotExpressive.glb', import.meta.url));+const ASSET_ID = 'cd'.repeat(32);+const loadRobot = () => parseGltf(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength), { maxVertices: 500000 });++function clipIndex(asset, name) {+ const index = asset.animations.findIndex(animation => animation.name === name);+ assert.ok(index >= 0, `no clip ${name}`);+ return index;+}++function assetScene(asset, layers, duration = 8) {+ return createAgentAssetScene(asset, { format: '67js.asset', schemaVersion: 1, assetId: ASSET_ID, motion: { duration, loop: false, layers } });+}++function poseAt(asset, layers, time) {+ const scene = assetScene(asset, layers);+ scene.sampleMotion(time);+ return scene.parts.map(part => Array.from(part.matrix));+}++function assertSamePose(first, second, message) {+ const distance = Math.max(...first.flatMap((matrix, part) => matrix.map((value, index) => Math.abs(value - second[part][index]))));+ assert.ok(distance < 1e-5, `${message}: poses differ by ${distance}`);+}++function refusalMessage(asset, layer) {+ try {+ assetScene(asset, [layer]);+ } catch (error) {+ return error.message;+ }+ return assert.fail('expected the strip to be refused');+}++const unit = { start: 0, scale: 1, repeat: 1, blendIn: 0, blendOut: 0, extend: 'nothing' };++test('a strip maps motion time to clip time with start, scale and repeat', () => {+ const strip = compileClipStrip({ ...unit, start: 1, scale: 2, repeat: 2.5 }, 1);+ assert.equal(strip.clipTime(0), 0);+ assert.equal(strip.clipTime(1), 0);+ assert.equal(strip.clipTime(2), 0.5);+ assert.equal(strip.clipTime(3), 1);+ assert.equal(strip.clipTime(4), 0.5);+ assert.equal(strip.clipTime(5), 1);+ assert.equal(strip.clipTime(6), 0.5);+ assert.equal(strip.clipTime(6.5), 0.5);+ assert.equal(strip.clipTime(100), 0.5);+ assert.equal(strip.end, 6);+});++test('a strip fades in and out linearly and extends as asked', () => {+ const faded = { ...unit, start: 1, repeat: 4, blendIn: 1, blendOut: 2 };+ const nothing = compileClipStrip(faded, 1);+ const weights = [0.5, 1, 1.5, 2, 3, 4, 4.5, 5, 6].map(time => nothing.weight(time));+ assert.deepEqual(weights, [0, 0, 0.5, 1, 1, 0.5, 0.25, 0, 0]);++ const hold = compileClipStrip({ ...faded, extend: 'hold' }, 1);+ assert.equal(hold.weight(0), 0, 'a hold before the start keeps the weight the strip starts with');+ const holdForward = compileClipStrip({ ...unit, start: 1, extend: 'holdForward' }, 1);+ assert.equal(holdForward.weight(0), 0);+ assert.equal(holdForward.weight(9), 1);+ assert.equal(compileClipStrip({ ...unit, extend: 'hold' }, 1).weight(-4), 1);+});++test('a walk repeated three times crossfades into an idle', async () => {+ const asset = await loadRobot();+ const walking = clipIndex(asset, 'Walking');+ const idle = clipIndex(asset, 'Idle');+ const walkLength = asset.animations[walking].duration;+ const fade = 0.5;+ const idleStart = walkLength * 3 - fade;+ const strips = [+ { clip: walking, strip: { repeat: 3 } },+ { clip: idle, strip: { start: idleStart, blendIn: fade, repeat: 1 } },+ ];++ assertSamePose(poseAt(asset, strips, 1.3), poseAt(asset, [{ clip: walking }], 1.3), 'second walk cycle');+ assertSamePose(poseAt(asset, strips, 2.2), poseAt(asset, [{ clip: walking }], 2.2), 'last walk cycle before the fade');+ const midFade = idleStart + fade / 2;+ assertSamePose(+ poseAt(asset, strips, midFade),+ poseAt(asset, [{ clip: walking }, { clip: idle, weight: 0.5, offset: -idleStart, loop: false }], midFade),+ 'halfway through the crossfade',+ );+ assertSamePose(poseAt(asset, strips, 4.5), poseAt(asset, [{ clip: idle, offset: -idleStart, loop: false }], 4.5), 'idle after the fade');+ const afterIdle = idleStart + asset.animations[idle].duration + 0.5;+ assertSamePose(poseAt(asset, strips, afterIdle), poseAt(asset, [{ clip: walking, weight: 0 }], afterIdle), 'nothing after the last strip');+});++test('scale stretches the clip and hold keeps its last pose', async () => {+ const asset = await loadRobot();+ const walking = clipIndex(asset, 'Walking');+ const walkLength = asset.animations[walking].duration;+ assertSamePose(+ poseAt(asset, [{ clip: walking, strip: { scale: 2 } }], 1),+ poseAt(asset, [{ clip: walking, speed: 0.5 }], 1),+ 'half speed',+ );+ const held = [{ clip: walking, strip: { extend: 'hold' } }];+ const clamped = [{ clip: walking, loop: false }];+ assertSamePose(poseAt(asset, held, walkLength + 3), poseAt(asset, clamped, walkLength + 3), 'held end');+ assertSamePose(poseAt(asset, held, walkLength), poseAt(asset, clamped, walkLength), 'strip end');+ assertSamePose(poseAt(asset, [{ clip: walking, strip: { start: 2, extend: 'hold' } }], 0.5), poseAt(asset, clamped, 0), 'held start');+});++test('an add strip adds the clip change on top of the pose below', async () => {+ const asset = await loadRobot();+ const base = clipIndex(asset, 'Idle');+ const wave = clipIndex(asset, 'Wave');+ assertSamePose(+ poseAt(asset, [{ clip: base }, { clip: wave, strip: { start: 0.5, blend: 'add' } }], 1.2),+ poseAt(asset, [{ clip: base }, { clip: wave, additive: true, offset: -0.5, loop: false }], 1.2),+ 'additive wave',+ );+});++test('a strip pose is the same after seeking elsewhere and back', async () => {+ const asset = await loadRobot();+ const scene = assetScene(asset, [{ clip: clipIndex(asset, 'Walking'), strip: { repeat: 3, blendOut: 0.3 } }], 5);+ const read = time => {+ scene.sampleMotion(time);+ return scene.parts.map(part => Array.from(part.matrix));+ };+ const first = read(2.1);+ read(0.4);+ read(4);+ assertSamePose(first, read(2.1), 'seek');+});++test('strip input outside its bounds names the field and what to pass', async () => {+ const asset = await loadRobot();+ const clip = clipIndex(asset, 'Walking');+ const message = (strip, extra = {}) => refusalMessage(asset, { clip, ...extra, strip });+ assert.match(message({ repeat: 0 }), /repeat/);+ assert.match(message({ repeat: 1000 }), /repeat/);+ assert.match(message({ extend: 'forever' }), /motion\.layers\[0\]\.strip\.extend.*nothing, hold, holdForward/);+ assert.match(message({ blend: 'combine' }), /strip\.blend.*replace, add/);+ assert.match(message({ end: 5, repeat: 2 }), /strip\.end.*end or repeat/);+ assert.match(message({ start: 2, end: 1 }), /strip\.end.*after start 2/);+ assert.match(message({ blendIn: 0.8, blendOut: 0.5 }), /strip\.blendOut.*blendIn 0\.8/);+ assert.match(message({ scale: 0 }), /scale/);+ assert.match(message({ colour: 1 }), /colour/);+ assert.match(message({}, { speed: 2 }), /motion\.layers\[0\]\.speed.*own start, scale and repeat/);+ assert.match(message({ blend: 'add' }, { additive: false }), /additive/);+});++test('end stops the strip at a time, as a fractional repeat', async () => {+ const asset = await loadRobot();+ const walking = clipIndex(asset, 'Walking');+ const walkLength = asset.animations[walking].duration;+ const stopAt = walkLength * 1.5;+ assertSamePose(+ poseAt(asset, [{ clip: walking, strip: { end: stopAt, extend: 'hold' } }], 5),+ poseAt(asset, [{ clip: walking, loop: false, offset: -walkLength }], stopAt),+ 'held half cycle',+ );+});