@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,582 @@
1
+ import { Spine2DComponent } from './Spine2DComponent';
2
+ import {
3
+ type BonePose,
4
+ type PathConstraintData,
5
+ type RegionAttachment,
6
+ type SlotData,
7
+ type SpineData,
8
+ } from './SpineSkeletonRuntime';
9
+ import { requiredItemAt, requiredNumberAt } from '../utils/arrayAccess';
10
+ import {
11
+ sampleCompiledTimeline,
12
+ type SpineTimelineSamplerState,
13
+ } from './SpineTimelineRuntime';
14
+
15
+ export interface SpinePathConstraintScratch {
16
+ pathBonesScratch: BonePose[];
17
+ pathConstrainedBonesScratch: Set<string>;
18
+ pathSpacesScratch: number[];
19
+ pathLengthsScratch: number[];
20
+ pathWorldScratch: number[];
21
+ pathOutScratch: number[];
22
+ pathCurveWorldScratch: number[];
23
+ pathCurvesScratch: number[];
24
+ pathSegmentsScratch: number[];
25
+ pathCurvePointScratch: number[];
26
+ pathStateScratch: { position: number; spacing: number; mixRotate: number; mixX: number; mixY: number };
27
+ }
28
+
29
+ export interface SpinePathConstraintRuntime extends SpinePathConstraintScratch {
30
+ data: SpineData;
31
+ timelineSamplerState: SpineTimelineSamplerState;
32
+ }
33
+
34
+ export interface SpinePathConstraintDeps {
35
+ normalizeRadians(value: number): number;
36
+ updateDescendantBoneTrees(
37
+ name: string,
38
+ poses: Map<string, BonePose>,
39
+ children: Map<string, string[]>,
40
+ blockedRoots?: Set<string>,
41
+ ): void;
42
+ }
43
+
44
+ export function createSpinePathConstraintScratch(): SpinePathConstraintScratch {
45
+ return {
46
+ pathBonesScratch: [],
47
+ pathConstrainedBonesScratch: new Set(),
48
+ pathSpacesScratch: [],
49
+ pathLengthsScratch: [],
50
+ pathWorldScratch: [],
51
+ pathOutScratch: [],
52
+ pathCurveWorldScratch: [],
53
+ pathCurvesScratch: [],
54
+ pathSegmentsScratch: [],
55
+ pathCurvePointScratch: [],
56
+ pathStateScratch: { position: 0, spacing: 0, mixRotate: 0, mixX: 0, mixY: 0 },
57
+ };
58
+ }
59
+
60
+ export function applyPathConstraint(
61
+ runtime: SpinePathConstraintRuntime,
62
+ component: Spine2DComponent,
63
+ constraint: PathConstraintData,
64
+ time: number,
65
+ duration: number,
66
+ loop: boolean,
67
+ poses: Map<string, BonePose>,
68
+ children: Map<string, string[]>,
69
+ deps: SpinePathConstraintDeps,
70
+ ): void {
71
+ const data = runtime.data;
72
+ const slot = data.slots.find(item => item.name === constraint.slot);
73
+ if (!slot) return;
74
+ const slotBone = poses.get(slot.bone);
75
+ if (!slotBone) return;
76
+ const skin = data.skins[component.skin] ?? {};
77
+ const slotSkin = skin[slot.name] ?? data.skins.default?.[slot.name] ?? {};
78
+ const attachmentName = slot.attachment ?? Object.keys(slotSkin)[0];
79
+ const attachment = attachmentName ? slotSkin[attachmentName] : null;
80
+ if (!attachment || attachment.type !== 'path') return;
81
+ const state = samplePathConstraint(
82
+ runtime,
83
+ constraint,
84
+ data.animations[component.animation]?.path?.[constraint.name],
85
+ time,
86
+ duration,
87
+ loop,
88
+ runtime.pathStateScratch,
89
+ );
90
+ if (state.mixRotate === 0 && state.mixX === 0 && state.mixY === 0) return;
91
+
92
+ const bones = runtime.pathBonesScratch;
93
+ const constrainedBones = runtime.pathConstrainedBonesScratch;
94
+ bones.length = 0;
95
+ constrainedBones.clear();
96
+ for (const name of constraint.bones) {
97
+ constrainedBones.add(name);
98
+ const bone = poses.get(name);
99
+ if (bone) bones.push(bone);
100
+ }
101
+ const boneCount = bones.length;
102
+ if (boneCount === 0) return;
103
+ const tangents = constraint.rotateMode === 'tangent';
104
+ const chainScale = constraint.rotateMode === 'chainScale';
105
+ const spacesCount = tangents ? boneCount : boneCount + 1;
106
+ const spaces = runtime.pathSpacesScratch;
107
+ const lengths = runtime.pathLengthsScratch;
108
+ spaces.length = spacesCount;
109
+ lengths.length = boneCount;
110
+ for (let i = 0; i < spacesCount; i++) spaces[i] = 0;
111
+ for (let i = 0; i < boneCount; i++) lengths[i] = 0;
112
+
113
+ switch (constraint.spacingMode) {
114
+ case 'percent':
115
+ if (chainScale) {
116
+ for (let i = 0; i < spacesCount - 1; i++) {
117
+ lengths[i] = getBoneWorldLength(requiredItemAt(bones, i, 'path constrained bones'));
118
+ }
119
+ }
120
+ for (let i = 1; i < spacesCount; i++) spaces[i] = state.spacing;
121
+ break;
122
+ case 'proportional': {
123
+ let sum = 0;
124
+ for (let i = 0; i < spacesCount - 1;) {
125
+ const length = getBoneWorldLength(requiredItemAt(bones, i, 'path constrained bones'));
126
+ if (chainScale) lengths[i] = length;
127
+ spaces[++i] = length < 0.000001 ? state.spacing : length;
128
+ sum += length < 0.000001 ? 0 : length;
129
+ }
130
+ if (sum > 0) {
131
+ const scale = spacesCount / sum * state.spacing;
132
+ for (let i = 1; i < spacesCount; i++) spaces[i] = requiredNumberAt(spaces, i, 'path spaces') * scale;
133
+ }
134
+ break;
135
+ }
136
+ default:
137
+ for (let i = 0; i < spacesCount - 1;) {
138
+ const bone = requiredItemAt(bones, i, 'path constrained bones');
139
+ const worldLength = getBoneWorldLength(bone);
140
+ if (chainScale) lengths[i] = worldLength;
141
+ spaces[++i] = constraint.spacingMode === 'length' && bone.data.length > 0
142
+ ? Math.max(0, bone.data.length + state.spacing) * worldLength / bone.data.length
143
+ : state.spacing;
144
+ }
145
+ break;
146
+ }
147
+
148
+ const positions = computePathWorldPositions(runtime, poses, slotBone, attachment, constraint, state.position, spaces, tangents);
149
+ let boneX = requiredNumberAt(positions, 0, 'path positions');
150
+ let boneY = requiredNumberAt(positions, 1, 'path positions');
151
+ let offsetRotation = constraint.offsetRotation * Math.PI / 180;
152
+ if (offsetRotation !== 0 && slotBone.a * slotBone.d - slotBone.b * slotBone.c < 0) offsetRotation = -offsetRotation;
153
+ const tip = offsetRotation === 0 && constraint.rotateMode === 'chain';
154
+
155
+ for (let i = 0, positionIndex = 3; i < boneCount; i++, positionIndex += 3) {
156
+ const bone = requiredItemAt(bones, i, 'path constrained bones');
157
+ bone.worldX += (boneX - bone.worldX) * state.mixX;
158
+ bone.worldY += (boneY - bone.worldY) * state.mixY;
159
+ const x = requiredNumberAt(positions, positionIndex, 'path positions');
160
+ const y = requiredNumberAt(positions, positionIndex + 1, 'path positions');
161
+ const dx = x - boneX;
162
+ const dy = y - boneY;
163
+ if (chainScale) {
164
+ const length = requiredNumberAt(lengths, i, 'path lengths');
165
+ if (length !== 0) {
166
+ const scale = (Math.hypot(dx, dy) / length - 1) * state.mixRotate + 1;
167
+ bone.a *= scale;
168
+ bone.c *= scale;
169
+ }
170
+ }
171
+ boneX = x;
172
+ boneY = y;
173
+ if (state.mixRotate > 0) {
174
+ const a = bone.a;
175
+ const b = bone.b;
176
+ const c = bone.c;
177
+ const d = bone.d;
178
+ let rotation = tangents
179
+ ? requiredNumberAt(positions, positionIndex - 1, 'path positions')
180
+ : requiredNumberAt(spaces, i + 1, 'path spaces') === 0
181
+ ? requiredNumberAt(positions, positionIndex + 2, 'path positions')
182
+ : Math.atan2(dy, dx);
183
+ rotation -= Math.atan2(c, a);
184
+ if (tip) {
185
+ const cos = Math.cos(rotation);
186
+ const sin = Math.sin(rotation);
187
+ const length = bone.data.length;
188
+ boneX += (length * (cos * a - sin * c) - dx) * state.mixRotate;
189
+ boneY += (length * (sin * a + cos * c) - dy) * state.mixRotate;
190
+ } else {
191
+ rotation += offsetRotation;
192
+ }
193
+ rotation = deps.normalizeRadians(rotation) * state.mixRotate;
194
+ const cos = Math.cos(rotation);
195
+ const sin = Math.sin(rotation);
196
+ bone.a = cos * a - sin * c;
197
+ bone.b = cos * b - sin * d;
198
+ bone.c = sin * a + cos * c;
199
+ bone.d = sin * b + cos * d;
200
+ }
201
+ }
202
+ for (const boneName of constraint.bones) deps.updateDescendantBoneTrees(boneName, poses, children, constrainedBones);
203
+ }
204
+
205
+ function samplePathConstraint(
206
+ runtime: SpinePathConstraintRuntime,
207
+ constraint: PathConstraintData,
208
+ frames: unknown[] | undefined,
209
+ time: number,
210
+ duration: number,
211
+ loop: boolean,
212
+ out: { position: number; spacing: number; mixRotate: number; mixX: number; mixY: number },
213
+ ): { position: number; spacing: number; mixRotate: number; mixX: number; mixY: number } {
214
+ const sampler = runtime.timelineSamplerState;
215
+ out.position = sampleCompiledTimeline(frames ?? [], time, 'position', constraint.position, duration, loop, sampler);
216
+ out.spacing = sampleCompiledTimeline(frames ?? [], time, 'spacing', constraint.spacing, duration, loop, sampler);
217
+ out.mixRotate = sampleCompiledTimeline(frames ?? [], time, 'mixRotate', constraint.mixRotate, duration, loop, sampler);
218
+ out.mixX = sampleCompiledTimeline(frames ?? [], time, 'mixX', constraint.mixX, duration, loop, sampler);
219
+ out.mixY = sampleCompiledTimeline(frames ?? [], time, 'mixY', constraint.mixY, duration, loop, sampler);
220
+ return out;
221
+ }
222
+
223
+ function getBoneWorldLength(bone: BonePose): number {
224
+ return Math.hypot(bone.data.length * bone.a, bone.data.length * bone.c);
225
+ }
226
+
227
+ function computePathPoints(
228
+ runtime: SpinePathConstraintRuntime,
229
+ poses: Map<string, BonePose>,
230
+ slotBone: BonePose,
231
+ attachment: RegionAttachment,
232
+ out: number[],
233
+ ): number[] {
234
+ const data = runtime.data;
235
+ const vertices = attachment.vertices ?? [];
236
+ const vertexCount = attachment.vertices ? attachment.vertexCount ?? inferWeightedVertexCount(vertices) : 0;
237
+ out.length = 0;
238
+ if (vertexCount > 0 && vertices.length !== vertexCount * 2) {
239
+ let offset = 0;
240
+ for (let vertex = 0; vertex < vertexCount && offset < vertices.length; vertex++) {
241
+ const boneCount = vertices[offset++] ?? 0;
242
+ let x = 0;
243
+ let y = 0;
244
+ for (let influence = 0; influence < boneCount; influence++) {
245
+ const boneIndex = vertices[offset++] ?? -1;
246
+ const vx = vertices[offset++] ?? 0;
247
+ const vy = vertices[offset++] ?? 0;
248
+ const weight = vertices[offset++] ?? 0;
249
+ const boneName = data.bones[boneIndex]?.name;
250
+ const bone = boneName ? poses.get(boneName) : null;
251
+ if (!bone) continue;
252
+ x += (bone.a * vx + bone.b * vy + bone.worldX) * weight;
253
+ y += (bone.c * vx + bone.d * vy + bone.worldY) * weight;
254
+ }
255
+ out.push(x, y);
256
+ }
257
+ return out;
258
+ }
259
+ for (let i = 0; i < vertices.length - 1; i += 2) {
260
+ out.push(
261
+ slotBone.a * requiredNumberAt(vertices, i, 'path vertices')
262
+ + slotBone.b * requiredNumberAt(vertices, i + 1, 'path vertices') + slotBone.worldX,
263
+ slotBone.c * requiredNumberAt(vertices, i, 'path vertices')
264
+ + slotBone.d * requiredNumberAt(vertices, i + 1, 'path vertices') + slotBone.worldY,
265
+ );
266
+ }
267
+ return out;
268
+ }
269
+
270
+ function computePathWorldPositions(
271
+ runtime: SpinePathConstraintRuntime,
272
+ poses: Map<string, BonePose>,
273
+ slotBone: BonePose,
274
+ attachment: RegionAttachment,
275
+ constraint: PathConstraintData,
276
+ position: number,
277
+ spaces: number[],
278
+ tangents: boolean,
279
+ ): number[] {
280
+ const vertexCount = attachment.vertexCount ?? inferWeightedVertexCount(attachment.vertices ?? []);
281
+ const world = computePathPoints(runtime, poses, slotBone, attachment, runtime.pathWorldScratch);
282
+ const spacesCount = spaces.length;
283
+ const out = runtime.pathOutScratch;
284
+ out.length = spacesCount * 3 + 2;
285
+ for (let i = 0; i < out.length; i++) out[i] = 0;
286
+ if (world.length < 8) return out;
287
+ const closed = attachment.closed ?? false;
288
+ let verticesLength = vertexCount * 2;
289
+ let curveCount = verticesLength / 6;
290
+
291
+ if (!attachment.constantSpeed) {
292
+ const lengths = attachment.lengths ?? [];
293
+ curveCount -= closed ? 1 : 2;
294
+ const pathLength = lengths[curveCount] ?? lengths[lengths.length - 1] ?? 0;
295
+ if (constraint.positionMode === 'percent') position *= pathLength;
296
+ const multiplier = constraint.spacingMode === 'percent'
297
+ ? pathLength
298
+ : constraint.spacingMode === 'proportional'
299
+ ? pathLength / spacesCount
300
+ : 1;
301
+ let curve = 0;
302
+ let previousCurve = -4;
303
+ const curveWorld = runtime.pathCurveWorldScratch;
304
+ for (let i = 0, o = 0; i < spacesCount; i++, o += 3) {
305
+ position += requiredNumberAt(spaces, i, 'path spaces') * multiplier;
306
+ let p = position;
307
+ if (closed) {
308
+ p %= pathLength;
309
+ if (p < 0) p += pathLength;
310
+ curve = 0;
311
+ } else if (p < 0) {
312
+ addBeforePathPosition(p, world, 2, out, o);
313
+ continue;
314
+ } else if (p > pathLength) {
315
+ addAfterPathPosition(p - pathLength, world, verticesLength - 6, out, o);
316
+ continue;
317
+ }
318
+ for (;; curve++) {
319
+ const length = lengths[curve] ?? pathLength;
320
+ if (p > length) continue;
321
+ const previousLength = curve === 0 ? 0 : requiredNumberAt(lengths, curve - 1, 'path attachment lengths');
322
+ p = curve === 0 ? p / length : (p - previousLength) / (length - previousLength);
323
+ break;
324
+ }
325
+ if (curve !== previousCurve) {
326
+ previousCurve = curve;
327
+ curveWorld.length = 0;
328
+ if (closed && curve === curveCount) {
329
+ appendArrayRange(curveWorld, world, verticesLength - 4, verticesLength);
330
+ appendArrayRange(curveWorld, world, 0, 4);
331
+ } else {
332
+ appendArrayRange(curveWorld, world, curve * 6 + 2, curve * 6 + 10);
333
+ }
334
+ }
335
+ addCurvePathPosition(
336
+ p,
337
+ curveWorld,
338
+ out,
339
+ o,
340
+ tangents || (i > 0 && requiredNumberAt(spaces, i, 'path spaces') === 0),
341
+ );
342
+ }
343
+ return out;
344
+ }
345
+
346
+ const pathWorld = runtime.pathCurveWorldScratch;
347
+ pathWorld.length = 0;
348
+ if (closed) {
349
+ verticesLength += 2;
350
+ appendArrayRange(pathWorld, world, 2, verticesLength - 2);
351
+ appendArrayRange(pathWorld, world, 0, 2);
352
+ pathWorld.push(
353
+ requiredNumberAt(pathWorld, 0, 'closed path world points'),
354
+ requiredNumberAt(pathWorld, 1, 'closed path world points'),
355
+ );
356
+ } else {
357
+ curveCount--;
358
+ verticesLength -= 4;
359
+ appendArrayRange(pathWorld, world, 2, 2 + verticesLength);
360
+ }
361
+ const curves = runtime.pathCurvesScratch;
362
+ curves.length = curveCount;
363
+ let pathLength = 0;
364
+ let x1 = requiredNumberAt(pathWorld, 0, 'path world points');
365
+ let y1 = requiredNumberAt(pathWorld, 1, 'path world points');
366
+ let cx1 = 0;
367
+ let cy1 = 0;
368
+ let cx2 = 0;
369
+ let cy2 = 0;
370
+ let x2 = 0;
371
+ let y2 = 0;
372
+ let tmpx = 0;
373
+ let tmpy = 0;
374
+ let dddfx = 0;
375
+ let dddfy = 0;
376
+ let ddfx = 0;
377
+ let ddfy = 0;
378
+ let dfx = 0;
379
+ let dfy = 0;
380
+ for (let i = 0, w = 2; i < curveCount; i++, w += 6) {
381
+ cx1 = requiredNumberAt(pathWorld, w, 'path world points');
382
+ cy1 = requiredNumberAt(pathWorld, w + 1, 'path world points');
383
+ cx2 = requiredNumberAt(pathWorld, w + 2, 'path world points');
384
+ cy2 = requiredNumberAt(pathWorld, w + 3, 'path world points');
385
+ x2 = requiredNumberAt(pathWorld, w + 4, 'path world points');
386
+ y2 = requiredNumberAt(pathWorld, w + 5, 'path world points');
387
+ tmpx = (x1 - cx1 * 2 + cx2) * 0.1875;
388
+ tmpy = (y1 - cy1 * 2 + cy2) * 0.1875;
389
+ dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375;
390
+ dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375;
391
+ ddfx = tmpx * 2 + dddfx;
392
+ ddfy = tmpy * 2 + dddfy;
393
+ dfx = (cx1 - x1) * 0.75 + tmpx + dddfx * 0.16666667;
394
+ dfy = (cy1 - y1) * 0.75 + tmpy + dddfy * 0.16666667;
395
+ pathLength += Math.hypot(dfx, dfy);
396
+ dfx += ddfx;
397
+ dfy += ddfy;
398
+ ddfx += dddfx;
399
+ ddfy += dddfy;
400
+ pathLength += Math.hypot(dfx, dfy);
401
+ dfx += ddfx;
402
+ dfy += ddfy;
403
+ pathLength += Math.hypot(dfx, dfy);
404
+ dfx += ddfx + dddfx;
405
+ dfy += ddfy + dddfy;
406
+ pathLength += Math.hypot(dfx, dfy);
407
+ curves[i] = pathLength;
408
+ x1 = x2;
409
+ y1 = y2;
410
+ }
411
+ if (constraint.positionMode === 'percent') position *= pathLength;
412
+ const multiplier = constraint.spacingMode === 'percent'
413
+ ? pathLength
414
+ : constraint.spacingMode === 'proportional'
415
+ ? pathLength / spacesCount
416
+ : 1;
417
+
418
+ const segments = runtime.pathSegmentsScratch;
419
+ segments.length = 10;
420
+ let curveLength = 0;
421
+ let previousCurve = -1;
422
+ let segment = 0;
423
+ for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
424
+ const space = requiredNumberAt(spaces, i, 'path spaces') * multiplier;
425
+ position += space;
426
+ let p = position;
427
+ if (closed) {
428
+ p %= pathLength;
429
+ if (p < 0) p += pathLength;
430
+ curve = 0;
431
+ segment = 0;
432
+ } else if (p < 0) {
433
+ addBeforePathPosition(p, pathWorld, 0, out, o);
434
+ continue;
435
+ } else if (p > pathLength) {
436
+ addAfterPathPosition(p - pathLength, pathWorld, pathWorld.length - 4, out, o);
437
+ continue;
438
+ }
439
+ for (;; curve++) {
440
+ const length = requiredNumberAt(curves, curve, 'path curve lengths');
441
+ if (p > length) continue;
442
+ const previousLength = curve === 0 ? 0 : requiredNumberAt(curves, curve - 1, 'path curve lengths');
443
+ p = curve === 0 ? p / length : (p - previousLength) / (length - previousLength);
444
+ break;
445
+ }
446
+ if (curve !== previousCurve) {
447
+ previousCurve = curve;
448
+ const w = curve * 6;
449
+ x1 = requiredNumberAt(pathWorld, w, 'path world points');
450
+ y1 = requiredNumberAt(pathWorld, w + 1, 'path world points');
451
+ cx1 = requiredNumberAt(pathWorld, w + 2, 'path world points');
452
+ cy1 = requiredNumberAt(pathWorld, w + 3, 'path world points');
453
+ cx2 = requiredNumberAt(pathWorld, w + 4, 'path world points');
454
+ cy2 = requiredNumberAt(pathWorld, w + 5, 'path world points');
455
+ x2 = requiredNumberAt(pathWorld, w + 6, 'path world points');
456
+ y2 = requiredNumberAt(pathWorld, w + 7, 'path world points');
457
+ tmpx = (x1 - cx1 * 2 + cx2) * 0.03;
458
+ tmpy = (y1 - cy1 * 2 + cy2) * 0.03;
459
+ dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006;
460
+ dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006;
461
+ ddfx = tmpx * 2 + dddfx;
462
+ ddfy = tmpy * 2 + dddfy;
463
+ dfx = (cx1 - x1) * 0.3 + tmpx + dddfx * 0.16666667;
464
+ dfy = (cy1 - y1) * 0.3 + tmpy + dddfy * 0.16666667;
465
+ curveLength = Math.hypot(dfx, dfy);
466
+ segments[0] = curveLength;
467
+ for (let ii = 1; ii < 8; ii++) {
468
+ dfx += ddfx;
469
+ dfy += ddfy;
470
+ ddfx += dddfx;
471
+ ddfy += dddfy;
472
+ curveLength += Math.hypot(dfx, dfy);
473
+ segments[ii] = curveLength;
474
+ }
475
+ dfx += ddfx;
476
+ dfy += ddfy;
477
+ curveLength += Math.hypot(dfx, dfy);
478
+ segments[8] = curveLength;
479
+ dfx += ddfx + dddfx;
480
+ dfy += ddfy + dddfy;
481
+ curveLength += Math.hypot(dfx, dfy);
482
+ segments[9] = curveLength;
483
+ segment = 0;
484
+ }
485
+
486
+ p *= curveLength;
487
+ for (;; segment++) {
488
+ const length = requiredNumberAt(segments, segment, 'path segments');
489
+ if (p > length) continue;
490
+ if (segment === 0) p = length === 0 ? 0 : p / length;
491
+ else {
492
+ const previous = requiredNumberAt(segments, segment - 1, 'path segments');
493
+ p = length === previous ? segment : segment + (p - previous) / (length - previous);
494
+ }
495
+ break;
496
+ }
497
+ const curvePoint = runtime.pathCurvePointScratch;
498
+ curvePoint[0] = x1;
499
+ curvePoint[1] = y1;
500
+ curvePoint[2] = cx1;
501
+ curvePoint[3] = cy1;
502
+ curvePoint[4] = cx2;
503
+ curvePoint[5] = cy2;
504
+ curvePoint[6] = x2;
505
+ curvePoint[7] = y2;
506
+ addCurvePathPosition(p * 0.1, curvePoint, out, o, tangents || (i > 0 && space === 0));
507
+ }
508
+ return out;
509
+ }
510
+
511
+ function appendArrayRange(out: number[], source: number[], start: number, end: number): void {
512
+ for (let i = start; i < end && i < source.length; i++) {
513
+ out.push(requiredNumberAt(source, i, 'path source range'));
514
+ }
515
+ }
516
+
517
+ function inferWeightedVertexCount(vertices: number[]): number {
518
+ let count = 0;
519
+ let offset = 0;
520
+ while (offset < vertices.length) {
521
+ const boneCount = vertices[offset++] ?? 0;
522
+ offset += boneCount * 4;
523
+ count++;
524
+ }
525
+ return count;
526
+ }
527
+
528
+ function addBeforePathPosition(p: number, points: number[], index: number, out: number[], outIndex: number): void {
529
+ const x1 = requiredNumberAt(points, index, 'path points');
530
+ const y1 = requiredNumberAt(points, index + 1, 'path points');
531
+ const dx = requiredNumberAt(points, index + 2, 'path points') - x1;
532
+ const dy = requiredNumberAt(points, index + 3, 'path points') - y1;
533
+ const r = Math.atan2(dy, dx);
534
+ out[outIndex] = x1 + p * Math.cos(r);
535
+ out[outIndex + 1] = y1 + p * Math.sin(r);
536
+ out[outIndex + 2] = r;
537
+ }
538
+
539
+ function addAfterPathPosition(p: number, points: number[], index: number, out: number[], outIndex: number): void {
540
+ const x1 = requiredNumberAt(points, index + 2, 'path points');
541
+ const y1 = requiredNumberAt(points, index + 3, 'path points');
542
+ const dx = x1 - requiredNumberAt(points, index, 'path points');
543
+ const dy = y1 - requiredNumberAt(points, index + 1, 'path points');
544
+ const r = Math.atan2(dy, dx);
545
+ out[outIndex] = x1 + p * Math.cos(r);
546
+ out[outIndex + 1] = y1 + p * Math.sin(r);
547
+ out[outIndex + 2] = r;
548
+ }
549
+
550
+ function addCurvePathPosition(p: number, points: number[], out: number[], outIndex: number, tangents: boolean): void {
551
+ const x1 = requiredNumberAt(points, 0, 'Bezier path points');
552
+ const y1 = requiredNumberAt(points, 1, 'Bezier path points');
553
+ const cx1 = requiredNumberAt(points, 2, 'Bezier path points');
554
+ const cy1 = requiredNumberAt(points, 3, 'Bezier path points');
555
+ const cx2 = requiredNumberAt(points, 4, 'Bezier path points');
556
+ const cy2 = requiredNumberAt(points, 5, 'Bezier path points');
557
+ const x2 = requiredNumberAt(points, 6, 'Bezier path points');
558
+ const y2 = requiredNumberAt(points, 7, 'Bezier path points');
559
+ if (p === 0 || Number.isNaN(p)) {
560
+ out[outIndex] = x1;
561
+ out[outIndex + 1] = y1;
562
+ out[outIndex + 2] = Math.atan2(cy1 - y1, cx1 - x1);
563
+ return;
564
+ }
565
+ const tt = p * p;
566
+ const ttt = tt * p;
567
+ const u = 1 - p;
568
+ const uu = u * u;
569
+ const uuu = uu * u;
570
+ const ut = u * p;
571
+ const ut3 = ut * 3;
572
+ const uut3 = u * ut3;
573
+ const utt3 = ut3 * p;
574
+ const x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt;
575
+ const y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt;
576
+ out[outIndex] = x;
577
+ out[outIndex + 1] = y;
578
+ if (tangents) {
579
+ if (p < 0.001) out[outIndex + 2] = Math.atan2(cy1 - y1, cx1 - x1);
580
+ else out[outIndex + 2] = Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
581
+ }
582
+ }
@@ -0,0 +1,76 @@
1
+ import type { EnginePlugin } from '@haiyue/engine/core';
2
+ import type { RenderPipelineEntryOptions } from '@haiyue/engine/extension-authoring';
3
+ import { Spine2DComponent } from './Spine2DComponent';
4
+ import { Spine2DRenderSystem, type Spine2DRenderSystemOptions } from './Spine2DRenderSystem';
5
+ import {
6
+ EXTENSIONS_PLUGIN_VERSION,
7
+ installEditorRenderSystem,
8
+ removeSystem,
9
+ type EditorViewportContributionContext,
10
+ } from '../plugins/pluginUtils';
11
+
12
+ export interface SpinePluginOptions {
13
+ system?: Spine2DRenderSystemOptions;
14
+ render?: RenderPipelineEntryOptions | false | null;
15
+ }
16
+
17
+ export function createSpinePlugin(options: SpinePluginOptions = {}): EnginePlugin {
18
+ let system: Spine2DRenderSystem | null = null;
19
+ return {
20
+ name: '@haiyue/extensions/spine',
21
+ version: EXTENSIONS_PLUGIN_VERSION,
22
+ installEngine(context) {
23
+ context.registerComponent({ type: 'Spine2DComponent', component: Spine2DComponent });
24
+ },
25
+ installScene(context) {
26
+ context.registerComponent({ type: 'Spine2DComponent', component: Spine2DComponent });
27
+ system = new Spine2DRenderSystem(context.engine, context.cameraEntity, options.system);
28
+ context.addSystem(system, options.render ?? { pass: 'shared', loadOp: system.loadOp });
29
+ },
30
+ uninstallScene(context) {
31
+ removeSystem(context, system);
32
+ system = null;
33
+ },
34
+ installEditor(context) {
35
+ context.registerContribution({ components: [{
36
+ type: 'Spine2DComponent',
37
+ create: () => new Spine2DComponent({ jsonUrl: '', atlasUrl: '', imageUrl: '', scale: 1 }),
38
+ inspector: Spine2DComponent.editor,
39
+ serialize(component: Spine2DComponent) {
40
+ return {
41
+ type: 'Spine2DComponent',
42
+ jsonUrl: component.jsonUrl,
43
+ atlasUrl: component.atlasUrl,
44
+ imageUrl: component.imageUrl,
45
+ imageUrls: { ...component.imageUrls },
46
+ skin: component.skin,
47
+ animation: component.animation,
48
+ loop: component.loop,
49
+ timeScale: component.timeScale,
50
+ scale: component.scale,
51
+ premultipliedAlpha: component.premultipliedAlpha,
52
+ };
53
+ },
54
+ deserialize(data: unknown) {
55
+ const value = data as ConstructorParameters<typeof Spine2DComponent>[0] & { type?: unknown };
56
+ return value.type === 'Spine2DComponent' ? new Spine2DComponent(value) : null;
57
+ },
58
+ clone: (component: Spine2DComponent) => component.clone(),
59
+ installViewport(viewport: EditorViewportContributionContext) {
60
+ return installEditorRenderSystem(viewport, Spine2DRenderSystem, () => new Spine2DRenderSystem(viewport.engine, viewport.camera2DEntity, options.system));
61
+ },
62
+ runtimeExport: {
63
+ imports: [{ from: '@haiyue/extensions/spine', names: ['Spine2DComponent', 'Spine2DRenderSystem'] }],
64
+ systems: ['Spine2DRenderSystem'],
65
+ deserializeExpression: 'new Spine2DComponent(data)',
66
+ installSystems: ` const spineCamera = findCamera2DEntity(world);
67
+ if (spineCamera && hasComponentType(world, Spine2DComponent)) {
68
+ applyViewportSettingsToCamera2D(spineCamera, scene.globals);
69
+ addRenderSystem(new Spine2DRenderSystem(engine, spineCamera, { loadOp: 'load', priority: 3 }), { pass: 'shared', loadOp: 'load' });
70
+ }`,
71
+ has2D: true,
72
+ },
73
+ }] });
74
+ },
75
+ };
76
+ }