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(modeling): a model's picture can be a recipe - material.texture took a .png, .jpg or .webp and refused the .esimage the picture was drawn from, so a model named pixels where the scene beside it named layers; a recipe is accepted, and whether a path names one is asked in one place (textureRecipePath) by the runtime, the packager and the model source

yhh1c4bb47e388a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ded434ee3..eb4a39345 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,6 +36,7 @@ published separately; it ships inside the editor.
### Fixed
+- **A model's picture can be a recipe.** A model source's `material.texture` took a `.png`, `.jpg` or `.webp` and refused an `.esimage`, the recipe `image_write` answers as the picture's `ref`: a tree's branches named the pixels while the foliage material beside them named the layers, and a game shipped whichever was referenced. A recipe is now accepted there. Whether a path names a recipe is asked in one place, `sdk/src/asset/textureRecipePath.ts`, which reads nothing of the runtime: the registry that draws recipes, the packager deciding what ships and the model source's check each spelled the extension themselves.
- **A model's report is its steps as written, and names a step that undoes a decimate.** `report.steps` of a baked model listed every plain step its repeats came to, by an index among those: a spruce of thirteen rows of branches reported a hundred and thirty-eight steps, most the same line, and none under the index `model_edit` takes. It is now one entry for each step as written, by that index, a repeat counted once with how many steps it `made`, and each entry says the `triangles` the mesh had after it. And a step that splits faces to carry its own detail (a stain by a pattern, a displace, a sculpt) after a `decimate` took the decimate's triangles back in silence: a rock thinned to 1100 came out at 214,534, under the 300,000 the report calls heavy, and a field of them would have been gigabytes. The report now warns of each such step, with what it was given, what it left and which decimate it undid, and says how to keep the detail (before the decimate, carried by `normalBake`) or bound it (`detail`). The test also notes what the advice costs: a pattern stained before a decimate leaves colour seams the decimate will not cross, so it is `normalBake`'s `color: true` that carries it.
- **A playable's start-screen bar moves through the whole boot.** The bar's stages were weighed for a web page, most of whose start is fetching the engine. A playable has the engine inlined, so its bar stood at 82% within a second and crawled to 95% over the twenty-five that followed. A playable now weighs its own stages (the scene's is four fifths of the bar), and that stage is followed in three stretches: assets being read and made (eased by the clock, since nothing counts them), shaders compiled against the most seen compiling, and the world prepared against the most its makers said was left. For that, a hold given to `holdShaderWarmup` may answer a number (pages, cells) where it answered yes, and `warmShaders` passes the sum to `onProgress`; Terrain and Foliage count theirs. One lake scene's bar went from 18% to 95% over its 22 seconds, with one stretch of four seconds standing still. `attachSplash` takes the weights.
- **An effect chain keeps its uniform buffers from frame to frame.** A camera's post-process chain is said again every frame, and each of its passes made a uniform buffer for its parameters and deleted it when the chain was cleared: seventeen buffers created and seventeen deleted every frame for a lake scene with a volume's usual effects, counted in the GL calls of an exported page. The buffers of a cleared chain are now taken over by the passes of the next chain that need one the same size, and one that nothing has taken in eight clears is deleted. The same scene creates none in a steady frame.
diff --git a/pipeline/src/assets/assetDb.ts b/pipeline/src/assets/assetDb.ts
index c89c67e12..497c65433 100644
--- a/pipeline/src/assets/assetDb.ts
+++ b/pipeline/src/assets/assetDb.ts
@@ -32,6 +32,7 @@ import { resolveRelativePath } from '../../../sdk/src/asset/documentRef';
// so the dep scan discovers an atlas's texture pages the same way they will be requested.
import { parseSpineAtlasPages } from '../../../sdk/src/spine/atlasPages';
import { getEditorType } from '../../../sdk/src/assetTypes';
+import { isTextureRecipePath } from '../../../sdk/src/asset/textureRecipePath';
/** Local, gitignored cache inside the project (next to workspace.json). */
const CACHE_DIR = '.esengine/cache';
@@ -239,7 +240,7 @@ const JSON_REF_TYPES = new Set([
'json', 'sound-event', 'world-rules', 'terrain-layer', 'terrain-tiles',
]);
-const isTextureRecipe = (e: { type: string; path: string }): boolean => e.type === 'imageSource' && e.path.toLowerCase().endsWith('.esimage');
+const isTextureRecipe = (e: { type: string; path: string }): boolean => e.type === 'imageSource' && isTextureRecipePath(e.path);
/** A clip that is a recipe names the recordings it plays (a sampled instrument's notes, a sample layer's file). */
const isAudioRecipe = (e: { type: string }): boolean => e.type === 'soundSource' || e.type === 'musicSource';
diff --git a/pipeline/src/modeling/modelSource.ts b/pipeline/src/modeling/modelSource.ts
index 6e9729974..bb732de0a 100644
--- a/pipeline/src/modeling/modelSource.ts
+++ b/pipeline/src/modeling/modelSource.ts
@@ -33,6 +33,7 @@ import { strip } from './strip';
import { expandSteps, ModelExpandError, needsExpanding } from './modelExpand';
import { checkAnimations, checkController, checkRig, checkShapes, resolveJoints, type AnimationSource, type ControllerSource, type RigSource, type ShapeSource } from './rig';
import { compact, type Face, type FaceSelector, type PolyMesh, type Vec3 } from './polyMesh';
+import { isTextureRecipePath } from '../../../sdk/src/asset/textureRecipePath';
export const MODEL_SOURCE_VERSION = 1;
export const MODEL_SOURCE_EXT = '.esmodel';
@@ -496,7 +497,11 @@ function validatePlain(raw: unknown): ModelSource {
continue;
}
if (key === 'texture') {
- if (typeof value !== 'string' || !/.(png|jpg|jpeg|webp)$/i.test(value)) throw new ModelBuildError('material.texture must be a project path to a picture (.png, .jpg, .webp)', null, null, null);
+ // A picture, or the recipe one is drawn from: a recipe is read wherever an image is, and a model that could only name
+ // the .png shipped pixels where its scene shipped layers.
+ if (typeof value !== 'string' || !(/\.(png|jpg|jpeg|webp)$/i.test(value) || isTextureRecipePath(value))) {
+ throw new ModelBuildError('material.texture must be a project path to a picture (.png, .jpg, .webp) or to the recipe of one (.esimage)', null, null, null);
+ }
continue;
}
if (!['roughness', 'metallic', 'cutoff'].includes(key)) throw new ModelBuildError(`material has an unknown field "${key}"; it takes roughness, metallic, alpha, cutoff, emissive, texture`, null, null, null);
diff --git a/sdk/src/asset/textureRecipe.ts b/sdk/src/asset/textureRecipe.ts
index 1663948cc..4cc68624b 100644
--- a/sdk/src/asset/textureRecipe.ts
+++ b/sdk/src/asset/textureRecipe.ts
@@ -16,6 +16,7 @@
import { contentHashHex } from './contentHash';
import { platformReadCacheFile, platformWriteCacheFile } from '../platform';
import { decodeUtf8, encodeUtf8 } from '../util/utf8';
+import { isTextureRecipePath } from './textureRecipePath';
/** The pixels a recipe draws: top row first, RGBA, as a decoded image is. */
export interface RecipePixels { width: number; height: number; pixels: Uint8Array }
@@ -42,17 +43,12 @@ export interface TextureRecipeStats {
reused: number;
}
-const RECIPE_EXTENSION = '.esimage';
/** A kept picture's bytes: two sizes, then its pixels. */
const KEPT_HEADER = 8;
let drawer: TextureRecipeDrawer | null = null;
const stats: TextureRecipeStats = { drawn: 0, drawMs: 0, reused: 0 };
-/** Whether a texture's path names a recipe and not an image. */
-export function isTextureRecipePath(path: string): boolean {
- const end = path.indexOf('?');
- return (end < 0 ? path : path.slice(0, end)).toLowerCase().endsWith(RECIPE_EXTENSION);
-}
+export { isTextureRecipePath } from './textureRecipePath';
/** Installs what draws recipes (null takes it out again). `esengine/image` does this on import. */
export function setTextureRecipeDrawer(next: TextureRecipeDrawer | null): void {
diff --git a/sdk/src/asset/textureRecipePath.ts b/sdk/src/asset/textureRecipePath.ts
new file mode 100644
index 000000000..86c63366f
--- /dev/null
+++ b/sdk/src/asset/textureRecipePath.ts
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file textureRecipePath.ts
+ * @brief Whether a path names a picture's recipe, with nothing else in the file.
+ *
+ * Its own file because the question is asked where nothing of the runtime may come along: the packager deciding what ships, a model's
+ * source being checked. The registry that draws recipes (textureRecipe.ts) reads the platform, and they must not have to.
+ */
+
+/** The extension of a picture's recipe. */
+export const TEXTURE_RECIPE_EXTENSION = '.esimage';
+
+/** Whether a texture's path names a recipe and not an image. */
+export function isTextureRecipePath(path: string): boolean {
+ const end = path.indexOf('?');
+ return (end < 0 ? path : path.slice(0, end)).toLowerCase().endsWith(TEXTURE_RECIPE_EXTENSION);
+}
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 30b417bbc..d24b8ce03 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -4798,4 +4798,6 @@ export const NOTED = {
{"note": "A shadow map is drawn again only when what it holds changed."},
"fix(modeling): a model's report is its steps as written, and names a step that undoes a decimate - the report listed every plain step a repeat came to (a tree of thirteen rows of branches was a hundred and thirty-eight entries) under indexes no edit takes, and said nothing when a patterned stain after a decimate split 1100 triangles into 214,534; a repeat is one entry counted, each step says the triangles it left, and such a step is a warning naming both":
{"note": "A model's report is its steps as written, and names a step that undoes a decimate."},
+ "fix(modeling): a model's picture can be a recipe - material.texture took a .png, .jpg or .webp and refused the .esimage the picture was drawn from, so a model named pixels where the scene beside it named layers; a recipe is accepted, and whether a path names one is asked in one place (textureRecipePath) by the runtime, the packager and the model source":
+ {"note": "A model's picture can be a recipe."},
};