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.

test(assets): a scene naming geometry reaches a handle

esenginebae0eaf1d807
diff --git a/sdk/tests/assets.test.ts b/sdk/tests/assets.test.ts
index 2de3cd2e1..41dbe00b5 100644
--- a/sdk/tests/assets.test.ts
+++ b/sdk/tests/assets.test.ts
@@ -5,6 +5,7 @@ import { Assets } from '../src/asset/Assets';
import { Catalog, type CatalogData } from '../src/asset/Catalog';
import type { Backend } from '../src/asset/Backend';
import type { AssetLoader, LoadContext } from '../src/asset/AssetLoader';
+import type { SceneData } from '../src/scene/scene';
const mockModule = {
_malloc: vi.fn(() => 0),
@@ -146,3 +147,34 @@ describe('Assets', () => {
});
});
});
+
+// A scene naming geometry has to reach a handle the same way it reaches a
+// texture. Asserted end to end through the real preload + bind, because the
+// gap this closes was one layer knowing about mesh and the next not.
+describe('Assets: mesh references in a scene', () => {
+ it('preloads an .esmesh and binds its handle onto the component', async () => {
+ const backend = createMockBackend();
+ const assets = Assets.create({ backend, module: mockModule });
+
+ assets.register({
+ type: 'mesh',
+ extensions: ['.esmesh'],
+ load: async () => ({ handle: 77 }),
+ unload: () => {},
+ } as unknown as AssetLoader<{ handle: number }>);
+
+ const scene = {
+ version: '1.0', name: 'meshscene',
+ entities: [{
+ id: 1, name: 'e1', parent: null, children: [],
+ components: [{ type: 'Mesh2D', data: { mesh: 'ship.esmesh' } }],
+ }],
+ } as unknown as SceneData;
+
+ const result = await assets.preloadSceneAssets(scene);
+ expect(result.meshHandles.get('ship.esmesh')).toBe(77);
+
+ assets.resolveSceneAssetPaths(scene, result);
+ expect(scene.entities[0]!.components[0]!.data.mesh).toBe(77);
+ });
+});
diff --git a/sdk/tests/discoverAssets.test.ts b/sdk/tests/discoverAssets.test.ts
index cf57618ae..18d6ac9db 100644
--- a/sdk/tests/discoverAssets.test.ts
+++ b/sdk/tests/discoverAssets.test.ts
@@ -13,6 +13,7 @@ const SPRITE_NAME = 'DiscoverTest_Sprite';
const AUDIO_NAME = 'DiscoverTest_Audio';
const SPINE_NAME = 'DiscoverTest_Spine';
const SM_NAME = 'DiscoverTest_StateMachine';
+const MESH_NAME = 'DiscoverTest_Mesh';
beforeEach(() => {
clearUserComponents();
@@ -28,6 +29,10 @@ beforeEach(() => {
],
});
+ defineComponent(MESH_NAME, { mesh: '' }, {
+ assetFields: [{ field: 'mesh', type: 'mesh' }],
+ });
+
defineComponent(AUDIO_NAME, {
clip: '',
}, {
@@ -79,6 +84,19 @@ describe('discoverSceneAssets', () => {
expect(getAssetPathsByType(refs, 'material')).toEqual(new Set(['default.mat']));
});
+ // The whole point of an asset type: a scene naming geometry has to reach the
+ // preload, or the cook culls the .esmesh and the frame draws nothing.
+ it('discovers a mesh reference', () => {
+ const scene = makeScene([{
+ id: 1, name: 'e1', parent: null, children: [],
+ components: [{ type: MESH_NAME, data: { mesh: 'ship.esmesh' } }],
+ }]);
+
+ const refs = discoverSceneAssets(scene);
+
+ expect(getAssetPathsByType(refs, 'mesh')).toEqual(new Set(['ship.esmesh']));
+ });
+
it('discovers spine paired fields', () => {
const scene = makeScene([{
id: 1, name: 'e1', parent: null, children: [],