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 viewport draws textures compressed, as a build ships them
esengine6dda9cdd4082
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e3c3dbe9..299b746b8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,8 @@ published separately; it ships inside the editor.### Fixed+- **A large project opens in minutes, not half an hour.** The editor uploaded every texture as decoded pixels. ORCA Bistro's 224 2K textures came to 4.7 GiB of video memory, past what an 8 GB card had free, so Windows paged them in and out while the GPU sat idle. One frame stalled for up to 25 minutes, and Chromium's GPU watchdog then restarted the GPU process and the whole load began again. The editor, and the play realm beside it, now draw textures GPU-compressed, as a build does: the same KTX2, from the same cook cache, so the editor pays nothing for art an export already compressed and an export after an editing session encodes nothing. A texture the cache does not hold yet is drawn from a preview no larger than 1024 while it compresses in the background, then reloaded, and the editor does not report idle until it is. Textures with Compress off stay as they are. The editor keeps the KTX2 even where a build ships the PNG because the file is smaller: in a viewport, video memory is the cost. Bistro now opens with a cold GPU cache in about two minutes, where it took 20 to 36.+- **`bake-scene` refuses a scene made of prefab instances instead of crashing on it.** It cannot expand an instance, so it found nothing to bake and then threw on the instance entity; it now says to bake such a scene in the editor, as it already did for parented entities.- **An environment is no longer mirrored.** A panorama was read with its left and right swapped, so a camera facing its centre saw what the photographer saw on the left on its right — in the sky, in reflections and in the light the environment casts. ORCA Bistro's HDRI put its sun on the wrong side of the street. The sky, reflections and irradiance now read a panorama as it was shot, through one mapping, and a gate draws a panorama that is red left of its centre and blue right of it. Reimport a `.hdr` to pick it up; a scene that was turned to suit the mirror needs its `environmentRotation` set again.diff --git a/desktop b/desktopindex 969a0fae8..50461b1d7 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 969a0fae843b68ddb54b5634dd9882111a2ab476+Subproject commit 50461b1d7d74ccad839cbfc0e00d7e7916280e61diff --git a/sdk/etc/dragonbones.api.md b/sdk/etc/dragonbones.api.mdindex 150f1a0c9..d7e636faa 100644--- a/sdk/etc/dragonbones.api.md+++ b/sdk/etc/dragonbones.api.md@@ -138,6 +138,7 @@ update: (instanceId: number, dt: number) => void## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 32805dd4f..9193776f6 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -4574,6 +4574,7 @@ spacing: number## LightStatus — interface @experimental```accepted: boolean+environmentSunAim: [number, number, number] | nulllimit: numberrefusal: "none" | "capacity" | "no-environment-sun"refusedCount: number@@ -6003,6 +6004,7 @@ assetPathMap: Record<string, string> | undefinedaudioConfig: AudioProjectConfig | undefinedcanvas: HTMLCanvasElementcatalogData: CatalogData | null | undefined+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefinedenableStats: boolean | undefinedentrySceneName: string | undefinedextraScenes: { name: string; data?: SceneData; path?: string; }[] | undefined@@ -6890,6 +6892,7 @@ rotation: Quat## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex bdf22cf26..cfa2118e9 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -4582,6 +4582,7 @@ spacing: number## LightStatus — interface @experimental```accepted: boolean+environmentSunAim: [number, number, number] | nulllimit: numberrefusal: "none" | "capacity" | "no-environment-sun"refusedCount: number@@ -6194,6 +6195,7 @@ assetPathMap: Record<string, string> | undefinedaudioConfig: AudioProjectConfig | undefinedcanvas: HTMLCanvasElementcatalogData: CatalogData | null | undefined+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefinedenableStats: boolean | undefinedentrySceneName: string | undefinedextraScenes: { name: string; data?: SceneData; path?: string; }[] | undefined@@ -7091,6 +7093,7 @@ rotation: Quat## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex f1e128497..eaf0b2974 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -4569,6 +4569,7 @@ spacing: number## LightStatus — interface @experimental```accepted: boolean+environmentSunAim: [number, number, number] | nulllimit: numberrefusal: "none" | "capacity" | "no-environment-sun"refusedCount: number@@ -5998,6 +5999,7 @@ assetPathMap: Record<string, string> | undefinedaudioConfig: AudioProjectConfig | undefinedcanvas: HTMLCanvasElementcatalogData: CatalogData | null | undefined+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefinedenableStats: boolean | undefinedentrySceneName: string | undefinedextraScenes: { name: string; data?: SceneData; path?: string; }[] | undefined@@ -6885,6 +6887,7 @@ rotation: Quat## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 1e95a6e55..c43b50b8c 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -4569,6 +4569,7 @@ spacing: number## LightStatus — interface @experimental```accepted: boolean+environmentSunAim: [number, number, number] | nulllimit: numberrefusal: "none" | "capacity" | "no-environment-sun"refusedCount: number@@ -6268,6 +6269,7 @@ assetPathMap: Record<string, string> | undefinedaudioConfig: AudioProjectConfig | undefinedcanvas: HTMLCanvasElementcatalogData: CatalogData | null | undefined+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefinedenableStats: boolean | undefinedentrySceneName: string | undefinedextraScenes: { name: string; data?: SceneData; path?: string; }[] | undefined@@ -7155,6 +7157,7 @@ rotation: Quat## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/spine.api.md b/sdk/etc/spine.api.mdindex 730f97b88..20956097a 100644--- a/sdk/etc/spine.api.md+++ b/sdk/etc/spine.api.md@@ -27,6 +27,7 @@ spacing: number## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 7a9a32274..d93eab85e 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -4576,6 +4576,7 @@ spacing: number## LightStatus — interface @experimental```accepted: boolean+environmentSunAim: [number, number, number] | nulllimit: numberrefusal: "none" | "capacity" | "no-environment-sun"refusedCount: number@@ -6005,6 +6006,7 @@ assetPathMap: Record<string, string> | undefinedaudioConfig: AudioProjectConfig | undefinedcanvas: HTMLCanvasElementcatalogData: CatalogData | null | undefined+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefinedenableStats: boolean | undefinedentrySceneName: string | undefinedextraScenes: { name: string; data?: SceneData; path?: string; }[] | undefined@@ -6892,6 +6894,7 @@ rotation: Quat## RuntimeAssetSource — interface @experimental```backend: Backend+compressedTexture: ((path: string) => Promise<Uint8Array | "pending" | null>) | undefineddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefinedresolveAddress: ((ref: string) => string | null) | undefineddiff --git a/sdk/src/asset/loaders/TextureLoader.ts b/sdk/src/asset/loaders/TextureLoader.tsindex dad8fad9a..44ca1b8ce 100644--- a/sdk/src/asset/loaders/TextureLoader.ts+++ b/sdk/src/asset/loaders/TextureLoader.ts@@ -33,6 +33,17 @@ export type TexturePixelDecoder = (flip: boolean,) => Promise<{ width: number; height: number; pixels: Uint8Array }>;+/**+ * Where a host keeps its textures GPU-compressed: the KTX2 for `path`, `'pending'`+ * while it is being made, or null for one that is not. A pending texture is drawn+ * from a preview no larger than {@link TEXTURE_PREVIEW_EDGE}, so art still being+ * compressed is not held in video memory in full.+ */+export type TextureCompressedSource = (path: string) => Promise<Uint8Array | 'pending' | null>;++/** The longest edge a texture waiting for its compressed form is drawn at. */+export const TEXTURE_PREVIEW_EDGE = 1024;+/*** Texture import-time settings. Applied when the GL texture is first uploaded,* because WebGL sampler state lives on the texture object — the only way to@@ -140,6 +151,10 @@ export class TextureLoader implements AssetLoader<TextureResult> {setPixelDecoder(decoder: TexturePixelDecoder | null): void { this.pixelDecoder_ = decoder; }get pixelDecoder(): TexturePixelDecoder | null { return this.pixelDecoder_; }+ /** Compressed-texture source (see {@link TextureCompressedSource}). */+ private compressedSource_: TextureCompressedSource | null = null;+ setCompressedSource(source: TextureCompressedSource | null): void { this.compressedSource_ = source; }+async load(path: string, ctx: LoadContext): Promise<TextureResult> {const settings = this.pendingSettings_;this.pendingSettings_ = undefined;@@ -214,7 +229,14 @@ export class TextureLoader implements AssetLoader<TextureResult> {): Promise<TextureResult> {this.lastDecision_ = RAW_PAYLOAD_UPLOAD;if (isKtx2Path(path)) {- return this.loadCompressed(path, ctx, settings);+ const buf = await ctx.backend.fetchBinary(ctx.catalog.getBuildPath(path));+ return this.uploadKtx2_(path, new Uint8Array(buf), settings);+ }+ let preview = false;+ if (this.compressedSource_) {+ const compressed = await this.compressedSource_(path);+ if (compressed instanceof Uint8Array) return this.uploadKtx2_(path, compressed, settings);+ preview = compressed === 'pending';}// A platform pixel decoder (runtime scene loader) pre-decodes to RGBA and// uploads through the shared createTexture path — the same code the old@@ -225,20 +247,18 @@ export class TextureLoader implements AssetLoader<TextureResult> {return { handle, width: result.width, height: result.height };}const url = ctx.backend.resolveUrl(ctx.catalog.getBuildPath(path));- const img = await this.loadImage(url, flip);+ const img = await this.loadImage(url, flip, preview ? TEXTURE_PREVIEW_EDGE : 0);return this.createTextureFromImage(img, flip, settings);}/**- * Load a KTX2 (Basis) compressed texture: fetch the container, transcode to a- * device-supported GPU format (or RGBA8 fallback), and upload. KTX2 carries its- * own orientation, so the `flip` flag does not apply.+ * Upload a KTX2 (Basis) compressed texture: transcode to a device-supported GPU+ * format (or RGBA8 fallback), and upload. KTX2 carries its own orientation, so+ * the `flip` flag does not apply.*/- private async loadCompressed(- path: string, ctx: LoadContext, settings?: TextureImportSettings,+ private async uploadKtx2_(+ path: string, bytes: Uint8Array, settings?: TextureImportSettings,): Promise<TextureResult> {- const buf = await ctx.backend.fetchBinary(ctx.catalog.getBuildPath(path));- const bytes = new Uint8Array(buf);if (!isKtx2(bytes)) throw new Error(`TextureLoader: ${path} is not a KTX2 file`);// Native (embedded Dawn): the ResourceManager transcodes the KTX2 with the// host's basis library and uploads the compressed blocks — no WebGL2, no@@ -324,14 +344,27 @@ export class TextureLoader implements AssetLoader<TextureResult> {* on it uploads every texture upside-down. The raw `<img>` fallback keeps the* flag (it works for element/pixel sources) — see {@link createTextureFromImage}.*/- private loadImage(src: string, flip: boolean): Promise<PlatformImage | ImageBitmap> {+ private loadImage(src: string, flip: boolean, maxEdge = 0): Promise<PlatformImage | ImageBitmap> {return new Promise((resolve, reject) => {const img = platformCreateImage();img.crossOrigin = 'anonymous';img.onload = async () => {if (typeof createImageBitmap !== 'undefined') {try {- resolve(await decodeImageBitmap(img, flip));+ const bitmap = await decodeImageBitmap(img, flip);+ const longest = Math.max(bitmap.width, bitmap.height);+ if (maxEdge > 0 && longest > maxEdge) {+ const k = maxEdge / longest;+ const smaller = await createImageBitmap(bitmap, {+ resizeWidth: Math.max(1, Math.round(bitmap.width * k)),+ resizeHeight: Math.max(1, Math.round(bitmap.height * k)),+ resizeQuality: 'high',+ });+ bitmap.close();+ resolve(smaller);+ return;+ }+ resolve(bitmap);return;} catch {// fallbackdiff --git a/sdk/src/runtime/playRealmRuntime.ts b/sdk/src/runtime/playRealmRuntime.tsindex 527420ecc..b2c6df647 100644--- a/sdk/src/runtime/playRealmRuntime.ts+++ b/sdk/src/runtime/playRealmRuntime.ts@@ -40,6 +40,8 @@ export interface PlayRealmRuntimeConfig {canvas: HTMLCanvasElement;/** The current scene as RAW (`@uuid:`) SceneData — handles are realm-local. */sceneData: SceneData;+ /** Where the host keeps this realm's textures compressed (RuntimeAssetSource). */+ compressedTexture?: RuntimeAssetSource['compressedTexture'];/** Additional switchable scenes beyond the entry (SceneManager targets).* `path` entries load lazily through the runtime Assets on first switch. */extraScenes?: Array<{ name: string; data?: SceneData; path?: string }>;@@ -161,10 +163,12 @@ function createPlayRealmSource(assetBaseUrl?: string,pathMap?: Record<string, string>,addressable?: AddressableManifest | null,+ compressedTexture?: RuntimeAssetSource['compressedTexture'],): RuntimeAssetSource {const backend = new HttpBackend({ baseUrl: '' });return {backend,+ ...(compressedTexture ? { compressedTexture } : {}),decodePixels: (path) => fetchDecodePixels(backend.resolveUrl(path)),resolveRef: (ref) => resolvePlayAssetRef(ref, manifest, assetBaseUrl, pathMap),// Cooked builds: logical paths (the pathMap keys). Editor play: the@@ -218,7 +222,8 @@ export async function cutPlayWorld(*/export async function initPlayRealmRuntime(config: PlayRealmRuntimeConfig): Promise<void> {const { app, module, canvas, sceneData, assetManifest, assetBaseUrl } = config;- const source = createPlayRealmSource(assetManifest, assetBaseUrl, config.assetPathMap, config.manifest);+ const source = createPlayRealmSource(assetManifest, assetBaseUrl, config.assetPathMap, config.manifest,+ config.compressedTexture);applyAssetRefResolvers(app, (ref) => resolvePlayAssetRef(ref, assetManifest, assetBaseUrl, config.assetPathMap));const entryName = config.entrySceneName ?? '__play';const cut = await cutPlayWorld(diff --git a/sdk/src/runtime/runtimeAssets.ts b/sdk/src/runtime/runtimeAssets.tsindex c34ac4bea..38634986b 100644--- a/sdk/src/runtime/runtimeAssets.ts+++ b/sdk/src/runtime/runtimeAssets.ts@@ -42,6 +42,12 @@ export interface RuntimeAssetSource {* to recover, and a caller falls back to the resolved path.*/resolveAddress?(ref: string): string | null;+ /**+ * A texture as its host keeps it GPU-compressed (TextureLoader's+ * `TextureCompressedSource`). The editor's play realm supplies it, so the+ * running game holds the art compressed as the edit viewport does.+ */+ compressedTexture?(path: string): Promise<Uint8Array | 'pending' | null>;/*** Every asset path this realm ships (logical, extension-bearing). Powers* content-driven discovery of assets NO scene references — locale stringdiff --git a/sdk/src/runtime/runtimeLoader.ts b/sdk/src/runtime/runtimeLoader.tsindex 80634f68b..9b7b98a90 100644--- a/sdk/src/runtime/runtimeLoader.ts+++ b/sdk/src/runtime/runtimeLoader.ts@@ -116,6 +116,7 @@ function ensureRuntimeAssets(const loader = assets.getTextureLoader();loader.setPixelDecoder((path, flip) => source.decodePixels(path, flip));+ if (source.compressedTexture) loader.setCompressedSource((path) => source.compressedTexture!(path));// KTX2 transcoder, self-gated off app.sideModules — identical wiring to// AssetPlugin.build so eager + on-demand loads transcode the same way.loader.setTranscoderProvider(() => basisTranscoderFor(app.sideModules));diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex c954fdc62..e6aaa6146 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -1304,6 +1304,10 @@ export const NOTED = {{ note: 'A directional light can be the environment\'s sun' },'fix(bake-scene): a scene of prefab instances is refused, not crashed on':{ note: '`bake-scene` refuses a scene made of prefab instances instead of crashing on it' },+ 'fix(editor): the viewport draws textures compressed, as a build ships them':+ { note: 'A large project opens in minutes, not half an hour' },+ 'refactor(assets): one texture cook for a build and the editor':+ { note: 'A large project opens in minutes, not half an hour' },'fix(bake): a coloured light bakes the colour it lights with':{ note: 'A coloured light bakes the colour it lights with' },'fix(bake): the collector reads the colour space from the engine host':