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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): render spine in the editor viewport (S1 editor remainder)
esengine15e1590ca2d1
diff --git a/desktop/headless.html b/desktop/headless.htmlindex 156a61b14..b1ccbedb2 100644--- a/desktop/headless.html+++ b/desktop/headless.html@@ -7,7 +7,7 @@origins) — a render that fails here for a CSP reason would fail there too. --><metahttp-equiv="Content-Security-Policy"- content="default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data:; connect-src 'self' ws: estella:; worker-src 'self' blob:;"+ content="default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data:; connect-src 'self' ws: estella:; worker-src 'self' blob:;"/><title>Estella Headless</title></head>diff --git a/desktop/index.html b/desktop/index.htmlindex 1b306a8dc..f3e262de3 100644--- a/desktop/index.html+++ b/desktop/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8" /><metahttp-equiv="Content-Security-Policy"- content="default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data:; connect-src 'self' ws: estella:; worker-src 'self' blob:; frame-src 'self' estella:;"+ content="default-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: estella:; font-src 'self' data:; connect-src 'self' ws: estella:; worker-src 'self' blob:; frame-src 'self' estella:;"/><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Estella Editor</title>diff --git a/desktop/public/assets/spine/spineboy-pro.skel b/desktop/public/assets/spine/spineboy-pro.skelnew file mode 100644index 000000000..09e564b7eBinary files /dev/null and b/desktop/public/assets/spine/spineboy-pro.skel differdiff --git a/desktop/public/assets/spine/spineboy.atlas b/desktop/public/assets/spine/spineboy.atlasnew file mode 100644index 000000000..eca542b71--- /dev/null+++ b/desktop/public/assets/spine/spineboy.atlas@@ -0,0 +1,94 @@+spineboy.png+ size: 1024, 256+ filter: Linear, Linear+ scale: 0.5+crosshair+ bounds: 352, 7, 45, 45+eye-indifferent+ bounds: 862, 105, 47, 45+eye-surprised+ bounds: 505, 79, 47, 45+front-bracer+ bounds: 826, 66, 29, 40+front-fist-closed+ bounds: 786, 65, 38, 41+front-fist-open+ bounds: 710, 51, 43, 44+ rotate: 90+front-foot+ bounds: 210, 6, 63, 35+front-shin+ bounds: 665, 128, 41, 92+ rotate: 90+front-thigh+ bounds: 2, 2, 23, 56+ rotate: 90+front-upper-arm+ bounds: 250, 205, 23, 49+goggles+ bounds: 665, 171, 131, 83+gun+ bounds: 798, 152, 105, 102+head+ bounds: 2, 27, 136, 149+hoverboard-board+ bounds: 2, 178, 246, 76+hoverboard-thruster+ bounds: 722, 96, 30, 32+ rotate: 90+hoverglow-small+ bounds: 275, 81, 137, 38+mouth-grind+ bounds: 614, 97, 47, 30+mouth-oooo+ bounds: 612, 65, 47, 30+mouth-smile+ bounds: 661, 64, 47, 30+muzzle-glow+ bounds: 382, 54, 25, 25+muzzle-ring+ bounds: 275, 54, 25, 105+ rotate: 90+muzzle01+ bounds: 911, 95, 67, 40+ rotate: 90+muzzle02+ bounds: 792, 108, 68, 42+muzzle03+ bounds: 956, 171, 83, 53+ rotate: 90+muzzle04+ bounds: 275, 7, 75, 45+muzzle05+ bounds: 140, 3, 68, 38+neck+ bounds: 250, 182, 18, 21+portal-bg+ bounds: 140, 43, 133, 133+portal-flare1+ bounds: 554, 65, 56, 30+portal-flare2+ bounds: 759, 112, 57, 31+ rotate: 90+portal-flare3+ bounds: 554, 97, 58, 30+portal-shade+ bounds: 275, 121, 133, 133+portal-streaks1+ bounds: 410, 126, 126, 128+portal-streaks2+ bounds: 538, 129, 125, 125+rear-bracer+ bounds: 857, 67, 28, 36+rear-foot+ bounds: 663, 96, 57, 30+rear-shin+ bounds: 414, 86, 38, 89+ rotate: 90+rear-thigh+ bounds: 756, 63, 28, 47+rear-upper-arm+ bounds: 60, 5, 20, 44+ rotate: 90+torso+ bounds: 905, 164, 49, 90diff --git a/desktop/public/assets/spine/spineboy.png b/desktop/public/assets/spine/spineboy.pngnew file mode 100644index 000000000..0ea9737f3Binary files /dev/null and b/desktop/public/assets/spine/spineboy.png differdiff --git a/desktop/public/scenes/spine-test.esscene b/desktop/public/scenes/spine-test.esscenenew file mode 100644index 000000000..f5a918052--- /dev/null+++ b/desktop/public/scenes/spine-test.esscene@@ -0,0 +1,42 @@+{+ "version": "1.0",+ "name": "SpineTest",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 300, "isActive": true, "priority": 0 } }+ ],+ "visible": true+ },+ {+ "id": 1,+ "name": "Spineboy",+ "parent": null,+ "children": [],+ "components": [+ { "type": "Transform", "data": { "position": { "x": 0, "y": -150, "z": 0 } } },+ {+ "type": "SpineAnimation",+ "data": {+ "skeletonPath": "/assets/spine/spineboy-pro.skel",+ "atlasPath": "/assets/spine/spineboy.atlas",+ "animation": "idle",+ "skin": "default",+ "loop": true,+ "playing": true,+ "skeletonScale": 0.5,+ "color": { "r": 1, "g": 1, "b": 1, "a": 1 },+ "layer": 0,+ "enabled": true+ }+ }+ ],+ "visible": true+ }+ ]+}diff --git a/desktop/public/scenes/spine-test.textures.json b/desktop/public/scenes/spine-test.textures.jsonnew file mode 100644index 000000000..0967ef424--- /dev/null+++ b/desktop/public/scenes/spine-test.textures.json@@ -0,0 +1 @@+{}diff --git a/desktop/src/engine/SceneLoader.ts b/desktop/src/engine/SceneLoader.tsindex cb4255833..5e2e5392c 100644--- a/desktop/src/engine/SceneLoader.ts+++ b/desktop/src/engine/SceneLoader.ts@@ -3,6 +3,7 @@ import type { App, SceneData } from 'esengine';import { SceneModel } from './SceneModel';import { Reconciler } from './Reconciler';import { EditorHistory } from './EditorHistory';+import { loadEditorSpine } from './spineLoad';type SceneDataArg = Parameters<typeof loadSceneData>[1];@@ -47,6 +48,12 @@ export const SceneLoader = {}const map = loadSceneData(app.world, resolved as SceneDataArg);+ // Spine renders through its side modules, loaded separately from Assets (skel+ // /atlas/textures + per-entity instances). Refs are the scene's own paths or+ // @uuid: (resolved via the manifest).+ await loadEditorSpine(app, raw, map as Map<number, number>, (ref) =>+ ref.startsWith(UUID_PREFIX) ? (uuidToUrl.get(ref.slice(UUID_PREFIX.length)) ?? ref) : ref,+ );EditorHistory.clear();SceneModel.adopt(raw, map as Map<number, number>);return map.size;diff --git a/desktop/src/engine/spineLoad.ts b/desktop/src/engine/spineLoad.tsnew file mode 100644index 000000000..a25cd384f--- /dev/null+++ b/desktop/src/engine/spineLoad.ts@@ -0,0 +1,80 @@+import { SpinePlugin, loadSpineSceneEntities } from 'esengine/spine';+import type { RuntimeAssetProvider } from 'esengine/spine';+import type { App, SceneData } from 'esengine';++/**+ * Fetch-backed asset provider for spine in the editor: skeleton/atlas come over+ * fetch as text/bytes; the atlas PNG is decoded to RGBA via createImageBitmap →+ * canvas → getImageData (the same path the play realm uses — robust across the+ * editor's http/app:// origins). `toUrl` maps an asset ref to a fetchable URL.+ */+class EditorSpineProvider implements RuntimeAssetProvider {+ constructor(private readonly toUrl: (ref: string) => string) {}++ resolvePath(ref: string): string {+ return this.toUrl(ref);+ }++ async readText(ref: string): Promise<string> {+ const r = await fetch(this.toUrl(ref));+ if (!r.ok) throw new Error(`spine asset ${r.status}: ${ref}`);+ return r.text();+ }++ async readBinary(ref: string): Promise<Uint8Array> {+ const r = await fetch(this.toUrl(ref));+ if (!r.ok) throw new Error(`spine asset ${r.status}: ${ref}`);+ return new Uint8Array(await r.arrayBuffer());+ }++ async loadPixels(ref: string): Promise<{ width: number; height: number; pixels: Uint8Array }> {+ const r = await fetch(this.toUrl(ref));+ if (!r.ok) throw new Error(`spine texture ${r.status}: ${ref}`);+ const bitmap = await createImageBitmap(await r.blob(), {+ premultiplyAlpha: 'none',+ colorSpaceConversion: 'none',+ });+ const canvas = document.createElement('canvas');+ canvas.width = bitmap.width;+ canvas.height = bitmap.height;+ const ctx = canvas.getContext('2d');+ if (!ctx) throw new Error('2d context unavailable for spine texture decode');+ ctx.drawImage(bitmap, 0, 0);+ bitmap.close?.();+ const data = ctx.getImageData(0, 0, canvas.width, canvas.height);+ return { width: canvas.width, height: canvas.height, pixels: new Uint8Array(data.data.buffer) };+ }+}++/**+ * Bind every SpineAnimation entity's skeleton/atlas/textures into the app's+ * SpineManager so spine renders in the editor viewport. The World already holds+ * the SpineAnimation components (loadSceneData ran); this loads the runtime+ * assets + spawns the per-entity spine instances through the SAME shared loader+ * the builder runtime uses (REARCH_SPINE single-impl). No-op when the app has no+ * spine provider/manager or the scene has no spine entities.+ */+export async function loadEditorSpine(+ app: App,+ sceneData: SceneData,+ entityMap: Map<number, number>,+ toUrl: (ref: string) => string,+): Promise<void> {+ const spineManager = app.getPlugin(SpinePlugin)?.spineManager;+ const module = app.wasmModule;+ const registry = app.world.getCppRegistry();+ if (!spineManager || !module || !registry) return;++ try {+ await loadSpineSceneEntities({+ module,+ provider: new EditorSpineProvider(toUrl),+ spineManager,+ sceneData,+ entityMap: entityMap as Map<number, number>,+ registry,+ });+ } catch (err) {+ console.warn('[engine] spine scene load failed', err);+ }+}diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex 20970ee74..944d819f1 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -60,7 +60,7 @@ void renderer_submitSpineBatch(uintptr_t indicesPtr, i32 indexCount,u32 textureId, i32 blendMode,uintptr_t transformPtr,- Entity entity, i32 layer, f32 depth+ u32 entity, i32 layer, f32 depth) {if (!g_initialized || !g_renderFrame) return;auto* vertices = reinterpret_cast<const f32*>(verticesPtr);@@ -68,7 +68,7 @@ void renderer_submitSpineBatch(auto* transform = reinterpret_cast<const f32*>(transformPtr);g_renderFrame->submitSpineBatch(vertices, vertexCount, indices, indexCount,- textureId, blendMode, transform, entity, layer, depth);+ textureId, blendMode, transform, Entity::fromRaw(entity), layer, depth);}void renderer_submitSpineBatchByEntity(@@ -76,13 +76,14 @@ void renderer_submitSpineBatchByEntity(uintptr_t verticesPtr, i32 vertexCount,uintptr_t indicesPtr, i32 indexCount,u32 textureId, i32 blendMode,- Entity entity, f32 skelScale, bool flipX, bool flipY,+ u32 entity, f32 skelScale, bool flipX, bool flipY,i32 layer, f32 depth) {if (!g_initialized || !g_renderFrame) return;- if (!registry.has<ecs::Transform>(entity)) return;+ const Entity ent = Entity::fromRaw(entity);+ if (!registry.has<ecs::Transform>(ent)) return;- auto& t = registry.get<ecs::Transform>(entity);+ auto& t = registry.get<ecs::Transform>(ent);t.ensureDecomposed();glm::vec3 s = t.worldScale;@@ -99,7 +100,7 @@ void renderer_submitSpineBatchByEntity(auto* indices = reinterpret_cast<const u16*>(indicesPtr);g_renderFrame->submitSpineBatch(vertices, vertexCount, indices, indexCount,- textureId, blendMode, &model[0][0], entity, layer, depth);+ textureId, blendMode, &model[0][0], ent, layer, depth);}#endifdiff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex 813bca08c..17b5248b3 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -59,14 +59,14 @@ void renderer_submitSpineBatch(uintptr_t indicesPtr, i32 indexCount,u32 textureId, i32 blendMode,uintptr_t transformPtr,- Entity entity, i32 layer, f32 depth+ u32 entity, i32 layer, f32 depth);void renderer_submitSpineBatchByEntity(ecs::Registry& registry,uintptr_t verticesPtr, i32 vertexCount,uintptr_t indicesPtr, i32 indexCount,u32 textureId, i32 blendMode,- Entity entity, f32 skelScale, bool flipX, bool flipY,+ u32 entity, f32 skelScale, bool flipX, bool flipY,i32 layer, f32 depth);#endif