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(viewport): compare legacy 2D widgets and correct the depth fixture scale

yhh1a1d1cac7989
diff --git a/.github/workflows/editor-spatial.yml b/.github/workflows/editor-spatial.yml
index f3b78d17d..4a6f2571b 100644
--- a/.github/workflows/editor-spatial.yml
+++ b/.github/workflows/editor-spatial.yml
@@ -24,6 +24,8 @@ jobs:
artifact: gizmo-planes-editor-checks
- suite: interaction
artifact: gizmo-interaction-editor-checks
+ - suite: legacy-2d
+ artifact: gizmo-legacy-2d-editor-checks
env:
ESTELLA_WIN_W: '1480'
ESTELLA_WIN_H: '920'
@@ -34,6 +36,7 @@ jobs:
- uses: ./.github/actions/editor-checkout
with:
ssh-key: ${{ secrets.EDITOR_SSH_KEY }}
+ history: full
- uses: ./.github/actions/setup
- name: Require identical engine and SDK sources and a successful Web build
env:
@@ -68,6 +71,9 @@ jobs:
- name: Check origins and universal gestures with undo and cancel
if: matrix.suite == 'interaction'
run: node tools/verify-gizmo-origins.mjs
+ - name: Compare legacy 2D project widgets with their previous editor
+ if: matrix.suite == 'legacy-2d'
+ run: node tools/verify-gizmo-legacy-2d.mjs
- name: Keep spatial acceptance evidence
if: always()
uses: actions/upload-artifact@v7
@@ -78,5 +84,6 @@ jobs:
output/gizmo-occlusion-ci
output/gizmo-hover-ci
output/gizmo-origins-ci
+ output/gizmo-legacy-2d-ci
if-no-files-found: warn
retention-days: 3
diff --git a/tools/verify-gizmo-legacy-2d.mjs b/tools/verify-gizmo-legacy-2d.mjs
new file mode 100644
index 000000000..4e994863c
--- /dev/null
+++ b/tools/verify-gizmo-legacy-2d.mjs
@@ -0,0 +1,95 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import fs from 'node:fs';
+import path from 'node:path';
+import assert from 'node:assert/strict';
+import { execFileSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+import { runElectron } from './lib/electronRun.mjs';
+import { readPNG } from './lib/png.mjs';
+
+if (!process.env.CI) throw Error('Editor acceptance runs only in CI; do not launch the local editor.');
+const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const desktop = path.join(root, 'desktop');
+const out = path.join(root, 'output/gizmo-legacy-2d-ci');
+fs.mkdirSync(out, { recursive: true });
+const git = (args, cwd = root) => execFileSync('git', args, { cwd, windowsHide: true, maxBuffer: 32 * 1024 * 1024 });
+const original = git(['rev-parse', 'HEAD'], desktop).toString().trim();
+// Last editor revision before the RM-117 hover/size/plane/universal additions.
+const baselineRoot = git(['rev-parse', '4005a25b5']).toString().trim();
+const baseline = git(['ls-tree', baselineRoot, 'desktop']).toString().split(/\s+/)[2];
+assert.match(baseline, /^[0-9a-f]{40}$/);
+git(['cat-file', '-e', baseline + '^{commit}'], desktop);
+const project = fs.mkdtempSync(path.join(out, 'legacy-project-'));
+const prefix = 'examples/hello-world/';
+for (const file of git(['ls-tree', '-r', '--name-only', baselineRoot, '--', prefix]).toString().trim().split('\n')) {
+ assert(file.startsWith(prefix), 'Unexpected legacy asset');
+ const target = path.resolve(project, file.slice(prefix.length));
+ assert(target.startsWith(project + path.sep), 'Unexpected legacy output');
+ fs.mkdirSync(path.dirname(target), { recursive: true });
+ fs.writeFileSync(target, git(['show', baselineRoot + ':' + file]));
+}
+const records = [];
+const build = revision => {
+ git(['-c', 'core.hooksPath=' + (process.platform === 'win32' ? 'NUL' : '/dev/null'),
+ 'checkout', '--detach', revision], desktop);
+ const log = execFileSync('pnpm', ['--dir', 'desktop', 'exec', 'vite', 'build'], {
+ cwd: root, encoding: 'utf8', windowsHide: true, maxBuffer: 32 * 1024 * 1024,
+ });
+ fs.writeFileSync(path.join(out, revision + '-build.log'), log);
+};
+try {
+ for (const [label, revision] of [['baseline', baseline], ['current', original]]) {
+ build(revision);
+ for (const mode of ['move', 'rotate', 'scale']) {
+ const name = label + '-' + mode;
+ const run = runElectron(['.'], { via: 'npx', encoding: 'utf8', cwd: desktop, timeout: 180000, env: {
+ ESTELLA_SHOT: path.join(out, name + '.png'), ESTELLA_SHOT_PROJECT: project,
+ ESTELLA_SHOT_SCENE: 'assets/scenes/main.esscene', ESTELLA_SHOT_CROP: '.viewport__stage canvas',
+ ESTELLA_SHOT_EVAL: `(async()=>{
+ const e=window.__estellaEditor;e.runCommand('mode.scene');e.surface.setViewPerspective(false);
+ e.runCommand('view.resetOrbit');e.surface.select(1);e.frame([1]);
+ await new Promise(r=>setTimeout(r,1000));e.runCommand('tool.${mode}');
+ await new Promise(r=>setTimeout(r,200));
+ const t=e.surface.serializeScene().entities.find(v=>v.id===1).components.find(c=>c.type==='Transform').data;
+ return {view:e.editorView(),pose:{position:t.position,scale:t.scale??{x:1,y:1,z:1},rotation:t.rotation??{x:0,y:0,z:0,w:1}}};
+ })()`,
+ } });
+ fs.writeFileSync(path.join(out, name + '.log'), run.stdout + '\n' + run.stderr);
+ assert.equal(run.status, 0, run.stderr);
+ const line = run.stdout.split('\n').find(s => s.startsWith('[eval] '));
+ assert(line, 'Missing legacy project observation');
+ records.push({ label, mode, revision, ...JSON.parse(line.slice(7)) });
+ fs.writeFileSync(path.join(out, 'observations.json'), JSON.stringify({ baselineRoot, baseline, original, records }, null, 2));
+ }
+ }
+ const comparisons = [];
+ for (const mode of ['move', 'rotate', 'scale']) {
+ const a = records.find(r => r.label === 'baseline' && r.mode === mode);
+ const b = records.find(r => r.label === 'current' && r.mode === mode);
+ assert.deepEqual(b.pose, a.pose, 'Legacy project transform changed');
+ assert.deepEqual(b.view, a.view, 'Legacy project framing changed');
+ const before = readPNG(fs.readFileSync(path.join(out, 'baseline-' + mode + '.png')));
+ const after = readPNG(fs.readFileSync(path.join(out, 'current-' + mode + '.png')));
+ assert.equal(before.w, after.w); assert.equal(before.h, after.h);
+ let changed = 0, error = 0, pixels = 0;
+ // Frame places the selected pivot at canvas center; cover the complete widget.
+ for (let y = Math.floor(before.h / 2) - 90; y <= Math.floor(before.h / 2) + 90; y++) {
+ for (let x = Math.floor(before.w / 2) - 90; x <= Math.floor(before.w / 2) + 90; x++) {
+ const p = before.px(x, y), q = after.px(x, y);
+ const delta = Math.max(...p.map((v, i) => Math.abs(v - q[i])));
+ if (delta > 8) changed++;
+ error += p.reduce((n, v, i) => n + Math.abs(v - q[i]), 0); pixels++;
+ }
+ }
+ const result = { mode, changedFraction: changed / pixels, meanError: error / (pixels * 3) };
+ comparisons.push(result);
+ assert(result.changedFraction < 0.01 && result.meanError < 1, 'Flat 2D widget differs from pre-RM-117 baseline: ' + JSON.stringify(result));
+ }
+ fs.writeFileSync(path.join(out, 'checks.json'), JSON.stringify({ status: 'checks-passed', baselineRoot, baseline, original, records, comparisons }, null, 2));
+ console.log('Legacy Hello World: move, rotate and scale widgets match the pre-RM-117 2D editor.');
+} finally {
+ if (git(['rev-parse', 'HEAD'], desktop).toString().trim() !== original) build(original);
+ if (!project.startsWith(out + path.sep)) throw Error('Unexpected cleanup path');
+ fs.rmSync(project, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });
+}
diff --git a/tools/verify-gizmo-occlusion.mjs b/tools/verify-gizmo-occlusion.mjs
index f58ae222b..c75885991 100644
--- a/tools/verify-gizmo-occlusion.mjs
+++ b/tools/verify-gizmo-occlusion.mjs
@@ -22,9 +22,9 @@ fs.writeFileSync(path.join(project, 'assets/scenes/main.esscene'), JSON.stringif
{ id: 1, name: 'Pivot inside blocker', parent: null, children: [], visible: true,
components: [{ type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } }] },
{ id: 2, name: 'Opaque blocker', parent: null, children: [], visible: true, components: [
- { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 }, scale: { x: 200, y: 200, z: 200 } } },
+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 }, scale: { x: 2, y: 2, z: 2 } } },
{ type: 'MeshRenderer', data: { mesh: 'builtin:cube', lit: false, opaque: true,
- color: { r: 0.22, g: 0.22, b: 0.22, a: 1 } } },
+ color: { r: 0.4, g: 0.4, b: 0.4, a: 1 } } },
] },
],
}));
@@ -55,7 +55,8 @@ try {
e.surface.select(1);e.runCommand('tool.rotate');await wait(300);
const g=e.gizmoLayout(),r=document.querySelector('.viewport__stage canvas').getBoundingClientRect();
if(!g?.spatial)throw Error('Missing spatial handles');
- return {layout:g,rect:{x:r.x,y:r.y},dpr:window.devicePixelRatio,saved};
+ return {layout:g,rect:{x:r.x,y:r.y},dpr:window.devicePixelRatio,saved,view:e.editorView(),
+ blocker:e.surface.serializeScene().entities.find(v=>v.id===2)};
})()`,
} });
fs.writeFileSync(path.join(out, name + '.log'), run.stdout + '\n' + run.stderr);