@haiyue/extensions 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/animation/Animation2DComponent.d.ts +46 -0
  4. package/dist/animation/Animation2DExtensionRegistry.d.ts +27 -0
  5. package/dist/animation/Animation2DRenderSystem.d.ts +89 -0
  6. package/dist/animation/Animation2DRuntime.d.ts +99 -0
  7. package/dist/animation/Animation2DStateMachine.d.ts +13 -0
  8. package/dist/animation/Animation2DStateMachineComponent.d.ts +54 -0
  9. package/dist/animation/Animation2DStateMachineRuntime.d.ts +30 -0
  10. package/dist/animation/Animation2DStateMachineSystem.d.ts +14 -0
  11. package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +27 -0
  12. package/dist/animation/Animation2DSystem.d.ts +14 -0
  13. package/dist/animation/AnimationAssetLoader.d.ts +9 -0
  14. package/dist/animation/AnimationAudioClip.d.ts +26 -0
  15. package/dist/animation/AnimationPathTessellator.d.ts +52 -0
  16. package/dist/animation/AnimationTextRasterizer.d.ts +21 -0
  17. package/dist/animation/AnimationVisual2D.d.ts +68 -0
  18. package/dist/animation/HyaAnimation2DClipAdapter.d.ts +16 -0
  19. package/dist/animation/Particle2DDescriptorAdapter.d.ts +5 -0
  20. package/dist/animation/runtime/mixer/Action.d.ts +150 -0
  21. package/dist/animation/runtime/mixer/Mixer.d.ts +54 -0
  22. package/dist/animation/runtime/mixer/PoseBuffer.d.ts +23 -0
  23. package/dist/animation/runtime/mixer/Sampler.d.ts +17 -0
  24. package/dist/animation/runtime/mixer/Types.d.ts +101 -0
  25. package/dist/animation/runtime/mixer/index.d.ts +6 -0
  26. package/dist/animation-state-machine/AnimationStateMachine.d.ts +111 -0
  27. package/dist/animation-state-machine/AnimationStateMachineChannels.d.ts +23 -0
  28. package/dist/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.d.ts +51 -0
  29. package/dist/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.d.ts +14 -0
  30. package/dist/animation-state-machine/runtime/AnimationStateMachineCompiler.d.ts +109 -0
  31. package/dist/animation-state-machine/runtime/AnimationStateMachineController.d.ts +103 -0
  32. package/dist/animation-state-machine/runtime/AnimationStateMachineMixerPort.d.ts +35 -0
  33. package/dist/animation-state-machine/runtime/index.d.ts +7 -0
  34. package/dist/animation.d.ts +15 -0
  35. package/dist/animation.js +1171 -0
  36. package/dist/animation3d/Animation3DAction.d.ts +46 -0
  37. package/dist/animation3d/Animation3DBinding.d.ts +85 -0
  38. package/dist/animation3d/Animation3DClip.d.ts +20 -0
  39. package/dist/animation3d/Animation3DError.d.ts +13 -0
  40. package/dist/animation3d/Animation3DMixer.d.ts +27 -0
  41. package/dist/animation3d/Animation3DPose.d.ts +40 -0
  42. package/dist/animation3d/Animation3DPoseBuffer.d.ts +24 -0
  43. package/dist/animation3d/Animation3DResource.d.ts +28 -0
  44. package/dist/animation3d/Animation3DStateMachine.d.ts +95 -0
  45. package/dist/animation3d/Animation3DStateMachineRuntime.d.ts +70 -0
  46. package/dist/animation3d/Animation3DTrack.d.ts +19 -0
  47. package/dist/animation3d/hya/HyaAnimation3DRuntime.d.ts +73 -0
  48. package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +65 -0
  49. package/dist/animation3d/hya/HyaAnimation3DTypes.d.ts +170 -0
  50. package/dist/animation3d/hya/index.d.ts +4 -0
  51. package/dist/animation3d/index.d.ts +14 -0
  52. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +81 -0
  53. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +39 -0
  54. package/dist/animation3d/runtime/integration/index.d.ts +2 -0
  55. package/dist/animation3d/runtime/mixer/Action.d.ts +150 -0
  56. package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +6 -0
  57. package/dist/animation3d/runtime/mixer/Mixer.d.ts +59 -0
  58. package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +1 -0
  59. package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +24 -0
  60. package/dist/animation3d/runtime/mixer/index.d.ts +4 -0
  61. package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +1 -0
  62. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +1 -0
  63. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +1 -0
  64. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +1 -0
  65. package/dist/animation3d/runtime/state-machine/index.d.ts +6 -0
  66. package/dist/animation3d.d.ts +5 -0
  67. package/dist/animation3d.js +1708 -0
  68. package/dist/benchmark.d.ts +30 -0
  69. package/dist/benchmark.js +119 -0
  70. package/dist/canvas-text/CanvasText2DRenderSystem.d.ts +24 -0
  71. package/dist/canvas-text/CanvasTextComponent.d.ts +18 -0
  72. package/dist/canvas-text.d.ts +4 -0
  73. package/dist/canvas-text.js +276 -0
  74. package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +4 -0
  75. package/dist/chunks/2d-ui-canvas-text-2d.generated-C0Eaej2m.js +4 -0
  76. package/dist/chunks/2d-ui-spine2d.generated-CUUi8xjl.js +4 -0
  77. package/dist/chunks/2d-ui-tilemap2d.generated-gebw4mX7.js +4 -0
  78. package/dist/chunks/Animation2DStateMachine-9IonguNa.js +3245 -0
  79. package/dist/chunks/AnimationStateMachineController-BIcAh-sT.js +1438 -0
  80. package/dist/chunks/GltfAnimation3DAdapter-Cu3rQQsW.js +2240 -0
  81. package/dist/chunks/GltfAnimationRuntime-CRHsLycN.js +631 -0
  82. package/dist/chunks/RenderSystem2DBase-DDT61dAu.js +227 -0
  83. package/dist/chunks/Spine2DRuntime-D9M9LAQR.js +3056 -0
  84. package/dist/chunks/SpineAssetParser-BSDmPge1.js +378 -0
  85. package/dist/chunks/gltfLoader-Dm22jLYB.js +2085 -0
  86. package/dist/chunks/pluginUtils-CvwroRMd.js +33 -0
  87. package/dist/experimental-gltf-worker.d.ts +4 -0
  88. package/dist/experimental-gltf-worker.js +138 -0
  89. package/dist/experimental-spine-worker.d.ts +4 -0
  90. package/dist/experimental-spine-worker.js +110 -0
  91. package/dist/gltf/GltfAccessorReader.d.ts +7 -0
  92. package/dist/gltf/GltfAnimation3DAdapter.d.ts +47 -0
  93. package/dist/gltf/GltfAnimationRuntime.d.ts +10 -0
  94. package/dist/gltf/GltfAssetWorkerClient.d.ts +20 -0
  95. package/dist/gltf/GltfCompatibilityReport.d.ts +70 -0
  96. package/dist/gltf/GltfConservativeBounds.d.ts +18 -0
  97. package/dist/gltf/GltfDracoDecoder.d.ts +4 -0
  98. package/dist/gltf/GltfExtensionAdapter.d.ts +54 -0
  99. package/dist/gltf/GltfLoaderContract.d.ts +249 -0
  100. package/dist/gltf/GltfLoaderErrors.d.ts +4 -0
  101. package/dist/gltf/GltfMaterialDescriptor.d.ts +23 -0
  102. package/dist/gltf/GltfMaterialEncoder.d.ts +20 -0
  103. package/dist/gltf/GltfMaterialLoader.d.ts +6 -0
  104. package/dist/gltf/GltfModelComponent.d.ts +72 -0
  105. package/dist/gltf/GltfModelSystem.d.ts +37 -0
  106. package/dist/gltf/GltfPlugin.d.ts +6 -0
  107. package/dist/gltf/GltfSchema.d.ts +225 -0
  108. package/dist/gltf/GltfUvSemanticPlanner.d.ts +33 -0
  109. package/dist/gltf/gltfLoader.d.ts +9 -0
  110. package/dist/gltf-animation3d.d.ts +3 -0
  111. package/dist/gltf-animation3d.js +8 -0
  112. package/dist/gltf-worker-runtime.d.ts +7 -0
  113. package/dist/gltf-worker-runtime.js +6981 -0
  114. package/dist/gltf.d.ts +12 -0
  115. package/dist/gltf.js +517 -0
  116. package/dist/grid/Grid2DComponent.d.ts +25 -0
  117. package/dist/grid.d.ts +2 -0
  118. package/dist/grid.js +56 -0
  119. package/dist/hya-state-machine.d.ts +7 -0
  120. package/dist/hya-state-machine.js +2934 -0
  121. package/dist/index.d.ts +2 -0
  122. package/dist/index.js +7 -0
  123. package/dist/internal/2d-ui-shader-artifact.js +870 -0
  124. package/dist/plugins/pluginUtils.d.ts +20 -0
  125. package/dist/plugins.d.ts +6 -0
  126. package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +658 -0
  127. package/dist/spine/Spine2DComponent.d.ts +116 -0
  128. package/dist/spine/Spine2DGpuRenderer.d.ts +65 -0
  129. package/dist/spine/Spine2DRenderSystem.d.ts +27 -0
  130. package/dist/spine/Spine2DRuntime.d.ts +103 -0
  131. package/dist/spine/SpineAnimationBoneTimelines.d.ts +8 -0
  132. package/dist/spine/SpineAssetParser.d.ts +18 -0
  133. package/dist/spine/SpineAssetWorkerClient.d.ts +19 -0
  134. package/dist/spine/SpineAssetWorkerContract.d.ts +6 -0
  135. package/dist/spine/SpineAtlasParser.d.ts +21 -0
  136. package/dist/spine/SpineFloatBuilder.d.ts +15 -0
  137. package/dist/spine/SpinePathConstraintSolver.d.ts +32 -0
  138. package/dist/spine/SpinePlugin.d.ts +8 -0
  139. package/dist/spine/SpineSkeletonRuntime.d.ts +185 -0
  140. package/dist/spine/SpineSlotAnimation.d.ts +17 -0
  141. package/dist/spine/SpineTimelineRuntime.d.ts +25 -0
  142. package/dist/spine/SpineVertexBuilder.d.ts +61 -0
  143. package/dist/spine.d.ts +7 -0
  144. package/dist/spine.js +578 -0
  145. package/dist/tilemap/Tilemap2DComponent.d.ts +110 -0
  146. package/dist/tilemap/Tilemap2DRenderSystem.d.ts +11 -0
  147. package/dist/tilemap/Tilemap2DRenderer.d.ts +24 -0
  148. package/dist/tilemap/TilemapPlugin.d.ts +8 -0
  149. package/dist/tilemap.d.ts +6 -0
  150. package/dist/tilemap.js +535 -0
  151. package/dist/tween/Tween2DComponent.d.ts +70 -0
  152. package/dist/tween/Tween2DSystem.d.ts +12 -0
  153. package/dist/tween.d.ts +4 -0
  154. package/dist/tween.js +138 -0
  155. package/dist/utils/RenderSystem2DBase.d.ts +42 -0
  156. package/dist/utils/arrayAccess.d.ts +4 -0
  157. package/dist/utils/camera2d.d.ts +12 -0
  158. package/dist/utils/render2dGpu.d.ts +32 -0
  159. package/package.json +124 -0
  160. package/src/animation/Animation2DComponent.ts +135 -0
  161. package/src/animation/Animation2DExtensionRegistry.ts +52 -0
  162. package/src/animation/Animation2DRenderSystem.ts +1026 -0
  163. package/src/animation/Animation2DRuntime.ts +1326 -0
  164. package/src/animation/Animation2DStateMachine.ts +39 -0
  165. package/src/animation/Animation2DStateMachineComponent.ts +228 -0
  166. package/src/animation/Animation2DStateMachineRuntime.ts +141 -0
  167. package/src/animation/Animation2DStateMachineSystem.ts +60 -0
  168. package/src/animation/Animation2DStateMachineVisualRuntime.ts +282 -0
  169. package/src/animation/Animation2DSystem.ts +72 -0
  170. package/src/animation/AnimationAssetLoader.ts +84 -0
  171. package/src/animation/AnimationAudioClip.ts +140 -0
  172. package/src/animation/AnimationPathTessellator.ts +691 -0
  173. package/src/animation/AnimationTextRasterizer.ts +340 -0
  174. package/src/animation/AnimationVisual2D.ts +153 -0
  175. package/src/animation/HyaAnimation2DClipAdapter.ts +845 -0
  176. package/src/animation/Particle2DDescriptorAdapter.ts +35 -0
  177. package/src/animation/runtime/mixer/Action.ts +876 -0
  178. package/src/animation/runtime/mixer/Mixer.ts +505 -0
  179. package/src/animation/runtime/mixer/PoseBuffer.ts +105 -0
  180. package/src/animation/runtime/mixer/Sampler.ts +252 -0
  181. package/src/animation/runtime/mixer/Types.ts +138 -0
  182. package/src/animation/runtime/mixer/index.ts +31 -0
  183. package/src/animation-state-machine/AnimationStateMachine.ts +146 -0
  184. package/src/animation-state-machine/AnimationStateMachineChannels.ts +116 -0
  185. package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +197 -0
  186. package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +503 -0
  187. package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +763 -0
  188. package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +987 -0
  189. package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +54 -0
  190. package/src/animation-state-machine/runtime/index.ts +47 -0
  191. package/src/animation.ts +33 -0
  192. package/src/animation3d/Animation3DAction.ts +73 -0
  193. package/src/animation3d/Animation3DBinding.ts +116 -0
  194. package/src/animation3d/Animation3DClip.ts +22 -0
  195. package/src/animation3d/Animation3DError.ts +34 -0
  196. package/src/animation3d/Animation3DMixer.ts +82 -0
  197. package/src/animation3d/Animation3DPose.ts +100 -0
  198. package/src/animation3d/Animation3DPoseBuffer.ts +85 -0
  199. package/src/animation3d/Animation3DResource.ts +49 -0
  200. package/src/animation3d/Animation3DStateMachine.ts +126 -0
  201. package/src/animation3d/Animation3DStateMachineRuntime.ts +191 -0
  202. package/src/animation3d/Animation3DTrack.ts +29 -0
  203. package/src/animation3d/hya/HyaAnimation3DRuntime.ts +756 -0
  204. package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +618 -0
  205. package/src/animation3d/hya/HyaAnimation3DTypes.ts +168 -0
  206. package/src/animation3d/hya/index.ts +10 -0
  207. package/src/animation3d/index.ts +76 -0
  208. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +325 -0
  209. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +158 -0
  210. package/src/animation3d/runtime/integration/index.ts +9 -0
  211. package/src/animation3d/runtime/mixer/Action.ts +833 -0
  212. package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +26 -0
  213. package/src/animation3d/runtime/mixer/Mixer.ts +562 -0
  214. package/src/animation3d/runtime/mixer/PoseBuffer.ts +1 -0
  215. package/src/animation3d/runtime/mixer/TrackSampler.ts +399 -0
  216. package/src/animation3d/runtime/mixer/index.ts +8 -0
  217. package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +4 -0
  218. package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +1 -0
  219. package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +1 -0
  220. package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +1 -0
  221. package/src/animation3d/runtime/state-machine/index.ts +45 -0
  222. package/src/animation3d.ts +5 -0
  223. package/src/benchmark.ts +168 -0
  224. package/src/canvas-text/CanvasText2DRenderSystem.ts +292 -0
  225. package/src/canvas-text/CanvasTextComponent.ts +47 -0
  226. package/src/canvas-text.ts +4 -0
  227. package/src/experimental-gltf-worker.ts +18 -0
  228. package/src/experimental-spine-worker.ts +9 -0
  229. package/src/gltf/GltfAccessorReader.ts +271 -0
  230. package/src/gltf/GltfAnimation3DAdapter.ts +680 -0
  231. package/src/gltf/GltfAnimationRuntime.ts +392 -0
  232. package/src/gltf/GltfAssetWorkerClient.ts +136 -0
  233. package/src/gltf/GltfCompatibilityReport.ts +214 -0
  234. package/src/gltf/GltfConservativeBounds.ts +219 -0
  235. package/src/gltf/GltfDracoDecoder.ts +251 -0
  236. package/src/gltf/GltfExtensionAdapter.ts +340 -0
  237. package/src/gltf/GltfLoaderContract.ts +333 -0
  238. package/src/gltf/GltfLoaderErrors.ts +59 -0
  239. package/src/gltf/GltfMaterialDescriptor.ts +134 -0
  240. package/src/gltf/GltfMaterialEncoder.ts +173 -0
  241. package/src/gltf/GltfMaterialLoader.ts +293 -0
  242. package/src/gltf/GltfModelComponent.ts +115 -0
  243. package/src/gltf/GltfModelSystem.ts +208 -0
  244. package/src/gltf/GltfPlugin.ts +84 -0
  245. package/src/gltf/GltfSchema.ts +229 -0
  246. package/src/gltf/GltfUvSemanticPlanner.ts +166 -0
  247. package/src/gltf/gltfLoader.ts +910 -0
  248. package/src/gltf-animation3d.ts +10 -0
  249. package/src/gltf-worker-runtime.ts +10 -0
  250. package/src/gltf.ts +56 -0
  251. package/src/grid/Grid2DComponent.ts +69 -0
  252. package/src/grid.ts +2 -0
  253. package/src/hya-state-machine.ts +19 -0
  254. package/src/index.ts +2 -0
  255. package/src/plugins/pluginUtils.ts +50 -0
  256. package/src/plugins.ts +6 -0
  257. package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +242 -0
  258. package/src/shaders/generated/2d-ui-artifact.generated.ts +867 -0
  259. package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +38 -0
  260. package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +41 -0
  261. package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +36 -0
  262. package/src/spine/Spine2DComponent.ts +168 -0
  263. package/src/spine/Spine2DGpuRenderer.ts +449 -0
  264. package/src/spine/Spine2DRenderSystem.ts +199 -0
  265. package/src/spine/Spine2DRuntime.ts +1529 -0
  266. package/src/spine/SpineAnimationBoneTimelines.ts +30 -0
  267. package/src/spine/SpineAssetParser.ts +20 -0
  268. package/src/spine/SpineAssetWorkerClient.ts +112 -0
  269. package/src/spine/SpineAssetWorkerContract.ts +4 -0
  270. package/src/spine/SpineAtlasParser.ts +127 -0
  271. package/src/spine/SpineFloatBuilder.ts +66 -0
  272. package/src/spine/SpinePathConstraintSolver.ts +582 -0
  273. package/src/spine/SpinePlugin.ts +76 -0
  274. package/src/spine/SpineSkeletonRuntime.ts +521 -0
  275. package/src/spine/SpineSlotAnimation.ts +195 -0
  276. package/src/spine/SpineTimelineRuntime.ts +453 -0
  277. package/src/spine/SpineVertexBuilder.ts +686 -0
  278. package/src/spine.ts +7 -0
  279. package/src/tilemap/Tilemap2DComponent.ts +232 -0
  280. package/src/tilemap/Tilemap2DRenderSystem.ts +58 -0
  281. package/src/tilemap/Tilemap2DRenderer.ts +289 -0
  282. package/src/tilemap/TilemapPlugin.ts +75 -0
  283. package/src/tilemap.ts +6 -0
  284. package/src/tween/Tween2DComponent.ts +83 -0
  285. package/src/tween/Tween2DSystem.ts +78 -0
  286. package/src/tween.ts +4 -0
  287. package/src/types/earcut.d.ts +7 -0
  288. package/src/types/wgsl.d.ts +4 -0
  289. package/src/utils/RenderSystem2DBase.ts +164 -0
  290. package/src/utils/arrayAccess.ts +17 -0
  291. package/src/utils/camera2d.ts +68 -0
  292. package/src/utils/render2dGpu.ts +132 -0
  293. package/test/fixtures/gltf/animation-characterization.gltf +344 -0
