Skip to content

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.

test(2d): verify sprite nine-slice corners and add stretchable platforms

yhh6612e93d5de8
diff --git a/desktop b/desktop
index 4be7891e8..19533ad0e 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 4be7891e88b4e2b34adcc23338d672523bd4fb17
+Subproject commit 19533ad0e069e7d9c95ad0396cb64d9220534f1a
diff --git a/examples/platformer/README.md b/examples/platformer/README.md
new file mode 100644
index 000000000..9f097ce36
--- /dev/null
+++ b/examples/platformer/README.md
@@ -0,0 +1,27 @@
+# Platformer
+
+Run the project in the editor or export it for Web. Move with Left/Right or A/D;
+jump with Space. Collect coins while climbing the platforms.
+
+## Stretchable platforms
+
+The four platforms use `Sprite.drawMode = NineSlice` and the existing
+`platform.png` texture. Its import settings define an 8-pixel border on each
+side. The platforms have different widths; their corners remain 8 pixels wide.
+The border belongs to the texture importer, so Sprite and UI share one definition.
+
+Select a platform and use the Rect tool (`T`) to drag its edge. This changes
+`Sprite.size`, leaving `Transform.scale` alone. Undo restores the size and position.
+When changing the playable width, also adjust `BoxCollider2D.halfExtents.x` to
+`Sprite.size.x / 200` (the project uses 100 pixels per physics metre).
+
+The pixel probe checks a fivefold stretch, shared UI corners, batch counts and
+legacy Auto behavior on both backends. From the repository root:
+
+```sh
+pnpm render-host
+node tools/sprite-nine-slice-browser.mjs
+```
+
+Open each printed URL in a browser and click **Run pixel checks**. This workflow
+does not start a desktop application. Set `PROBE_OUTPUT` to retain JSON reports.
diff --git a/examples/platformer/VALIDATION.md b/examples/platformer/VALIDATION.md
new file mode 100644
index 000000000..6830d3673
--- /dev/null
+++ b/examples/platformer/VALIDATION.md
@@ -0,0 +1,47 @@
+# Sprite nine-slice acceptance
+
+RM-088, 2026-10-08. Existing master already implements Sprite Auto/Simple/Tiled/
+NineSlice, `size`, shared batch geometry and editor Rect resizing. This increment
+adds the stretchable platform sample and repeatable pixel acceptance.
+
+## Local WebGL2
+
+The built-in browser used Chrome 155 on Windows. The engine render host loaded
+the real wasm, runtime texture decoder and five-entity fixture. All 10 checks
+passed. Four complete 8×8 corner blocks are identical between a 32×32 Sprite,
+a 160×32 Sprite and a 160×32 UIVisual: 512 compared RGBA pixels. Simple mode is
+a negative control and visibly changes the corner pixels; legacy Auto still
+infers the same texture border. Frame capture agrees with draw replay.
+
+Both NineSlice and Simple produced two draws in two passes, with two RunStart
+breaks. Sprites and screen UI use separate passes; the nine-slice geometry adds
+no extra draw or state break relative to Simple. This is a batching check, not
+a frame-time performance claim.
+
+The platformer Web export succeeded with no warnings/errors, including physics
+and Basis decoding for its existing KTX2 asset. The four platforms retain their
+authored widths, collider sizes and transforms; only their draw mode and the
+texture's shared 8-pixel border change.
+
+Windowless regression: editor Rect drag 11 and texture-border geometry 19 tests;
+SDK import settings 13, generated field metadata 1, scene format/loading/
+validation 84; pixel-predicate tests 4. No local desktop/Electron verifier ran.
+
+## Second backend
+
+The built-in browser reports **no WebGPU adapter**. That is unavailable coverage,
+not a pass. The same full-corner predicate is registered as the PR-tier
+`sprite-nine-slice` scene on WebGL2 and WebGPU, so a CI machine with an adapter
+can run it. The roadmap must retain pending acceptance until this passes.
+
+## Reproduce without desktop windows
+
+```sh
+pnpm render-host
+node tools/sprite-nine-slice-browser.mjs
+```
+
+Open both printed URLs and click **Run pixel checks**. `PROBE_OUTPUT` optionally
+saves JSON reports. Local evidence is retained outside the repository in
+`output/sprite-nine-slice/`: WebGL2 report/screenshot, unavailable WebGPU report,
+and the platformer export report. No native-device acceptance is claimed.
diff --git a/examples/platformer/assets/scenes/main.esscene b/examples/platformer/assets/scenes/main.esscene
index 44c9535bc..9410ee3bb 100644
--- a/examples/platformer/assets/scenes/main.esscene
+++ b/examples/platformer/assets/scenes/main.esscene
@@ -150,7 +150,8 @@
"b": 0.3,
"a": 1
},
- "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7"
+ "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7",
+ "drawMode": 3
}
},
{
@@ -203,7 +204,8 @@
"b": 0.3,
"a": 1
},
- "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7"
+ "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7",
+ "drawMode": 3
}
},
{
@@ -256,7 +258,8 @@
"b": 0.3,
"a": 1
},
- "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7"
+ "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7",
+ "drawMode": 3
}
},
{
@@ -309,7 +312,8 @@
"b": 0.3,
"a": 1
},
- "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7"
+ "texture": "@uuid:0258e55e-9aa0-47eb-8092-7386e03f97c7",
+ "drawMode": 3
}
},
{
diff --git a/examples/platformer/assets/textures/platform.png.meta b/examples/platformer/assets/textures/platform.png.meta
index 57e82d172..ac796a5e7 100644
--- a/examples/platformer/assets/textures/platform.png.meta
+++ b/examples/platformer/assets/textures/platform.png.meta
@@ -8,10 +8,10 @@
"wrapMode": "repeat",
"premultiplyAlpha": false,
"sliceBorder": {
- "left": 0,
- "right": 0,
- "top": 0,
- "bottom": 0
+ "left": 8,
+ "right": 8,
+ "top": 8,
+ "bottom": 8
}
}
-}
\ No newline at end of file
+}
diff --git a/fixtures/scenes/sprite-nine-slice.esscene b/fixtures/scenes/sprite-nine-slice.esscene
new file mode 100644
index 000000000..55b90d424
--- /dev/null
+++ b/fixtures/scenes/sprite-nine-slice.esscene
@@ -0,0 +1,177 @@
+{
+ "version": 4,
+ "name": "Sprite nine-slice fivefold stretch",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 10
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 64,
+ "isActive": true
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "NineSlice 1",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": -96,
+ "y": 24,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "texture": "@uuid:d657c898-17e7-44d9-9f37-e82b13e0107b",
+ "size": {
+ "x": 32,
+ "y": 32
+ },
+ "drawMode": 3
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 2,
+ "name": "NineSlice 2",
+ "parent": null,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 40,
+ "y": 24,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Sprite",
+ "data": {
+ "texture": "@uuid:d657c898-17e7-44d9-9f37-e82b13e0107b",
+ "size": {
+ "x": 160,
+ "y": 32
+ },
+ "drawMode": 3
+ }
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 3,
+ "name": "Canvas",
+ "parent": null,
+ "children": [
+ 4
+ ],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Canvas",
+ "data": {
+ "designResolution": {
+ "x": 320,
+ "y": 128
+ },
+ "scaleMode": 2
+ }
+ },
+ {
+ "type": "UINode",
+ "data": {}
+ }
+ ],
+ "visible": true
+ },
+ {
+ "id": 4,
+ "name": "Shared UI nine-slice",
+ "parent": 3,
+ "children": [],
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "UINode",
+ "data": {
+ "position": 1,
+ "insetLeft": {
+ "value": 120,
+ "unit": 0
+ },
+ "insetTop": {
+ "value": 80,
+ "unit": 0
+ },
+ "width": {
+ "value": 160,
+ "unit": 0
+ },
+ "height": {
+ "value": 32,
+ "unit": 0
+ }
+ }
+ },
+ {
+ "type": "UIVisual",
+ "data": {
+ "visualType": 3,
+ "texture": "@uuid:d657c898-17e7-44d9-9f37-e82b13e0107b",
+ "enabled": true
+ }
+ }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/fixtures/scenes/sprite-nine-slice.textures.json b/fixtures/scenes/sprite-nine-slice.textures.json
new file mode 100644
index 000000000..9d6d090ee
--- /dev/null
+++ b/fixtures/scenes/sprite-nine-slice.textures.json
@@ -0,0 +1,3 @@
+{
+ "d657c898-17e7-44d9-9f37-e82b13e0107b": "/textures/sprite-nine-slice.png"
+}
diff --git a/fixtures/textures/sprite-nine-slice.png b/fixtures/textures/sprite-nine-slice.png
new file mode 100644
index 000000000..44222f097
Binary files /dev/null and b/fixtures/textures/sprite-nine-slice.png differ
diff --git a/fixtures/textures/sprite-nine-slice.png.meta b/fixtures/textures/sprite-nine-slice.png.meta
new file mode 100644
index 000000000..c2cc8078a
--- /dev/null
+++ b/fixtures/textures/sprite-nine-slice.png.meta
@@ -0,0 +1,15 @@
+{
+ "uuid": "d657c898-17e7-44d9-9f37-e82b13e0107b",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "filterMode": "nearest",
+ "wrapMode": "clamp",
+ "sliceBorder": {
+ "left": 8,
+ "right": 8,
+ "top": 8,
+ "bottom": 8
+ }
+ }
+}
diff --git a/tools/lib/nineSliceProbe.mjs b/tools/lib/nineSliceProbe.mjs
new file mode 100644
index 000000000..76cc807dc
--- /dev/null
+++ b/tools/lib/nineSliceProbe.mjs
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/** Compare complete corner blocks of bottom-up GPU readbacks, in screen pixels.
+ * Reject empty/uniform references so a blank frame cannot pass by equality. */
+export function checkNineSliceCorners(rgba, width, height, rects, border = 8) {
+ if (!Number.isInteger(border) || border <= 0 || !Number.isInteger(width) || !Number.isInteger(height)
+ || width <= 0 || height <= 0 || rgba.length !== width * height * 4 || rects.length < 2) {
+ return { ok: false, error: 'Invalid readback or comparison' };
+ }
+ const blocks = [];
+ for (const [left, top, w, h] of rects) {
+ if (![left, top, w, h].every(Number.isInteger) || left < 0 || top < 0 || w < border * 2 || h < border * 2
+ || left + w > width || top + h > height) return { ok: false, error: 'Invalid rectangle' };
+ const pixels = [];
+ for (const [x, y] of [[left, top], [left + w - border, top], [left, top + h - border], [left + w - border, top + h - border]]) {
+ for (let j = 0; j < border; j++) for (let i = 0; i < border; i++) {
+ const k = ((height - 1 - y - j) * width + x + i) * 4;
+ pixels.push(...rgba.slice(k, k + 4));
+ }
+ }
+ blocks.push(pixels);
+ }
+ const varied = new Set(blocks[0]).size > 12;
+ const mismatches = blocks.slice(1).map(block => block.reduce((n, v, i) => n + (v !== blocks[0][i] ? 1 : 0), 0));
+ return { ok: varied && mismatches.every(n => n === 0), varied, mismatches, comparedPixels: (blocks.length - 1) * 4 * border * border };
+}
diff --git a/tools/render-host/run.mjs b/tools/render-host/run.mjs
index d6d7e80ed..bbdcf2856 100644
--- a/tools/render-host/run.mjs
+++ b/tools/render-host/run.mjs
@@ -53,6 +53,7 @@ import { fileURLToPath } from 'node:url';
import { onRendererConsole } from '../lib/rendererConsole.mjs';
import { serveHost } from '../lib/staticServer.mjs';
import { checkSeam } from '../lib/seamProbe.mjs';
+import { checkNineSliceCorners } from '../lib/nineSliceProbe.mjs';
// SwiftShader rasterizes on the CPU; run the whole electron tree below normal
// priority (child processes inherit the class) so a verify never starves the
@@ -219,7 +220,7 @@ function finish(result, server) {
// its pixels answer a different question — say which asset instead.
const assetsOk = (result.missingAssets?.length ?? 0) === 0;
const ok = result.ok && renderedOk && assetsOk && (result.expect?.ok ?? true) && (result.twins?.ok ?? true) && (result.count?.ok ?? true) &&
- (result.seam?.ok ?? true) &&
+ (result.seam?.ok ?? true) && (result.nineSlice?.ok ?? true) &&
(result.resize?.ok ?? true) && (result.preview?.ok ?? true) &&
(result.meshPreview?.ok ?? true) && (result.grid?.ok ?? true) &&
(result.draws?.ok ?? true) && (result.counters?.ok ?? true) && (result.frameDebug?.ok ?? true) && (result.edge?.ok ?? true) && (result.cutoutEdge?.ok ?? true) && (result.minified?.ok ?? true) &&
@@ -755,6 +756,11 @@ app.whenReady().then(async () => {
// ESTELLA_VERIFY_TWINS = { pairs: [[x1, y1, x2, y2], ...], tol }: points that must match —
// one surface drawn two ways, as a conformance model pairs a normal-mapped bump with the
// same bump built as geometry. Pins only that the two agree, not the lighting.
+ let nineSlice = null;
+ if (process.env.ESTELLA_VERIFY_NINE_SLICE) {
+ const rects = JSON.parse(process.env.ESTELLA_VERIFY_NINE_SLICE);
+ nineSlice = await readFrame(`return (${checkNineSliceCorners.toString()})(px, w, h, ${JSON.stringify(rects)});`);
+ }
let twins = null;
if (process.env.ESTELLA_VERIFY_TWINS) {
twins = await readFrame(`
@@ -1046,7 +1052,7 @@ app.whenReady().then(async () => {
`);
if (respaced != null) grid = { ...grid, respacedPixels: respaced, ok: grid.ok && respaced > 300 };
}
- finish({ ok: true, entityCount, missingAssets, drawCalls, draws, counters, frameDebug, edge, cutoutEdge, minified, profile, capture, expect, twins, count, seam, resize, preview, meshPreview, grid, deviceLoss, roundtrip, meshResident, meshAsset, meshMaterial, meshPrefab, setField, animator, pick, cameraTarget }, server);
+ finish({ ok: true, entityCount, missingAssets, drawCalls, draws, counters, frameDebug, edge, cutoutEdge, minified, profile, capture, expect, twins, nineSlice, count, seam, resize, preview, meshPreview, grid, deviceLoss, roundtrip, meshResident, meshAsset, meshMaterial, meshPrefab, setField, animator, pick, cameraTarget }, server);
} catch (e) {
finish({ ok: false, error: String((e && e.stack) || e) }, server);
}
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 144ae5f0d..09587bd23 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -56,6 +56,14 @@ export function sceneWatchdogMs(backend, host) {
* verbatim — an empty one is the default sprite scene.
*/
export const SCENES = [
+ // Full 8x8 corner blocks: native Sprite, 5x-wide Sprite, and shared UI geometry.
+ { id: 'sprite-nine-slice', tier: 'pr', webgpu: true, env: {
+ ESTELLA_VERIFY_SCENE: '/scenes/sprite-nine-slice.esscene',
+ ESTELLA_VERIFY_MANIFEST: '/scenes/sprite-nine-slice.textures.json',
+ ESTELLA_VERIFY_W: '320', ESTELLA_VERIFY_H: '128', ESTELLA_VERIFY_STEPS: '3',
+ ESTELLA_VERIFY_TEXTURES: 'runtime', ESTELLA_VERIFY_FRAME_DEBUG: '1',
+ ESTELLA_VERIFY_NINE_SLICE: '[[48,24,32,32],[120,24,160,32],[120,80,160,32]]',
+ } },
{ id: "sprite-default", tier: "pr", webgpu: true, env: { } },
// What the BATCHER achieved, which no pixel can show: nineteen sprites over two
// textures reach the GPU as three draws. Every break is accounted for to its
diff --git a/tools/sprite-nine-slice-browser.mjs b/tools/sprite-nine-slice-browser.mjs
new file mode 100644
index 000000000..8972740ba
--- /dev/null
+++ b/tools/sprite-nine-slice-browser.mjs
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+// Serve the engine pixel probe in an ordinary browser. Does not launch Electron.
+// First: pnpm render-host. Then open the printed WebGL2 and WebGPU URLs.
+import { createServer } from 'node:http';
+import { readFile, stat, mkdir, writeFile } from 'node:fs/promises';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const host = path.join(root, 'build/render-host');
+await stat(path.join(host, 'host.js'));
+const port = Number(process.env.PORT ?? 5192);
+const output = process.env.PROBE_OUTPUT ? path.resolve(process.env.PROBE_OUTPUT) : null;
+const types = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript', '.wasm': 'application/wasm', '.png': 'image/png', '.json': 'application/json' };
+const page = `<!doctype html><meta charset="utf-8"><title>Sprite nine-slice pixel probe</title>
+<style>body{background:#18202e;color:#e7edf5;font:16px system-ui;margin:24px}button{padding:10px}canvas{image-rendering:pixelated}#result{white-space:pre-wrap}</style>
+<h1>Sprite nine-slice</h1><p>Native / five times wider / shared UI geometry</p>
+<button id="run">Run pixel checks</button><p id="summary">Booting…</p><canvas id="preview"></canvas><details><summary>Evidence</summary><pre id="result"></pre></details>
+<script type="module" src="/tools/sprite-nine-slice-probe.mjs"></script>`;
+const server = createServer(async (req, res) => {
+ try {
+ const url = new URL(req.url, 'http://localhost');
+ if (url.pathname === '/report' && req.method === 'POST') {
+ let body = ''; for await (const chunk of req) { body += chunk; if (body.length > 2_000_000) throw Error('Report too large'); }
+ const report = JSON.parse(body);
+ if (!['webgl2', 'webgpu'].includes(report.backend)) throw Error('Invalid backend');
+ if (output) {
+ await mkdir(output, { recursive: true });
+ await writeFile(path.join(output, `${report.backend}.json`), JSON.stringify(report, null, 2) + '\n');
+ }
+ res.writeHead(200); res.end('saved'); return;
+ }
+ if (req.method !== 'GET') { res.writeHead(405); res.end(); return; }
+ if (url.pathname === '/') { res.setHeader('Content-Type', 'text/html'); res.end(page); return; }
+ const rel = decodeURIComponent(url.pathname).slice(1);
+ const base = rel.startsWith('tools/') ? root : rel.startsWith('textures/') || rel.startsWith('scenes/') ? path.join(root, 'fixtures') : host;
+ const file = path.resolve(base, rel);
+ if (!file.startsWith(base + path.sep)) { res.writeHead(403); res.end(); return; }
+ res.setHeader('Content-Type', types[path.extname(file)] ?? 'application/octet-stream');
+ res.end(await readFile(file));
+ } catch (error) { res.writeHead(404); res.end(String(error)); }
+});
+server.listen(port, '127.0.0.1', () => {
+ for (const backend of ['webgl2', 'webgpu']) console.log(`http://127.0.0.1:${port}/?w=320&h=128&textures=runtime&backend=${backend}`);
+});
diff --git a/tools/sprite-nine-slice-probe.mjs b/tools/sprite-nine-slice-probe.mjs
new file mode 100644
index 000000000..486d7a5a9
--- /dev/null
+++ b/tools/sprite-nine-slice-probe.mjs
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import '/host.js';
+import { checkNineSliceCorners } from './lib/nineSliceProbe.mjs';
+
+const result = document.querySelector('#result');
+const button = document.querySelector('#run');
+const backend = new URL(location.href).searchParams.get('backend') ?? 'webgl2';
+const scene = '/scenes/sprite-nine-slice.esscene';
+const manifest = '/scenes/sprite-nine-slice.textures.json';
+const summary = document.querySelector('#summary');
+const preview = document.querySelector('#preview');
+const checks = [];
+function check(name, condition, detail) {
+ checks.push({ name, pass: !!condition, detail });
+ if (!condition) throw Error(`${name}: ${JSON.stringify(detail)}`);
+}
+function block(px, x, y) {
+ const out = [];
+ for (let j = 0; j < 8; j++) for (let i = 0; i < 8; i++) {
+ // GPU readback is bottom-up.
+ const k = ((px.height - 1 - y - j) * px.width + x + i) * 4;
+ out.push(...px.rgba.slice(k, k + 4));
+ }
+ return out;
+}
+function corners(px, left, top, width) {
+ return [[left, top], [left + width - 8, top], [left, top + 24], [left + width - 8, top + 24]]
+ .map(([x, y]) => block(px, x, y));
+}
+function same(a, b) { return a.every((corner, c) => corner.every((v, i) => v === b[c][i])); }
+function show(px) {
+ preview.width = px.width; preview.height = px.height;
+ const ctx = preview.getContext('2d');
+ const data = new Uint8ClampedArray(px.rgba.length);
+ for (let y = 0; y < px.height; y++) data.set(px.rgba.slice((px.height - 1 - y) * px.width * 4, (px.height - y) * px.width * 4), y * px.width * 4);
+ ctx.putImageData(new ImageData(data, px.width, px.height), 0, 0);
+}
+button.disabled = true;
+try { await window.__estellaHeadless.ready; summary.textContent = `Ready: ${backend}`; button.disabled = false; }
+catch (error) {
+ summary.textContent = `Unavailable: ${backend} — ${error.message}`;
+ const report = { backend, available: false, error: error.stack, passed: 0, failed: 0 };
+ result.textContent = JSON.stringify(report, null, 2);
+ await fetch('/report', { method: 'POST', body: JSON.stringify(report) });
+}
+button.onclick = async () => {
+ button.disabled = true; checks.length = 0; summary.textContent = 'Checking…';
+ try {
+ const api = window.__estellaHeadless.api;
+ const loaded = await api.loadScene(scene, manifest);
+ check('All fixture assets loaded', loaded.missing.length === 0, loaded);
+ await api.step(3);
+ let px = await api.captureViewportPixels();
+ check('GPU readback', px?.width === 320 && px?.height === 128, { width: px?.width, height: px?.height });
+ const native = corners(px, 48, 24, 32), wide = corners(px, 120, 24, 160);
+ check('Corners contain the authored pattern', new Set(native.flat()).size > 12, new Set(native.flat()).size);
+ check('Five times wider preserves every corner pixel', same(native, wide));
+ check('UIVisual uses identical corner pixels', same(native, corners(px, 120, 80, 160)));
+ const fullComparison = checkNineSliceCorners(px.rgba, px.width, px.height, [[48,24,32,32],[120,24,160,32],[120,80,160,32]]);
+ check('CI corner predicate', fullComparison.ok, fullComparison);
+ const slicedBatch = await api.frameDebug();
+ check('Frame capture matches replay', slicedBatch?.matches, slicedBatch);
+ api.setField(2, 'Sprite', 'drawMode', 'enum', 1);
+ await api.step(2); px = await api.captureViewportPixels();
+ check('Simple negative control deforms corners', !same(native, corners(px, 120, 24, 160)));
+ const plainBatch = await api.frameDebug();
+ check('Nine-slice adds no draw calls or state breaks', slicedBatch.draws === plainBatch.draws && JSON.stringify(slicedBatch.breaks) === JSON.stringify(plainBatch.breaks), { slicedBatch, plainBatch });
+ api.setField(2, 'Sprite', 'drawMode', 'enum', 0);
+ await api.step(2); px = await api.captureViewportPixels();
+ check('Legacy Auto still infers texture borders', same(native, corners(px, 120, 24, 160)));
+ api.setField(2, 'Sprite', 'drawMode', 'enum', 3);
+ await api.step(2); show(await api.captureViewportPixels());
+ } catch (error) { checks.push({ name: 'Probe error', pass: false, detail: error.stack }); }
+ const report = { backend, userAgent: navigator.userAgent, checks, passed: checks.filter(c => c.pass).length, failed: checks.filter(c => !c.pass).length };
+ result.textContent = JSON.stringify(report, null, 2);
+ summary.textContent = `${backend}: ${report.passed} passed, ${report.failed} failed`;
+ const saved = await fetch('/report', { method: 'POST', body: JSON.stringify(report) });
+ if (!saved.ok) result.textContent += '\nReport could not be saved';
+ button.disabled = false;
+};
diff --git a/tools/tests/nine-slice-probe.test.ts b/tools/tests/nine-slice-probe.test.ts
new file mode 100644
index 000000000..aae03f4d9
--- /dev/null
+++ b/tools/tests/nine-slice-probe.test.ts
@@ -0,0 +1,33 @@
+import { describe, it, expect } from 'vitest';
+import { checkNineSliceCorners } from '../lib/nineSliceProbe.mjs';
+
+describe('nine-slice pixel acceptance', () => {
+ const width = 64, height = 16;
+ function frame() {
+ const rgba = new Uint8Array(width * height * 4);
+ for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
+ const k = ((height - 1 - y) * width + x) * 4;
+ rgba.set([x % 8 + y * 8, y * 7, (x % 8) * 15, 255], k);
+ }
+ return rgba;
+ }
+ const rects = [[0,0,16,16],[24,0,40,16]];
+ it('compares every corner pixel after a width change', () => {
+ expect(checkNineSliceCorners(frame(), width, height, rects)).toMatchObject({ok:true,comparedPixels:256});
+ });
+ it('rejects one damaged channel inside each corner', () => {
+ for (const [x,y] of [[26,2],[58,2],[26,10],[58,10]]) {
+ const rgba = frame(); rgba[((height - 1 - y) * width + x) * 4 + 1]++;
+ expect(checkNineSliceCorners(rgba, width, height, rects).ok).toBe(false);
+ }
+ });
+ it('rejects empty and uniform frames even if equal', () => {
+ expect(checkNineSliceCorners(new Uint8Array(width * height * 4), width, height, rects).ok).toBe(false);
+ expect(checkNineSliceCorners(new Uint8Array(width * height * 4).fill(255), width, height, rects).ok).toBe(false);
+ });
+ it('rejects an invalid readback or rectangle', () => {
+ expect(checkNineSliceCorners(frame(),width,height,[[0,0,16,16],[60,0,40,16]]).ok).toBe(false);
+ expect(checkNineSliceCorners(frame(),width,height,rects,0).ok).toBe(false);
+ expect(checkNineSliceCorners(frame().slice(4),width,height,rects).ok).toBe(false);
+ });
+});