bake-multi-res
PURPOSE
Bake a single baked-component definition at multiple tile sizes in one call, returning one PNG-bearing BakeResult per resolution. Runtime selects the appropriate resolution based on DPR × visual size; ComponentEditor uses this to write size-suffixed atlas PNGs (e.g. body_bolt_t64.png).
OWNS
MultiResBakeResultinterface —{ tileSize: number; result: BakeResult }.DEFAULT_BAKE_RESOLUTIONS—readonly [64, 128, 256].bakeComponentMultiRes(def, tileSizes?)— async function returningMultiResBakeResult[].
READS FROM
./bake—bakeComponent(per-pass execution) andComponentDeftype../atlas-format—BakeResulttype.def.baked.bake.tileSize— used as hint only; overridden per pass.
PUSHES TO
- Returns
MultiResBakeResult[]to the caller. No I/O of its own. - Caller (ComponentEditor) POSTs each
result.pngBytesto/__dev/atlas-writewith a size-suffixed filename.
DOES NOT
- Does not write files, hit the network, or touch the atlas registry.
- Does not mutate the input
def— patches a shallow clone per pass. - Does not parallelize bakes; passes run sequentially via
awaitin aforloop. - Does not handle non-baked components — throws if
def.kind !== 'baked'ordef.bakedmissing.
Signals
- Throws
Error("bakeComponentMultiRes: <id> is not a baked component")when the component definition is not ofkind === 'baked'or lacks abakedblock.
Entry points
- Called by ComponentEditor (VFX workbench UI) to produce the per-resolution atlas PNG set for a baked component.
- Default invocation bakes at 64 / 128 / 256 px tiles; caller may supply any
readonly number[]of tile sizes.
Pattern notes
- The component’s
baked.bake.tileSizeis treated as a hint only — each pass deep-patchesbake: { ...def.baked.bake, tileSize }so the per-passtileSizewins. The originaldefis untouched. - Sequential
await(notPromise.all) — bakes likely share a Canvas / GPU context, so serialization is intentional. - The size-suffix filename convention (
<id>_t<size>.png) is enforced by the caller, not this module.
EXTRACT-CANDIDATE
- The pattern “patch one nested field per pass, await, collect results” is generic enough to live in a shared
mapAsyncWithPatchhelper if other workbench tooling adopts it. Currently single-use; not yet warranted. DEFAULT_BAKE_RESOLUTIONScould move to a shared atlas-resolution constants module if runtime-side DPR resolution selection grows beyond ad-hoc thresholds.