A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(look): text, a grid on a face, buildings in perspective, reflections
yhh768b4e87799d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 27431576b..93188739e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,7 +22,7 @@ published separately; it ships inside the editor.- **Glyphs can be put on the atlas before they are shown.** The first page of a novel is hundreds of new characters, all landing in one frame. `preloadGlyphs(app, label, text, { budgetMs })` makes them ahead of time, a slice a frame, drawn as that `Text` will draw them, and returns `progress`, `done` and `release()`. On a Snapdragon 8 Elite a book's 2992 characters at 28 px took 145 ms over 25 frames with the worst frame at 9.5 ms, after which the first page's frame went from 49 to 11 ms and no page made a new glyph. Preloaded glyphs hold their atlas pages (4 MB each, a few hundred characters at that size) until `release()`.- **Voxel GI lights what the camera does not see, and bounces light more than once.** The cache now reads the sun's shadow map back into the world, so a surface the sun lights behind or beside the camera still sends light into the view. Each surface also gives off again the bounce light it received, so a corner or a floor in shade gets light that took two or more bounces to reach it. A ray now brings what it meets at full strength however far it went (it used to fade with distance, 40% at 4 m with 12 cm voxels). Each voxel is weighed by how much of it a surface covers, so a bright patch no longer lights like the whole voxel around it. Together these keep the result close to a path tracer's whatever the voxel size. In a sunlit test room the whole frame carries 0.95 of Cycles' light at the default size and 0.74 at 12 cm voxels; before, it was 0.54 at the default and darker the finer the grid. With the lit patch behind the camera, the walls went from no bounce light to 25–57%. A closed room the sun only lights from outside stays dark. Two inspector controls tune it: **Off-screen Sun Albedo** (the colour the shadow map cannot give, assumed) and **Multi-bounce**. A fine grid no longer drops every voxel: a count truncated by the cache's ageing had kept them below the two samples a ray asks for. The WebGL2 fallback does the same in its own passes: each voxel asks the sun's map whether a sunlit surface stands in it, and traces two rays through last frame's grid for the light it is given. In the test room it carries 1.00 of Cycles' light at the default size (it was 0.56) and 0.80 at 12 cm; with the lit patch behind the camera 0.20 (it was 0). Its voxel pass costs about 1.3 ms more at 720p on a desktop.-- **An AI can draw 2D pictures.** `image_write` turns layers into a `.png` beside an `.esimage`: shapes and SVG paths, gradients, strokes, shadows and glows, clipping and cutting, or pixel art as rows of characters. It answers with the picture on a mid ground and a light check and at 96, 64, 48 and 32 pixels, to look at and correct; `image_edit` changes one layer, a row or a block of pixels without restating the rest, and moves layers or wraps them in a group. Strokes can keep sharp corners, and the reply measures where each layer ended up. A layer or group can be blurred, for depth of field, and a fill can be noise for cloud, texture and film grain, the same picture from the same seed. A `paint` layer is a canvas of brush strokes with pressure, softness, tapering, bristles and smudging, added to round by round, for what shapes cannot do; one `sweep` instruction lays a mass of hair gathered into locks, one `field` covers a region in strokes along a flow, with named brushes from ink and pencil to oil and watercolor, and one `along` repeats strokes along a line. A layer can work across everything under it, to fuse separate parts into one painting, and `image_read` shows lightness alone and reads colours. A `figure` layer is a posed skeleton in plain blocks from any angle to draw over, and an `image` layer brings in the team's own art: both stay out of the `.png`, and the figure reports where each joint landed and lets broad light follow the form. `image_read` enlarges a part, and `image_set` shows several together with the stroke widths and size of each. Drawn on the CPU, so a source makes the same picture on any machine.+- **An AI can draw 2D pictures.** `image_write` turns layers into a `.png` beside an `.esimage`: shapes and SVG paths, gradients, strokes, shadows and glows, clipping and cutting, or pixel art as rows of characters. It answers with the picture on a mid ground and a light check and at 96, 64, 48 and 32 pixels, to look at and correct; `image_edit` changes one layer, a row or a block of pixels without restating the rest, and moves layers or wraps them in a group. Strokes can keep sharp corners, and the reply measures where each layer ended up. A layer or group can be blurred, for depth of field, and a fill can be noise for cloud, texture and film grain, the same picture from the same seed. A `paint` layer is a canvas of brush strokes with pressure, softness, tapering, bristles and smudging, added to round by round, for what shapes cannot do; one `sweep` instruction lays a mass of hair gathered into locks, one `field` covers a region in strokes along a flow, with named brushes from ink and pencil to oil and watercolor, and one `along` repeats strokes along a line. A layer can work across everything under it, to fuse separate parts into one painting, and `image_read` shows lightness alone and reads colours. Text in any script, windows in rows on a face, buildings in true perspective and reflections on wet ground are one instruction each. A `figure` layer is a posed skeleton in plain blocks from any angle to draw over, and an `image` layer brings in the team's own art: both stay out of the `.png`, and the figure reports where each joint landed and lets broad light follow the form. `image_read` enlarges a part, and `image_set` shows several together with the stroke widths and size of each. Drawn on the CPU, so a source makes the same picture on any machine.- **An AI can build a person, and not a picture of one.** The `humanoid` step makes a whole body from a few numbers, with fingers, a face and ears, seen right from every side, and `rig: { humanoid: true }` gives it bones that fit. `garment` makes clothes from the body's own surface: loose or tight, a bell sleeve that hangs, a clean hem, a thickness; what a body wears now takes its weights from the skin under it, so an arm stays in its sleeve. `pose` holds a body in a pose by angles, or with `reach` by where a hand should be. `organic` gains `limb`, cross-sections along a path, and `fine`, regions split finer on one skin. `displace` gains `folds`, running the way cloth hangs. `scene_views` no longer takes on a shot's lens blur and grade.diff --git a/desktop b/desktopindex de685bc9d..e550ab4e8 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit de685bc9d670746bdc4127e7ad141280d9d5b8d3+Subproject commit e550ab4e88f36aaa1e19cbbfec81f1643d8ea12adiff --git a/pipeline/src/image/imageRaster.ts b/pipeline/src/image/imageRaster.tsindex 597d73337..69fb4fc94 100644--- a/pipeline/src/image/imageRaster.ts+++ b/pipeline/src/image/imageRaster.ts@@ -8,7 +8,7 @@* On the CPU rather than through a canvas, so the same source makes the same bytes on any machine and a test can read them.*/import { figureLight, flattenFigure, type FlatFigure } from './imageFigure';-import { IMAGE_BRUSHES, MAX_MARK_STROKES } from './imageSource';+import { IMAGE_BRUSHES, isGuideLayer, MAX_MARK_STROKES } from './imageSource';import type { ImageFill, ImageLayer, ImageSource, ImageAlong, ImageBrushSettings, ImageEffect, ImageField, ImageMark, ImageStroke, ImageSweep, ImageTransform } from './imageSource';export interface RgbaBitmap { width: number; height: number; rgba: Uint8Array }@@ -460,12 +460,72 @@ function fractalNoise(x: number, y: number, octaves: number, seed: number): numbreturn Math.max(0, Math.min(1, 0.5 + (sum / weight) * NOISE_CONTRAST[octaves - 1]!));}+/** From a place in the picture to where it lies on four corners, 0..1 each way; null when the corners cannot be solved. */+function quadToUnit(q: readonly (readonly number[])[]): ((x: number, y: number) => readonly [number, number]) | null {+ const [[x0, y0], [x1, y1], [x2, y2], [x3, y3]] = q as unknown as [[number, number], [number, number], [number, number], [number, number]];+ // The square onto the corners, as a projective map.+ const [dx1, dx2, sx, dy1, dy2, sy] = [x1 - x2, x3 - x2, x0 - x1 + x2 - x3, y1 - y2, y3 - y2, y0 - y1 + y2 - y3];+ const det = dx1 * dy2 - dx2 * dy1;+ if (Math.abs(det) < 1e-9) return null;+ const g = (sx * dy2 - dx2 * sy) / det, h = (dx1 * sy - sx * dy1) / det;+ const [a, b, c, d, e, f] = [x1 - x0 + g * x1, x3 - x0 + h * x3, x0, y1 - y0 + g * y1, y3 - y0 + h * y3, y0];+ // Its inverse, by cofactors.+ const [A, B, C, D, E, F, G, H, I] = [e - f * h, c * h - b, b * f - c * e, f * g - d, a - c * g, c * d - a * f, d * h - e * g, b * g - a * h, a * e - b * d];+ return (x, y) => {+ const z = G * x + H * y + I;+ return [(A * x + B * y + C) / z, (D * x + E * y + F) / z];+ };+}++/** Marks in rows and columns, each with its own colour and whether it is on, sampled within the pixel so distant rows blend and do not shimmer. */+function gridPaint(fill: Extract<ImageFill, { type: 'grid' }>, m: Matrix): (x: number, y: number) => Rgba {+ const colors = fill.colors.map(parseColor);+ const ground = fill.ground ? parseColor(fill.ground) : ([0, 0, 0, 0] as Rgba);+ const off = fill.off ? parseColor(fill.off) : ground;+ const [mw, mh] = fill.mark ?? [0.6, 0.6];+ const [lit, seed] = [fill.lit ?? 1, fill.seed ?? 1];+ const inverse = invert(m);+ const toUnit = fill.quad ? quadToUnit(fill.quad) : null;+ const [cols, rows] = fill.cells ?? [1, 1];+ const [cw, ch] = fill.cell ?? [1, 1];+ const at = (x: number, y: number): Rgba => {+ let u: number, v: number;+ if (toUnit) {+ const p = toUnit(x, y);+ if (p[0] < 0 || p[1] < 0 || p[0] > 1 || p[1] > 1) return ground;+ [u, v] = [p[0] * cols, p[1] * rows];+ } else {+ const p = apply(inverse, [x, y]);+ [u, v] = [p[0] / cw, p[1] / ch];+ }+ const [i, j] = [Math.floor(u), Math.floor(v)];+ if (Math.abs(u - i - 0.5) > mw / 2 || Math.abs(v - j - 0.5) > mh / 2) return ground;+ if (hash01(seed * 41 + i, j) >= lit) return off;+ return colors[Math.floor(hash01(seed * 43 + j, i) * colors.length) % colors.length]!;+ };+ const SAMPLES = 3;+ return (x, y) => {+ const sum = [0, 0, 0, 0];+ for (let sy = 0; sy < SAMPLES; sy++) {+ for (let sx = 0; sx < SAMPLES; sx++) {+ const c = at(x - 0.5 + (sx + 0.5) / SAMPLES, y - 0.5 + (sy + 0.5) / SAMPLES);+ sum[0]! += c[0] * c[3]; sum[1]! += c[1] * c[3]; sum[2]! += c[2] * c[3]; sum[3]! += c[3];+ }+ }+ const a = sum[3]!;+ return a > 0 ? [sum[0]! / a, sum[1]! / a, sum[2]! / a, a / (SAMPLES * SAMPLES)] : [0, 0, 0, 0];+ };+}++/** Draws text to coverage in the picture's pixels. Lives in whoever has fonts: this file has none. */+export type ImageTextDrawer = (layer: ImageLayer, m: readonly number[], w: number, h: number) => { fill: Float32Array; line: Float32Array | null };+function paintOf(fill: ImageFill, m: Matrix, drawn?: Drawn, w = 0): (x: number, y: number) => Rgba {if (typeof fill === 'string') {const c = parseColor(fill);return () => c;}- const stops = [...(fill.type === 'image' ? [] : fill.stops)].map(([t, c]) => [t, parseColor(c)] as const).sort((a, b) => a[0] - b[0]);+ const stops = [...(fill.type === 'image' || fill.type === 'grid' ? [] : fill.stops)].map(([t, c]) => [t, parseColor(c)] as const).sort((a, b) => a[0] - b[0]);const inverse = invert(m);const at = (t: number): Rgba => {if (t <= stops[0]![0]) return stops[0]![1];@@ -489,6 +549,7 @@ function paintOf(fill: ImageFill, m: Matrix, drawn?: Drawn, w = 0): (x: number,return [image[i] ?? 0, image[i + 1] ?? 0, image[i + 2] ?? 0, image[i + 3] ?? 0];};}+ if (fill.type === 'grid') return gridPaint(fill, m);if (fill.type === 'form') {const figure = drawn?.figures.get(fill.figure);if (!figure) {@@ -582,7 +643,7 @@ function effectLayers(effects: readonly ImageEffect[] | undefined, under: boolea}}-interface Drawn { masks: Map<string, Float32Array>; notes: string[]; bounds: Map<string, ImageBox>; painted: Map<string, { entries: number; strokes: number }>; figures: Map<string, FlatFigure>; figureJoints: Map<string, Record<string, readonly [number, number]>>; showGuides: boolean; pictures: Readonly<Record<string, RgbaBitmap>>; images: Map<string, Float32Array> }+interface Drawn { masks: Map<string, Float32Array>; notes: string[]; bounds: Map<string, ImageBox>; painted: Map<string, { entries: number; strokes: number }>; figures: Map<string, FlatFigure>; figureJoints: Map<string, Record<string, readonly [number, number]>>; showGuides: boolean; pictures: Readonly<Record<string, RgbaBitmap>>; images: Map<string, Float32Array>; text: ImageTextDrawer | undefined; blocks: Map<string, Record<string, readonly (readonly number[])[]>> }/** x, y, width and height in the picture's pixels. */export type ImageBox = readonly [number, number, number, number];@@ -616,14 +677,14 @@ function drawLayer(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn):const { w, h } = c;if (layer.visible === false) {// A guide hidden from sight is still what others are clipped to and lit by. Anything else hidden is simply not there.- if (layer.guide ?? (layer.shape === 'figure' || layer.shape === 'image')) {+ if (isGuideLayer(layer)) {const { visible: _v, ...shown } = layer;drawLayer(new Canvas(w, h), { ...shown, guide: false }, parent, drawn);}return;}// What a guide masks is still wanted when it is not seen, so it draws somewhere that is thrown away.- if (!drawn.showGuides && (layer.guide ?? (layer.shape === 'figure' || layer.shape === 'image'))) {+ if (!drawn.showGuides && isGuideLayer(layer)) {drawLayer(new Canvas(w, h), { ...layer, guide: false }, parent, drawn);return;}@@ -709,6 +770,26 @@ function drawLayer(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn):return;}+ if (layer.shape === 'text') {+ drawText(c, layer, parent, drawn, opacity, blend, clip);+ return;+ }++ if (layer.shape === 'block') {+ drawBlock(c, layer, parent, drawn);+ return;+ }++ if (layer.shape === 'perspective') {+ drawPerspective(c, layer, parent, opacity);+ return;+ }++ if (layer.shape === 'reflect') {+ drawReflection(c, layer, parent, drawn, opacity, clip);+ return;+ }+const { runs, middle } = outlinesOf(layer);const m = times(parent, transformOf(layer.transform, middle));const placed = runs.map((run) => ({ closed: run.closed, points: run.points.map((p) => apply(m, p)) }));@@ -1302,6 +1383,154 @@ function drawFigure(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn,if (layer.id) drawn.figureJoints.set(layer.id, figure.joints);}+function drawText(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn, opacity: number, blend: Blend, clip: Float32Array | undefined): void {+ const { w, h } = c;+ if (!drawn.text) throw new Error(`layer ${layer.id ?? 'text'}: text needs the editor's fonts, and this render has none`);+ const m = times(parent, transformOf(layer.transform, layer.at as Pt));+ const { fill, line } = drawn.text(layer, m, w, h);+ const whole = new Float32Array(w * h);+ for (let i = 0; i < whole.length; i++) whole[i] = Math.max(layer.fill !== undefined ? fill[i]! : 0, line ? line[i]! : 0) * (clip ? clip[i]! : 1);+ if (layer.id) drawn.masks.set(layer.id, whole);+ noteBox(drawn, layer.id, whole, w, h);+ effectLayers(layer.effects, true, c, whole);+ const lay = (mask: Float32Array, paint: (x: number, y: number) => Rgba): void => {+ for (let y = 0; y < h; y++) {+ for (let x = 0; x < w; x++) {+ const i = y * w + x;+ const v = mask[i]! * (clip ? clip[i]! : 1);+ if (v <= 0) continue;+ const col = paint(x + 0.5, y + 0.5);+ put(c, i, col[0], col[1], col[2], v * col[3] * opacity, blend);+ }+ }+ };+ if (line && layer.stroke) lay(line, paintOf(layer.stroke.color, m, drawn, w));+ if (layer.fill !== undefined) lay(fill, paintOf(layer.fill, m, drawn, w));+ effectLayers(layer.effects, false, c, whole);+}++/** A building's visible faces, from the corner nearest the viewer toward the vanishing points. Each is a layer of its own to clip to. */+function drawBlock(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn): void {+ const [bx, by] = layer.at as Pt;+ const top = by - (layer.height as number);+ const toward = (x: number, y: number, v: readonly number[], t: number): number[] => [x + (v[0]! - x) * t, y + (v[1]! - y) * t];+ const quads: Record<string, readonly (readonly number[])[]> = {};+ const names = ['a', 'b'];+ const common: Partial<ImageLayer> = { ...(layer.opacity !== undefined ? { opacity: layer.opacity } : {}), ...(layer.blend ? { blend: layer.blend } : {}), ...(layer.clip ? { clip: layer.clip } : {}), ...(layer.except ? { except: layer.except } : {}), ...(layer.stroke ? { stroke: layer.stroke } : {}) };+ const faces: ImageLayer[] = (layer.vanish ?? []).map((v, n) => {+ const t = layer.depth![n]!;+ const [tx, ty] = toward(bx, top, v, t);+ const [fx, fy] = toward(bx, by, v, t);+ // Top left, top right, bottom right, bottom left, as seen: the far edge is on whichever side it recedes to.+ const quad = v[0]! < bx ? [[tx, ty], [bx, top], [bx, by], [fx, fy]] : [[bx, top], [tx, ty], [fx, fy], [bx, by]];+ quads[names[n]!] = quad;+ const given = layer.faces![n]!;+ const fill = typeof given !== 'string' && given.type === 'grid' && !given.quad ? { ...given, quad } : given;+ return { ...common, ...(layer.id ? { id: `${layer.id}.${names[n]}` } : {}), shape: 'polygon', points: quad as [number, number][], fill } as ImageLayer;+ });+ // A roof shows only from above, which is when the top is below the line the vanishing points are on.+ const vanish = layer.vanish ?? [];+ if (layer.roof !== undefined && vanish[0]![1]! < top) {+ const near: number[] = [bx, top];+ const [p, q] = [toward(bx, top, vanish[0]!, layer.depth![0]!), vanish[1] ? toward(bx, top, vanish[1], layer.depth![1]!) : null];+ const roof = q && vanish[1]+ ? [near, p, (() => {+ // Where the lines from each far corner to the other vanishing point meet.+ const [a, b, cc, d] = [p, vanish[1]!, q, vanish[0]!];+ const den = (a[0]! - b[0]!) * (cc[1]! - d[1]!) - (a[1]! - b[1]!) * (cc[0]! - d[0]!);+ if (Math.abs(den) < 1e-6) return a;+ const k = ((a[0]! - cc[0]!) * (cc[1]! - d[1]!) - (a[1]! - cc[1]!) * (cc[0]! - d[0]!)) / den;+ return [a[0]! + k * (b[0]! - a[0]!), a[1]! + k * (b[1]! - a[1]!)];+ })(), q]+ : null;+ if (roof) {+ quads.top = roof;+ faces.unshift({ ...common, ...(layer.id ? { id: `${layer.id}.top` } : {}), shape: 'polygon', points: roof as [number, number][], fill: layer.roof } as ImageLayer);+ }+ }+ for (const face of faces) drawLayer(c, face, parent, drawn);+ if (layer.id) {+ drawn.blocks.set(layer.id, Object.fromEntries(Object.entries(quads).map(([k, q]) => [k, q.map((p) => { const a = apply(parent, p as unknown as Pt); return [Math.round(a[0]), Math.round(a[1])]; })])));+ const whole = new Float32Array(c.w * c.h);+ for (const key of Object.keys(quads)) {+ const mask = drawn.masks.get(`${layer.id}.${key}`);+ if (mask) for (let i = 0; i < whole.length; i++) whole[i] = Math.max(whole[i]!, mask[i]!);+ }+ drawn.masks.set(layer.id, whole);+ noteBox(drawn, layer.id, whole, c.w, c.h);+ }+}++/** Lines running out from each vanishing point, to build along. A guide. */+function drawPerspective(c: Canvas, layer: ImageLayer, parent: Matrix, opacity: number): void {+ const { w, h } = c;+ const reach = Math.hypot(w, h);+ const lines = (layer.vanish ?? []).flatMap((v) => Array.from({ length: 24 }, (_, i) => {+ const a = (i / 24) * Math.PI * 2;+ const from = apply(parent, [v[0]!, v[1]!]);+ return { closed: false, points: [from, [from[0] + Math.cos(a) * reach, from[1] + Math.sin(a) * reach]] as Pt[] };+ }));+ const horizon = (layer.vanish ?? [])[0];+ if (horizon) lines.push({ closed: false, points: [apply(parent, [-w, horizon[1]!]), apply(parent, [w * 2, horizon[1]!])] });+ const mask = strokeMask(lines, 1, w, h);+ for (let i = 0; i < mask.length; i++) put(c, i, 0.3, 0.9, 1, mask[i]! * 0.55 * opacity, 'normal');+}++/** What is above a line, turned over below it: a wet street or still water. It wavers side to side, longer toward the viewer, and fades as it reaches. */+function drawReflection(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn, opacity: number, clip: Float32Array | undefined): void {+ const { w, h } = c;+ const k = drawnScale(parent);+ // Where each column turns over: things in perspective stand on a slanting line, and a level one would not meet their feet.+ const lineAt = new Float32Array(w);+ const edge = layer.edge?.map((p) => apply(parent, p as unknown as Pt)).sort((a, b) => a[0] - b[0]);+ for (let x = 0; x < w; x++) {+ if (!edge) { lineAt[x] = apply(parent, [0, layer.y as number])[1]; continue; }+ let i = 0;+ while (i + 2 < edge.length && edge[i + 1]![0] < x + 0.5) i++;+ const [a, b] = [edge[i]!, edge[i + 1]!];+ const t = b[0] === a[0] ? 0 : Math.max(0, Math.min(1, (x + 0.5 - a[0]) / (b[0] - a[0])));+ lineAt[x] = a[1] + (b[1] - a[1]) * t;+ }+ const reach = (layer.reach ?? h) * k;+ const ripple = (layer.ripple ?? 3) * k;+ const seed = 11;+ const out = new Float32Array(w * h * 4);+ for (let y = 0; y < h; y++) {+ for (let x = 0; x < w; x++) {+ const depth = y + 0.5 - lineAt[x]!;+ if (depth < 0 || depth >= reach) continue;+ const from = Math.floor(lineAt[x]! - depth);+ if (from < 0) continue;+ const swing = ripple * (depth / reach + 0.2);+ const shift = gradientNoise(x / 90, y / 3.5, seed) * swing * 2.4 + gradientNoise(x / 22, y / 1.6, seed + 1) * swing;+ const sx = Math.max(0, Math.min(w - 1, Math.round(x + shift)));+ const [to, at] = [(y * w + x) * 4, (from * w + sx) * 4];+ for (let n = 0; n < 4; n++) out[to + n] = c.px[at + n]!;+ }+ }+ const smear = (layer.smear ?? 2) * k;+ const channels = [0, 1, 2, 3].map((n) => {+ const channel = new Float32Array(w * h);+ for (let i = 0; i < channel.length; i++) channel[i] = out[i * 4 + n]!;+ return smear > 0 ? blurMask(channel, w, h, smear) : channel;+ }) as [Float32Array, Float32Array, Float32Array, Float32Array];+ const mask = new Float32Array(w * h);+ for (let y = 0; y < h; y++) {+ for (let x = 0; x < w; x++) {+ const depth = y + 0.5 - lineAt[x]!;+ if (depth < 0) continue;+ const fading = Math.max(0, 1 - depth / reach);+ const i = y * w + x;+ const a = channels[3][i]!;+ mask[i] = a * fading * (clip ? clip[i]! : 1);+ if (a <= 0 || mask[i]! <= 0) continue;+ put(c, i, channels[0][i]! / a, channels[1][i]! / a, channels[2][i]! / a, mask[i]! * opacity, layer.blend ?? 'normal');+ }+ }+ if (layer.id) drawn.masks.set(layer.id, mask);+ noteBox(drawn, layer.id, mask, w, h);+}+/** A picture from the project, smoothly scaled to where it goes. */function drawPicture(c: Canvas, layer: ImageLayer, parent: Matrix, drawn: Drawn, opacity: number, blend: Blend, clip: Float32Array | undefined): void {const { w, h } = c;@@ -1377,17 +1606,19 @@ export interface RenderedImage extends RgbaBitmap {painted: Record<string, { entries: number; strokes: number }>;/** For each figure with an id: where its joints landed in the picture. */figures: Record<string, Record<string, readonly [number, number]>>;+ /** For each block with an id: its faces' corners in the picture, to place things on. */+ blocks: Record<string, Record<string, readonly (readonly number[])[]>>;}/** Draws a source that has been validated. */-export function renderImage(source: ImageSource, options: { guides?: boolean; pictures?: Readonly<Record<string, RgbaBitmap>> } = {}): RenderedImage {+export function renderImage(source: ImageSource, options: { guides?: boolean; pictures?: Readonly<Record<string, RgbaBitmap>>; text?: ImageTextDrawer } = {}): RenderedImage {const [w, h] = typeof source.size === 'number' ? [source.size, source.size] : source.size;const canvas = new Canvas(w, h);if (source.background) {const [r, g, b, a] = parseColor(source.background);for (let i = 0; i < w * h; i++) put(canvas, i, r, g, b, a, 'normal');}- const drawn: Drawn = { masks: new Map(), notes: [], bounds: new Map(), painted: new Map(), figures: new Map(), figureJoints: new Map(), showGuides: options.guides === true, pictures: options.pictures ?? {}, images: new Map() };+ const drawn: Drawn = { masks: new Map(), notes: [], bounds: new Map(), painted: new Map(), figures: new Map(), figureJoints: new Map(), showGuides: options.guides === true, pictures: options.pictures ?? {}, images: new Map(), text: options.text, blocks: new Map() };for (const layer of source.layers) drawLayer(canvas, layer, IDENTITY, drawn);const rgba = new Uint8Array(w * h * 4);for (let i = 0; i < w * h; i++) {@@ -1407,6 +1638,7 @@ export function renderImage(source: ImageSource, options: { guides?: boolean; pilayerBounds: Object.fromEntries(drawn.bounds),painted: Object.fromEntries(drawn.painted),figures: Object.fromEntries(drawn.figureJoints),+ blocks: Object.fromEntries(drawn.blocks),};}diff --git a/pipeline/src/image/imageSource.ts b/pipeline/src/image/imageSource.tsindex 90d87d3c4..d49f9f342 100644--- a/pipeline/src/image/imageSource.ts+++ b/pipeline/src/image/imageSource.ts@@ -17,7 +17,25 @@ export type ImageFill = string/** By which way a figure's surface faces: 1 toward the light, 0.5 side on, 0 away. So light turns the form and does not sit on its edge. */| { type: 'form'; figure: string; light?: readonly number[]; stops: readonly (readonly [number, string])[] }/** The colour of an `image` layer at each place. */- | { type: 'image'; image: string };+ | { type: 'image'; image: string }+ /** Marks in rows and columns: windows, tiles, grilles. On four corners it lies in perspective. */+ | {+ type: 'grid';+ /** A cell's size in pixels, or with `quad` how many columns and rows there are. */+ cell?: readonly [number, number];+ cells?: readonly [number, number];+ /** Corners in order round: top left, top right, bottom right, bottom left. */+ quad?: readonly (readonly number[])[];+ /** The mark as a share of its cell, each 0..1. */+ mark?: readonly [number, number];+ colors: readonly string[];+ /** Between the marks; clear without it. */+ ground?: string;+ /** The share of marks that are on, 0..1, and what the rest show. */+ lit?: number;+ off?: string;+ seed?: number;+ };export interface ImageEffect {type: 'shadow' | 'glow' | 'innerShadow' | 'innerGlow';@@ -37,7 +55,7 @@ export interface ImageTransform {origin?: readonly [number, number];}-export type ImageShape = 'rect' | 'circle' | 'ellipse' | 'ring' | 'polygon' | 'line' | 'star' | 'gear' | 'path' | 'pixels' | 'paint' | 'figure' | 'image' | 'group';+export type ImageShape = 'rect' | 'circle' | 'ellipse' | 'ring' | 'polygon' | 'line' | 'star' | 'gear' | 'path' | 'pixels' | 'paint' | 'figure' | 'image' | 'text' | 'block' | 'perspective' | 'reflect' | 'group';/** How a brush lays colour. Any of these on a stroke, a sweep or a field, over what its `brush` starts from. */export interface ImageBrushSettings {@@ -223,6 +241,30 @@ export interface ImageLayer {/** A joint and where it must be: [x, y] in the picture, or [x, y, z] on the body's own axes. */reach?: Readonly<Record<string, { at: readonly number[]; pole?: readonly number[] }>>;};+ /** Text: what it says. */+ text?: string;+ fontSize?: number;+ /** A family the machine has, or a font file in the project. */+ font?: string;+ weight?: number | string;+ align?: 'left' | 'center' | 'right';+ /** Characters one under the other, as a sign down a building. */+ vertical?: boolean;+ /** Extra between characters, in pixels. */+ tracking?: number;+ /** A block or a perspective: the points lines recede to. */+ vanish?: readonly (readonly number[])[];+ /** A block: how far each face runs toward its vanishing point, 0..1. */+ depth?: readonly number[];+ /** A block: the fill of each face, and of the roof if it can be seen. */+ faces?: readonly ImageFill[];+ roof?: ImageFill;+ /** A reflect: the line it mirrors about, level or as points along where things meet the ground, how far down it reaches, and how far it wavers and smears in pixels. */+ y?: number;+ edge?: readonly (readonly number[])[];+ reach?: number;+ ripple?: number;+ smear?: number;/** An image: a picture in the project. */src?: string;/** Drawn everywhere but inside this earlier layer. */@@ -258,7 +300,20 @@ function checkFill(v: unknown): string | null {if (typeof v === 'string') return isColor(v) ? null : `${JSON.stringify(v)} must be #rgb, #rgba, #rrggbb or #rrggbbaa`;const f = v as Record<string, unknown> | null;if (typeof f !== 'object' || f === null) return 'must be a colour or a gradient';- if (f.type !== 'linear' && f.type !== 'radial' && f.type !== 'noise' && f.type !== 'form' && f.type !== 'image') return 'a gradient has type linear, radial, noise, form or image';+ if (f.type !== 'linear' && f.type !== 'radial' && f.type !== 'noise' && f.type !== 'form' && f.type !== 'image' && f.type !== 'grid') return 'a gradient has type linear, radial, noise, form, image or grid';+ if (f.type === 'grid') {+ if (!Array.isArray(f.colors) || f.colors.length === 0 || !f.colors.every(isColor)) return 'a grid needs colors: one or more';+ for (const key of ['ground', 'off']) if (f[key] !== undefined && !isColor(f[key])) return `a grid's ${key} must be a colour`;+ const quad = f.quad as unknown[] | undefined;+ if (quad !== undefined && !(Array.isArray(quad) && quad.length === 4 && quad.every(isPair))) return 'a grid\'s quad must be four [x, y], in order round from the top left';+ if (f.cell === undefined && f.cells === undefined) return 'a grid needs cell: [w, h] in pixels, or cells: [columns, rows]';+ for (const key of ['cell', 'cells']) if (f[key] !== undefined && !(isPair(f[key]) && (f[key] as number[]).every((v) => v > 0))) return `a grid's ${key} must be two positive numbers`;+ if (f.cell !== undefined && quad !== undefined) return 'a grid on a quad is counted in cells: [columns, rows]';+ if (f.mark !== undefined && !(isPair(f.mark) && (f.mark as number[]).every((v) => v > 0 && v <= 1))) return 'a grid\'s mark must be [w, h], each above 0 and up to 1';+ if (f.lit !== undefined && !(isNum(f.lit) && (f.lit as number) >= 0 && (f.lit as number) <= 1)) return 'a grid\'s lit must be 0..1';+ if (f.seed !== undefined && !Number.isInteger(f.seed)) return 'a grid\'s seed must be a whole number';+ return null;+ }if (f.type === 'image') return typeof f.image === 'string' && f.image ? null : 'an image fill needs image, the id of an image layer drawn before it';if (f.type === 'form') {if (typeof f.figure !== 'string' || !f.figure) return 'a form needs figure, the id of a figure drawn before it';@@ -279,8 +334,11 @@ function checkFill(v: unknown): string | null {return null;}-const FIELDS = ['id', 'shape', 'at', 'size', 'radius', 'radii', 'inner', 'count', 'tooth', 'turn', 'points', 'd', 'rows', 'palette', 'scale', 'layers', 'fill', 'stroke', 'opacity', 'blend', 'transform', 'mirror', 'effects', 'clip', 'erase', 'visible', 'blur', 'strokes', 'from', 'guide', 'height', 'yaw', 'pitch', 'build', 'pose', 'light', 'src', 'except'];-const SHAPES: readonly ImageShape[] = ['rect', 'circle', 'ellipse', 'ring', 'polygon', 'line', 'star', 'gear', 'path', 'pixels', 'paint', 'figure', 'image', 'group'];+const FIELDS = ['id', 'shape', 'at', 'size', 'radius', 'radii', 'inner', 'count', 'tooth', 'turn', 'points', 'd', 'rows', 'palette', 'scale', 'layers', 'fill', 'stroke', 'opacity', 'blend', 'transform', 'mirror', 'effects', 'clip', 'erase', 'visible', 'blur', 'strokes', 'from', 'guide', 'height', 'yaw', 'pitch', 'build', 'pose', 'light', 'src', 'except', 'text', 'fontSize', 'font', 'weight', 'align', 'vertical', 'tracking', 'vanish', 'depth', 'faces', 'roof', 'y', 'edge', 'reach', 'ripple', 'smear'];++/** Layers that are aids to drawing unless told otherwise: seen when looking, and not in the .png. */+export const isGuideLayer = (l: ImageLayer): boolean => l.guide ?? (l.shape === 'figure' || l.shape === 'image' || l.shape === 'perspective');+const SHAPES: readonly ImageShape[] = ['rect', 'circle', 'ellipse', 'ring', 'polygon', 'line', 'star', 'gear', 'path', 'pixels', 'paint', 'figure', 'image', 'text', 'block', 'perspective', 'reflect', 'group'];const STROKE_FIELDS = ['points', 'color', 'to', 'size', 'hardness', 'opacity', 'taper', 'bristles', 'strand', 'spread', 'vary', 'wobble', 'seed', 'smudge', 'erase', 'blend', ...BRUSH_FIELDS];/** What a brush's own settings must be, on whatever carries them. */@@ -436,6 +494,32 @@ function checkLayer(l: Record<string, unknown>, where: string, ids: Set<string>)}break;}+ case 'text':+ if (typeof l.text !== 'string' || !l.text) fail('text must say something');+ pair('at');+ if (!(isNum(l.fontSize) && (l.fontSize as number) > 0)) fail('fontSize must be positive, in pixels');+ if (l.font !== undefined && typeof l.font !== 'string') fail('font must be a family name or a font file in the project');+ if (l.align !== undefined && !['left', 'center', 'right'].includes(l.align as string)) fail('align must be left, center or right');+ if (l.tracking !== undefined && !isNum(l.tracking)) fail('tracking must be pixels');+ if (l.fill === undefined && l.stroke === undefined) fail('it needs a fill or a stroke, or it draws nothing');+ break;+ case 'perspective':+ if (!Array.isArray(l.vanish) || l.vanish.length === 0 || !l.vanish.every(isPair)) fail('vanish must be one or more [x, y]');+ break;+ case 'block': {+ pair('at');+ if (!(isNum(l.height) && (l.height as number) > 0)) fail('height must be pixels, from the corner at its foot up to its top');+ if (!Array.isArray(l.vanish) || l.vanish.length < 1 || l.vanish.length > 2 || !l.vanish.every(isPair)) fail('vanish must be one or two [x, y], where its faces recede to');+ if (!Array.isArray(l.depth) || l.depth.length !== (l.vanish as unknown[]).length || !l.depth.every((d) => isNum(d) && d > 0 && d <= 1)) fail('depth must give each vanishing point how far the face runs toward it, each above 0 and up to 1');+ if (!Array.isArray(l.faces) || l.faces.length !== (l.vanish as unknown[]).length) fail('faces must give one fill for each vanishing point');+ for (const face of l.faces as unknown[]) { const bad = checkFill(face); if (bad) fail(`face ${bad}`); }+ if (l.roof !== undefined) { const bad = checkFill(l.roof); if (bad) fail(`roof ${bad}`); }+ break;+ }+ case 'reflect':+ if (!isNum(l.y) && !(Array.isArray(l.edge) && l.edge.length >= 2 && l.edge.every(isPair))) fail('y must be the line it mirrors about, or edge two or more [x, y] along where things meet the ground');+ for (const key of ['reach', 'ripple', 'smear']) if (l[key] !== undefined && !(isNum(l[key]) && (l[key] as number) >= 0)) fail(`${key} must be 0 or more pixels`);+ break;case 'image':if (typeof l.src !== 'string' || !l.src) fail('src must be the path of a picture in the project');if (l.at !== undefined && !isPair(l.at)) fail('at must be [x, y]');@@ -485,7 +569,7 @@ function checkLayer(l: Record<string, unknown>, where: string, ids: Set<string>)if (s.join !== undefined && !['round', 'miter', 'bevel'].includes(s.join as string)) fail('stroke join must be round, miter or bevel');if (s.cap !== undefined && !['round', 'butt', 'square'].includes(s.cap as string)) fail('stroke cap must be round, butt or square');}- if (!['group', 'pixels', 'paint', 'figure', 'image', 'line'].includes(l.shape as string) && l.fill === undefined && l.stroke === undefined && !l.erase) fail('it needs a fill or a stroke, or it draws nothing');+ if (!['group', 'pixels', 'paint', 'figure', 'image', 'text', 'block', 'perspective', 'reflect', 'line'].includes(l.shape as string) && l.fill === undefined && l.stroke === undefined && !l.erase) fail('it needs a fill or a stroke, or it draws nothing');if (l.from !== undefined && l.shape !== 'paint') fail('from is for a paint layer');if (l.guide !== undefined && typeof l.guide !== 'boolean') fail('guide must be true or false');if (l.blur !== undefined && !(isNum(l.blur) && (l.blur as number) >= 0)) fail('blur must be 0 or more, in pixels');diff --git a/pipeline/tests/image-raster.test.ts b/pipeline/tests/image-raster.test.tsindex 686be1850..abca59021 100644--- a/pipeline/tests/image-raster.test.ts+++ b/pipeline/tests/image-raster.test.ts@@ -608,7 +608,7 @@ describe('noise', () => {expect(() => bad({ scale: 0 })).toThrow(/scale must be a positive/);expect(() => bad({ octaves: 9 })).toThrow(/octaves must be/);expect(() => bad({ seed: 1.5 })).toThrow(/seed must be/);- expect(() => validateImageSource({ size: 8, layers: [{ shape: 'rect', at: [0, 0], size: [8, 8], fill: { type: 'wavy', stops: [] } }] })).toThrow(/linear, radial, noise, form or image/);+ expect(() => validateImageSource({ size: 8, layers: [{ shape: 'rect', at: [0, 0], size: [8, 8], fill: { type: 'wavy', stops: [] } }] })).toThrow(/linear, radial, noise, form, image or grid/);});});@@ -1117,6 +1117,125 @@ describe('a picture to draw over', () => {});});+describe('a built world', () => {+ const windows = (fields: object): object => ({ type: 'grid', colors: [RED], ground: BLUE, ...fields });+ const rect = (fill: object): ImageLayer => ({ shape: 'rect', at: [0, 0], size: [64, 64], fill } as never);++ it('a grid repeats its marks by the pixel, on and off as told', () => {+ const img = draw([rect(windows({ cell: [16, 16], mark: [0.5, 0.5] }))]);+ expect(px(img, 8, 8)).toEqual([255, 0, 0, 255]);+ expect(px(img, 24, 8)).toEqual([255, 0, 0, 255]);+ expect(px(img, 1, 1)).toEqual([0, 0, 255, 255]);+ expect(px(img, 16, 8)).toEqual([0, 0, 255, 255]);+ const clear = draw([rect({ type: 'grid', colors: [RED], cell: [16, 16], mark: [0.5, 0.5] })]);+ expect(px(clear, 1, 1)[3]).toBe(0);+ });++ it('lights only some, the same ones every time, and shows what the rest show', () => {+ const count = (lit: number): number => { const img = draw([rect(windows({ cell: [8, 8], mark: [0.5, 0.5], lit, off: '#00ff00' }))]); let n = 0; for (let y = 4; y < 64; y += 8) for (let x = 4; x < 64; x += 8) if (px(img, x, y)[0] === 255) n++; return n; };+ expect(count(1)).toBe(64);+ expect(count(0)).toBe(0);+ expect(count(0.5)).toBeGreaterThan(20);+ expect(count(0.5)).toBeLessThan(44);+ expect(count(0.5)).toBe(count(0.5));+ });++ it('lies on four corners in perspective: rows crowd toward the far side', () => {+ const fill = windows({ cells: [8, 4], mark: [0.5, 1], quad: [[4, 4], [60, 24], [60, 40], [4, 60]] });+ const img = draw([rect(fill)]);+ const width = (x0: number, x1: number, y: number): number[] => { const runs: number[] = []; let run = 0; for (let x = x0; x < x1; x++) { if (px(img, x, y)[0]! > 128) run++; else if (run) { runs.push(run); run = 0; } } return runs; };+ const runs = width(0, 64, 32);+ expect(runs.length).toBeGreaterThan(4);+ expect(runs[0]!).toBeGreaterThan(runs[runs.length - 1]!);+ expect(px(img, 60, 10)[0]).toBe(0);+ });++ it('a block puts faces toward its vanishing points, each a layer, its corners reported', () => {+ const img = renderImage(validateImageSource({ size: 256, layers: [{ id: 'b', shape: 'block', at: [128, 200], height: 120, vanish: [[-200, 100], [500, 100]], depth: [0.2, 0.2], faces: [RED, BLUE] }] }));+ expect(px(img, 110, 150)[0]).toBe(255);+ expect(px(img, 146, 150)[2]).toBe(255);+ expect(Object.keys(img.layerBounds).sort()).toEqual(['b', 'b.a', 'b.b']);+ const a = img.blocks.b!.a!;+ expect(a).toHaveLength(4);+ // Toward a horizon above the foot, the far foot rises, and the far top too where the top is below it.+ expect(a[3]![1]).toBeLessThan(200);+ expect(a[0]![1]).toBeGreaterThan(a[1]![1]!);+ });++ it('a grid on a face lies on it unasked', () => {+ const img = renderImage(validateImageSource({ size: 128, layers: [{ shape: 'block', at: [20, 110], height: 90, vanish: [[120, 60]], depth: [0.6], faces: [{ type: 'grid', cells: [4, 8], colors: [RED], ground: BLUE }] }] }));+ let [red, blue] = [0, 0];+ for (let y = 20; y < 110; y++) for (let x = 20; x < 80; x++) { if (px(img, x, y)[0] === 255) red++; if (px(img, x, y)[2] === 255) blue++; }+ expect(red).toBeGreaterThan(200);+ expect(blue).toBeGreaterThan(200);+ });++ it('shows a roof only from above', () => {+ const block = (vy: number): ReturnType<typeof renderImage> => renderImage(validateImageSource({ size: 256, layers: [{ id: 'b', shape: 'block', at: [128, 200], height: 80, vanish: [[-200, vy], [500, vy]], depth: [0.2, 0.2], faces: [RED, BLUE], roof: '#00ff00' }] }));+ expect(block(20).blocks.b!.top).toBeDefined();+ expect(block(180).blocks.b!.top).toBeUndefined();+ });++ it('a perspective guide is seen when looking and is not in the picture', () => {+ const source = validateImageSource({ size: 64, layers: [{ shape: 'perspective', vanish: [[32, 20]] }] });+ expect(renderImage(source, { guides: true }).rgba.some((v, i) => i % 4 === 3 && v > 0)).toBe(true);+ expect(renderImage(source).rgba.every((v, i) => i % 4 !== 3 || v === 0)).toBe(true);+ });++ it('a reflection turns what is above a line over below it, and fades', () => {+ const scene: ImageLayer[] = [{ shape: 'rect', at: [10, 20], size: [10, 20], fill: RED }, { shape: 'reflect', y: 40, reach: 24, ripple: 0, smear: 0 } as never];+ const img = draw(scene);+ expect(px(img, 14, 44)[0]).toBe(255);+ expect(px(img, 14, 44)[3]).toBeGreaterThan(px(img, 14, 56)[3]!);+ expect(px(img, 40, 44)[3]).toBe(0);+ expect(px(img, 14, 10)[3]).toBe(0);+ });++ it('wavers when asked, stays inside its clip, and leaves what is above alone', () => {+ const stack = (ripple: number): ImageLayer[] => [{ id: 'g', shape: 'rect', at: [0, 40], size: [32, 24], fill: '#00000001' }, { shape: 'rect', at: [10, 10], size: [40, 30], fill: RED }, { shape: 'reflect', y: 40, reach: 24, ripple, smear: 0, clip: 'g' } as never];+ expect(px(draw(stack(0)), 40, 44)[0]).toBe(0);+ expect(draw(stack(4)).rgba).not.toEqual(draw(stack(0)).rgba);+ expect(px(draw(stack(0)), 20, 20)).toEqual([255, 0, 0, 255]);+ });++ it('a reflection turns over along where things stand, slanting with them', () => {+ const scene = (extra: object): ImageLayer[] => [{ shape: 'polygon', points: [[0, 10], [64, 10], [64, 20], [0, 40]], fill: RED }, { shape: 'reflect', reach: 40, ripple: 0, smear: 0, ...extra } as never];+ const img = draw(scene({ edge: [[0, 40], [64, 20]] }));+ // Below the slanted foot on both sides: the left as far under its foot as the right under its own.+ expect(px(img, 4, 44)[0]).toBe(255);+ expect(px(img, 60, 26)[0]).toBe(255);+ expect(px(img, 60, 10)[0]).toBe(255);+ expect(() => validateImageSource({ size: 8, layers: [{ shape: 'reflect', edge: [[0, 0]] }] })).toThrow(/edge two or more/);+ });++ it('text draws through whoever has fonts, fill and stroke, and says when there is none', () => {+ const drawer = (layer: ImageLayer, m: readonly number[], w: number, h: number): { fill: Float32Array; line: Float32Array | null } => {+ const fill = new Float32Array(w * h);+ const [x, y] = [Math.round(layer.at![0] * m[0]! + m[4]!), Math.round(layer.at![1] * m[3]! + m[5]!)];+ for (let j = 0; j < 8; j++) for (let i = 0; i < 20; i++) fill[(y - j) * w + x + i] = 1;+ return { fill, line: layer.stroke ? fill.map((v) => v) : null };+ };+ const label = { id: 't', shape: 'text', text: '东京', at: [10, 30], fontSize: 12, fill: RED } as ImageLayer;+ const img = renderImage(validateImageSource({ size: 64, layers: [label, { shape: 'rect', at: [0, 0], size: [64, 64], fill: BLUE, clip: 't' }] }), { text: drawer });+ expect(px(img as never, 14, 26)[2]).toBe(255);+ expect(img.layerBounds.t).toEqual([10, 23, 20, 8]);+ expect(() => renderImage(validateImageSource({ size: 64, layers: [label] }))).toThrow(/needs the editor's fonts/);+ });++ it('says what is wrong with each', () => {+ const bad = (l: object): unknown => validateImageSource({ size: 8, layers: [l] });+ expect(() => bad(rect({ type: 'grid', colors: [RED] }))).toThrow(/grid needs cell/);+ expect(() => bad(rect({ type: 'grid', cell: [2, 2], colors: [] }))).toThrow(/needs colors/);+ expect(() => bad(rect({ type: 'grid', cell: [2, 2], colors: [RED], quad: [[0, 0]] }))).toThrow(/quad must be four/);+ expect(() => bad(rect({ type: 'grid', cell: [2, 2], colors: [RED], quad: [[0, 0], [1, 0], [1, 1], [0, 1]] }))).toThrow(/counted in cells/);+ expect(() => bad({ shape: 'text', at: [0, 0], fontSize: 4, fill: RED })).toThrow(/text must say something/);+ expect(() => bad({ shape: 'text', text: 'a', at: [0, 0], fill: RED })).toThrow(/fontSize must be/);+ expect(() => bad({ shape: 'block', at: [0, 0], height: 4, vanish: [[1, 1]], depth: [2], faces: [RED] })).toThrow(/depth must/);+ expect(() => bad({ shape: 'block', at: [0, 0], height: 4, vanish: [[1, 1]], depth: [0.5], faces: [] })).toThrow(/faces must/);+ expect(() => bad({ shape: 'reflect' })).toThrow(/y must be/);+ });+});+describe('clipping to what was itself clipped', () => {const left: ImageLayer = { id: 'left', shape: 'rect', at: [0, 0], size: [32, 64], fill: BLUE };const strokes = [{ points: [[0, 32], [64, 32]], color: RED, size: 20, hardness: 1 }];diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex fba6a9367..faea36be9 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3888,6 +3888,10 @@ export const NOTED = {{"note":"An AI can draw 2D pictures."},"feat(look): layers moved and wrapped, one pixel changed, a set and a close look drawn":{"note":"An AI can draw 2D pictures."},+ "feat(look): text, a grid on a face, buildings in perspective, reflections":+ {"note":"An AI can draw 2D pictures."},+ "feat(mcp): image_write draws text in the editor's fonts, and documents the built world":+ {"note":"An AI can draw 2D pictures."},"fix(look): what clips to a clipped layer stays inside what that layer holds":{"internal":"the paint, figure and image layers it fixes have not been released"},"fix(look): a hidden guide still works, opacity 0 hides its bones, a faint layer has a real box":