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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
* @file corpora.mjs — published scenes and models the checks run on, fetched at a
* pinned revision, verified by hash, and never committed.
*
* Hand-made fixtures only exercise what their author thought of; an asset someone
* else authored for their own engine carries the conventions we did not. Each
* entry names its source, licence and every file's sha256, so a changed upstream
* 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>/`, 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, rm, 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 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-normal-tangent-test': {
what: 'Khronos glTF sample: normal-mapped bumps beside the same bumps built as geometry, in every UV orientation, with no tangents supplied',
license: 'CC-BY-4.0 (© 2017 Analytical Graphics, Inc.; Khronos glTF-Sample-Assets)',
source: 'https://github.com/KhronosGroup/glTF-Sample-Assets/tree/7d4ba189827916452eeadc82d4b712dbc6280a6f/Models/NormalTangentTest',
base: `${KHRONOS_SAMPLES}/Models/NormalTangentTest/glTF`,
models: ['NormalTangentTest.gltf'],
files: {
'NormalTangentTest.gltf': 'ef2b152063304ebb0314646d3d1610cdc680e131d2cbfef10972dc6120d4dd18',
'NormalTangentTest0.bin': '2d0fc6d43cb11b61a746bc80218b5e9e6c60dcc40f86d4a3f4fdbf11909cd990',
'NormalTangentTest_BaseColor.png': '4182902c6dc833b48c0325568c2c5bd3e2d5fc04e27a8dc1917ced2818e1fac1',
'NormalTangentTest_OcclusionRoughnessMetallic.png': '3fff511720bea1fd8590ddb7b62090700e812e39ca71dd3200493093ad704399',
'NormalTangentTest_Normal.png': '9cebea6c513ddfb1f5f5c761c08bca1468d2283a3cd9772bba3a57e484862ead',
},
},
'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',
'WaterBottle_baseColor.png': '62d0ad9b4e2c75e9bc7d67644a50d697563000ffa586d2e185ea38f5000e0a63',
'WaterBottle_emissive.png': 'e9b03ea395b0182917f876befda2d31639ce46058c832dd64e5ad02cde5bddb9',
'WaterBottle_normal.png': '284883ce27cc22351557616bad247ef88de4ad42c7a74b493205c92dbd23e536',
'WaterBottle_occlusionRoughnessMetallic.png': '10cc809d9762e8c671f1ae73618dd5fdd07792d2c6ec9c4691cdb991617c9369',
},
},
};
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) {
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) {
let last;
for (let attempt = 0; attempt < 3; attempt++) {
try {
const res = await fetch(url);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const bytes = new Uint8Array(await res.arrayBuffer());
const got = sha256(bytes);
if (got !== want) throw new Error(`sha256 ${got}, expected ${want} — the upstream file changed`);
return bytes;
} catch (e) {
last = e;
}
}
throw new Error(`${url}: ${last?.message ?? last}`);
}
/** The corpus's directory, every file present and matching its hash; fetches what is not. */
export async function corpus(id) {
const entry = CORPORA[id];
if (!entry) throw new Error(`no corpus "${id}" (have: ${Object.keys(CORPORA).join(', ')})`);
const dir = corpusDir(id);
await mkdir(dir, { recursive: true });
for (const [file, want] of Object.entries(entry.files)) {
const abs = path.join(dir, file);
if (existsSync(abs) && sha256(await readFile(abs)) === want) continue;
const bytes = await fetchVerified(`${entry.base}/${file}`, want);
await writeFile(`${abs}.part`, bytes);
await rename(`${abs}.part`, abs);
}
return dir;
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const [cmd = 'list', ...ids] = process.argv.slice(2);
if (cmd === 'list') {
for (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 …] | import [id …] | list');
process.exit(2);
}
}