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): pictures laid side by side, one outlined over another, and their exact colours
yhh3335c55d1a8a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex cf264ecec..52f638122 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,8 @@ 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 put the game beside the pictures it is imitating.** The `look` tool group takes pictures or a video's frames, and `reference_compare` sets a frame of the game beside one with the reference's outline drawn over it and the exact colours of both. `field_sweep` shows a field at several values on one sheet, so what a number does is seen before it is chosen. `motion_sheet` lays the running game out over time, under a video's frames. `scene_views` shows the scene as the engine draws it from every side, in clay, paint and wireframe.+- **An AI building a model can dress it in clothes that swing.** `rig.drape` turns a skirt or a cape into a ring of chains that swing as the game runs, blended so it moves as one sheet, `rig.colliders` keeps it out of the legs, and a `pleats` pattern presses folds into it.- **An AI building a model can make hair.** A `hair` step grows cards from a scalp, falling around the head, and writes the strand textures and a Hair material. `hairSway` gives them bones that swing as the game runs, and a character's `attach` carries the hair at its head joint, through saving and export.diff --git a/desktop b/desktopindex bf154e330..3eec347b0 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit bf154e330df5d6dbc06495b1da1a70da61189fab+Subproject commit 3eec347b0cda02c7f876daa0e531aa994e3ebc2bdiff --git a/pipeline/src/look/pictures.ts b/pipeline/src/look/pictures.tsnew file mode 100644index 000000000..0b7c2344b--- /dev/null+++ b/pipeline/src/look/pictures.ts@@ -0,0 +1,262 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file pictures.ts — pictures laid out so an agent can look at them together.+ *+ * An agent judges a look by looking, so nothing here gives a verdict: it cuts, scales and lays pictures+ * side by side, draws one over another to show whether the shapes line up, and reads the exact colours,+ * which an eye cannot give as numbers to paint with.+ * Pure: pixels in, pixels out, so a test and the editor run the same code.+ */++export interface RgbaImage {+ width: number;+ height: number;+ rgba: Uint8Array | Uint8ClampedArray;+}++export interface Region { x: number; y: number; w: number; h: number }++export interface PaletteEntry { color: string; share: number }++export interface PictureColors {+ /** What most of the picture is made of, largest first. */+ palette: PaletteEntry[];+ /** The colour each band of tones leans to, as a grade or a light would set it. */+ shadows: string;+ mids: string;+ highlights: string;+}++const COLOR_EDGE = 256;+const PALETTE_SIZE = 6;+/** A row or column this dark in nearly all of it is a bar around the picture, not the picture. */+const BAR_LEVEL = 14;+const BAR_SHARE = 0.985;+/** The share of a reference's pixels drawn as its outline: its strongest edges, whatever its contrast. */+const OUTLINE_SHARE = 0.08;+const OUTLINE_COLOR = [255, 225, 0] as const;+const LINE_GREY = 110;++const toLinear = (c: number): number => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);+const labF = (t: number): number => (t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116);++/** sRGB bytes to CIE Lab, through a table for speed: a picture has thousands of pixels and each needs three of these. */+const LINEAR = Float64Array.from({ length: 256 }, (_, i) => toLinear(i / 255));+function toLab(r: number, g: number, b: number, out: number[]): void {+ const [lr, lg, lb] = [LINEAR[r]!, LINEAR[g]!, LINEAR[b]!];+ const fx = labF((0.4124 * lr + 0.3576 * lg + 0.1805 * lb) / 0.95047);+ const fy = labF(0.2126 * lr + 0.7152 * lg + 0.0722 * lb);+ const fz = labF((0.0193 * lr + 0.1192 * lg + 0.9505 * lb) / 1.08883);+ out[0] = 116 * fy - 16;+ out[1] = 500 * (fx - fy);+ out[2] = 200 * (fy - fz);+}++const hex = (r: number, g: number, b: number): string =>+ `#${[r, g, b].map((v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0')).join('')}`;++/** The picture inside any black bars: a recording of a film has them, and they are not part of what it shows. */+export function activeArea(image: RgbaImage): Region {+ const { width, height, rgba } = image;+ const darkRow = (y: number): boolean => {+ let dark = 0;+ for (let x = 0; x < width; x += 2) {+ const at = (y * width + x) * 4;+ if (rgba[at]! < BAR_LEVEL && rgba[at + 1]! < BAR_LEVEL && rgba[at + 2]! < BAR_LEVEL) dark++;+ }+ return dark >= (width / 2) * BAR_SHARE;+ };+ const darkColumn = (x: number): boolean => {+ let dark = 0;+ for (let y = 0; y < height; y += 2) {+ const at = (y * width + x) * 4;+ if (rgba[at]! < BAR_LEVEL && rgba[at + 1]! < BAR_LEVEL && rgba[at + 2]! < BAR_LEVEL) dark++;+ }+ return dark >= (height / 2) * BAR_SHARE;+ };+ let top = 0, bottom = height - 1, left = 0, right = width - 1;+ while (top < bottom && darkRow(top)) top++;+ while (bottom > top && darkRow(bottom)) bottom--;+ while (left < right && darkColumn(left)) left++;+ while (right > left && darkColumn(right)) right--;+ // A picture that is nearly all dark is a night scene, not a sliver between bars.+ if ((bottom - top + 1) * (right - left + 1) < width * height * 0.05) return { x: 0, y: 0, w: width, h: height };+ return { x: left, y: top, w: right - left + 1, h: bottom - top + 1 };+}++/** A part of an image, by pixels. */+export function cropImage(image: RgbaImage, r: Region): RgbaImage {+ const [x0, y0] = [Math.max(0, Math.floor(r.x)), Math.max(0, Math.floor(r.y))];+ const width = Math.max(1, Math.min(image.width - x0, Math.round(r.w)));+ const height = Math.max(1, Math.min(image.height - y0, Math.round(r.h)));+ const rgba = new Uint8Array(width * height * 4);+ for (let y = 0; y < height; y++) {+ const from = ((y0 + y) * image.width + x0) * 4;+ rgba.set(image.rgba.subarray(from, from + width * 4), y * width * 4);+ }+ return { width, height, rgba };+}++/** The picture at this size, each pixel the mean of what falls in it. */+export function resizeImage(image: RgbaImage, width: number, height: number): RgbaImage {+ const rgba = new Uint8Array(width * height * 4);+ for (let y = 0; y < height; y++) {+ const [sy0, sy1] = [Math.floor((y * image.height) / height), Math.max(Math.floor((y * image.height) / height) + 1, Math.floor(((y + 1) * image.height) / height))];+ for (let x = 0; x < width; x++) {+ const [sx0, sx1] = [Math.floor((x * image.width) / width), Math.max(Math.floor((x * image.width) / width) + 1, Math.floor(((x + 1) * image.width) / width))];+ let [r, g, b, n] = [0, 0, 0, 0];+ for (let sy = sy0; sy < Math.min(sy1, image.height); sy++) {+ for (let sx = sx0; sx < Math.min(sx1, image.width); sx++) {+ const at = (sy * image.width + sx) * 4;+ r += image.rgba[at]!; g += image.rgba[at + 1]!; b += image.rgba[at + 2]!; n++;+ }+ }+ const to = (y * width + x) * 4;+ rgba[to] = r / n; rgba[to + 1] = g / n; rgba[to + 2] = b / n; rgba[to + 3] = 255;+ }+ }+ return { width, height, rgba };+}++/** A picture cut to a shape from its middle: stretching it would make every proportion in it wrong. */+export function toShape(image: RgbaImage, aspect: number): RgbaImage {+ const own = image.width / image.height;+ if (Math.abs(own - aspect) < 0.01) return image;+ return own > aspect+ ? cropImage(image, { x: (image.width - image.height * aspect) / 2, y: 0, w: image.height * aspect, h: image.height })+ : cropImage(image, { x: 0, y: (image.height - image.width / aspect) / 2, w: image.width, h: image.width / aspect });+}++/** Colours most of a picture is made of, largest first. The same picture gives the same answer: it starts from bands of lightness, not at random. */+function paletteOf(lab: Float64Array, rgba: ArrayLike<number>, count: number): PaletteEntry[] {+ const sorted = Array.from({ length: count }, (_, i) => i).sort((a, b) => lab[a * 3]! - lab[b * 3]!);+ const centres = Array.from({ length: PALETTE_SIZE }, (_, k) => {+ const i = sorted[Math.floor(((k + 0.5) / PALETTE_SIZE) * count)]!;+ return [lab[i * 3]!, lab[i * 3 + 1]!, lab[i * 3 + 2]!];+ });+ const owner = new Uint8Array(count);+ for (let pass = 0; pass < 8; pass++) {+ const sums = centres.map(() => [0, 0, 0, 0]);+ for (let i = 0; i < count; i++) {+ let best = Infinity;+ for (let k = 0; k < PALETTE_SIZE; k++) {+ const c = centres[k]!;+ const d = (lab[i * 3]! - c[0]!) ** 2 + (lab[i * 3 + 1]! - c[1]!) ** 2 + (lab[i * 3 + 2]! - c[2]!) ** 2;+ if (d < best) { best = d; owner[i] = k; }+ }+ const s = sums[owner[i]!]!;+ s[0]! += lab[i * 3]!; s[1]! += lab[i * 3 + 1]!; s[2]! += lab[i * 3 + 2]!; s[3]!++;+ }+ sums.forEach((s, k) => { if (s[3]) centres[k] = [s[0]! / s[3]!, s[1]! / s[3]!, s[2]! / s[3]!]; });+ }+ const totals = centres.map(() => [0, 0, 0, 0]);+ for (let i = 0; i < count; i++) {+ const t = totals[owner[i]!]!;+ t[0]! += rgba[i * 4]!; t[1]! += rgba[i * 4 + 1]!; t[2]! += rgba[i * 4 + 2]!; t[3]!++;+ }+ return totals.filter((t) => t[3]! > 0)+ .map((t) => ({ color: hex(t[0]! / t[3]!, t[1]! / t[3]!, t[2]! / t[3]!), share: Math.round((t[3]! / count) * 1000) / 1000 }))+ .sort((a, b) => b.share - a.share);+}++/** The exact colours of a picture: what to paint with, as an eye reads colour well and its value badly. */+export function colorsOf(source: RgbaImage): PictureColors {+ const k = Math.min(1, COLOR_EDGE / Math.max(source.width, source.height));+ const image = k === 1 ? source : resizeImage(source, Math.max(1, Math.round(source.width * k)), Math.max(1, Math.round(source.height * k)));+ const { rgba } = image;+ const count = image.width * image.height;+ const lab = new Float64Array(count * 3);+ const px = [0, 0, 0];+ const bands = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];+ for (let i = 0; i < count; i++) {+ toLab(rgba[i * 4]!, rgba[i * 4 + 1]!, rgba[i * 4 + 2]!, px);+ lab[i * 3] = px[0]!; lab[i * 3 + 1] = px[1]!; lab[i * 3 + 2] = px[2]!;+ const band = bands[px[0]! < 30 ? 0 : px[0]! < 65 ? 1 : 2]!;+ band[0]! += rgba[i * 4]!; band[1]! += rgba[i * 4 + 1]!; band[2]! += rgba[i * 4 + 2]!; band[3]!++;+ }+ const bandColor = (b: number[]): string => (b[3] ? hex(b[0]! / b[3]!, b[1]! / b[3]!, b[2]! / b[3]!) : '#808080');+ return { palette: paletteOf(lab, rgba, count), shadows: bandColor(bands[0]!), mids: bandColor(bands[1]!), highlights: bandColor(bands[2]!) };+}++/** One picture seen through another at the same size: half of each. */+export function blendImages(under: RgbaImage, over: RgbaImage): RgbaImage {+ const top = over.width === under.width && over.height === under.height ? over : resizeImage(over, under.width, under.height);+ const rgba = new Uint8Array(under.width * under.height * 4);+ for (let i = 0; i < rgba.length; i += 4) {+ rgba[i] = (under.rgba[i]! + top.rgba[i]!) / 2;+ rgba[i + 1] = (under.rgba[i + 1]! + top.rgba[i + 1]!) / 2;+ rgba[i + 2] = (under.rgba[i + 2]! + top.rgba[i + 2]!) / 2;+ rgba[i + 3] = 255;+ }+ return { width: under.width, height: under.height, rgba };+}++/** A picture with the strongest edges of another drawn on it, to see whether the shapes in the two line up. */+export function outlineOver(under: RgbaImage, outlined: RgbaImage): RgbaImage {+ const { width, height } = under;+ const shape = outlined.width === width && outlined.height === height ? outlined : resizeImage(outlined, width, height);+ const gray = new Float32Array(width * height);+ for (let i = 0; i < gray.length; i++) gray[i] = shape.rgba[i * 4]! * 0.3 + shape.rgba[i * 4 + 1]! * 0.59 + shape.rgba[i * 4 + 2]! * 0.11;+ const edge = new Float32Array(width * height);+ for (let y = 1; y < height - 1; y++) {+ for (let x = 1; x < width - 1; x++) {+ const at = y * width + x;+ edge[at] = Math.abs(gray[at + 1]! - gray[at - 1]!) + Math.abs(gray[at + width]! - gray[at - width]!);+ }+ }+ const cut = Float32Array.from(edge).sort()[Math.floor(edge.length * (1 - OUTLINE_SHARE))]!;+ const rgba = Uint8Array.from(under.rgba);+ for (let i = 0; i < edge.length; i++) {+ if (edge[i]! > cut && edge[i]! > 0) rgba.set(OUTLINE_COLOR, i * 4);+ }+ return { width, height, rgba };+}++const filled = (width: number, height: number): Uint8Array => {+ const rgba = new Uint8Array(width * height * 4);+ for (let i = 0; i < width * height; i++) { rgba[i * 4] = LINE_GREY; rgba[i * 4 + 1] = LINE_GREY; rgba[i * 4 + 2] = LINE_GREY; rgba[i * 4 + 3] = 255; }+ return rgba;+};++/** Pictures side by side at one height, with a thin line between. */+export function sideBySide(images: readonly RgbaImage[], height = 360): RgbaImage {+ const scaled = images.map((img) => resizeImage(img, Math.max(1, Math.round((img.width * height) / img.height)), height));+ const gap = 4;+ const width = scaled.reduce((sum, img) => sum + img.width, 0) + gap * (scaled.length - 1);+ const rgba = filled(width, height);+ let at = 0;+ for (const img of scaled) {+ for (let y = 0; y < height; y++) rgba.set(img.rgba.subarray(y * img.width * 4, (y + 1) * img.width * 4), (y * width + at) * 4);+ at += img.width + gap;+ }+ return { width, height, rgba };+}++/** A picture whole inside a cell of this size, centred on a grey ground: a video's frames need not all be one shape. */+function fitInto(image: RgbaImage, width: number, height: number): RgbaImage {+ const k = Math.min(width / image.width, height / image.height);+ const scaled = resizeImage(image, Math.max(1, Math.round(image.width * k)), Math.max(1, Math.round(image.height * k)));+ const rgba = filled(width, height);+ const [ox, oy] = [Math.floor((width - scaled.width) / 2), Math.floor((height - scaled.height) / 2)];+ for (let y = 0; y < scaled.height; y++) rgba.set(scaled.rgba.subarray(y * scaled.width * 4, (y + 1) * scaled.width * 4), ((oy + y) * width + ox) * 4);+ return { width, height, rgba };+}++/** Pictures in a grid of equal cells, row by row, each at its own shape: the cell is the size most of them have. */+export function gridOf(images: readonly RgbaImage[], columns: number): RgbaImage {+ const seen = new Map<string, number>();+ for (const img of images) seen.set(`${img.width}x${img.height}`, (seen.get(`${img.width}x${img.height}`) ?? 0) + 1);+ const common = [...seen.entries()].sort((a, b) => b[1] - a[1])[0]![0].split('x').map(Number);+ const [cw, ch] = [common[0]!, common[1]!];+ const rows = Math.ceil(images.length / columns);+ const gap = 3;+ const width = cw * columns + gap * (columns - 1), height = ch * rows + gap * (rows - 1);+ const rgba = filled(width, height);+ images.forEach((img, n) => {+ const [ox, oy] = [(n % columns) * (cw + gap), Math.floor(n / columns) * (ch + gap)];+ const fitted = img.width === cw && img.height === ch ? img : fitInto(img, cw, ch);+ for (let y = 0; y < ch; y++) rgba.set(fitted.rgba.subarray(y * cw * 4, (y + 1) * cw * 4), ((oy + y) * width + ox) * 4);+ });+ return { width, height, rgba };+}diff --git a/pipeline/tests/look-pictures.test.ts b/pipeline/tests/look-pictures.test.tsnew file mode 100644index 000000000..8f6b852ce--- /dev/null+++ b/pipeline/tests/look-pictures.test.ts@@ -0,0 +1,130 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/** Pictures laid out for an agent to look at: each one holds what it says, and the colours read are the colours there. */+import { describe, expect, it } from 'vitest';+import { activeArea, blendImages, colorsOf, cropImage, gridOf, outlineOver, resizeImage, sideBySide, toShape, type RgbaImage } from '../src/look/pictures';++type Shade = (x: number, y: number) => readonly [number, number, number];+function image(width: number, height: number, shade: Shade): RgbaImage {+ const rgba = new Uint8Array(width * height * 4);+ for (let y = 0; y < height; y++) {+ for (let x = 0; x < width; x++) {+ const c = shade(x / width, y / height);+ rgba.set([c[0], c[1], c[2], 255], (y * width + x) * 4);+ }+ }+ return { width, height, rgba };+}+const flat = (r: number, g: number, b: number, w = 64, h = 36): RgbaImage => image(w, h, () => [r, g, b]);+const at = (img: RgbaImage, x: number, y: number): number[] => Array.from(img.rgba.subarray((y * img.width + x) * 4, (y * img.width + x) * 4 + 3));++describe('activeArea', () => {+ it('finds the picture inside black bars', () => {+ const barred = image(100, 200, (_, y) => (y < 0.4 || y >= 0.6 ? [0, 0, 0] : [120, 90, 60]));+ expect(activeArea(barred)).toEqual({ x: 0, y: 80, w: 100, h: 40 });+ });++ it('takes a picture with no bars whole', () => {+ expect(activeArea(flat(120, 90, 60, 50, 30))).toEqual({ x: 0, y: 0, w: 50, h: 30 });+ });++ it('does not mistake a night scene for bars', () => {+ expect(activeArea(flat(3, 3, 5, 50, 30))).toEqual({ x: 0, y: 0, w: 50, h: 30 });+ });+});++describe('colorsOf', () => {+ it('finds what colours a picture is made of, and in what share', () => {+ const two = image(100, 100, (x) => (x < 0.75 ? [200, 30, 30] : [30, 30, 200]));+ const { palette } = colorsOf(two);+ expect(palette[0]!.color).toBe('#c81e1e');+ expect(palette[0]!.share).toBeCloseTo(0.75, 1);+ expect(palette.some((p) => p.color === '#1e1ec8')).toBe(true);+ });++ it('reads what the shadows and highlights lean to', () => {+ const graded = image(100, 100, (x) => (x < 0.5 ? [10, 15, 50] : [250, 220, 170]));+ const c = colorsOf(graded);+ expect(c.shadows).toBe('#0a0f32');+ expect(c.highlights).toBe('#fadcaa');+ });++ it('gives the same answer every time', () => {+ const noisy = image(200, 120, (x, y) => [Math.floor(x * 255), Math.floor(y * 255), 90]);+ expect(colorsOf(noisy)).toEqual(colorsOf(noisy));+ });+});++describe('over one another', () => {+ it('blendImages is half of each, and fits the top one to the bottom one', () => {+ const b = blendImages(flat(200, 0, 100, 20, 10), flat(0, 100, 100, 40, 20));+ expect([b.width, b.height]).toEqual([20, 10]);+ expect(at(b, 5, 5)).toEqual([100, 50, 100]);+ });++ it('outlineOver draws the edge of the other picture, and nothing where it has none', () => {+ const under = flat(40, 40, 40, 100, 100);+ const halves = image(100, 100, (x) => (x < 0.5 ? [0, 0, 0] : [255, 255, 255]));+ const o = outlineOver(under, halves);+ expect(at(o, 50, 50)).toEqual([255, 225, 0]);+ expect(at(o, 20, 50)).toEqual([40, 40, 40]);+ expect(at(o, 80, 50)).toEqual([40, 40, 40]);+ });++ it('outlineOver of a blank picture leaves the one under it alone', () => {+ const under = flat(40, 90, 40, 50, 50);+ expect(Array.from(outlineOver(under, flat(120, 120, 120, 50, 50)).rgba)).toEqual(Array.from(under.rgba));+ });++ it('shows the same edge in the same place when the shapes line up, and elsewhere when they do not', () => {+ const figure = (cx: number): RgbaImage => image(120, 120, (x) => (Math.abs(x - cx) < 0.1 ? [230, 230, 230] : [20, 20, 20]));+ const onIt = outlineOver(figure(0.5), figure(0.5));+ const offIt = outlineOver(figure(0.2), figure(0.5));+ expect(at(onIt, 72, 60)).toEqual([255, 225, 0]);+ expect(at(offIt, 72, 60)).toEqual([255, 225, 0]);+ // The figure itself is where the outline is in one, and away from it in the other.+ expect(at(onIt, 60, 60)).toEqual([230, 230, 230]);+ expect(at(offIt, 60, 60)).toEqual([20, 20, 20]);+ });+});++describe('pictures', () => {+ it('cropImage takes the part asked for', () => {+ const c = cropImage(image(10, 10, (x) => (x >= 0.5 ? [255, 0, 0] : [0, 0, 255])), { x: 5, y: 2, w: 3, h: 4 });+ expect([c.width, c.height, c.rgba[0], c.rgba[2]]).toEqual([3, 4, 255, 0]);+ });++ it('resizeImage averages what falls in a pixel', () => {+ const r = resizeImage(image(2, 1, (x) => (x < 0.5 ? [0, 0, 0] : [200, 200, 200])), 1, 1);+ expect(r.rgba[0]).toBe(100);+ });++ it('toShape cuts rather than stretches', () => {+ const wide = image(320, 90, (x) => (x >= 0.25 && x < 0.75 ? [200, 200, 200] : [255, 0, 255]));+ const cut = toShape(wide, 160 / 90);+ expect([cut.width, cut.height]).toEqual([160, 90]);+ expect(at(cut, 0, 40)).toEqual([200, 200, 200]);+ expect(at(cut, 159, 40)).toEqual([200, 200, 200]);+ });++ it('sideBySide lays them out at one height', () => {+ const s = sideBySide([flat(255, 0, 0, 100, 50), flat(0, 255, 0, 100, 100)], 50);+ expect([s.width, s.height]).toEqual([100 + 4 + 50, 50]);+ expect(s.rgba[0]).toBe(255);+ expect(s.rgba[(10 * s.width + 120) * 4 + 1]).toBe(255);+ });++ it('gridOf does not stretch a picture of another shape: it sits whole in a cell the size most of them are', () => {+ const tall = image(10, 40, () => [255, 0, 0]);+ const g = gridOf([tall, flat(0, 255, 0, 40, 20), flat(0, 0, 255, 40, 20)], 3);+ expect([g.width, g.height]).toEqual([3 * 40 + 6, 20]);+ expect(at(g, 20, 10)).toEqual([255, 0, 0]);+ expect(at(g, 2, 10)).toEqual([110, 110, 110]);+ });++ it('gridOf lays out cells row by row', () => {+ const g = gridOf([flat(255, 0, 0, 10, 10), flat(0, 255, 0, 10, 10), flat(0, 0, 255, 10, 10)], 2);+ expect([g.width, g.height]).toEqual([23, 23]);+ expect(g.rgba[(15 * g.width + 2) * 4 + 2]).toBe(255);+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex c5dd3f0c8..e1d3fcf1f 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3884,6 +3884,10 @@ export const NOTED = {{"note":"A material's normal and metal-rough maps are read as data in the editor's Play."},"fix(minigame): no mini-game module needs BigInt64Array, so WeChat DevTools boots the game":{"note":"A WeChat mini-game opens in WeChat DevTools."},+ "feat(look): pictures laid side by side, one outlined over another, and their exact colours":+ {"note":"An AI can put the game beside the pictures it is imitating."},+ "feat(mcp): reference_compare, field_sweep and motion_sheet show the game beside what it imitates, at several values and over time":+ {"note":"An AI can put the game beside the pictures it is imitating."},"feat(modeling): a hanging part swings as a ring of chains, kept out of the legs, and a pattern presses pleats into it":{"note":"An AI building a model can dress it in clothes that swing."},"feat(mcp): model_write dresses a model in clothes that swing, and a check walks a skirt":