@@ -0,0 +1,61 @@
1
+ import { Spine2DComponent } from './Spine2DComponent';
2
+ import { SpineFloatBuilder } from './SpineFloatBuilder';
3
+ import type { AtlasRegion } from './SpineAtlasParser';
4
+ import type { BonePose, RegionAttachment, SlotData, SpineData } from './SpineSkeletonRuntime';
5
+ export interface SpineDrawBatch {
6
+ blend: 'normal' | 'additive';
7
+ page: string;
8
+ firstVertex: number;
9
+ vertexCount: number;
10
+ }
11
+ export interface SpineSlotGeometryCache {
12
+ key: string;
13
+ signature: number;
14
+ debugSignature: number;
15
+ vertices: Float32Array;
16
+ vertexLength: number;
17
+ vertexCapacity: number;
18
+ debugVertices: Float32Array;
19
+ debugVertexLength: number;
20
+ debugVertexCapacity: number;
21
+ batch: Omit<SpineDrawBatch, 'firstVertex'>;
22
+ vertexOffset: number;
23
+ debugVertexOffset: number;
24
+ }
25
+ export interface SpineVertexRuntime {
26
+ data: SpineData;
27
+ pages: Map<string, {
28
+ width: number;
29
+ height: number;
30
+ }>;
31
+ vertexBuilder: SpineFloatBuilder;
32
+ debugVertexBuilder: SpineFloatBuilder;
33
+ meshPointBuilder: SpineFloatBuilder;
34
+ batches: SpineDrawBatch[];
35
+ batchPool: SpineDrawBatch[];
36
+ allocationStats?: {
37
+ batchPoolMisses: number;
38
+ };
39
+ vertexColorScratch: [number, number, number, number];
40
+ }
41
+ export declare const HASH_OFFSET = 2166136261;
42
+ export declare function createEmptySlotCache(key: string): SpineSlotGeometryCache;
43
+ export declare function copyBuilderData(builder: SpineFloatBuilder, target: Float32Array): Float32Array;
44
+ export declare function hasInvalidOffsets(entries: SpineSlotGeometryCache[]): boolean;
45
+ export declare function rebuildCachedGeometryLayout(runtime: SpineVertexRuntime, entries: SpineSlotGeometryCache[]): void;
46
+ export declare function rebuildCachedDrawBatches(runtime: SpineVertexRuntime, entries: SpineSlotGeometryCache[]): void;
47
+ export declare function getSlotOrderHash(entries: SpineSlotGeometryCache[]): number;
48
+ export declare function getSlotBuildSignature(slot: SlotData, attachmentName: string, attachment: RegionAttachment, regionName: string, region: AtlasRegion, bone: BonePose, poses: Map<string, BonePose>, slotColor: [number, number, number, number] | undefined, clip: {
49
+ endSlot?: string;
50
+ polygon: Array<[number, number]>;
51
+ } | null, component: Spine2DComponent): number;
52
+ export declare function getDebugBonesSignature(scale: number, poses: Map<string, BonePose>): number;
53
+ export declare function hashInt(hash: number, value: number): number;
54
+ export declare function normalizeBlend(blend: string): 'normal' | 'additive';
55
+ export declare function computeClipPolygon(bone: BonePose, attachment: RegionAttachment, scale: number): Array<[number, number]>;
56
+ export declare function replaceClippedRange(floats: SpineFloatBuilder, start: number, polygon: Array<[number, number]>, clipped: SpineFloatBuilder): void;
57
+ export declare function appendRegionVertices(out: SpineFloatBuilder, component: Spine2DComponent, runtime: SpineVertexRuntime, bone: BonePose, slotColor: [number, number, number, number] | undefined, attachment: RegionAttachment, region: AtlasRegion): void;
58
+ export declare function appendMeshVertices(out: SpineFloatBuilder, component: Spine2DComponent, runtime: SpineVertexRuntime, data: SpineData, poses: Map<string, BonePose>, bone: BonePose, slotColor: [number, number, number, number] | undefined, attachment: RegionAttachment, region: AtlasRegion): void;
59
+ export declare function appendMeshWireframe(out: SpineFloatBuilder, component: Spine2DComponent, runtime: SpineVertexRuntime, data: SpineData, poses: Map<string, BonePose>, bone: BonePose, attachment: RegionAttachment): void;
60
+ export declare function appendRegionWireframe(out: SpineFloatBuilder, component: Spine2DComponent, bone: BonePose, attachment: RegionAttachment, region: AtlasRegion): void;
61
+ export declare function appendBoneDebug(out: SpineFloatBuilder, data: SpineData, poses: Map<string, BonePose>, scale: number): void;
@@ -0,0 +1,7 @@
1
+ export { Spine2DComponent } from './spine/Spine2DComponent';
2
+ export type { Spine2DComponentOptions, Spine2DStatus } from './spine/Spine2DComponent';
3
+ export { Spine2DRenderSystem } from './spine/Spine2DRenderSystem';
4
+ export type { Spine2DRenderSystemOptions } from './spine/Spine2DRenderSystem';
5
+ export type { SpineAssetWorker } from './spine/SpineAssetWorkerContract';
6
+ export { createSpinePlugin } from './spine/SpinePlugin';
7
+ export type { SpinePluginOptions } from './spine/SpinePlugin';
package/dist/spine.js ADDED
@@ -0,0 +1,578 @@
1
+ import { S as Spine2DComponent, d as advanceSpineRuntime, g as buildSpineVertices, l as loadSpineRuntime } from './chunks/Spine2DRuntime-D9M9LAQR.js';
2
+ import { requireEngineDevice, getExtensionGPUResourceTracker, alignUp4, beginRenderCommandPass } from '@haiyue/engine/extension-authoring';
3
+ import { EngineError, EngineErrorCode } from '@haiyue/engine';
4
+ import { ErrorRecovery, ErrorDomain } from '@haiyue/engine/core';
5
+ import { r as resolveAtlasPageImageUrl } from './chunks/SpineAssetParser-BSDmPge1.js';
6
+ import { c as createCamera2DGpu, b as createObject2DLayout, e as createTexture2DGpu, d as destroyCamera2DGpu, a as destroyTexture2DGpu, R as RenderSystem2DBase, w as writeObjectMatrixIfChanged } from './chunks/RenderSystem2DBase-DDT61dAu.js';
7
+ import { s as spine2dWgsl } from './chunks/2d-ui-spine2d.generated-CUUi8xjl.js';
8
+ import { E as EXTENSIONS_PLUGIN_VERSION, i as installEditorRenderSystem, r as removeSystem } from './chunks/pluginUtils-CvwroRMd.js';
9
+ import '@haiyue/engine/ecs';
10
+ import '@haiyue/engine/experimental/async';
11
+ import '@haiyue/engine/components';
12
+ import 'wgpu-matrix';
13
+
14
+ const SPINE_WGSL = spine2dWgsl;
15
+ class Spine2DGpuRenderer {
16
+ engine = null;
17
+ cameraGpu = null;
18
+ textureGpu = null;
19
+ objectLayoutGpu = null;
20
+ shaderModule = null;
21
+ pipelineLayout = null;
22
+ pipelines = new Map();
23
+ reverseZ = false;
24
+ sampleCount = 1;
25
+ pendingBufferDestroys = new Set();
26
+ get cameraBuffer() {
27
+ return this.requirePrepared().cameraGpu.buffer;
28
+ }
29
+ get objectLayout() {
30
+ return this.requirePrepared().objectLayout;
31
+ }
32
+ prepare(engine) {
33
+ if (this.engine === engine && this.cameraGpu && this.textureGpu && this.objectLayoutGpu)
34
+ return;
35
+ if (this.engine && this.engine !== engine)
36
+ this.destroy();
37
+ this.engine = engine;
38
+ const device = requireEngineDevice(engine);
39
+ this.cameraGpu = createCamera2DGpu(device, getExtensionGPUResourceTracker(engine));
40
+ this.objectLayoutGpu = createObject2DLayout(device);
41
+ this.textureGpu = createTexture2DGpu(device, 255, getExtensionGPUResourceTracker(engine));
42
+ this.shaderModule = device.createShaderModule({ code: SPINE_WGSL });
43
+ this.pipelineLayout = device.createPipelineLayout({
44
+ bindGroupLayouts: [this.cameraGpu.layout, this.objectLayoutGpu, this.textureGpu.layout],
45
+ });
46
+ }
47
+ destroy() {
48
+ if (this.cameraGpu)
49
+ destroyCamera2DGpu(this.cameraGpu);
50
+ if (this.textureGpu)
51
+ destroyTexture2DGpu(this.textureGpu);
52
+ this.flushPendingBufferDestroys();
53
+ this.cameraGpu = null;
54
+ this.textureGpu = null;
55
+ this.objectLayoutGpu = null;
56
+ this.shaderModule = null;
57
+ this.pipelineLayout = null;
58
+ this.pipelines.clear();
59
+ }
60
+ setRenderView(reverseZ, sampleCount) {
61
+ this.reverseZ = reverseZ;
62
+ this.sampleCount = sampleCount;
63
+ }
64
+ createRuntimeBuffers() {
65
+ const engine = this.requireEngine();
66
+ const vertexBufferSize = 1024;
67
+ const debugVertexBufferSize = 1024;
68
+ const vertexBuffer = engine.device.createBuffer({
69
+ size: vertexBufferSize,
70
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
71
+ });
72
+ const debugVertexBuffer = engine.device.createBuffer({
73
+ size: debugVertexBufferSize,
74
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
75
+ });
76
+ getExtensionGPUResourceTracker(engine)?.trackBuffer(vertexBuffer, 'Spine2D.vertexBuffer', vertexBufferSize);
77
+ getExtensionGPUResourceTracker(engine)?.trackBuffer(debugVertexBuffer, 'Spine2D.debugVertexBuffer', debugVertexBufferSize);
78
+ return { vertexBuffer, vertexBufferSize, debugVertexBuffer, debugVertexBufferSize };
79
+ }
80
+ async loadAtlasPages(component, atlas) {
81
+ const engine = this.requireEngine();
82
+ const textureGpu = this.requirePrepared().textureGpu;
83
+ const pageNames = Array.from(new Set(Array.from(atlas.values()).map(region => region.page).filter(Boolean)));
84
+ const pages = new Map();
85
+ const names = pageNames.length ? pageNames : [''];
86
+ for (const pageName of names) {
87
+ const imageUrl = resolveAtlasPageImageUrl({
88
+ atlasUrl: component.atlasUrl,
89
+ imageUrl: component.imageUrl,
90
+ imageUrls: component.imageUrls,
91
+ }, atlas, pageName);
92
+ const image = await loadImage(imageUrl);
93
+ const width = Math.max(1, image.naturalWidth || image.width);
94
+ const height = Math.max(1, image.naturalHeight || image.height);
95
+ const texture = engine.device.createTexture({
96
+ size: [width, height],
97
+ format: 'rgba8unorm',
98
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
99
+ });
100
+ getExtensionGPUResourceTracker(engine)?.trackTexture(texture, 'Spine2D.atlasTexture', width * height * 4);
101
+ engine.device.queue.copyExternalImageToTexture({ source: image }, { texture }, [width, height]);
102
+ const textureBindGroup = engine.device.createBindGroup({
103
+ layout: textureGpu.layout,
104
+ entries: [
105
+ { binding: 0, resource: texture.createView() },
106
+ { binding: 1, resource: textureGpu.sampler },
107
+ ],
108
+ });
109
+ pages.set(pageName, { image, texture, textureBindGroup, width, height });
110
+ }
111
+ return pages;
112
+ }
113
+ writeVertices(runtime, vertices, dirtyRanges) {
114
+ const engine = this.requireEngine();
115
+ if (vertices.byteLength > runtime.vertexBufferSize) {
116
+ const nextSize = nextGpuBufferSize(vertices.byteLength, runtime.vertexBufferSize);
117
+ const nextBuffer = engine.device.createBuffer({
118
+ size: nextSize,
119
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
120
+ });
121
+ this.deferBufferDestroy(runtime.vertexBuffer);
122
+ runtime.vertexBuffer = nextBuffer;
123
+ runtime.vertexBufferSize = nextSize;
124
+ getExtensionGPUResourceTracker(engine)?.trackBuffer(runtime.vertexBuffer, 'Spine2D.vertexBuffer', nextSize);
125
+ engine.device.queue.writeBuffer(runtime.vertexBuffer, 0, vertices.data.buffer, 0, vertices.byteLength);
126
+ return;
127
+ }
128
+ this.writeDirtyRanges(runtime, runtime.vertexBuffer, vertices, dirtyRanges, runtime.mergedDirtyRanges);
129
+ }
130
+ writeDebugVertices(runtime, vertices, dirtyRanges) {
131
+ const engine = this.requireEngine();
132
+ if (vertices.byteLength > runtime.debugVertexBufferSize) {
133
+ const nextSize = nextGpuBufferSize(vertices.byteLength, runtime.debugVertexBufferSize);
134
+ const nextBuffer = engine.device.createBuffer({
135
+ size: nextSize,
136
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
137
+ });
138
+ this.deferBufferDestroy(runtime.debugVertexBuffer);
139
+ runtime.debugVertexBuffer = nextBuffer;
140
+ runtime.debugVertexBufferSize = nextSize;
141
+ getExtensionGPUResourceTracker(engine)?.trackBuffer(runtime.debugVertexBuffer, 'Spine2D.debugVertexBuffer', nextSize);
142
+ engine.device.queue.writeBuffer(runtime.debugVertexBuffer, 0, vertices.data.buffer, 0, vertices.byteLength);
143
+ return;
144
+ }
145
+ this.writeDirtyRanges(runtime, runtime.debugVertexBuffer, vertices, dirtyRanges, runtime.mergedDirtyRanges);
146
+ }
147
+ drawRuntime(pass, runtime, objectBindGroup, debugVertexCount) {
148
+ const { cameraGpu, textureGpu } = this.requirePrepared();
149
+ pass.setPipeline(this.getPipeline('normal'));
150
+ pass.setBindGroup(0, cameraGpu.bindGroup);
151
+ pass.setBindGroup(1, objectBindGroup);
152
+ pass.setVertexBuffer(0, runtime.vertexBuffer);
153
+ let currentBlend = 'normal';
154
+ let currentPage = '';
155
+ for (const batch of runtime.batches) {
156
+ if (batch.blend !== currentBlend) {
157
+ currentBlend = batch.blend;
158
+ pass.setPipeline(this.getPipeline(currentBlend));
159
+ pass.setBindGroup(0, cameraGpu.bindGroup);
160
+ pass.setBindGroup(1, objectBindGroup);
161
+ pass.setVertexBuffer(0, runtime.vertexBuffer);
162
+ }
163
+ if (batch.page !== currentPage) {
164
+ currentPage = batch.page;
165
+ pass.setBindGroup(2, runtime.pages.get(batch.page)?.textureBindGroup ?? textureGpu.fallbackBindGroup);
166
+ }
167
+ pass.draw(batch.vertexCount, 1, batch.firstVertex);
168
+ }
169
+ if (debugVertexCount > 0) {
170
+ pass.setPipeline(this.getPipeline('line'));
171
+ pass.setBindGroup(0, cameraGpu.bindGroup);
172
+ pass.setBindGroup(1, objectBindGroup);
173
+ pass.setBindGroup(2, textureGpu.fallbackBindGroup);
174
+ pass.setVertexBuffer(0, runtime.debugVertexBuffer);
175
+ pass.draw(debugVertexCount);
176
+ }
177
+ }
178
+ destroyRuntime(runtime) {
179
+ const engine = this.requireEngine();
180
+ getExtensionGPUResourceTracker(engine)?.untrackBuffer(runtime.vertexBuffer);
181
+ getExtensionGPUResourceTracker(engine)?.untrackBuffer(runtime.debugVertexBuffer);
182
+ runtime.vertexBuffer.destroy();
183
+ runtime.debugVertexBuffer.destroy();
184
+ for (const page of runtime.pages.values())
185
+ this.destroyAtlasPage(page);
186
+ runtime.pages.clear();
187
+ runtime.batches.length = 0;
188
+ }
189
+ destroyAtlasPage(page) {
190
+ const engine = this.requireEngine();
191
+ getExtensionGPUResourceTracker(engine)?.untrackTexture(page.texture);
192
+ page.texture.destroy();
193
+ }
194
+ getPipeline(blend) {
195
+ const key = `${blend}:${this.reverseZ ? 1 : 0}:${this.sampleCount}`;
196
+ const cached = this.pipelines.get(key);
197
+ if (cached)
198
+ return cached;
199
+ const engine = this.requireEngine();
200
+ const prepared = this.requirePrepared();
201
+ const pipeline = engine.device.createRenderPipeline({
202
+ layout: prepared.pipelineLayout,
203
+ vertex: {
204
+ module: prepared.shaderModule,
205
+ entryPoint: 'vs_main',
206
+ buffers: [{
207
+ arrayStride: 32,
208
+ attributes: [
209
+ { shaderLocation: 0, offset: 0, format: 'float32x2' },
210
+ { shaderLocation: 1, offset: 8, format: 'float32x2' },
211
+ { shaderLocation: 2, offset: 16, format: 'float32x4' },
212
+ ],
213
+ }],
214
+ },
215
+ fragment: {
216
+ module: prepared.shaderModule,
217
+ entryPoint: 'fs_main',
218
+ targets: [{
219
+ format: engine.format,
220
+ blend: {
221
+ color: blend === 'additive'
222
+ ? { srcFactor: 'src-alpha', dstFactor: 'one', operation: 'add' }
223
+ : { srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha', operation: 'add' },
224
+ alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
225
+ },
226
+ }],
227
+ },
228
+ primitive: { topology: blend === 'line' ? 'line-list' : 'triangle-list' },
229
+ depthStencil: {
230
+ format: engine.getDepthFormat(this.reverseZ),
231
+ depthWriteEnabled: false,
232
+ depthCompare: this.reverseZ ? 'greater-equal' : 'less-equal',
233
+ },
234
+ multisample: { count: this.sampleCount },
235
+ });
236
+ this.pipelines.set(key, pipeline);
237
+ return pipeline;
238
+ }
239
+ writeDirtyRanges(runtime, buffer, vertices, dirtyRanges, mergedRanges) {
240
+ const engine = this.requireEngine();
241
+ for (const range of mergeDirtyRanges(dirtyRanges, mergedRanges, runtime.mergedDirtyRangePool, runtime.allocationStats)) {
242
+ if (range.byteLength <= 0)
243
+ continue;
244
+ engine.device.queue.writeBuffer(buffer, range.byteOffset, vertices.data.buffer, range.byteOffset, range.byteLength);
245
+ }
246
+ }
247
+ deferBufferDestroy(buffer) {
248
+ const engine = this.requireEngine();
249
+ this.pendingBufferDestroys.add(buffer);
250
+ void engine.device.queue.onSubmittedWorkDone().finally(() => {
251
+ if (!this.pendingBufferDestroys.delete(buffer))
252
+ return;
253
+ getExtensionGPUResourceTracker(engine)?.untrackBuffer(buffer);
254
+ buffer.destroy();
255
+ });
256
+ }
257
+ flushPendingBufferDestroys() {
258
+ const engine = this.engine;
259
+ for (const buffer of this.pendingBufferDestroys) {
260
+ if (engine)
261
+ getExtensionGPUResourceTracker(engine)?.untrackBuffer(buffer);
262
+ buffer.destroy();
263
+ }
264
+ this.pendingBufferDestroys.clear();
265
+ }
266
+ requireEngine() {
267
+ if (!this.engine)
268
+ throw spineRendererStateError();
269
+ requireEngineDevice(this.engine);
270
+ return this.engine;
271
+ }
272
+ requirePrepared() {
273
+ if (!this.cameraGpu
274
+ || !this.textureGpu
275
+ || !this.objectLayoutGpu
276
+ || !this.shaderModule
277
+ || !this.pipelineLayout) {
278
+ throw spineRendererStateError();
279
+ }
280
+ return {
281
+ cameraGpu: this.cameraGpu,
282
+ textureGpu: this.textureGpu,
283
+ objectLayout: this.objectLayoutGpu,
284
+ shaderModule: this.shaderModule,
285
+ pipelineLayout: this.pipelineLayout,
286
+ };
287
+ }
288
+ }
289
+ function nextGpuBufferSize(requiredBytes, currentBytes) {
290
+ const required = Math.max(4, alignUp4(requiredBytes));
291
+ let next = Math.max(1024, currentBytes);
292
+ while (next < required)
293
+ next *= 2;
294
+ return next;
295
+ }
296
+ function mergeDirtyRanges(ranges, out, pool, allocationStats) {
297
+ if (ranges.length <= 1)
298
+ return ranges;
299
+ ranges.sort((a, b) => a.byteOffset - b.byteOffset);
300
+ out.length = 0;
301
+ for (const range of ranges) {
302
+ const last = out[out.length - 1];
303
+ if (!last) {
304
+ pushMergedRange(out, pool, range.byteOffset, range.byteLength, allocationStats);
305
+ continue;
306
+ }
307
+ const lastEnd = last.byteOffset + last.byteLength;
308
+ if (range.byteOffset <= lastEnd) {
309
+ last.byteLength = Math.max(lastEnd, range.byteOffset + range.byteLength) - last.byteOffset;
310
+ }
311
+ else {
312
+ pushMergedRange(out, pool, range.byteOffset, range.byteLength, allocationStats);
313
+ }
314
+ }
315
+ return out;
316
+ }
317
+ function pushMergedRange(out, pool, byteOffset, byteLength, allocationStats) {
318
+ const index = out.length;
319
+ let range = pool[index];
320
+ if (!range) {
321
+ range = { byteOffset, byteLength };
322
+ pool.push(range);
323
+ allocationStats.dirtyRangePoolMisses++;
324
+ }
325
+ else {
326
+ range.byteOffset = byteOffset;
327
+ range.byteLength = byteLength;
328
+ }
329
+ out.push(range);
330
+ }
331
+ function loadImage(url) {
332
+ return new Promise((resolve, reject) => {
333
+ const image = new Image();
334
+ image.crossOrigin = 'anonymous';
335
+ image.onload = () => resolve(image);
336
+ image.onerror = () => reject(new EngineError(EngineErrorCode.AssetLoadFailed, `Failed to load Spine image: ${url}`, {
337
+ domain: ErrorDomain.Component,
338
+ recovery: ErrorRecovery.Retry,
339
+ context: { url, resourceType: 'skeleton/spine-image' },
340
+ path: 'spine.atlas.pages',
341
+ }));
342
+ image.src = url;
343
+ });
344
+ }
345
+ function spineRendererStateError() {
346
+ return new EngineError(EngineErrorCode.RendererResourceNotReady, 'Spine2DGpuRenderer is not prepared.', {
347
+ domain: ErrorDomain.Component,
348
+ recovery: ErrorRecovery.TerminateRuntime,
349
+ path: 'spine.renderer',
350
+ });
351
+ }
352
+
353
+ class Spine2DRenderSystem extends RenderSystem2DBase {
354
+ gpuRenderer = new Spine2DGpuRenderer();
355
+ runtimes = new Map();
356
+ entityGpu = new Map();
357
+ liveComponents = new Set();
358
+ pendingLoads = new Map();
359
+ assetWorker;
360
+ disposed = false;
361
+ get renderPipelineOptions() {
362
+ return {
363
+ pass: 'shared',
364
+ loadOp: this.loadOp,
365
+ recordMode: 'delta',
366
+ sort: this.priority,
367
+ };
368
+ }
369
+ constructor(engine, cameraEntity, options = {}) {
370
+ super({ all: [Spine2DComponent] }, engine, cameraEntity, options, 'Spine2DRenderSystem');
371
+ this.assetWorker = options.assetWorker ?? null;
372
+ }
373
+ record(world, delta, context) {
374
+ if (this.disabled || !this.engine.device)
375
+ return this;
376
+ this.gpuRenderer.prepare(this.engine);
377
+ this.gpuRenderer.setRenderView(context.view?.reverseZ ?? this.engine.reverseZ, context.view?.sampleCount ?? this.engine.msaaSamples);
378
+ const liveEntities = this.beginLiveEntityTracking();
379
+ this.liveComponents.clear();
380
+ if (!this.writeCameraBuffer(this.engine.device.queue, this.gpuRenderer.cameraBuffer, context))
381
+ return this;
382
+ const { passEncoder: pass, ownsPass } = beginRenderCommandPass(context);
383
+ const entities = this.entitySet.get(world);
384
+ if (entities)
385
+ for (const entity of entities) {
386
+ if (!this.isEntityRenderable(entity))
387
+ continue;
388
+ const component = entity.getComponent(Spine2DComponent);
389
+ if (!component || !component.jsonUrl)
390
+ continue;
391
+ this.liveComponents.add(component);
392
+ this.ensureRuntime(component);
393
+ const runtime = this.runtimes.get(component);
394
+ if (!runtime || component.status !== 'loaded')
395
+ continue;
396
+ advanceSpineRuntime(component, delta);
397
+ const { vertices, debugVertices, vertexDirtyRanges, debugDirtyRanges, verticesChanged, debugVerticesChanged, } = buildSpineVertices(component, runtime);
398
+ if (vertices.length === 0)
399
+ continue;
400
+ if (verticesChanged)
401
+ this.gpuRenderer.writeVertices(runtime, vertices, vertexDirtyRanges);
402
+ const gpu = this.getEntityGpu(entity);
403
+ this.markEntityLive(entity);
404
+ const worldMatrix = this.getWorldMatrix2D(entity, context);
405
+ writeObjectMatrixIfChanged(this.engine.device.queue, gpu.objectGpu, worldMatrix);
406
+ if (debugVertices.length > 0) {
407
+ if (debugVerticesChanged)
408
+ this.gpuRenderer.writeDebugVertices(runtime, debugVertices, debugDirtyRanges);
409
+ }
410
+ this.gpuRenderer.drawRuntime(pass, runtime, gpu.objectGpu.bindGroup, debugVertices.length / 8);
411
+ }
412
+ if (ownsPass)
413
+ pass.end();
414
+ this.releaseEntityGpuEntriesNotIn(this.entityGpu, gpu => this.destroyEntityGpu(gpu), liveEntities);
415
+ this.releaseRuntimesNotIn(this.liveComponents);
416
+ return this;
417
+ }
418
+ destroy() {
419
+ this.disposed = true;
420
+ for (const pending of this.pendingLoads.values())
421
+ pending.controller.abort('system-destroyed');
422
+ this.pendingLoads.clear();
423
+ this.releaseGpuResourcesForRecovery();
424
+ return super.destroy();
425
+ }
426
+ releaseGpuResourcesForRecovery() {
427
+ for (const pending of this.pendingLoads.values())
428
+ pending.controller.abort('device-lost');
429
+ this.pendingLoads.clear();
430
+ this.destroyEntityGpuEntries(this.entityGpu, gpu => this.destroyEntityGpu(gpu));
431
+ for (const [component, runtime] of this.runtimes) {
432
+ this.destroyRuntime(runtime);
433
+ component.runtimeKey = '';
434
+ component.loadingKey = '';
435
+ }
436
+ this.runtimes.clear();
437
+ this.gpuRenderer.destroy();
438
+ }
439
+ restoreGpuResourcesAfterRecovery() {
440
+ this.gpuRenderer = new Spine2DGpuRenderer();
441
+ this.disposed = false;
442
+ }
443
+ getEntityGpu(entity) {
444
+ return this.getOrCreateEntityGpu(this.entityGpu, entity, () => ({
445
+ objectGpu: this.createObjectGpu(this.gpuRenderer.objectLayout),
446
+ }));
447
+ }
448
+ releaseRuntimesNotIn(liveComponents) {
449
+ for (const [component, pending] of this.pendingLoads) {
450
+ if (liveComponents.has(component))
451
+ continue;
452
+ pending.controller.abort('component-removed');
453
+ this.pendingLoads.delete(component);
454
+ component.loadingKey = '';
455
+ }
456
+ for (const [component, runtime] of this.runtimes) {
457
+ if (!liveComponents.has(component)) {
458
+ this.destroyRuntime(runtime);
459
+ this.runtimes.delete(component);
460
+ component.runtimeKey = '';
461
+ }
462
+ }
463
+ }
464
+ destroyEntityGpu(gpu) {
465
+ this.destroyObjectGpu(gpu.objectGpu);
466
+ }
467
+ destroyRuntime(runtime) {
468
+ this.gpuRenderer.destroyRuntime(runtime);
469
+ }
470
+ ensureRuntime(component) {
471
+ const key = component.sourceKey;
472
+ if (component.runtimeKey === key || component.loadingKey === key)
473
+ return;
474
+ const previousPending = this.pendingLoads.get(component);
475
+ previousPending?.controller.abort('source-changed');
476
+ this.pendingLoads.delete(component);
477
+ const previous = this.runtimes.get(component);
478
+ if (previous) {
479
+ this.destroyRuntime(previous);
480
+ this.runtimes.delete(component);
481
+ component.runtimeKey = '';
482
+ }
483
+ component.status = 'loading';
484
+ component.error = null;
485
+ component.loadingKey = key;
486
+ const controller = new AbortController();
487
+ const pending = { key, controller };
488
+ this.pendingLoads.set(component, pending);
489
+ void loadSpineRuntime(this.gpuRenderer, component, { assetWorker: this.assetWorker, signal: controller.signal })
490
+ .then((runtime) => {
491
+ if (this.disposed || component.loadingKey !== key) {
492
+ this.destroyRuntime(runtime);
493
+ return;
494
+ }
495
+ this.runtimes.set(component, runtime);
496
+ component.runtimeKey = key;
497
+ component.status = 'loaded';
498
+ component.elapsed = 0;
499
+ })
500
+ .catch((error) => {
501
+ if (controller.signal.aborted)
502
+ return;
503
+ component.status = 'error';
504
+ component.error = error instanceof Error ? error.message : String(error);
505
+ console.warn(`[Spine2DRenderSystem] ${component.error}`);
506
+ })
507
+ .finally(() => {
508
+ if (this.pendingLoads.get(component) === pending)
509
+ this.pendingLoads.delete(component);
510
+ if (component.loadingKey === key)
511
+ component.loadingKey = '';
512
+ });
513
+ }
514
+ }
515
+
516
+ function createSpinePlugin(options = {}) {
517
+ let system = null;
518
+ return {
519
+ name: '@haiyue/extensions/spine',
520
+ version: EXTENSIONS_PLUGIN_VERSION,
521
+ installEngine(context) {
522
+ context.registerComponent({ type: 'Spine2DComponent', component: Spine2DComponent });
523
+ },
524
+ installScene(context) {
525
+ context.registerComponent({ type: 'Spine2DComponent', component: Spine2DComponent });
526
+ system = new Spine2DRenderSystem(context.engine, context.cameraEntity, options.system);
527
+ context.addSystem(system, options.render ?? { pass: 'shared', loadOp: system.loadOp });
528
+ },
529
+ uninstallScene(context) {
530
+ removeSystem(context, system);
531
+ system = null;
532
+ },
533
+ installEditor(context) {
534
+ context.registerContribution({ components: [{
535
+ type: 'Spine2DComponent',
536
+ create: () => new Spine2DComponent({ jsonUrl: '', atlasUrl: '', imageUrl: '', scale: 1 }),
537
+ inspector: Spine2DComponent.editor,
538
+ serialize(component) {
539
+ return {
540
+ type: 'Spine2DComponent',
541
+ jsonUrl: component.jsonUrl,
542
+ atlasUrl: component.atlasUrl,
543
+ imageUrl: component.imageUrl,
544
+ imageUrls: { ...component.imageUrls },
545
+ skin: component.skin,
546
+ animation: component.animation,
547
+ loop: component.loop,
548
+ timeScale: component.timeScale,
549
+ scale: component.scale,
550
+ premultipliedAlpha: component.premultipliedAlpha,
551
+ };
552
+ },
553
+ deserialize(data) {
554
+ const value = data;
555
+ return value.type === 'Spine2DComponent' ? new Spine2DComponent(value) : null;
556
+ },
557
+ clone: (component) => component.clone(),
558
+ installViewport(viewport) {
559
+ return installEditorRenderSystem(viewport, Spine2DRenderSystem, () => new Spine2DRenderSystem(viewport.engine, viewport.camera2DEntity, options.system));
560
+ },
561
+ runtimeExport: {
562
+ imports: [{ from: '@haiyue/extensions/spine', names: ['Spine2DComponent', 'Spine2DRenderSystem'] }],
563
+ systems: ['Spine2DRenderSystem'],
564
+ deserializeExpression: 'new Spine2DComponent(data)',
565
+ installSystems: ` const spineCamera = findCamera2DEntity(world);
566
+ if (spineCamera && hasComponentType(world, Spine2DComponent)) {
567
+ applyViewportSettingsToCamera2D(spineCamera, scene.globals);
568
+ addRenderSystem(new Spine2DRenderSystem(engine, spineCamera, { loadOp: 'load', priority: 3 }), { pass: 'shared', loadOp: 'load' });
569
+ }`,
570
+ has2D: true,
571
+ },
572
+ }] });
573
+ },
574
+ };
575
+ }
576
+
577
+ export { Spine2DComponent, Spine2DRenderSystem, createSpinePlugin };
578
+ //# sourceMappingURL=spine.js.map