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): the eye's own point is not in front of it
yhh171d5edce79d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5f091d9fd..60bfd09c6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -141,6 +141,19 @@ published separately; it ships inside the editor.### Fixed+- **The 3D view head-on no longer paints the frame flat.** A perspective view+ authors on the ground, and an editor eye at y = 0 stands IN it. Every pixel's+ ray then meets that plane at t = 0 — at the eye's own point — and `step(0.0, t)`+ counted the eye as a hit in front of itself. One point's grid coordinate landed+ on every pixel, `fwidth` of it was zero, every coverage and legibility term+ saturated, and the whole viewport came back washed in the axis colour. Two+ buttons reach it: **3D View**, then **Face Scene Head-On**.++ The eye's own point is not in front of the eye. A plane through it has no+ picture — zero thickness, seen edge-on — so the grid draws nothing there, which+ is what gate `editor-grid-edge-on` asserts on both backends: the same view,+ grid on and grid off, has to come back the same frame to the pixel.+- **Whether a surface has normals no longer decides where its light is.** Twofacts had one switch: `MESH_NORMALS` said "this geometry carries a normalchannel", and the injected lighting read it as "so measure the light in threediff --git a/build-tools/toolchain/setup-emsdk.js b/build-tools/toolchain/setup-emsdk.jsindex 33d24b687..7685560ce 100644--- a/build-tools/toolchain/setup-emsdk.js+++ b/build-tools/toolchain/setup-emsdk.js@@ -49,10 +49,11 @@ function main() {process.exit(1);}- // tools/emsdk/emsdk (POSIX) or tools/emsdk/emsdk.bat (Windows). With shell:true- // on Windows, the bare name resolves to emsdk.bat from EMSDK_DIR.+ // The path is spelled out on both platforms: cmd searches the working+ // directory for a bare name only where NoDefaultCurrentDirectoryInExePath is+ // unset. Quoted because a .bat needs a shell, which concatenates its args.const emsdkCmd = process.platform === 'win32'- ? 'emsdk.bat'+ ? `"${path.join(EMSDK_DIR, 'emsdk.bat')}"`: path.join(EMSDK_DIR, 'emsdk');run(emsdkCmd, ['install', EMSCRIPTEN_VERSION]);diff --git a/desktop/scripts/headless-verify.mjs b/desktop/scripts/headless-verify.mjsindex 93063d9e2..54eaa5509 100644--- a/desktop/scripts/headless-verify.mjs+++ b/desktop/scripts/headless-verify.mjs@@ -18,6 +18,7 @@* ESTELLA_VERIFY_W / _H capture size (default 640×480)* ESTELLA_VERIFY_STEPS fixed-dt frames to advance before capture (default 30)* ESTELLA_VERIFY_GRID editor-grid on/off pixel-diff assertion (value = spacing)+ * ESTELLA_VERIFY_GRID_EXPECT what that diff must be: "frame" (default) or "nothing"* ESTELLA_VERIFY_DEPTH_LAYERS bitmask of layers resolved by depth (2.5D)* ESTELLA_VERIFY_PREFAB .esprefab instantiated into the scene after load* ESTELLA_VERIFY_SET_FIELD one inspector field written after load (JSON)@@ -582,6 +583,13 @@ app.whenReady().then(async () => {let grid = null;if (process.env.ESTELLA_VERIFY_GRID) {const spacing = Number(process.env.ESTELLA_VERIFY_GRID) || 64;+ // What the grid owes this view. A plane the eye lies IN is edge-on through+ // the eye's own point: it has no picture, and "none" is the answer rather+ // than a frame nobody can read.+ const wantGrid = process.env.ESTELLA_VERIFY_GRID_EXPECT ?? 'frame';+ if (wantGrid !== 'frame' && wantGrid !== 'nothing') {+ throw new Error(`ESTELLA_VERIFY_GRID_EXPECT is "frame" or "nothing", not "${wantGrid}"`);+ }await exec(`window.__estellaHeadless.api.setGrid(true, ${spacing})`);await exec('window.__estellaHeadless.api.step(2, 1 / 60)');// Optional PNG of the grid-on frame (ESTELLA_VERIFY_GRID_OUT) for eyeballing.@@ -615,7 +623,12 @@ app.whenReady().then(async () => {}// A grid is there everywhere you look, so every quarter of the frame has// some of it. A plane seen edge-on lights one band and passes a total.- return { differingPixels: differing, quadrants, ok: differing > 300 && quadrants.every((q) => q > 20) };+ const covers = differing > 300 && quadrants.every((q) => q > 20);+ const want = ${JSON.stringify(wantGrid)};+ return {+ differingPixels: differing, quadrants, want,+ ok: want === 'nothing' ? differing === 0 : covers,+ };`);}finish({ ok: true, entityCount, drawCalls, draws, capture, expect, resize, preview, meshPreview, grid, deviceLoss, meshResident, meshAsset, meshMaterial, meshPrefab, setField, pick }, server);diff --git a/sdk/src/camera/editorGridRenderer.ts b/sdk/src/camera/editorGridRenderer.tsindex ddba87aa5..31d322b35 100644--- a/sdk/src/camera/editorGridRenderer.ts+++ b/sdk/src/camera/editorGridRenderer.ts@@ -114,8 +114,10 @@ void main() {vec2 p = vec2(dot(hit, u_planeU.xyz), dot(hit, u_planeV.xyz));vec2 wpp = fwidth(p);- // Orthographic sees the plane on both sides of the eye; perspective only in front.- float inFront = max(step(0.0, t), 1.0 - u_rayForward.w);+ // Orthographic sees the plane on both sides of the eye; perspective only in+ // front of it, and the eye's OWN point is not in front. An eye lying IN the+ // plane meets it at t = 0 on every ray: one point's coordinate on every pixel.+ float inFront = max(t > 0.0 ? 1.0 : 0.0, 1.0 - u_rayForward.w);float sp = u_gridParams.x;float major = sp * u_gridParams.y;@@ -194,7 +196,7 @@ fn over(top : vec4f, bot : vec4f) -> vec4f {let p = vec2f(dot(hit, mc.u_planeU.xyz), dot(hit, mc.u_planeV.xyz));let wpp = fwidth(p);- let inFront = max(step(0.0, t), 1.0 - mc.u_rayForward.w);+ let inFront = max(select(0.0, 1.0, t > 0.0), 1.0 - mc.u_rayForward.w);let sp = mc.u_gridParams.x;let major = sp * mc.u_gridParams.y;diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjsindex 1d70c5d17..c64397907 100644--- a/tools/renderScenes.mjs+++ b/tools/renderScenes.mjs@@ -48,6 +48,10 @@ export const SCENES = [{ id: "editor-grid", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_STEPS: "3" } },// The same grid from straight above a 3D view. It stands on the ground there, so it fills the frame; the 2D plane would be edge-on and light one band.{ id: "editor-grid-3d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-instanced.esscene", ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_PERSPECTIVE: "1", ESTELLA_VERIFY_ORBIT: "0,90", ESTELLA_VERIFY_STEPS: "3" } },+ // The same 3D view head-on, where the eye stands IN the ground it works on: the+ // plane is edge-on through the eye's own point, so it has no picture at all.+ // Counting that hit paints one point's grid coordinate over the whole frame.+ { id: "editor-grid-edge-on", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh-instanced.esscene", ESTELLA_VERIFY_GRID: "64", ESTELLA_VERIFY_GRID_EXPECT: "nothing", ESTELLA_VERIFY_PERSPECTIVE: "1", ESTELLA_VERIFY_ORBIT: "0,0", ESTELLA_VERIFY_STEPS: "3" } },{ id: "mesh2d", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mesh2d.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh2d.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.30,\"y\":0.40,\"rgb\":[255,0,0],\"tol\":40}]" } },{ id: "parallax-shape", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/parallax-shape.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/parallax-shape.textures.json", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.25,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40}]" } },{ id: "tilemap-flip", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/tilemap-flip.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/tilemap-flip.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.40,\"y\":0.36,\"rgb\":[255,0,0]},{\"x\":0.60,\"y\":0.36,\"rgb\":[0,255,0]},{\"x\":0.40,\"y\":0.58,\"rgb\":[0,0,255]},{\"x\":0.60,\"y\":0.58,\"rgb\":[255,255,0]}]" } },