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(editor): edit viewport honors texture import settings (edit == play)

esengineef0f4253eded
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index d7ac2168c..9e085cf9f 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -1791,6 +1791,9 @@ function GenericAssetInspector({ path }: { path: string }) {
await window.estella.fs.write(path + '.meta', JSON.stringify(meta, null, 2) + '\n');
setDirty(false);
await ProjectStore.refreshAssets();
+ // Push filter/wrap to the live gl handle so the edit viewport updates now
+ // (no scene reload); a no-op for types/assets without a live texture.
+ if (type === 'texture' || type === 'sprite') ProjectStore.applyLiveTextureSettings(path);
Toasts.push('Import settings saved', 'info', 1400);
} catch (e) {
Toasts.push(`保存导入设置失败:${String(e)}`, 'error');
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 731d09f20..c81c51442 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { createStore } from 'zustand/vanilla';
-import { getComponent, Assets, migratePrefabData, extractPrefab, diffAgainstSource, applyOverridesToSource } from 'esengine';
+import { getComponent, Assets, migratePrefabData, extractPrefab, diffAgainstSource, applyOverridesToSource, setTextureParams, TextureFilter, TextureWrap } from 'esengine';
+import { readTextureImportSettings } from './assetImporter';
import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig } from 'esengine';
import { EngineHost } from '@/engine/EngineHost';
import { SceneModel } from '@/engine/SceneModel';
@@ -108,6 +109,10 @@ class ProjectStoreImpl {
/** path → uuid (reverse), so a Content Browser drag (which carries a path) can
* be turned into a portable `@uuid:` ref for the model. */
private readonly pathToUuid = new Map<string, string>();
+ /** uuid → the asset's `.meta` importer block, so the edit viewport applies the
+ * same texture filter/wrap the runtime does (edit == play), and the asset
+ * inspector's Save can push a live sampler update. */
+ private readonly uuidToImporter = new Map<string, Record<string, unknown>>();
/** ref → loaded `.esprefab` (PrefabData), for scene load-expand / save-collapse. */
private readonly prefabCache = new Map<string, PrefabData>();
/** The latest scene preload result; the Reconciler resolver reads handles from
@@ -372,7 +377,7 @@ class ProjectStoreImpl {
*/
private async buildAssetRegistry(): Promise<void> {
if (!this.state) return;
- let entries: { uuid: string; path: string }[];
+ let entries: { uuid: string; path: string; importer?: Record<string, unknown> }[];
try {
({ entries } = (await window.estella.project.scanAssets()).index);
} catch (err) {
@@ -381,20 +386,49 @@ class ProjectStoreImpl {
}
this.uuidToPath.clear();
this.pathToUuid.clear();
+ this.uuidToImporter.clear();
this.prefabCache.clear();
for (const e of entries) {
const uuid = e.uuid.toLowerCase();
this.uuidToPath.set(uuid, e.path);
this.pathToUuid.set(e.path, uuid);
+ if (e.importer) this.uuidToImporter.set(uuid, e.importer);
}
const assets = EngineHost.getResource(Assets);
if (assets) {
assets.baseUrl = 'estella://project';
assets.setAssetRefResolver((ref) => this.resolveRef(ref));
+ // Edit viewport honors each texture's `.meta` filter/wrap at load — the same
+ // settings the runtime applies (was runtime-only, so edit ≠ play before).
+ assets.setTextureImportSettingsResolver((ref) => this.textureImportFor(ref));
}
}
+ /** The texture filter/wrap for a ref (`@uuid:` or path), from its `.meta`
+ * importer — the shape `Assets`'s TextureLoader consumes. Undefined ⇒ defaults. */
+ private textureImportFor(ref: string): ReturnType<typeof readTextureImportSettings> {
+ const uuid = ref.startsWith(UUID_PREFIX)
+ ? ref.slice(UUID_PREFIX.length).toLowerCase()
+ : this.pathToUuid.get(ref);
+ return readTextureImportSettings(uuid ? this.uuidToImporter.get(uuid) : undefined);
+ }
+
+ /** Push a texture's just-saved import settings to its LIVE gl handle so the edit
+ * viewport reflects a filter/wrap change immediately — no scene reload / sprite
+ * repoint (the handle is updated in place; sprites keep referencing it). Call
+ * after the asset inspector writes the `.meta` + refreshAssets. */
+ applyLiveTextureSettings(path: string): void {
+ const uuid = this.pathToUuid.get(path);
+ const s = readTextureImportSettings(uuid ? this.uuidToImporter.get(uuid) : undefined);
+ const handle = uuid ? EngineHost.getResource(Assets)?.getTexture(UUID_PREFIX + uuid)?.handle : undefined;
+ if (!s || !handle) return;
+ const filter = s.filter === 'nearest' ? TextureFilter.Nearest : TextureFilter.Linear;
+ const wrap =
+ s.wrap === 'clamp' ? TextureWrap.ClampToEdge : s.wrap === 'mirror' ? TextureWrap.MirroredRepeat : TextureWrap.Repeat;
+ setTextureParams(handle, filter, filter, wrap, wrap);
+ }
+
/** Resolve a serialized asset ref to a project-relative path for the engine
* loader: `@uuid:` → path (null if unknown); a plain path passes through. */
private resolveRef(ref: string): string | null {
diff --git a/desktop/src/project/assetImporter.ts b/desktop/src/project/assetImporter.ts
index 37e7b6860..6fd2cba4d 100644
--- a/desktop/src/project/assetImporter.ts
+++ b/desktop/src/project/assetImporter.ts
@@ -115,6 +115,18 @@ export function buildImporterComponent(type: string, importer: Record<string, un
return { name: 'Import Settings', label: 'Import Settings', fields };
}
+/** A texture's sampler settings, in the string shape the engine's TextureLoader
+ * and the runtime importer-resolver consume (filterMode/wrapMode → filter/wrap).
+ * Undefined when the `.meta` carries neither ⇒ loader defaults. */
+export function readTextureImportSettings(
+ importer: Record<string, unknown> | undefined,
+): { filter?: 'linear' | 'nearest'; wrap?: 'repeat' | 'clamp' | 'mirror' } | undefined {
+ if (!importer) return undefined;
+ const filter = importer.filterMode as 'linear' | 'nearest' | undefined;
+ const wrap = importer.wrapMode as 'repeat' | 'clamp' | 'mirror' | undefined;
+ return filter || wrap ? { filter, wrap } : undefined;
+}
+
/** Apply one inspector edit to a copy of the `importer` block (dotted keys →
* nested), returning the new block. Pure — the caller owns dirty/save. */
export function applyImporterEdit(
diff --git a/desktop/tests/asset-importer.test.ts b/desktop/tests/asset-importer.test.ts
index ab867acd6..fb518e286 100644
--- a/desktop/tests/asset-importer.test.ts
+++ b/desktop/tests/asset-importer.test.ts
@@ -13,6 +13,7 @@ import {
buildImporterComponent,
applyImporterEdit,
hasImporterSettings,
+ readTextureImportSettings,
} from '../src/project/assetImporter';
describe('importerDefaults (import-time .meta)', () => {
@@ -60,6 +61,18 @@ describe('buildImporterComponent (inspector fields)', () => {
});
});
+describe('readTextureImportSettings (edit-viewport = runtime)', () => {
+ it('maps filterMode/wrapMode to the loader filter/wrap shape', () => {
+ expect(readTextureImportSettings({ filterMode: 'nearest', wrapMode: 'clamp' })).toEqual({ filter: 'nearest', wrap: 'clamp' });
+ expect(readTextureImportSettings({ filterMode: 'linear' })).toEqual({ filter: 'linear', wrap: undefined });
+ });
+ it('is undefined when neither is present (loader defaults) or no importer', () => {
+ expect(readTextureImportSettings({ maxSize: 2048 })).toBeUndefined();
+ expect(readTextureImportSettings(undefined)).toBeUndefined();
+ expect(readTextureImportSettings({})).toBeUndefined();
+ });
+});
+
describe('applyImporterEdit (dotted keys → nested, pure)', () => {
it('sets a nested key without mutating the input', () => {
const before = { filterMode: 'linear', sliceBorder: { left: 0, right: 0 } };