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.

fix(pipeline): the cook's size rule stands away from the cook's decoder

esengineee5c997d936b
diff --git a/desktop b/desktop
index d509e08e9..3f7a7374d 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit d509e08e9be9add3a5234972685f925dc1c140ca
+Subproject commit 3f7a7374d29d76ad545d107e0b2f9f8f749d10b4
diff --git a/pipeline/src/assets/atlasPacker.ts b/pipeline/src/assets/atlasPacker.ts
index b061a4281..6d2e1fe91 100644
--- a/pipeline/src/assets/atlasPacker.ts
+++ b/pipeline/src/assets/atlasPacker.ts
@@ -12,6 +12,7 @@
*/
import { PNG } from 'pngjs';
import { ShelfPacker } from '../../../sdk/src/util/shelfPack';
+import { downscaledSize } from './textureCookDecision';
export interface AtlasInputImage {
/** Stable identity (the project-relative texture path). */
@@ -180,18 +181,6 @@ export function encodePagePng(page: AtlasPage): Uint8Array {
* to a texture needs this number rather than the source's — from the same
* arithmetic the resize uses, or the prediction is right until a rounding case.
*/
-export function downscaledSize(
- width: number, height: number, maxDim: number,
-): { width: number; height: number } {
- const longest = Math.max(width, height);
- if (!(maxDim > 0) || longest <= maxDim) return { width, height };
- const scale = maxDim / longest;
- return {
- width: Math.max(1, Math.round(width * scale)),
- height: Math.max(1, Math.round(height * scale)),
- };
-}
-
export function downscaleRgba(img: AtlasInputImage, maxDim: number): AtlasInputImage {
const longest = Math.max(img.width, img.height);
if (!(maxDim > 0) || longest <= maxDim) return img;
diff --git a/pipeline/src/assets/textureCookDecision.ts b/pipeline/src/assets/textureCookDecision.ts
index 777a449ee..885219e27 100644
--- a/pipeline/src/assets/textureCookDecision.ts
+++ b/pipeline/src/assets/textureCookDecision.ts
@@ -16,6 +16,25 @@
* what an inspector predicts are one function with one branch order.
*/
+/**
+ * What a source image becomes under the import's `maxSize` — the size every
+ * later decision is about, block alignment included.
+ *
+ * Here rather than beside the packer that downsamples: reading it must not cost
+ * a PNG decoder, which reached the renderer as a `require('util')` that throws.
+ */
+export function downscaledSize(
+ width: number, height: number, maxDim: number,
+): { width: number; height: number } {
+ const longest = Math.max(width, height);
+ if (!(maxDim > 0) || longest <= maxDim) return { width, height };
+ const scale = maxDim / longest;
+ return {
+ width: Math.max(1, Math.round(width * scale)),
+ height: Math.max(1, Math.round(height * scale)),
+ };
+}
+
/** The Basis encoding modes a cooked KTX2 can be written in. */
export type TextureCookFormat = 'uastc' | 'etc1s';