@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,203 +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 {
31
- collectAllRenderables,
32
- extensions, ExtensionType,
33
- InstructionSet,
34
- type BLEND_MODES,
35
- type Container,
36
- type Renderer,
37
- type RenderPipe,
38
- } from 'pixi.js';
39
- import { BatchableSpineSlot } from './BatchableSpineSlot.js';
40
- import { Spine } from './Spine.js';
41
- import { MeshAttachment, RegionAttachment } from '@esotericsoftware/spine-core';
42
-
43
- const spineBlendModeMap: Record<number, BLEND_MODES> = {
44
- 0: 'normal',
45
- 1: 'add',
46
- 2: 'multiply',
47
- 3: 'screen'
48
- };
49
-
50
- type GpuSpineDataElement = { slotBatches: Record<string, BatchableSpineSlot> };
51
-
52
- // eslint-disable-next-line max-len
53
- export class SpinePipe implements RenderPipe<Spine> {
54
- /** @ignore */
55
- static extension = {
56
- type: [
57
- ExtensionType.WebGLPipes,
58
- ExtensionType.WebGPUPipes,
59
- ExtensionType.CanvasPipes,
60
- ],
61
- name: 'spine',
62
- } as const;
63
-
64
- renderer: Renderer;
65
-
66
- private gpuSpineData: Record<string, GpuSpineDataElement> = {};
67
- private readonly _destroyRenderableBound = this.destroyRenderable.bind(this) as (renderable: Container) => void;
68
-
69
- constructor (renderer: Renderer) {
70
- this.renderer = renderer;
71
- }
72
-
73
- validateRenderable (spine: Spine): boolean {
74
- spine._validateAndTransformAttachments();
75
-
76
- // if spine attachments have changed or destroyed, we need to rebuild the batch!
77
- if (spine.spineAttachmentsDirty) {
78
- return true;
79
- }
80
-
81
- // if the textures have changed, we need to rebuild the batch, but only if the texture is not already in the batch
82
- else if (spine.spineTexturesDirty) {
83
- // loop through and see if the textures have changed..
84
- const drawOrder = spine.skeleton.drawOrder;
85
- const gpuSpine = this.gpuSpineData[spine.uid];
86
-
87
- for (let i = 0, n = drawOrder.length; i < n; i++) {
88
- const slot = drawOrder[i];
89
- const attachment = slot.getAttachment();
90
-
91
- if (attachment instanceof RegionAttachment || attachment instanceof MeshAttachment) {
92
- const cacheData = spine._getCachedData(slot, attachment);
93
- const batchableSpineSlot = gpuSpine.slotBatches[cacheData.id];
94
-
95
- const texture = cacheData.texture;
96
-
97
- if (texture !== batchableSpineSlot.texture) {
98
- if (!batchableSpineSlot._batcher.checkAndUpdateTexture(batchableSpineSlot, texture)) {
99
- return true;
100
- }
101
- }
102
- }
103
- }
104
- }
105
-
106
- return false;
107
- }
108
-
109
- addRenderable (spine: Spine, instructionSet: InstructionSet) {
110
- const gpuSpine = this._getSpineData(spine);
111
-
112
- const batcher = this.renderer.renderPipes.batch;
113
-
114
- const drawOrder = spine.skeleton.drawOrder;
115
-
116
- const roundPixels = (this.renderer._roundPixels | spine._roundPixels) as 0 | 1;
117
-
118
- spine._validateAndTransformAttachments();
119
-
120
- spine.spineAttachmentsDirty = false;
121
- spine.spineTexturesDirty = false;
122
-
123
- for (let i = 0, n = drawOrder.length; i < n; i++) {
124
- const slot = drawOrder[i];
125
- const attachment = slot.getAttachment();
126
- const blendMode = spineBlendModeMap[slot.data.blendMode];
127
-
128
- if (attachment instanceof RegionAttachment || attachment instanceof MeshAttachment) {
129
- const cacheData = spine._getCachedData(slot, attachment);
130
- const batchableSpineSlot = gpuSpine.slotBatches[cacheData.id] ||= new BatchableSpineSlot();
131
-
132
- batchableSpineSlot.setData(
133
- spine,
134
- cacheData,
135
- blendMode,
136
- roundPixels
137
- );
138
-
139
- if (!cacheData.skipRender) {
140
- batcher.addToBatch(batchableSpineSlot, instructionSet);
141
- }
142
- }
143
-
144
- const containerAttachment = spine._slotsObject[slot.data.name];
145
-
146
- if (containerAttachment) {
147
- const container = containerAttachment.container;
148
-
149
- container.includeInBuild = true;
150
- collectAllRenderables(container, instructionSet, this.renderer);
151
- container.includeInBuild = false;
152
- }
153
- }
154
- }
155
-
156
- updateRenderable (spine: Spine) {
157
- const gpuSpine = this.gpuSpineData[spine.uid];
158
-
159
- spine._validateAndTransformAttachments();
160
-
161
- spine.spineAttachmentsDirty = false;
162
- spine.spineTexturesDirty = false;
163
-
164
- const drawOrder = spine.skeleton.drawOrder;
165
-
166
- for (let i = 0, n = drawOrder.length; i < n; i++) {
167
- const slot = drawOrder[i];
168
- const attachment = slot.getAttachment();
169
-
170
- if (attachment instanceof RegionAttachment || attachment instanceof MeshAttachment) {
171
- const cacheData = spine._getCachedData(slot, attachment);
172
-
173
- if (!cacheData.skipRender) {
174
- const batchableSpineSlot = gpuSpine.slotBatches[spine._getCachedData(slot, attachment).id];
175
-
176
- batchableSpineSlot._batcher?.updateElement(batchableSpineSlot);
177
- }
178
- }
179
- }
180
- }
181
-
182
- destroyRenderable (spine: Spine) {
183
- this.gpuSpineData[spine.uid] = null as any;
184
- spine.off('destroyed', this._destroyRenderableBound);
185
- }
186
-
187
- destroy () {
188
- this.gpuSpineData = null as any;
189
- this.renderer = null as any;
190
- }
191
-
192
- private _getSpineData (spine: Spine): GpuSpineDataElement {
193
- return this.gpuSpineData[spine.uid] || this._initMeshData(spine);
194
- }
195
-
196
- private _initMeshData (spine: Spine): GpuSpineDataElement {
197
- this.gpuSpineData[spine.uid] = { slotBatches: {} };
198
- spine.on('destroyed', this._destroyRenderableBound);
199
- return this.gpuSpineData[spine.uid];
200
- }
201
- }
202
-
203
- extensions.add(SpinePipe);
@@ -1,143 +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 { Texture as PixiTexture } from 'pixi.js';
31
- import { BlendMode, Texture, TextureFilter, TextureWrap } from '@esotericsoftware/spine-core';
32
-
33
- import type { BLEND_MODES, SCALE_MODE, TextureSource, WRAP_MODE } from 'pixi.js';
34
-
35
- export class SpineTexture extends Texture {
36
- private static readonly textureMap: Map<TextureSource, SpineTexture> = new Map<TextureSource, SpineTexture>();
37
-
38
- public static from (texture: TextureSource): SpineTexture {
39
- if (SpineTexture.textureMap.has(texture)) {
40
- return SpineTexture.textureMap.get(texture) as SpineTexture;
41
- }
42
-
43
- return new SpineTexture(texture);
44
- }
45
-
46
- public readonly texture: PixiTexture;
47
-
48
- private constructor (image: TextureSource) {
49
- // Todo: maybe add error handling if you feed a video texture to spine?
50
- super(image.resource);
51
- this.texture = PixiTexture.from(image);
52
- }
53
-
54
- public setFilters (minFilter: TextureFilter, magFilter: TextureFilter): void {
55
- const style = this.texture.source.style;
56
-
57
- style.minFilter = SpineTexture.toPixiTextureFilter(minFilter);
58
- style.magFilter = SpineTexture.toPixiTextureFilter(magFilter);
59
- this.texture.source.autoGenerateMipmaps = SpineTexture.toPixiMipMap(minFilter);
60
- this.texture.source.updateMipmaps();
61
- }
62
-
63
- public setWraps (uWrap: TextureWrap, vWrap: TextureWrap): void {
64
- const style = this.texture.source.style;
65
-
66
- style.addressModeU = SpineTexture.toPixiTextureWrap(uWrap);
67
- style.addressModeV = SpineTexture.toPixiTextureWrap(vWrap);
68
- }
69
-
70
- public dispose (): void {
71
- // I am not entirely sure about this...
72
- this.texture.destroy();
73
- }
74
-
75
- private static toPixiMipMap (filter: TextureFilter): boolean {
76
- switch (filter) {
77
- case TextureFilter.Nearest:
78
- case TextureFilter.Linear:
79
- return false;
80
-
81
- case TextureFilter.MipMapNearestLinear:
82
- case TextureFilter.MipMapNearestNearest:
83
- case TextureFilter.MipMapLinearLinear: // TextureFilter.MipMapLinearLinear == TextureFilter.MipMap
84
- case TextureFilter.MipMapLinearNearest:
85
- return true;
86
-
87
- default:
88
- throw new Error(`Unknown texture filter: ${String(filter)}`);
89
- }
90
- }
91
-
92
- private static toPixiTextureFilter (filter: TextureFilter): SCALE_MODE {
93
- switch (filter) {
94
- case TextureFilter.Nearest:
95
- case TextureFilter.MipMapNearestLinear:
96
- case TextureFilter.MipMapNearestNearest:
97
- return 'nearest';
98
-
99
- case TextureFilter.Linear:
100
- case TextureFilter.MipMapLinearLinear: // TextureFilter.MipMapLinearLinear == TextureFilter.MipMap
101
- case TextureFilter.MipMapLinearNearest:
102
- return 'linear';
103
-
104
- default:
105
- throw new Error(`Unknown texture filter: ${String(filter)}`);
106
- }
107
- }
108
-
109
- private static toPixiTextureWrap (wrap: TextureWrap): WRAP_MODE {
110
- switch (wrap) {
111
- case TextureWrap.ClampToEdge:
112
- return 'clamp-to-edge';
113
-
114
- case TextureWrap.MirroredRepeat:
115
- return 'mirror-repeat';
116
-
117
- case TextureWrap.Repeat:
118
- return 'repeat';
119
-
120
- default:
121
- throw new Error(`Unknown texture wrap: ${String(wrap)}`);
122
- }
123
- }
124
-
125
- public static toPixiBlending (blend: BlendMode): BLEND_MODES {
126
- switch (blend) {
127
- case BlendMode.Normal:
128
- return 'normal';
129
-
130
- case BlendMode.Additive:
131
- return 'add';
132
-
133
- case BlendMode.Multiply:
134
- return 'multiply';
135
-
136
- case BlendMode.Screen:
137
- return 'screen';
138
-
139
- default:
140
- throw new Error(`Unknown blendMode: ${String(blend)}`);
141
- }
142
- }
143
- }
@@ -1,158 +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 {
31
- checkExtension,
32
- DOMAdapter,
33
- extensions,
34
- ExtensionType,
35
- LoaderParserPriority,
36
- path,
37
- Resolver,
38
- TextureSource
39
- } from 'pixi.js';
40
- import { SpineTexture } from '../SpineTexture.js';
41
- import { TextureAtlas } from '@esotericsoftware/spine-core';
42
-
43
- import type { AssetExtension, Loader, ResolvedAsset, Texture, UnresolvedAsset } from 'pixi.js';
44
-
45
- type RawAtlas = string;
46
-
47
- const spineTextureAtlasLoader: AssetExtension<RawAtlas | TextureAtlas, ISpineAtlasMetadata> = {
48
- extension: ExtensionType.Asset,
49
-
50
- resolver: {
51
- test: (value: string): boolean => checkExtension(value, ".atlas"),
52
- parse: (value: string): UnresolvedAsset => {
53
- const split = value.split('.');
54
-
55
- return {
56
- resolution: parseFloat(Resolver.RETINA_PREFIX?.exec(value)?.[1] ?? '1'),
57
- format: split[split.length - 2],
58
- src: value,
59
- };
60
- },
61
- },
62
-
63
- loader: {
64
- extension: {
65
- type: ExtensionType.LoadParser,
66
- priority: LoaderParserPriority.Normal,
67
- name: 'spineTextureAtlasLoader',
68
- },
69
-
70
- test (url: string): boolean {
71
- return checkExtension(url, '.atlas');
72
- },
73
-
74
- async load (url: string): Promise<RawAtlas> {
75
- const response = await DOMAdapter.get().fetch(url);
76
-
77
- const txt = await response.text();
78
-
79
- return txt;
80
- },
81
-
82
- testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
83
- const isExtensionRight = checkExtension(options.src as string, '.atlas');
84
- const isString = typeof asset === 'string';
85
-
86
- return Promise.resolve(isExtensionRight && isString);
87
- },
88
-
89
- unload (atlas: TextureAtlas) {
90
- atlas.dispose();
91
- },
92
-
93
- async parse (asset: RawAtlas, options: ResolvedAsset, loader: Loader): Promise<TextureAtlas> {
94
- const metadata: ISpineAtlasMetadata = options.data || {};
95
- let basePath = path.dirname(options.src as string);
96
-
97
- if (basePath && basePath.lastIndexOf('/') !== basePath.length - 1) {
98
- basePath += '/';
99
- }
100
-
101
- // Retval is going to be a texture atlas. However we need to wait for it's callback to resolve this promise.
102
- const retval = new TextureAtlas(asset);
103
-
104
- // If the user gave me only one texture, that one is assumed to be the "first" texture in the atlas
105
- if (metadata.images instanceof TextureSource || typeof metadata.images === 'string') {
106
- const pixiTexture = metadata.images;
107
-
108
- metadata.images = {} as Record<string, TextureSource | string>;
109
- metadata.images[retval.pages[0].name] = pixiTexture;
110
- }
111
-
112
- // we will wait for all promises for the textures at the same time at the end.
113
- const textureLoadingPromises: Promise<any>[] = [];
114
-
115
- // fill the pages
116
- for (const page of retval.pages) {
117
- const pageName = page.name;
118
- const providedPage = metadata?.images ? metadata.images[pageName] : undefined;
119
-
120
- if (providedPage instanceof TextureSource) {
121
- page.setTexture(SpineTexture.from(providedPage));
122
- }
123
- else {
124
- // eslint-disable-next-line max-len
125
- const url: string = providedPage ?? path.normalize([...basePath.split(path.sep), pageName].join(path.sep));
126
-
127
- const assetsToLoadIn = {
128
- src: url,
129
- data: {
130
- ...metadata.imageMetadata,
131
- alphaMode: page.pma ? 'premultiplied-alpha' : 'premultiply-alpha-on-upload'
132
- }
133
- };
134
-
135
- const pixiPromise = loader.load<Texture>(assetsToLoadIn).then((texture) => {
136
- page.setTexture(SpineTexture.from(texture.source));
137
- });
138
-
139
- textureLoadingPromises.push(pixiPromise);
140
- }
141
- }
142
-
143
- await Promise.all(textureLoadingPromises);
144
-
145
- return retval;
146
- },
147
- },
148
- } as AssetExtension<RawAtlas | TextureAtlas, ISpineAtlasMetadata>;
149
-
150
- extensions.add(spineTextureAtlasLoader);
151
-
152
- export interface ISpineAtlasMetadata {
153
- // If you are downloading an .atlas file, this metadata will go to the Texture loader
154
- imageMetadata?: any;
155
- // If you already have atlas pages loaded as pixi textures
156
- // and want to use that to create the atlas, you can pass them here
157
- images?: TextureSource | string | Record<string, TextureSource | string>;
158
- }
@@ -1,81 +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 {
31
- type AssetExtension,
32
- checkExtension,
33
- DOMAdapter,
34
- extensions,
35
- ExtensionType,
36
- LoaderParserPriority,
37
- ResolvedAsset
38
- } from 'pixi.js';
39
-
40
- type SkeletonJsonAsset = any;
41
- type SkeletonBinaryAsset = Uint8Array;
42
-
43
- function isJson (resource: any): resource is SkeletonJsonAsset {
44
- return Object.prototype.hasOwnProperty.call(resource, 'bones');
45
- }
46
-
47
- function isBuffer (resource: any): resource is SkeletonBinaryAsset {
48
- return resource instanceof Uint8Array;
49
- }
50
-
51
- const spineLoaderExtension: AssetExtension<SkeletonJsonAsset | SkeletonBinaryAsset> = {
52
- extension: ExtensionType.Asset,
53
-
54
- loader: {
55
- extension: {
56
- type: ExtensionType.LoadParser,
57
- priority: LoaderParserPriority.Normal,
58
- name: 'spineSkeletonLoader',
59
- },
60
-
61
- test (url) {
62
- return checkExtension(url, '.skel');
63
- },
64
-
65
- async load (url: string): Promise<SkeletonBinaryAsset> {
66
- const response = await DOMAdapter.get().fetch(url);
67
-
68
- const buffer = new Uint8Array(await response.arrayBuffer());
69
-
70
- return buffer;
71
- },
72
- testParse (asset: unknown, options: ResolvedAsset): Promise<boolean> {
73
- const isJsonSpineModel = checkExtension(options.src!, '.json') && isJson(asset);
74
- const isBinarySpineModel = checkExtension(options.src!, '.skel') && isBuffer(asset);
75
-
76
- return Promise.resolve(isJsonSpineModel || isBinarySpineModel);
77
- },
78
- },
79
- } as AssetExtension<SkeletonJsonAsset | SkeletonBinaryAsset>;
80
-
81
- extensions.add(spineLoaderExtension);
@@ -1,92 +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 { Buffer, BufferUsage, Geometry } from 'pixi.js';
31
-
32
- const placeHolderBufferData = new Float32Array(1);
33
- const placeHolderIndexData = new Uint32Array(1);
34
-
35
- export class DarkTintBatchGeometry extends Geometry {
36
- constructor () {
37
- const vertexSize = 7;
38
-
39
- const attributeBuffer = new Buffer({
40
- data: placeHolderBufferData,
41
- label: 'attribute-batch-buffer',
42
- usage: BufferUsage.VERTEX | BufferUsage.COPY_DST,
43
- shrinkToFit: false,
44
- });
45
-
46
- const indexBuffer = new Buffer({
47
- data: placeHolderIndexData,
48
- label: 'index-batch-buffer',
49
- usage: BufferUsage.INDEX | BufferUsage.COPY_DST, // | BufferUsage.STATIC,
50
- shrinkToFit: false,
51
- });
52
-
53
- const stride = vertexSize * 4;
54
-
55
- super({
56
- attributes: {
57
- aPosition: {
58
- buffer: attributeBuffer,
59
- format: 'float32x2',
60
- stride,
61
- offset: 0,
62
- },
63
- aUV: {
64
- buffer: attributeBuffer,
65
- format: 'float32x2',
66
- stride,
67
- offset: 2 * 4,
68
- },
69
- aColor: {
70
- buffer: attributeBuffer,
71
- format: 'unorm8x4',
72
- stride,
73
- offset: 4 * 4,
74
- },
75
- aDarkColor: {
76
- buffer: attributeBuffer,
77
- format: 'unorm8x4',
78
- stride,
79
- offset: 5 * 4,
80
- },
81
- aTextureIdAndRound: {
82
- buffer: attributeBuffer,
83
- format: 'uint16x2',
84
- stride,
85
- offset: 6 * 4,
86
- },
87
- },
88
- indexBuffer
89
- });
90
- }
91
- }
92
-