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
fix: suppress Vite dynamic import warning in SpineModuleLoader
esengine16bab7b55db9
diff --git a/desktop/public/sdk/esm/spine/index.js b/desktop/public/sdk/esm/spine/index.jsindex 55ac001d7..ee1d87436 100644--- a/desktop/public/sdk/esm/spine/index.js+++ b/desktop/public/sdk/esm/spine/index.js@@ -1,2 +1,2 @@-import{S as e,f as t}from"../shared/system.js";function n(e){const t=e.cwrap.bind(e);return{loadSkeleton:t("spine_loadSkeleton","number",["number","number","string","number","number"]),getLastError:t("spine_getLastError","string",[]),unloadSkeleton:t("spine_unloadSkeleton",null,["number"]),getAtlasPageCount:t("spine_getAtlasPageCount","number",["number"]),getAtlasPageTextureName:t("spine_getAtlasPageTextureName","string",["number","number"]),setAtlasPageTexture:t("spine_setAtlasPageTexture",null,["number","number","number","number","number"]),createInstance:t("spine_createInstance","number",["number"]),destroyInstance:t("spine_destroyInstance",null,["number"]),playAnimation:t("spine_playAnimation","number",["number","string","number","number"]),addAnimation:t("spine_addAnimation","number",["number","string","number","number","number"]),setSkin:t("spine_setSkin",null,["number","string"]),update:t("spine_update",null,["number","number"]),getAnimations:t("spine_getAnimations","string",["number"]),getSkins:t("spine_getSkins","string",["number"]),getBonePosition:t("spine_getBonePosition","number",["number","string","number","number"]),getBoneRotation:t("spine_getBoneRotation","number",["number","string"]),getBounds:t("spine_getBounds",null,["number","number","number","number","number"]),getMeshBatchCount:t("spine_getMeshBatchCount","number",["number"]),getMeshBatchVertexCount:t("spine_getMeshBatchVertexCount","number",["number","number"]),getMeshBatchIndexCount:t("spine_getMeshBatchIndexCount","number",["number","number"]),getMeshBatchData:t("spine_getMeshBatchData",null,["number","number","number","number","number","number"])}}function s(e){const t=["3.8","4.1","4.2"],n=new Map;for(const s of t)n.set(s,async()=>{const[t,n]=await Promise.all([e.loadJs(s),e.loadWasm(s)]),i=new Blob([`${t};\nself.__ESSpineModule__ = ESSpineModule;`],{type:"application/javascript"}),r=URL.createObjectURL(i);await import(r),URL.revokeObjectURL(r);const a=globalThis.__ESSpineModule__;return delete globalThis.__ESSpineModule__,a({instantiateWasm:(e,t)=>(WebAssembly.instantiate(n,e).then(e=>t(e.instance,e.module)).catch(e=>{console.error("[Spine] WASM instantiation failed:",e)}),{})})});return n}async function i(e,t){if(!t)throw new Error("SpineModuleLoader: factory parameter is required. Pass the Spine WASM factory function explicitly via loadSpineModule(url, factory).");const s=await t();return{raw:s,api:n(s)}}class r{constructor(e,t){this.raw_=e,this.api_=t,this.listeners_=new Map}get raw(){return this.raw_}loadSkeleton(e,t,n){let s,i;if("string"==typeof e){const t=(new TextEncoder).encode(e);i=t.length,s=this.raw_._malloc(i+1),this.raw_.HEAPU8.set(t,s),this.raw_.HEAPU8[s+i]=0}else i=e.length,s=this.raw_._malloc(i),this.raw_.HEAPU8.set(e,s);const r=this.api_.loadSkeleton(s,i,t,t.length,n);return this.raw_._free(s),r}getLastError(){return this.api_.getLastError()}unloadSkeleton(e){this.api_.unloadSkeleton(e)}getAtlasPageCount(e){return this.api_.getAtlasPageCount(e)}getAtlasPageTextureName(e,t){return this.api_.getAtlasPageTextureName(e,t)}setAtlasPageTexture(e,t,n,s,i){this.api_.setAtlasPageTexture(e,t,n,s,i)}createInstance(e){return this.api_.createInstance(e)}destroyInstance(e){this.api_.destroyInstance(e),this.listeners_.delete(e)}play(e,t,n=!0,s=0){return!!this.api_.playAnimation(e,t,n,s)}addAnimation(e,t,n=!0,s=0,i=0){return!!this.api_.addAnimation(e,t,n,s,i)}setSkin(e,t){this.api_.setSkin(e,t)}update(e,t){this.api_.update(e,t)}getAnimations(e){const t=this.api_.getAnimations(e);try{return JSON.parse(t)}catch(e){return console.warn("[Spine] Failed to parse animations JSON",e),[]}}getSkins(e){const t=this.api_.getSkins(e);try{return JSON.parse(t)}catch(e){return console.warn("[Spine] Failed to parse skins JSON",e),[]}}getBonePosition(e,t){const n=this.raw_._malloc(4),s=this.raw_._malloc(4);if(!this.api_.getBonePosition(e,t,n,s))return this.raw_._free(n),this.raw_._free(s),null;const i=this.raw_.HEAPF32[n>>2],r=this.raw_.HEAPF32[s>>2];return this.raw_._free(n),this.raw_._free(s),{x:i,y:r}}getBoneRotation(e,t){return this.api_.getBoneRotation(e,t)}getBounds(e){const t=this.raw_._malloc(16);this.api_.getBounds(e,t,t+4,t+8,t+12);const n=this.raw_.HEAPF32,s=t>>2,i={x:n[s],y:n[s+1],width:n[s+2],height:n[s+3]};return this.raw_._free(t),i}extractMeshBatches(e){const t=this.api_.getMeshBatchCount(e),n=[],s=this.raw_._malloc(8),i=s,r=s+4;for(let s=0;s<t;s++){const t=this.api_.getMeshBatchVertexCount(e,s),a=this.api_.getMeshBatchIndexCount(e,s);if(t<=0||a<=0)continue;const o=8*t*4,l=2*a,c=this.raw_._malloc(o),u=this.raw_._malloc(l);this.api_.getMeshBatchData(e,s,c,u,i,r);const h=new Float32Array(this.raw_.HEAPF32.buffer,c,8*t),_=new Uint16Array(this.raw_.HEAPU8.buffer,u,a);n.push({vertices:new Float32Array(h),indices:new Uint16Array(_),textureId:this.raw_.HEAPU32[i>>2],blendMode:this.raw_.HEAPU32[r>>2]}),this.raw_._free(c),this.raw_._free(u)}return this.raw_._free(s),n}on(e,t,n){this.listeners_.has(e)||this.listeners_.set(e,new Map);const s=this.listeners_.get(e);s.has(t)||s.set(t,new Set),s.get(t).add(n)}off(e,t,n){const s=this.listeners_.get(e);if(!s)return;const i=s.get(t);i&&i.delete(n)}removeAllListeners(e){this.listeners_.delete(e)}}class a{constructor(e){this.entities_=new Map,this.transform16_=new Float32Array(16),this.controller_=e}get controller(){return this.controller_}get entityCount(){return this.entities_.size}loadEntity(e,t,n,s,i){const r=this.controller_.loadSkeleton(t,n,i);if(r<0)return console.error(`[ModuleBackend] Failed to load skeleton: ${this.controller_.getLastError()}`),!1;const a=this.controller_.getAtlasPageCount(r);for(let e=0;e<a;e++){const t=this.controller_.getAtlasPageTextureName(r,e),n=s.get(t);n&&this.controller_.setAtlasPageTexture(r,e,n.glId,n.w,n.h)}const o=this.controller_.createInstance(r);return this.entities_.set(e,{skelHandle:r,instanceId:o,skeletonScale:1,flipX:!1,flipY:!1,layer:0}),!0}setEntityProps(e,t){const n=this.entities_.get(e);n&&(void 0!==t.skeletonScale&&(n.skeletonScale=t.skeletonScale),void 0!==t.flipX&&(n.flipX=t.flipX),void 0!==t.flipY&&(n.flipY=t.flipY),void 0!==t.layer&&(n.layer=t.layer))}setAnimation(e,t,n){const s=this.entities_.get(e);s&&this.controller_.play(s.instanceId,t,n)}setSkin(e,t){const n=this.entities_.get(e);n&&this.controller_.setSkin(n.instanceId,t)}getBounds(e){const t=this.entities_.get(e);return t?this.controller_.getBounds(t.instanceId):null}getAnimations(e){const t=this.entities_.get(e);return t?this.controller_.getAnimations(t.instanceId):[]}getSkins(e){const t=this.entities_.get(e);return t?this.controller_.getSkins(t.instanceId):[]}updateAll(e){for(const t of this.entities_.values())this.controller_.update(t.instanceId,e)}extractAndSubmitMeshes(e,t){const n=e.renderer_submitSpineBatch;if(!n)return;const s=e.HEAPF32;for(const[i,r]of this.entities_){const a=e.getTransformPtr?.(t,i);if(!a)continue;this.buildTransformMatrix_(s,a,r.skeletonScale,r.flipX,r.flipY);const o=this.controller_.extractMeshBatches(r.instanceId);for(const t of o){const s=t.vertices.length/8,a=t.indices.length;if(s<=0||a<=0)continue;const o=t.vertices.byteLength,l=t.indices.byteLength,c=64,u=e._malloc(o),h=e._malloc(l),_=e._malloc(c);e.HEAPF32.set(t.vertices,u>>2),new Uint16Array(e.HEAPU8.buffer,h,a).set(t.indices),e.HEAPF32.set(this.transform16_,_>>2),n.call(e,u,s,h,a,t.textureId,t.blendMode,_,i,r.layer,0),e._free(u),e._free(h),e._free(_)}}}removeEntity(e){const t=this.entities_.get(e);t&&(this.controller_.destroyInstance(t.instanceId),this.controller_.unloadSkeleton(t.skelHandle),this.entities_.delete(e))}shutdown(){for(const e of this.entities_.values())this.controller_.destroyInstance(e.instanceId),this.controller_.unloadSkeleton(e.skelHandle);this.entities_.clear()}buildTransformMatrix_(e,t,n,s,i){const r=t>>2,a=r+10,o=r+13,l=r+17,c=e[a],u=e[a+1],h=e[a+2],_=e[o],d=e[o+1],p=e[o+2],g=e[o+3],m=e[l]*n*(s?-1:1),f=e[l+1]*n*(i?-1:1),b=e[l+2],y=_+_,S=d+d,k=p+p,w=_*y,A=_*S,M=_*k,B=d*S,P=d*k,E=p*k,v=g*y,x=g*S,I=g*k,V=this.transform16_;V[0]=(1-(B+E))*m,V[1]=(A+I)*m,V[2]=(M-x)*m,V[3]=0,V[4]=(A-I)*f,V[5]=(1-(w+E))*f,V[6]=(P+v)*f,V[7]=0,V[8]=(M+x)*b,V[9]=(P-v)*b,V[10]=(1-(w+B))*b,V[11]=0,V[12]=c,V[13]=u,V[14]=h,V[15]=1}}class o{constructor(e,t){this.backends_=new Map,this.loadingBackends_=new Map,this.entityVersions_=new Map,this.coreModule_=e,this.factories_=t}static detectVersion(e){const t=function(e){if(e.length<10)return null;let t=8;const{value:n,bytesRead:s}=l(e,t);if(t+=s,n<=1||t+n-1>e.length)return null;const i=(new TextDecoder).decode(e.subarray(t,t+n-1));return i.startsWith("4.2")?"4.2":i.startsWith("4.1")?"4.1":null}(e);return t||function(e){if(e.length<4)return null;let t=0;const{value:n,bytesRead:s}=l(e,t);t+=s,n>0&&(t+=n-1);if(t>=e.length)return null;const{value:i,bytesRead:r}=l(e,t);if(t+=r,i<=1||t+i-1>e.length)return null;const a=(new TextDecoder).decode(e.subarray(t,t+i-1));return a.startsWith("3.")?"3.8":null}(e)}static detectVersionJson(e){const t=e.match(/"spine"\s*:\s*"(\d+\.\d+)/);return t?t[1].startsWith("4.2")?"4.2":t[1].startsWith("4.1")?"4.1":t[1].startsWith("3.")?"3.8":null:null}async loadEntity(e,t,n,s,i){const r="string"==typeof t?o.detectVersionJson(t):o.detectVersion(t);if(!r)return null;if("4.2"===r&&!this.factories_.has("4.2"))return this.entityVersions_.set(e,"4.2"),"4.2";this.coreModule_.spine_setNeedsReload?.(i,e,!1);const a=await this.ensureBackend(r);if(!a)return console.error(`[SpineManager] Failed to create backend for version ${r}`),null;const l=t instanceof Uint8Array;return a.loadEntity(e,t,n,s,l)?(this.entityVersions_.set(e,r),r):(console.error(`[SpineManager] Failed to load entity ${e} into backend ${r}`),null)}updateAnimations(e){for(const t of this.backends_.values())t.updateAll(e)}submitMeshes(e){for(const t of this.backends_.values())t.extractAndSubmitMeshes(this.coreModule_,e)}removeEntity(e){const t=this.entityVersions_.get(e);if(!t)return void this.entityVersions_.delete(e);const n=this.backends_.get(t);n&&n.removeEntity(e),this.entityVersions_.delete(e)}getEntityVersion(e){return this.entityVersions_.get(e)}hasModuleBackend(e){return this.backends_.has(e)}getModuleBackend(e){return this.backends_.get(e)}setAnimation(e,t,n){const s=this.entityVersions_.get(e);if(!s)return;const i=this.backends_.get(s);i&&i.setAnimation(e,t,n)}setSkin(e,t){const n=this.entityVersions_.get(e);if(!n)return;const s=this.backends_.get(n);s&&s.setSkin(e,t)}setEntityProps(e,t){const n=this.entityVersions_.get(e);if(!n)return;const s=this.backends_.get(n);s&&s.setEntityProps(e,t)}getBounds(e){const t=this.entityVersions_.get(e);if(!t)return null;const n=this.backends_.get(t);return n?n.getBounds(e):null}getAnimations(e){const t=this.entityVersions_.get(e);if(!t)return[];const n=this.backends_.get(t);return n?n.getAnimations(e):[]}getSkins(e){const t=this.entityVersions_.get(e);if(!t)return[];const n=this.backends_.get(t);return n?n.getSkins(e):[]}hasInstance(e){return this.entityVersions_.has(e)}shutdown(){for(const e of this.backends_.values())e.shutdown();this.backends_.clear(),this.loadingBackends_.clear(),this.entityVersions_.clear()}async ensureBackend(e){const t=this.backends_.get(e);if(t)return t;const s=this.loadingBackends_.get(e);if(s)return s;const i=this.factories_.get(e);if(!i)return console.warn(`[SpineManager] No module factory for version ${e}`),null;const o=(async()=>{try{const t=await i(),s=n(t),o=new r(t,s),l=new a(o);return this.backends_.set(e,l),l}catch(t){return console.error(`[SpineManager] Failed to load WASM module for version ${e}:`,t),null}finally{this.loadingBackends_.delete(e)}})();return this.loadingBackends_.set(e,o),o}}function l(e,t){let n=0,s=0,i=0;do{const r=e[t+i++];if(n|=(127&r)<<s,s+=7,!(128&r))break}while(s<35);return{value:n,bytesRead:i}}let c=null;function u(e){c=e}function h(){c=null}const _={update(e,t){c?.spine_update?.(e._cpp,t)},play:(e,t,n=!0,s=0)=>c?.spine_play?.(e,t,n,s)??!1,addAnimation:(e,t,n=!0,s=0,i=0)=>c?.spine_addAnimation?.(e,t,n,s,i)??!1,setSkin:(e,t)=>c?.spine_setSkin?.(e,t)??!1,getBonePosition:(e,t)=>c?.spine_getBonePosition?.(e,t)??null,hasInstance:e=>c?.spine_hasInstance?.(e)??!1,reloadAssets(e){c?.spine_reloadAssets?.(e._cpp)},getAnimations:e=>c?.spine_getAnimations?.(e)??[],getSkins:e=>c?.spine_getSkins?.(e)??[]};class d{constructor(e){this.app_=null,e instanceof o?(this.spineManager_=e,this.provider_=null):(this.spineManager_=null,this.provider_=e??null)}get spineManager(){return this.spineManager_}setSpineManager(e){if(this.spineManager_=e,this.app_){const t=this.app_.pipeline;t?.addPreFlushCallback(t=>{e.submitMeshes(t._cpp)})}}build(n){this.app_=n;const i=n.wasmModule;if(u(i),!this.spineManager_&&this.provider_){const e=s(this.provider_);this.spineManager_=new o(i,e)}const r=this,a={_id:Symbol("SpineUpdateSystem"),_name:"SpineUpdateSystem",_params:[],_fn:()=>{const e=n.world.getCppRegistry();if(!e)return;const s=n.getResource(t);_.update({_cpp:e},s.delta),r.spineManager_?.updateAnimations(s.delta)}};if(n.addSystemToSchedule(e.PreUpdate,a),this.spineManager_){const e=this.spineManager_,t=n.pipeline;t?.addPreFlushCallback(t=>{e.submitMeshes(t._cpp)})}}}export{a as ModuleBackend,_ as SpineCpp,o as SpineManager,r as SpineModuleController,d as SpinePlugin,s as createSpineFactories,u as initSpineCppAPI,i as loadSpineModule,h as shutdownSpineCppAPI,n as wrapSpineModule};+import{S as e,f as t}from"../shared/system.js";function n(e){const t=e.cwrap.bind(e);return{loadSkeleton:t("spine_loadSkeleton","number",["number","number","string","number","number"]),getLastError:t("spine_getLastError","string",[]),unloadSkeleton:t("spine_unloadSkeleton",null,["number"]),getAtlasPageCount:t("spine_getAtlasPageCount","number",["number"]),getAtlasPageTextureName:t("spine_getAtlasPageTextureName","string",["number","number"]),setAtlasPageTexture:t("spine_setAtlasPageTexture",null,["number","number","number","number","number"]),createInstance:t("spine_createInstance","number",["number"]),destroyInstance:t("spine_destroyInstance",null,["number"]),playAnimation:t("spine_playAnimation","number",["number","string","number","number"]),addAnimation:t("spine_addAnimation","number",["number","string","number","number","number"]),setSkin:t("spine_setSkin",null,["number","string"]),update:t("spine_update",null,["number","number"]),getAnimations:t("spine_getAnimations","string",["number"]),getSkins:t("spine_getSkins","string",["number"]),getBonePosition:t("spine_getBonePosition","number",["number","string","number","number"]),getBoneRotation:t("spine_getBoneRotation","number",["number","string"]),getBounds:t("spine_getBounds",null,["number","number","number","number","number"]),getMeshBatchCount:t("spine_getMeshBatchCount","number",["number"]),getMeshBatchVertexCount:t("spine_getMeshBatchVertexCount","number",["number","number"]),getMeshBatchIndexCount:t("spine_getMeshBatchIndexCount","number",["number","number"]),getMeshBatchData:t("spine_getMeshBatchData",null,["number","number","number","number","number","number"])}}function s(e){const t=["3.8","4.1","4.2"],n=new Map;for(const s of t)n.set(s,async()=>{const[t,n]=await Promise.all([e.loadJs(s),e.loadWasm(s)]),i=new Blob([`${t};\nself.__ESSpineModule__ = ESSpineModule;`],{type:"application/javascript"}),r=URL.createObjectURL(i);await import(/* @vite-ignore */r),URL.revokeObjectURL(r);const a=globalThis.__ESSpineModule__;return delete globalThis.__ESSpineModule__,a({instantiateWasm:(e,t)=>(WebAssembly.instantiate(n,e).then(e=>t(e.instance,e.module)).catch(e=>{console.error("[Spine] WASM instantiation failed:",e)}),{})})});return n}async function i(e,t){if(!t)throw new Error("SpineModuleLoader: factory parameter is required. Pass the Spine WASM factory function explicitly via loadSpineModule(url, factory).");const s=await t();return{raw:s,api:n(s)}}class r{constructor(e,t){this.raw_=e,this.api_=t,this.listeners_=new Map}get raw(){return this.raw_}loadSkeleton(e,t,n){let s,i;if("string"==typeof e){const t=(new TextEncoder).encode(e);i=t.length,s=this.raw_._malloc(i+1),this.raw_.HEAPU8.set(t,s),this.raw_.HEAPU8[s+i]=0}else i=e.length,s=this.raw_._malloc(i),this.raw_.HEAPU8.set(e,s);const r=this.api_.loadSkeleton(s,i,t,t.length,n);return this.raw_._free(s),r}getLastError(){return this.api_.getLastError()}unloadSkeleton(e){this.api_.unloadSkeleton(e)}getAtlasPageCount(e){return this.api_.getAtlasPageCount(e)}getAtlasPageTextureName(e,t){return this.api_.getAtlasPageTextureName(e,t)}setAtlasPageTexture(e,t,n,s,i){this.api_.setAtlasPageTexture(e,t,n,s,i)}createInstance(e){return this.api_.createInstance(e)}destroyInstance(e){this.api_.destroyInstance(e),this.listeners_.delete(e)}play(e,t,n=!0,s=0){return!!this.api_.playAnimation(e,t,n,s)}addAnimation(e,t,n=!0,s=0,i=0){return!!this.api_.addAnimation(e,t,n,s,i)}setSkin(e,t){this.api_.setSkin(e,t)}update(e,t){this.api_.update(e,t)}getAnimations(e){const t=this.api_.getAnimations(e);try{return JSON.parse(t)}catch(e){return console.warn("[Spine] Failed to parse animations JSON",e),[]}}getSkins(e){const t=this.api_.getSkins(e);try{return JSON.parse(t)}catch(e){return console.warn("[Spine] Failed to parse skins JSON",e),[]}}getBonePosition(e,t){const n=this.raw_._malloc(4),s=this.raw_._malloc(4);if(!this.api_.getBonePosition(e,t,n,s))return this.raw_._free(n),this.raw_._free(s),null;const i=this.raw_.HEAPF32[n>>2],r=this.raw_.HEAPF32[s>>2];return this.raw_._free(n),this.raw_._free(s),{x:i,y:r}}getBoneRotation(e,t){return this.api_.getBoneRotation(e,t)}getBounds(e){const t=this.raw_._malloc(16);this.api_.getBounds(e,t,t+4,t+8,t+12);const n=this.raw_.HEAPF32,s=t>>2,i={x:n[s],y:n[s+1],width:n[s+2],height:n[s+3]};return this.raw_._free(t),i}extractMeshBatches(e){const t=this.api_.getMeshBatchCount(e),n=[],s=this.raw_._malloc(8),i=s,r=s+4;for(let s=0;s<t;s++){const t=this.api_.getMeshBatchVertexCount(e,s),a=this.api_.getMeshBatchIndexCount(e,s);if(t<=0||a<=0)continue;const o=8*t*4,l=2*a,c=this.raw_._malloc(o),u=this.raw_._malloc(l);this.api_.getMeshBatchData(e,s,c,u,i,r);const h=new Float32Array(this.raw_.HEAPF32.buffer,c,8*t),_=new Uint16Array(this.raw_.HEAPU8.buffer,u,a);n.push({vertices:new Float32Array(h),indices:new Uint16Array(_),textureId:this.raw_.HEAPU32[i>>2],blendMode:this.raw_.HEAPU32[r>>2]}),this.raw_._free(c),this.raw_._free(u)}return this.raw_._free(s),n}on(e,t,n){this.listeners_.has(e)||this.listeners_.set(e,new Map);const s=this.listeners_.get(e);s.has(t)||s.set(t,new Set),s.get(t).add(n)}off(e,t,n){const s=this.listeners_.get(e);if(!s)return;const i=s.get(t);i&&i.delete(n)}removeAllListeners(e){this.listeners_.delete(e)}}class a{constructor(e){this.entities_=new Map,this.transform16_=new Float32Array(16),this.controller_=e}get controller(){return this.controller_}get entityCount(){return this.entities_.size}loadEntity(e,t,n,s,i){const r=this.controller_.loadSkeleton(t,n,i);if(r<0)return console.error(`[ModuleBackend] Failed to load skeleton: ${this.controller_.getLastError()}`),!1;const a=this.controller_.getAtlasPageCount(r);for(let e=0;e<a;e++){const t=this.controller_.getAtlasPageTextureName(r,e),n=s.get(t);n&&this.controller_.setAtlasPageTexture(r,e,n.glId,n.w,n.h)}const o=this.controller_.createInstance(r);return this.entities_.set(e,{skelHandle:r,instanceId:o,skeletonScale:1,flipX:!1,flipY:!1,layer:0}),!0}setEntityProps(e,t){const n=this.entities_.get(e);n&&(void 0!==t.skeletonScale&&(n.skeletonScale=t.skeletonScale),void 0!==t.flipX&&(n.flipX=t.flipX),void 0!==t.flipY&&(n.flipY=t.flipY),void 0!==t.layer&&(n.layer=t.layer))}setAnimation(e,t,n){const s=this.entities_.get(e);s&&this.controller_.play(s.instanceId,t,n)}setSkin(e,t){const n=this.entities_.get(e);n&&this.controller_.setSkin(n.instanceId,t)}getBounds(e){const t=this.entities_.get(e);return t?this.controller_.getBounds(t.instanceId):null}getAnimations(e){const t=this.entities_.get(e);return t?this.controller_.getAnimations(t.instanceId):[]}getSkins(e){const t=this.entities_.get(e);return t?this.controller_.getSkins(t.instanceId):[]}updateAll(e){for(const t of this.entities_.values())this.controller_.update(t.instanceId,e)}extractAndSubmitMeshes(e,t){const n=e.renderer_submitSpineBatch;if(!n)return;const s=e.HEAPF32;for(const[i,r]of this.entities_){const a=e.getTransformPtr?.(t,i);if(!a)continue;this.buildTransformMatrix_(s,a,r.skeletonScale,r.flipX,r.flipY);const o=this.controller_.extractMeshBatches(r.instanceId);for(const t of o){const s=t.vertices.length/8,a=t.indices.length;if(s<=0||a<=0)continue;const o=t.vertices.byteLength,l=t.indices.byteLength,c=64,u=e._malloc(o),h=e._malloc(l),_=e._malloc(c);e.HEAPF32.set(t.vertices,u>>2),new Uint16Array(e.HEAPU8.buffer,h,a).set(t.indices),e.HEAPF32.set(this.transform16_,_>>2),n.call(e,u,s,h,a,t.textureId,t.blendMode,_,i,r.layer,0),e._free(u),e._free(h),e._free(_)}}}removeEntity(e){const t=this.entities_.get(e);t&&(this.controller_.destroyInstance(t.instanceId),this.controller_.unloadSkeleton(t.skelHandle),this.entities_.delete(e))}shutdown(){for(const e of this.entities_.values())this.controller_.destroyInstance(e.instanceId),this.controller_.unloadSkeleton(e.skelHandle);this.entities_.clear()}buildTransformMatrix_(e,t,n,s,i){const r=t>>2,a=r+10,o=r+13,l=r+17,c=e[a],u=e[a+1],h=e[a+2],_=e[o],d=e[o+1],p=e[o+2],g=e[o+3],m=e[l]*n*(s?-1:1),f=e[l+1]*n*(i?-1:1),b=e[l+2],y=_+_,S=d+d,k=p+p,w=_*y,A=_*S,M=_*k,B=d*S,P=d*k,E=p*k,v=g*y,x=g*S,I=g*k,V=this.transform16_;V[0]=(1-(B+E))*m,V[1]=(A+I)*m,V[2]=(M-x)*m,V[3]=0,V[4]=(A-I)*f,V[5]=(1-(w+E))*f,V[6]=(P+v)*f,V[7]=0,V[8]=(M+x)*b,V[9]=(P-v)*b,V[10]=(1-(w+B))*b,V[11]=0,V[12]=c,V[13]=u,V[14]=h,V[15]=1}}class o{constructor(e,t){this.backends_=new Map,this.loadingBackends_=new Map,this.entityVersions_=new Map,this.coreModule_=e,this.factories_=t}static detectVersion(e){const t=function(e){if(e.length<10)return null;let t=8;const{value:n,bytesRead:s}=l(e,t);if(t+=s,n<=1||t+n-1>e.length)return null;const i=(new TextDecoder).decode(e.subarray(t,t+n-1));return i.startsWith("4.2")?"4.2":i.startsWith("4.1")?"4.1":null}(e);return t||function(e){if(e.length<4)return null;let t=0;const{value:n,bytesRead:s}=l(e,t);t+=s,n>0&&(t+=n-1);if(t>=e.length)return null;const{value:i,bytesRead:r}=l(e,t);if(t+=r,i<=1||t+i-1>e.length)return null;const a=(new TextDecoder).decode(e.subarray(t,t+i-1));return a.startsWith("3.")?"3.8":null}(e)}static detectVersionJson(e){const t=e.match(/"spine"\s*:\s*"(\d+\.\d+)/);return t?t[1].startsWith("4.2")?"4.2":t[1].startsWith("4.1")?"4.1":t[1].startsWith("3.")?"3.8":null:null}async loadEntity(e,t,n,s,i){const r="string"==typeof t?o.detectVersionJson(t):o.detectVersion(t);if(!r)return null;if("4.2"===r&&!this.factories_.has("4.2"))return this.entityVersions_.set(e,"4.2"),"4.2";this.coreModule_.spine_setNeedsReload?.(i,e,!1);const a=await this.ensureBackend(r);if(!a)return console.error(`[SpineManager] Failed to create backend for version ${r}`),null;const l=t instanceof Uint8Array;return a.loadEntity(e,t,n,s,l)?(this.entityVersions_.set(e,r),r):(console.error(`[SpineManager] Failed to load entity ${e} into backend ${r}`),null)}updateAnimations(e){for(const t of this.backends_.values())t.updateAll(e)}submitMeshes(e){for(const t of this.backends_.values())t.extractAndSubmitMeshes(this.coreModule_,e)}removeEntity(e){const t=this.entityVersions_.get(e);if(!t)return void this.entityVersions_.delete(e);const n=this.backends_.get(t);n&&n.removeEntity(e),this.entityVersions_.delete(e)}getEntityVersion(e){return this.entityVersions_.get(e)}hasModuleBackend(e){return this.backends_.has(e)}getModuleBackend(e){return this.backends_.get(e)}setAnimation(e,t,n){const s=this.entityVersions_.get(e);if(!s)return;const i=this.backends_.get(s);i&&i.setAnimation(e,t,n)}setSkin(e,t){const n=this.entityVersions_.get(e);if(!n)return;const s=this.backends_.get(n);s&&s.setSkin(e,t)}setEntityProps(e,t){const n=this.entityVersions_.get(e);if(!n)return;const s=this.backends_.get(n);s&&s.setEntityProps(e,t)}getBounds(e){const t=this.entityVersions_.get(e);if(!t)return null;const n=this.backends_.get(t);return n?n.getBounds(e):null}getAnimations(e){const t=this.entityVersions_.get(e);if(!t)return[];const n=this.backends_.get(t);return n?n.getAnimations(e):[]}getSkins(e){const t=this.entityVersions_.get(e);if(!t)return[];const n=this.backends_.get(t);return n?n.getSkins(e):[]}hasInstance(e){return this.entityVersions_.has(e)}shutdown(){for(const e of this.backends_.values())e.shutdown();this.backends_.clear(),this.loadingBackends_.clear(),this.entityVersions_.clear()}async ensureBackend(e){const t=this.backends_.get(e);if(t)return t;const s=this.loadingBackends_.get(e);if(s)return s;const i=this.factories_.get(e);if(!i)return console.warn(`[SpineManager] No module factory for version ${e}`),null;const o=(async()=>{try{const t=await i(),s=n(t),o=new r(t,s),l=new a(o);return this.backends_.set(e,l),l}catch(t){return console.error(`[SpineManager] Failed to load WASM module for version ${e}:`,t),null}finally{this.loadingBackends_.delete(e)}})();return this.loadingBackends_.set(e,o),o}}function l(e,t){let n=0,s=0,i=0;do{const r=e[t+i++];if(n|=(127&r)<<s,s+=7,!(128&r))break}while(s<35);return{value:n,bytesRead:i}}let c=null;function u(e){c=e}function h(){c=null}const _={update(e,t){c?.spine_update?.(e._cpp,t)},play:(e,t,n=!0,s=0)=>c?.spine_play?.(e,t,n,s)??!1,addAnimation:(e,t,n=!0,s=0,i=0)=>c?.spine_addAnimation?.(e,t,n,s,i)??!1,setSkin:(e,t)=>c?.spine_setSkin?.(e,t)??!1,getBonePosition:(e,t)=>c?.spine_getBonePosition?.(e,t)??null,hasInstance:e=>c?.spine_hasInstance?.(e)??!1,reloadAssets(e){c?.spine_reloadAssets?.(e._cpp)},getAnimations:e=>c?.spine_getAnimations?.(e)??[],getSkins:e=>c?.spine_getSkins?.(e)??[]};class d{constructor(e){this.app_=null,e instanceof o?(this.spineManager_=e,this.provider_=null):(this.spineManager_=null,this.provider_=e??null)}get spineManager(){return this.spineManager_}setSpineManager(e){if(this.spineManager_=e,this.app_){const t=this.app_.pipeline;t?.addPreFlushCallback(t=>{e.submitMeshes(t._cpp)})}}build(n){this.app_=n;const i=n.wasmModule;if(u(i),!this.spineManager_&&this.provider_){const e=s(this.provider_);this.spineManager_=new o(i,e)}const r=this,a={_id:Symbol("SpineUpdateSystem"),_name:"SpineUpdateSystem",_params:[],_fn:()=>{const e=n.world.getCppRegistry();if(!e)return;const s=n.getResource(t);_.update({_cpp:e},s.delta),r.spineManager_?.updateAnimations(s.delta)}};if(n.addSystemToSchedule(e.PreUpdate,a),this.spineManager_){const e=this.spineManager_,t=n.pipeline;t?.addPreFlushCallback(t=>{e.submitMeshes(t._cpp)})}}}export{a as ModuleBackend,_ as SpineCpp,o as SpineManager,r as SpineModuleController,d as SpinePlugin,s as createSpineFactories,u as initSpineCppAPI,i as loadSpineModule,h as shutdownSpineCppAPI,n as wrapSpineModule};//# sourceMappingURL=index.js.mapdiff --git a/sdk/rollup.config.js b/sdk/rollup.config.jsindex e458cf5ea..c23919ec5 100644--- a/sdk/rollup.config.js+++ b/sdk/rollup.config.js@@ -23,26 +23,26 @@ const esmBuilds = [},plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }),- terser(),+ terser({ format: { comments: (_, comment) => comment.value.includes('@vite-ignore') } }),],treeshake,},{input: 'src/index.ts',output: { file: 'dist/index.bundled.js', format: 'esm', sourcemap: true },- plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser()],+ plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser({ format: { comments: (_, comment) => comment.value.includes('@vite-ignore') } })],treeshake,},{input: 'src/index.wechat.ts',output: { file: 'dist/index.wechat.js', format: 'esm', sourcemap: true },- plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser()],+ plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser({ format: { comments: (_, comment) => comment.value.includes('@vite-ignore') } })],treeshake,},{input: 'src/index.wechat.ts',output: { file: 'dist/index.wechat.cjs.js', format: 'cjs', sourcemap: true },- plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser()],+ plugins: [typescript({ tsconfig: './tsconfig.json', declaration: false }), terser({ format: { comments: (_, comment) => comment.value.includes('@vite-ignore') } })],treeshake,},];diff --git a/sdk/src/spine/SpineModuleLoader.ts b/sdk/src/spine/SpineModuleLoader.tsindex 0f00627e5..d116b08dd 100644--- a/sdk/src/spine/SpineModuleLoader.ts+++ b/sdk/src/spine/SpineModuleLoader.ts@@ -116,7 +116,7 @@ export function createSpineFactories(provider: SpineWasmProvider): Map<SpineVers]);const blob = new Blob([`${jsSource};\nself.__ESSpineModule__ = ESSpineModule;`], { type: 'application/javascript' });const url = URL.createObjectURL(blob);- await import(/* webpackIgnore: true */ url);+ await import(/* @vite-ignore */ /* webpackIgnore: true */ url);URL.revokeObjectURL(url);const moduleFactory = (globalThis as any).__ESSpineModule__ as(opts: Record<string, unknown>) => Promise<SpineWasmModule>;