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 DragonBones armature renders in the viewport, and is called one

yhh5629ca86da85
diff --git a/desktop/src/engine/EngineHost.ts b/desktop/src/engine/EngineHost.ts
index 310a4c25e..a53548298 100644
--- a/desktop/src/engine/EngineHost.ts
+++ b/desktop/src/engine/EngineHost.ts
@@ -21,6 +21,8 @@ import type { SpineManager } from 'esengine/spine';
import { SceneLoader } from './SceneLoader';
import { useSettings } from '@/store/settingsStore';
import { loadEditorSpine } from './spineLoad';
+import { loadEditorDragonBones, editorDragonBonesManager } from './dragonBonesLoad';
+import type { DragonBonesManager } from 'esengine/dragonbones';
import { checkEngineBuild } from './EngineGuard';
import { bootProfiler } from './bootProfiler';
import { PROJECT_MANIFEST_FILE } from '@/project/format';
@@ -119,6 +121,10 @@ class EngineHostImpl {
spineSkins(runtimeId: number): string[] {
return this.app_?.getPlugin(SpinePlugin)?.spineManager?.getSkins(runtimeId as never) ?? [];
}
+ /** The viewport's DragonBonesManager; null until a scene has asked for one. */
+ get dragonBonesManager(): DragonBonesManager | null {
+ return editorDragonBonesManager(this.app_);
+ }
get module(): ESEngineModule | null {
return this.module_;
}
@@ -400,6 +406,16 @@ class EngineHostImpl {
if (this.app_) await loadEditorSpine(this.app_, sceneData, entityMap, toUrl, resolvePath);
}
+ /** The DragonBones counterpart of {@link loadSpine}, over the same transport. */
+ async loadDragonBones(
+ sceneData: SceneData,
+ entityMap: Map<number, number>,
+ toUrl: (ref: string) => string,
+ resolvePath?: (ref: string) => string,
+ ): Promise<void> {
+ if (this.app_) await loadEditorDragonBones(this.app_, sceneData, entityMap, toUrl, resolvePath);
+ }
+
private resize() {
const canvas = this.canvas_;
const parent = canvas?.parentElement;
diff --git a/desktop/src/engine/dragonBonesLoad.ts b/desktop/src/engine/dragonBonesLoad.ts
new file mode 100644
index 000000000..59f35b509
--- /dev/null
+++ b/desktop/src/engine/dragonBonesLoad.ts
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { DragonBonesPlugin, loadDragonBonesSceneEntities } from 'esengine/dragonbones';
+import type { DragonBonesManager } from 'esengine/dragonbones';
+import type { App, SceneData } from 'esengine';
+import { editorSkeletalSource } from './skeletalSource';
+
+/**
+ * Bind every DragonBonesAnimation entity's armature into the app's
+ * DragonBonesManager so it renders in the editor viewport, through the SAME
+ * shared loader the builder runtime uses.
+ *
+ * The manager is acquired here rather than read: the plugin fetches its wasm on
+ * first ask, so an editor session that never opens a scene with an armature in it
+ * never loads the module — and one that does, waits for it exactly once.
+ */
+export async function loadEditorDragonBones(
+ app: App,
+ sceneData: SceneData,
+ entityMap: Map<number, number>,
+ toUrl: (ref: string) => string,
+ resolvePath: (ref: string) => string = (ref) => ref,
+): Promise<void> {
+ const module = app.wasmModule;
+ if (!module) return;
+
+ try {
+ const manager = await app.getPlugin(DragonBonesPlugin)?.acquire();
+ if (!manager) return;
+ await loadDragonBonesSceneEntities({
+ module,
+ source: editorSkeletalSource(toUrl, resolvePath, 'dragonbones'),
+ manager,
+ sceneData,
+ entityMap,
+ });
+ } catch (err) {
+ console.warn('[engine] DragonBones scene load failed', err);
+ }
+}
+
+/** The viewport's manager, or null when nothing has asked for one yet. */
+export function editorDragonBonesManager(app: App | null): DragonBonesManager | null {
+ return app?.getPlugin(DragonBonesPlugin)?.manager ?? null;
+}
diff --git a/desktop/src/engine/skeletalSource.ts b/desktop/src/engine/skeletalSource.ts
new file mode 100644
index 000000000..28ff3dc4d
--- /dev/null
+++ b/desktop/src/engine/skeletalSource.ts
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file skeletalSource.ts
+ * @brief The asset source the editor's skeletal loaders fetch over.
+ *
+ * Skeleton and atlas come over fetch as text/bytes; the atlas image is decoded to
+ * RGBA via the shared `decodeImagePixels` (the same path the play realm uses —
+ * robust across the editor's http/app:// origins). `toUrl` maps an asset ref to a
+ * fetchable URL, applied uniformly on fetch. `resolvePath` maps a `@uuid:` ref to
+ * its project path, which is how each loader derives its atlas's image paths (a
+ * raw uuid ref has no directory) — the job the runtime Catalog does in play.
+ *
+ * One factory for both runtimes: what differs between Spine and DragonBones is
+ * how the atlas names its images, not how the editor reaches a file.
+ */
+import { decodeImagePixels } from 'esengine';
+import type { RuntimeAssetSource } from 'esengine/spine';
+
+export function editorSkeletalSource(
+ toUrl: (ref: string) => string,
+ resolvePath: (ref: string) => string,
+ /** Names the runtime in fetch errors, so a failure says which loader wanted it. */
+ label: string,
+): RuntimeAssetSource {
+ const fetchOk = async (ref: string, kind: string): Promise<Response> => {
+ const r = await fetch(toUrl(ref));
+ if (!r.ok) throw new Error(`${label} ${kind} ${r.status}: ${ref}`);
+ return r;
+ };
+ return {
+ resolveRef: (ref) => resolvePath(ref),
+ backend: {
+ resolveUrl: (ref) => toUrl(ref),
+ fetchText: async (ref) => (await fetchOk(ref, 'asset')).text(),
+ fetchBinary: async (ref) => (await fetchOk(ref, 'asset')).arrayBuffer(),
+ },
+ decodePixels: async (ref) => decodeImagePixels(await (await fetchOk(ref, 'texture')).blob()),
+ };
+}
diff --git a/desktop/src/engine/skeletalSync.ts b/desktop/src/engine/skeletalSync.ts
new file mode 100644
index 000000000..4ce5e3e6b
--- /dev/null
+++ b/desktop/src/engine/skeletalSync.ts
@@ -0,0 +1,257 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file skeletalSync.ts
+ * @brief Keeps the viewport's skeletal bindings a live projection of the model,
+ * the same way the Reconciler keeps the World one. Skeleton instances live
+ * OUTSIDE the World (per-entity bindings in a runtime's manager, loaded
+ * through the shared runtime loader), so World projection alone can't
+ * keep them true. This module subscribes to the SceneModel and:
+ *
+ * - on `reset` (scene open / play-stop rebuild) re-binds every skeletal
+ * entity — the rebuild despawned the old runtime entities, which
+ * dropped their instances;
+ * - on a skeleton/atlas ref edit reloads that entity's binding through
+ * the SAME shared loader the scene load uses;
+ * - on animation/props edits applies them in place (live preview
+ * without restarting the animation on unrelated field scrubs).
+ *
+ * Two runtimes reach the viewport this way, and every step above means the
+ * same thing for both — so the subscription is written once and the three
+ * places they differ (which manager holds the binding, which loader fills
+ * it, and what counts as a change) are an adapter picked per component.
+ * A component names its runtime in its skeletal descriptor.
+ *
+ * ProjectStore installs it with the project's ref→URL transport; without
+ * an install every event is a no-op (dev/automation scene loads bind
+ * skeletons themselves, once).
+ */
+import { getComponentSkeletalFieldDescriptor } from 'esengine';
+import { spineEntityProps } from 'esengine/spine';
+import { dragonBonesEntityProps } from 'esengine/dragonbones';
+import type { SceneData } from 'esengine';
+import { SceneModel, type ModelEvent } from './SceneModel';
+import { SceneStore } from './SceneStore';
+import { EngineHost } from './EngineHost';
+
+type SceneEntity = SceneData['entities'][number];
+
+/** What an entity's binding was loaded/applied from, for change detection. */
+interface BoundState {
+ runtime: string;
+ skel: string;
+ atlas: string;
+ /** Spine's skin, or DragonBones' armature — the field that selects WHICH
+ * figure inside the file, and so forces a rebind when it changes. */
+ variant: string;
+ animation: string;
+ loop: boolean;
+}
+
+/**
+ * The three things that differ between runtimes. Everything else in this file is
+ * shared, which is the point of the split.
+ */
+interface RuntimeAdapter {
+ /** Drop this entity's binding; a rebind will make a new one. */
+ remove(runtimeId: number): void;
+ /** Load these entities' bindings through the shared scene loader. */
+ load(sceneData: SceneData, entityMap: Map<number, number>,
+ toUrl: (ref: string) => string, resolvePath: (ref: string) => string): Promise<void>;
+ /** Apply an in-place edit that did not change which file is bound. */
+ apply(runtimeId: number, data: Record<string, unknown>, prev: BoundState, next: BoundState): void;
+ /** The field selecting which figure inside the file this entity uses. */
+ variantField: string;
+}
+
+const spineAdapter: RuntimeAdapter = {
+ variantField: 'skin',
+ remove: (rt) => EngineHost.spineManager?.removeEntity(rt as never),
+ load: (sceneData, entityMap, toUrl, resolvePath) =>
+ EngineHost.loadSpine(sceneData, entityMap, toUrl, resolvePath),
+ apply: (rt, d, prev, next) => {
+ const spine = EngineHost.spineManager;
+ if (!spine) return;
+ spine.setEntityProps(rt as never, spineEntityProps(d));
+ if (prev.variant !== next.variant && next.variant) spine.setSkin(rt as never, next.variant);
+ if (prev.animation !== next.animation || prev.loop !== next.loop) {
+ if (next.animation) spine.setAnimation(rt as never, next.animation, next.loop);
+ }
+ },
+};
+
+const dragonBonesAdapter: RuntimeAdapter = {
+ // Not a skin: a DragonBones file holds several armatures, and picking a
+ // different one is a different figure — so it reloads rather than applies.
+ variantField: 'armature',
+ remove: (rt) => EngineHost.dragonBonesManager?.removeEntity(rt as never),
+ load: (sceneData, entityMap, toUrl, resolvePath) =>
+ EngineHost.loadDragonBones(sceneData, entityMap, toUrl, resolvePath),
+ apply: (rt, d, prev, next) => {
+ const db = EngineHost.dragonBonesManager;
+ if (!db) return;
+ db.setEntityProps(rt as never, dragonBonesEntityProps(d));
+ if (prev.animation !== next.animation || prev.loop !== next.loop) {
+ if (next.animation) {
+ const fade = typeof d.fadeInTime === 'number' ? d.fadeInTime : 0;
+ if (fade > 0) db.fadeIn(rt as never, next.animation, fade, next.loop);
+ else db.play(rt as never, next.animation, next.loop);
+ }
+ }
+ },
+};
+
+function adapterFor(runtime: string): RuntimeAdapter {
+ return runtime === 'dragonbones' ? dragonBonesAdapter : spineAdapter;
+}
+
+/** The project transport skeletal assets load over: ref → fetchable URL, and
+ * `@uuid:` ref → project path (atlas image paths derive from the atlas dir). */
+export interface SkeletalTransport {
+ toUrl: (ref: string) => string;
+ resolvePath: (ref: string) => string;
+}
+
+let transport: SkeletalTransport | null = null;
+let subscribed = false;
+const bound = new Map<number, BoundState>();
+// Loads are async (fetch + decode + side-module init); serialize them so two
+// rapid ref edits can't finish out of order and leave the older skeleton.
+let chain: Promise<void> = Promise.resolve();
+
+/**
+ * Install (or re-target) the sync for the open project's transport. Call
+ * BEFORE the scene adopt so the model's `reset` performs the initial bind.
+ */
+export function installSkeletalSync(t: SkeletalTransport): void {
+ transport = t;
+ bound.clear();
+ if (!subscribed) {
+ subscribed = true;
+ SceneModel.subscribe(onEvent);
+ }
+}
+
+function onEvent(ev: ModelEvent): void {
+ if (!transport) return;
+ switch (ev.kind) {
+ case 'reset':
+ rebindAll();
+ return;
+ case 'entityAdded': // duplicate / paste / undo-of-delete
+ syncEntity(ev.sourceId);
+ return;
+ case 'componentAdded':
+ case 'componentChanged':
+ if (getComponentSkeletalFieldDescriptor(ev.type)) syncEntity(ev.sourceId);
+ return;
+ case 'componentRemoved':
+ if (getComponentSkeletalFieldDescriptor(ev.type)) unbind(ev.sourceId);
+ return;
+ case 'entityRemoved':
+ bound.delete(ev.sourceId); // the World despawn already dropped the instance
+ return;
+ }
+}
+
+/** The entity's skeletal component (any component with a skeletal descriptor). */
+function skeletalComp(entity: SceneEntity): { type: string; d: Record<string, unknown> } | null {
+ for (const c of entity.components ?? []) {
+ if (getComponentSkeletalFieldDescriptor(c.type) && c.data) {
+ return { type: c.type, d: c.data as Record<string, unknown> };
+ }
+ }
+ return null;
+}
+
+function stateOf(type: string, d: Record<string, unknown>): BoundState {
+ const desc = getComponentSkeletalFieldDescriptor(type)!;
+ const str = (v: unknown): string => (typeof v === 'string' ? v : '');
+ return {
+ runtime: desc.runtime,
+ skel: str(d[desc.skeletonField]),
+ atlas: str(d[desc.atlasField]),
+ variant: str(d[adapterFor(desc.runtime).variantField]),
+ animation: str(d.animation),
+ loop: d.loop !== false,
+ };
+}
+
+/** Re-bind every skeletal entity from the current model (scene open / play-stop). */
+function rebindAll(): void {
+ bound.clear();
+ const data = SceneModel.current;
+ if (!data) return;
+ // Grouped by runtime: each loader discovers the pairs in the scene it is given,
+ // so handing one a scene holding the other's entities would ask it to parse a
+ // file it cannot read.
+ const perRuntime = new Map<string, { entities: SceneEntity[]; entityMap: Map<number, number> }>();
+ for (const e of data.entities) {
+ const sc = skeletalComp(e);
+ if (!sc) continue;
+ const rt = SceneModel.runtimeFor(e.id);
+ if (rt === undefined) continue;
+ const next = stateOf(sc.type, sc.d);
+ if (!next.skel || !next.atlas) continue;
+ bound.set(e.id, next);
+ let group = perRuntime.get(next.runtime);
+ if (!group) {
+ group = { entities: [], entityMap: new Map() };
+ perRuntime.set(next.runtime, group);
+ }
+ group.entities.push(e);
+ group.entityMap.set(e.id, rt as number);
+ }
+ for (const [runtime, group] of perRuntime) {
+ load(runtime, { ...data, entities: group.entities }, group.entityMap);
+ }
+}
+
+/** Project one entity's skeletal component: ref change → reload, else apply in place. */
+function syncEntity(sourceId: number): void {
+ const entity = SceneModel.entityBySource(sourceId);
+ const rt = SceneModel.runtimeFor(sourceId);
+ if (!entity || rt === undefined) return;
+ const sc = skeletalComp(entity);
+ if (!sc) return;
+
+ const next = stateOf(sc.type, sc.d);
+ const prev = bound.get(sourceId);
+ const adapter = adapterFor(next.runtime);
+ bound.set(sourceId, next);
+
+ // A variant change is a rebind for DragonBones (a different armature is a
+ // different instance) but not for Spine (a skin is swapped on the one it has).
+ const variantForcesReload = next.runtime === 'dragonbones' && prev?.variant !== next.variant;
+ if (!prev || prev.skel !== next.skel || prev.atlas !== next.atlas || variantForcesReload) {
+ adapter.remove(rt as number);
+ if (!next.skel || !next.atlas) return;
+ const data = SceneModel.current;
+ if (!data) return;
+ load(next.runtime, { ...data, entities: [entity] }, new Map([[sourceId, rt as number]]));
+ return;
+ }
+
+ // Same binding — apply the editable state in place. Props are idempotent;
+ // variant/animation only on change so scrubbing an unrelated field never
+ // restarts the animation.
+ adapter.apply(rt as number, sc.d, prev, next);
+}
+
+function unbind(sourceId: number): void {
+ const prev = bound.get(sourceId);
+ bound.delete(sourceId);
+ const rt = SceneModel.runtimeFor(sourceId);
+ if (rt !== undefined) adapterFor(prev?.runtime ?? '').remove(rt as number);
+}
+
+/** Queue a load through the shared loader; poke panels when it lands so the
+ * animation/skin dropdowns pick up the fresh skeleton's options. */
+function load(runtime: string, sceneData: SceneData, entityMap: Map<number, number>): void {
+ const t = transport!;
+ const adapter = adapterFor(runtime);
+ chain = chain
+ .then(() => adapter.load(sceneData, entityMap, t.toUrl, t.resolvePath))
+ .then(() => SceneStore.poke())
+ .catch((err) => console.warn(`[${runtime}] viewport binding load failed`, err));
+}
diff --git a/desktop/src/engine/spineLoad.ts b/desktop/src/engine/spineLoad.ts
index 7b3447e82..63b6ee168 100644
--- a/desktop/src/engine/spineLoad.ts
+++ b/desktop/src/engine/spineLoad.ts
@@ -1,37 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { SpinePlugin, loadSpineSceneEntities } from 'esengine/spine';
-import type { RuntimeAssetSource } from 'esengine/spine';
-import { decodeImagePixels, type App, type SceneData } from 'esengine';
-
-/**
- * Fetch-backed asset source for spine in the editor: skeleton/atlas come over
- * fetch as text/bytes; the atlas PNG is decoded to RGBA via the shared
- * `decodeImagePixels` (the same path the play realm uses — robust across the
- * editor's http/app:// origins). `toUrl` maps an asset ref to a fetchable URL,
- * applied uniformly on fetch. `resolvePath` maps a `@uuid:` ref to its project
- * path — the loader derives the atlas's page-texture paths from it (a raw uuid
- * ref has no directory), the same job the runtime Catalog does in play.
- */
-function editorSpineSource(
- toUrl: (ref: string) => string,
- resolvePath: (ref: string) => string,
-): RuntimeAssetSource {
- const fetchOk = async (ref: string, kind: string): Promise<Response> => {
- const r = await fetch(toUrl(ref));
- if (!r.ok) throw new Error(`spine ${kind} ${r.status}: ${ref}`);
- return r;
- };
- return {
- resolveRef: (ref) => resolvePath(ref),
- backend: {
- resolveUrl: (ref) => toUrl(ref),
- fetchText: async (ref) => (await fetchOk(ref, 'asset')).text(),
- fetchBinary: async (ref) => (await fetchOk(ref, 'asset')).arrayBuffer(),
- },
- decodePixels: async (ref) => decodeImagePixels(await (await fetchOk(ref, 'texture')).blob()),
- };
-}
+import type { App, SceneData } from 'esengine';
+import { editorSkeletalSource } from './skeletalSource';
/**
* Bind every SpineAnimation entity's skeleton/atlas/textures into the app's
@@ -56,7 +27,7 @@ export async function loadEditorSpine(
try {
await loadSpineSceneEntities({
module,
- source: editorSpineSource(toUrl, resolvePath),
+ source: editorSkeletalSource(toUrl, resolvePath, 'spine'),
spineManager,
sceneData,
entityMap: entityMap as Map<number, number>,
diff --git a/desktop/src/engine/spineSync.ts b/desktop/src/engine/spineSync.ts
deleted file mode 100644
index 0a3436878..000000000
--- a/desktop/src/engine/spineSync.ts
+++ /dev/null
@@ -1,180 +0,0 @@
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
-/**
- * @file spineSync.ts
- * @brief Keeps the viewport's spine bindings a live projection of the model,
- * the same way the Reconciler keeps the World one. Spine instances live
- * OUTSIDE the World (per-entity bindings in the SpineManager, loaded
- * through the shared runtime loader), so World projection alone can't
- * keep them true. This module subscribes to the SceneModel and:
- *
- * - on `reset` (scene open / play-stop rebuild) re-binds every spine
- * entity — the rebuild despawned the old runtime entities, which
- * dropped their instances;
- * - on a skeleton/atlas ref edit reloads that entity's binding through
- * the SAME shared loader the scene load uses;
- * - on skin/animation/props edits applies them in place (live preview
- * without restarting the animation on unrelated field scrubs).
- *
- * ProjectStore installs it with the project's ref→URL transport; without
- * an install every event is a no-op (dev/automation scene loads bind
- * spine themselves, once).
- */
-import { getComponentSkeletalFieldDescriptor } from 'esengine';
-import { spineEntityProps } from 'esengine/spine';
-import type { SceneData } from 'esengine';
-import { SceneModel, type ModelEvent } from './SceneModel';
-import { SceneStore } from './SceneStore';
-import { EngineHost } from './EngineHost';
-
-type SceneEntity = SceneData['entities'][number];
-
-/** What an entity's binding was loaded/applied from, for change detection. */
-interface BoundState {
- skel: string;
- atlas: string;
- skin: string;
- animation: string;
- loop: boolean;
-}
-
-/** The project transport spine assets load over: ref → fetchable URL, and
- * `@uuid:` ref → project path (page-texture paths derive from the atlas dir). */
-export interface SpineTransport {
- toUrl: (ref: string) => string;
- resolvePath: (ref: string) => string;
-}
-
-let transport: SpineTransport | null = null;
-let subscribed = false;
-const bound = new Map<number, BoundState>();
-// Spine (re)loads are async (fetch + decode + side-module init); serialize them
-// so two rapid ref edits can't finish out of order and leave the older skeleton.
-let chain: Promise<void> = Promise.resolve();
-
-/**
- * Install (or re-target) the sync for the open project's transport. Call
- * BEFORE the scene adopt so the model's `reset` performs the initial bind.
- */
-export function installSpineSync(t: SpineTransport): void {
- transport = t;
- bound.clear();
- if (!subscribed) {
- subscribed = true;
- SceneModel.subscribe(onEvent);
- }
-}
-
-function onEvent(ev: ModelEvent): void {
- if (!transport) return;
- switch (ev.kind) {
- case 'reset':
- rebindAll();
- return;
- case 'entityAdded': // duplicate / paste / undo-of-delete
- syncEntity(ev.sourceId);
- return;
- case 'componentAdded':
- case 'componentChanged':
- if (getComponentSkeletalFieldDescriptor(ev.type)) syncEntity(ev.sourceId);
- return;
- case 'componentRemoved':
- if (getComponentSkeletalFieldDescriptor(ev.type)) unbind(ev.sourceId);
- return;
- case 'entityRemoved':
- bound.delete(ev.sourceId); // the World despawn already dropped the instance
- return;
- }
-}
-
-/** The entity's spine component (any component with a spine field descriptor). */
-function spineComp(entity: SceneEntity): { type: string; d: Record<string, unknown> } | null {
- for (const c of entity.components ?? []) {
- if (getComponentSkeletalFieldDescriptor(c.type) && c.data) {
- return { type: c.type, d: c.data as Record<string, unknown> };
- }
- }
- return null;
-}
-
-function stateOf(type: string, d: Record<string, unknown>): BoundState {
- const desc = getComponentSkeletalFieldDescriptor(type)!;
- const str = (v: unknown): string => (typeof v === 'string' ? v : '');
- return {
- skel: str(d[desc.skeletonField]),
- atlas: str(d[desc.atlasField]),
- skin: str(d.skin),
- animation: str(d.animation),
- loop: d.loop !== false,
- };
-}
-
-/** Re-bind every spine entity from the current model (scene open / play-stop). */
-function rebindAll(): void {
- bound.clear();
- const data = SceneModel.current;
- if (!data) return;
- const entityMap = new Map<number, number>();
- const entities: SceneEntity[] = [];
- for (const e of data.entities) {
- const sc = spineComp(e);
- if (!sc) continue;
- const rt = SceneModel.runtimeFor(e.id);
- if (rt === undefined) continue;
- const next = stateOf(sc.type, sc.d);
- if (!next.skel || !next.atlas) continue;
- bound.set(e.id, next);
- entityMap.set(e.id, rt as number);
- entities.push(e);
- }
- if (entities.length === 0) return;
- load({ ...data, entities }, entityMap);
-}
-
-/** Project one entity's spine component: ref change → reload, else apply in place. */
-function syncEntity(sourceId: number): void {
- const entity = SceneModel.entityBySource(sourceId);
- const rt = SceneModel.runtimeFor(sourceId);
- const spine = EngineHost.spineManager;
- if (!entity || rt === undefined || !spine) return;
- const sc = spineComp(entity);
- if (!sc) return;
-
- const next = stateOf(sc.type, sc.d);
- const prev = bound.get(sourceId);
- bound.set(sourceId, next);
-
- if (!prev || prev.skel !== next.skel || prev.atlas !== next.atlas) {
- spine.removeEntity(rt as never);
- if (!next.skel || !next.atlas) return;
- const data = SceneModel.current;
- if (!data) return;
- load({ ...data, entities: [entity] }, new Map([[sourceId, rt as number]]));
- return;
- }
-
- // Same binding — apply the editable spine state in place. Props are
- // idempotent; skin/animation only on change so scrubbing an unrelated
- // field never restarts the animation.
- spine.setEntityProps(rt as never, spineEntityProps(sc.d));
- if (prev.skin !== next.skin && next.skin) spine.setSkin(rt as never, next.skin);
- if (prev.animation !== next.animation || prev.loop !== next.loop) {
- if (next.animation) spine.setAnimation(rt as never, next.animation, next.loop);
- }
-}
-
-function unbind(sourceId: number): void {
- bound.delete(sourceId);
- const rt = SceneModel.runtimeFor(sourceId);
- if (rt !== undefined) EngineHost.spineManager?.removeEntity(rt as never);
-}
-
-/** Queue a load through the shared loader; poke panels when it lands so the
- * animation/skin dropdowns pick up the fresh skeleton's options. */
-function load(sceneData: SceneData, entityMap: Map<number, number>): void {
- const t = transport!;
- chain = chain
- .then(() => EngineHost.loadSpine(sceneData, entityMap, t.toUrl, t.resolvePath))
- .then(() => SceneStore.poke())
- .catch((err) => console.warn('[spine] viewport binding load failed', err));
-}
diff --git a/desktop/src/i18n/messages/details.ts b/desktop/src/i18n/messages/details.ts
index 499f9d1dc..5e25c5409 100644
--- a/desktop/src/i18n/messages/details.ts
+++ b/desktop/src/i18n/messages/details.ts
@@ -110,7 +110,7 @@ export const detailsMessages = defineMessages({
// — Entity kind pill (mirrors the Outliner's kind labels) —
'det.kindCamera': { en: 'Camera', zh: '相机' },
'det.kindSprite': { en: 'Sprite', zh: '精灵' },
- 'det.kindSpine': { en: 'Spine', zh: 'Spine' },
+ 'det.kindSkeletal': { en: 'Skeletal', zh: '骨骼' },
'det.kindPhysics': { en: 'Physics', zh: '物理' },
'det.kindUi': { en: 'UI', zh: 'UI' },
'det.kindAudio': { en: 'Audio', zh: '音频' },
diff --git a/desktop/src/i18n/messages/outliner.ts b/desktop/src/i18n/messages/outliner.ts
index b2aaf0df0..976cda931 100644
--- a/desktop/src/i18n/messages/outliner.ts
+++ b/desktop/src/i18n/messages/outliner.ts
@@ -68,7 +68,7 @@ export const outlinerMessages = defineMessages({
'out.prefab': { en: 'Prefab', zh: '预制体' },
'out.kindCamera': { en: 'Camera', zh: '相机' },
'out.kindSprite': { en: 'Sprite', zh: '精灵' },
- 'out.kindSpine': { en: 'Spine', zh: 'Spine' },
+ 'out.kindSkeletal': { en: 'Skeletal', zh: '骨骼' },
'out.kindPhysics': { en: 'Physics', zh: '物理' },
'out.kindUi': { en: 'UI', zh: 'UI' },
'out.kindAudio': { en: 'Audio', zh: '音频' },
diff --git a/desktop/src/outliner/columns.tsx b/desktop/src/outliner/columns.tsx
index b339820b6..def36ab63 100644
--- a/desktop/src/outliner/columns.tsx
+++ b/desktop/src/outliner/columns.tsx
@@ -37,7 +37,7 @@ export interface OutlinerColumn {
const KIND_TYPE: Record<NodeKind, string> = {
camera: t('out.kindCamera'),
sprite: t('out.kindSprite'),
- skeletal: t('out.kindSpine'),
+ skeletal: t('out.kindSkeletal'),
physics: t('out.kindPhysics'),
ui: t('out.kindUi'),
audio: t('out.kindAudio'),
diff --git a/desktop/src/panels/Details.tsx b/desktop/src/panels/Details.tsx
index 0c9f737c2..251a71988 100644
--- a/desktop/src/panels/Details.tsx
+++ b/desktop/src/panels/Details.tsx
@@ -162,7 +162,7 @@ function componentIcon(name: string): LucideIcon {
const KIND_LABEL: Record<NodeKind, string> = {
camera: t('det.kindCamera'),
sprite: t('det.kindSprite'),
- skeletal: t('det.kindSpine'),
+ skeletal: t('det.kindSkeletal'),
physics: t('det.kindPhysics'),
ui: t('det.kindUi'),
audio: t('det.kindAudio'),
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 1c3d3a841..18e422dc3 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -21,7 +21,7 @@ import { setUserSchemas, userSchema, setBitmaskSource, setEnumSource, type UserC
import { installDragonBonesEnumSources } from '@/engine/dragonBonesNames';
import { setProjectActions, type ProjectActionSchema } from '@/ai/actionCatalog';
import { setAssetRefProblemResolver } from '@/engine/EditorControlSurface';
-import { installSpineSync, type SpineTransport } from '@/engine/spineSync';
+import { installSkeletalSync, type SkeletalTransport } from '@/engine/skeletalSync';
import { SceneStore } from '@/engine/SceneStore';
import { useSelection } from '@/store/selectionStore';
import { usePrefabConflicts } from '@/store/prefabConflicts';
@@ -496,10 +496,11 @@ class ProjectStoreImpl {
// A projection that resolves COLD (assigned after the scene-open preload)
// hands its ref here: async load through the engine loaders, re-project.
Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
- // Spine bindings (skeleton/atlas/pages → SpineManager) are a live projection
- // of the model, driven by model events: adopt's `reset` performs the initial
- // bind, and later ref/field edits keep the viewport true (see spineSync).
- installSpineSync(this.spineTransport());
+ // Skeletal bindings (skeleton/atlas/pages → the runtime's manager) are a live
+ // projection of the model, driven by model events: adopt's `reset` performs the
+ // initial bind, and later ref/field edits keep the viewport true (see
+ // skeletalSync).
+ installSkeletalSync(this.skeletalTransport());
await bootProfiler.phase('reconcile (build world)', () => Reconciler.adopt(expandedRaw, resolved));
// Re-apply prefab-instance tags (adopt cleared them) so save can collapse.
for (const { id, tag } of tags) SceneModel.setPrefabTag(id, tag);
@@ -555,7 +556,7 @@ class ProjectStoreImpl {
Reconciler.setAssetResolver((ref) => this.handleForRef(ref));
Reconciler.setRefPathResolver((ref) => this.resolveRef(ref));
Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
- installSpineSync(this.spineTransport());
+ installSkeletalSync(this.skeletalTransport());
Reconciler.adopt(blank, blank); // no @uuid: refs → resolved === raw
EngineHost.syncEditorViewToScene();
usePrefabConflicts.getState().clear();
@@ -770,9 +771,9 @@ class ProjectStoreImpl {
return this.uuidToPath.get(uuid) ?? null;
}
- /** The project transport spine assets load over: ref → `estella://` URL for
+ /** The project transport skeletal assets load over: ref → `estella://` URL for
* fetches, `@uuid:` ref → project path for atlas-dir derivation. */
- private spineTransport(): SpineTransport {
+ private skeletalTransport(): SkeletalTransport {
return {
toUrl: (ref) =>
ref.startsWith(UUID_PREFIX)
@@ -2145,7 +2146,7 @@ class ProjectStoreImpl {
Reconciler.setAssetResolver((ref) => this.handleForRef(ref));
Reconciler.setRefPathResolver((ref) => this.resolveRef(ref));
Reconciler.setAssetTouchListener((ref, slot) => this.hotLoadAsset(ref, slot));
- installSpineSync(this.spineTransport());
+ installSkeletalSync(this.skeletalTransport());
Reconciler.adopt(raw, resolved);
EngineHost.syncEditorViewToScene();
applyWidgetTheme(this.uiTheme(), this.uiThemeOverrides());