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.

feat(export): a web build ships a small copy of each texture a mesh draws, and streaming fetches the file only once a view needs more

yhhaf3a825744de
diff --git a/desktop b/desktop
index 3e715db86..8ad508783 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 3e715db868520fee34f0bc8a40b9c49895e07ce7
+Subproject commit 8ad508783d7d693a206bce6cd7b567ad93eedd74
diff --git a/docs/astro/src/content/docs/performance/quality-levels.mdx b/docs/astro/src/content/docs/performance/quality-levels.mdx
index 6f46a1ff5..1b671b98a 100644
--- a/docs/astro/src/content/docs/performance/quality-levels.mdx
+++ b/docs/astro/src/content/docs/performance/quality-levels.mdx
@@ -78,8 +78,24 @@ Measured in the editor's Play at Low, in the `texture-streaming` editor check (t
| `dusk-fort` | 285.6 MB | 33.6 MB | 31.0 MB | mean difference 0.28 of 255 |
| `bistro` | 1293.5 MB | 321.1 MB | 449.6 MB (228 textures, 149 moves) | mean difference 1.1 of 255; 0.04% of pixels differ visibly |
-What it does not do: it saves GPU memory, not the download, since a file is read whole the first time and again for each size it
-is moved to. Until a view has asked for more, a texture is drawn at the size it started at: the first second or two of a scene can
+**The download.** A web build ships a small copy beside each texture a mesh draws as its surface and that is more than 512 texels
+on a side: no larger than 256, in the same format (a KTX2 encoded again in its own mode, a PNG or a JPEG written as what it was),
+halved from the shipped file with the box filter the cook's own mip chains use. Streaming starts the texture from the copy, and
+fetches the file itself only once a view needs more than the copy holds; a texture nothing comes close to is never downloaded
+whole. Exported for the web at Low and run in a headless browser (software rendering, the files served as immutable):
+
+| Example | Texture download, without the copies | With the copies | Files fetched whole |
+|---|---|---|---|
+| `dusk-fort`, 20 s | 44.8 MB | 14.9 MB (the copies are 0.4 MB of it) | 3 of 12 |
+| `bistro`, 20 s | 35.3 MB | 16.1 MB (3.4 MB of copies) | 4 of 155 |
+| `bistro`, 120 s | — | 18.8 MB | 15 of 155 |
+
+A headless browser draws in software, a frame or two a second, so it grows textures far slower than a GPU does: `bistro` was still
+fetching a file every five seconds or so at two minutes, and these are what was downloaded by then, not what it settles at. The
+copies cost the package their own size (430 KB beside `dusk-fort`'s 42.6 MB of textures). A mini game downloads its package whole,
+so no copies are made for one; nor for a texture something other than a mesh draws.
+
+What it does not do: until a view has asked for more, a texture is drawn at the size it started at: the first second or two of a scene can
be softer than the rest, and a move costs a decode and an upload on the frame it lands, which shows as a frame or two of tens of
milliseconds while a scene settles. A texture a sprite, a UI element, a tilemap, a particle or a trail also draws is put back at its
size and left there. A KTX2 file is cut at a level without decoding; where the host transcodes KTX2 itself (the native builds) it
diff --git a/docs/astro/src/content/docs/zh-cn/performance/quality-levels.mdx b/docs/astro/src/content/docs/zh-cn/performance/quality-levels.mdx
index 5d1793043..88a48e661 100644
--- a/docs/astro/src/content/docs/zh-cn/performance/quality-levels.mdx
+++ b/docs/astro/src/content/docs/zh-cn/performance/quality-levels.mdx
@@ -55,7 +55,17 @@ import { Aside } from '@astrojs/starlight/components';
| `dusk-fort` | 285.6 MB | 33.6 MB | 31.0 MB | 平均差 0.28/255 |
| `bistro` | 1293.5 MB | 321.1 MB | 449.6 MB(228 张贴图,149 次缩放) | 平均差 1.1/255;0.04% 的像素有明显变化 |
-它做不到的:省的是显存,不是下载。文件第一次仍然完整读取,每换一次尺寸还要再读一次。在视图要求更大之前,贴图按起始尺寸绘制:场景开头的一两秒可能比之后模糊;一次缩放要在它落地的那一帧付出解码和上传,场景稳定之前会有一两帧几十毫秒。同时被精灵、UI、瓦片地图、粒子或拖尾使用的贴图会恢复原尺寸并保持不变。KTX2 文件直接从某一级截取,不用重新解码;宿主自己转码 KTX2 的平台(原生打包)做不到这一点,这类贴图保持原尺寸。
+**下载。** Web 构建会为每张被网格当表面使用、边长超过 512 纹素的贴图另存一份小副本:边长不超过 256,格式不变(KTX2 按原模式重新编码,PNG、JPEG 原样格式写出),从打包的文件用和构建自身 mip 链相同的盒式滤波缩小。流式加载先从小副本开始,只有视图需要的比副本大时才去下载原文件;没有任何东西靠近的贴图永远不会被完整下载。按低档导出 Web 版,在无头浏览器里运行(软件渲染,文件按 immutable 提供):
+
+| 示例 | 不带副本的贴图下载 | 带副本 | 被完整下载的文件 |
+|---|---|---|---|
+| `dusk-fort`,20 秒 | 44.8 MB | 14.9 MB(其中副本 0.4 MB) | 12 张中 3 张 |
+| `bistro`,20 秒 | 35.3 MB | 16.1 MB(其中副本 3.4 MB) | 155 张中 4 张 |
+| `bistro`,120 秒 | — | 18.8 MB | 155 张中 15 张 |
+
+无头浏览器用软件渲染,一秒一两帧,长大贴图比 GPU 慢得多:`bistro` 到两分钟时还在每五秒左右下载一张原文件,所以这些是到那时为止下载的量,不是最终稳定的量。副本本身会增加包体(`dusk-fort` 42.6 MB 贴图旁多出 430 KB)。小游戏是整包下载,不生成副本;被网格以外的东西使用的贴图也不生成。
+
+它做不到的:在视图要求更大之前,贴图按起始尺寸绘制:场景开头的一两秒可能比之后模糊;一次缩放要在它落地的那一帧付出解码和上传,场景稳定之前会有一两帧几十毫秒。同时被精灵、UI、瓦片地图、粒子或拖尾使用的贴图会恢复原尺寸并保持不变。KTX2 文件直接从某一级截取,不用重新解码;宿主自己转码 KTX2 的平台(原生打包)做不到这一点,这类贴图保持原尺寸。
## 去掉一些效果
diff --git a/pipeline/package.json b/pipeline/package.json
index e8fe4cdd5..80f630b37 100644
--- a/pipeline/package.json
+++ b/pipeline/package.json
@@ -19,6 +19,7 @@
"esbuild": "^0.27.0",
"esengine": "workspace:*",
"ffmpeg-static": "^5.3.0",
+ "jpeg-js": "0.4.4",
"js-yaml": "4.3.0",
"meshoptimizer": "^1.2.0",
"pngjs": "^7.0.0",
diff --git a/pipeline/src/assets/addressableManifest.ts b/pipeline/src/assets/addressableManifest.ts
index fdef6ab30..b75d145cd 100644
--- a/pipeline/src/assets/addressableManifest.ts
+++ b/pipeline/src/assets/addressableManifest.ts
@@ -27,6 +27,7 @@ interface FlatManifest {
uuid: string; path: string; sourcePath?: string; type: string;
contentHash?: string; size?: number; group?: string; groupMode?: string;
compressedFormats?: string[];
+ streamTail?: { path: string; size: number; width: number; height: number; fullWidth: number; fullHeight: number };
importer?: Record<string, unknown>;
atlas?: { page: number; frame: { x: number; y: number; width: number; height: number }; pageWidth: number; pageHeight: number };
pack?: { file: string; offset: number; size: number };
@@ -61,6 +62,7 @@ export async function buildAddressableManifest(absOut: string): Promise<string>
type Entry = {
path: string; address?: string; type: string; size: number; labels: string[]; contentHash?: string;
compressedFormats?: string[];
+ streamTail?: { path: string; size: number; width: number; height: number; fullWidth: number; fullHeight: number };
textureImport?: ParsedTextureImportSettings;
spineImport?: SpineManifestContract;
pack?: { file: string; offset: number; size: number };
@@ -92,6 +94,7 @@ export async function buildAddressableManifest(absOut: string): Promise<string>
// the addressable manifest — the flat one it came from is a build-time
// intermediate that no longer ships.
if (e.compressedFormats?.length) entry.compressedFormats = e.compressedFormats;
+ if (e.streamTail) entry.streamTail = e.streamTail;
// Parsed here, not shipped raw: the runtime needs how the texture is sampled
// and sliced, never the cook's own knobs (maxSize, compression format). This
// is the ONLY channel a packaged build has for the `.meta` — without it a
diff --git a/pipeline/src/assets/cookAssets.ts b/pipeline/src/assets/cookAssets.ts
index 215c32d57..5c0ff4986 100644
--- a/pipeline/src/assets/cookAssets.ts
+++ b/pipeline/src/assets/cookAssets.ts
@@ -51,6 +51,7 @@ import {
import { cookCached } from './cookCache';
import { cookTexture, loadTextureEncoder, pngDimensions, COMPRESSED_TARGETS, type BasisEncoderModule } from './textureCook';
import { meshTextureRoles } from './textureUsage';
+import { makeStreamTail, type StreamTail } from './streamTail';
const MANIFEST = 'assets.manifest.json';
@@ -81,6 +82,11 @@ export interface CookManifestEntry extends AssetEntry {
sourcePath: string;
/** GPU formats the staged KTX2 can transcode to, when the asset was compressed. */
compressedFormats?: string[];
+ /**
+ * The small copy of a texture a mesh draws (streamTail.ts), staged beside it: what texture streaming fetches first, so the full
+ * file is downloaded only once a view needs it. `width`/`height` are the copy's, `fullWidth`/`fullHeight` the file's.
+ */
+ streamTail?: { path: string; size: number; width: number; height: number; fullWidth: number; fullHeight: number };
/**
* What this build did to the texture's compression request, for images only.
*
@@ -487,6 +493,9 @@ export async function cookAssets(
* compressing any of it, and is answered before anything is encoded.
*/
textureDecoderBytes?: number;
+ /** Stage a small copy of each texture a mesh draws as its surface (streamTail.ts), for texture streaming to fetch first.
+ * Worth it where files are fetched as they are needed (the web); a package downloaded whole only grows. */
+ streamTails?: boolean;
},
): Promise<CookResult> {
const contentAddressed = opts.contentAddressed ?? false;
@@ -494,6 +503,7 @@ export async function cookAssets(
const compressAudio = opts.compressAudio ?? false;
const transcodeVideo = opts.transcodeVideo ?? false;
const platform = opts.platform;
+ const streamTails = opts.streamTails ?? false;
const { index } = await scanAssetDatabase(root, { write: false, adopt: false });
const warnings: string[] = [];
const failed: string[] = [];
@@ -758,6 +768,7 @@ export async function cookAssets(
? new Uint8Array(0)
: await readFile(path.join(root, entry.path));
let ext = path.extname(entry.path);
+ let tail: StreamTail | null = null;
let compressedFormats: string[] | undefined;
let cook: TextureCookDecision | undefined;
// An authored single-level UASTC KTX2 gets the chain a compressed texture
@@ -795,6 +806,14 @@ export async function cookAssets(
data = t.data; ext = t.ext; cook = t.cook; compressedFormats = t.compressedFormats;
warnings.push(...t.warnings);
if (t.defeatedByFormat) defeatedByFormat.push(entry.path);
+ // After the payload is decided, from its bytes: the copy is the picture that ships, in the format it ships in.
+ if (streamTails && roles.get(entry.uuid)?.has('surface')) {
+ try {
+ tail = await makeStreamTail(data, ext, readTextureCookSettings(entry.importer, platform).srgb, textureEnc);
+ } catch (err) {
+ warnings.push(`${entry.path}: no small copy for streaming — ${err instanceof Error ? err.message : String(err)}`);
+ }
+ }
}
// WAV sources re-encode to MP3 (universal decode); other audio formats are
// already compressed and pass through. Hash + name reflect the ENCODED bytes.
@@ -911,6 +930,15 @@ export async function cookAssets(
await mkdir(path.dirname(dst), { recursive: true });
await writeFile(dst, data);
}
+ let streamTail: CookManifestEntry['streamTail'];
+ if (tail) {
+ const tailRel = useCA ? `${caBase}/${contentHashHex(tail.bytes)}${tail.ext}` : `${outRel}.tail${tail.ext}`;
+ if (!staged.has(tailRel)) {
+ staged.add(tailRel);
+ await writeFile(path.join(absOut, tailRel), tail.bytes);
+ }
+ streamTail = { path: tailRel, size: tail.bytes.byteLength, width: tail.width, height: tail.height, fullWidth: tail.fullWidth, fullHeight: tail.fullHeight };
+ }
manifestEntries.push({
uuid: entry.uuid,
path: outRel,
@@ -923,6 +951,7 @@ export async function cookAssets(
groupMode: delivery,
...(compressedFormats ? { compressedFormats } : {}),
...(cook ? { cook } : {}),
+ ...(streamTail ? { streamTail } : {}),
});
// The video's audio track ships as its own manifest entry addressed as
// `<source path>.m4a` / uuid `<video uuid>-audio` — the runtime resolves
diff --git a/pipeline/src/assets/streamTail.ts b/pipeline/src/assets/streamTail.ts
new file mode 100644
index 000000000..6a51e669e
--- /dev/null
+++ b/pipeline/src/assets/streamTail.ts
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file streamTail.ts — the small copy of a 3D texture a streamed build ships beside it.
+ *
+ * Texture streaming starts a mesh's texture small and grows it to what its views need. A build that ships the file alone still makes
+ * the game download it whole before the first, small upload; this writes a copy no larger than {@link STREAM_TAIL_EDGE} on a side
+ * next to it, in the same format, and the runtime fetches that one first. The full file is fetched only once a view needs more than
+ * the copy holds, and a texture nothing comes close to is never fetched whole at all.
+ *
+ * The copy is made from the shipped bytes, not the source, so it is the same picture at every size: halved with the same box filter
+ * the cook's own mip chains use, linear-light for a colour texture and plain for data. A KTX2 is encoded again in its own mode; a PNG
+ * and a JPEG are written as what they were.
+ */
+import { PNG } from 'pngjs';
+import jpeg from 'jpeg-js';
+import { halveRgba, readKtx2Layout } from './ktx2Mips';
+import type { BasisEncoderModule } from './textureCook';
+
+/** The longer side of the copy. Texture streaming starts a mesh texture at this. */
+export const STREAM_TAIL_EDGE = 256;
+
+export interface StreamTail {
+ bytes: Uint8Array;
+ ext: string;
+ width: number;
+ height: number;
+ /** The shipped file's size, which the copy stands in for. */
+ fullWidth: number;
+ fullHeight: number;
+}
+
+const KHR_DF_MODEL_UASTC = 166;
+
+async function decode(data: Uint8Array, ext: string, enc: BasisEncoderModule | null): Promise<{ width: number; height: number; rgba: Uint8Array } | null> {
+ const e = ext.toLowerCase();
+ if (e === '.png') {
+ const png = PNG.sync.read(Buffer.from(data.buffer, data.byteOffset, data.byteLength));
+ return { width: png.width, height: png.height, rgba: new Uint8Array(png.data.buffer, png.data.byteOffset, png.data.byteLength) };
+ }
+ if (e === '.jpg' || e === '.jpeg') {
+ const img = jpeg.decode(data, { useTArray: true, formatAsRGBA: true, maxMemoryUsageInMB: 1024 });
+ return { width: img.width, height: img.height, rgba: img.data };
+ }
+ if (e === '.ktx2' && enc) {
+ const img = await enc.transcodeKtx2ToRgba(data);
+ return { width: img.width, height: img.height, rgba: img.pixels };
+ }
+ return null;
+}
+
+/**
+ * The small copy of a shipped texture, or null when it is small enough already (no larger than twice the copy: the saving would not
+ * pay for a second file) or its format cannot be read here. @p srgb says whether the texels are colour, which decides how they are
+ * averaged; a KTX2 says it itself.
+ */
+export async function makeStreamTail(
+ data: Uint8Array, ext: string, srgb: boolean, enc: BasisEncoderModule | null,
+): Promise<StreamTail | null> {
+ const image = await decode(data, ext, enc);
+ if (!image || Math.max(image.width, image.height) <= STREAM_TAIL_EDGE * 2) return null;
+ const layout = ext.toLowerCase() === '.ktx2' ? readKtx2Layout(data) : null;
+ const colour = layout ? layout.srgb : srgb;
+ let level = { rgba: image.rgba, width: image.width, height: image.height };
+ while (Math.max(level.width, level.height) > STREAM_TAIL_EDGE) level = halveRgba(level.rgba, level.width, level.height, colour);
+
+ const e = ext.toLowerCase();
+ let bytes: Uint8Array;
+ if (e === '.png') {
+ const png = new PNG({ width: level.width, height: level.height });
+ png.data = Buffer.from(level.rgba.buffer, level.rgba.byteOffset, level.rgba.byteLength);
+ bytes = new Uint8Array(PNG.sync.write(png));
+ } else if (e === '.jpg' || e === '.jpeg') {
+ bytes = new Uint8Array(jpeg.encode({ data: level.rgba, width: level.width, height: level.height }, 90).data);
+ } else {
+ const uastc = layout?.colorModel === KHR_DF_MODEL_UASTC;
+ bytes = await enc!.encodeToKtx2({ type: enc!.ImageType.RGBA, data: level.rgba, width: level.width, height: level.height },
+ { mode: uastc ? 'uastc' : 'etc1s', srgb: colour, mipmaps: true, supercompress: uastc });
+ }
+ return { bytes, ext, width: level.width, height: level.height, fullWidth: image.width, fullHeight: image.height };
+}
diff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.ts
index 3fe8ce0a9..3cc6b1377 100644
--- a/pipeline/src/export/exportGame.ts
+++ b/pipeline/src/export/exportGame.ts
@@ -974,7 +974,9 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>
// for this target before anything is staged — their ids ride game.config.json, so
// the runtime can acquire them exactly like the engine's own.
const projectModules = await loadProjectModules(opts.root, platform);
- const cook = await cookAssets(opts.root, { entryScenes: scenes.map((s) => s.path), outDir: payloadDir, contentAddressed: opts.contentAddressed ?? true, compressTextures: opts.compressTextures, compressAudio: opts.compressAudio, atlasTextures: opts.atlasTextures, transcodeVideo, platform, textureDecoderBytes: textureDecoderBytes(opts.wasmDir) });
+ const cook = await cookAssets(opts.root, { entryScenes: scenes.map((s) => s.path), outDir: payloadDir, contentAddressed: opts.contentAddressed ?? true, compressTextures: opts.compressTextures, compressAudio: opts.compressAudio, atlasTextures: opts.atlasTextures, transcodeVideo, platform, textureDecoderBytes: textureDecoderBytes(opts.wasmDir),
+ // A web game fetches each file as it is needed, so a texture streamed small need not be downloaded whole until it grows.
+ streamTails: platform === 'web' });
warnings.push(...cook.warnings);
// An asset the game reaches and the cook could not produce is a hole, not a
// note: the scene still references it and the runtime 404s at boot.
diff --git a/pipeline/tests/stream-tail.test.ts b/pipeline/tests/stream-tail.test.ts
new file mode 100644
index 000000000..911687478
--- /dev/null
+++ b/pipeline/tests/stream-tail.test.ts
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { describe, expect, it } from 'vitest';
+import { PNG } from 'pngjs';
+import jpeg from 'jpeg-js';
+import { makeStreamTail, STREAM_TAIL_EDGE } from '../src/assets/streamTail';
+
+/** A `w` x `h` image whose left half is red and right half blue. */
+function halves(w: number, h: number): Uint8Array {
+ const rgba = new Uint8Array(w * h * 4);
+ for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
+ const i = (y * w + x) * 4;
+ rgba.set(x < w / 2 ? [220, 20, 20, 255] : [20, 20, 220, 255], i);
+ }
+ return rgba;
+}
+
+describe('the small copy of a 3D texture', () => {
+ it('is a PNG no larger than the start edge, the same picture, for a PNG', async () => {
+ const png = new PNG({ width: 1024, height: 512 });
+ png.data = Buffer.from(halves(1024, 512));
+ const tail = await makeStreamTail(new Uint8Array(PNG.sync.write(png)), '.png', true, null);
+ expect(tail).not.toBeNull();
+ expect([tail!.width, tail!.height, tail!.fullWidth, tail!.fullHeight]).toEqual([STREAM_TAIL_EDGE, STREAM_TAIL_EDGE / 2, 1024, 512]);
+ const back = PNG.sync.read(Buffer.from(tail!.bytes));
+ expect(back.width).toBe(STREAM_TAIL_EDGE);
+ expect([...back.data.subarray(0, 3)]).toEqual([220, 20, 20]);
+ const right = ((STREAM_TAIL_EDGE / 4) * STREAM_TAIL_EDGE + STREAM_TAIL_EDGE - 1) * 4;
+ expect([...back.data.subarray(right, right + 3)]).toEqual([20, 20, 220]);
+ });
+
+ it('is a JPEG for a JPEG', async () => {
+ const source = jpeg.encode({ data: halves(2048, 2048), width: 2048, height: 2048 }, 90).data;
+ const tail = await makeStreamTail(new Uint8Array(source), '.jpg', true, null);
+ expect(tail!.ext).toBe('.jpg');
+ const back = jpeg.decode(tail!.bytes, { useTArray: true });
+ expect([back.width, back.height]).toEqual([STREAM_TAIL_EDGE, STREAM_TAIL_EDGE]);
+ expect(back.data[0]).toBeGreaterThan(180);
+ expect(tail!.bytes.byteLength).toBeLessThan(source.byteLength / 8);
+ });
+
+ it('is not made for a texture small enough already, or one it cannot read', async () => {
+ const png = new PNG({ width: 512, height: 512 });
+ png.data = Buffer.from(halves(512, 512));
+ expect(await makeStreamTail(new Uint8Array(PNG.sync.write(png)), '.png', true, null)).toBeNull();
+ expect(await makeStreamTail(new Uint8Array(16), '.ktx2', true, null)).toBeNull();
+ });
+});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7c6f6cbfd..02e867b62 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -183,6 +183,9 @@ importers:
ffmpeg-static:
specifier: ^5.3.0
version: 5.3.0
+ jpeg-js:
+ specifier: 0.4.4
+ version: 0.4.4
js-yaml:
specifier: 4.3.0
version: 4.3.0
@@ -2548,6 +2551,9 @@ packages:
resolution: {integrity: sha512-YYVDInQKFJfR/xa3ojUTl8c2KoTwiL1R5Wg9YCydwH0x0B9grbzlg5HC7mMjCtUJjbQ/YnGEZIhI5tCgfTb4Hw==}
+ resolution: {integrity: sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==}
+
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
@@ -6206,6 +6212,8 @@ snapshots:
+
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 12b041dbf..41d6117ae 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 164 beta · 2025 experimental · 3 deprecated
+Symbols: 115 public · 164 beta · 2027 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -146,6 +146,7 @@ pack: AssetPackRef | undefined
path: string
size: number
spineImport: SpineManifestContract | undefined
+streamTail: StreamTailInfo | undefined
textureImport: ParsedTextureImportSettings | undefined
type: AddressableAssetType
```
@@ -2206,6 +2207,8 @@ ResourceDef<CameraViewAPI>
clipSegment: (a: Vec3, b: Vec3) => { a: Vec3; b: Vec3; } | null
getWorldBounds: () => { left: number; right: number; bottom: number; top: number; } | null
getWorldMousePosition: () => { x: number; y: number; } | null
+pointerRay: (pointerX: number, pointerY: number) => WorldRay | null
+pointerToWorld: (pointerX: number, pointerY: number, planeZ?: number) => { x: number; y: number; } | null
projectDirectionAt: (at: Vec3, dir: Vec3) => { x: number; y: number; } | null
screenRay: (screenX: number, screenY: number) => WorldRay | null
screenToWorld: (screenX: number, screenY: number, planeZ?: number) => { x: number; y: number; } | null
@@ -2354,6 +2357,7 @@ getBuildPath: (path: string) => string
getByLabel: (label: string) => string[]
getDeps: (path: string) => string[]
getEntry: (path: string) => CatalogEntry | null
+getStreamTail: (path: string) => StreamTailInfo | null
hasAddress: (address: string) => boolean
hasEntry: (path: string) => boolean
isEmpty: boolean
@@ -2378,6 +2382,7 @@ atlas: string | undefined
buildPath: string | undefined
deps: string[] | undefined
frame: { x: number; y: number; w: number; h: number; } | undefined
+streamTail: StreamTailInfo | undefined
trim: { sourceW: number; sourceH: number; offsetX: number; offsetY: number; } | undefined
type: string
uv: { offset: [number, number]; scale: [number, number]; } | undefined
@@ -12505,6 +12510,12 @@ x: number
y: number
```
+## UvRect — interface @experimental
+```
+uvOffset: { x: number; y: number; }
+uvScale: { x: number; y: number; }
+```
+
## ValidatePrefabOptions — interface @experimental
```
instanceOverrides: readonly PrefabOverride[] | undefined
@@ -17299,6 +17310,11 @@ UIVisibilityPlugin
(uprights: readonly Upright[], view: { left: number; bottom: number; right: number; top: number; }): MaskRect[]
```
+## uvRectFromPixels — function @experimental
+```
+(rect: { x: number; y: number; width: number; height: number; }, textureWidth: number, textureHeight: number): UvRect
+```
+
## v2 — const @experimental
```
{ readonly create: (x?: number, y?: number) => Vec2; readonly clone: (a: Vec2) => Vec2; readonly add: (a: Vec2, b: Vec2) => Vec2; readonly sub: (a: Vec2, b: Vec2) => Vec2; readonly scale: (a: Vec2, s: number) => Vec2; readonly mul: (a: Vec2, b: Vec2) => Vec2; readonly neg: (a: Vec2) => Vec2; readonly dot: (a: Vec2, b: Vec2) => number; readonly cross: (a: Vec2, b: Vec2) => number; readonly len: (a: Vec2) => number; readonly len2: (a: Vec2) => number; readonly dist: (a: Vec2, b: Vec2) => number; readonly dist2: (a: Vec2, b: Vec2) => number; readonly normalize: (a: Vec2) => Vec2; readonly lerp: (a: Vec2, b: Vec2, t: number) => Vec2; readonly angle: (a: Vec2) => number; readonly fromAngle: (radians: number, length?: number) => Vec2; readonly rotate: (a: Vec2, radians: number) => Vec2; readonly perp: (a: Vec2) => Vec2; readonly equals: (a: Vec2, b: Vec2, epsilon?: number) => boolean; }
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 05df402b0..eebd84168 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 169 beta · 2044 experimental · 3 deprecated
+Symbols: 115 public · 169 beta · 2046 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -146,6 +146,7 @@ pack: AssetPackRef | undefined
path: string
size: number
spineImport: SpineManifestContract | undefined
+streamTail: StreamTailInfo | undefined
textureImport: ParsedTextureImportSettings | undefined
type: AddressableAssetType
```
@@ -2206,6 +2207,8 @@ ResourceDef<CameraViewAPI>
clipSegment: (a: Vec3, b: Vec3) => { a: Vec3; b: Vec3; } | null
getWorldBounds: () => { left: number; right: number; bottom: number; top: number; } | null
getWorldMousePosition: () => { x: number; y: number; } | null
+pointerRay: (pointerX: number, pointerY: number) => WorldRay | null
+pointerToWorld: (pointerX: number, pointerY: number, planeZ?: number) => { x: number; y: number; } | null
projectDirectionAt: (at: Vec3, dir: Vec3) => { x: number; y: number; } | null
screenRay: (screenX: number, screenY: number) => WorldRay | null
screenToWorld: (screenX: number, screenY: number, planeZ?: number) => { x: number; y: number; } | null
@@ -2354,6 +2357,7 @@ getBuildPath: (path: string) => string
getByLabel: (label: string) => string[]
getDeps: (path: string) => string[]
getEntry: (path: string) => CatalogEntry | null
+getStreamTail: (path: string) => StreamTailInfo | null
hasAddress: (address: string) => boolean
hasEntry: (path: string) => boolean
isEmpty: boolean
@@ -2378,6 +2382,7 @@ atlas: string | undefined
buildPath: string | undefined
deps: string[] | undefined
frame: { x: number; y: number; w: number; h: number; } | undefined
+streamTail: StreamTailInfo | undefined
trim: { sourceW: number; sourceH: number; offsetX: number; offsetY: number; } | undefined
type: string
uv: { offset: [number, number]; scale: [number, number]; } | undefined
@@ -8415,7 +8420,7 @@ ReadonlyMap<string, string>
## RESOURCE_BINDINGS — const @experimental
```
-{ readonly createTexture: "es_rm_createTextureEx"; readonly createTextureArray: "es_rm_createTextureArray"; readonly createTextureKTX2: "es_createTextureKTX2"; readonly releaseTexture: "es_rm_releaseTexture"; readonly registerTextureWithPath: "es_rm_registerTextureWithPath"; readonly getTextureDimensions: "es_getTextureDimensions"; }
+{ readonly createTexture: "es_rm_createTextureEx"; readonly createTextureArray: "es_rm_createTextureArray"; readonly createTextureKTX2: "es_createTextureKTX2"; readonly releaseTexture: "es_rm_releaseTexture"; readonly registerTextureWithPath: "es_rm_registerTextureWithPath"; readonly getTextureDimensions: "es_getTextureDimensions"; readonly setTextureMetadata: "es_rm_setTextureMetadata"; }
```
## RETIRED_COMPONENT_TYPES — const @experimental
@@ -12718,6 +12723,12 @@ x: number
y: number
```
+## UvRect — interface @experimental
+```
+uvOffset: { x: number; y: number; }
+uvScale: { x: number; y: number; }
+```
+
## ValidatePrefabOptions — interface @experimental
```
instanceOverrides: readonly PrefabOverride[] | undefined
@@ -17562,6 +17573,11 @@ UIVisibilityPlugin
(uprights: readonly Upright[], view: { left: number; bottom: number; right: number; top: number; }): MaskRect[]
```
+## uvRectFromPixels — function @experimental
+```
+(rect: { x: number; y: number; width: number; height: number; }, textureWidth: number, textureHeight: number): UvRect
+```
+
## v2 — const @experimental
```
{ readonly create: (x?: number, y?: number) => Vec2; readonly clone: (a: Vec2) => Vec2; readonly add: (a: Vec2, b: Vec2) => Vec2; readonly sub: (a: Vec2, b: Vec2) => Vec2; readonly scale: (a: Vec2, s: number) => Vec2; readonly mul: (a: Vec2, b: Vec2) => Vec2; readonly neg: (a: Vec2) => Vec2; readonly dot: (a: Vec2, b: Vec2) => number; readonly cross: (a: Vec2, b: Vec2) => number; readonly len: (a: Vec2) => number; readonly len2: (a: Vec2) => number; readonly dist: (a: Vec2, b: Vec2) => number; readonly dist2: (a: Vec2, b: Vec2) => number; readonly normalize: (a: Vec2) => Vec2; readonly lerp: (a: Vec2, b: Vec2, t: number) => Vec2; readonly angle: (a: Vec2) => number; readonly fromAngle: (radians: number, length?: number) => Vec2; readonly rotate: (a: Vec2, radians: number) => Vec2; readonly perp: (a: Vec2) => Vec2; readonly equals: (a: Vec2, b: Vec2, epsilon?: number) => boolean; }
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 0156c4d28..5a64430c3 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 166 beta · 2024 experimental · 3 deprecated
+Symbols: 115 public · 166 beta · 2026 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -141,6 +141,7 @@ pack: AssetPackRef | undefined
path: string
size: number
spineImport: SpineManifestContract | undefined
+streamTail: StreamTailInfo | undefined
textureImport: ParsedTextureImportSettings | undefined
type: AddressableAssetType
```
@@ -2201,6 +2202,8 @@ ResourceDef<CameraViewAPI>
clipSegment: (a: Vec3, b: Vec3) => { a: Vec3; b: Vec3; } | null
getWorldBounds: () => { left: number; right: number; bottom: number; top: number; } | null
getWorldMousePosition: () => { x: number; y: number; } | null
+pointerRay: (pointerX: number, pointerY: number) => WorldRay | null
+pointerToWorld: (pointerX: number, pointerY: number, planeZ?: number) => { x: number; y: number; } | null
projectDirectionAt: (at: Vec3, dir: Vec3) => { x: number; y: number; } | null
screenRay: (screenX: number, screenY: number) => WorldRay | null
screenToWorld: (screenX: number, screenY: number, planeZ?: number) => { x: number; y: number; } | null
@@ -2349,6 +2352,7 @@ getBuildPath: (path: string) => string
getByLabel: (label: string) => string[]
getDeps: (path: string) => string[]
getEntry: (path: string) => CatalogEntry | null
+getStreamTail: (path: string) => StreamTailInfo | null
hasAddress: (address: string) => boolean
hasEntry: (path: string) => boolean
isEmpty: boolean
@@ -2373,6 +2377,7 @@ atlas: string | undefined
buildPath: string | undefined
deps: string[] | undefined
frame: { x: number; y: number; w: number; h: number; } | undefined
+streamTail: StreamTailInfo | undefined
trim: { sourceW: number; sourceH: number; offsetX: number; offsetY: number; } | undefined
type: string
uv: { offset: [number, number]; scale: [number, number]; } | undefined
@@ -12500,6 +12505,12 @@ x: number
y: number
```
+## UvRect — interface @experimental
+```
+uvOffset: { x: number; y: number; }
+uvScale: { x: number; y: number; }
+```
+
## ValidatePrefabOptions — interface @experimental
```
instanceOverrides: readonly PrefabOverride[] | undefined
@@ -17304,6 +17315,11 @@ UIVisibilityPlugin
(uprights: readonly Upright[], view: { left: number; bottom: number; right: number; top: number; }): MaskRect[]
```
+## uvRectFromPixels — function @experimental
+```
+(rect: { x: number; y: number; width: number; height: number; }, textureWidth: number, textureHeight: number): UvRect
+```
+
## v2 — const @experimental
```
{ readonly create: (x?: number, y?: number) => Vec2; readonly clone: (a: Vec2) => Vec2; readonly add: (a: Vec2, b: Vec2) => Vec2; readonly sub: (a: Vec2, b: Vec2) => Vec2; readonly scale: (a: Vec2, s: number) => Vec2; readonly mul: (a: Vec2, b: Vec2) => Vec2; readonly neg: (a: Vec2) => Vec2; readonly dot: (a: Vec2, b: Vec2) => number; readonly cross: (a: Vec2, b: Vec2) => number; readonly len: (a: Vec2) => number; readonly len2: (a: Vec2) => number; readonly dist: (a: Vec2, b: Vec2) => number; readonly dist2: (a: Vec2, b: Vec2) => number; readonly normalize: (a: Vec2) => Vec2; readonly lerp: (a: Vec2, b: Vec2, t: number) => Vec2; readonly angle: (a: Vec2) => number; readonly fromAngle: (radians: number, length?: number) => Vec2; readonly rotate: (a: Vec2, radians: number) => Vec2; readonly perp: (a: Vec2) => Vec2; readonly equals: (a: Vec2, b: Vec2, epsilon?: number) => boolean; }
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index e9971dac6..c460403e8 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 164 beta · 2046 experimental · 3 deprecated
+Symbols: 115 public · 164 beta · 2048 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -141,6 +141,7 @@ pack: AssetPackRef | undefined
path: string
size: number
spineImport: SpineManifestContract | undefined
+streamTail: StreamTailInfo | undefined
textureImport: ParsedTextureImportSettings | undefined
type: AddressableAssetType
```
@@ -2201,6 +2202,8 @@ ResourceDef<CameraViewAPI>
clipSegment: (a: Vec3, b: Vec3) => { a: Vec3; b: Vec3; } | null
getWorldBounds: () => { left: number; right: number; bottom: number; top: number; } | null
getWorldMousePosition: () => { x: number; y: number; } | null
+pointerRay: (pointerX: number, pointerY: number) => WorldRay | null
+pointerToWorld: (pointerX: number, pointerY: number, planeZ?: number) => { x: number; y: number; } | null
projectDirectionAt: (at: Vec3, dir: Vec3) => { x: number; y: number; } | null
screenRay: (screenX: number, screenY: number) => WorldRay | null
screenToWorld: (screenX: number, screenY: number, planeZ?: number) => { x: number; y: number; } | null
@@ -2349,6 +2352,7 @@ getBuildPath: (path: string) => string
getByLabel: (label: string) => string[]
getDeps: (path: string) => string[]
getEntry: (path: string) => CatalogEntry | null
+getStreamTail: (path: string) => StreamTailInfo | null
hasAddress: (address: string) => boolean
hasEntry: (path: string) => boolean
isEmpty: boolean
@@ -2373,6 +2377,7 @@ atlas: string | undefined
buildPath: string | undefined
deps: string[] | undefined
frame: { x: number; y: number; w: number; h: number; } | undefined
+streamTail: StreamTailInfo | undefined
trim: { sourceW: number; sourceH: number; offsetX: number; offsetY: number; } | undefined
type: string
uv: { offset: [number, number]; scale: [number, number]; } | undefined
@@ -12795,6 +12800,12 @@ x: number
y: number
```
+## UvRect — interface @experimental
+```
+uvOffset: { x: number; y: number; }
+uvScale: { x: number; y: number; }
+```
+
## ValidatePrefabOptions — interface @experimental
```
instanceOverrides: readonly PrefabOverride[] | undefined
@@ -17610,6 +17621,11 @@ UIVisibilityPlugin
(uprights: readonly Upright[], view: { left: number; bottom: number; right: number; top: number; }): MaskRect[]
```
+## uvRectFromPixels — function @experimental
+```
+(rect: { x: number; y: number; width: number; height: number; }, textureWidth: number, textureHeight: number): UvRect
+```
+
## v2 — const @experimental
```
{ readonly create: (x?: number, y?: number) => Vec2; readonly clone: (a: Vec2) => Vec2; readonly add: (a: Vec2, b: Vec2) => Vec2; readonly sub: (a: Vec2, b: Vec2) => Vec2; readonly scale: (a: Vec2, s: number) => Vec2; readonly mul: (a: Vec2, b: Vec2) => Vec2; readonly neg: (a: Vec2) => Vec2; readonly dot: (a: Vec2, b: Vec2) => number; readonly cross: (a: Vec2, b: Vec2) => number; readonly len: (a: Vec2) => number; readonly len2: (a: Vec2) => number; readonly dist: (a: Vec2, b: Vec2) => number; readonly dist2: (a: Vec2, b: Vec2) => number; readonly normalize: (a: Vec2) => Vec2; readonly lerp: (a: Vec2, b: Vec2, t: number) => Vec2; readonly angle: (a: Vec2) => number; readonly fromAngle: (radians: number, length?: number) => Vec2; readonly rotate: (a: Vec2, radians: number) => Vec2; readonly perp: (a: Vec2) => Vec2; readonly equals: (a: Vec2, b: Vec2, epsilon?: number) => boolean; }
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index e53bbf6ea..bc98f89ec 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 115 public · 164 beta · 2037 experimental · 3 deprecated
+Symbols: 115 public · 164 beta · 2039 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -141,6 +141,7 @@ pack: AssetPackRef | undefined
path: string
size: number
spineImport: SpineManifestContract | undefined
+streamTail: StreamTailInfo | undefined
textureImport: ParsedTextureImportSettings | undefined
type: AddressableAssetType
```
@@ -2201,6 +2202,8 @@ ResourceDef<CameraViewAPI>
clipSegment: (a: Vec3, b: Vec3) => { a: Vec3; b: Vec3; } | null
getWorldBounds: () => { left: number; right: number; bottom: number; top: number; } | null
getWorldMousePosition: () => { x: number; y: number; } | null
+pointerRay: (pointerX: number, pointerY: number) => WorldRay | null
+pointerToWorld: (pointerX: number, pointerY: number, planeZ?: number) => { x: number; y: number; } | null
projectDirectionAt: (at: Vec3, dir: Vec3) => { x: number; y: number; } | null
screenRay: (screenX: number, screenY: number) => WorldRay | null
screenToWorld: (screenX: number, screenY: number, planeZ?: number) => { x: number; y: number; } | null
@@ -2349,6 +2352,7 @@ getBuildPath: (path: string) => string
getByLabel: (label: string) => string[]
getDeps: (path: string) => string[]
getEntry: (path: string) => CatalogEntry | null
+getStreamTail: (path: string) => StreamTailInfo | null
hasAddress: (address: string) => boolean
hasEntry: (path: string) => boolean
isEmpty: boolean
@@ -2373,6 +2377,7 @@ atlas: string | undefined
buildPath: string | undefined
deps: string[] | undefined
frame: { x: number; y: number; w: number; h: number; } | undefined
+streamTail: StreamTailInfo | undefined
trim: { sourceW: number; sourceH: number; offsetX: number; offsetY: number; } | undefined
type: string
uv: { offset: [number, number]; scale: [number, number]; } | undefined
@@ -12507,6 +12512,12 @@ x: number
y: number
```
+## UvRect — interface @experimental
+```
+uvOffset: { x: number; y: number; }
+uvScale: { x: number; y: number; }
+```
+
## ValidatePrefabOptions — interface @experimental
```
instanceOverrides: readonly PrefabOverride[] | undefined
@@ -17336,6 +17347,11 @@ UIVisibilityPlugin
(uprights: readonly Upright[], view: { left: number; bottom: number; right: number; top: number; }): MaskRect[]
```
+## uvRectFromPixels — function @experimental
+```
+(rect: { x: number; y: number; width: number; height: number; }, textureWidth: number, textureHeight: number): UvRect
+```
+
## v2 — const @experimental
```
{ readonly create: (x?: number, y?: number) => Vec2; readonly clone: (a: Vec2) => Vec2; readonly add: (a: Vec2, b: Vec2) => Vec2; readonly sub: (a: Vec2, b: Vec2) => Vec2; readonly scale: (a: Vec2, s: number) => Vec2; readonly mul: (a: Vec2, b: Vec2) => Vec2; readonly neg: (a: Vec2) => Vec2; readonly dot: (a: Vec2, b: Vec2) => number; readonly cross: (a: Vec2, b: Vec2) => number; readonly len: (a: Vec2) => number; readonly len2: (a: Vec2) => number; readonly dist: (a: Vec2, b: Vec2) => number; readonly dist2: (a: Vec2, b: Vec2) => number; readonly normalize: (a: Vec2) => Vec2; readonly lerp: (a: Vec2, b: Vec2, t: number) => Vec2; readonly angle: (a: Vec2) => number; readonly fromAngle: (radians: number, length?: number) => Vec2; readonly rotate: (a: Vec2, radians: number) => Vec2; readonly perp: (a: Vec2) => Vec2; readonly equals: (a: Vec2, b: Vec2, epsilon?: number) => boolean; }
diff --git a/sdk/src/asset/AddressableManifest.ts b/sdk/src/asset/AddressableManifest.ts
index 64fc3265e..be7ddd1fe 100644
--- a/sdk/src/asset/AddressableManifest.ts
+++ b/sdk/src/asset/AddressableManifest.ts
@@ -7,6 +7,16 @@ import { contentHashOf } from './contentHash';
export type { AddressableAssetType };
+/** Where a texture's small copy is, and how big it and the file are. */
+export interface StreamTailInfo {
+ path: string;
+ size: number;
+ width: number;
+ height: number;
+ fullWidth: number;
+ fullHeight: number;
+}
+
export interface AddressableManifestAsset {
path: string;
address?: string;
@@ -23,6 +33,8 @@ export interface AddressableManifestAsset {
contentHash?: string;
/** GPU compressed formats this asset was encoded for (e.g. ['astc-4x4','etc2-rgba8']). */
compressedFormats?: string[];
+ /** A small copy of a texture a mesh draws, which texture streaming fetches first (`path` is its build path). */
+ streamTail?: StreamTailInfo;
/**
* How the texture is sampled and sliced — the runtime half of the `.meta`
* importer block, parsed at cook time rather than shipped raw: a packaged
diff --git a/sdk/src/asset/Catalog.ts b/sdk/src/asset/Catalog.ts
index b48a9a135..a0dd5523c 100644
--- a/sdk/src/asset/Catalog.ts
+++ b/sdk/src/asset/Catalog.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import type { StreamTailInfo } from './AddressableManifest';
import { extractUuid, UUID_REF_PREFIX } from './AssetRegistry';
export interface AtlasFrameInfo {
@@ -18,6 +19,8 @@ export interface CatalogEntry {
trim?: { sourceW: number; sourceH: number; offsetX: number; offsetY: number };
deps?: string[];
buildPath?: string;
+ /** A small copy of the texture that texture streaming fetches first. */
+ streamTail?: StreamTailInfo;
}
export interface CatalogData {
@@ -133,6 +136,11 @@ export class Catalog {
return this.addressByBuildPath_.get(path) ?? null;
}
+ /** The small copy of a texture streaming fetches first, or null when the build shipped none. */
+ getStreamTail(path: string): StreamTailInfo | null {
+ return this.entries_.get(path)?.streamTail ?? null;
+ }
+
getBuildPath(path: string): string {
const entry = this.entries_.get(path);
return entry?.buildPath ?? path;
diff --git a/sdk/src/asset/loaders/TextureLoader.ts b/sdk/src/asset/loaders/TextureLoader.ts
index b7370befc..849efda9d 100644
--- a/sdk/src/asset/loaders/TextureLoader.ts
+++ b/sdk/src/asset/loaders/TextureLoader.ts
@@ -284,14 +284,29 @@ export class TextureLoader implements AssetLoader<TextureResult> {
private async decodeAndUpload_(
path: string, ctx: LoadContext, flip: boolean, settings?: TextureImportSettings, maxEdge = 0,
+ ): Promise<TextureResult> {
+ // A build that shipped a small copy beside the file (texture streaming) is read from the copy whenever the size asked for
+ // fits in it: the file itself is downloaded only once a view needs more than the copy holds.
+ const tail = maxEdge > 0 ? ctx.catalog.getStreamTail?.(path) ?? null : null;
+ if (tail && maxEdge <= Math.max(tail.width, tail.height)) {
+ const made = await this.decodeFile_(path, tail.path, ctx, flip, settings, maxEdge, true);
+ return { ...made, fullWidth: tail.fullWidth, fullHeight: tail.fullHeight };
+ }
+ return this.decodeFile_(path, ctx.catalog?.getBuildPath(path) ?? path, ctx, flip, settings, maxEdge, false);
+ }
+
+ /** Decode @p path (whose bytes are at @p buildPath; @p copy when that is its small copy) no larger than @p maxEdge, and upload it. */
+ private async decodeFile_(
+ path: string, buildPath: string, ctx: LoadContext, flip: boolean, settings: TextureImportSettings | undefined, maxEdge: number,
+ copy: boolean,
): Promise<TextureResult> {
this.lastDecision_ = RAW_PAYLOAD_UPLOAD;
- if (isKtx2Path(path)) {
- const buf = await ctx.backend.fetchBinary(ctx.catalog.getBuildPath(path));
+ if (isKtx2Path(buildPath)) {
+ const buf = await ctx.backend.fetchBinary(buildPath);
return this.uploadKtx2_(path, new Uint8Array(buf), settings, maxEdge);
}
let preview = false;
- if (this.compressedSource_) {
+ if (!copy && this.compressedSource_) {
const compressed = await this.compressedSource_(path);
if (compressed instanceof Uint8Array) return this.uploadKtx2_(path, compressed, settings, maxEdge);
preview = compressed === 'pending';
@@ -302,7 +317,8 @@ export class TextureLoader implements AssetLoader<TextureResult> {
// uploads through the shared createTexture path — the same code the old
// runtimeLoader.loadTextures used — instead of a URL-based <img>.
if (this.pixelDecoder_) {
- const result = await this.pixelDecoder_(path, flip, edge);
+ // A decoder resolves a logical path itself; a copy is named by where it is.
+ const result = await this.pixelDecoder_(copy ? buildPath : path, flip, edge);
const handle = createTextureFromPixels(this.module_, result, TextureContent.Asset, flip, pixelParams(settings));
// A decoder that made it smaller says what it was made from; one that could not (a host decoding whole) answers with the
// file's own size, and the texture is simply whole.
@@ -310,9 +326,9 @@ export class TextureLoader implements AssetLoader<TextureResult> {
? { handle, width: result.width, height: result.height, fullWidth: result.sourceWidth, fullHeight: result.sourceHeight }
: { handle, width: result.width, height: result.height };
}
- const url = ctx.backend.resolveUrl(ctx.catalog.getBuildPath(path));
+ const url = ctx.backend.resolveUrl(buildPath);
const full = { width: 0, height: 0 };
- const img = await this.loadImage(url, flip, edge, this.imageRevisions_.get(path), full);
+ const img = await this.loadImage(url, flip, edge, copy ? undefined : this.imageRevisions_.get(path), full);
const made = this.createTextureFromImage(img, flip, settings);
return full.width > made.width || full.height > made.height ? { ...made, fullWidth: full.width, fullHeight: full.height } : made;
}
diff --git a/sdk/src/render/quality.ts b/sdk/src/render/quality.ts
index cf5a432a5..1be8b1bae 100644
--- a/sdk/src/render/quality.ts
+++ b/sdk/src/render/quality.ts
@@ -86,7 +86,8 @@ export interface QualityProfile {
drawCallBudget: number;
/**
* Hold each texture only meshes draw at the size its views need (see `textureStreamingPlugin`): a texture far away takes a
- * fraction of its memory, and grows back as the camera comes close. Its file is still read and decoded whole the first time.
+ * fraction of its memory, and grows back as the camera comes close. A web build ships a small copy beside each such texture, so its
+ * file is downloaded only once a view needs more than the copy holds.
*/
textureStreaming: boolean;
/** The megabytes the streamed textures may take together; past it they are held a level softer. 0 is no cap. */
diff --git a/sdk/src/render/textureStreaming.ts b/sdk/src/render/textureStreaming.ts
index 0f34952cc..77e33d218 100644
--- a/sdk/src/render/textureStreaming.ts
+++ b/sdk/src/render/textureStreaming.ts
@@ -12,9 +12,10 @@
* been needed smaller for a while, so a camera passing by does not make it go back and forth.
*
* What it streams: textures decoded from a file that only meshes draw. A texture a sprite, a UI element, a tilemap, a particle
- * or a trail also draws is left at its size, since nothing measures what those need. What it saves is GPU memory; a texture is
- * still read and decoded whole from its file the first time, so it saves neither the download nor the decode. A KTX2 file
- * is cut at a level and not decoded again.
+ * or a trail also draws is put back at its size, since nothing measures what those need. A mesh texture is loaded no larger
+ * than 256 texels on a side to begin with (Assets.setTextureStreamingStart); a web build ships a small copy beside it
+ * (pipeline streamTail.ts), which is what is fetched then, so the file itself is downloaded only once a view needs more. A
+ * KTX2 file is cut at a level and not decoded again.
*/
import type { App, Plugin } from '../app/app';
import { defineSystem, Schedule } from '../ecs/system';
diff --git a/sdk/src/runtime/packagedRuntime.ts b/sdk/src/runtime/packagedRuntime.ts
index c3c9fd749..52977955b 100644
--- a/sdk/src/runtime/packagedRuntime.ts
+++ b/sdk/src/runtime/packagedRuntime.ts
@@ -283,12 +283,15 @@ export function catalogFromManifest(manifest: AddressableManifest): Catalog | un
asset.path,
)
: null;
- if (atlasFields) {
- entries[`@uuid:${uuid}`] = { type: asset.type, buildPath: asset.path, ...atlasFields };
+ const tail = asset.streamTail ? { streamTail: asset.streamTail } : {};
+ if (atlasFields || asset.streamTail) {
+ entries[`@uuid:${uuid}`] = { type: asset.type, buildPath: asset.path, ...(atlasFields ?? {}), ...tail };
}
+ // A texture with a small copy is found by whatever spelling a load uses, the build path among them.
+ if (asset.streamTail) entries[asset.path] = { type: asset.type, buildPath: asset.path, ...tail };
if (!asset.address || asset.address === asset.path) continue;
- entries[asset.address] = { type: asset.type, buildPath: asset.path, ...(atlasFields ?? {}) };
- entries[`/${asset.address}`] = { type: asset.type, buildPath: asset.path, ...(atlasFields ?? {}) };
+ entries[asset.address] = { type: asset.type, buildPath: asset.path, ...(atlasFields ?? {}), ...tail };
+ entries[`/${asset.address}`] = { type: asset.type, buildPath: asset.path, ...(atlasFields ?? {}), ...tail };
}
}
return Object.keys(entries).length > 0 ? Catalog.fromJson({ version: 1, entries }) : undefined;
diff --git a/sdk/tests/texture-streaming-start.test.ts b/sdk/tests/texture-streaming-start.test.ts
index 85539537a..231bd0064 100644
--- a/sdk/tests/texture-streaming-start.test.ts
+++ b/sdk/tests/texture-streaming-start.test.ts
@@ -42,3 +42,21 @@ describe('which textures a scene\'s meshes draw', () => {
expect([...found.meshMaterials]).toEqual(['assets/wall.esmaterial']);
});
});
+
+describe('a build\'s small copies', () => {
+ it('reach the catalog by every spelling a load uses', async () => {
+ const { catalogFromManifest } = await import('../src/runtime/packagedRuntime');
+ const tail = { path: 'assets/ab12.jpg', size: 9000, width: 256, height: 128, fullWidth: 2048, fullHeight: 1024 };
+ const catalog = catalogFromManifest({
+ version: '2.0', revision: 'r', groups: {
+ main: { bundleMode: 'local', labels: [], assets: {
+ 'u-1': { path: 'assets/cd34.jpg', address: 'assets/wall.jpg', type: 'texture', size: 400000, labels: [], streamTail: tail },
+ } },
+ },
+ } as never)!;
+ expect(catalog.getStreamTail('assets/wall.jpg')).toEqual(tail);
+ expect(catalog.getStreamTail('@uuid:u-1')).toEqual(tail);
+ expect(catalog.getStreamTail('assets/cd34.jpg')).toEqual(tail);
+ expect(catalog.getStreamTail('assets/other.jpg')).toBeNull();
+ });
+});