3D engine that AI agents drive
JavaScript 3d3d-engineagentic-aiai-agentsblenderclaude-codegame-enginegaussian-splattinggltfjavascriptmcpmcp-servermodel-context-protocolpath-tracerpath-tracingpbrrenderingthreejs-alternativewebgl2webgpu
Merge main into the icons sketch branch and give sketch a typed schema (#2031)
Nguyen Xuan An405807e6f68e
diff --cc changes/2031-sketch.mdindex 00000000,00000000..ae556a94new file mode 100644--- /dev/null+++ b/changes/2031-sketch.md@@@ -1,0 -1,0 +1,1 @@@++- Icon jobs gain `style: "sketch"`, which inks the outline and hatches the shadow with pencil lines that still read at 64 px; `angles: 4|8` draws a turnaround sheet per item, and `breakdown: true` writes a shaded, outline, hatching, final strip per item (#2031)diff --cc changes/2031-sketch.size.mdindex 00000000,00000000..bc8e1c32new file mode 100644--- /dev/null+++ b/changes/2031-sketch.size.md@@@ -1,0 -1,0 +1,2 @@@++- tool:scene_render_submit: the `icons` job kind adds `items`, `size`, `style`, `viewpoint`, `scale`, `padding`, `angles`, `breakdown`, `seed` and `sketch` so an agent can ask for a whole icon set, a turnaround or a breakdown in one call; each field is bare and named, the detail (ranges, defaults, errors) stays in `scene_capabilities` topic `jobs` under `icons`, and the new code sits in the MCP server bundle only.++- tool-total: 1167 bytes over the base for `scene_render_submit` (5901 against its 6000 ceiling), 42 of them from this slice's `angles`, `breakdown`, `seed` and `sketch`; no new tool.diff --cc docs/agent-render-jobs.mdindex b7979945,6602c8b8..e7fa3849--- a/docs/agent-render-jobs.md+++ b/docs/agent-render-jobs.md@@@ -206,11 -226,7 +230,11 @@@ The camera is orthographic, so an item'Framing fits the silhouette, not the bounding sphere. The job draws the item once from a bounding sphere, measures the alpha box of what was drawn and moves the camera until that box is centred and spans the icon minus its padding (up to four draws per item). A thin or flat item such as a sword or a coin therefore fills its icon instead of drawing small. An item that draws nothing, or cannot be framed in four draws, fails the job and names the item.-Output, all in the job's folder: `icon-0.png` to `icon-<n-1>.png` (one per item, in order), `atlas.png` (a near square grid, row by row, transparent where unused) and `icons.json`:+### The sketch style+- Sketch is a [user pass](user-passes.md) on the shaded frame, so it has the same scene, camera and framing as the other styles. It inks the outline from the silhouette, the depth steps and the creases, hatches the shadow with pencil lines in three directions chosen by how dark the light is, and fills the model with paper. Hatch spacing is laid out in whole pixels (3 px at 64, growing with the icon) so the lines do not beat against the pixel grid. A test renders a model at 64 px and checks that the sketch stays a line pattern: the outline is inked along at least 95 percent of the silhouette, and in the hatched band at least 80 percent of the pixels are clearly paper or ink, not grey, with a contrast of at least 0.7 of the ink to paper range. [Icon sheets](learn/icon-sheets.md) (the docs guide page) shows the three styles and a breakdown.++Sketch is a [user pass](user-passes.md) on the shaded frame, so it has the same scene, camera and framing as the other styles. It inks the outline from the silhouette, the depth steps and the creases, hatches the shadow with pencil lines in three directions chosen by how dark the light is, and fills the model with paper. Hatch spacing is laid out in whole pixels (3 px at 64, growing with the icon) so the lines do not beat against the pixel grid. A test renders a model at 64 px and checks that the sketch stays a line pattern: the outline is inked along at least 95 percent of the silhouette, and in the hatched band at least 80 percent of the pixels are clearly paper or ink, not grey, with a contrast of at least 0.7 of the ink to paper range. [Icon sheets](https://github.com/codepawl/crucible/blob/main/docs/learn/icon-sheets.md) (the docs guide page) shows the three styles and a breakdown.++Output, all in the job's folder: `icon-0.png` to `icon-<n-1>.png` (one per frame, items first and then angles), `breakdown-<item>.png` (one strip per item, with `breakdown`), `atlas.png` (a near square grid, row by row, transparent where unused) and `icons.json`:```json{ "version": 1, "size": 256, "style": "toon", "scale": "relative", "padding": 0.08, "viewpoint": { "azimuth": 35, "elevation": 25 },diff --cc scripts/agent-render-jobs.mjsindex 877d67e2,ca493d79..b3777191--- a/scripts/agent-render-jobs.mjs+++ b/scripts/agent-render-jobs.mjs@@@ -317,11 -304,32 +318,32 @@@ function passesFrom(passes, kind)return [...passes];}- /** Every artifact filename of a job, lit image first and then each requested pass, frame by frame. */- export function artifactNames(kind, passes = [], format = 'png', multilayer = false, stillCount = 8, iconSettings = {}) {+ const MAXIMUM_MATTES = 8;+ const MAXIMUM_MATTE_NAME_LENGTH = 120;++ /** The ID mattes of a job: each names one object (part) or one material, and writes one gray PNG per frame. */+ function mattesFrom(input) {+ const { mattes, kind, renderer, format, multilayer } = input;+ if (kind === 'video') throw new RangeError('mattes need kind image or stills; a video holds the lit image only.');+ if (renderer !== undefined) throw new RangeError('mattes cannot combine with renderer: the path tracer has no object ID or Cryptomatte pass. Leave renderer out.');+ if (format !== undefined && format !== 'png') throw new RangeError('mattes are 8-bit PNG files: leave format out or use png.');+ if (multilayer) throw new RangeError('mattes cannot combine with multilayer. Leave multilayer out.');+ if (!Array.isArray(mattes) || mattes.length < 1 || mattes.length > MAXIMUM_MATTES) throw new TypeError(`mattes must list 1 to ${MAXIMUM_MATTES} entries, each { object: "<part name>" } or { material: "<material name>" }.`);+ return mattes.map((matte, index) => {+ objectKeys(matte, ['object', 'material'], `mattes[${index}]`);+ const kindsGiven = ['object', 'material'].filter(key => matte[key] !== undefined);+ if (kindsGiven.length !== 1) throw new TypeError(`mattes[${index}] needs exactly one of object or material. Pass { object: "<part name>" } or { material: "<material name>" }.`);+ const name = matte[kindsGiven[0]];+ if (typeof name !== 'string' || name.length < 1 || name.length > MAXIMUM_MATTE_NAME_LENGTH) throw new TypeError(`mattes[${index}].${kindsGiven[0]} must be a name of 1 to ${MAXIMUM_MATTE_NAME_LENGTH} characters. scene_render_result metrics.objectNames and metrics.cryptomatte list the names of a render.`);+ return { [kindsGiven[0]]: name };+ });+ }++ /** Every artifact filename of a job, lit image first and then each requested pass and matte, frame by frame. */-export function artifactNames(kind, passes = [], format = 'png', multilayer = false, stillCount = 8, mattes = []) {++export function artifactNames(kind, passes = [], format = 'png', multilayer = false, stillCount = 8, mattes = [], iconSettings = {}) {if (kind === 'video') return ['render.mp4'];- // An icons job has one frame per item, so its frame count is its item count.- if (kind === 'icons') return iconArtifactNames(stillCount);+ // An icons job has one frame per icon (an item at one angle); a breakdown adds one strip per item.+ if (kind === 'icons') return iconArtifactNames(stillCount, { itemCount: iconSettings.breakdown ? iconSettings.items.length : 0 });const extension = format === 'exr' ? 'exr' : 'png';const stems = kind === 'image' ? ['render'] : Array.from({ length: stillCount }, (_, index) => `frame-${index}`);if (multilayer) return stems.map(stem => `${stem}.${extension}`);@@@ -856,7 -864,7 +878,7 @@@ export async function createAgentRenderboundedNumber(record.progress.maximumPendingFrames, 0, 1, 'persisted pending frames', true);if (record.metrics !== undefined) record.metrics = jsonCopy(record.metrics, 65536);if (record.reason !== undefined && (typeof record.reason !== 'string' || record.reason.length > 2048)) throw new Error('Invalid persisted job reason.');- const namesAllowed = artifactNames(settings.kind, settings.passes, settings.format, settings.multilayer, settings.frameCount, settings);- const namesAllowed = artifactNames(settings.kind, settings.passes, settings.format, settings.multilayer, settings.frameCount, settings.mattes);++ const namesAllowed = artifactNames(settings.kind, settings.passes, settings.format, settings.multilayer, settings.frameCount, settings.mattes, settings);if (!Array.isArray(record.artifacts) || record.artifacts.length > namesAllowed.length) throw new Error('Invalid persisted artifacts.');const seen = new Set();for (const artifact of record.artifacts) {@@@ -939,7 -947,7 +961,7 @@@record.state = 'finalizing';await persist(job);objectKeys(completed, ['artifacts', 'metrics'], 'runner result');- const expected = artifactNames(record.settings.kind, record.settings.passes, record.settings.format, record.settings.multilayer, record.settings.frameCount, record.settings);- const expected = artifactNames(record.settings.kind, record.settings.passes, record.settings.format, record.settings.multilayer, record.settings.frameCount, record.settings.mattes);++ const expected = artifactNames(record.settings.kind, record.settings.passes, record.settings.format, record.settings.multilayer, record.settings.frameCount, record.settings.mattes, record.settings);if (!Array.isArray(completed.artifacts) || completed.artifacts.length !== expected.length) throw new Error('Runner did not return the required fixed artifacts.');const directory = await directoryFor(record.jobId);const metrics = jsonCopy(completed.metrics ?? {}, 65536);diff --cc scripts/mcp-server.mjsindex 93262821,9ef49688..229a0b5e--- a/scripts/mcp-server.mjs+++ b/scripts/mcp-server.mjs@@@ -867,18 -870,14 +870,18 @@@ function jobKeysHint(toolName, accepted}const renderSettings = z.strictObject({kind: z.enum(['image', 'stills', 'video', 'icons']),- width: z.number().int().min(64).max(MAXIMUM_JOB_SIDE).optional().describe('Not for icons, which use size.'),+ width: z.number().int().min(64).max(MAXIMUM_JOB_SIDE).optional(),height: z.number().int().min(64).max(MAXIMUM_JOB_SIDE).optional(),- items: z.array(z.string().max(260)).min(1).max(256).optional().describe('icons: catalog GLB names or asset ids, one PNG each plus atlas and icons.json. Every icons field: scene_capabilities jobs.icons.'),- size: z.number().int().min(64).max(512).optional().describe('icons: 64, 128, 256 or 512 px.'),- style: z.enum(['clean', 'toon', 'sketch']).optional(),- viewpoint: z.union([z.literal('three-quarter'), z.record(z.string(), z.number())]).optional().describe('icons: three-quarter or { azimuth, elevation }.'),- scale: z.enum(['fit', 'relative']).optional(),- padding: z.number().optional(),+ items: z.array(z.string().max(260)).min(1).max(256).optional().describe('icons: catalog GLB names or asset ids; a PNG each plus atlas.png, icons.json. See scene_capabilities jobs.icons.'),+ size: z.union([z.literal(64), z.literal(128), z.literal(256), z.literal(512)]).optional().describe('icons: pixels per icon side (default 256).'),- style: z.enum(['clean', 'toon', 'sketch']).optional().describe('icons: clean (default) or toon.'),++ style: z.enum(['clean', 'toon', 'sketch']).optional().describe('icons: clean (default), toon or sketch.'),+ viewpoint: z.union([z.literal('three-quarter'), z.strictObject({ azimuth: z.number().optional(), elevation: z.number().optional() })]).optional().describe('icons: three-quarter or azimuth/elevation degrees.'),+ scale: z.enum(['fit', 'relative']).optional().describe('icons: fit fills every icon; relative keeps one scale for the set.'),+ padding: z.number().optional().describe('icons: border fraction, 0.02 to 0.4.'),+ angles: z.number().int().min(1).max(8).optional().describe('icons: 1, 4 or 8 views per item.'),+ breakdown: z.boolean().optional().describe('icons, sketch: steps strip per item.'),+ seed: z.number().int().min(0).max(65535).optional(),- sketch: z.record(z.string(), z.union([z.string(), z.number()])).optional().describe('icons, sketch: inkColor, paperColor, hatchDensity, jitter.'),++ sketch: z.strictObject({ inkColor: z.string().max(32).optional(), paperColor: z.string().max(32).optional(), hatchDensity: z.number().optional(), jitter: z.number().optional() }).optional().describe('icons, sketch: inkColor, paperColor, hatchDensity, jitter.'),fps: z.number().int().min(1).max(MAXIMUM_JOB_FPS).optional(),duration: z.number().min(0.1).max(60).optional(),animation: z.strictObject({ clip: z.number().int().min(0), start: z.number().min(0).max(3600).optional() }).optional(),diff --cc tests/agent-icon-job.test.jsindex bb0eab35,5fc2c865..e6e8a57f--- a/tests/agent-icon-job.test.js+++ b/tests/agent-icon-job.test.js@@@ -175,68 -166,3 +175,68 @@@ test('the job store knows the icons setconst { frameCount, ...stored } = settings;assert.deepEqual(normalizeJobSettings(stored, [], {}), settings, 'stored settings normalise to themselves');});++test('a turnaround draws every item from each angle at one view height per item, one row per item in the atlas', async () => {+ const { files, settings, result, openedViews } = await runJob(['coin', 'chest'], { angles: 4, size: 64 });+ const manifest = JSON.parse(files['icons.json']);+ assert.equal(settings.frameCount, 8);+ assert.deepEqual(manifest.atlas, { file: 'atlas.png', width: 256, height: 128, columns: 4, rows: 2 });+ assert.deepEqual(manifest.icons.map(icon => [icon.item, icon.turn, icon.angle]), [[0, 0, 35], [0, 1, 125], [0, 2, -145], [0, 3, -55], [1, 0, 35], [1, 1, 125], [1, 2, -145], [1, 3, -55]]);+ const coinHeights = new Set(manifest.icons.slice(0, 4).map(icon => icon.viewHeight));+ const chestHeights = new Set(manifest.icons.slice(4).map(icon => icon.viewHeight));+ assert.equal(coinHeights.size, 1, 'the four views of the coin share one scale');+ assert.equal(chestHeights.size, 1, 'the four views of the chest share one scale');+ assert.notEqual([...coinHeights][0], [...chestHeights][0], 'each item keeps its own scale under fit');+ for (const icon of manifest.icons) {+ const box = iconBox(files[icon.file]);+ assert.ok(box.left >= 1 && box.top >= 1 && box.right <= 63 && box.bottom <= 63, `${icon.file} is clipped`);+ assert.ok(Math.abs((box.left + box.right) / 2 - 32) <= 1 && Math.abs((box.top + box.bottom) / 2 - 32) <= 1, `${icon.file} is off centre`);+ }+ assert.equal(result.artifacts.length, 10, 'eight icons, the atlas and icons.json');+ assert.deepEqual(openedViews.slice(0, 4), [[0, 35], [0, 125], [0, -145], [0, -55]], 'the first pass measures every angle of the first item');+});++test('a turnaround under relative scale keeps one scale for the whole set', async () => {+ const { files } = await runJob(['coin', 'chest'], { angles: 4, size: 64, scale: 'relative' });+ const manifest = JSON.parse(files['icons.json']);+ assert.equal(new Set(manifest.icons.map(icon => icon.viewHeight)).size, 1);+});++test('a breakdown strip shows shaded, outline, hatching and the final icon side by side, and is listed in icons.json', async () => {+ const { files, result, settings } = await runJob(['coin', 'chest'], { style: 'sketch', breakdown: true, size: 64, angles: 4 });+ const manifest = JSON.parse(files['icons.json']);+ assert.deepEqual(result.artifacts.map(artifact => artifact.filename).filter(name => name.startsWith('breakdown')), ['breakdown-0.png', 'breakdown-1.png']);+ assert.deepEqual(manifest.icons.filter(icon => icon.breakdown).map(icon => [icon.item, icon.turn, icon.breakdown]), [[0, 0, 'breakdown-0.png'], [1, 0, 'breakdown-1.png']]);+ assert.equal(result.artifacts.length, 8 + 2 + 2);+ for (const itemIndex of [0, 1]) {+ const strip = decodePng(files[`breakdown-${itemIndex}.png`]);+ assert.deepEqual([strip.width, strip.height], [settings.size * 4, settings.size]);+ const finalIcon = decodePng(files[`icon-${itemIndex * 4}.png`]);+ const colorOf = position => [...strip.data.subarray((32 * strip.width + position * settings.size + 32) * 4, (32 * strip.width + position * settings.size + 32) * 4 + 4)];+ assert.deepEqual([0, 1, 2].map(colorOf), [STEP_COLORS.shaded, STEP_COLORS.outline, STEP_COLORS.hatching], 'the first three panels are the steps in order');+ for (let row = 0; row < settings.size; row++) {+ const panel = strip.data.subarray((row * strip.width + 3 * settings.size) * 4, (row * strip.width + 4 * settings.size) * 4);+ assert.ok(panel.equals(finalIcon.data.subarray(row * settings.size * 4, (row + 1) * settings.size * 4)), `the last panel is the final icon (row ${row})`);+ }+ }+});++test('the same sketch job with a breakdown writes byte-identical files', async () => {+ const options = { style: 'sketch', breakdown: true, size: 64, angles: 4, seed: 3 };+ const first = await runJob(['coin', 'sword'], options);+ const second = await runJob(['coin', 'sword'], options);+ assert.deepEqual(Object.keys(first.files), Object.keys(second.files));+ for (const name of Object.keys(first.files)) assert.ok(first.files[name].equals(second.files[name]), `${name} differs between runs`);+});++test('the job store lists the breakdown strips among the artifacts it expects, and a longer deadline for icons', () => {+ const settings = normalizeJobSettings({ kind: 'icons', items: ['a.glb', 'b.glb'], size: 64, style: 'sketch', breakdown: true, angles: 4 }, [], {});- assert.deepEqual(artifactNames('icons', [], 'png', false, settings.frameCount, settings).slice(8, 10), ['breakdown-0.png', 'breakdown-1.png']);- assert.equal(artifactNames('icons', [], 'png', false, settings.frameCount, settings).length, 8 + 2 + 2);++ assert.deepEqual(artifactNames('icons', [], 'png', false, settings.frameCount, [], settings).slice(8, 10), ['breakdown-0.png', 'breakdown-1.png']);++ assert.equal(artifactNames('icons', [], 'png', false, settings.frameCount, [], settings).length, 8 + 2 + 2);+ const { frameCount, ...stored } = settings;+ assert.deepEqual(normalizeJobSettings(stored, [], {}), settings);+ assert.ok(jobDeadlineMs(settings) > 60000 + 8 * 4000 * 2, 'two passes of eight frames and two strips fit the deadline');+ const plain = normalizeJobSettings({ kind: 'icons', items: ['a.glb'], size: 64 }, [], {});+ assert.equal(jobDeadlineMs(plain), 60000 + 4000);+ assert.equal(jobDeadlineMs(normalizeJobSettings({ kind: 'icons', items: Array.from({ length: 256 }, (_, index) => `i${index}.glb`), size: 64, scale: 'relative' }, [], {})), 30 * 60 * 1000);+});