Skip to content

3D engine that AI agents drive

Name the Map packObjectMotion reads when it gets another value (#2632)

abu-tahir-0945908a5d780
diff --git a/changes/2632.md b/changes/2632.md
new file mode 100644
index 00000000..43d8f750
--- /dev/null
+++ b/changes/2632.md
@@ -0,0 +1 @@
+- `packObjectMotion` names `current` or `previous` and asks for the Map from `sampleWorldMatrices(parts)` instead of failing with a raw TypeError (#2632)
diff --git a/changes/2632.size.md b/changes/2632.size.md
new file mode 100644
index 00000000..6965c149
--- /dev/null
+++ b/changes/2632.size.md
@@ -0,0 +1 @@
+- scene:agent-scene+lazy: the check names the Map to pass to packObjectMotion, so an agent can fix the input instead of reading current.get on a plain object.
diff --git a/src/object-motion-blur.js b/src/object-motion-blur.js
index 27c53707..70a41d79 100644
--- a/src/object-motion-blur.js
+++ b/src/object-motion-blur.js
@@ -2,6 +2,7 @@ import { mat4 } from 'gl-matrix';
import {
createStage, previousViewProjectionOf, sharedFragmentHeader, MOTION_BLUR_SAMPLES, MAXIMUM_STREAK,
} from './camera-effects.js';
+import { invalidField } from './field-error.js';
// Per-object motion blur: a fast prop or part smears along its own screen motion while the still background stays sharp.
// It is opt-in (`effects.motionBlur.objects` above zero) and loads on demand, so a scene without it pays nothing.
@@ -67,6 +68,11 @@ export function sampleWorldMatrices(parts) {
* A part with no matrix in `previous` or one that did not move keeps the identity, and so does a pixel of no object.
*/
export function packObjectMotion(renderer, current, previous) {
+ for (const [name, matrices] of [['current', current], ['previous', previous]]) {
+ if (!(matrices instanceof Map)) {
+ throw invalidField(name, matrices, 'the Map from sampleWorldMatrices(parts)');
+ }
+ }
const drawnParts = renderer.batches.filter(batch => renderer.drawsInOpaqueLoop(batch)).flatMap(batch => batch.parts);
const rows = Math.max(1, Math.ceil(drawnParts.length / MATRICES_PER_ROW));
const matrices = new Float32Array(TEXTURE_WIDTH * rows * 4);
diff --git a/tests/object-motion-blur.test.js b/tests/object-motion-blur.test.js
index 76432ff1..e5dab03d 100644
--- a/tests/object-motion-blur.test.js
+++ b/tests/object-motion-blur.test.js
@@ -53,3 +53,13 @@ test('the object stage replaces camera blur on a frame that carries object motio
assert.equal(objectStage.apply({ depthTexture: null }, { previousCamera: {} }, effects, null), null, 'Without object motion the stage passes through.');
assert.equal(installObjectMotionBlur(renderer).postStages.length, 3, 'Installing twice adds nothing.');
});
+
+test('packObjectMotion names a matrix set that is not the Map it reads (#2632)', () => {
+ const renderer = fakeRenderer(['prop']);
+ const matrices = new Map();
+ for (const [name, value] of [['current', {}], ['current', []], ['previous', {}], ['previous', []]]) {
+ const [current, previous] = name === 'current' ? [value, matrices] : [matrices, value];
+ assert.throws(() => packObjectMotion(renderer, current, previous), new RegExp(`${name}: .*expected the Map from sampleWorldMatrices\\(parts\\)`));
+ }
+ assert.throws(() => packObjectMotion(fakeRenderer([]), {}, {}), /current: /, 'An empty scene reaches the check too.');
+});