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: add Spine animation query, event callback, and constraint APIs
esengineaf121028b890
diff --git a/sdk/src/spine/ModuleBackend.ts b/sdk/src/spine/ModuleBackend.tsindex b0fd2ee9a..7e52d3a0e 100644--- a/sdk/src/spine/ModuleBackend.ts+++ b/sdk/src/spine/ModuleBackend.ts@@ -1,6 +1,7 @@import type { Entity } from '../types';import type { ESEngineModule, CppRegistry } from '../wasm';import type { SpineModuleController } from './SpineController';+import type { RawSpineEvent, ConstraintList, TransformMixData, PathMixData } from './SpineController';interface EntityInfo {skelHandle: number;@@ -20,6 +21,7 @@ type BatchEntry = {export class ModuleBackend {private controller_: SpineModuleController;private entities_: Map<Entity, EntityInfo> = new Map();+ private disabledEntities_: Set<Entity> = new Set();private cachedFrame_: number = -1;private cachedEntries_: BatchEntry[] = [];@@ -137,11 +139,60 @@ export class ModuleBackend {return this.controller_.setSlotColor(info.instanceId, slotName, r, g, b, a);}+ listConstraints(entity: Entity): ConstraintList | null {+ const info = this.entities_.get(entity);+ if (!info) return null;+ return this.controller_.listConstraints(info.instanceId);+ }++ getTransformConstraintMix(entity: Entity, name: string): TransformMixData | null {+ const info = this.entities_.get(entity);+ if (!info) return null;+ return this.controller_.getTransformConstraintMix(info.instanceId, name);+ }++ setTransformConstraintMix(entity: Entity, name: string, mix: TransformMixData): boolean {+ const info = this.entities_.get(entity);+ if (!info) return false;+ return this.controller_.setTransformConstraintMix(info.instanceId, name, mix);+ }++ getPathConstraintMix(entity: Entity, name: string): PathMixData | null {+ const info = this.entities_.get(entity);+ if (!info) return null;+ return this.controller_.getPathConstraintMix(info.instanceId, name);+ }++ setPathConstraintMix(entity: Entity, name: string, mix: PathMixData): boolean {+ const info = this.entities_.get(entity);+ if (!info) return false;+ return this.controller_.setPathConstraintMix(info.instanceId, name, mix);+ }++ setEnabled(entity: Entity, enabled: boolean): void {+ if (enabled) {+ this.disabledEntities_.delete(entity);+ } else {+ this.disabledEntities_.add(entity);+ }+ }+enableEvents(entity: Entity): void {const info = this.entities_.get(entity);if (info) this.controller_.enableEvents(info.instanceId);}+ collectAllEvents(): { entity: Entity; raw: RawSpineEvent }[] {+ const result: { entity: Entity; raw: RawSpineEvent }[] = [];+ for (const [entity, info] of this.entities_) {+ const events = this.controller_.collectEvents(info.instanceId);+ for (const raw of events) {+ result.push({ entity, raw });+ }+ }+ return result;+ }+updateAll(dt: number): void {for (const info of this.entities_.values()) {this.controller_.update(info.instanceId, dt);@@ -155,6 +206,7 @@ export class ModuleBackend {if (this.cachedFrame_ !== frameCount) {this.cachedEntries_.length = 0;for (const [entity, info] of this.entities_) {+ if (this.disabledEntities_.has(entity)) continue;const batches = this.controller_.extractMeshBatches(info.instanceId);for (const batch of batches) {if (batch.vertices.length === 0 || batch.indices.length === 0) continue;@@ -210,6 +262,7 @@ export class ModuleBackend {this.controller_.destroyInstance(info.instanceId);this.controller_.unloadSkeleton(info.skelHandle);this.entities_.delete(entity);+ this.disabledEntities_.delete(entity);}shutdown(): void {@@ -218,5 +271,6 @@ export class ModuleBackend {this.controller_.unloadSkeleton(info.skelHandle);}this.entities_.clear();+ this.disabledEntities_.clear();}}diff --git a/sdk/src/spine/SpineController.ts b/sdk/src/spine/SpineController.tsindex af9bd6dbf..42b4c38ae 100644--- a/sdk/src/spine/SpineController.ts+++ b/sdk/src/spine/SpineController.ts@@ -8,6 +8,39 @@ import type { SpineWasmModule, SpineWrappedAPI } from './SpineModuleLoader';export type SpineEventType = 'start' | 'interrupt' | 'end' | 'complete' | 'dispose' | 'event';+export interface RawSpineEvent {+ type: number;+ track: number;+ floatValue: number;+ intValue: number;+ animationName: string;+ eventName: string;+ stringValue: string;+}++export interface ConstraintList {+ ik: string[];+ transform: string[];+ path: string[];+}++export interface TransformMixData {+ mixRotate: number;+ mixX: number;+ mixY: number;+ mixScaleX: number;+ mixScaleY: number;+ mixShearY: number;+}++export interface PathMixData {+ position: number;+ spacing: number;+ mixRotate: number;+ mixX: number;+ mixY: number;+}+export type SpineEventCallback = (event: SpineEvent) => void;export interface SpineEvent {@@ -281,7 +314,7 @@ export class SpineModuleController {this.api_.enableEvents(instanceId);}- collectEvents(instanceId: number): { type: number; track: number; floatValue: number; intValue: number }[] {+ collectEvents(instanceId: number): RawSpineEvent[] {const count = this.api_.getEventCount(instanceId);if (count === 0) return [];@@ -290,20 +323,71 @@ export class SpineModuleController {const f32 = this.raw_.HEAPF32;const base = bufferPtr >> 2;- const events: { type: number; track: number; floatValue: number; intValue: number }[] = [];+ const events: RawSpineEvent[] = [];for (let i = 0; i < count; i++) {const offset = base + i * EVENT_STRIDE;+ const typeNum = f32[offset];events.push({- type: f32[offset],+ type: typeNum,track: f32[offset + 1],floatValue: f32[offset + 2],intValue: f32[offset + 3],+ animationName: this.api_.getEventAnimationName(i),+ eventName: typeNum === 5 ? this.api_.getEventName(i) : '',+ stringValue: typeNum === 5 ? this.api_.getEventStringValue(i) : '',});}this.api_.clearEvents();return events;}+ // =========================================================================+ // Constraints+ // =========================================================================++ listConstraints(instanceId: number): ConstraintList {+ const json = this.api_.listConstraints(instanceId);+ try {+ return JSON.parse(json);+ } catch {+ return { ik: [], transform: [], path: [] };+ }+ }++ getTransformConstraintMix(instanceId: number, name: string): TransformMixData | null {+ const json = this.api_.getTransformConstraintMix(instanceId, name);+ if (!json) return null;+ try {+ return JSON.parse(json);+ } catch {+ return null;+ }+ }++ setTransformConstraintMix(instanceId: number, name: string, mix: TransformMixData): boolean {+ return !!this.api_.setTransformConstraintMix(instanceId, name,+ mix.mixRotate, mix.mixX, mix.mixY, mix.mixScaleX, mix.mixScaleY, mix.mixShearY);+ }++ getPathConstraintMix(instanceId: number, name: string): PathMixData | null {+ const json = this.api_.getPathConstraintMix(instanceId, name);+ if (!json) return null;+ try {+ return JSON.parse(json);+ } catch {+ return null;+ }+ }++ setPathConstraintMix(instanceId: number, name: string, mix: PathMixData): boolean {+ return !!this.api_.setPathConstraintMix(instanceId, name,+ mix.position, mix.spacing, mix.mixRotate, mix.mixX, mix.mixY);+ }++ // =========================================================================+ // Listeners+ // =========================================================================+on(entity: Entity, type: SpineEventType, callback: SpineEventCallback): void {if (!this.listeners_.has(entity)) {this.listeners_.set(entity, new Map());diff --git a/sdk/src/spine/SpineCppAPI.ts b/sdk/src/spine/SpineCppAPI.tsindex 3ecb2d583..978c507fd 100644--- a/sdk/src/spine/SpineCppAPI.ts+++ b/sdk/src/spine/SpineCppAPI.ts@@ -47,4 +47,40 @@ export const SpineCpp = {getSkins(entity: Entity): string[] {return module?.spine_getSkins?.(entity) ?? [];},++ listConstraints(entity: Entity): { ik: string[]; transform: string[]; path: string[] } | null {+ return (module as any)?.spine_native_listConstraints?.(entity) ?? null;+ },++ getTransformConstraintMix(entity: Entity, name: string): { mixRotate: number; mixX: number; mixY: number; mixScaleX: number; mixScaleY: number; mixShearY: number } | null {+ return (module as any)?.spine_native_getTransformConstraintMix?.(entity, name) ?? null;+ },++ setTransformConstraintMix(entity: Entity, name: string, rotate: number, x: number, y: number, scaleX: number, scaleY: number, shearY: number): boolean {+ return (module as any)?.spine_native_setTransformConstraintMix?.(entity, name, rotate, x, y, scaleX, scaleY, shearY) ?? false;+ },++ getPathConstraintMix(entity: Entity, name: string): { position: number; spacing: number; mixRotate: number; mixX: number; mixY: number } | null {+ return (module as any)?.spine_native_getPathConstraintMix?.(entity, name) ?? null;+ },++ setPathConstraintMix(entity: Entity, name: string, position: number, spacing: number, rotate: number, x: number, y: number): boolean {+ return (module as any)?.spine_native_setPathConstraintMix?.(entity, name, position, spacing, rotate, x, y) ?? false;+ },++ getEventCount(): number {+ return (module as any)?.spine_native_getEventCount?.() ?? 0;+ },++ getEventRecord(index: number): { entity: number; animationName: string; eventName: string; stringValue: string } | null {+ return (module as any)?.spine_native_getEventRecord?.(index) ?? null;+ },++ getEventBuffer(): number {+ return (module as any)?.spine_native_getEventBuffer?.() ?? 0;+ },++ clearEvents(): void {+ (module as any)?.spine_native_clearEvents?.();+ },};diff --git a/sdk/src/spine/SpineManager.ts b/sdk/src/spine/SpineManager.tsindex e2211ed64..a7e52faad 100644--- a/sdk/src/spine/SpineManager.ts+++ b/sdk/src/spine/SpineManager.ts@@ -1,9 +1,11 @@import type { ESEngineModule, CppRegistry } from '../wasm';import type { Entity } from '../types';+import type { RawSpineEvent, ConstraintList, TransformMixData, PathMixData } from './SpineController';import type { SpineModuleFactory } from './SpineModuleLoader';import { wrapSpineModule } from './SpineModuleLoader';import { SpineModuleController } from './SpineController';import { ModuleBackend } from './ModuleBackend';+import { SpineCpp } from './SpineCppAPI';export type SpineVersion = '3.8' | '4.1' | '4.2';@@ -190,11 +192,59 @@ export class SpineManager {return backend.setSlotColor(entity, slotName, r, g, b, a);}+ listConstraints(entity: Entity): ConstraintList | null {+ const backend = this.getEntityBackend_(entity);+ if (backend) return backend.listConstraints(entity);+ return SpineCpp.listConstraints(entity);+ }++ getTransformConstraintMix(entity: Entity, name: string): TransformMixData | null {+ const backend = this.getEntityBackend_(entity);+ if (backend) return backend.getTransformConstraintMix(entity, name);+ return SpineCpp.getTransformConstraintMix(entity, name);+ }++ setTransformConstraintMix(entity: Entity, name: string, mix: TransformMixData): boolean {+ const backend = this.getEntityBackend_(entity);+ if (backend) return backend.setTransformConstraintMix(entity, name, mix);+ return SpineCpp.setTransformConstraintMix(entity, name,+ mix.mixRotate, mix.mixX, mix.mixY, mix.mixScaleX, mix.mixScaleY, mix.mixShearY);+ }++ getPathConstraintMix(entity: Entity, name: string): PathMixData | null {+ const backend = this.getEntityBackend_(entity);+ if (backend) return backend.getPathConstraintMix(entity, name);+ return SpineCpp.getPathConstraintMix(entity, name);+ }++ setPathConstraintMix(entity: Entity, name: string, mix: PathMixData): boolean {+ const backend = this.getEntityBackend_(entity);+ if (backend) return backend.setPathConstraintMix(entity, name, mix);+ return SpineCpp.setPathConstraintMix(entity, name,+ mix.position, mix.spacing, mix.mixRotate, mix.mixX, mix.mixY);+ }++ setEnabled(entity: Entity, enabled: boolean): void {+ const backend = this.getEntityBackend_(entity);+ if (backend) backend.setEnabled(entity, enabled);+ }+enableEvents(entity: Entity): void {const backend = this.getEntityBackend_(entity);if (backend) backend.enableEvents(entity);}+ collectAllEvents(): { entity: Entity; raw: RawSpineEvent }[] {+ const result: { entity: Entity; raw: RawSpineEvent }[] = [];+ for (const backend of this.backends_.values()) {+ const events = backend.collectAllEvents();+ for (const evt of events) {+ result.push(evt);+ }+ }+ return result;+ }+hasInstance(entity: Entity): boolean {return this.entityVersions_.has(entity);}diff --git a/sdk/src/spine/SpineModuleLoader.ts b/sdk/src/spine/SpineModuleLoader.tsindex 70dd0f94d..ab6e5a67d 100644--- a/sdk/src/spine/SpineModuleLoader.ts+++ b/sdk/src/spine/SpineModuleLoader.ts@@ -39,10 +39,18 @@ export interface SpineWasmModule {_spine_getEventCount(instanceId: number): number;_spine_getEventBuffer(): number;_spine_clearEvents(): void;+ _spine_getEventAnimationName(index: number): number;+ _spine_getEventName(index: number): number;+ _spine_getEventStringValue(index: number): number;_spine_setAttachment(instanceId: number, slotName: number, attachmentName: number): number;_spine_setIKTarget(instanceId: number, constraintName: number, targetX: number, targetY: number, mix: number): number;_spine_setSlotColor(instanceId: number, slotName: number, r: number, g: number, b: number, a: number): number;+ _spine_listConstraints(instanceId: number): number;+ _spine_getTransformConstraintMix(instanceId: number, name: number): number;+ _spine_setTransformConstraintMix(instanceId: number, name: number, rotate: number, x: number, y: number, scaleX: number, scaleY: number, shearY: number): number;+ _spine_getPathConstraintMix(instanceId: number, name: number): number;+ _spine_setPathConstraintMix(instanceId: number, name: number, position: number, spacing: number, rotate: number, x: number, y: number): number;cwrap(ident: string, returnType: string | null, argTypes: string[]): (...args: unknown[]) => unknown;UTF8ToString(ptr: number): string;@@ -88,10 +96,18 @@ export interface SpineWrappedAPI {getEventCount(instanceId: number): number;getEventBuffer(): number;clearEvents(): void;+ getEventAnimationName(index: number): string;+ getEventName(index: number): string;+ getEventStringValue(index: number): string;setAttachment(instanceId: number, slotName: string, attachmentName: string): boolean;setIKTarget(instanceId: number, constraintName: string, targetX: number, targetY: number, mix: number): boolean;setSlotColor(instanceId: number, slotName: string, r: number, g: number, b: number, a: number): boolean;+ listConstraints(instanceId: number): string;+ getTransformConstraintMix(instanceId: number, name: string): string;+ setTransformConstraintMix(instanceId: number, name: string, rotate: number, x: number, y: number, scaleX: number, scaleY: number, shearY: number): boolean;+ getPathConstraintMix(instanceId: number, name: string): string;+ setPathConstraintMix(instanceId: number, name: string, position: number, spacing: number, rotate: number, x: number, y: number): boolean;}export function wrapSpineModule(raw: SpineWasmModule): SpineWrappedAPI {@@ -127,10 +143,18 @@ export function wrapSpineModule(raw: SpineWasmModule): SpineWrappedAPI {getEventCount: cw('spine_getEventCount', 'number', ['number']) as SpineWrappedAPI['getEventCount'],getEventBuffer: cw('spine_getEventBuffer', 'number', []) as SpineWrappedAPI['getEventBuffer'],clearEvents: cw('spine_clearEvents', null, []) as SpineWrappedAPI['clearEvents'],+ getEventAnimationName: cw('spine_getEventAnimationName', 'string', ['number']) as SpineWrappedAPI['getEventAnimationName'],+ getEventName: cw('spine_getEventName', 'string', ['number']) as SpineWrappedAPI['getEventName'],+ getEventStringValue: cw('spine_getEventStringValue', 'string', ['number']) as SpineWrappedAPI['getEventStringValue'],setAttachment: cw('spine_setAttachment', 'number', ['number', 'string', 'string']) as SpineWrappedAPI['setAttachment'],setIKTarget: cw('spine_setIKTarget', 'number', ['number', 'string', 'number', 'number', 'number']) as SpineWrappedAPI['setIKTarget'],setSlotColor: cw('spine_setSlotColor', 'number', ['number', 'string', 'number', 'number', 'number', 'number']) as SpineWrappedAPI['setSlotColor'],+ listConstraints: cw('spine_listConstraints', 'string', ['number']) as SpineWrappedAPI['listConstraints'],+ getTransformConstraintMix: cw('spine_getTransformConstraintMix', 'string', ['number', 'string']) as SpineWrappedAPI['getTransformConstraintMix'],+ setTransformConstraintMix: cw('spine_setTransformConstraintMix', 'number', ['number', 'string', 'number', 'number', 'number', 'number', 'number', 'number']) as SpineWrappedAPI['setTransformConstraintMix'],+ getPathConstraintMix: cw('spine_getPathConstraintMix', 'string', ['number', 'string']) as SpineWrappedAPI['getPathConstraintMix'],+ setPathConstraintMix: cw('spine_setPathConstraintMix', 'number', ['number', 'string', 'number', 'number', 'number', 'number', 'number']) as SpineWrappedAPI['setPathConstraintMix'],};}diff --git a/sdk/src/spine/SpinePlugin.ts b/sdk/src/spine/SpinePlugin.tsindex 6154ea444..7a3f45c2f 100644--- a/sdk/src/spine/SpinePlugin.ts+++ b/sdk/src/spine/SpinePlugin.ts@@ -1,13 +1,42 @@import type { Plugin } from '../app';import type { App } from '../app';-import { Time } from '../resource';+import { defineResource, Time } from '../resource';import { Schedule } from '../system';import type { SystemDef } from '../system';+import type { Entity } from '../types';import { initSpineCppAPI, SpineCpp } from './SpineCppAPI';import { SpineManager } from './SpineManager';import type { SpineWasmProvider } from './SpineModuleLoader';import { createSpineFactories } from './SpineModuleLoader';+export type SpineEventType = 'start' | 'interrupt' | 'end' | 'complete' | 'event';++export interface SpineEvent {+ entity: Entity;+ type: SpineEventType;+ track: number;+ animationName: string;+ eventName?: string;+ floatValue?: number;+ intValue?: number;+ stringValue?: string;+}++export interface SpineEventsData {+ readonly events: readonly SpineEvent[];+}++export const SpineEvents = defineResource<SpineEventsData>({ events: [] }, 'SpineEvents');++const SPINE_TYPE_MAP: Record<number, SpineEventType | null> = {+ 0: 'start',+ 1: 'interrupt',+ 2: 'end',+ 3: 'complete',+ 4: null,+ 5: 'event',+};+export class SpinePlugin implements Plugin {private spineManager_: SpineManager | null;private provider_: SpineWasmProvider | null;@@ -49,6 +78,8 @@ export class SpinePlugin implements Plugin {this.spineManager_ = new SpineManager(coreModule, factories);}+ app.insertResource(SpineEvents, { events: [] });+const self = this;const spineUpdateSystem: SystemDef = {@@ -61,6 +92,7 @@ export class SpinePlugin implements Plugin {const time = app.getResource(Time);SpineCpp.update({ _cpp: cppRegistry }, time.delta);self.spineManager_?.updateAnimations(time.delta);+ self.collectAndPublishEvents_(app);},};@@ -75,4 +107,73 @@ export class SpinePlugin implements Plugin {});}}++ private collectAndPublishEvents_(app: App): void {+ const events: SpineEvent[] = [];++ if (this.spineManager_) {+ for (const { entity, raw } of this.spineManager_.collectAllEvents()) {+ const type = SPINE_TYPE_MAP[raw.type];+ if (type === null || type === undefined) continue;+ const evt: SpineEvent = {+ entity,+ type,+ track: raw.track,+ animationName: raw.animationName,+ };+ if (type === 'event') {+ evt.eventName = raw.eventName;+ evt.floatValue = raw.floatValue;+ evt.intValue = raw.intValue;+ evt.stringValue = raw.stringValue;+ }+ events.push(evt);+ }+ }++ this.collectNativeEvents_(events);+ app.insertResource(SpineEvents, { events });+ }++ private collectNativeEvents_(events: SpineEvent[]): void {+ const EVENT_STRIDE = 4;+ const count = SpineCpp.getEventCount();+ if (count === 0) return;++ const bufferPtr = SpineCpp.getEventBuffer();+ const coreModule = this.app_?.wasmModule;+ if (!coreModule || !bufferPtr) {+ SpineCpp.clearEvents();+ return;+ }++ const f32 = coreModule.HEAPF32;+ const base = bufferPtr >> 2;++ for (let i = 0; i < count; i++) {+ const offset = base + i * EVENT_STRIDE;+ const typeNum = f32[offset];+ const type = SPINE_TYPE_MAP[typeNum];+ if (type === null || type === undefined) continue;++ const record = SpineCpp.getEventRecord(i);+ if (!record) continue;++ const evt: SpineEvent = {+ entity: record.entity as Entity,+ type,+ track: f32[offset + 1],+ animationName: record.animationName,+ };+ if (type === 'event') {+ evt.eventName = record.eventName;+ evt.floatValue = f32[offset + 2];+ evt.intValue = f32[offset + 3];+ evt.stringValue = record.stringValue;+ }+ events.push(evt);+ }++ SpineCpp.clearEvents();+ }}diff --git a/sdk/src/spine/index.ts b/sdk/src/spine/index.tsindex 0d3374454..3553ccdb8 100644--- a/sdk/src/spine/index.ts+++ b/sdk/src/spine/index.ts@@ -1,9 +1,10 @@-export { SpinePlugin } from './SpinePlugin';+export { SpinePlugin, SpineEvents } from './SpinePlugin';+export type { SpineEvent, SpineEventType, SpineEventsData } from './SpinePlugin';export { SpineCpp, initSpineCppAPI, shutdownSpineCppAPI } from './SpineCppAPI';export { SpineManager } from './SpineManager';export type { SpineVersion } from './SpineManager';export { ModuleBackend } from './ModuleBackend';export { SpineModuleController } from './SpineController';-export type { SpineEventType, SpineEventCallback, SpineEvent } from './SpineController';+export type { SpineEventCallback, ConstraintList, TransformMixData, PathMixData } from './SpineController';export type { SpineModuleFactory, SpineWasmProvider } from './SpineModuleLoader';export { loadSpineModule, wrapSpineModule, createSpineFactories } from './SpineModuleLoader';diff --git a/src/esengine/bindings/RendererBindings.cpp b/src/esengine/bindings/RendererBindings.cppindex 963b996bb..8c01abd1c 100644--- a/src/esengine/bindings/RendererBindings.cpp+++ b/src/esengine/bindings/RendererBindings.cpp@@ -190,6 +190,96 @@ void spine_setNeedsReload(ecs::Registry& registry, Entity entity, bool value) {auto& comp = registry.get<ecs::SpineAnimation>(entity);comp.needsReload = value;}++i32 spine_native_getEventCount() {+ if (!g_spineSystem) return 0;+ return g_spineSystem->getEventCount();+}++uintptr_t spine_native_getEventBuffer() {+ if (!g_spineSystem) return 0;+ return reinterpret_cast<uintptr_t>(g_spineSystem->getEventBuffer());+}++emscripten::val spine_native_getEventRecord(i32 index) {+ if (!g_spineSystem || index < 0 || index >= g_spineSystem->getEventCount()) {+ return emscripten::val::null();+ }+ auto& record = g_spineSystem->getEventRecord(index);+ auto result = emscripten::val::object();+ result.set("entity", static_cast<i32>(record.entity));+ result.set("animationName", record.animationName);+ result.set("eventName", record.eventName);+ result.set("stringValue", record.stringValue);+ return result;+}++void spine_native_clearEvents() {+ if (!g_spineSystem) return;+ g_spineSystem->clearEvents();+}++emscripten::val spine_native_listConstraints(Entity entity) {+ auto result = emscripten::val::object();+ if (!g_spineSystem) return result;++ auto names = g_spineSystem->listConstraints(entity);++ auto ikArr = emscripten::val::array();+ for (size_t i = 0; i < names.ik.size(); ++i) ikArr.call<void>("push", names.ik[i]);+ auto tfArr = emscripten::val::array();+ for (size_t i = 0; i < names.transform.size(); ++i) tfArr.call<void>("push", names.transform[i]);+ auto pathArr = emscripten::val::array();+ for (size_t i = 0; i < names.path.size(); ++i) pathArr.call<void>("push", names.path[i]);++ result.set("ik", ikArr);+ result.set("transform", tfArr);+ result.set("path", pathArr);+ return result;+}++emscripten::val spine_native_getTransformConstraintMix(Entity entity, const std::string& name) {+ if (!g_spineSystem) return emscripten::val::null();+ f32 rotate = 0, x = 0, y = 0, scaleX = 0, scaleY = 0, shearY = 0;+ if (!g_spineSystem->getTransformConstraintMix(entity, name, rotate, x, y, scaleX, scaleY, shearY)) {+ return emscripten::val::null();+ }+ auto result = emscripten::val::object();+ result.set("mixRotate", rotate);+ result.set("mixX", x);+ result.set("mixY", y);+ result.set("mixScaleX", scaleX);+ result.set("mixScaleY", scaleY);+ result.set("mixShearY", shearY);+ return result;+}++bool spine_native_setTransformConstraintMix(Entity entity, const std::string& name,+ f32 rotate, f32 x, f32 y, f32 scaleX, f32 scaleY, f32 shearY) {+ if (!g_spineSystem) return false;+ return g_spineSystem->setTransformConstraintMix(entity, name, rotate, x, y, scaleX, scaleY, shearY);+}++emscripten::val spine_native_getPathConstraintMix(Entity entity, const std::string& name) {+ if (!g_spineSystem) return emscripten::val::null();+ f32 position = 0, spacing = 0, rotate = 0, x = 0, y = 0;+ if (!g_spineSystem->getPathConstraintMix(entity, name, position, spacing, rotate, x, y)) {+ return emscripten::val::null();+ }+ auto result = emscripten::val::object();+ result.set("position", position);+ result.set("spacing", spacing);+ result.set("mixRotate", rotate);+ result.set("mixX", x);+ result.set("mixY", y);+ return result;+}++bool spine_native_setPathConstraintMix(Entity entity, const std::string& name,+ f32 position, f32 spacing, f32 rotate, f32 x, f32 y) {+ if (!g_spineSystem) return false;+ return g_spineSystem->setPathConstraintMix(entity, name, position, spacing, rotate, x, y);+}#endifvoid renderFrame(ecs::Registry& registry, i32 viewportWidth, i32 viewportHeight) {diff --git a/src/esengine/bindings/RendererBindings.hpp b/src/esengine/bindings/RendererBindings.hppindex ddcf89722..10877df75 100644--- a/src/esengine/bindings/RendererBindings.hpp+++ b/src/esengine/bindings/RendererBindings.hpp@@ -71,6 +71,18 @@ void renderer_submitSpineBatchByEntity(i32 layer, f32 depth);void spine_setNeedsReload(ecs::Registry& registry, Entity entity, bool value);+i32 spine_native_getEventCount();+uintptr_t spine_native_getEventBuffer();+emscripten::val spine_native_getEventRecord(i32 index);+void spine_native_clearEvents();++emscripten::val spine_native_listConstraints(Entity entity);+emscripten::val spine_native_getTransformConstraintMix(Entity entity, const std::string& name);+bool spine_native_setTransformConstraintMix(Entity entity, const std::string& name,+ f32 rotate, f32 x, f32 y, f32 scaleX, f32 scaleY, f32 shearY);+emscripten::val spine_native_getPathConstraintMix(Entity entity, const std::string& name);+bool spine_native_setPathConstraintMix(Entity entity, const std::string& name,+ f32 position, f32 spacing, f32 rotate, f32 x, f32 y);#endif#ifdef ES_ENABLE_PARTICLESvoid renderer_submitParticles(ecs::Registry& registry);diff --git a/src/esengine/bindings/SpineModuleEntry.cpp b/src/esengine/bindings/SpineModuleEntry.cppindex 8c5196b54..3d5bbf8af 100644--- a/src/esengine/bindings/SpineModuleEntry.cpp+++ b/src/esengine/bindings/SpineModuleEntry.cpp@@ -110,7 +110,14 @@ struct SpineContext {std::string stringBuffer;std::string lastError;+ struct EventRecord {+ const char* animationName = nullptr;+ const char* eventName = nullptr;+ const char* stringValue = nullptr;+ };+std::vector<float> eventBuffer;+ std::vector<EventRecord> eventRecords;int eventCount = 0;void reset() {@@ -133,6 +140,9 @@ struct SpineContext {worldVertices.clear();stringBuffer.clear();lastError.clear();+ eventBuffer.clear();+ eventRecords.clear();+ eventCount = 0;}};@@ -801,6 +811,15 @@ static void spineEventListener(spAnimationState* state, spEventType type,g_ctx.eventBuffer.push_back(0.0f);g_ctx.eventBuffer.push_back(0.0f);}++ SpineContext::EventRecord record{};+ record.animationName = (entry && entry->animation) ? entry->animation->name : nullptr;+ if (type == SP_ANIMATION_EVENT && event) {+ record.eventName = event->data->name;+ record.stringValue = event->stringValue;+ }+ g_ctx.eventRecords.push_back(record);+g_ctx.eventCount++;}@@ -825,9 +844,31 @@ uintptr_t spine_getEventBuffer() {EMSCRIPTEN_KEEPALIVEvoid spine_clearEvents() {g_ctx.eventBuffer.clear();+ g_ctx.eventRecords.clear();g_ctx.eventCount = 0;}+EMSCRIPTEN_KEEPALIVE+const char* spine_getEventAnimationName(int index) {+ if (index < 0 || index >= g_ctx.eventCount) return "";+ auto name = g_ctx.eventRecords[index].animationName;+ return name ? name : "";+}++EMSCRIPTEN_KEEPALIVE+const char* spine_getEventName(int index) {+ if (index < 0 || index >= g_ctx.eventCount) return "";+ auto name = g_ctx.eventRecords[index].eventName;+ return name ? name : "";+}++EMSCRIPTEN_KEEPALIVE+const char* spine_getEventStringValue(int index) {+ if (index < 0 || index >= g_ctx.eventCount) return "";+ auto val = g_ctx.eventRecords[index].stringValue;+ return val ? val : "";+}+// =============================================================================// Attachment Manipulation// =============================================================================@@ -864,6 +905,143 @@ int spine_setIKTarget(int instanceId, const char* constraintName,return 1;}+// =============================================================================+// Transform Constraint Control+// =============================================================================++EMSCRIPTEN_KEEPALIVE+const char* spine_listConstraints(int instanceId) {+ static std::string jsonBuf;+ auto it = g_ctx.instances.find(instanceId);+ if (it == g_ctx.instances.end()) return "{}";++ auto* skeleton = it->second.skeleton;+ jsonBuf = "{\"ik\":[";+ for (int i = 0; i < skeleton->ikConstraintsCount; ++i) {+ if (i > 0) jsonBuf += ',';+ jsonBuf += '"';+ jsonBuf += skeleton->ikConstraints[i]->data->name;+ jsonBuf += '"';+ }+ jsonBuf += "],\"transform\":[";+ for (int i = 0; i < skeleton->transformConstraintsCount; ++i) {+ if (i > 0) jsonBuf += ',';+ jsonBuf += '"';+ jsonBuf += skeleton->transformConstraints[i]->data->name;+ jsonBuf += '"';+ }+ jsonBuf += "],\"path\":[";+ for (int i = 0; i < skeleton->pathConstraintsCount; ++i) {+ if (i > 0) jsonBuf += ',';+ jsonBuf += '"';+ jsonBuf += skeleton->pathConstraints[i]->data->name;+ jsonBuf += '"';+ }+ jsonBuf += "]}";+ return jsonBuf.c_str();+}++EMSCRIPTEN_KEEPALIVE+const char* spine_getTransformConstraintMix(int instanceId, const char* name) {+ static std::string jsonBuf;+ auto it = g_ctx.instances.find(instanceId);+ if (it == g_ctx.instances.end()) return "";++ auto* constraint = spSkeleton_findTransformConstraint(it->second.skeleton, name);+ if (!constraint) return "";++ char buf[256];+#ifdef ES_SPINE_38+ snprintf(buf, sizeof(buf),+ "{\"mixRotate\":%.6g,\"mixX\":%.6g,\"mixY\":%.6g,\"mixScaleX\":%.6g,\"mixScaleY\":%.6g,\"mixShearY\":%.6g}",+ constraint->rotateMix, constraint->translateMix, constraint->translateMix,+ constraint->scaleMix, constraint->scaleMix, constraint->shearMix);+#else+ snprintf(buf, sizeof(buf),+ "{\"mixRotate\":%.6g,\"mixX\":%.6g,\"mixY\":%.6g,\"mixScaleX\":%.6g,\"mixScaleY\":%.6g,\"mixShearY\":%.6g}",+ constraint->mixRotate, constraint->mixX, constraint->mixY,+ constraint->mixScaleX, constraint->mixScaleY, constraint->mixShearY);+#endif+ jsonBuf = buf;+ return jsonBuf.c_str();+}++EMSCRIPTEN_KEEPALIVE+int spine_setTransformConstraintMix(int instanceId, const char* name,+ float rotate, float x, float y, float scaleX, float scaleY, float shearY) {+ auto it = g_ctx.instances.find(instanceId);+ if (it == g_ctx.instances.end()) return 0;++ auto* constraint = spSkeleton_findTransformConstraint(it->second.skeleton, name);+ if (!constraint) return 0;++#ifdef ES_SPINE_38+ constraint->rotateMix = rotate;+ constraint->translateMix = (x + y) * 0.5f;+ constraint->scaleMix = (scaleX + scaleY) * 0.5f;+ constraint->shearMix = shearY;+#else+ constraint->mixRotate = rotate;+ constraint->mixX = x;+ constraint->mixY = y;+ constraint->mixScaleX = scaleX;+ constraint->mixScaleY = scaleY;+ constraint->mixShearY = shearY;+#endif+ return 1;+}++// =============================================================================+// Path Constraint Control+// =============================================================================++EMSCRIPTEN_KEEPALIVE+const char* spine_getPathConstraintMix(int instanceId, const char* name) {+ static std::string jsonBuf;+ auto it = g_ctx.instances.find(instanceId);+ if (it == g_ctx.instances.end()) return "";++ auto* constraint = spSkeleton_findPathConstraint(it->second.skeleton, name);+ if (!constraint) return "";++ char buf[256];+#ifdef ES_SPINE_38+ snprintf(buf, sizeof(buf),+ "{\"position\":%.6g,\"spacing\":%.6g,\"mixRotate\":%.6g,\"mixX\":%.6g,\"mixY\":%.6g}",+ constraint->position, constraint->spacing,+ constraint->rotateMix, constraint->translateMix, constraint->translateMix);+#else+ snprintf(buf, sizeof(buf),+ "{\"position\":%.6g,\"spacing\":%.6g,\"mixRotate\":%.6g,\"mixX\":%.6g,\"mixY\":%.6g}",+ constraint->position, constraint->spacing,+ constraint->mixRotate, constraint->mixX, constraint->mixY);+#endif+ jsonBuf = buf;+ return jsonBuf.c_str();+}++EMSCRIPTEN_KEEPALIVE+int spine_setPathConstraintMix(int instanceId, const char* name,+ float position, float spacing, float rotate, float x, float y) {+ auto it = g_ctx.instances.find(instanceId);+ if (it == g_ctx.instances.end()) return 0;++ auto* constraint = spSkeleton_findPathConstraint(it->second.skeleton, name);+ if (!constraint) return 0;++ constraint->position = position;+ constraint->spacing = spacing;+#ifdef ES_SPINE_38+ constraint->rotateMix = rotate;+ constraint->translateMix = (x + y) * 0.5f;+#else+ constraint->mixRotate = rotate;+ constraint->mixX = x;+ constraint->mixY = y;+#endif+ return 1;+}+// =============================================================================// Slot Color Control// =============================================================================diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cppindex e92580ea5..df2ad7a9d 100644--- a/src/esengine/bindings/WebSDKEntry.cpp+++ b/src/esengine/bindings/WebSDKEntry.cpp@@ -544,6 +544,15 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {emscripten::function("renderer_submitSpineBatch", &esengine::renderer_submitSpineBatch);emscripten::function("renderer_submitSpineBatchByEntity", &esengine::renderer_submitSpineBatchByEntity);emscripten::function("spine_setNeedsReload", &esengine::spine_setNeedsReload);+ emscripten::function("spine_native_getEventCount", &esengine::spine_native_getEventCount);+ emscripten::function("spine_native_getEventBuffer", &esengine::spine_native_getEventBuffer);+ emscripten::function("spine_native_getEventRecord", &esengine::spine_native_getEventRecord);+ emscripten::function("spine_native_clearEvents", &esengine::spine_native_clearEvents);+ emscripten::function("spine_native_listConstraints", &esengine::spine_native_listConstraints);+ emscripten::function("spine_native_getTransformConstraintMix", &esengine::spine_native_getTransformConstraintMix);+ emscripten::function("spine_native_setTransformConstraintMix", &esengine::spine_native_setTransformConstraintMix);+ emscripten::function("spine_native_getPathConstraintMix", &esengine::spine_native_getPathConstraintMix);+ emscripten::function("spine_native_setPathConstraintMix", &esengine::spine_native_setPathConstraintMix);#endifemscripten::function("invalidateMaterialCache", &esengine::invalidateMaterialCache);diff --git a/src/esengine/spine/SpineSystem.cpp b/src/esengine/spine/SpineSystem.cppindex d6394b4b1..0e1bddb93 100644--- a/src/esengine/spine/SpineSystem.cpp+++ b/src/esengine/spine/SpineSystem.cpp@@ -81,6 +81,12 @@ void SpineSystem::loadSkeletonForEntity(Entity entity, ecs::SpineAnimation& compinstance.skeleton->setScaleX(comp.flipX ? -1.0f : 1.0f);instance.skeleton->setScaleY(comp.flipY ? -1.0f : 1.0f);+ instance.state->setListener(+ [this, entity](::spine::AnimationState*, ::spine::EventType type,+ ::spine::TrackEntry* entry, ::spine::Event* event) {+ recordEvent(entity, type, entry, event);+ });+comp.skeletonData = handle;comp.needsReload = false;@@ -242,4 +248,134 @@ std::vector<std::string> SpineSystem::getSkinNames(Entity entity) const {return result;}+// =============================================================================+// Constraints+// =============================================================================++SpineSystem::ConstraintNames SpineSystem::listConstraints(Entity entity) const {+ ConstraintNames result;+ auto it = instances_.find(entity);+ if (it == instances_.end() || !it->second.skeleton) return result;++ auto* data = it->second.skeleton->getData();++ auto& ikList = data->getIkConstraints();+ for (size_t i = 0; i < ikList.size(); ++i) {+ result.ik.emplace_back(ikList[i]->getName().buffer());+ }+ auto& transformList = data->getTransformConstraints();+ for (size_t i = 0; i < transformList.size(); ++i) {+ result.transform.emplace_back(transformList[i]->getName().buffer());+ }+ auto& pathList = data->getPathConstraints();+ for (size_t i = 0; i < pathList.size(); ++i) {+ result.path.emplace_back(pathList[i]->getName().buffer());+ }+ return result;+}++bool SpineSystem::getTransformConstraintMix(Entity entity, const std::string& name,+ f32& outRotate, f32& outX, f32& outY,+ f32& outScaleX, f32& outScaleY, f32& outShearY) const {+ auto it = instances_.find(entity);+ if (it == instances_.end() || !it->second.skeleton) return false;++ auto* constraint = it->second.skeleton->findTransformConstraint(name.c_str());+ if (!constraint) return false;++ outRotate = constraint->getMixRotate();+ outX = constraint->getMixX();+ outY = constraint->getMixY();+ outScaleX = constraint->getMixScaleX();+ outScaleY = constraint->getMixScaleY();+ outShearY = constraint->getMixShearY();+ return true;+}++bool SpineSystem::setTransformConstraintMix(Entity entity, const std::string& name,+ f32 rotate, f32 x, f32 y, f32 scaleX, f32 scaleY, f32 shearY) {+ auto it = instances_.find(entity);+ if (it == instances_.end() || !it->second.skeleton) return false;++ auto* constraint = it->second.skeleton->findTransformConstraint(name.c_str());+ if (!constraint) return false;++ constraint->setMixRotate(rotate);+ constraint->setMixX(x);+ constraint->setMixY(y);+ constraint->setMixScaleX(scaleX);+ constraint->setMixScaleY(scaleY);+ constraint->setMixShearY(shearY);+ return true;+}++bool SpineSystem::getPathConstraintMix(Entity entity, const std::string& name,+ f32& outPosition, f32& outSpacing,+ f32& outRotate, f32& outX, f32& outY) const {+ auto it = instances_.find(entity);+ if (it == instances_.end() || !it->second.skeleton) return false;++ auto* constraint = it->second.skeleton->findPathConstraint(name.c_str());+ if (!constraint) return false;++ outPosition = constraint->getPosition();+ outSpacing = constraint->getSpacing();+ outRotate = constraint->getMixRotate();+ outX = constraint->getMixX();+ outY = constraint->getMixY();+ return true;+}++bool SpineSystem::setPathConstraintMix(Entity entity, const std::string& name,+ f32 position, f32 spacing, f32 rotate, f32 x, f32 y) {+ auto it = instances_.find(entity);+ if (it == instances_.end() || !it->second.skeleton) return false;++ auto* constraint = it->second.skeleton->findPathConstraint(name.c_str());+ if (!constraint) return false;++ constraint->setPosition(position);+ constraint->setSpacing(spacing);+ constraint->setMixRotate(rotate);+ constraint->setMixX(x);+ constraint->setMixY(y);+ return true;+}++// =============================================================================+// Events+// =============================================================================++void SpineSystem::recordEvent(Entity entity, ::spine::EventType type,+ ::spine::TrackEntry* entry, ::spine::Event* event) {+ if (type == ::spine::EventType_Dispose) return;+ if (native_event_count_ >= MAX_NATIVE_EVENTS) return;++ auto idx = native_event_count_;+ auto base = idx * EVENT_STRIDE;++ native_event_buffer_[base + 0] = static_cast<f32>(type);+ native_event_buffer_[base + 1] = entry ? static_cast<f32>(entry->getTrackIndex()) : 0.0f;+ native_event_buffer_[base + 2] = (type == ::spine::EventType_Event && event) ? event->getFloatValue() : 0.0f;+ native_event_buffer_[base + 3] = (type == ::spine::EventType_Event && event) ? static_cast<f32>(event->getIntValue()) : 0.0f;++ auto& record = native_event_records_[idx];+ record.entity = entity;+ record.animationName = (entry && entry->getAnimation())+ ? entry->getAnimation()->getName().buffer() : "";+ if (type == ::spine::EventType_Event && event) {+ record.eventName = event->getData().getName().buffer();+ record.stringValue = event->getStringValue().buffer();+ } else {+ record.eventName.clear();+ record.stringValue.clear();+ }++ ++native_event_count_;+}++void SpineSystem::clearEvents() {+ native_event_count_ = 0;+}+} // namespace esengine::spinediff --git a/src/esengine/spine/SpineSystem.hpp b/src/esengine/spine/SpineSystem.hppindex 6dffa2226..181408378 100644--- a/src/esengine/spine/SpineSystem.hpp+++ b/src/esengine/spine/SpineSystem.hpp@@ -22,6 +22,7 @@#include <spine/spine.h>+#include <array>#include <unordered_map>namespace esengine::spine {@@ -169,7 +170,47 @@ public:std::vector<std::string> getAnimationNames(Entity entity) const;std::vector<std::string> getSkinNames(Entity entity) const;+ // ── Constraints ─────────────────────────────────────────────────────++ struct ConstraintNames {+ std::vector<std::string> ik;+ std::vector<std::string> transform;+ std::vector<std::string> path;+ };++ ConstraintNames listConstraints(Entity entity) const;++ bool getTransformConstraintMix(Entity entity, const std::string& name,+ f32& outRotate, f32& outX, f32& outY,+ f32& outScaleX, f32& outScaleY, f32& outShearY) const;+ bool setTransformConstraintMix(Entity entity, const std::string& name,+ f32 rotate, f32 x, f32 y, f32 scaleX, f32 scaleY, f32 shearY);++ bool getPathConstraintMix(Entity entity, const std::string& name,+ f32& outPosition, f32& outSpacing,+ f32& outRotate, f32& outX, f32& outY) const;+ bool setPathConstraintMix(Entity entity, const std::string& name,+ f32 position, f32 spacing, f32 rotate, f32 x, f32 y);++ // ── Event buffer ────────────────────────────────────────────────────+ static constexpr i32 MAX_NATIVE_EVENTS = 64;+ static constexpr i32 EVENT_STRIDE = 4;++ struct NativeEventRecord {+ Entity entity = 0;+ std::string animationName;+ std::string eventName;+ std::string stringValue;+ };++ i32 getEventCount() const { return native_event_count_; }+ const f32* getEventBuffer() const { return native_event_buffer_.data(); }+ const NativeEventRecord& getEventRecord(i32 index) const { return native_event_records_[index]; }+ void clearEvents();+private:+ void recordEvent(Entity entity, ::spine::EventType type,+ ::spine::TrackEntry* entry, ::spine::Event* event);void loadSkeletonForEntity(Entity entity, ecs::SpineAnimation& comp);void updateAnimation(Entity entity, ecs::SpineAnimation& comp, f32 deltaTime);void syncComponentToInstance(Entity entity, ecs::SpineAnimation& comp);@@ -177,6 +218,10 @@ private:SpineResourceManager& resource_manager_;std::unordered_map<Entity, SpineInstance> instances_;u32 destroy_callback_id_ = 0;++ std::array<f32, MAX_NATIVE_EVENTS * EVENT_STRIDE> native_event_buffer_{};+ std::array<NativeEventRecord, MAX_NATIVE_EVENTS> native_event_records_{};+ i32 native_event_count_ = 0;};} // namespace esengine::spinediff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txtindex d2b70f351..01c04cca7 100644--- a/third_party/CMakeLists.txt+++ b/third_party/CMakeLists.txt@@ -18,7 +18,7 @@ if(ES_ENABLE_SPINE)target_include_directories(spine-cpp PUBLIC${CMAKE_CURRENT_SOURCE_DIR}/spine-runtimes-4.2/spine-cpp/spine-cpp/include)- target_compile_definitions(spine-cpp PUBLIC SPINE_SHORT_NAMES)+ target_compile_definitions(spine-cpp PUBLIC SPINE_SHORT_NAMES SPINE_USE_STD_FUNCTION)if(NOT MSVC)target_compile_options(spine-cpp PRIVATE -Wno-unused-parameter -Wno-shadow)endif()