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(native): Spine renders on a device — resolve its atlas pages, register them
esenginee21dbe9f650b
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.mdindex 980b46e88..9fd1a7c29 100644--- a/sdk/etc/index.api.md+++ b/sdk/etc/index.api.md@@ -4236,6 +4236,7 @@ Record<string, PtrLayout>## PackagedAssetIndex — interface```+addressOf: (ref: string) => string | nullassetPaths: () => string[]catalog: Catalog | undefinedmanifest: AddressableManifest@@ -5523,6 +5524,7 @@ linearDamping: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex 364eb7c9c..c352ddefc 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -4384,6 +4384,7 @@ Record<string, PtrLayout>## PackagedAssetIndex — interface```+addressOf: (ref: string) => string | nullassetPaths: () => string[]catalog: Catalog | undefinedmanifest: AddressableManifest@@ -5363,7 +5364,7 @@ static prototype: QueryInstance<any>## RESOURCE_BINDINGS — const```-{ readonly createTexture: "es_rm_createTextureEx"; readonly createTextureKTX2: "es_createTextureKTX2"; readonly releaseTexture: "es_rm_releaseTexture"; readonly getTextureDimensions: "es_getTextureDimensions"; }+{ readonly createTexture: "es_rm_createTextureEx"; readonly createTextureKTX2: "es_createTextureKTX2"; readonly releaseTexture: "es_rm_releaseTexture"; readonly registerTextureWithPath: "es_rm_registerTextureWithPath"; readonly getTextureDimensions: "es_getTextureDimensions"; }```## RETIRED_COMPONENT_TYPES — const@@ -5681,6 +5682,7 @@ linearDamping: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.mdindex f2cdf7910..5afbda51c 100644--- a/sdk/etc/index.node.api.md+++ b/sdk/etc/index.node.api.md@@ -4231,6 +4231,7 @@ Record<string, PtrLayout>## PackagedAssetIndex — interface```+addressOf: (ref: string) => string | nullassetPaths: () => string[]catalog: Catalog | undefinedmanifest: AddressableManifest@@ -5518,6 +5519,7 @@ linearDamping: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 491276c81..03a12969c 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -4446,6 +4446,7 @@ Record<string, PtrLayout>## PackagedAssetIndex — interface```+addressOf: (ref: string) => string | nullassetPaths: () => string[]catalog: Catalog | undefinedmanifest: AddressableManifest@@ -5733,6 +5734,7 @@ linearDamping: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/etc/spine.api.md b/sdk/etc/spine.api.mdindex 363df1135..f4e57e193 100644--- a/sdk/etc/spine.api.md+++ b/sdk/etc/spine.api.md@@ -57,6 +57,7 @@ spacing: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.mdindex 066e1aff9..9a741033f 100644--- a/sdk/etc/wechat.api.md+++ b/sdk/etc/wechat.api.md@@ -4238,6 +4238,7 @@ Record<string, PtrLayout>## PackagedAssetIndex — interface```+addressOf: (ref: string) => string | nullassetPaths: () => string[]catalog: Catalog | undefinedmanifest: AddressableManifest@@ -5525,6 +5526,7 @@ linearDamping: numberbackend: BackenddecodePixels: (path: string, flip: boolean) => Promise<{ width: number; height: number; pixels: Uint8Array; }>listAssetPaths: (() => string[]) | undefined+resolveAddress: ((ref: string) => string | null) | undefinedresolveRef: ((ref: string) => string) | undefined```diff --git a/sdk/src/ecs/nativeBindings.ts b/sdk/src/ecs/nativeBindings.tsindex d712b4217..ddb9b4f64 100644--- a/sdk/src/ecs/nativeBindings.ts+++ b/sdk/src/ecs/nativeBindings.ts@@ -48,6 +48,7 @@ export const RESOURCE_BINDINGS = {createTexture: 'es_rm_createTextureEx',createTextureKTX2: 'es_createTextureKTX2',releaseTexture: 'es_rm_releaseTexture',+ registerTextureWithPath: 'es_rm_registerTextureWithPath',getTextureDimensions: 'es_getTextureDimensions',} as const;diff --git a/sdk/src/ecs/nativeResourceManager.ts b/sdk/src/ecs/nativeResourceManager.tsindex c65dc9720..1904a2d84 100644--- a/sdk/src/ecs/nativeResourceManager.ts+++ b/sdk/src/ecs/nativeResourceManager.ts@@ -100,6 +100,16 @@ export function createNativeResourceManager(hostCallOpt(scope, RESOURCE_BINDINGS.releaseTexture, [handle]);},+ // Register the handle under a logical path so a later load-by-path revives+ // the same texture instead of re-decoding. The web RM does this in its+ // loaders; the Spine loader calls it directly (not through the optional+ // TextureLoader path), so the native RM must answer it or Spine textures+ // fail to bind. hostCallOpt: a host that did not compile the entry point+ // simply skips the cache registration.+ registerTextureWithPath: (handle, path): void => {+ hostCallOpt(scope, RESOURCE_BINDINGS.registerTextureWithPath, [handle, path]);+ },+getTextureDimensions: (handle): { width: number; height: number } | null =>(hostCallOpt(scope, RESOURCE_BINDINGS.getTextureDimensions, [handle]) as{ width: number; height: number } | null | undefined) ?? null,diff --git a/sdk/src/packagedRuntime.ts b/sdk/src/packagedRuntime.tsindex 061fbe7c6..f78a654a0 100644--- a/sdk/src/packagedRuntime.ts+++ b/sdk/src/packagedRuntime.ts@@ -58,6 +58,10 @@ export interface PackagedAssetIndex {catalog?: Catalog;/** Resolve any ref spelling (`@uuid:`, logical, "/"-rooted) to a staged path. */resolvePath(ref: string): string;+ /** The asset's LOGICAL source path for any ref spelling (including its own staged+ * path), or null when unknown — recovers the authored directory a+ * content-addressed rename hid. */+ addressOf(ref: string): string | null;/** Every staged asset path — content-driven discovery (locale tables). */assetPaths(): string[];}@@ -109,6 +113,13 @@ export function indexPackagedManifest(manifest: AddressableManifest): PackagedAs// uuids — strip the prefix before looking up, or every `@uuid:` ref falls// through as a literal path and 404s.resolvePath: (ref) => model.resolvePath(extractUuid(ref) ?? ref, toBuildPath),+ // The authored logical path behind any spelling — its uuid, its logical+ // address, or its staged (content-addressed) path. Lets a loader recover the+ // directory a sibling was authored in after the rename hid it.+ addressOf: (ref) => {+ const asset = model.assetByKey(extractUuid(ref) ?? ref) ?? model.assetByPath(ref);+ return asset ? (asset.address ?? asset.path) : null;+ },// The logical address where there is one (content-addressed packs rename// the staged file), else the staged path — either keeps the extension// .eslocale discovery filters on.@@ -140,6 +151,7 @@ export function createPackagedAssetSource(backend: options.backend ?? new FileSystemBackend(),decodePixels: options.decodePixels ?? ((path) => platformLoadImagePixels(path)),resolveRef: index.resolvePath,+ resolveAddress: index.addressOf,listAssetPaths: index.assetPaths,};}diff --git a/sdk/src/runtimeAssets.ts b/sdk/src/runtimeAssets.tsindex 78ce9d42a..22af70e5f 100644--- a/sdk/src/runtimeAssets.ts+++ b/sdk/src/runtimeAssets.ts@@ -32,6 +32,15 @@ export interface RuntimeAssetSource {backend: Backend;decodePixels(path: string, flip: boolean): Promise<{ width: number; height: number; pixels: Uint8Array }>;resolveRef?(ref: string): string;+ /**+ * The LOGICAL source path a ref was authored at (e.g. `assets/spine/hero.atlas`),+ * even after a content-addressed build renamed the physical file to a hash. A+ * loader that resolves a SIBLING by name — a Spine atlas naming its page PNG+ * relative to itself — needs the logical directory, which `resolveRef` (a build+ * path) has lost. Optional: a realm that stages under logical paths has nothing+ * to recover, and a caller falls back to the resolved path.+ */+ resolveAddress?(ref: string): string | 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/spine/loadSpineScene.ts b/sdk/src/spine/loadSpineScene.tsindex e749e0e1d..9937b1b37 100644--- a/sdk/src/spine/loadSpineScene.ts+++ b/sdk/src/spine/loadSpineScene.ts@@ -110,7 +110,13 @@ export async function loadSpineAssets(: null;const texNames = parseSpineAtlasPages(atlasContent);- const atlasDir = atlasPath.substring(0, atlasPath.lastIndexOf('/'));+ // Pages are named relative to the atlas's AUTHORED location, not its+ // staged one — a content-addressed build renamed the atlas to a hash+ // under assets/, so `atlasPath`'s directory is not where the pages were.+ // Recover the authored directory from the atlas's logical address, so+ // `<dir>/page.png` resolves through the manifest like every other ref.+ const atlasLogical = source.resolveAddress?.(atlasRef) ?? atlasPath;+ const atlasDir = atlasLogical.substring(0, atlasLogical.lastIndexOf('/'));const rm = requireResourceManager();const textures = new Map<string, { glId: number; w: number; h: number }>();diff --git a/sdk/tests/packaged-runtime-address.test.ts b/sdk/tests/packaged-runtime-address.test.tsnew file mode 100644index 000000000..e9a38fa91--- /dev/null+++ b/sdk/tests/packaged-runtime-address.test.ts@@ -0,0 +1,56 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file packaged-runtime-address.test.ts+ * @brief addressOf / resolveAddress recovers the authored path a content-addressed+ * build hid — the directory a Spine atlas names its page PNG relative to.+ */+import { describe, it, expect } from 'vitest';+import { indexPackagedManifest, createPackagedAssetSource } from '../src/packagedRuntime';+import type { AddressableManifest } from '../src/asset/AddressableManifest';++// A content-addressed pack: the atlas and its page PNG are staged under hashed+// names, but each keeps `address` — the path it was authored at.+function manifest(): AddressableManifest {+ return {+ version: '2.0',+ groups: {+ main: {+ bundleMode: 'local',+ labels: [],+ assets: {+ '11111111-1111-4111-8111-111111111111': { path: 'assets/aaa111.atlas', address: 'assets/spine/hero.atlas', type: 'binary', size: 10, labels: [] },+ '22222222-2222-4222-8222-222222222222': { path: 'assets/bbb222.png', address: 'assets/spine/hero.png', type: 'texture', size: 20, labels: [] },+ },+ },+ },+ } as unknown as AddressableManifest;+}++describe('packaged addressOf / resolveAddress', () => {+ it('recovers the authored address from a staged (hashed) path', () => {+ const index = indexPackagedManifest(manifest());+ expect(index.addressOf('assets/aaa111.atlas')).toBe('assets/spine/hero.atlas');+ });++ it('recovers the authored address from a uuid ref', () => {+ const index = indexPackagedManifest(manifest());+ expect(index.addressOf('@uuid:11111111-1111-4111-8111-111111111111')).toBe('assets/spine/hero.atlas');+ expect(index.addressOf('11111111-1111-4111-8111-111111111111')).toBe('assets/spine/hero.atlas');+ });++ it('returns null for an unknown ref', () => {+ const index = indexPackagedManifest(manifest());+ expect(index.addressOf('assets/nope.atlas')).toBeNull();+ });++ it('the source exposes resolveAddress, so <atlasDir>/page resolves to the staged page', () => {+ const index = indexPackagedManifest(manifest());+ const source = createPackagedAssetSource(index, { backend: {} as never, decodePixels: (async () => ({ width: 0, height: 0, pixels: new Uint8Array() })) });+ // The atlas names its page "hero.png"; join it onto the atlas's authored dir,+ // then resolve — the way loadSpineScene does — and it lands on the staged file.+ const atlasAddr = source.resolveAddress!('assets/aaa111.atlas')!;+ const dir = atlasAddr.substring(0, atlasAddr.lastIndexOf('/'));+ expect(source.resolveRef!(`${dir}/hero.png`)).toBe('assets/bbb222.png');+ });+});