Skip to content

3D engine that AI agents drive

Merge main into 2031-icons-render-job

Nguyen Xuan An113e99138f0c
diff --cc scripts/agent-render-jobs.mjs
index 31f92bbf,ae1f4fc2..b7274883
--- a/scripts/agent-render-jobs.mjs
+++ b/scripts/agent-render-jobs.mjs
@@@ -110,9 -109,8 +110,9 @@@ export function normalizeJobSettings(in
}
function settingsFrom(input, clips = [], recipe) {
+ if (input?.kind === 'icons') return normalizeIconSettings(input);
- objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'renderer', 'timeline', 'audio', 'encoder', 'transparent', 'format', 'multilayer', 'region', 'quality', 'stillCount'], 'settings');
+ objectKeys(input, ['kind', 'width', 'height', 'fps', 'duration', 'animation', 'motion', 'rendererTime', 'passes', 'renderer', 'timeline', 'audio', 'encoder', 'transparent', 'format', 'multilayer', 'region', 'quality', 'stillCount', 'mattes'], 'settings');
- if (!['image', 'stills', 'video'].includes(input.kind)) throw new TypeError('kind must be image, stills or video.');
+ if (!['image', 'stills', 'video'].includes(input.kind)) throw new TypeError('kind must be image, stills, video or icons.');
const largeFrame = input.kind === 'image';
const maximumSide = largeFrame ? MAXIMUM_JOB_SIDE : MAXIMUM_SEQUENCE_JOB_SIDE;
const maximumPixels = largeFrame ? MAXIMUM_JOB_PIXELS : MAXIMUM_SEQUENCE_JOB_PIXELS;
@@@ -303,20 -302,38 +304,41 @@@ 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) {
+ 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 = []) {
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);
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}`);
- return stems.flatMap(stem => [`${stem}.${extension}`, ...passes.map(pass => `${stem}-${pass}.${extension}`)]);
+ return stems.flatMap(stem => [`${stem}.${extension}`, ...passes.map(pass => `${stem}-${pass}.${extension}`), ...mattes.map((_, index) => `${stem}-matte-${index}.png`)]);
}
-function artifactMimeType(settings) {
+function artifactMimeType(settings, filename = '') {
if (settings.kind === 'video') return 'video/mp4';
+ if (settings.kind === 'icons' && filename.endsWith('.json')) return 'application/json';
return settings.format === 'exr' ? 'image/x-exr' : 'image/png';
}
@@@ -354,7 -370,7 +376,7 @@@ function artifactByteLimit(settings, li
function allowedFile(name) {
const passNames = RENDER_PASS_NAMES.join('|');
- const artifact = new RegExp(`^(?:render\\.(?:png|mp4|exr)|(?:icon-\\d{1,3}|atlas)\\.png|icons\\.json|(?:render|frame-\\d{1,3})(?:-(?:${passNames}))?\\.(?:png|exr))(?:\\.partial)?$`);
- const artifact = new RegExp(`^(?:render\\.(?:png|mp4|exr)|(?:render|frame-\\d{1,3})(?:-(?:${passNames}|matte-[0-7]))?\\.(?:png|exr))(?:\\.partial)?$`);
++ const artifact = new RegExp(`^(?:render\\.(?:png|mp4|exr)|(?:icon-\\d{1,3}|atlas)\\.png|icons\\.json|(?:render|frame-\\d{1,3})(?:-(?:${passNames}|matte-[0-7]))?\\.(?:png|exr))(?:\\.partial)?$`);
return INTERNAL_FILES.has(name) || artifact.test(name);
}
diff --cc scripts/agent-runtime.mjs
index aad0a3e9,3327fc21..1accca07
--- a/scripts/agent-runtime.mjs
+++ b/scripts/agent-runtime.mjs
@@@ -44,8 -44,7 +44,9 @@@ import { RENDER_QUALITY_NOTE, applyQual
import { RENDER_BUDGET_NOTE, chooseBudgetSettings, parseBudget } from './agent-render-budget.mjs';
import { RENDER_ESTIMATE_NOTE, estimateRenderJob, historyWithJob, parseHistory, pathTraceTriangleProblem, renderReport, sceneSizeFrom } from './agent-render-estimate.mjs';
import { objectIdMetrics } from './agent-object-id-metrics.mjs';
+import { renderIconsInPage } from './agent-icon-page.mjs';
+import { ICON_CAPABILITIES } from '../src/icon-sheet.js';
+ import { renderJobMattes } from './job-mattes.mjs';
import { encodeRenderOutput, encodeMultilayerExr } from './render-output-encoders.mjs';
import { createFrameEncoder } from './frame-encoder.mjs';
import { DEFAULT_PAGE_ENCODER_QUANTIZER, createFrameReceiver, startVideoEncoderInPage } from './gpu-frame-reader.mjs';