Skip to content

3D engine that AI agents drive

Warn when a pinned part shares its material (#1972)

Nguyen Xuan And65b3eea5c67
diff --git a/bench/agent-modeling/README.md b/bench/agent-modeling/README.md
index 65c71b0c..4db6ad75 100644
--- a/bench/agent-modeling/README.md
+++ b/bench/agent-modeling/README.md
@@ -152,6 +152,7 @@ pass when the statue's material is red and the plinth is not recoloured. A test
A mark may carry `"lasso":[[x,y],...]` (3 to 64 points inside the frame) instead of `pixel`; the answer then lists the parts under the outline.
`ask-user-lasso` (`ask-user-lasso.json`) outlines the statue and the plinth with the note "make these blue"; its checks pass when both are blue
and the floor, which shares the plinth's stone material, is not.
+`ask-user-pin-shared` (`ask-user-pin-shared.json`) pins the plinth with the note "make this red"; its checks pass when the plinth is red and the floor, which shares its stone material, is not (#1972).
### Several runs and several models
diff --git a/bench/agent-modeling/ask-user-pin-shared.json b/bench/agent-modeling/ask-user-pin-shared.json
new file mode 100644
index 00000000..0a899407
--- /dev/null
+++ b/bench/agent-modeling/ask-user-pin-shared.json
@@ -0,0 +1,5 @@
+{
+ "marks": [
+ { "pixel": [386, 295], "note": "make this red" }
+ ]
+}
diff --git a/bench/agent-modeling/scenes.mjs b/bench/agent-modeling/scenes.mjs
index 96b853eb..b46ca1f1 100644
--- a/bench/agent-modeling/scenes.mjs
+++ b/bench/agent-modeling/scenes.mjs
@@ -102,6 +102,14 @@ const ASK_USER_LASSO_CHECKS = [
{ kind: 'materialOf', node: 'floor', blue: false, label: 'the floor outside the lasso is not recoloured' },
];
+// The plinth and the floor share the stone material, so reddening the pinned plinth needs a material of its own.
+const ASK_USER_PIN_SHARED_CHECKS = [
+ { kind: 'lint' },
+ { kind: 'parts', min: 3, max: 3 },
+ { kind: 'materialOf', node: 'plinth', red: true, label: 'the pinned plinth is red' },
+ { kind: 'materialOf', node: 'floor', red: false, label: 'the floor sharing its material is not recoloured' },
+];
+
export const SCENE_TASKS = [
{
id: 'camera-closeup',
@@ -180,6 +188,16 @@ colour so it turns warmer (red up, blue down) between time 0 and time 4. ${FINIS
Read their pin with scene_ask_user (it returns the part under the pin and their note), then make that change to that part and nothing else. ${FINISH}`,
checks: ASK_USER_PIN_CHECKS,
},
+ {
+ // The answer comes from bench/agent-modeling/ask-user-pin-shared.json, a pin on the plinth, whose stone material the floor also uses.
+ id: 'ask-user-pin-shared',
+ askUserFixture: 'ask-user-pin-shared.json',
+ startRecipe: stageRecipe(),
+ ownPreamble: true,
+ prompt: `${PLAIN_PREAMBLE} ${STAGE} A person has pinned one spot on the picture of this scene and left a note about a change to make there.
+Read their pin with scene_ask_user (it returns the part under the pin and their note), then make that change to that part and nothing else. ${FINISH}`,
+ checks: ASK_USER_PIN_SHARED_CHECKS,
+ },
{
// The answer comes from bench/agent-modeling/ask-user-lasso.json, drawn around the statue and the plinth.
id: 'ask-user-lasso',
@@ -258,6 +276,12 @@ export const SCENE_REFERENCES = {
recipe.materials = recipe.materials.map(material => (material.id === 'bronze' ? { id: 'bronze', color: [0.85, 0.12, 0.1] } : material));
return recipe;
})(),
+ 'ask-user-pin-shared': (() => {
+ const recipe = stageRecipe();
+ recipe.materials.push({ id: 'plinth-red', color: [0.85, 0.12, 0.1] });
+ recipe.nodes = recipe.nodes.map(node => (node.id === 'plinth' ? { ...node, material: 'plinth-red' } : node));
+ return recipe;
+ })(),
'ask-user-lasso': (() => {
const recipe = stageRecipe();
recipe.materials = recipe.materials.map(material => (material.id === 'bronze' ? { id: 'bronze', color: [0.1, 0.2, 0.85] } : material));
diff --git a/bench/agent-modeling/suite.mjs b/bench/agent-modeling/suite.mjs
index 1fc5ae59..71005eca 100644
--- a/bench/agent-modeling/suite.mjs
+++ b/bench/agent-modeling/suite.mjs
@@ -28,6 +28,7 @@ export const BENCH_TASKS = [
{ id: 'look-metal', kind: 'look' },
{ id: 'look-fog', kind: 'look' },
{ id: 'ask-user-pin', kind: 'look', topics: ['askUser'] },
+ { id: 'ask-user-pin-shared', kind: 'look', topics: ['askUser'] },
{ id: 'ask-user-lasso', kind: 'look', topics: ['askUser'] },
{ id: 'render-pick', kind: 'light' },
{ id: 'light-pick-hard', kind: 'light' },
diff --git a/changes/1972.md b/changes/1972.md
new file mode 100644
index 00000000..d6cc8ed5
--- /dev/null
+++ b/changes/1972.md
@@ -0,0 +1 @@
+- `scene_ask_user`: a pin on a part whose material other parts also use returns `materialSharedWith` (and `materialSharedWithMore`) like a lasso part, so an agent gives the part its own material before recolouring it; the bench has a new task, `ask-user-pin-shared` (#1972).
diff --git a/docs/mcp.md b/docs/mcp.md
index 974664ea..b6cd5c84 100644
--- a/docs/mcp.md
+++ b/docs/mcp.md
@@ -223,7 +223,7 @@ Imported clip sampling remains available through `set-animation`.
`scene_ask_user` is for a change the person cannot put in words. It renders the current view, opens it in their default browser on a loopback address under a random path, and waits up to `timeoutSeconds` (default 300, at most 900) for them to pin up to 16 points with a note of at most 280 characters each and press Send. Each mark comes back with its pixel, the `partId` and world `point` and `normal` the pin lands on (all `null` on empty sky), the `distance` from the camera and the part's `material`, plus the `view` camera and a PNG with the numbered pins. A cancelled or timed-out page returns `outcome` `cancelled` or `timeout` with no marks. Nothing leaves the machine and the tool takes no code or remote URL.
-The page also has a lasso tool: the person draws a closed outline around a region (3 to 64 points, thinned from the pen stroke) and adds a note, so one mark can mean "these parts". Such a mark counts toward the 16 and comes back with the pin fields plus `kind` `"lasso"`, `points` and `parts`. `parts` lists the parts under the outline, most covered first, each as `{ partId, samples, coverage, material }`: the server picks a fixed 24 by 24 grid of pixels over the outline's bounding box, keeps the ones inside it (even-odd rule) and runs the same pick as a pin on each, so `coverage` is the share of those pixels a part holds (pixels on empty sky count toward no part, so the shares may add up to less than 1). `pixel`, `partId`, `point`, `normal`, `distance` and `material` are those of the most covered part, taken at the picked pixel nearest the outline's centre; `parts` is empty and `partId` `null` when the outline holds only sky. A part under 0.15 coverage carries `edge: true` and stays listed: it only grazes the outline. A part whose material is also used by parts outside the mark carries `materialSharedWith` (those part IDs, sorted, at most 8, plus `materialSharedWithMore` with the count left over): recolouring that material would change them too, so give the part its own material first. Pins are unchanged. The inline chat view and the review page take pins only. Not yet marks: dragged transforms, colours, saved views and film times (issue #922 lists them).
+The page also has a lasso tool: the person draws a closed outline around a region (3 to 64 points, thinned from the pen stroke) and adds a note, so one mark can mean "these parts". Such a mark counts toward the 16 and comes back with the pin fields plus `kind` `"lasso"`, `points` and `parts`. `parts` lists the parts under the outline, most covered first, each as `{ partId, samples, coverage, material }`: the server picks a fixed 24 by 24 grid of pixels over the outline's bounding box, keeps the ones inside it (even-odd rule) and runs the same pick as a pin on each, so `coverage` is the share of those pixels a part holds (pixels on empty sky count toward no part, so the shares may add up to less than 1). `pixel`, `partId`, `point`, `normal`, `distance` and `material` are those of the most covered part, taken at the picked pixel nearest the outline's centre; `parts` is empty and `partId` `null` when the outline holds only sky. A part under 0.15 coverage carries `edge: true` and stays listed: it only grazes the outline. A part whose material is also used by parts outside the mark carries `materialSharedWith` (those part IDs, sorted, at most 8, plus `materialSharedWithMore` with the count left over): recolouring that material would change them too, so give the part its own material first. A pin gets the same warning: the part it lands on carries `materialSharedWith` (and `materialSharedWithMore`) when other parts use its material. The inline chat view and the review page take pins only. Not yet marks: dragged transforms, colours, saved views and film times (issue #922 lists them).
#### Inline in chat apps (MCP Apps)
diff --git a/src/agent-annotate.js b/src/agent-annotate.js
index 20a595ec..50ed6729 100644
--- a/src/agent-annotate.js
+++ b/src/agent-annotate.js
@@ -206,13 +206,14 @@ function describeLasso(mark, index, camera, { width, height, raycast, partMateri
/**
* Numbers the marks and attaches what each one points at: part ID, world point, normal and distance, or null on empty sky.
* A lasso also returns kind, points and parts (the parts under its outline); its partId and point are the most covered part's.
- * partMaterials ({ partId: material }, optional) lets each lasso part list materialSharedWith, the unmarked parts on its material.
+ * partMaterials ({ partId: material }, optional) lets each lasso part, and the part a pin lands on, list materialSharedWith: the unmarked parts on its material.
* A part covering under ANNOTATE_LIMITS.edgeCoverage of the picked pixels is marked edge: true and stays listed.
*/
export function describeMarks(marks, camera, { width, height, raycast, partMaterials }) {
return marks.map((mark, index) => {
if (mark.kind === 'lasso') return describeLasso(mark, index, camera, { width, height, raycast, partMaterials });
const hit = raycast(pixelRay(camera, mark.x, mark.y, width, height));
- return { number: index + 1, pixel: [mark.x, mark.y], note: mark.note, ...hitFields(hit) };
+ const shared = hit ? sharedMaterialFields(hit.material ?? null, new Set([hit.id]), partMaterials, hit.id) : {};
+ return { number: index + 1, pixel: [mark.x, mark.y], note: mark.note, ...hitFields(hit), ...shared };
});
}
diff --git a/tests/agent-annotate-lasso.test.js b/tests/agent-annotate-lasso.test.js
index 7ef69eeb..4a0b6753 100644
--- a/tests/agent-annotate-lasso.test.js
+++ b/tests/agent-annotate-lasso.test.js
@@ -167,9 +167,25 @@ test('a part under 15 percent of the picked pixels is marked edge: true and stay
assert.equal(ANNOTATE_LIMITS.edgeCoverage, 0.15);
});
-test('a pin result is unchanged by partMaterials', () => {
+test('a pin result gains materialSharedWith only when partMaterials shows other parts on its material', () => {
const pin = { x: 100, y: 100, note: 'pin' };
const expected = { number: 1, pixel: [100, 100], note: 'pin', partId: 'wall', point: [-1, 0, 0], normal: [0, 0, 1], distance: 10, material: 'plaster' };
assert.deepEqual(describeMarks([pin], camera, { ...view, raycast: wallLampSky })[0], expected);
- assert.deepEqual(describeMarks([pin], camera, { ...view, raycast: wallLampSky, partMaterials: { wall: 'plaster', other: 'plaster' } })[0], expected);
+ assert.deepEqual(describeMarks([pin], camera, { ...view, raycast: wallLampSky, partMaterials: { wall: 'plaster', other: 'paint' } })[0], expected, 'a unique material has no field');
+ assert.deepEqual(
+ describeMarks([pin], camera, { ...view, raycast: wallLampSky, partMaterials: { wall: 'plaster', zeta: 'plaster', alpha: 'plaster' } })[0],
+ { ...expected, materialSharedWith: ['alpha', 'zeta'] },
+ );
+});
+
+test('a pin on empty sky has no materialSharedWith, and a pin list caps it at 8 with a count of the rest', () => {
+ const sky = { x: 100, y: 100, note: 'sky' };
+ assert.equal('materialSharedWith' in describeMarks([sky], camera, { ...view, raycast: () => null, partMaterials: { wall: 'plaster' } })[0], false);
+ const raycast = () => ({ id: 'plinth', point: [0, 0, 0], normal: [0, 1, 0], distance: 5, material: 'stone' });
+ const partMaterials = { plinth: 'stone' };
+ for (let index = 0; index < 11; index++) partMaterials[`floor-${String(index).padStart(2, '0')}`] = 'stone';
+ const [pin] = describeMarks([{ x: 100, y: 100, note: 'pin' }], camera, { ...view, raycast, partMaterials });
+ assert.equal(pin.materialSharedWith.length, 8);
+ assert.equal(pin.materialSharedWith[0], 'floor-00');
+ assert.equal(pin.materialSharedWithMore, 3);
});
diff --git a/tests/agent-bench-subsets.test.js b/tests/agent-bench-subsets.test.js
index 12908561..b26abda8 100644
--- a/tests/agent-bench-subsets.test.js
+++ b/tests/agent-bench-subsets.test.js
@@ -79,19 +79,19 @@ test('bench.mjs --dry-run lists the selected tasks and rejects unknown values wi
assert.throws(() => execFileSync(process.execPath, [benchPath, '--topics', 'nope', '--dry-run'], { encoding: 'utf8', stdio: 'pipe' }), /Unknown topic nope/);
});
-test('--tasks accepts a scene task that the default run leaves out, and the default run stays on the 32 bench tasks', () => {
+test('--tasks accepts a scene task that the default run leaves out, and the default run stays on the 33 bench tasks', () => {
assert.deepEqual(OPTIONAL_TASK_IDS, ['findings-fix']);
assert.deepEqual(selectTasks({ tasks: 'findings-fix' }, BENCH_TASKS, OPTIONAL_TASK_IDS), ['findings-fix']);
assert.deepEqual(selectTasks({ tasks: 'findings-fix,bolt' }, BENCH_TASKS, OPTIONAL_TASK_IDS), ['bolt', 'findings-fix']);
- assert.equal(selectTasks({}, BENCH_TASKS, OPTIONAL_TASK_IDS).length, 32);
+ assert.equal(selectTasks({}, BENCH_TASKS, OPTIONAL_TASK_IDS).length, 33);
assert.equal(selectTasks({ kinds: 'light' }, BENCH_TASKS, OPTIONAL_TASK_IDS).includes('findings-fix'), false);
assert.throws(() => selectTasks({ tasks: 'nope' }, BENCH_TASKS, OPTIONAL_TASK_IDS), /Unknown task nope\. Valid tasks: crate,.*findings-fix\./);
});
-test('bench.mjs --tasks findings-fix --dry-run selects it, an unknown id lists the valid ids, the default dry run selects 32 tasks', () => {
+test('bench.mjs --tasks findings-fix --dry-run selects it, an unknown id lists the valid ids, the default dry run selects 33 tasks', () => {
const run = argumentsList => execFileSync(process.execPath, [benchPath, ...argumentsList, '--dry-run'], { encoding: 'utf8', stdio: 'pipe' });
- assert.match(run(['--tasks', 'findings-fix']), /^1 of 32 tasks: findings-fix/);
- assert.match(run([]), /^32 of 32 tasks: crate,/);
+ assert.match(run(['--tasks', 'findings-fix']), /^1 of 33 tasks: findings-fix/);
+ assert.match(run([]), /^33 of 33 tasks: crate,/);
assert.throws(() => run(['--tasks', 'nope']), /Unknown task nope\. Valid tasks: crate,.*findings-fix\./s);
});
diff --git a/tests/agent-bench.test.js b/tests/agent-bench.test.js
index c0b19d27..60b10bfd 100644
--- a/tests/agent-bench.test.js
+++ b/tests/agent-bench.test.js
@@ -11,8 +11,8 @@ import { taskById } from '../bench/agent-modeling/tasks.mjs';
const failedKinds = grade => grade.results.filter(result => !result.pass).map(result => result.label ?? result.kind);
-test('the bench has 20 to 32 tasks, each known to the suite, covering every kind of work', () => {
- assert.ok(BENCH_TASKS.length >= 20 && BENCH_TASKS.length <= 32, `${BENCH_TASKS.length} tasks`);
+test('the bench has 20 to 33 tasks, each known to the suite, covering every kind of work', () => {
+ assert.ok(BENCH_TASKS.length >= 20 && BENCH_TASKS.length <= 33, `${BENCH_TASKS.length} tasks`);
assert.equal(new Set(BENCH_TASKS.map(task => task.id)).size, BENCH_TASKS.length);
for (const { id } of BENCH_TASKS) assert.ok(taskById(id).checks.length > 0, id);
for (const id of SMOKE_TASKS) assert.ok(BENCH_TASKS.some(task => task.id === id), id);
@@ -40,6 +40,12 @@ test('the camera, light, look and film tasks reject plausible wrong answers', as
assert.deepEqual(failedKinds(await wrong('film-reveal', recipe => { recipe.motion.tracks.pop(); })), ['exposure fades up']);
assert.deepEqual(failedKinds(await wrong('ask-user-lasso', recipe => { recipe.materials.find(material => material.id === 'bronze').color = [0.45, 0.3, 0.2]; })), ['the lassoed statue is blue']);
assert.deepEqual(failedKinds(await wrong('ask-user-lasso', recipe => { recipe.nodes.find(node => node.id === 'plinth').material = 'stone'; })), ['the lassoed plinth is blue']);
+ assert.deepEqual(failedKinds(await wrong('ask-user-pin-shared', recipe => { recipe.nodes.find(node => node.id === 'plinth').material = 'stone'; })), ['the pinned plinth is red']);
+ // The shared stone material: reddening it reddens the floor too, which the pin did not cover.
+ assert.deepEqual(failedKinds(await wrong('ask-user-pin-shared', recipe => {
+ recipe.materials.find(material => material.id === 'stone').color = [0.85, 0.12, 0.1];
+ recipe.nodes.find(node => node.id === 'plinth').material = 'stone';
+ })), ['the floor sharing its material is not recoloured']);
// The shared stone material: colouring it blue colours the floor too, which the lasso did not cover.
assert.deepEqual(failedKinds(await wrong('ask-user-lasso', recipe => {
recipe.materials.find(material => material.id === 'stone').color = [0.1, 0.2, 0.85];
diff --git a/tests/ask-user-fixture.test.js b/tests/ask-user-fixture.test.js
index 22cb8d86..81bd7461 100644
--- a/tests/ask-user-fixture.test.js
+++ b/tests/ask-user-fixture.test.js
@@ -159,6 +159,24 @@ test('the variable is in no flag list and no tool schema', async () => {
assert.ok(mentions.every(line => !/register\(|z\.|describe\(/.test(line)), mentions.join('\n'));
});
+test('the bench pin on the plinth lands on it at the stage camera and warns that the floor shares its stone (#1972)', async () => {
+ const task = taskById('ask-user-pin-shared');
+ assert.ok(BENCH_TASKS.find(candidate => candidate.id === 'ask-user-pin-shared').topics.includes('askUser'));
+ const sharedFixture = join(import.meta.dirname, '..', 'bench', 'agent-modeling', 'ask-user-pin-shared.json');
+ assert.deepEqual(askUserEnvironment(task), { [ASK_USER_FIXTURE_VARIABLE]: resolve(sharedFixture) });
+ const fixture = loadFrom(sharedFixture);
+ const { preview } = previewHarness();
+ preview.create({ recipe: structuredClone(task.startRecipe), sessionId: 'pin-shared', backend: 'cpu', memoryBudgetMiB: 64 });
+ const frame = preview.annotateFrame({ sessionId: 'pin-shared' });
+ const picked = await preview.pickMarks({ sessionId: 'pin-shared', camera: frame.camera, width: frame.width, height: frame.height, marks: fixture.marks });
+ const [mark] = picked.marks;
+ assert.equal(mark.partId, 'plinth');
+ assert.equal(mark.note, 'make this red');
+ assert.deepEqual(mark.materialSharedWith, ['floor']);
+ const statuePick = await preview.pickMarks({ sessionId: 'pin-shared', camera: frame.camera, width: frame.width, height: frame.height, marks: loadFrom(benchFixture).marks });
+ assert.equal('materialSharedWith' in statuePick.marks[0], false, 'the statue has a material of its own');
+});
+
test('only a bench task tagged askUser gets the fixture, and its pin lands on the statue at the bench camera', async () => {
const task = taskById('ask-user-pin');
assert.ok(BENCH_TASKS.find(candidate => candidate.id === 'ask-user-pin').topics.includes('askUser'));