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.

refactor(sdk): the preview host the editor stopped using

esengined218471474dc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 05dcf33bc..62f8192c9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,7 +23,10 @@ published separately; it ships inside the editor.
is gone with it, so `renderer_submitAll` takes a viewport and nothing else.
`registerAssetBuildTransform` / `getAssetBuildTransform` were a registry with
no registrar and no reader — what actually transforms an asset for a build is
- the cook pipeline. `sceneErrors` filtered diagnostics for no one.
+ the cook pipeline. `sceneErrors` filtered diagnostics for no one. `PreviewPlugin`
+ / `previewPlugin` fetched a scene over HTTP and watched it over an EventSource:
+ the editor previews through `EngineHost` in-process, and nothing had assembled
+ this one since.
- **A `Text` that names no family is drawn in the project's.** `fontFamily`
defaults to empty now, and empty means "whatever this project uses" — resolved
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index a77a4e04f..089f29977 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 113,
"beta": 73,
- "experimental": 1623,
+ "experimental": 1621,
"deprecated": 3
},
- "total": 1809,
+ "total": 1807,
"subsystems": [
{
"id": "ecs",
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 95386e2da..60e695096 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 66 beta · 1509 experimental · 3 deprecated
+Symbols: 113 public · 66 beta · 1507 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -5968,16 +5968,6 @@ static new (): PrefabsPlugin
static prototype: PrefabsPlugin
```
-## PreviewPlugin — class @experimental
-```
-build: (app: App) => void
-cleanup: () => void
-name: string
-waitForReady: () => Promise<void>
-static new (sceneUrl: string, baseUrl?: string): PreviewPlugin
-static prototype: PreviewPlugin
-```
-
## PrismaticJoint — const @experimental
```
ComponentDef<PrismaticJointData>
@@ -11383,11 +11373,6 @@ PrefabsPlugin
(prefab: PrefabData, loadPrefab: (path: string) => Promise<PrefabData>, cache: Map<string, PrefabData>, visited?: Set<string>, depth?: number): Promise<void>
```
-## previewPlugin — function @experimental
-```
-(sceneUrl: string, baseUrl?: string): PreviewPlugin
-```
-
## probeRegistrations — function @experimental
```
(register: () => Promise<void>): Promise<ProbedRegistrations>
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 77b30a4b0..8c75d2992 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 71 beta · 1528 experimental · 3 deprecated
+Symbols: 113 public · 71 beta · 1526 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -6151,16 +6151,6 @@ static new (): PrefabsPlugin
static prototype: PrefabsPlugin
```
-## PreviewPlugin — class @experimental
-```
-build: (app: App) => void
-cleanup: () => void
-name: string
-waitForReady: () => Promise<void>
-static new (sceneUrl: string, baseUrl?: string): PreviewPlugin
-static prototype: PreviewPlugin
-```
-
## PrismaticJoint — const @experimental
```
ComponentDef<PrismaticJointData>
@@ -11626,11 +11616,6 @@ PrefabsPlugin
(prefab: PrefabData, loadPrefab: (path: string) => Promise<PrefabData>, cache: Map<string, PrefabData>, visited?: Set<string>, depth?: number): Promise<void>
```
-## previewPlugin — function @experimental
-```
-(sceneUrl: string, baseUrl?: string): PreviewPlugin
-```
-
## probeRegistrations — function @experimental
```
(register: () => Promise<void>): Promise<ProbedRegistrations>
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 85d2a2e8b..315a258c4 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 68 beta · 1508 experimental · 3 deprecated
+Symbols: 113 public · 68 beta · 1506 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -5963,16 +5963,6 @@ static new (): PrefabsPlugin
static prototype: PrefabsPlugin
```
-## PreviewPlugin — class @experimental
-```
-build: (app: App) => void
-cleanup: () => void
-name: string
-waitForReady: () => Promise<void>
-static new (sceneUrl: string, baseUrl?: string): PreviewPlugin
-static prototype: PreviewPlugin
-```
-
## PrismaticJoint — const @experimental
```
ComponentDef<PrismaticJointData>
@@ -11388,11 +11378,6 @@ PrefabsPlugin
(prefab: PrefabData, loadPrefab: (path: string) => Promise<PrefabData>, cache: Map<string, PrefabData>, visited?: Set<string>, depth?: number): Promise<void>
```
-## previewPlugin — function @experimental
-```
-(sceneUrl: string, baseUrl?: string): PreviewPlugin
-```
-
## probeRegistrations — function @experimental
```
(register: () => Promise<void>): Promise<ProbedRegistrations>
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index d754e6058..011e8e6b8 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 66 beta · 1529 experimental · 3 deprecated
+Symbols: 113 public · 66 beta · 1527 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -6208,16 +6208,6 @@ static new (): PrefabsPlugin
static prototype: PrefabsPlugin
```
-## PreviewPlugin — class @experimental
-```
-build: (app: App) => void
-cleanup: () => void
-name: string
-waitForReady: () => Promise<void>
-static new (sceneUrl: string, baseUrl?: string): PreviewPlugin
-static prototype: PreviewPlugin
-```
-
## PrismaticJoint — const @experimental
```
ComponentDef<PrismaticJointData>
@@ -11638,11 +11628,6 @@ PrefabsPlugin
(prefab: PrefabData, loadPrefab: (path: string) => Promise<PrefabData>, cache: Map<string, PrefabData>, visited?: Set<string>, depth?: number): Promise<void>
```
-## previewPlugin — function @experimental
-```
-(sceneUrl: string, baseUrl?: string): PreviewPlugin
-```
-
## probeRegistrations — function @experimental
```
(register: () => Promise<void>): Promise<ProbedRegistrations>
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index eb6a4649a..dac52c14e 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 66 beta · 1519 experimental · 3 deprecated
+Symbols: 113 public · 66 beta · 1517 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -5970,16 +5970,6 @@ static new (): PrefabsPlugin
static prototype: PrefabsPlugin
```
-## PreviewPlugin — class @experimental
-```
-build: (app: App) => void
-cleanup: () => void
-name: string
-waitForReady: () => Promise<void>
-static new (sceneUrl: string, baseUrl?: string): PreviewPlugin
-static prototype: PreviewPlugin
-```
-
## PrismaticJoint — const @experimental
```
ComponentDef<PrismaticJointData>
@@ -11410,11 +11400,6 @@ PrefabsPlugin
(prefab: PrefabData, loadPrefab: (path: string) => Promise<PrefabData>, cache: Map<string, PrefabData>, visited?: Set<string>, depth?: number): Promise<void>
```
-## previewPlugin — function @experimental
-```
-(sceneUrl: string, baseUrl?: string): PreviewPlugin
-```
-
## probeRegistrations — function @experimental
```
(register: () => Promise<void>): Promise<ProbedRegistrations>
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index 75a45fde9..c010a8eb4 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -322,7 +322,6 @@ export {
// Preview
// =============================================================================
-export { PreviewPlugin, previewPlugin } from './preview';
// =============================================================================
// Animation
diff --git a/sdk/src/preview/PreviewPlugin.ts b/sdk/src/preview/PreviewPlugin.ts
deleted file mode 100644
index e72640fe1..000000000
--- a/sdk/src/preview/PreviewPlugin.ts
+++ /dev/null
@@ -1,220 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
-/**
- * @file PreviewPlugin.ts
- * @brief Plugin for editor preview functionality
- */
-
-import type { App, Plugin } from '../app/app';
-import type { SceneData } from '../scene/scene';
-import { loadRuntimeScene } from '../runtime/runtimeLoader';
-import { Transform, Camera, Canvas, ProjectionType, ClearFlags, type TransformData, type CameraData, type CanvasData } from '../ecs/component';
-import { DEFAULT_DESIGN_WIDTH, DEFAULT_DESIGN_HEIGHT } from '../defaults';
-import { platformFetch } from '../platform';
-import { SceneManager } from '../scene/sceneManager';
-import { HttpBackend } from '../asset/Backend';
-import { fetchDecodePixels } from '../asset/imageDecode';
-import type { RuntimeAssetSource } from '../runtime/runtimeAssets';
-import { SpinePlugin } from '../spine/SpinePlugin';
-import { log } from '../util/logger';
-
-const PREVIEW_SCENE = '__preview__';
-
-// =============================================================================
-// PreviewPlugin
-// =============================================================================
-
-export function previewPlugin(sceneUrl: string, baseUrl?: string): PreviewPlugin {
- return new PreviewPlugin(sceneUrl, baseUrl);
-}
-
-export class PreviewPlugin implements Plugin {
- name = 'preview';
- private sceneUrl_: string;
- private baseUrl_: string;
- private app_: App | null = null;
- private loadPromise_: Promise<void> | null = null;
- private eventSource_: EventSource | null = null;
- private onMessage_: ((event: MessageEvent) => void) | null = null;
- private onError_: ((event: Event) => void) | null = null;
-
- constructor(sceneUrl: string, baseUrl?: string) {
- this.sceneUrl_ = sceneUrl;
- this.baseUrl_ = baseUrl ?? '';
- }
-
- build(app: App): void {
- this.app_ = app;
-
- const manager = app.getResource(SceneManager);
- manager.register({
- name: PREVIEW_SCENE,
- setup: async () => {
- await this.loadRuntimeData();
- this.ensureCamera();
- },
- });
- manager.setInitial(PREVIEW_SCENE);
-
- this.loadPromise_ = manager.load(PREVIEW_SCENE).then(() => {}).catch(e => {
- log.error('preview', 'Failed to load preview scene', e);
- });
- this.setupHotReload();
- }
-
- /**
- * @brief Wait for scene loading to complete
- */
- async waitForReady(): Promise<void> {
- if (this.loadPromise_) {
- await this.loadPromise_;
- }
- }
-
- private async loadRuntimeData(): Promise<void> {
- if (!this.app_) return;
-
- const response = await platformFetch(this.sceneUrl_);
- if (!response.ok) {
- throw new Error(`Failed to fetch scene: ${response.status}`);
- }
- const sceneData = await response.json<SceneData>();
-
- // Canonical asset source: http fetch over the preview origin + fetch→blob
- // image decode. Preview refs are plain paths (resolveRef = identity).
- const backend = new HttpBackend({ baseUrl: this.baseUrl_ });
- const source: RuntimeAssetSource = {
- backend,
- decodePixels: (path) => fetchDecodePixels(backend.resolveUrl(path)),
- };
-
- const spinePlugin = this.app_.getPlugin(SpinePlugin);
- const spineManager = spinePlugin?.spineManager ?? null;
-
- await loadRuntimeScene({
- app: this.app_,
- module: this.app_.wasmModule!,
- sceneData,
- source,
- spineManager,
- sceneName: PREVIEW_SCENE,
- });
- }
-
- private ensureCamera(): void {
- if (!this.app_) return;
-
- const world = this.app_.world;
- let hasActiveCamera = false;
-
- const cameraEntities = world.getEntitiesWithComponents([Camera]);
- for (const entity of cameraEntities) {
- const camera = world.get(entity, Camera) as CameraData;
- if (camera.isActive) {
- hasActiveCamera = true;
- break;
- }
- }
-
- if (!hasActiveCamera) {
- log.warn('preview', 'No active camera found, creating default camera');
-
- let orthoSize = 540;
- let aspectRatio = DEFAULT_DESIGN_WIDTH / DEFAULT_DESIGN_HEIGHT;
-
- const canvasEntities = world.getEntitiesWithComponents([Canvas]);
- for (const entity of canvasEntities) {
- const canvas = world.get(entity, Canvas) as CanvasData;
- if (canvas.designResolution) {
- // World units are design pixels (editor cameras author orthoSize
- // = designResolution.y / 2); pixelsPerUnit is the physics meter
- // scale and has no bearing on the camera fit.
- orthoSize = canvas.designResolution.y / 2;
- aspectRatio = canvas.designResolution.x / canvas.designResolution.y;
- break;
- }
- }
-
- const manager = this.app_.getResource(SceneManager);
- const sceneCtx = manager.getScene(PREVIEW_SCENE);
- const cameraEntity = sceneCtx ? sceneCtx.spawn() : world.spawn();
-
- const transformData: TransformData = {
- position: { x: 0, y: 0, z: 10 },
- rotation: { x: 0, y: 0, z: 0, w: 1 },
- scale: { x: 1, y: 1, z: 1 },
- worldPosition: { x: 0, y: 0, z: 10 },
- worldRotation: { x: 0, y: 0, z: 0, w: 1 },
- worldScale: { x: 1, y: 1, z: 1 },
- };
- world.insert(cameraEntity, Transform, transformData);
-
- const cameraData: CameraData = {
- isActive: true,
- projectionType: ProjectionType.Orthographic,
- fov: 60,
- orthoSize,
- nearPlane: 0.1,
- farPlane: 1000,
- aspectRatio,
- priority: 0,
- showFrustum: false,
- pixelPerfect: false,
- viewport: { x: 0, y: 0, z: 1, w: 1 },
- clearFlags: ClearFlags.ColorAndDepth,
- cullingMask: 0xFFFFFFFF,
- };
- world.insert(cameraEntity, Camera, cameraData);
- }
- }
-
- cleanup(): void {
- if (this.eventSource_) {
- if (this.onMessage_) {
- this.eventSource_.removeEventListener('message', this.onMessage_ as EventListener);
- }
- if (this.onError_) {
- this.eventSource_.removeEventListener('error', this.onError_);
- }
- this.eventSource_.close();
- this.eventSource_ = null;
- }
- this.onMessage_ = null;
- this.onError_ = null;
- this.app_ = null;
- }
-
- private setupHotReload(): void {
- const url = new URL(this.sceneUrl_, window.location.href);
- const eventsUrl = `${url.protocol}//${url.host}/sse-reload`;
-
- this.eventSource_ = new EventSource(eventsUrl);
-
- this.onMessage_ = async (event: MessageEvent) => {
- if (event.data === 'reload') {
- log.info('preview', 'Reload event received, updating scene...');
- await this.reloadScene();
- }
- };
-
- this.onError_ = (err: Event) => {
- log.error('preview', 'EventSource error', err);
- };
-
- this.eventSource_.addEventListener('message', this.onMessage_ as EventListener);
- this.eventSource_.addEventListener('error', this.onError_);
- }
-
- private async reloadScene(): Promise<void> {
- if (!this.app_) return;
-
- try {
- const manager = this.app_.getResource(SceneManager);
- await manager.switchTo(PREVIEW_SCENE);
- log.info('preview', 'Scene reloaded successfully');
- } catch (err) {
- const msg = err instanceof Error ? err.message : String(err);
- log.error('preview', `Failed to reload scene: ${msg}`);
- }
- }
-}
diff --git a/sdk/src/preview/index.ts b/sdk/src/preview/index.ts
deleted file mode 100644
index f933fac3d..000000000
--- a/sdk/src/preview/index.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
-/**
- * @file index.ts
- * @brief Preview module exports
- */
-
-export { PreviewPlugin, previewPlugin } from './PreviewPlugin';