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
refactor(pipeline): the PNG encoder gets its own file
esengine6f5baf0723a5
diff --git a/pipeline/src/assets/environmentImport.ts b/pipeline/src/assets/environmentImport.tsindex 07f388584..e7b524679 100644--- a/pipeline/src/assets/environmentImport.ts+++ b/pipeline/src/assets/environmentImport.ts@@ -11,7 +11,7 @@* at all — and the specular half one ordinary RGBA8 image, so nothing* downstream learns a cube map or a float format.*/-import { PNG } from 'pngjs';+import { encodeRgbaPng } from './png';/** A panorama in linear light: equirectangular, row 0 = up (+Y). */export interface Panorama {@@ -428,13 +428,6 @@ export function prefilterOctahedral(env: Panorama, faceSize = ENV_FACE_SIZE,return { width, height, rgba };}-/** Encode raw RGBA8 (row 0 = top) as PNG bytes. */-export function encodeAtlasPng(width: number, height: number, rgba: Uint8Array): Uint8Array {- const png = new PNG({ width, height });- png.data = Buffer.from(rgba);- return new Uint8Array(PNG.sync.write(png));-}-/** Everything a `.hdr` becomes, less the reference the caller has to resolve. */export interface ImportedEnvironment {/** `<stem>_env.png` — the octahedral atlas. */@@ -468,7 +461,7 @@ export function importEnvironment(bytes: Uint8Array, stem: string,const atlas = prefilterOctahedral(panorama, faceSize, mipCount, ENV_MAX_RANGE);return {atlasName: `${stem}_env.png`,- atlasBytes: encodeAtlasPng(atlas.width, atlas.height, atlas.rgba),+ atlasBytes: encodeRgbaPng(atlas.width, atlas.height, atlas.rgba),warnings,document: {version: ENVIRONMENT_FORMAT_VERSION,diff --git a/pipeline/src/assets/png.ts b/pipeline/src/assets/png.tsnew file mode 100644index 000000000..186b56bc4--- /dev/null+++ b/pipeline/src/assets/png.ts@@ -0,0 +1,18 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file png.ts+ * @brief Raw pixels to PNG bytes, for the imports that compute an image.+ *+ * Its own file because two unrelated bakes need it — an environment's atlas and+ * a lightmap's — and the second reaching into the first for it is how a third+ * copy gets written.+ */+import { PNG } from 'pngjs';++/** Encode raw RGBA8 (row 0 = top) as PNG bytes. */+export function encodeRgbaPng(width: number, height: number, rgba: Uint8Array): Uint8Array {+ const png = new PNG({ width, height });+ png.data = Buffer.from(rgba);+ return new Uint8Array(PNG.sync.write(png));+}