Skip to content

3D engine that AI agents drive

Keep lint pair codes distinct past 1000 parts and name points in the drive path error (#2529)

Nguyen Xuan An0e558141368f
diff --git a/changes/2529.md b/changes/2529.md
new file mode 100644
index 00000000..9ba203ae
--- /dev/null
+++ b/changes/2529.md
@@ -0,0 +1 @@
+- Mesh lint keeps part pairs distinct past 1000 parts, and a drive path that is not a list of points says so.
diff --git a/src/agent-drive-schema.js b/src/agent-drive-schema.js
index 8b7fff2e..0b83faf9 100644
--- a/src/agent-drive-schema.js
+++ b/src/agent-drive-schema.js
@@ -16,6 +16,7 @@ const LIGHT_FIELDS = ['headlights', 'tailLights'];
const HEADLIGHT_FIELDS = ['id', 'position', 'direction'];
const TAIL_LIGHT_FIELDS = ['id', 'material', 'signal', 'off', 'on'];
const CAMERA_PATH_FIELDS = ['duration', 'loop', 'eye'];
+const PATH_EXPECTED = 'an array of [x, y, z] points, such as [[0, 0, 0], [0, 0, 10]], or a camera path such as { "duration": 5, "eye": { "keyframes": [] } }';
function knownKeys(value, allowed, path) {
if (!value || typeof value !== 'object' || Array.isArray(value)) throw invalidField(path, value, 'an object, such as {}', TypeError);
@@ -43,9 +44,10 @@ function normalizePath(path, label) {
}
return path.map((point, index) => vector(point, `${label}[${index}]`));
}
+ if (!path || typeof path !== 'object') throw invalidField(label, path, PATH_EXPECTED, TypeError);
knownKeys(path, CAMERA_PATH_FIELDS, label);
if (!path.eye || !Array.isArray(path.eye.keyframes) || path.eye.keyframes.length > DRIVE_LIMITS.maxPathPoints) {
- throw invalidField(label, path, 'an array of [x, y, z] points, such as [[0, 0, 0], [0, 0, 10]], or a camera path such as { "duration": 5, "eye": { "keyframes": [] } }', TypeError);
+ throw invalidField(label, path, PATH_EXPECTED, TypeError);
}
return structuredClone(path);
}
diff --git a/src/mesh-lint-geometry.js b/src/mesh-lint-geometry.js
index 204b27d4..a7c36cc2 100644
--- a/src/mesh-lint-geometry.js
+++ b/src/mesh-lint-geometry.js
@@ -104,6 +104,8 @@ function findFloatingParts(bounds, contactDistance) {
function findIntersectingParts(geometries, bounds, contactDistance, skipped) {
const crossing = [];
+ // Larger than every part index, so two different pairs never share a code.
+ const pairStride = Math.max(1000, geometries.length);
let pairsTested = 0;
for (let first = 0; first < geometries.length; first++) {
for (let second = first + 1; second < geometries.length; second++) {
@@ -116,7 +118,7 @@ function findIntersectingParts(geometries, bounds, contactDistance, skipped) {
const secondIndex = createMeshQueryIndex(geometries[second]);
try {
const result = createMeshPairQuery(firstIndex, secondIndex).evaluate(IDENTITY_MATRIX, IDENTITY_MATRIX);
- if (result.kind === 'surface-intersection') crossing.push(first * 1000 + second);
+ if (result.kind === 'surface-intersection') crossing.push(first * pairStride + second);
} catch {
skipped.add('intersecting-parts');
} finally {
@@ -234,7 +236,7 @@ function problem(kind, elements, extra = {}) {
/**
* Runs the spatial checks on a polygon mesh. `solidParts` lists the parts that are closed, consistently wound and
* outward facing. Returns { problems, skipped }, where each problem has kind, count and a sample of element indices
- * (part pairs as first * 1000 + second, parts, faces or vertices by kind).
+ * (part pairs as first * max(1000, partCount) + second, parts, faces or vertices by kind).
*/
export function lintMeshGeometry(mesh, { facePart, partCount, solidParts, bounds, diagonal }) {
const skipped = new Set();
diff --git a/src/mesh-lint.js b/src/mesh-lint.js
index 71828bde..566bc213 100644
--- a/src/mesh-lint.js
+++ b/src/mesh-lint.js
@@ -20,7 +20,7 @@ export const MESH_PROBLEMS = Object.freeze({
// Spatial checks, opt in through lintMesh(mesh, { geometry: true }) because each builds a BVH. All are warnings: a mesh
// can cross itself, be thin or float on purpose, so none of them turns ok off.
export const GEOMETRY_PROBLEMS = Object.freeze({
- 'intersecting-parts': { severity: 'warning', fix: 'Two parts cross each other (sample holds first * 1000 + second part index). Move them apart, or run a union boolean if they should be one solid.' },
+ 'intersecting-parts': { severity: 'warning', fix: 'Two parts cross each other (sample holds first * max(1000, part count) + second part index). Move them apart, or run a union boolean if they should be one solid.' },
'self-intersection': { severity: 'warning', fix: 'A closed part cuts through itself. Undo the last extrude, inset or translate that folded it, or lower its offset.' },
'thin-wall': { severity: 'warning', fix: 'The wall behind these faces (sample is face indices) is under 0.5% of the mesh size thick. Thicken it with solidify, or move the faces apart.' },
'floating-part': { severity: 'warning', fix: 'This part (sample is part indices) touches no other part. Translate it onto its neighbour, or ignore this if it is meant to stand alone.' },
diff --git a/tests/agent-drive.test.js b/tests/agent-drive.test.js
index 9c655c87..552269c9 100644
--- a/tests/agent-drive.test.js
+++ b/tests/agent-drive.test.js
@@ -208,3 +208,9 @@ test('a placed car drives its path in the placement frame, with its own decoded
for (const asset of assets.values()) asset.dispose();
}
});
+
+test('a drive path or leg path that is not a list of points says it wants points, not an object', () => {
+ for (const input of [{ path: 'abc' }, { path: null }, { legs: [{}] }, { legs: [{ path: 7 }] }]) {
+ assert.throws(() => normalizeDrive(input), error => error instanceof TypeError && /array of \[x, y, z\] points/.test(error.message));
+ }
+});
diff --git a/tests/mesh-lint-geometry.test.js b/tests/mesh-lint-geometry.test.js
index 61685d51..5f832c24 100644
--- a/tests/mesh-lint-geometry.test.js
+++ b/tests/mesh-lint-geometry.test.js
@@ -106,3 +106,13 @@ test('a prism over a concave outline raises no spatial warning at any starting c
assert.equal(result.skippedChecks, undefined, `shift ${shift}`);
}
});
+
+test('part pairs stay distinct in the sample once a mesh has more than 1000 parts', () => {
+ const boxes = Array.from({ length: 1501 }, (_, index) => placedBox({ translation: [index * 10, 0, 0] }));
+ boxes[1500] = placedBox({ translation: [0.5, 0.5, 0.5] });
+ boxes[500] = placedBox({ translation: [10.5, 0.5, 0.5] });
+ const mesh = meshFromGeometry(joined(...boxes));
+ const crossing = lintMesh(mesh, { geometry: true }).problems.find(problem => problem.kind === 'intersecting-parts');
+ assert.equal(crossing.count, 2);
+ assert.equal(new Set(crossing.sample).size, 2);
+});