Skip to content

3D engine that AI agents drive

Name the part with a missing world matrix in the closed room test (#2626)

abu-tahir-0ec60e042f2e8
diff --git a/changes/2626.md b/changes/2626.md
new file mode 100644
index 00000000..31d1cc88
--- /dev/null
+++ b/changes/2626.md
@@ -0,0 +1 @@
+- The closed room test names the part whose world matrix is missing and tells the caller to pass `partMatrixLookup(parts)` (#2626)
diff --git a/changes/2626.size.md b/changes/2626.size.md
new file mode 100644
index 00000000..db73e60a
--- /dev/null
+++ b/changes/2626.size.md
@@ -0,0 +1,3 @@
+- scene:agent-scene: the closed room test names the part whose matrix is missing and the lookup to pass, so a caller can fix the input instead of reading a TypeError on undefined.
+- scene:agent-scene+lazy: same change; the message is one short line in the closed room test.
+- goal:agent-scene: the closed room diagnostic runs in the agent scene; naming the missing part is worth 73 bytes over the goal.
diff --git a/src/closed-room.js b/src/closed-room.js
index 9d40cb45..00873c80 100644
--- a/src/closed-room.js
+++ b/src/closed-room.js
@@ -29,6 +29,7 @@ export function worldTriangles(parts, worldMatrices) {
let write = 0;
for (const part of parts) {
const matrix = worldMatrices.get(part) ?? worldMatrices.get(part.name);
+ if (matrix === undefined) throw new Error(`No world matrix for part "${part.name}"; pass partMatrixLookup(parts) as worldMatrices.`);
const { positions, indices } = part.geometry;
const partMinimum = [Infinity, Infinity, Infinity];
const partMaximum = [-Infinity, -Infinity, -Infinity];
diff --git a/tests/closed-room-missing-matrix.test.js b/tests/closed-room-missing-matrix.test.js
new file mode 100644
index 00000000..faca2f46
--- /dev/null
+++ b/tests/closed-room-missing-matrix.test.js
@@ -0,0 +1,21 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { closedRoomShare, partMatrixLookup, worldTriangles } from '../src/closed-room.js';
+
+const IDENTITY = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
+const triangle = (firstCorner, secondCorner, thirdCorner) => ({ positions: new Float32Array([...firstCorner, ...secondCorner, ...thirdCorner]), indices: new Uint32Array([0, 1, 2]) });
+const facingCentre = () => [
+ { name: 'near', matrix: IDENTITY, geometry: triangle([-9, -9, -5], [9, -9, -5], [0, 9, -5]) },
+ { name: 'far', matrix: IDENTITY, geometry: triangle([-9, -9, 5], [0, 9, 5], [9, -9, 5]) },
+];
+
+test('a missing world matrix names the part and the lookup to pass', () => {
+ const parts = facingCentre();
+ assert.throws(() => worldTriangles(parts, new Map([['near', IDENTITY]])), /No world matrix for part "far"; pass partMatrixLookup\(parts\)/);
+});
+
+test('a complete lookup returns the same share whether it is keyed by part or by name', () => {
+ const parts = facingCentre();
+ assert.equal(closedRoomShare(parts, new Map(parts.map(part => [part.name, IDENTITY]))), 0.375);
+ assert.equal(closedRoomShare(parts, partMatrixLookup(parts)), 0.375);
+});