@safe-engine/pixi 8.4.7 → 8.5.1

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 (92) hide show
  1. package/README.md +14 -23
  2. package/dist/box2d-wasm/ContactListener.d.ts +1 -1
  3. package/dist/box2d-wasm/ContactListener.d.ts.map +1 -1
  4. package/dist/box2d-wasm/ContactListener.js +50 -18
  5. package/dist/box2d-wasm/PhysicsComponent.d.ts +27 -30
  6. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  7. package/dist/box2d-wasm/PhysicsComponent.js +44 -11
  8. package/dist/box2d-wasm/PhysicsSprite.d.ts +3 -0
  9. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  10. package/dist/box2d-wasm/PhysicsSprite.js +24 -3
  11. package/dist/box2d-wasm/PhysicsSystem.d.ts +4 -2
  12. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  13. package/dist/box2d-wasm/PhysicsSystem.js +134 -44
  14. package/dist/collider/CollideComponent.d.ts +27 -10
  15. package/dist/collider/CollideComponent.d.ts.map +1 -1
  16. package/dist/collider/CollideComponent.js +10 -12
  17. package/dist/collider/helper/Intersection.d.ts +6 -6
  18. package/dist/collider/helper/Intersection.d.ts.map +1 -1
  19. package/dist/collider/helper/Intersection.js +4 -4
  20. package/dist/helper/utils.d.ts +0 -6
  21. package/dist/helper/utils.d.ts.map +1 -1
  22. package/dist/helper/utils.js +0 -12
  23. package/package.json +6 -2
  24. package/.github/workflows/npm-publish.yml +0 -35
  25. package/dist/@types/safex.d.ts +0 -15
  26. package/src/@types/index.d.ts +0 -2
  27. package/src/app.ts +0 -91
  28. package/src/base/EnhancedComponent.ts +0 -38
  29. package/src/base/gworld.ts +0 -20
  30. package/src/base/index.ts +0 -14
  31. package/src/base/utils.ts +0 -23
  32. package/src/box2d-wasm/ContactListener.ts +0 -66
  33. package/src/box2d-wasm/PhysicsComponent.ts +0 -83
  34. package/src/box2d-wasm/PhysicsSprite.ts +0 -42
  35. package/src/box2d-wasm/PhysicsSystem.ts +0 -142
  36. package/src/box2d-wasm/debugDraw.ts +0 -249
  37. package/src/box2d-wasm/index.ts +0 -19
  38. package/src/collider/CollideComponent.ts +0 -257
  39. package/src/collider/CollideSystem.ts +0 -166
  40. package/src/collider/helper/Intersection.ts +0 -139
  41. package/src/collider/helper/utils.ts +0 -37
  42. package/src/collider/index.ts +0 -16
  43. package/src/components/BaseComponent.ts +0 -17
  44. package/src/components/NodeComp.ts +0 -442
  45. package/src/components/Scene.ts +0 -17
  46. package/src/core/Color.ts +0 -7
  47. package/src/core/LoadingBar.ts +0 -63
  48. package/src/core/NodePool.ts +0 -28
  49. package/src/core/Size.ts +0 -21
  50. package/src/core/Vec2.ts +0 -108
  51. package/src/core/director.ts +0 -11
  52. package/src/core/index.ts +0 -7
  53. package/src/core/loader.ts +0 -14
  54. package/src/core/math.ts +0 -22
  55. package/src/dragonbones/DragonBonesComponent.ts +0 -32
  56. package/src/dragonbones/DragonBonesSystem.ts +0 -35
  57. package/src/dragonbones/index.ts +0 -11
  58. package/src/gui/GUIComponent.ts +0 -155
  59. package/src/gui/GUISystem.ts +0 -125
  60. package/src/helper/utils.ts +0 -50
  61. package/src/index.ts +0 -21
  62. package/src/norender/NoRenderComponent.ts +0 -60
  63. package/src/norender/NoRenderSystem.ts +0 -67
  64. package/src/norender/Touch.ts +0 -37
  65. package/src/planck/PhysicsComponent.ts +0 -83
  66. package/src/planck/PhysicsSprite.ts +0 -43
  67. package/src/planck/PhysicsSystem.ts +0 -201
  68. package/src/planck/index.ts +0 -3
  69. package/src/render/RenderComponent.ts +0 -132
  70. package/src/render/RenderSystem.ts +0 -64
  71. package/src/richtext/RichTextComp.ts +0 -50
  72. package/src/richtext/RichTextSystem.ts +0 -26
  73. package/src/richtext/html-text-parser.ts +0 -87
  74. package/src/richtext/index.ts +0 -8
  75. package/src/spine/SpineComponent.ts +0 -18
  76. package/src/spine/SpineSystem.ts +0 -30
  77. package/src/spine/index.ts +0 -11
  78. package/src/spine/lib/BatchableSpineSlot.ts +0 -138
  79. package/src/spine/lib/Spine.ts +0 -894
  80. package/src/spine/lib/SpineDebugRenderer.ts +0 -615
  81. package/src/spine/lib/SpinePipe.ts +0 -203
  82. package/src/spine/lib/SpineTexture.ts +0 -143
  83. package/src/spine/lib/assets/atlasLoader.ts +0 -158
  84. package/src/spine/lib/assets/skeletonLoader.ts +0 -81
  85. package/src/spine/lib/darktint/DarkTintBatchGeometry.ts +0 -92
  86. package/src/spine/lib/darktint/DarkTintBatcher.ts +0 -186
  87. package/src/spine/lib/darktint/DarkTintShader.ts +0 -74
  88. package/src/spine/lib/darktint/darkTintBit.ts +0 -77
  89. package/src/spine/lib/index.ts +0 -43
  90. package/src/spine/lib/require-shim.ts +0 -43
  91. package/tsconfig.json +0 -18
  92. /package/{dist/@types → @types}/index.d.ts +0 -0
