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
fix(editor): an environment assigned in the editor reaches the viewport
esengineaa1181e7e28a
diff --git a/desktop/scripts/editor-checks/panorama-import.mjs b/desktop/scripts/editor-checks/panorama-import.mjsindex 1215df52f..1806caf84 100644--- a/desktop/scripts/editor-checks/panorama-import.mjs+++ b/desktop/scripts/editor-checks/panorama-import.mjs@@ -12,7 +12,7 @@*/import { mkdir, readFile, writeFile } from 'node:fs/promises';import path from 'node:path';-import { makeProject, checker } from '../lib/editorDriver.mjs';+import { makeProject, checker, readPNG } from '../lib/editorDriver.mjs';export const name = 'panorama-import';export const describes = 'an imported panorama writes its environment and the atlas it names';@@ -40,15 +40,48 @@ function panoramaHdr(width = 32, height = 16) {export async function run(ed) {const root = await makeProject({'project.esproject': JSON.stringify({ name: 'Panorama', version: '1.0' }, null, 2),+ 'assets/lit.esmaterial': JSON.stringify({+ version: '1.0', type: 'material', shader: 'builtin:sprite-lit', blendMode: 0,+ depthTest: false, properties: {},+ }, null, 2),'assets/scenes/main.esscene': JSON.stringify({version: '1.0', name: 'Main',- entities: [{- id: 0, name: 'Camera', parent: null, children: [], visible: true,- components: [- { type: 'Transform', data: { position: { x: 0, y: 0, z: 10 } } },- { type: 'Camera', data: { projectionType: 1, orthoSize: 300, isActive: true, priority: 0 } },- ],- }],+ entities: [+ {+ id: 0, name: 'Camera', parent: null, children: [], visible: true,+ components: [+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 10 } } },+ { type: 'Camera', data: { projectionType: 1, orthoSize: 300, isActive: true, priority: 0 } },+ ],+ },+ {+ id: 1, name: 'Sky', parent: null, children: [], visible: true,+ components: [+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } },+ {+ type: 'Light2D',+ data: {+ type: 2, intensity: 1,+ color: { r: 1, g: 1, b: 1, a: 1 },+ },+ },+ ],+ },+ {+ id: 2, name: 'Wall', parent: null, children: [], visible: true,+ components: [+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 0 } } },+ {+ type: 'Sprite',+ data: {+ size: { x: 400, y: 400 },+ color: { r: 1, g: 1, b: 1, a: 1 },+ material: 'assets/lit.esmaterial',+ },+ },+ ],+ },+ ],}, null, 1),});await mkdir(path.join(root, 'assets'), { recursive: true });@@ -56,7 +89,9 @@ export async function run(ed) {await writeFile(source, panoramaHdr());const check = checker();- await ed.open(root, 'assets/scenes/main.esscene');+ // The project first, the scene AFTER the import: a scene opened before its+ // assets exist resolves their refs to nothing, and no later write revisits that.+ await ed.open(root);const result = await ed.json('import_assets', { destDir: 'assets', sources: [source] }, 120000);const imported = result?.imported ?? [];if (!check(imported.includes('assets/sky.esenv') && imported.includes('assets/sky_env.png'),@@ -75,7 +110,7 @@ export async function run(ed) {if (!check(env != null, 'the environment is named in the import but is not on disk')) {return check.failures;}- check(env.specular === 'assets/sky_env.png',+ check(env.specular === 'sky_env.png',`the environment points at ${JSON.stringify(env.specular)}`);check(Array.isArray(env.irradiance) && env.irradiance.length === 27,`the irradiance is ${env.irradiance?.length} numbers, not 27`);@@ -87,5 +122,29 @@ export async function run(ed) {const meta = await read('assets/sky_env.png.meta');check(meta?.importer?.sRGB === false, 'the atlas is marked sRGB, but it stores an encoding');check(meta?.importer?.compress === false, 'the atlas would be block-compressed with its own multiplier');++ await ed.call('open_scene', { path: 'assets/scenes/main.esscene' }, 120000);+ await ed.sleep(2500);++ // The editor's OWN door: assigning the `.esenv` to a light has to resolve it to+ // a handle and reach the viewport. A flat ambient draws the wall white; the sky+ // draws it in its own colour, which has no green in it at all.+ await ed.sleep(600);+ const viewport = async () => {+ const block = await ed.call('capture_viewport', {}, 60000);+ return readPNG(Buffer.from(block.data ?? '', 'base64'));+ };+ const flat = await viewport();+ await ed.call('set_field', { entity: 1, component: 'Light2D', key: 'environment',+ type: 'asset', value: 'assets/sky.esenv' }, 30000);+ await ed.sleep(1500);+ const lit = await viewport();+ const at = (shot) => shot.px(Math.round(shot.w * 0.5), Math.round(shot.h * 0.5));+ const before = at(flat);+ const after = at(lit);+ check(before[0] > 200 && before[1] > 200 && before[2] > 200,+ `a flat white ambient drew the wall ${JSON.stringify(before)}`);+ check(after[1] + 20 < after[0] && after[1] + 20 < after[2],+ `with the environment the wall is ${JSON.stringify(after)} — a sky with no green in it`);return check.failures;}diff --git a/desktop/src/engine/AssetBinding.ts b/desktop/src/engine/AssetBinding.tsindex 87a844c5e..aabaeb927 100644--- a/desktop/src/engine/AssetBinding.ts+++ b/desktop/src/engine/AssetBinding.ts@@ -53,7 +53,7 @@ class AssetBindingImpl {const r = this.preload;if (!path || !r) return 0;return r.materialHandles.get(path) ?? r.fontHandles.get(path)- ?? r.meshHandles.get(path) ?? 0;+ ?? r.meshHandles.get(path) ?? r.environmentHandles.get(path) ?? 0;}/** The live material handle for @p path, or 0 — the Material Editor pushes