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): saving an import setting remakes what it decides

esengine865d30151adc
diff --git a/desktop/scripts/editor-checks/model-reimport.mjs b/desktop/scripts/editor-checks/model-reimport.mjs
index cb5ed467c..ba96d3296 100644
--- a/desktop/scripts/editor-checks/model-reimport.mjs
+++ b/desktop/scripts/editor-checks/model-reimport.mjs
@@ -95,15 +95,13 @@ export async function run(ed) {
return check.failures;
}
- const doc = JSON.parse(await readFile(meta, 'utf8'));
- doc.importer.scale = 64;
- await writeFile(meta, JSON.stringify(doc, null, 2));
- // The setting decides a product, so the product is re-made: touching the
- // source is what a user's Reimport does through the same door.
- await writeFile(source, gltf());
+ // Set the way the inspector sets it — the setting decides a product, so
+ // writing it has to remake that product with no further prompting.
+ await ed.call('set_import_settings',
+ { path: 'assets/models/robot.gltf', patch: { scale: 64 } }, 60000);
check(
await until(ed, prefab, (p) => p.entities?.[0]?.components?.[0]?.data?.scale?.x === 64),
- 'the edited scale never reached the prefab — the re-import does not read the settings',
+ 'the edited scale never reached the prefab — saving a setting does not remake its product',
);
return check.failures;
diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjs
index c4617081a..8ebdbe835 100644
--- a/desktop/shared/toolCatalog.mjs
+++ b/desktop/shared/toolCatalog.mjs
@@ -510,7 +510,7 @@ const ATOMS = [
description: 'Patch an asset\'s .meta import settings and persist. Keys are DOTTED paths into the importer block, matching the inspector field keys — a texture\'s 9-slice border is '
+ '{"sliceBorder.left":12,"sliceBorder.right":12,"sliceBorder.top":12,"sliceBorder.bottom":12}; filter/wrap are {"filterMode":"nearest","wrapMode":"clamp"}. '
+ 'These live in IMPORT, not on a component: a UIVisual set to NineSlice takes its border from texture metadata, so this is what makes frames and buttons stretch correctly. '
- + 'Re-registers the asset and updates the live texture. Returns the resulting importer block.',
+ + 'Re-registers the asset, updates the live texture, and RE-IMPORTS an asset whose products a setting decides (a model\'s scale). Returns the resulting importer block.',
schema: obj({ path: { type: 'string' }, patch: { type: 'object' } }, ['path', 'patch']),
method: 'setImportSettings', args: (i) => [i.path, i.patch], root: 'editor' },
{ name: 'read_project_file',
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 6bcba9aa6..33689744a 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -1964,15 +1964,12 @@ function GenericAssetInspector({ path }: { path: string }) {
const save = async () => {
try {
- const meta = JSON.parse(await window.estella.fs.read(path + '.meta'));
- meta.importer = importerRef.current;
- await window.estella.fs.write(path + '.meta', JSON.stringify(meta, null, 2) + '\n');
+ // Through the project's own door, not a second write of the same file:
+ // that is where re-registering, the live texture push and re-importing a
+ // product-bearing asset all happen.
+ await ProjectStore.setImportSettings(path, importerRef.current ?? {});
setDirty(false);
DirtyRegistry.bump();
- 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') AssetRegistry.applyLiveTextureSettings(path);
Toasts.push(t('det.importSaved'), 'info', 1400);
} catch (e) {
Toasts.push(t('det.importSaveFailed', { error: String(e) }), 'error');
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index ef45a1a1a..f1dd41e3f 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -3,6 +3,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 { hasImporter, runImporters } from '../plugins/importers';
import { importerDefaults } from '../../../pipeline/src/project/importSettings';
import { AssetRegistry, UUID_PREFIX, type AssetEntryLite } from './AssetRegistry';
import { imageSize } from './imageSize';
@@ -860,6 +861,10 @@ class ProjectStoreImpl {
await window.estella.fs.write(path + '.meta', JSON.stringify(meta, null, 2) + '\n');
await this.refreshAssets();
AssetRegistry.applyLiveTextureSettings(path);
+ // A setting that decides a PRODUCT only means something once the product is
+ // remade: a model's scale lives on the prefab this rebuilds. Types with no
+ // importer (a texture's filter) are read at cook or bind time and skip it.
+ if (hasImporter(path)) await runImporters([path]);
return importer;
}