@@ -1,615 +0,0 @@
1
- /** ****************************************************************************
2
- * Spine Runtimes License Agreement
3
- * Last updated July 28, 2023. Replaces all prior versions.
4
- *
5
- * Copyright (c) 2013-2023, Esoteric Software LLC
6
- *
7
- * Integration of the Spine Runtimes into software or otherwise creating
8
- * derivative works of the Spine Runtimes is permitted under the terms and
9
- * conditions of Section 2 of the Spine Editor License Agreement:
10
- * http://esotericsoftware.com/spine-editor-license
11
- *
12
- * Otherwise, it is permitted to integrate the Spine Runtimes into software or
13
- * otherwise create derivative works of the Spine Runtimes (collectively,
14
- * "Products"), provided that each user of the Products must obtain their own
15
- * Spine Editor license and redistribution of the Products in any form must
16
- * include this license and copyright notice.
17
- *
18
- * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
19
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
- * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
22
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
24
- * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
25
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE
27
- * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
- *****************************************************************************/
29
-
30
- import { Container, Graphics, Text } from 'pixi.js';
31
- import { Spine } from './Spine.js';
32
- import {
33
- ClippingAttachment,
34
- MeshAttachment,
35
- PathAttachment,
36
- RegionAttachment,
37
- SkeletonBounds
38
- } from '@esotericsoftware/spine-core';
39
-
40
- import type { AnimationStateListener } from '@esotericsoftware/spine-core';
41
-
42
- /**
43
- * Make a class that extends from this interface to create your own debug renderer.
44
- * @public
45
- */
46
- export interface ISpineDebugRenderer {
47
- /**
48
- * This will be called every frame, after the spine has been updated.
49
- */
50
- renderDebug: (spine: Spine) => void;
51
-
52
- /**
53
- * This is called when the `spine.debug` object is set to null or when the spine is destroyed.
54
- */
55
- unregisterSpine: (spine: Spine) => void;
56
-
57
- /**
58
- * This is called when the `spine.debug` object is set to a new instance of a debug renderer.
59
- */
60
- registerSpine: (spine: Spine) => void;
61
- }
62
-
63
- type DebugDisplayObjects = {
64
- bones: Container;
65
- skeletonXY: Graphics;
66
- regionAttachmentsShape: Graphics;
67
- meshTrianglesLine: Graphics;
68
- meshHullLine: Graphics;
69
- clippingPolygon: Graphics;
70
- boundingBoxesRect: Graphics;
71
- boundingBoxesCircle: Graphics;
72
- boundingBoxesPolygon: Graphics;
73
- pathsCurve: Graphics;
74
- pathsLine: Graphics;
75
- parentDebugContainer: Container;
76
- eventText: Container;
77
- eventCallback: AnimationStateListener;
78
- };
79
-
80
- /**
81
- * This is a debug renderer that uses PixiJS Graphics under the hood.
82
- * @public
83
- */
84
- export class SpineDebugRenderer implements ISpineDebugRenderer {
85
- private readonly registeredSpines: Map<Spine, DebugDisplayObjects> = new Map();
86
-
87
- public drawMeshHull = true;
88
- public drawMeshTriangles = true;
89
- public drawBones = true;
90
- public drawPaths = true;
91
- public drawBoundingBoxes = true;
92
- public drawClipping = true;
93
- public drawRegionAttachments = true;
94
- public drawEvents = true;
95
-
96
- public lineWidth = 1;
97
- public regionAttachmentsColor = 0x0078ff;
98
- public meshHullColor = 0x0078ff;
99
- public meshTrianglesColor = 0xffcc00;
100
- public clippingPolygonColor = 0xff00ff;
101
- public boundingBoxesRectColor = 0x00ff00;
102
- public boundingBoxesPolygonColor = 0x00ff00;
103
- public boundingBoxesCircleColor = 0x00ff00;
104
- public pathsCurveColor = 0xff0000;
105
- public pathsLineColor = 0xff00ff;
106
- public skeletonXYColor = 0xff0000;
107
- public bonesColor = 0x00eecc;
108
- public eventFontSize = 24;
109
- public eventFontColor = 0x0;
110
-
111
- /**
112
- * The debug is attached by force to each spine object.
113
- * So we need to create it inside the spine when we get the first update
114
- */
115
- public registerSpine (spine: Spine): void {
116
- if (this.registeredSpines.has(spine)) {
117
- console.warn('SpineDebugRenderer.registerSpine() - this spine is already registered!', spine);
118
-
119
- return;
120
- }
121
- const debugDisplayObjects: DebugDisplayObjects = {
122
- parentDebugContainer: new Container(),
123
- bones: new Container(),
124
- skeletonXY: new Graphics(),
125
- regionAttachmentsShape: new Graphics(),
126
- meshTrianglesLine: new Graphics(),
127
- meshHullLine: new Graphics(),
128
- clippingPolygon: new Graphics(),
129
- boundingBoxesRect: new Graphics(),
130
- boundingBoxesCircle: new Graphics(),
131
- boundingBoxesPolygon: new Graphics(),
132
- pathsCurve: new Graphics(),
133
- pathsLine: new Graphics(),
134
- eventText: new Container(),
135
- eventCallback: {
136
- event: (_, event) => {
137
- if (this.drawEvents) {
138
- const scale = Math.abs(spine.scale.x || spine.scale.y || 1);
139
- const text = new Text({
140
- text: event.data.name,
141
- style: {
142
- fontSize: this.eventFontSize / scale,
143
- fill: this.eventFontColor,
144
- fontFamily: 'monospace'
145
- }
146
- });
147
-
148
- text.scale.x = Math.sign(spine.scale.x);
149
- text.anchor.set(0.5);
150
- debugDisplayObjects.eventText.addChild(text);
151
- setTimeout(() => {
152
- if (!text.destroyed) {
153
- text.destroy();
154
- }
155
- }, 250);
156
- }
157
- },
158
- },
159
- };
160
-
161
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.bones);
162
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.skeletonXY);
163
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.regionAttachmentsShape);
164
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.meshTrianglesLine);
165
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.meshHullLine);
166
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.clippingPolygon);
167
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.boundingBoxesRect);
168
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.boundingBoxesCircle);
169
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.boundingBoxesPolygon);
170
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.pathsCurve);
171
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.pathsLine);
172
- debugDisplayObjects.parentDebugContainer.addChild(debugDisplayObjects.eventText);
173
-
174
- (debugDisplayObjects.parentDebugContainer as any).zIndex = 9999999;
175
-
176
- // Disable screen reader and mouse input on debug objects.
177
- (debugDisplayObjects.parentDebugContainer as any).accessibleChildren = false;
178
- (debugDisplayObjects.parentDebugContainer as any).eventMode = 'none';
179
- (debugDisplayObjects.parentDebugContainer as any).interactiveChildren = false;
180
-
181
- spine.addChild(debugDisplayObjects.parentDebugContainer);
182
-
183
- spine.state.addListener(debugDisplayObjects.eventCallback);
184
-
185
- this.registeredSpines.set(spine, debugDisplayObjects);
186
- }
187
-
188
- public renderDebug (spine: Spine): void {
189
- if (!this.registeredSpines.has(spine)) {
190
- // This should never happen. Spines are registered when you assign spine.debug
191
- this.registerSpine(spine);
192
- }
193
-
194
- const debugDisplayObjects = this.registeredSpines.get(spine);
195
-
196
- if (!debugDisplayObjects) {
197
- return;
198
- }
199
- spine.addChild(debugDisplayObjects.parentDebugContainer);
200
-
201
- debugDisplayObjects.skeletonXY.clear();
202
- debugDisplayObjects.regionAttachmentsShape.clear();
203
- debugDisplayObjects.meshTrianglesLine.clear();
204
- debugDisplayObjects.meshHullLine.clear();
205
- debugDisplayObjects.clippingPolygon.clear();
206
- debugDisplayObjects.boundingBoxesRect.clear();
207
- debugDisplayObjects.boundingBoxesCircle.clear();
208
- debugDisplayObjects.boundingBoxesPolygon.clear();
209
- debugDisplayObjects.pathsCurve.clear();
210
- debugDisplayObjects.pathsLine.clear();
211
-
212
- for (let len = debugDisplayObjects.bones.children.length; len > 0; len--) {
213
- debugDisplayObjects.bones.children[len - 1].destroy({ children: true, texture: true, textureSource: true });
214
- }
215
-
216
- const scale = Math.abs(spine.scale.x || spine.scale.y || 1);
217
- const lineWidth = this.lineWidth / scale;
218
-
219
- if (this.drawBones) {
220
- this.drawBonesFunc(spine, debugDisplayObjects, lineWidth, scale);
221
- }
222
-
223
- if (this.drawPaths) {
224
- this.drawPathsFunc(spine, debugDisplayObjects, lineWidth);
225
- }
226
-
227
- if (this.drawBoundingBoxes) {
228
- this.drawBoundingBoxesFunc(spine, debugDisplayObjects, lineWidth);
229
- }
230
-
231
- if (this.drawClipping) {
232
- this.drawClippingFunc(spine, debugDisplayObjects, lineWidth);
233
- }
234
-
235
- if (this.drawMeshHull || this.drawMeshTriangles) {
236
- this.drawMeshHullAndMeshTriangles(spine, debugDisplayObjects, lineWidth);
237
- }
238
-
239
- if (this.drawRegionAttachments) {
240
- this.drawRegionAttachmentsFunc(spine, debugDisplayObjects, lineWidth);
241
- }
242
-
243
- if (this.drawEvents) {
244
- for (const child of debugDisplayObjects.eventText.children) {
245
- child.alpha -= 0.05;
246
- child.y -= 2;
247
- }
248
- }
249
- }
250
-
251
- private drawBonesFunc (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number, scale: number): void {
252
- const skeleton = spine.skeleton;
253
- const skeletonX = skeleton.x;
254
- const skeletonY = skeleton.y;
255
- const bones = skeleton.bones;
256
-
257
- debugDisplayObjects.skeletonXY.strokeStyle = { width: lineWidth, color: this.skeletonXYColor };
258
-
259
- for (let i = 0, len = bones.length; i < len; i++) {
260
- const bone = bones[i];
261
- const boneLen = bone.data.length;
262
- const starX = skeletonX + bone.worldX;
263
- const starY = skeletonY + bone.worldY;
264
- const endX = skeletonX + (boneLen * bone.a) + bone.worldX;
265
- const endY = skeletonY + (boneLen * bone.b) + bone.worldY;
266
-
267
- if (bone.data.name === 'root' || bone.data.parent === null) {
268
- continue;
269
- }
270
-
271
- const w = Math.abs(starX - endX);
272
- const h = Math.abs(starY - endY);
273
- // a = w, // side length a
274
- const a2 = Math.pow(w, 2); // square root of side length a
275
- const b = h; // side length b
276
- const b2 = Math.pow(h, 2); // square root of side length b
277
- const c = Math.sqrt(a2 + b2); // side length c
278
- const c2 = Math.pow(c, 2); // square root of side length c
279
- const rad = Math.PI / 180;
280
- // A = Math.acos([a2 + c2 - b2] / [2 * a * c]) || 0, // Angle A
281
- // C = Math.acos([a2 + b2 - c2] / [2 * a * b]) || 0, // C angle
282
- const B = Math.acos((c2 + b2 - a2) / (2 * b * c)) || 0; // angle of corner B
283
-
284
- if (c === 0) {
285
- continue;
286
- }
287
-
288
- const gp = new Graphics();
289
-
290
- debugDisplayObjects.bones.addChild(gp);
291
-
292
- // draw bone
293
- const refRation = c / 50 / scale;
294
-
295
- gp.context
296
- .poly([0, 0, 0 - refRation, c - (refRation * 3), 0, c - refRation, 0 + refRation, c - (refRation * 3)])
297
- .fill(this.bonesColor);
298
- gp.x = starX;
299
- gp.y = starY;
300
- gp.pivot.y = c;
301
-
302
- // Calculate bone rotation angle
303
- let rotation = 0;
304
-
305
- if (starX < endX && starY < endY) {
306
- // bottom right
307
- rotation = -B + (180 * rad);
308
- }
309
- else if (starX > endX && starY < endY) {
310
- // bottom left
311
- rotation = (180 * rad) + B;
312
- }
313
- else if (starX > endX && starY > endY) {
314
- // top left
315
- rotation = -B;
316
- }
317
- else if (starX < endX && starY > endY) {
318
- // bottom left
319
- rotation = B;
320
- }
321
- else if (starY === endY && starX < endX) {
322
- // To the right
323
- rotation = 90 * rad;
324
- }
325
- else if (starY === endY && starX > endX) {
326
- // go left
327
- rotation = -90 * rad;
328
- }
329
- else if (starX === endX && starY < endY) {
330
- // down
331
- rotation = 180 * rad;
332
- }
333
- else if (starX === endX && starY > endY) {
334
- // up
335
- rotation = 0;
336
- }
337
- gp.rotation = rotation;
338
-
339
- // Draw the starting rotation point of the bone
340
- gp.circle(0, c, refRation * 1.2)
341
- .fill({ color: 0x000000, alpha: 0.6 })
342
- .stroke({ width: lineWidth + refRation / 2.4, color: this.bonesColor });
343
- }
344
-
345
- // Draw the skeleton starting point "X" form
346
- const startDotSize = lineWidth * 3;
347
-
348
- debugDisplayObjects.skeletonXY.context
349
- .moveTo(skeletonX - startDotSize, skeletonY - startDotSize)
350
- .lineTo(skeletonX + startDotSize, skeletonY + startDotSize)
351
- .moveTo(skeletonX + startDotSize, skeletonY - startDotSize)
352
- .lineTo(skeletonX - startDotSize, skeletonY + startDotSize)
353
- .stroke();
354
- }
355
-
356
- private drawRegionAttachmentsFunc (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number): void {
357
- const skeleton = spine.skeleton;
358
- const slots = skeleton.slots;
359
-
360
- for (let i = 0, len = slots.length; i < len; i++) {
361
- const slot = slots[i];
362
- const attachment = slot.getAttachment();
363
-
364
- if (attachment === null || !(attachment instanceof RegionAttachment)) {
365
- continue;
366
- }
367
-
368
- const regionAttachment = attachment;
369
-
370
- const vertices = new Float32Array(8);
371
-
372
- regionAttachment.computeWorldVertices(slot, vertices, 0, 2);
373
-
374
- debugDisplayObjects.regionAttachmentsShape.poly(Array.from(vertices.slice(0, 8)));
375
- }
376
-
377
- debugDisplayObjects.regionAttachmentsShape.stroke({
378
- color: this.regionAttachmentsColor,
379
- width: lineWidth
380
- });
381
- }
382
-
383
- private drawMeshHullAndMeshTriangles (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number): void {
384
- const skeleton = spine.skeleton;
385
- const slots = skeleton.slots;
386
-
387
- for (let i = 0, len = slots.length; i < len; i++) {
388
- const slot = slots[i];
389
-
390
- if (!slot.bone.active) {
391
- continue;
392
- }
393
- const attachment = slot.getAttachment();
394
-
395
- if (attachment === null || !(attachment instanceof MeshAttachment)) {
396
- continue;
397
- }
398
-
399
- const meshAttachment = attachment;
400
-
401
- const vertices = new Float32Array(meshAttachment.worldVerticesLength);
402
- const triangles = meshAttachment.triangles;
403
- let hullLength = meshAttachment.hullLength;
404
-
405
- meshAttachment.computeWorldVertices(slot, 0, meshAttachment.worldVerticesLength, vertices, 0, 2);
406
- // draw the skinned mesh (triangle)
407
- if (this.drawMeshTriangles) {
408
- for (let i = 0, len = triangles.length; i < len; i += 3) {
409
- const v1 = triangles[i] * 2;
410
- const v2 = triangles[i + 1] * 2;
411
- const v3 = triangles[i + 2] * 2;
412
-
413
- debugDisplayObjects.meshTrianglesLine.context
414
- .moveTo(vertices[v1], vertices[v1 + 1])
415
- .lineTo(vertices[v2], vertices[v2 + 1])
416
- .lineTo(vertices[v3], vertices[v3 + 1]);
417
- }
418
- }
419
-
420
- // draw skin border
421
- if (this.drawMeshHull && hullLength > 0) {
422
- hullLength = (hullLength >> 1) * 2;
423
- let lastX = vertices[hullLength - 2];
424
- let lastY = vertices[hullLength - 1];
425
-
426
- for (let i = 0, len = hullLength; i < len; i += 2) {
427
- const x = vertices[i];
428
- const y = vertices[i + 1];
429
-
430
- debugDisplayObjects.meshHullLine.context
431
- .moveTo(x, y)
432
- .lineTo(lastX, lastY);
433
- lastX = x;
434
- lastY = y;
435
- }
436
- }
437
- }
438
-
439
- debugDisplayObjects.meshHullLine.stroke({ width: lineWidth, color: this.meshHullColor });
440
- debugDisplayObjects.meshTrianglesLine.stroke({ width: lineWidth, color: this.meshTrianglesColor });
441
- }
442
-
443
- drawClippingFunc (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number): void {
444
- const skeleton = spine.skeleton;
445
- const slots = skeleton.slots;
446
-
447
- for (let i = 0, len = slots.length; i < len; i++) {
448
- const slot = slots[i];
449
-
450
- if (!slot.bone.active) {
451
- continue;
452
- }
453
- const attachment = slot.getAttachment();
454
-
455
- if (attachment === null || !(attachment instanceof ClippingAttachment)) {
456
- continue;
457
- }
458
-
459
- const clippingAttachment = attachment;
460
-
461
- const nn = clippingAttachment.worldVerticesLength;
462
- const world = new Float32Array(nn);
463
-
464
- clippingAttachment.computeWorldVertices(slot, 0, nn, world, 0, 2);
465
- debugDisplayObjects.clippingPolygon.poly(Array.from(world));
466
- }
467
-
468
- debugDisplayObjects.clippingPolygon.stroke({
469
- width: lineWidth, color: this.clippingPolygonColor, alpha: 1
470
- });
471
- }
472
-
473
- drawBoundingBoxesFunc (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number): void {
474
- // draw the total outline of the bounding box
475
- const bounds = new SkeletonBounds();
476
- bounds.update(spine.skeleton, true);
477
-
478
- if (bounds.minX !== Infinity) {
479
- debugDisplayObjects.boundingBoxesRect
480
- .rect(bounds.minX, bounds.minY, bounds.getWidth(), bounds.getHeight())
481
- .stroke({ width: lineWidth, color: this.boundingBoxesRectColor });
482
- }
483
-
484
- const polygons = bounds.polygons;
485
- const drawPolygon = (polygonVertices: ArrayLike<number>, _offset: unknown, count: number): void => {
486
- if (count < 3) {
487
- throw new Error('Polygon must contain at least 3 vertices');
488
- }
489
- const paths: number[] = [];
490
- const dotSize = lineWidth * 2;
491
-
492
- for (let i = 0, len = polygonVertices.length; i < len; i += 2) {
493
- const x1 = polygonVertices[i];
494
- const y1 = polygonVertices[i + 1];
495
-
496
- // draw the bounding box node
497
- debugDisplayObjects.boundingBoxesCircle.beginFill(this.boundingBoxesCircleColor);
498
- debugDisplayObjects.boundingBoxesCircle.drawCircle(x1, y1, dotSize);
499
- debugDisplayObjects.boundingBoxesCircle.fill(0);
500
-
501
- debugDisplayObjects.boundingBoxesCircle
502
- .circle(x1, y1, dotSize)
503
- .fill({ color: this.boundingBoxesCircleColor })
504
-
505
- paths.push(x1, y1);
506
- }
507
-
508
- // draw the bounding box area
509
- debugDisplayObjects.boundingBoxesPolygon
510
- .poly(paths)
511
- .fill({
512
- color: this.boundingBoxesPolygonColor,
513
- alpha: 0.1
514
- })
515
- .stroke({
516
- width: lineWidth,
517
- color: this.boundingBoxesPolygonColor
518
- });
519
- };
520
-
521
- for (let i = 0, len = polygons.length; i < len; i++) {
522
- const polygon = polygons[i];
523
-
524
- drawPolygon(polygon, 0, polygon.length);
525
- }
526
- }
527
-
528
- private drawPathsFunc (spine: Spine, debugDisplayObjects: DebugDisplayObjects, lineWidth: number): void {
529
- const skeleton = spine.skeleton;
530
- const slots = skeleton.slots;
531
-
532
- for (let i = 0, len = slots.length; i < len; i++) {
533
- const slot = slots[i];
534
-
535
- if (!slot.bone.active) {
536
- continue;
537
- }
538
- const attachment = slot.getAttachment();
539
-
540
- if (attachment === null || !(attachment instanceof PathAttachment)) {
541
- continue;
542
- }
543
-
544
- const pathAttachment = attachment;
545
- let nn = pathAttachment.worldVerticesLength;
546
- const world = new Float32Array(nn);
547
-
548
- pathAttachment.computeWorldVertices(slot, 0, nn, world, 0, 2);
549
- let x1 = world[2];
550
- let y1 = world[3];
551
- let x2 = 0;
552
- let y2 = 0;
553
-
554
- if (pathAttachment.closed) {
555
- const cx1 = world[0];
556
- const cy1 = world[1];
557
- const cx2 = world[nn - 2];
558
- const cy2 = world[nn - 1];
559
-
560
- x2 = world[nn - 4];
561
- y2 = world[nn - 3];
562
-
563
- // curve
564
- debugDisplayObjects.pathsCurve.moveTo(x1, y1);
565
- debugDisplayObjects.pathsCurve.bezierCurveTo(cx1, cy1, cx2, cy2, x2, y2);
566
-
567
- // handle
568
- debugDisplayObjects.pathsLine.moveTo(x1, y1);
569
- debugDisplayObjects.pathsLine.lineTo(cx1, cy1);
570
- debugDisplayObjects.pathsLine.moveTo(x2, y2);
571
- debugDisplayObjects.pathsLine.lineTo(cx2, cy2);
572
- }
573
- nn -= 4;
574
- for (let ii = 4; ii < nn; ii += 6) {
575
- const cx1 = world[ii];
576
- const cy1 = world[ii + 1];
577
- const cx2 = world[ii + 2];
578
- const cy2 = world[ii + 3];
579
-
580
- x2 = world[ii + 4];
581
- y2 = world[ii + 5];
582
- // curve
583
- debugDisplayObjects.pathsCurve.moveTo(x1, y1);
584
- debugDisplayObjects.pathsCurve.bezierCurveTo(cx1, cy1, cx2, cy2, x2, y2);
585
-
586
- // handle
587
- debugDisplayObjects.pathsLine.moveTo(x1, y1);
588
- debugDisplayObjects.pathsLine.lineTo(cx1, cy1);
589
- debugDisplayObjects.pathsLine.moveTo(x2, y2);
590
- debugDisplayObjects.pathsLine.lineTo(cx2, cy2);
591
- x1 = x2;
592
- y1 = y2;
593
- }
594
- }
595
-
596
- debugDisplayObjects.pathsCurve.stroke({ width: lineWidth, color: this.pathsCurveColor });
597
- debugDisplayObjects.pathsLine.stroke({ width: lineWidth, color: this.pathsLineColor });
598
- }
599
-
600
- public unregisterSpine (spine: Spine): void {
601
- if (!this.registeredSpines.has(spine)) {
602
- console.warn('SpineDebugRenderer.unregisterSpine() - spine is not registered, can\'t unregister!', spine);
603
- }
604
- const debugDisplayObjects = this.registeredSpines.get(spine);
605
-
606
- if (!debugDisplayObjects) {
607
- return;
608
- }
609
-
610
- spine.state.removeListener(debugDisplayObjects.eventCallback);
611
-
612
- debugDisplayObjects.parentDebugContainer.destroy({ textureSource: true, children: true, texture: true });
613
- this.registeredSpines.delete(spine);
614
- }
615
- }