3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Refuse a mixer play() offset that would overflow later applies (#2416)
Nguyen Xuan Anaa3e6b5ed76f
diff --git a/changes/2416.md b/changes/2416.mdindex 3ddd5f8c..432c1e86 100644--- a/changes/2416.md+++ b/changes/2416.md@@ -1 +1 @@-- Refuse a mixer `play()` timeScale beyond 1e6, hold the graph speedParameter multiplier to 0 to 100 and keep 2D blend weights summing to 1 when positions overflow (#2416, #2417, #2418).+- Refuse a mixer `play()` timeScale beyond 1e6 or offset beyond 1e9, hold the graph speedParameter multiplier to 0 to 100 and keep 2D blend weights summing to 1 when positions overflow (#2416, #2417, #2418).diff --git a/docs/animation-mixer.md b/docs/animation-mixer.mdindex 8cc3860a..5daac614 100644--- a/docs/animation-mixer.md+++ b/docs/animation-mixer.md@@ -20,7 +20,7 @@ mixer.apply(1);| Method | Behavior || --- | --- |-| `play({ at, offset = 0, timeScale = 1, weight = 1 })` | Starts or restarts playback at `at`, with the given local offset and speed. `timeScale` stays within 1e6 either way. |+| `play({ at, offset = 0, timeScale = 1, weight = 1 })` | Starts or restarts playback at `at`, with the given local offset and speed. `timeScale` stays within 1e6 and `offset` within 1e9 either way. || `stop(at)` | Stops contributing from `at` onward. Earlier times retain their recorded playback. || `fadeTo(weight, { at, duration })` | Interpolates from the effective weight at `at` to the target weight. || `getState(time)` | Returns `phase`, `playing`, `weight` and the unwrapped `localTime`. |diff --git a/src/animation-mixer.js b/src/animation-mixer.jsindex 64dc79c2..1b303857 100644--- a/src/animation-mixer.js+++ b/src/animation-mixer.js@@ -4,6 +4,7 @@ import { compileAnimationSampler, retainAnimationMaterial } from './animation.jsconst MATERIAL_PROPERTIES = new Set(['emission', 'metallic', 'roughness']);const MINIMUM_POSITIVE_VALUE = 1e-8;const MAXIMUM_TIME_SCALE = 1e6;+const MAXIMUM_OFFSET = 1e9;function finiteTime(time) {if (!Number.isFinite(time)) throw new TypeError('Mixer times must be finite.');@@ -98,6 +99,7 @@ function controlState(action, at) {function playState(action, { at = 0, offset = 0, timeScale = 1, weight = 1 } = {}) {controlState(action, at);finiteTime(offset);+ if (Math.abs(offset) > MAXIMUM_OFFSET) throw new RangeError(`Action offset must be within ${MAXIMUM_OFFSET}, got ${offset}.`);if (!Number.isFinite(timeScale)) throw new TypeError('Action timeScale must be finite.');if (Math.abs(timeScale) > MAXIMUM_TIME_SCALE) throw new RangeError(`Action timeScale must be within ${MAXIMUM_TIME_SCALE}, got ${timeScale}.`);validWeight(weight);diff --git a/tests/animation-mixer.test.js b/tests/animation-mixer.test.jsindex 651bfebd..913f35a2 100644--- a/tests/animation-mixer.test.js+++ b/tests/animation-mixer.test.js@@ -347,11 +347,12 @@ test('invalid bindings fail without publishing partially registered material copassert.throws(() => createAnimationMixer([shear]), /shear/);});-test('play refuses a timeScale that would overflow later applies', () => {+test('play refuses a timeScale or offset that would overflow later applies', () => {const mixer = createAnimationMixer([part('part')]);const action = mixer.clipAction(constantClip('part', 'emission', 2));assert.throws(() => action.play({ timeScale: 1e308 }), /timeScale must be within/);assert.throws(() => action.play({ timeScale: -1e308 }), RangeError);- action.play({ timeScale: 1e6 });+ assert.throws(() => action.play({ offset: 1e308 }), /offset must be within/);+ action.play({ timeScale: 1e6, offset: -1e9 });assert.doesNotThrow(() => mixer.apply(10));});