@haiyue/extensions 0.1.0 → 0.2.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 (269) hide show
  1. package/README.md +25 -0
  2. package/dist/animation/Animation2DComponent.d.ts +18 -0
  3. package/dist/animation/Animation2DExtensionRegistry.d.ts +7 -0
  4. package/dist/animation/Animation2DRenderSystem.d.ts +6 -0
  5. package/dist/animation/Animation2DRuntime.d.ts +6 -2
  6. package/dist/animation/AnimationTextRasterizer.d.ts +4 -0
  7. package/dist/animation/AnimationVisual2D.d.ts +58 -2
  8. package/dist/animation/interaction/InteractionRuntime.d.ts +83 -0
  9. package/dist/animation/interaction/runtime-types.d.ts +257 -0
  10. package/dist/animation.d.ts +3 -1
  11. package/dist/animation.js +551 -59
  12. package/dist/animation3d.js +1 -1
  13. package/dist/canvas-text.js +1 -1
  14. package/dist/chunks/2d-ui-animation-2d.generated-FpziAeGJ.js +4 -0
  15. package/dist/chunks/2d-ui-indexed-sprite.generated-DmKR0CC3.js +4 -0
  16. package/dist/chunks/Animation2DStateMachine-BHcA6Cu3.js +18212 -0
  17. package/dist/chunks/{AnimationStateMachineController-BIcAh-sT.js → AnimationStateMachineController-4sKaqh9E.js} +2 -2
  18. package/dist/chunks/AnimationVisual2D-8y3qp0_U.js +230 -0
  19. package/dist/chunks/{RenderSystem2DBase-DDT61dAu.js → RenderSystem2DBase-CF2s00vg.js} +2 -2
  20. package/dist/controls/VirtualJoystickControls.d.ts +46 -0
  21. package/dist/controls/contracts.d.ts +91 -0
  22. package/dist/controls.d.ts +2 -0
  23. package/dist/controls.js +358 -0
  24. package/dist/deformable-animation/runtime/DeformableMesh2DRuntimeExtension.d.ts +11 -0
  25. package/dist/deformable-animation/runtime/DeformableMesh2DSampler.d.ts +11 -0
  26. package/dist/deformable-animation.d.ts +5 -0
  27. package/dist/deformable-animation.js +316 -0
  28. package/dist/experimental-indexed-sprite.d.ts +5 -0
  29. package/dist/experimental-indexed-sprite.js +482 -0
  30. package/dist/gltf-worker-runtime.js +9 -9
  31. package/dist/hya-state-machine.js +3 -2
  32. package/dist/index.js +1 -1
  33. package/dist/indexed-sprite/AtlasLayout.d.ts +2 -0
  34. package/dist/indexed-sprite/IndexedSpriteRenderer.d.ts +23 -0
  35. package/dist/indexed-sprite/contracts.d.ts +89 -0
  36. package/dist/internal/2d-ui-shader-artifact.js +232 -23
  37. package/dist/ray-tracing/acceleration/bvh.d.ts +37 -0
  38. package/dist/ray-tracing/acceleration/index.d.ts +6 -0
  39. package/dist/ray-tracing/acceleration/pack.d.ts +152 -0
  40. package/dist/ray-tracing/acceleration/query.d.ts +4 -0
  41. package/dist/ray-tracing/acceleration/runtime.d.ts +30 -0
  42. package/dist/ray-tracing/acceleration/tlas.d.ts +4 -0
  43. package/dist/ray-tracing/acceleration/types.d.ts +165 -0
  44. package/dist/ray-tracing/denoise/index.d.ts +3 -0
  45. package/dist/ray-tracing/denoise/layout.d.ts +9 -0
  46. package/dist/ray-tracing/denoise/runtime.d.ts +23 -0
  47. package/dist/ray-tracing/denoise/types.d.ts +28 -0
  48. package/dist/ray-tracing/hybrid/contract.d.ts +2 -0
  49. package/dist/ray-tracing/hybrid/index.d.ts +5 -0
  50. package/dist/ray-tracing/hybrid/layout.d.ts +17 -0
  51. package/dist/ray-tracing/hybrid/plan.d.ts +2 -0
  52. package/dist/ray-tracing/hybrid/runtime.d.ts +31 -0
  53. package/dist/ray-tracing/hybrid/shaders/hybrid-artifact.generated.d.ts +625 -0
  54. package/dist/ray-tracing/hybrid/types.d.ts +144 -0
  55. package/dist/ray-tracing/lifecycle/device-recovery.d.ts +31 -0
  56. package/dist/ray-tracing/lifecycle/index.d.ts +2 -0
  57. package/dist/ray-tracing/lifecycle/types.d.ts +37 -0
  58. package/dist/ray-tracing/material/index.d.ts +2 -0
  59. package/dist/ray-tracing/material/pack.d.ts +5 -0
  60. package/dist/ray-tracing/material/types.d.ts +63 -0
  61. package/dist/ray-tracing/reference/index.d.ts +122 -0
  62. package/dist/ray-tracing/renderer/index.d.ts +7 -0
  63. package/dist/ray-tracing/renderer/layout.d.ts +20 -0
  64. package/dist/ray-tracing/renderer/plan.d.ts +2 -0
  65. package/dist/ray-tracing/renderer/reference.d.ts +17 -0
  66. package/dist/ray-tracing/renderer/runtime.d.ts +39 -0
  67. package/dist/ray-tracing/renderer/scene.d.ts +4 -0
  68. package/dist/ray-tracing/renderer/types.d.ts +115 -0
  69. package/dist/ray-tracing/sampling/index.d.ts +8 -0
  70. package/dist/ray-tracing/sampling/layout.d.ts +12 -0
  71. package/dist/ray-tracing/sampling/plan.d.ts +5 -0
  72. package/dist/ray-tracing/sampling/revision.d.ts +15 -0
  73. package/dist/ray-tracing/sampling/runtime.d.ts +44 -0
  74. package/dist/ray-tracing/sampling/sequence.d.ts +2 -0
  75. package/dist/ray-tracing/sampling/types.d.ts +96 -0
  76. package/dist/ray-tracing/scene/index.d.ts +41 -0
  77. package/dist/ray-tracing/traversal/index.d.ts +4 -0
  78. package/dist/ray-tracing/traversal/layout.d.ts +16 -0
  79. package/dist/ray-tracing/traversal/plan.d.ts +2 -0
  80. package/dist/ray-tracing/traversal/runtime.d.ts +25 -0
  81. package/dist/ray-tracing/traversal/types.d.ts +79 -0
  82. package/dist/ray-tracing/worker/client.d.ts +25 -0
  83. package/dist/ray-tracing/worker/index.d.ts +5 -0
  84. package/dist/ray-tracing/worker/runtime.d.ts +11 -0
  85. package/dist/ray-tracing/worker/serialization.d.ts +16 -0
  86. package/dist/ray-tracing/worker/source.d.ts +1 -0
  87. package/dist/ray-tracing/worker/types.d.ts +91 -0
  88. package/dist/ray-tracing.d.ts +17 -0
  89. package/dist/ray-tracing.js +7666 -0
  90. package/dist/spine.js +1 -1
  91. package/dist/tilemap.js +1 -1
  92. package/package.json +26 -23
  93. package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +0 -27
  94. package/dist/animation/Particle2DDescriptorAdapter.d.ts +0 -5
  95. package/dist/animation3d/Animation3DResource.d.ts +0 -28
  96. package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +0 -65
  97. package/dist/animation3d/hya/index.d.ts +0 -4
  98. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +0 -81
  99. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +0 -39
  100. package/dist/animation3d/runtime/integration/index.d.ts +0 -2
  101. package/dist/animation3d/runtime/mixer/Action.d.ts +0 -150
  102. package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +0 -6
  103. package/dist/animation3d/runtime/mixer/Mixer.d.ts +0 -59
  104. package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +0 -1
  105. package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +0 -24
  106. package/dist/animation3d/runtime/mixer/index.d.ts +0 -4
  107. package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +0 -1
  108. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +0 -1
  109. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +0 -1
  110. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +0 -1
  111. package/dist/animation3d/runtime/state-machine/index.d.ts +0 -6
  112. package/dist/benchmark.d.ts +0 -30
  113. package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +0 -4
  114. package/dist/chunks/Animation2DStateMachine-9IonguNa.js +0 -3245
  115. package/dist/gltf/GltfAccessorReader.d.ts +0 -7
  116. package/dist/gltf/GltfDracoDecoder.d.ts +0 -4
  117. package/dist/gltf/GltfLoaderErrors.d.ts +0 -4
  118. package/dist/gltf/GltfMaterialDescriptor.d.ts +0 -23
  119. package/dist/gltf/GltfMaterialLoader.d.ts +0 -6
  120. package/dist/gltf-worker-runtime.d.ts +0 -7
  121. package/dist/plugins/pluginUtils.d.ts +0 -20
  122. package/dist/plugins.d.ts +0 -6
  123. package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +0 -658
  124. package/dist/spine/Spine2DGpuRenderer.d.ts +0 -65
  125. package/dist/spine/Spine2DRuntime.d.ts +0 -103
  126. package/dist/spine/SpineAnimationBoneTimelines.d.ts +0 -8
  127. package/dist/spine/SpineFloatBuilder.d.ts +0 -15
  128. package/dist/spine/SpinePathConstraintSolver.d.ts +0 -32
  129. package/dist/spine/SpineSkeletonRuntime.d.ts +0 -185
  130. package/dist/spine/SpineSlotAnimation.d.ts +0 -17
  131. package/dist/spine/SpineTimelineRuntime.d.ts +0 -25
  132. package/dist/spine/SpineVertexBuilder.d.ts +0 -61
  133. package/dist/tilemap/Tilemap2DRenderer.d.ts +0 -24
  134. package/dist/utils/arrayAccess.d.ts +0 -4
  135. package/dist/utils/camera2d.d.ts +0 -12
  136. package/src/animation/Animation2DComponent.ts +0 -135
  137. package/src/animation/Animation2DExtensionRegistry.ts +0 -52
  138. package/src/animation/Animation2DRenderSystem.ts +0 -1026
  139. package/src/animation/Animation2DRuntime.ts +0 -1326
  140. package/src/animation/Animation2DStateMachine.ts +0 -39
  141. package/src/animation/Animation2DStateMachineComponent.ts +0 -228
  142. package/src/animation/Animation2DStateMachineRuntime.ts +0 -141
  143. package/src/animation/Animation2DStateMachineSystem.ts +0 -60
  144. package/src/animation/Animation2DStateMachineVisualRuntime.ts +0 -282
  145. package/src/animation/Animation2DSystem.ts +0 -72
  146. package/src/animation/AnimationAssetLoader.ts +0 -84
  147. package/src/animation/AnimationAudioClip.ts +0 -140
  148. package/src/animation/AnimationPathTessellator.ts +0 -691
  149. package/src/animation/AnimationTextRasterizer.ts +0 -340
  150. package/src/animation/AnimationVisual2D.ts +0 -153
  151. package/src/animation/HyaAnimation2DClipAdapter.ts +0 -845
  152. package/src/animation/Particle2DDescriptorAdapter.ts +0 -35
  153. package/src/animation/runtime/mixer/Action.ts +0 -876
  154. package/src/animation/runtime/mixer/Mixer.ts +0 -505
  155. package/src/animation/runtime/mixer/PoseBuffer.ts +0 -105
  156. package/src/animation/runtime/mixer/Sampler.ts +0 -252
  157. package/src/animation/runtime/mixer/Types.ts +0 -138
  158. package/src/animation/runtime/mixer/index.ts +0 -31
  159. package/src/animation-state-machine/AnimationStateMachine.ts +0 -146
  160. package/src/animation-state-machine/AnimationStateMachineChannels.ts +0 -116
  161. package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +0 -197
  162. package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +0 -503
  163. package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +0 -763
  164. package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +0 -987
  165. package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +0 -54
  166. package/src/animation-state-machine/runtime/index.ts +0 -47
  167. package/src/animation.ts +0 -33
  168. package/src/animation3d/Animation3DAction.ts +0 -73
  169. package/src/animation3d/Animation3DBinding.ts +0 -116
  170. package/src/animation3d/Animation3DClip.ts +0 -22
  171. package/src/animation3d/Animation3DError.ts +0 -34
  172. package/src/animation3d/Animation3DMixer.ts +0 -82
  173. package/src/animation3d/Animation3DPose.ts +0 -100
  174. package/src/animation3d/Animation3DPoseBuffer.ts +0 -85
  175. package/src/animation3d/Animation3DResource.ts +0 -49
  176. package/src/animation3d/Animation3DStateMachine.ts +0 -126
  177. package/src/animation3d/Animation3DStateMachineRuntime.ts +0 -191
  178. package/src/animation3d/Animation3DTrack.ts +0 -29
  179. package/src/animation3d/hya/HyaAnimation3DRuntime.ts +0 -756
  180. package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +0 -618
  181. package/src/animation3d/hya/HyaAnimation3DTypes.ts +0 -168
  182. package/src/animation3d/hya/index.ts +0 -10
  183. package/src/animation3d/index.ts +0 -76
  184. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +0 -325
  185. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +0 -158
  186. package/src/animation3d/runtime/integration/index.ts +0 -9
  187. package/src/animation3d/runtime/mixer/Action.ts +0 -833
  188. package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +0 -26
  189. package/src/animation3d/runtime/mixer/Mixer.ts +0 -562
  190. package/src/animation3d/runtime/mixer/PoseBuffer.ts +0 -1
  191. package/src/animation3d/runtime/mixer/TrackSampler.ts +0 -399
  192. package/src/animation3d/runtime/mixer/index.ts +0 -8
  193. package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +0 -4
  194. package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +0 -1
  195. package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +0 -1
  196. package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +0 -1
  197. package/src/animation3d/runtime/state-machine/index.ts +0 -45
  198. package/src/animation3d.ts +0 -5
  199. package/src/benchmark.ts +0 -168
  200. package/src/canvas-text/CanvasText2DRenderSystem.ts +0 -292
  201. package/src/canvas-text/CanvasTextComponent.ts +0 -47
  202. package/src/canvas-text.ts +0 -4
  203. package/src/experimental-gltf-worker.ts +0 -18
  204. package/src/experimental-spine-worker.ts +0 -9
  205. package/src/gltf/GltfAccessorReader.ts +0 -271
  206. package/src/gltf/GltfAnimation3DAdapter.ts +0 -680
  207. package/src/gltf/GltfAnimationRuntime.ts +0 -392
  208. package/src/gltf/GltfAssetWorkerClient.ts +0 -136
  209. package/src/gltf/GltfCompatibilityReport.ts +0 -214
  210. package/src/gltf/GltfConservativeBounds.ts +0 -219
  211. package/src/gltf/GltfDracoDecoder.ts +0 -251
  212. package/src/gltf/GltfExtensionAdapter.ts +0 -340
  213. package/src/gltf/GltfLoaderContract.ts +0 -333
  214. package/src/gltf/GltfLoaderErrors.ts +0 -59
  215. package/src/gltf/GltfMaterialDescriptor.ts +0 -134
  216. package/src/gltf/GltfMaterialEncoder.ts +0 -173
  217. package/src/gltf/GltfMaterialLoader.ts +0 -293
  218. package/src/gltf/GltfModelComponent.ts +0 -115
  219. package/src/gltf/GltfModelSystem.ts +0 -208
  220. package/src/gltf/GltfPlugin.ts +0 -84
  221. package/src/gltf/GltfSchema.ts +0 -229
  222. package/src/gltf/GltfUvSemanticPlanner.ts +0 -166
  223. package/src/gltf/gltfLoader.ts +0 -910
  224. package/src/gltf-animation3d.ts +0 -10
  225. package/src/gltf-worker-runtime.ts +0 -10
  226. package/src/gltf.ts +0 -56
  227. package/src/grid/Grid2DComponent.ts +0 -69
  228. package/src/grid.ts +0 -2
  229. package/src/hya-state-machine.ts +0 -19
  230. package/src/index.ts +0 -2
  231. package/src/plugins/pluginUtils.ts +0 -50
  232. package/src/plugins.ts +0 -6
  233. package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +0 -242
  234. package/src/shaders/generated/2d-ui-artifact.generated.ts +0 -867
  235. package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +0 -38
  236. package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +0 -41
  237. package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +0 -36
  238. package/src/spine/Spine2DComponent.ts +0 -168
  239. package/src/spine/Spine2DGpuRenderer.ts +0 -449
  240. package/src/spine/Spine2DRenderSystem.ts +0 -199
  241. package/src/spine/Spine2DRuntime.ts +0 -1529
  242. package/src/spine/SpineAnimationBoneTimelines.ts +0 -30
  243. package/src/spine/SpineAssetParser.ts +0 -20
  244. package/src/spine/SpineAssetWorkerClient.ts +0 -112
  245. package/src/spine/SpineAssetWorkerContract.ts +0 -4
  246. package/src/spine/SpineAtlasParser.ts +0 -127
  247. package/src/spine/SpineFloatBuilder.ts +0 -66
  248. package/src/spine/SpinePathConstraintSolver.ts +0 -582
  249. package/src/spine/SpinePlugin.ts +0 -76
  250. package/src/spine/SpineSkeletonRuntime.ts +0 -521
  251. package/src/spine/SpineSlotAnimation.ts +0 -195
  252. package/src/spine/SpineTimelineRuntime.ts +0 -453
  253. package/src/spine/SpineVertexBuilder.ts +0 -686
  254. package/src/spine.ts +0 -7
  255. package/src/tilemap/Tilemap2DComponent.ts +0 -232
  256. package/src/tilemap/Tilemap2DRenderSystem.ts +0 -58
  257. package/src/tilemap/Tilemap2DRenderer.ts +0 -289
  258. package/src/tilemap/TilemapPlugin.ts +0 -75
  259. package/src/tilemap.ts +0 -6
  260. package/src/tween/Tween2DComponent.ts +0 -83
  261. package/src/tween/Tween2DSystem.ts +0 -78
  262. package/src/tween.ts +0 -4
  263. package/src/types/earcut.d.ts +0 -7
  264. package/src/types/wgsl.d.ts +0 -4
  265. package/src/utils/RenderSystem2DBase.ts +0 -164
  266. package/src/utils/arrayAccess.ts +0 -17
  267. package/src/utils/camera2d.ts +0 -68
  268. package/src/utils/render2dGpu.ts +0 -132
  269. package/test/fixtures/gltf/animation-characterization.gltf +0 -344
@@ -1,582 +0,0 @@
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
- }
@@ -1,76 +0,0 @@
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
- }