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
test(render): a pixel gate can draw a published asset
esengine41587d1b4ee2
diff --git a/tools/check-render-scenes.mjs b/tools/check-render-scenes.mjsindex c5d9abdbe..aaea35c44 100644--- a/tools/check-render-scenes.mjs+++ b/tools/check-render-scenes.mjs@@ -46,7 +46,7 @@ for (const s of SCENES) {|| s.env.ESTELLA_VERIFY_SEAM|| s.env.ESTELLA_VERIFY_GRID || s.env.ESTELLA_VERIFY_PREVIEW|| s.env.ESTELLA_VERIFY_MESH_PREVIEW || s.env.ESTELLA_VERIFY_DEPTH_LAYERS- || s.env.ESTELLA_VERIFY_COUNTERS || s.env.ESTELLA_VERIFY_COUNTERS_MAX || s.env.ESTELLA_VERIFY_FRAME_DEBUG || s.env.ESTELLA_VERIFY_EDGE+ || s.env.ESTELLA_VERIFY_COUNTERS || s.env.ESTELLA_VERIFY_COUNTERS_MAX || s.env.ESTELLA_VERIFY_FRAME_DEBUG || s.env.ESTELLA_VERIFY_EDGE || s.env.ESTELLA_VERIFY_CUTOUT_EDGE|| s.env.ESTELLA_VERIFY_DRAW_CALLS|| s.env.ESTELLA_VERIFY_YSORT || s.id === 'sprite-default';if (!asserts && !s.rendersOnly) {diff --git a/tools/corpora.mjs b/tools/corpora.mjsindex 8ac91c4e0..934458e01 100644--- a/tools/corpora.mjs+++ b/tools/corpora.mjs@@ -10,13 +10,17 @@* fails loudly instead of quietly testing something else.** node tools/corpora.mjs fetch [id …] fetch (all by default) into the cache+ * node tools/corpora.mjs import [id …] …and import its models with this checkout's importer* node tools/corpora.mjs list*- * Cache: `.cache/corpora/<id>/` at the repository root, or `ESTELLA_CORPORA_DIR`.+ * Cache: `<cache>/corpora/<id>/`, where `<cache>` is `.cache` at the repository root+ * or `ESTELLA_CACHE_DIR`. `<cache>` is the project root imports resolve against, so+ * every product is addressed `corpora/<id>/…` — the path the render host serves.*/import { createHash } from 'node:crypto';+import { execFileSync } from 'node:child_process';import { existsSync } from 'node:fs';-import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';+import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';import path from 'node:path';import { fileURLToPath } from 'node:url';@@ -25,11 +29,27 @@ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');const KHRONOS_SAMPLES = 'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/7d4ba189827916452eeadc82d4b712dbc6280a6f';export const CORPORA = {+ 'khronos-alpha-blend-mode-test': {+ what: 'Khronos glTF sample: one box per alpha mode — opaque, blend, and cutouts at 0.25, the default 0.5 and 0.75',+ license: 'CC-BY-4.0 (© 2017 Analytical Graphics, Inc.; Khronos glTF-Sample-Assets)',+ source: 'https://github.com/KhronosGroup/glTF-Sample-Assets/tree/7d4ba189827916452eeadc82d4b712dbc6280a6f/Models/AlphaBlendModeTest',+ base: `${KHRONOS_SAMPLES}/Models/AlphaBlendModeTest/glTF`,+ models: ['AlphaBlendModeTest.gltf'],+ files: {+ 'AlphaBlendModeTest.gltf': '49e06672900df95593040d35bbc7a2ee5921ae8d46edc44b64ccf2df65e64849',+ 'AlphaBlendModeTest.bin': 'bb89ab8d9ac0cfbc168e5d552e3ec2fe1285fd01bacb65c863d838b3db025c85',+ 'AlphaBlendLabels.png': '19c705f7e207384ca1ab01e0665601c051ca33c5848c03ce4fffad625b416b53',+ 'MatBed_baseColor.jpg': '71571cce0d86c7c5ed4ac73d852ec34e72e7234a2f905f2758e118519c950bcf',+ 'MatBed_normal.jpg': 'd8891a9c08e375507ac8f1fb260577bda5e90506e79db92ebbfb5caa9216be49',+ 'MatBed_occlusionRoughnessMetallic.jpg': 'e1472454ad6be574c3a418985f06a8ba36877108a94f61590f01e118804379b4',+ },+ },'khronos-water-bottle': {what: 'Khronos glTF sample: a PBR bottle with base colour, normal, packed occlusion/roughness/metal and emissive maps',license: 'CC0-1.0',source: 'https://github.com/KhronosGroup/glTF-Sample-Assets/tree/7d4ba189827916452eeadc82d4b712dbc6280a6f/Models/WaterBottle',base: `${KHRONOS_SAMPLES}/Models/WaterBottle/glTF`,+ models: ['WaterBottle.gltf'],files: {'WaterBottle.gltf': '0596f4e61dc781439d254fdfb5e3462daf1762c18715e3e3ac13001aa8f3f547','WaterBottle.bin': 'e4921f2d0c0a03cf65286bd195f3688d4f99d7b6a58f25935e70d516d744156e',@@ -43,10 +63,46 @@ export const CORPORA = {const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');+/** The root imports resolve against; corpora live in its `corpora/`. */+export function corporaRoot() {+ return process.env.ESTELLA_CACHE_DIR || path.join(ROOT, '.cache');+}+/** Where a corpus lives once fetched. */export function corpusDir(id) {- const base = process.env.ESTELLA_CORPORA_DIR || path.join(ROOT, '.cache', 'corpora');- return path.join(base, id);+ return path.join(corporaRoot(), 'corpora', id);+}++/** What an import depends on besides the source: the importer's own code. */+async function importerStamp(entry) {+ const h = createHash('sha256');+ for (const hash of Object.values(entry.files)) h.update(hash);+ for (const f of ['gltfImport', 'fbxImport', 'modelImport', 'modelImages', 'readModelSource']) {+ h.update(await readFile(path.join(ROOT, 'pipeline', 'src', 'assets', `${f}.ts`)));+ }+ return h.digest('hex');+}++/**+ * The corpus fetched and its models imported into `imported/` beside the sources,+ * redone whenever the sources or the importer change — a product this checkout's+ * importer did not write would test someone else's.+ */+export async function importedCorpus(id) {+ const dir = await corpus(id);+ const entry = CORPORA[id];+ const out = path.join(dir, 'imported');+ const stampFile = path.join(out, '.stamp');+ const stamp = await importerStamp(entry);+ if (existsSync(stampFile) && (await readFile(stampFile, 'utf8')) === stamp) return out;+ await rm(out, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+ await mkdir(out, { recursive: true });+ for (const model of entry.models ?? []) {+ execFileSync(process.execPath, [path.join(ROOT, 'pipeline', 'bin', 'estella.mjs'), 'import-model',+ path.join(dir, model), out, '--project', corporaRoot()], { stdio: 'inherit' });+ }+ await writeFile(stampFile, stamp);+ return out;}async function fetchVerified(url, want) {@@ -88,8 +144,10 @@ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.mefor (const [id, e] of Object.entries(CORPORA)) console.log(`${id} ${e.license} ${e.what}\n ${e.source}`);} else if (cmd === 'fetch') {for (const id of ids.length ? ids : Object.keys(CORPORA)) console.log(`${id}: ${await corpus(id)}`);+ } else if (cmd === 'import') {+ for (const id of ids.length ? ids : Object.keys(CORPORA)) console.log(`${id}: ${await importedCorpus(id)}`);} else {- console.error('usage: node tools/corpora.mjs fetch [id …] | list');+ console.error('usage: node tools/corpora.mjs fetch [id …] | import [id …] | list');process.exit(2);}}diff --git a/tools/lib/staticServer.mjs b/tools/lib/staticServer.mjsindex afa26e056..e8398e38c 100644--- a/tools/lib/staticServer.mjs+++ b/tools/lib/staticServer.mjs@@ -20,6 +20,8 @@ import { fileURLToPath } from 'node:url';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');const FIXTURES = path.join(ROOT, 'fixtures');+/** Published assets tools/corpora.mjs fetched and imported, addressed `/corpora/<id>/…`. */+const CORPORA_ROOT = process.env.ESTELLA_CACHE_DIR || path.join(ROOT, '.cache');const MIME = {'.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript',@@ -47,7 +49,8 @@ async function readUnder(root, rel) {export function serveHost(dist) {const server = http.createServer(async (req, res) => {const rel = decodeURIComponent(new URL(req.url, 'http://x').pathname).replace(/^\/+/, '') || 'index.html';- const bytes = (await readUnder(dist, rel)) ?? (await readUnder(FIXTURES, rel));+ const bytes = (await readUnder(dist, rel)) ?? (await readUnder(FIXTURES, rel))+ ?? (rel.startsWith('corpora/') ? await readUnder(CORPORA_ROOT, rel) : null);if (!bytes) return void res.writeHead(404).end('not found');res.writeHead(200, { 'content-type': MIME[path.extname(rel).toLowerCase()] ?? 'application/octet-stream' });res.end(bytes);diff --git a/tools/render-host/host.ts b/tools/render-host/host.tsindex 8ebdaa7a4..3f86ec75d 100644--- a/tools/render-host/host.ts+++ b/tools/render-host/host.ts@@ -39,6 +39,7 @@ const height = Number(params.get('h')) || 720;const backend = params.get('backend') === 'webgpu' ? 'webgpu' : 'webgl2';const colorSpace = params.get('colorSpace') === 'linear' ? 'linear' : undefined;const outputTransform = params.get('outputTransform') === 'aces' ? 'aces' : undefined;+const msaaSamples = Number(params.get('msaa')) || undefined;const seedParam = params.get('seed');const randomSeed = seedParam !== null && Number.isFinite(Number(seedParam)) ? Number(seedParam) : undefined;const depthLayers = Number(params.get('depthLayers')) || undefined;@@ -135,6 +136,7 @@ async function boot(): Promise<void> {renderSurface,colorSpace,outputTransform,+ msaaSamples,randomSeed,depthLayers,screenFit,diff --git a/tools/render-host/run.mjs b/tools/render-host/run.mjsindex 20889424e..48952b010 100644--- a/tools/render-host/run.mjs+++ b/tools/render-host/run.mjs@@ -35,8 +35,10 @@* ESTELLA_VERIFY_FRAME_DEBUG capture the frame and replay it (the frame debugger)* ESTELLA_VERIFY_UNIFORM the frame is one colour on purpose; ESTELLA_VERIFY_COUNT says which* ESTELLA_VERIFY_EDGE how straight a straight edge is drawn (JSON: box, lit, dark, maxJag)+ * ESTELLA_VERIFY_CUTOUT_EDGE how often a cutout's edge pixel is a blend (JSON: box, lit, run, partial, minShare)* ESTELLA_VERIFY_SCALE copy the scene's content onto a grid (JSON), for a cost gate* ESTELLA_VERIFY_OUTPUT_TRANSFORM the frame's output curve ("aces")+ * ESTELLA_VERIFY_MSAA multisample count the scene asks for (the app's default otherwise)* ESTELLA_VERIFY_PROFILE record N further frames and report the TS/C++ cost split* ESTELLA_VERIFY_TIMEOUT_MS how long this run may take before it reports one*/@@ -88,6 +90,7 @@ const COLORSPACE = process.env.ESTELLA_VERIFY_COLORSPACE === 'linear' ? 'linear'// ESTELLA_VERIFY_OUTPUT_TRANSFORM=aces boots the project output transform, which// is a curve on the way out and engages the capture on its own.const OUTPUT_TRANSFORM = process.env.ESTELLA_VERIFY_OUTPUT_TRANSFORM === 'aces' ? 'aces' : '';+const MSAA = process.env.ESTELLA_VERIFY_MSAA ?? '';// A scene whose emitters roll dice has no constant to assert until the run is// seeded; the engine seeds itself from the clock when nobody says otherwise.const SEED = process.env.ESTELLA_VERIFY_SEED ?? '';@@ -215,7 +218,7 @@ function finish(result, server) {(result.seam?.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.draws?.ok ?? true) && (result.counters?.ok ?? true) && (result.frameDebug?.ok ?? true) && (result.edge?.ok ?? true) && (result.cutoutEdge?.ok ?? true) &&(result.roundtrip?.ok ?? true) && deviceLossOk && meshOk && pickOk;const why = assetsOk ? '' : `: could not load ${result.missingAssets.join(', ')}`;console.log(`\n[verify:render] ${ok ? 'PASS' : 'FAIL'} — ${SCENE} (${BACKEND})${why}`);@@ -235,7 +238,7 @@ app.whenReady().then(async () => {let server;try {server = await serveHost(DIST);- const url = `http://127.0.0.1:${server.address().port}/${PAGE}?w=${W}&h=${H}&backend=${BACKEND}${COLORSPACE ? `&colorSpace=${COLORSPACE}` : ''}${OUTPUT_TRANSFORM ? `&outputTransform=${OUTPUT_TRANSFORM}` : ''}${DEPTH_LAYERS ? `&depthLayers=${DEPTH_LAYERS}` : ''}${RENDER_RESOLUTION ? `&renderResolution=${RENDER_RESOLUTION}` : ''}${SEED ? `&seed=${SEED}` : ''}`;+ const url = `http://127.0.0.1:${server.address().port}/${PAGE}?w=${W}&h=${H}&backend=${BACKEND}${COLORSPACE ? `&colorSpace=${COLORSPACE}` : ''}${OUTPUT_TRANSFORM ? `&outputTransform=${OUTPUT_TRANSFORM}` : ''}${MSAA ? `&msaa=${MSAA}` : ''}${DEPTH_LAYERS ? `&depthLayers=${DEPTH_LAYERS}` : ''}${RENDER_RESOLUTION ? `&renderResolution=${RENDER_RESOLUTION}` : ''}${SEED ? `&seed=${SEED}` : ''}`;// useContentSize: the capture rectangle must be the page area, not the// outer frame (the same trap the parity runner documents).@@ -775,6 +778,31 @@ app.whenReady().then(async () => {return { rows: pos.length, jag, maxJag: e.maxJag, ok: pos.length >= (y1 - y0) * 0.8 && jag <= e.maxJag };`);}+ // ESTELLA_VERIFY_CUTOUT_EDGE = { box, lit, run, partial, minShare }: the share of rows+ // whose texel before a cutout's edge is a blend, which coverage from alpha makes and+ // an alpha test does not. The edge is the first `run` texels whose weakest channel is lit.+ let cutoutEdge = null;+ if (process.env.ESTELLA_VERIFY_CUTOUT_EDGE) {+ cutoutEdge = await readFrame(`+ const e = ${JSON.stringify(JSON.parse(process.env.ESTELLA_VERIFY_CUTOUT_EDGE))};+ const weakest = (x, y) => { const i = (((h - 1) - y) * w + x) * 4; return Math.min(px[i], px[i + 1], px[i + 2]); };+ const [x0, y0, x1, y1] = [e.box[0] * w, e.box[1] * h, e.box[2] * w, e.box[3] * h].map(Math.round);+ let rows = 0, blended = 0;+ for (let y = y0; y < y1; y++) {+ for (let x = x0 + 1; x < x1 - e.run; x++) {+ let lit = weakest(x - 1, y) < e.lit;+ for (let k = 0; lit && k < e.run; k++) lit = weakest(x + k, y) >= e.lit;+ if (!lit) continue;+ rows++;+ const v = weakest(x - 1, y);+ if (v > e.partial[0] && v < e.partial[1]) blended++;+ break;+ }+ }+ const share = rows ? blended / rows : 0;+ return { rows, blended, share, minShare: e.minShare, ok: rows >= (y1 - y0) * 0.8 && share >= e.minShare };+ `);+ }// ESTELLA_VERIFY_COUNT is a JSON array of { rgb:[r,g,b], tol?, atLeast?, atMost? }:// HOW MANY pixels of the frame are that colour, rather than which ones — a// point probe cannot ask that without also naming where a font put them.@@ -973,7 +1001,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, profile, capture, expect, 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, profile, capture, expect, 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/verify-render.mjs b/tools/verify-render.mjsindex 45eaac622..34361752e 100644--- a/tools/verify-render.mjs+++ b/tools/verify-render.mjs@@ -196,6 +196,14 @@ function runScene(scene) {};}+// Published assets a scene draws (tools/corpora.mjs), fetched and imported before+// any scene runs: a download inside a scene's watchdog would be timed as rendering.+const corporaNeeded = [...new Set(selected.flatMap((s) => s.corpora ?? []))];+if (corporaNeeded.length) {+ const { importedCorpus } = await import('./corpora.mjs');+ for (const id of corporaNeeded) await importedCorpus(id);+}+const failed = [];const unmeasured = [];const startedAt = Date.now();