3D engine that AI agents drive
Merge remote-tracking branch 'origin/main' into HEAD
Nguyen Xuan Ana6cbba818798
diff --cc bench/agent-modeling/check.mjsindex 9e631046,823bd3e7..dd8c9a7c--- a/bench/agent-modeling/check.mjs+++ b/bench/agent-modeling/check.mjs@@@ -79,15 -120,43 +120,52 @@@ function checkOne(check, measures)const onPath = close(solver.firstTarget, check.from) && close(solver.lastTarget, check.to);return { pass: onPath && solver.reached, detail: `targets ${JSON.stringify(solver.firstTarget)} to ${JSON.stringify(solver.lastTarget)}, reached ${solver.reached}, worst ${solver.worstError}` };}+ case 'shot': {+ const { camera } = measures;+ if (!camera) return { pass: false, detail: 'no camera in the recipe' };+ const offset = camera.eye.map((value, axis) => value - camera.target[axis]);+ const distance = Math.hypot(...offset);+ const sideOn = offset[0] >= check.minSideOffset && Math.abs(offset[2]) <= check.maxDepthOffset;+ const framed = camera.target[1] >= check.targetHeight[0] && camera.target[1] <= check.targetHeight[1] && distance >= check.distance[0] && distance <= check.distance[1];+ return { pass: sideOn && framed, detail: `eye offset ${offset.map(round).join(', ')}, target height ${round(camera.target[1])}` };+ }+ case 'rigBones': {+ const missing = REQUIRED_HUMANOID_BONES.filter(bone => !measures.rig?.bones.includes(bone));+ return { pass: Boolean(measures.rig) && missing.length === 0, detail: measures.rig ? (missing.length ? `missing bones ${missing.join(', ')}` : `${measures.rig.bones.length} bones, all humanoid bones present`) : 'no armature' };+ }+ case 'rigSkinned': {+ const rig = measures.rig;+ const problems = [];+ if (!rig) problems.push('no armature');+ else {+ if (rig.skinnedNodes !== rig.meshNodes) problems.push(`${rig.meshNodes - rig.skinnedNodes} of ${rig.meshNodes} mesh nodes have no skin`);+ if (rig.unweightedVertices > 0) problems.push(`${rig.unweightedVertices} unweighted vertices`);+ }+ return { pass: problems.length === 0, detail: problems.join('; ') || `${rig.skinnedNodes} mesh nodes skinned, no unweighted vertices` };+ }+ case 'rigWalk':+ return checkWalk(measures.rig, check);+ case 'physicsBody': {+ const body = measures.physics?.bodies.find(candidate => candidate.node === check.node);+ return { pass: body?.type === check.type && body?.shape === check.shape, detail: body ? `${body.node} is ${body.type} ${body.shape}` : `no physics body on ${check.node}` };+ }+ case 'physicsRest': {+ const problems = check.nodes.flatMap(node => {+ const body = measures.physics?.bodies.find(candidate => candidate.node === node);+ if (!body) return [`${node} has no physics body`];+ const [x, y, z] = body.finalPosition;+ const touching = measures.physics.contacts.some(contact => [contact.a, contact.b].includes(node) && [contact.a, contact.b].includes(check.touching) && contact.touchingAtEnd);+ const found = [];+ if (body.restsAtTime === null || body.restsAtTime === undefined) found.push(`${node} is still moving`);+ if (y < check.height[0] || y > check.height[1]) found.push(`${node} ends at height ${round(y)}`);+ if (Math.abs(x) > check.within || Math.abs(z) > check.within) found.push(`${node} ends outside the pocket at ${round(x)}, ${round(z)}`);+ if (!touching) found.push(`${node} does not touch ${check.touching}`);+ return found;+ });+ return { pass: problems.length === 0, detail: problems.join('; ') || `${check.nodes.length} balls at rest` };+ }+ case 'physicsSeek':+ return { pass: measures.physicsSeekStable === true, detail: measures.physicsSeekStable ? 'identical matrices' : 'no physics, or a seek back differs' };case 'tips':return { pass: measures.tips === check.equals, detail: `${measures.tips} tips` };case 'triangles':diff --cc tests/agent-modeling-suite.test.jsindex d718d272,46a589db..25242896--- a/tests/agent-modeling-suite.test.js+++ b/tests/agent-modeling-suite.test.js@@@ -36,70 -36,18 +36,82 @@@ test('checks reject objects that miss tassert.ok(failedKinds(await gradeRecipe(taskById('gear'), elevenTeeth)).includes('tips'));});+function movedAlong(node, axis, amount) {+ const translation = [...node.translation];+ translation[axis] += amount;+ return { ...node, translation };+}++test('long tasks reject plausible wrong variants', async () => {+ const smoothPlate = structuredClone(REFERENCES['chamfer-plate']);+ smoothPlate.geometries[0].edits = smoothPlate.geometries[0].edits.filter(edit => edit.op !== 'bevel');+ assert.deepEqual(failedKinds(await gradeRecipe(taskById('chamfer-plate'), smoothPlate)), ['chamfered top edge']);++ const fivePockets = structuredClone(REFERENCES['chamfer-plate']);+ fivePockets.geometries[0].edits.pop();+ assert.ok(failedKinds(await gradeRecipe(taskById('chamfer-plate'), fivePockets)).includes('plate outline and six pockets'));++ const squareRail = structuredClone(REFERENCES['slotted-rail']);+ squareRail.geometries[0].edits = squareRail.geometries[0].edits.filter(edit => edit.op !== 'bevel');+ assert.deepEqual(failedKinds(await gradeRecipe(taskById('slotted-rail'), squareRail)), ['chamfered end edges']);++ const fourSlots = structuredClone(REFERENCES['slotted-rail']);+ fourSlots.geometries[0].edits.pop();+ const fourSlotFailures = failedKinds(await gradeRecipe(taskById('slotted-rail'), fourSlots));+ assert.ok(fourSlotFailures.includes('holes') && fourSlotFailures.includes('bar outline and five slots'));++ const unchangedCrate = failedKinds(await gradeRecipe(taskById('crate-revision'), REFERENCES.crate));+ assert.ok(unchangedCrate.includes('size') && unchangedCrate.includes('raised lid with the hole'));++ const throughHoleCrate = structuredClone(REFERENCES['crate-revision']);+ throughHoleCrate.geometries[0].edits.at(-1).scale = [0.03, 0.6, 0.03];+ assert.ok(failedKinds(await gradeRecipe(taskById('crate-revision'), throughHoleCrate)).includes('hole stops at 0.5 m'));++ const oldBracket = failedKinds(await gradeRecipe(taskById('bracket-revision'), REFERENCES.bracket));+ assert.ok(oldBracket.includes('size') && oldBracket.includes('holes'));++ const lopsidedWorkshop = structuredClone(REFERENCES.workshop);+ lopsidedWorkshop.nodes = lopsidedWorkshop.nodes.filter(node => node.id !== 'chair-leg-3').map(node => (node.id === 'mug' ? movedAlong(node, 1, 0.2) : node));+ const workshopFailures = failedKinds(await gradeRecipe(taskById('workshop'), lopsidedWorkshop));+ assert.ok(workshopFailures.includes('four table legs and four chair legs') && workshopFailures.includes('mug on the table'));+});++test('the robot shot needs both hands on target and a side-on camera', async () => {+ const task = taskById('robot-shot');+ const oneHand = structuredClone(REFERENCES['robot-shot']);+ oneHand.motion.ik.pop();+ assert.deepEqual(failedKinds(await gradeRecipe(task, oneHand)), ['assetReach']);++ const defaultFraming = structuredClone(REFERENCES['robot-shot']);+ defaultFraming.camera.eye = [4, 5, 6];+ assert.deepEqual(failedKinds(await gradeRecipe(task, defaultFraming)), ['shot']);++ const noCamera = structuredClone(REFERENCES['robot-shot']);+ delete noCamera.camera;+ assert.deepEqual(failedKinds(await gradeRecipe(task, noCamera)), ['shot']);+});++test('tasks that change an existing scene carry their starting recipe in the prompt', () => {+ for (const id of ['crate-revision', 'bracket-revision']) {+ const task = taskById(id);+ assert.ok(taskPrompt(task).includes(JSON.stringify(task.startRecipe)), id);+ assert.doesNotMatch(taskPrompt(task), /\n/);+ }+ assert.equal(taskPrompt(taskById('bolt')).includes('scene_create with exactly'), false);+});++ test('the pillar court check rejects a grid with a wrong count or spacing', async () => {+ const fourByThree = structuredClone(REFERENCES['pillar-court']);+ fourByThree.nodes[0].instances.grid.counts = [4, 1, 3];+ const missingColumn = failedKinds(await gradeRecipe(taskById('pillar-court'), fourByThree));+ assert.ok(missingColumn.includes('fifteen pillars'), missingColumn.join(', '));+ assert.ok(missingColumn.includes('size'));++ const tooTight = structuredClone(REFERENCES['pillar-court']);+ tooTight.nodes[0].instances.grid.spacing = [3, 1, 5];+ assert.ok(failedKinds(await gradeRecipe(taskById('pillar-court'), tooTight)).includes('size'));+ });+test('an invalid recipe fails every check with the reason', async () => {const grade = await gradeRecipe(taskById('bolt'), { format: '67js.scene', schemaVersion: 1, geometries: [], materials: [], nodes: [{ id: 'x', geometry: 'missing' }] });assert.equal(grade.passed, 0);