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): a material's preview is a real sphere, cube or plane with a background and sample image, and its header, shader section and thumbnails follow

yhh4a7eb68c3934
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a90214759..f6715ccea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ published separately; it ships inside the editor.
### Changed
+- **A material's preview is a real shape.** Selecting a material shows it on a sphere, cube or plane (lit materials open on the sphere, sprite shaders on the plane), over a dark, checker or light background, with a sample image for shaders that sample a texture; the choice is remembered per kind. The header carries the ball as its icon and the name with a faint extension, the shader is a plain section with a link to make it unique, and the Content Browser's material thumbnails use the same preview. The engine's offscreen preview target now has a depth buffer, so a mesh drawn there is no longer drawn inside out.
- **The 2D animation editors are redrawn.** In the sprite animation editor the view's tools float over its corner, playback and the timeline are one panel, frame events are flags on an event track (click one to rename, move or remove it), the frame source folds into a strip that opens on an empty clip, and frame rate, loop and Save no longer appear a second time in the inspector. The animator controller shows states as cards with their clip and speed, wires between a pair of states run side by side with a pill for the condition (dashed when it waits for the exit time), and its inspector puts the selected state or transition first, with the controller's layers, typed parameters and a folded constraints section below.
- **The tile editor matches its design.** The layer and tileset menus sit on the raised surface, a picked tile has a 2px frame and shows its id on hover, the brush column shows the tile id, the replace dialog's button says Replace, and the tileset inspector shows one-way and trigger as switches, the layer opacity is a slim slider, and a collision layer's friction and bounce fields are flat with their own heading.
- **Collision layers are easier to paint.** A new collision layer takes its cell size, origin and position from the tilemap it sits over instead of a fixed 32px; solid, slope, one-way and trigger cells read differently in the viewport; the cell grid is drawn over the art while tiles are painted; the brushes are grouped, named on one line and picked with the digits 1–9; and the layer menu and the empty palette offer a new collision layer. Tilemap and collision layers have their own icons and type names in the Outliner and Details instead of reading as sprites.
diff --git a/desktop b/desktop
index 90a93ee38..913673a14 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 90a93ee3839304a8fa2c957e501da959b6cceb51
+Subproject commit 913673a14bdea4ddd109c592d96b86d4a8ff3154
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 55966cdf8..2780ac3c8 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -5118,7 +5118,7 @@ static prototype: MaskReach
## Material — const @experimental
```
-{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
+{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number, shape?: { mesh?: number; texture?: number; }): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
```
## MaterialAssetData — interface @experimental
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 500a33637..016251732 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5126,7 +5126,7 @@ static prototype: MaskReach
## Material — const @experimental
```
-{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
+{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number, shape?: { mesh?: number; texture?: number; }): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
```
## MaterialAssetData — interface @experimental
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 1c7b324e2..33ccf152b 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -5113,7 +5113,7 @@ static prototype: MaskReach
## Material — const @experimental
```
-{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
+{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number, shape?: { mesh?: number; texture?: number; }): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
```
## MaterialAssetData — interface @experimental
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 6523ca55a..4334be837 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -5113,7 +5113,7 @@ static prototype: MaskReach
## Material — const @experimental
```
-{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
+{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number, shape?: { mesh?: number; texture?: number; }): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
```
## MaterialAssetData — interface @experimental
diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.md
index c0c3af074..a8bdcf87b 100644
--- a/sdk/etc/wasm.api.md
+++ b/sdk/etc/wasm.api.md
@@ -474,7 +474,7 @@ renderer_pollSkeletalPreview: (preview: number) => number
renderer_pollSnapshotReadback: () => number
renderer_programEpoch: (() => number) | undefined
renderer_releaseTarget: (handle: number) => void
-renderer_renderMaterialPreview: (materialId: number, w: number, h: number) => void
+renderer_renderMaterialPreview: (materialId: number, w: number, h: number, meshId: number, textureId: number) => void
renderer_renderMeshPreview: (meshId: number, w: number, h: number) => void
renderer_renderSkeletalPreview: (preview: number, viewProjectionPtr: number) => number
renderer_replayToDrawCall: (drawCallIndex: number) => void
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index b50af317e..b8ee237bc 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -5120,7 +5120,7 @@ static prototype: MaskReach
## Material — const @experimental
```
-{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
+{ createShader(vertexSrc: string, fragmentSrc: string): ShaderHandle; releaseShader(shader: ShaderHandle): void; create(options: MaterialOptions): MaterialHandle; compileShader(esshaderSource: string, features?: string[]): ShaderHandle; getSwitch(material: MaterialHandle, name: string): boolean; setSwitch(material: MaterialHandle, name: string, on: boolean): void; get(material: MaterialHandle): MaterialData | undefined; getRenderState(material: MaterialHandle): Omit<ResolvedMaterial, "uniforms"> | null; applyState(material: MaterialHandle, state: Omit<MaterialOptions, "shader">, textureLeases?: ReadonlyMap<string, TextureLease>): void; setUniform(material: MaterialHandle, name: string, value: UniformValue): void; getUniform(material: MaterialHandle, name: string): UniformValue | undefined; setBlendMode(material: MaterialHandle, mode: BlendMode): void; getBlendMode(material: MaterialHandle): BlendMode; setDepthTest(material: MaterialHandle, enabled: boolean): void; setDepthWrite(material: MaterialHandle, enabled: boolean): void; setDepthBias(material: MaterialHandle, units: number): void; setCull(material: MaterialHandle, cull: CullMode): void; getShader(material: MaterialHandle): ShaderHandle; release(material: MaterialHandle): void; isValid(material: MaterialHandle): boolean; renderPreview(material: MaterialHandle, w: number, h: number, shape?: { mesh?: number; texture?: number; }): Promise<ImageData | null>; releaseAll(): void; createFromAsset(data: MaterialAssetData, shaderHandle: ShaderHandle, parentHandle?: MaterialHandle): MaterialHandle; createInstance(source: MaterialHandle): MaterialHandle; toAssetData(material: MaterialHandle, shaderPath: string, parentPath?: string): MaterialAssetData | null; getUniforms(material: MaterialHandle): Map<string, UniformValue>; tex(textureId: number, slot?: number): TextureRef; }
```
## MaterialAssetData — interface @experimental
diff --git a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
index 578580b63..94ef3908c 100644
--- a/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
+++ b/sdk/src/ecs/bridge/nativeEngineApi.generated.ts
@@ -187,7 +187,7 @@ export interface NativeEngineApi {
renderer_pollSnapshotReadback?(): number;
renderer_programEpoch?(): number;
renderer_releaseTarget?(handle: number): void;
- renderer_renderMaterialPreview?(materialId: number, w: number, h: number): void;
+ renderer_renderMaterialPreview?(materialId: number, w: number, h: number, meshId: number, textureId: number): void;
renderer_renderMeshPreview?(meshId: number, w: number, h: number): void;
renderer_renderSkeletalPreview?(preview: number, viewProjectionPtr: number): number;
renderer_replayToDrawCall?(drawCallIndex: number): void;
diff --git a/sdk/src/render/material.ts b/sdk/src/render/material.ts
index c03104c6b..bf1776447 100644
--- a/sdk/src/render/material.ts
+++ b/sdk/src/render/material.ts
@@ -638,14 +638,13 @@ export const Material = {
},
/**
- * Render a material to an offscreen @p w×@p h target and resolve with its pixels (a
- * "material ball" thumbnail). Reuses the real viewport render path — a unit quad lit by one
- * directional light — so the preview matches how the material looks in-scene. The readback
- * rides the engine's async seam: immediate on GL, resolved when the staging-buffer map
- * lands on WebGPU — one awaited call either way. Null if the engine isn't ready or the
- * readback fails.
+ * Render a material offscreen at @p w×@p h and resolve with its pixels, through the real
+ * viewport path, lit by one directional light. `shape.mesh` (a loaded mesh handle) draws it on
+ * that geometry, seen off-axis and framed; without, a sprite shader samples `shape.texture` on
+ * a flat quad. Null if the engine isn't ready or the readback fails.
*/
- async renderPreview(material: MaterialHandle, w: number, h: number): Promise<ImageData | null> {
+ async renderPreview(material: MaterialHandle, w: number, h: number,
+ shape: { mesh?: number; texture?: number } = {}): Promise<ImageData | null> {
const connected = module;
const m = previewCore(connected);
const data = materials.get(material);
@@ -664,7 +663,7 @@ export const Material = {
}
handle = materials.get(handle)?.parent;
}
- return m.renderer_renderMaterialPreview(material, w, h);
+ return m.renderer_renderMaterialPreview(material, w, h, shape.mesh ?? 0, shape.texture ?? 0);
});
} finally { releaseTextures(held); }
},
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.ts
index 7fb258ff7..6726ef837 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -728,7 +728,7 @@ export interface ESEngineModule {
renderer_getSnapshotSize(): number;
renderer_getSnapshotWidth(): number;
renderer_getSnapshotHeight(): number;
- renderer_renderMaterialPreview(materialId: number, w: number, h: number): void;
+ renderer_renderMaterialPreview(materialId: number, w: number, h: number, meshId: number, textureId: number): void;
/** A skeletal preview, owned by its handle: every call names one, so two of
* them cannot reach each other and there is no "current" preview. */
renderer_createSkeletalPreview(w: number, h: number): number;
diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cpp
index ec304be16..494191c9e 100644
--- a/src/esengine/bindings/RendererBindings.cpp
+++ b/src/esengine/bindings/RendererBindings.cpp
@@ -1520,21 +1520,61 @@ void renderer_destroySkeletalPreview(u32 preview) {
if (g_renderFrame) g_renderFrame->destroySkeletalPreview(preview);
}
-void renderer_renderMaterialPreview(u32 materialId, i32 w, i32 h) {
+void renderer_renderMaterialPreview(u32 materialId, i32 w, i32 h, u32 meshId, u32 textureId) {
if (!g_renderFrame || w <= 0 || h <= 0) return;
- // A throwaway one-sprite scene: a 2×2 quad filling the ortho [-1,1] with the material, lit by
- // one white directional light so Lit materials preview lit (Unlit ignores it).
ecs::Registry reg;
+ auto light = reg.create();
+ reg.emplace<ecs::Transform>(light);
+ reg.emplace<ecs::Light>(light).type = static_cast<i32>(ecs::LightType::Directional);
+ // A shape of the caller's choosing: the material on a mesh, seen off-axis and framed to the
+ // mesh's own bounds (a ball seen from one side is a disc), lit by one directional light.
+ auto* rm = meshId != 0 ? ctx().tryGet<resource::ResourceManager>() : nullptr;
+ const Mesh* res = rm ? rm->getMesh(resource::MeshHandle{meshId}) : nullptr;
+ if (res) {
+ auto entity = reg.create();
+ reg.emplace<ecs::Transform>(entity);
+ auto& mesh = reg.emplace<ecs::MeshRenderer>(entity);
+ mesh.mesh = resource::MeshHandle{meshId};
+ mesh.material = materialId;
+ mesh.lit = true;
+ mesh.opaque = true;
+ // By id, not through a reference held across the emplace above: it can have moved.
+ reg.get<ecs::Transform>(light).position = glm::vec3(0.0f, 0.0f, 1.0f);
+
+ if (g_transformSystem) {
+ esengine::World world{reg, ctx().services(), 0.0f};
+ g_transformSystem->update(world);
+ }
+
+ const glm::vec3 centre = (res->localMin + res->localMax) * 0.5f;
+ const f32 radius = std::max(glm::length(res->localMax - res->localMin) * 0.5f, 1e-4f);
+ const glm::vec3 eye = centre + glm::normalize(glm::vec3(0.6f, 0.45f, 1.0f)) * (radius * 4.0f);
+ const glm::mat4 view = glm::lookAt(eye, centre, glm::vec3(0.0f, 1.0f, 0.0f));
+ f32 half = 1e-4f;
+ for (i32 corner = 0; corner < 8; ++corner) {
+ const glm::vec3 world{
+ (corner & 1) ? res->localMax.x : res->localMin.x,
+ (corner & 2) ? res->localMax.y : res->localMin.y,
+ (corner & 4) ? res->localMax.z : res->localMin.z,
+ };
+ const glm::vec3 v = glm::vec3(view * glm::vec4(world, 1.0f));
+ half = std::max({half, std::abs(v.x), std::abs(v.y)});
+ }
+ half *= 1.08f;
+ const glm::mat4 proj = math::ortho(-half, half, -half, half, 0.01f, radius * 8.0f);
+ g_renderFrame->renderToTarget(reg, proj * view, static_cast<u32>(w), static_cast<u32>(h));
+ return;
+ }
+
+ // Otherwise a 2×2 quad filling the ortho [-1,1] with the material — a sprite, so a sprite shader
+ // gets the picture it samples (`textureId`, 0 = none).
auto quad = reg.create();
reg.emplace<ecs::Transform>(quad);
auto& sprite = reg.emplace<ecs::Sprite>(quad);
sprite.material = materialId;
sprite.size = glm::vec2(2.0f, 2.0f);
-
- auto light = reg.create();
- reg.emplace<ecs::Transform>(light);
- reg.emplace<ecs::Light>(light).type = static_cast<i32>(ecs::LightType::Directional);
+ if (textureId != 0) sprite.texture = resource::TextureHandle{textureId};
if (g_transformSystem) {
esengine::World world{reg, ctx().services(), 0.0f};
diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hpp
index 3789ac0d6..d4a42fc89 100644
--- a/src/esengine/bindings/RendererBindings.hpp
+++ b/src/esengine/bindings/RendererBindings.hpp
@@ -309,7 +309,7 @@ u32 renderer_getSkeletalPreviewWidth(u32 preview);
u32 renderer_getSkeletalPreviewHeight(u32 preview);
void renderer_destroySkeletalPreview(u32 preview);
-void renderer_renderMaterialPreview(u32 materialId, i32 w, i32 h);
+void renderer_renderMaterialPreview(u32 materialId, i32 w, i32 h, u32 meshId, u32 textureId);
void renderer_renderMeshPreview(u32 meshId, i32 w, i32 h);
i32 renderer_pollPreviewReadback();
uintptr_t renderer_getPreviewPtr();
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cpp
index a1f4237d4..cb3608734 100644
--- a/src/esengine/renderer/frame/RenderFrame.cpp
+++ b/src/esengine/renderer/frame/RenderFrame.cpp
@@ -718,7 +718,7 @@ void RenderFrame::renderSurface(ecs::Registry& registry, const glm::mat4& viewPr
if (!device_.isDeviceUsable()) return;
if (surface.target == 0) {
- surface.target = target_manager_.create(w, h, /*depth=*/false, /*linearFilter=*/false);
+ surface.target = target_manager_.create(w, h, /*depth=*/true, /*linearFilter=*/false);
} else if (auto* existing = target_manager_.get(surface.target);
existing && (existing->getWidth() != w || existing->getHeight() != h)) {
existing->resize(w, h);
@@ -727,6 +727,8 @@ void RenderFrame::renderSurface(ecs::Registry& registry, const glm::mat4& viewPr
if (!rt) return;
RenderPassDesc previewPass{rt->getFramebuffer(), /*clearColor=*/true};
+ previewPass.clearDepth = true; // a mesh drawn here needs its near faces to win
+ previewPass.clearStencil = true;
previewPass.clearColorValue[3] = 0.0f; // transparent black
device_.beginRenderPass(previewPass);
device_.setViewport(0, 0, w, h);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 10046e013..e71791aed 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -96,6 +96,8 @@ export const NOTED = {
{ note: 'The tile editor matches its design.' },
'feat(editor): the sprite animation editor merges playback and timeline with an event track, and the animator controller gets state cards, parallel wires and a sectioned inspector':
{ note: 'The 2D animation editors are redrawn.' },
+ "feat(editor): a material's preview is a real sphere, cube or plane with a background and sample image, and its header, shader section and thumbnails follow":
+ { note: "A material's preview is a real shape." },
'feat(editor): an asset header names its kind and size, and a segmented switch is used only when its words fit':
{ note: "An asset's header names its kind and size." },
"feat(editor): asset inspectors take the board's finish — a card preview, ruled key-value rows, tinted actions, a kind icon in the header":