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(editor): one binding answers what a live asset handle is

esengine3344786ee88a
diff --git a/desktop/scripts/headless-verify.mjs b/desktop/scripts/headless-verify.mjs
index fa18ef0a6..10818c008 100644
--- a/desktop/scripts/headless-verify.mjs
+++ b/desktop/scripts/headless-verify.mjs
@@ -20,6 +20,7 @@
* ESTELLA_VERIFY_GRID editor-grid on/off pixel-diff assertion (value = spacing)
* ESTELLA_VERIFY_DEPTH_LAYERS bitmask of layers resolved by depth (2.5D)
* ESTELLA_VERIFY_PREFAB .esprefab instantiated into the scene after load
+ * ESTELLA_VERIFY_SET_FIELD one inspector field written after load (JSON)
*/
import { app, BrowserWindow } from 'electron';
import http from 'node:http';
@@ -169,6 +170,7 @@ app.whenReady().then(async () => {
let meshAsset = null;
let meshMaterial = null;
let meshPrefab = null;
+ let setField = null;
await exec('window.__estellaHeadless.ready');
const entityCount = await exec(
`window.__estellaHeadless.api.loadScene(${JSON.stringify(SCENE)}, ${JSON.stringify(MANIFEST)})`,
@@ -264,6 +266,23 @@ app.whenReady().then(async () => {
})()`);
}
+ // ESTELLA_VERIFY_SET_FIELD={"entity","component","key","value"} writes one
+ // inspector field the way the editor's own door does, then waits: an asset
+ // assigned after load is COLD, and reaching the World is an async load away.
+ if (process.env.ESTELLA_VERIFY_SET_FIELD) {
+ const spec = JSON.parse(process.env.ESTELLA_VERIFY_SET_FIELD);
+ setField = await exec(`(async () => {
+ const api = window.__estellaHeadless.api;
+ api.setField(${JSON.stringify(spec.entity)}, ${JSON.stringify(spec.component)},
+ ${JSON.stringify(spec.key)}, "asset", ${JSON.stringify(spec.value)});
+ for (let i = 0; i < 40; i++) {
+ await api.step(1, 1 / 60);
+ await new Promise((r) => setTimeout(r, 16));
+ }
+ return { wrote: ${JSON.stringify(spec.key)} };
+ })()`);
+ }
+
// ESTELLA_VERIFY_PREFAB=<path> instantiates a prefab into the scene. For an
// import's products this is the whole chain: the prefab names the geometry,
// the image and the tint, and nothing here repeats what it should say.
@@ -511,7 +530,7 @@ app.whenReady().then(async () => {
return { differingPixels: differing, ok: differing > 300 };
`);
}
- finish({ ok: true, entityCount, drawCalls, capture, expect, resize, preview, grid, deviceLoss, meshResident, meshAsset, meshMaterial, meshPrefab }, server);
+ finish({ ok: true, entityCount, drawCalls, capture, expect, resize, preview, grid, deviceLoss, meshResident, meshAsset, meshMaterial, meshPrefab, setField }, server);
} catch (e) {
finish({ ok: false, error: String((e && e.stack) || e) }, server);
}
diff --git a/desktop/src/engine/AssetBinding.ts b/desktop/src/engine/AssetBinding.ts
new file mode 100644
index 000000000..668dbdbad
--- /dev/null
+++ b/desktop/src/engine/AssetBinding.ts
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The edit realm's one answer to "what live handle is this asset ref?".
+ *
+ * Two doors open a scene here — the project transport (ProjectStore) and the
+ * dev/automation one (SceneLoader). Resolution belongs to the realm, not to
+ * whichever of them opened the file, or they drift.
+ */
+import { Assets, type AssetsData } from 'esengine';
+import { EngineHost } from './EngineHost';
+import { Reconciler } from './Reconciler';
+import { SceneStore } from './SceneStore';
+import { AssetRegistry, refUuid } from '@/project/AssetRegistry';
+import { ASSET_SLOTS, type SlotRecord } from '@/project/assetSlots';
+
+/** The handle maps a scene preload produces — the subset this resolver reads. */
+export interface PreloadHandles {
+ textureHandles: Map<string, number>;
+ materialHandles: Map<string, number>;
+ fontHandles: Map<string, number>;
+ meshHandles: Map<string, number>;
+}
+
+const emptyHandles = (): PreloadHandles => ({
+ textureHandles: new Map(), materialHandles: new Map(),
+ fontHandles: new Map(), meshHandles: new Map(),
+});
+
+class AssetBindingImpl {
+ private preload: PreloadHandles | null = null;
+
+ /** Adopt a scene preload's handles as what refs resolve against. */
+ adopt(handles: PreloadHandles): void {
+ this.preload = handles;
+ }
+
+ /** Wire this binding into the Reconciler. Idempotent; both scene doors call it. */
+ install(): void {
+ Reconciler.setAssetResolver((ref) => this.handleFor(ref));
+ Reconciler.setRefPathResolver((ref) => AssetRegistry.refPath(ref));
+ Reconciler.setAssetTouchListener((ref, slot) => this.hotLoad(ref, slot));
+ }
+
+ /** The live GL handle for a ref. Textures read the engine's live cache (so a
+ * just-assigned one resolves); the rest fall back to the scene preload. */
+ handleFor(ref: string): number {
+ const tex = EngineHost.getResource(Assets)?.getTexture(ref);
+ if (tex) return tex.handle;
+ const uuid = refUuid(ref);
+ const path = uuid !== null ? AssetRegistry.pathForUuid(uuid) : ref;
+ const r = this.preload;
+ if (!path || !r) return 0;
+ return r.materialHandles.get(path) ?? r.fontHandles.get(path)
+ ?? r.meshHandles.get(path) ?? 0;
+ }
+
+ /** The live material handle for @p path, or 0 — the Material Editor pushes
+ * edits onto it so the viewport reflects them. */
+ materialHandle(path: string): number {
+ return this.preload?.materialHandles.get(path) ?? 0;
+ }
+
+ /**
+ * The async half: a projection resolved `ref` COLD (assigned after the scene
+ * preload, or re-written on disk). Load it through its slot's loader, then
+ * re-project what references it. Deduped per registry generation, so a broken
+ * ref cannot re-fetch forever.
+ */
+ hotLoad(ref: string, fieldType: string): void {
+ const path = AssetRegistry.refPath(ref);
+ if (path === null) return; // unknown uuid — diagnostics reports it; nothing to load
+ const key = `${fieldType}:${path}`;
+ if (AssetRegistry.hotLoadStartedFor(key)) return;
+ AssetRegistry.markHotLoadStarted(key);
+ const assets = EngineHost.getResource(Assets);
+ if (!assets) return;
+ void this.loadForSlot(assets, fieldType, ref, path)
+ .then(() => {
+ AssetRegistry.clearLoadFailure(path);
+ Reconciler.reprojectRefs((r) => AssetRegistry.refPath(r) === path);
+ SceneStore.poke();
+ })
+ .catch((err) => {
+ const msg = err instanceof Error ? err.message : String(err);
+ AssetRegistry.noteLoadFailure(path, msg);
+ console.error(`[assets] live load of ${fieldType} "${path}" failed: ${msg}`);
+ });
+ }
+
+ /** Load `ref` through the loader its slot type names — the same loaders the
+ * scene-open preload dispatches to (one loading truth, two trigger times). */
+ private loadForSlot(assets: AssetsData, fieldType: string, ref: string,
+ path: string): Promise<unknown> {
+ const def = ASSET_SLOTS[fieldType];
+ if (!def) return Promise.reject(new Error(`no live loader for asset slot type "${fieldType}"`));
+ const loaded = def.load(assets, ref, path);
+ if (!def.record) return loaded;
+ const kind = def.record;
+ return loaded.then((r) => this.record(kind, path, (r as { handle: number }).handle));
+ }
+
+ /** Record a hot-loaded handle where the incremental resolver looks it up
+ * (these slots have no live engine-side cache getter like textures). */
+ private record(kind: SlotRecord, path: string, handle: number): void {
+ if (!this.preload) this.preload = emptyHandles();
+ const maps = this.preload;
+ const target = kind === 'material' ? maps.materialHandles
+ : kind === 'font' ? maps.fontHandles : maps.meshHandles;
+ target.set(path, handle);
+ }
+}
+
+export const AssetBinding = new AssetBindingImpl();
diff --git a/desktop/src/engine/SceneLoader.ts b/desktop/src/engine/SceneLoader.ts
index b632df95f..7942c6e7d 100644
--- a/desktop/src/engine/SceneLoader.ts
+++ b/desktop/src/engine/SceneLoader.ts
@@ -3,7 +3,7 @@
import { loadSceneData, Assets } from 'esengine';
import type { App, SceneData } from 'esengine';
import { SceneModel } from './SceneModel';
-import { Reconciler } from './Reconciler';
+import { AssetBinding } from './AssetBinding';
import { EditorHistory } from './EditorHistory';
import { PerfMonitor } from './PerfMonitor';
import { loadEditorSpine } from './spineLoad';
@@ -45,9 +45,11 @@ export const SceneLoader = {
const result = await assets.preloadSceneAssets(raw);
resolved = JSON.parse(JSON.stringify(raw)) as SceneData; // resolveSceneAssetPaths mutates
assets.resolveSceneAssetPaths(resolved, result);
- // Incremental recreate (duplicate / undo) re-resolves textures from the
- // engine's live cache (just loaded above).
- Reconciler.setAssetResolver((ref) => assets.getTexture(ref)?.handle ?? 0);
+ // The realm's own binding, the same one the project transport installs:
+ // resolving a ref is not this door's business to define, and defining it
+ // here is how this path came to resolve textures and nothing else.
+ AssetBinding.adopt(result);
+ AssetBinding.install();
}
const map = PerfMonitor.measure('scene.load', () => loadSceneData(app.world, resolved as SceneDataArg));
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 7a1e8304b..ef45a1a1a 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -4,7 +4,7 @@ import { createStore } from 'zustand/vanilla';
import { getComponent, Assets, migratePrefabData, extractPrefab, flattenPrefab, collectExternalEntityRefs, collapseInstance, applyDeltaToSource, buildVariant, textureImportSettingsFrom, Renderer, RETIRED_COMPONENT_TYPES, parseThemeOverrides, resolveAssetGroup, folderGroupMode, withFolderGroup, folderAlwaysInclude, withFolderAlwaysInclude, withActiveRemoteRoot, Audio, applyAudioProjectConfig } from 'esengine';
import { applyImporterEdit } from './assetImporter';
import { importerDefaults } from '../../../pipeline/src/project/importSettings';
-import { AssetRegistry, UUID_PREFIX, refUuid, type AssetEntryLite } from './AssetRegistry';
+import { AssetRegistry, UUID_PREFIX, type AssetEntryLite } from './AssetRegistry';
import { imageSize } from './imageSize';
import { PrefabCache } from './PrefabCache';
import {
@@ -12,7 +12,7 @@ import {
type RuntimeProjectConfig,
} from '../../../pipeline/src/project/runtimeConfig';
import type { ParsedTextureImportSettings } from 'esengine';
-import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig, AudioProjectConfig, AssetsData, ThemeOverrides, AddressableManifest, AssetGroupsConfig, AssetGroupMode } from 'esengine';
+import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig, AudioProjectConfig, ThemeOverrides, AddressableManifest, AssetGroupsConfig, AssetGroupMode } from 'esengine';
import { EngineHost } from '@/engine/EngineHost';
import { applyWidgetTheme } from '@/engine/widgetTheme';
import { bootProfiler } from '@/engine/bootProfiler';
@@ -37,7 +37,6 @@ import { installLocaleKeyEnumSource } from './localeKeys';
import { setProjectActions, type ProjectActionSchema } from '@/ai/actionCatalog';
import { setAssetRefProblemResolver } from '@/engine/EditorControlSurface';
import { installSkeletalSync, type SkeletalTransport } from '@/engine/skeletalSync';
-import { SceneStore } from '@/engine/SceneStore';
import { useSelection } from '@/store/selectionStore';
import { usePrefabConflicts } from '@/store/prefabConflicts';
import { Toasts } from '@/store/Toasts';
@@ -45,7 +44,8 @@ import { confirmDiscard } from './discardGuard';
import { confirm } from '@/components/confirm';
import { previewApply } from './applyPreview';
import { t } from '@/i18n';
-import { ASSET_SLOTS, metaTypeToSlot } from '@/project/assetSlots';
+import { metaTypeToSlot } from '@/project/assetSlots';
+import { AssetBinding } from '@/engine/AssetBinding';
import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, resolveScripts, DEFAULT_SCRIPTS, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, SORTING_LAYER_COUNT, trimSortingLayers, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type SteamPackaging, type ProjectScripts, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform, type AcceptanceCriterion } from '../../../pipeline/src/project/format';
import { useEditorMode } from '@/store/editorModeStore';
import { PlayInspect } from '@/engine/PlayInspect';
@@ -73,13 +73,6 @@ function toDocumentEntity(e: ProcessedEntity): DocumentEntity {
* The lossless model keeps `@uuid:` refs verbatim, so save stays portable.
*/
-/** The subset of the engine's SceneAssetResult the Reconciler resolver reads. */
-interface PreloadResult {
- textureHandles: Map<string, number>;
- materialHandles: Map<string, number>;
- fontHandles: Map<string, number>;
-}
-
const NO_SCREEN_PRESETS: ScreenPreset[] = [];
interface ProjectState {
@@ -181,7 +174,6 @@ class ProjectStoreImpl {
private projectGeneration = 0;
/** The latest scene preload result; the Reconciler resolver reads handles from
* it for entities recreated incrementally (duplicate / undo / play-stop). */
- private lastAssetResult: PreloadResult | null = null;
/**
* What the open scene acquired, so the NEXT open can give it back.
*
@@ -541,7 +533,7 @@ class ProjectStoreImpl {
const result = await bootProfiler.phase('preloadSceneAssets', () => assets.preloadSceneAssets(expandedRaw));
resolved = JSON.parse(JSON.stringify(expandedRaw)) as SceneData; // resolveSceneAssetPaths mutates
assets.resolveSceneAssetPaths(resolved, result);
- this.lastAssetResult = result; // narrowed to the handle maps the resolver reads
+ AssetBinding.adopt(result);
}
// A scene is a session document: replacing it clears the SCENE's history
@@ -556,11 +548,9 @@ class ProjectStoreImpl {
// Incremental recreate (duplicate / undo / play-stop) re-resolves @uuid:→handle
// from the same preload result — for all types, not just textures. Spine
// slots resolve to project paths instead (they stay strings in the World).
- Reconciler.setAssetResolver((ref) => this.handleForRef(ref));
- Reconciler.setRefPathResolver((ref) => AssetRegistry.refPath(ref));
- // A projection that resolves COLD (assigned after the scene-open preload)
- // hands its ref here: async load through the engine loaders, re-project.
- Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
+ // One binding for both scene doors: the resolver, the path resolver and the
+ // cold-ref loader are the realm's, not this transport's.
+ AssetBinding.install();
// Skeletal bindings (skeleton/atlas/pages → the runtime's manager) are a live
// projection of the model, driven by model events: adopt's `reset` performs the
// initial bind, and later ref/field edits keep the viewport true (see
@@ -610,9 +600,7 @@ class ProjectStoreImpl {
await this.buildAssetRegistry(); // keep the uuid→path registry current for new refs
EditorHistory.clearScene();
useSelection.getState().select(null);
- Reconciler.setAssetResolver((ref) => this.handleForRef(ref));
- Reconciler.setRefPathResolver((ref) => AssetRegistry.refPath(ref));
- Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
+ AssetBinding.install();
installSkeletalSync(this.skeletalTransport());
Reconciler.adopt(blank, blank); // no @uuid: refs → resolved === raw
EngineHost.syncEditorViewToScene();
@@ -890,69 +878,6 @@ class ProjectStoreImpl {
};
}
- /** The live GL handle for a uuid. Textures read the engine's live cache (so a
- * just-assigned texture resolves); material/font fall back to the scene preload. */
- private handleForRef(ref: string): number {
- const tex = EngineHost.getResource(Assets)?.getTexture(ref);
- if (tex) return tex.handle;
- const uuid = refUuid(ref);
- const path = uuid !== null ? AssetRegistry.pathForUuid(uuid) : ref;
- const r = this.lastAssetResult;
- if (!path || !r) return 0;
- return r.materialHandles.get(path) ?? r.fontHandles.get(path) ?? 0;
- }
-
- /**
- * The async half of live asset resolution (the Reconciler's touch listener).
- * A projection just resolved `ref` COLD — the scene-open preload never saw it
- * (assigned after load: surface setField, the picker popover, a hot-created
- * asset). Load it through the engine's own loader for its slot type, then
- * re-project the components that reference it; failures are LOUD and recorded
- * for diagnostics. Deduped per registry generation so a broken ref can't
- * re-fetch forever.
- */
- private hotLoadAsset(ref: string, fieldType: string): void {
- const path = AssetRegistry.refPath(ref);
- if (path === null) return; // unknown uuid — diagnostics reports it; nothing to load
- const key = `${fieldType}:${path}`;
- if (AssetRegistry.hotLoadStartedFor(key)) return;
- AssetRegistry.markHotLoadStarted(key);
- const assets = EngineHost.getResource(Assets);
- if (!assets) return;
- void this.loadForSlot(assets, fieldType, ref, path)
- .then(() => {
- AssetRegistry.clearLoadFailure(path);
- Reconciler.reprojectRefs((r) => AssetRegistry.refPath(r) === path);
- SceneStore.poke();
- })
- .catch((err) => {
- const msg = err instanceof Error ? err.message : String(err);
- AssetRegistry.noteLoadFailure(path, msg);
- console.error(`[assets] live load of ${fieldType} "${path}" failed: ${msg}`);
- });
- }
-
- /** Load `ref` through the loader its slot type names — the same loaders the
- * scene-open preload dispatches to (one loading truth, two trigger times). */
- private loadForSlot(assets: AssetsData, fieldType: string, ref: string, path: string): Promise<unknown> {
- const def = ASSET_SLOTS[fieldType];
- if (!def) return Promise.reject(new Error(`no live loader for asset slot type "${fieldType}"`));
- const loaded = def.load(assets, ref, path);
- if (!def.record) return loaded;
- const kind = def.record;
- return loaded.then((r) => this.recordHandle(kind, path, (r as { handle: number }).handle));
- }
-
- /** Record a hot-loaded material/font handle where the incremental resolver
- * looks them up (they have no live engine-side cache getter like textures). */
- private recordHandle(kind: 'material' | 'font', path: string, handle: number): void {
- if (!this.lastAssetResult) {
- this.lastAssetResult = { textureHandles: new Map(), materialHandles: new Map(), fontHandles: new Map() };
- }
- const maps = this.lastAssetResult;
- (kind === 'material' ? maps.materialHandles : maps.fontHandles).set(path, handle);
- }
-
/**
* Content changed ON DISK (fs watcher) — keep the live realm coherent: drop
* every stale cache entry for the changed assets and, when something in the
@@ -975,7 +900,7 @@ class ProjectStoreImpl {
// through the same slot-typed path a cold projection uses.
AssetRegistry.forgetHotLoadsFor(rel);
const slot = metaTypeToSlot(AssetRegistry.typeForUuid(uuid));
- if (slot) this.hotLoadAsset(UUID_PREFIX + uuid, slot);
+ if (slot) AssetBinding.hotLoad(UUID_PREFIX + uuid, slot);
}
}
@@ -989,7 +914,7 @@ class ProjectStoreImpl {
* preload), or 0 if the material isn't loaded in the current scene. The Material Editor
* uses it to push live edits onto the running material so the viewport reflects them. */
materialHandle(path: string): number {
- return this.lastAssetResult?.materialHandles.get(path) ?? 0;
+ return AssetBinding.materialHandle(path);
}
/** Load a `.esprefab` asset (PrefabData) by ref, cached. The scene load-expand
@@ -2359,14 +2284,12 @@ class ProjectStoreImpl {
const result = await assets.preloadSceneAssets(raw);
resolved = JSON.parse(JSON.stringify(raw)) as SceneData;
assets.resolveSceneAssetPaths(resolved, result);
- this.lastAssetResult = result;
+ AssetBinding.adopt(result);
}
EditorHistory.clearScene();
useSelection.getState().select(null);
usePrefabConflicts.getState().clear(); // a prefab document has no scene instances
- Reconciler.setAssetResolver((ref) => this.handleForRef(ref));
- Reconciler.setRefPathResolver((ref) => AssetRegistry.refPath(ref));
- Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
+ AssetBinding.install();
installSkeletalSync(this.skeletalTransport());
Reconciler.adopt(raw, resolved);
EngineHost.syncEditorViewToScene();
diff --git a/desktop/src/project/assetSlots.ts b/desktop/src/project/assetSlots.ts
index a758fa495..328f42286 100644
--- a/desktop/src/project/assetSlots.ts
+++ b/desktop/src/project/assetSlots.ts
@@ -12,8 +12,8 @@
import type { AssetsData } from 'esengine';
/** Slots whose resolved `{handle}` must be recorded where the incremental resolver
- * looks it up — material/font have no live engine-side cache getter like textures. */
-export type SlotRecord = 'material' | 'font';
+ * looks it up — these have no live engine-side cache getter like textures. */
+export type SlotRecord = 'material' | 'font' | 'mesh';
export interface AssetSlotDef {
/** `.meta` type vocabulary values that resolve to this slot. `font` folds both
@@ -32,6 +32,9 @@ export const ASSET_SLOTS: Record<string, AssetSlotDef> = {
texture: { metaTypes: ['texture'], load: (a, ref) => a.loadTexture(ref) },
material: { metaTypes: ['material'], load: (a, ref) => a.loadMaterial(ref), record: 'material' },
font: { metaTypes: ['font', 'bitmapFont'], load: (a, ref) => a.loadFont(ref), record: 'font' },
+ // GPU geometry: a handle like a material's, so a mesh assigned after the
+ // scene-open preload (or re-imported on disk) reaches the World the same way.
+ mesh: { metaTypes: ['mesh'], load: (a, _ref, path) => a.load('mesh', path), record: 'mesh' },
audio: { metaTypes: ['audio'], load: (a, ref) => a.loadAudio(ref) },
// Video streams at runtime (play-mode only) — no edit-mode handle to preload.
video: { metaTypes: ['video'], load: () => Promise.resolve() },
diff --git a/desktop/tests/asset-slots.test.ts b/desktop/tests/asset-slots.test.ts
index c423f64bc..7b1762e9e 100644
--- a/desktop/tests/asset-slots.test.ts
+++ b/desktop/tests/asset-slots.test.ts
@@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, it, expect } from 'vitest';
import { ASSET_SLOTS, metaTypeToSlot } from '../src/project/assetSlots';
+import { getComponentRegistry, getComponentAssetFieldDescriptors } from 'esengine';
describe('ASSET_SLOTS', () => {
it('metaTypeToSlot only ever returns a slot that exists in the table', () => {
@@ -39,6 +40,7 @@ describe('ASSET_SLOTS', () => {
expect(metaTypeToSlot('statemachine')).toBe('statemachine');
expect(metaTypeToSlot('animatorcontroller')).toBe('animatorcontroller');
expect(metaTypeToSlot('behaviortree')).toBe('behaviortree');
+ expect(metaTypeToSlot('mesh')).toBe('mesh');
});
it('returns null for types with no component slot', () => {
@@ -49,8 +51,23 @@ describe('ASSET_SLOTS', () => {
expect(metaTypeToSlot('unknown-type')).toBeNull();
});
- it('only material/font capture a handle (the slots with no live cache getter)', () => {
+ it('the handle slots are the ones with no live cache getter', () => {
const recorded = Object.entries(ASSET_SLOTS).filter(([, d]) => d.record).map(([s]) => s).sort();
- expect(recorded).toEqual(['font', 'material']);
+ expect(recorded).toEqual(['font', 'material', 'mesh']);
+ });
+
+ it('every asset field a component declares has a slot to load it from', () => {
+ // A field the Inspector offers but nothing can load resolves to handle 0 —
+ // the asset silently missing, which is how mesh shipped before this entry.
+ const declared = new Set<string>();
+ for (const name of getComponentRegistry().keys()) {
+ for (const f of getComponentAssetFieldDescriptors(name)) declared.add(f.type);
+ }
+ // Spine halves load through their own two-phase manager, not a slot.
+ declared.delete('spine-skeleton');
+ declared.delete('spine-atlas');
+ for (const type of declared) {
+ expect(ASSET_SLOTS[type], `no slot for asset field type "${type}"`).toBeDefined();
+ }
});
});
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index d507536cd..2ab261818 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -140,6 +140,10 @@ export const SCENES = [
// normals the engine's vertex stage hands it. RED, so the fallback (the mesh
// shader, taken when a variant fails) cannot pass for it — that draws white.
{ id: "mesh-material-lit", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_MESH_ASSET: "/scenes/lit-triangles.esmesh", ESTELLA_VERIFY_MESH_MATERIAL: "/scenes/mesh-material-lit/litmat.esmaterial", ESTELLA_VERIFY_SCENE: "/scenes/mesh-lit.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-lit.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,0,0],\"tol\":40}]" } },
+ // A mesh assigned IN THE EDITOR: a cold ref reaches the World only through the
+ // live loader + re-projection. The quad covers the gap between the scene's own
+ // two triangles, so the frame says which geometry is drawn.
+ { id: "mesh-assign", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SET_FIELD: "{\"entity\":1,\"component\":\"Mesh2D\",\"key\":\"mesh\",\"value\":\"/scenes/textured-quad.esmesh\"}", ESTELLA_VERIFY_SCENE: "/scenes/mesh2d.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh2d.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,255,255],\"tol\":40},{\"x\":0.30,\"y\":0.556,\"rgb\":[255,255,255],\"tol\":40}]" } },
// A normal map over FLAT normals: the quad faces the viewer, so without the map
// both halves take the same light. Its texels point -X and +X, so the lit half
// and the unlit one are the tangent frame, derived per pixel from derivatives.