@melonjs/spine-plugin 1.2.0 → 1.2.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.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/@melonjs/spine-plugin.d.ts +0 -2
- package/dist/@melonjs/spine-plugin.js +41 -28
- package/package.json +13 -12
- package/src/SkeletonRenderer.js +41 -28
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.2.1 - _2023-08-23
|
|
4
|
+
|
|
5
|
+
- code refactoring and optimization to prepare for future feature additions
|
|
6
|
+
- fix URLs in the package.json file
|
|
7
|
+
|
|
8
|
+
## 1.2.0 - _2023-08-22
|
|
9
|
+
|
|
10
|
+
- add support for clipping (coin example is now rendered properly)
|
|
11
|
+
|
|
12
|
+
## 1.1.0 - _2023-08-19
|
|
13
|
+
|
|
14
|
+
- add some basic debug rendering
|
|
15
|
+
- optimize code (remove unneeded logic)
|
|
16
|
+
|
|
17
|
+
## 1.0.0 - _2023-08-16_
|
|
18
|
+
|
|
19
|
+
initial release
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# melonJS Spine Plugin
|
|
2
2
|
|
|
3
|
-
a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementation for [melonJS 2](www.melonjs.org)
|
|
3
|
+
a [Spine](http://en.esotericsoftware.com/spine-in-depth) 4.1 plugin implementation for [melonJS 2](http://www.melonjs.org)
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -4070,10 +4070,8 @@ declare class CanvasTexture extends Texture {
|
|
|
4070
4070
|
}
|
|
4071
4071
|
declare class SkeletonRenderer {
|
|
4072
4072
|
constructor(runtime: any);
|
|
4073
|
-
isWebGLRenderer: any;
|
|
4074
4073
|
skeletonRenderer: any;
|
|
4075
4074
|
runtime: any;
|
|
4076
|
-
tempColor: Color;
|
|
4077
4075
|
tintColor: Color$1;
|
|
4078
4076
|
vertexSize: number;
|
|
4079
4077
|
debugRendering: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Spine plugin - v1.2.
|
|
2
|
+
* melonJS Spine plugin - v1.2.1
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* @melonjs/spine-plugin is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -14932,11 +14932,12 @@ class AssetManager {
|
|
|
14932
14932
|
const worldVertices = new Float32Array(8);
|
|
14933
14933
|
const blendModeLUT = ["normal", "additive", "multiply", "screen"];
|
|
14934
14934
|
|
|
14935
|
+
const regionDebugColor = "green";
|
|
14936
|
+
const clipDebugColor = "blue";
|
|
14937
|
+
|
|
14935
14938
|
class SkeletonRenderer {
|
|
14936
|
-
isWebGLRenderer;
|
|
14937
14939
|
skeletonRenderer;
|
|
14938
14940
|
runtime;
|
|
14939
|
-
tempColor = new Color();
|
|
14940
14941
|
tintColor = new Color$1();
|
|
14941
14942
|
vertexSize = 2 + 2 + 4;
|
|
14942
14943
|
debugRendering = false;
|
|
@@ -14947,18 +14948,21 @@ class SkeletonRenderer {
|
|
|
14947
14948
|
constructor(runtime) {
|
|
14948
14949
|
this.runtime = runtime;
|
|
14949
14950
|
this.skeletonRenderer = new runtime.SkeletonRenderer();
|
|
14950
|
-
this.tempColor = new Color();
|
|
14951
14951
|
}
|
|
14952
14952
|
|
|
14953
14953
|
draw(renderer, skeleton) {
|
|
14954
14954
|
let clipper = this.clipper;
|
|
14955
14955
|
let drawOrder = skeleton.drawOrder;
|
|
14956
14956
|
let skeletonColor = skeleton.color;
|
|
14957
|
+
let clippingMask = this.clippingMask;
|
|
14958
|
+
let debugRendering = this.debugRendering;
|
|
14957
14959
|
|
|
14958
14960
|
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
|
14959
14961
|
let clippedVertexSize = clipper.isClipping() ? 2 : this.vertexSize;
|
|
14960
14962
|
let slot = drawOrder[i];
|
|
14961
14963
|
let bone = slot.bone;
|
|
14964
|
+
let image;
|
|
14965
|
+
let region;
|
|
14962
14966
|
|
|
14963
14967
|
if (!bone.active) {
|
|
14964
14968
|
clipper.clipEndWithSlot(slot);
|
|
@@ -14969,8 +14973,36 @@ class SkeletonRenderer {
|
|
|
14969
14973
|
let attachment = slot.getAttachment();
|
|
14970
14974
|
|
|
14971
14975
|
if (attachment instanceof RegionAttachment) {
|
|
14972
|
-
|
|
14973
|
-
|
|
14976
|
+
attachment.computeWorldVertices(slot, worldVertices, 0, clippedVertexSize);
|
|
14977
|
+
region = attachment.region;
|
|
14978
|
+
image = region.texture.getImage();
|
|
14979
|
+
} else if (attachment instanceof MeshAttachment) {
|
|
14980
|
+
/*
|
|
14981
|
+
// commenting for now as totally untested
|
|
14982
|
+
let mesh = attachment;
|
|
14983
|
+
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, worldVertices, 0, 2);
|
|
14984
|
+
region = mesh.region;
|
|
14985
|
+
image = mesh.region.texture.getImage();
|
|
14986
|
+
*/
|
|
14987
|
+
console.warn("spine-plugin: MeshAttachment is not supported yet");
|
|
14988
|
+
} else if (attachment instanceof ClippingAttachment) {
|
|
14989
|
+
let clip = attachment;
|
|
14990
|
+
let vertices = this.clippingVertices;
|
|
14991
|
+
clipper.clipStart(slot, clip);
|
|
14992
|
+
clip.computeWorldVertices(slot, 0, clip.worldVerticesLength, vertices, 0, 2);
|
|
14993
|
+
clippingMask.setVertices(vertices, clip.worldVerticesLength);
|
|
14994
|
+
if (debugRendering === true) {
|
|
14995
|
+
renderer.setColor(clipDebugColor);
|
|
14996
|
+
renderer.stroke(clippingMask);
|
|
14997
|
+
}
|
|
14998
|
+
continue;
|
|
14999
|
+
} else {
|
|
15000
|
+
clipper.clipEndWithSlot(slot);
|
|
15001
|
+
renderer.clearMask();
|
|
15002
|
+
continue;
|
|
15003
|
+
}
|
|
15004
|
+
|
|
15005
|
+
if (typeof image !== "undefined") {
|
|
14974
15006
|
let slotColor = slot.color;
|
|
14975
15007
|
let regionColor = attachment.color;
|
|
14976
15008
|
let blendMode = slot.data.blendMode;
|
|
@@ -14981,8 +15013,6 @@ class SkeletonRenderer {
|
|
|
14981
15013
|
skeletonColor.b * slotColor.b * regionColor.b,
|
|
14982
15014
|
skeletonColor.a * slotColor.a * regionColor.a);
|
|
14983
15015
|
|
|
14984
|
-
attachment.computeWorldVertices(slot, worldVertices, 0, clippedVertexSize);
|
|
14985
|
-
|
|
14986
15016
|
renderer.save();
|
|
14987
15017
|
renderer.transform(bone.a, bone.c, bone.b, bone.d, bone.worldX, bone.worldY);
|
|
14988
15018
|
renderer.translate(attachment.offset[0], attachment.offset[1]);
|
|
@@ -15007,34 +15037,17 @@ class SkeletonRenderer {
|
|
|
15007
15037
|
renderer.setGlobalAlpha(color.a);
|
|
15008
15038
|
|
|
15009
15039
|
if (clipper.isClipping()) {
|
|
15010
|
-
renderer.setMask(
|
|
15040
|
+
renderer.setMask(clippingMask);
|
|
15011
15041
|
}
|
|
15012
15042
|
|
|
15013
15043
|
renderer.drawImage(image, image.width * region.u, image.height * region.v, w, h, 0, 0, w, h);
|
|
15014
15044
|
|
|
15015
|
-
if (
|
|
15016
|
-
renderer.setColor(
|
|
15045
|
+
if (debugRendering === true) {
|
|
15046
|
+
renderer.setColor(regionDebugColor);
|
|
15017
15047
|
renderer.strokeRect(0, 0, w, h);
|
|
15018
15048
|
}
|
|
15019
15049
|
|
|
15020
15050
|
renderer.restore();
|
|
15021
|
-
} else if (attachment instanceof MeshAttachment) {
|
|
15022
|
-
// do nothing for now;
|
|
15023
|
-
} else if (attachment instanceof ClippingAttachment) {
|
|
15024
|
-
let clip = attachment;
|
|
15025
|
-
let vertices = this.clippingVertices;
|
|
15026
|
-
clipper.clipStart(slot, clip);
|
|
15027
|
-
clip.computeWorldVertices(slot, 0, clip.worldVerticesLength, vertices, 0, 2);
|
|
15028
|
-
this.clippingMask.setVertices(vertices, clip.worldVerticesLength);
|
|
15029
|
-
if (this.debugRendering === true) {
|
|
15030
|
-
renderer.setColor("blue");
|
|
15031
|
-
renderer.stroke(this.clippingMask);
|
|
15032
|
-
}
|
|
15033
|
-
continue;
|
|
15034
|
-
} else {
|
|
15035
|
-
clipper.clipEndWithSlot(slot);
|
|
15036
|
-
renderer.clearMask();
|
|
15037
|
-
continue;
|
|
15038
15051
|
}
|
|
15039
15052
|
clipper.clipEndWithSlot(slot);
|
|
15040
15053
|
renderer.clearMask();
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melonjs/spine-plugin",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "melonJS Spine plugin",
|
|
5
|
+
"homepage": "https://github.com/melonjs/spine-plugin#readme",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"2D",
|
|
8
9
|
"HTML5",
|
|
9
10
|
"javascript",
|
|
10
11
|
"TypeScript",
|
|
11
|
-
"
|
|
12
|
+
"ES6",
|
|
12
13
|
"Canvas",
|
|
13
14
|
"WebGL",
|
|
14
15
|
"WebGL2",
|
|
15
16
|
"melonjs",
|
|
16
|
-
"
|
|
17
|
+
"plugin",
|
|
18
|
+
"spine",
|
|
19
|
+
"spine-runtimes",
|
|
20
|
+
"spine-animation",
|
|
17
21
|
"esotericsoftware"
|
|
18
22
|
],
|
|
19
23
|
"repository": {
|
|
20
24
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/melonjs/
|
|
25
|
+
"url": "git+https://github.com/melonjs/spine-plugin.git"
|
|
22
26
|
},
|
|
23
27
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/melonjs/
|
|
28
|
+
"url": "https://github.com/melonjs/spine-plugin/issues"
|
|
25
29
|
},
|
|
26
30
|
"license": "MIT",
|
|
27
31
|
"author": "AltByte Pte Ltd",
|
|
@@ -38,7 +42,8 @@
|
|
|
38
42
|
"src/",
|
|
39
43
|
"package.json",
|
|
40
44
|
"README.md",
|
|
41
|
-
"LICENSE"
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"CHANGELOG.md"
|
|
42
47
|
],
|
|
43
48
|
"peerDependencies": {
|
|
44
49
|
"melonjs": "^15.9.0"
|
|
@@ -52,12 +57,12 @@
|
|
|
52
57
|
"@babel/eslint-parser": "^7.22.0",
|
|
53
58
|
"@babel/plugin-syntax-import-assertions": "^7.22.5",
|
|
54
59
|
"@rollup/plugin-commonjs": "^25.0.4",
|
|
55
|
-
"@rollup/plugin-node-resolve": "^15.2.
|
|
60
|
+
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
56
61
|
"@rollup/plugin-replace": "^5.0.2",
|
|
57
62
|
"del-cli": "^5.0.0",
|
|
58
63
|
"eslint": "^8.47.0",
|
|
59
64
|
"eslint-plugin-jsdoc": "^46.5.0",
|
|
60
|
-
"rollup": "^3.28.
|
|
65
|
+
"rollup": "^3.28.1",
|
|
61
66
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
62
67
|
"typescript": "^5.1.6"
|
|
63
68
|
},
|
|
@@ -69,9 +74,5 @@
|
|
|
69
74
|
"prepublishOnly": "npm run build",
|
|
70
75
|
"clean": "del-cli --force dist/*",
|
|
71
76
|
"types": "tsc"
|
|
72
|
-
},
|
|
73
|
-
"homepage": "https://github.com/melonjs/spine-plugin#readme",
|
|
74
|
-
"directories": {
|
|
75
|
-
"test": "test"
|
|
76
77
|
}
|
|
77
78
|
}
|
package/src/SkeletonRenderer.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Color as MColor, Math as MMath, Polygon } from "melonjs";
|
|
2
|
-
import { SkeletonClipping, ClippingAttachment, MeshAttachment, RegionAttachment
|
|
2
|
+
import { SkeletonClipping, ClippingAttachment, MeshAttachment, RegionAttachment } from "@esotericsoftware/spine-core";
|
|
3
3
|
|
|
4
4
|
const worldVertices = new Float32Array(8);
|
|
5
5
|
const blendModeLUT = ["normal", "additive", "multiply", "screen"];
|
|
6
6
|
|
|
7
|
+
const regionDebugColor = "green";
|
|
8
|
+
const clipDebugColor = "blue";
|
|
9
|
+
|
|
7
10
|
export default class SkeletonRenderer {
|
|
8
|
-
isWebGLRenderer;
|
|
9
11
|
skeletonRenderer;
|
|
10
12
|
runtime;
|
|
11
|
-
tempColor = new Color();
|
|
12
13
|
tintColor = new MColor();
|
|
13
14
|
vertexSize = 2 + 2 + 4;
|
|
14
15
|
debugRendering = false;
|
|
@@ -19,18 +20,21 @@ export default class SkeletonRenderer {
|
|
|
19
20
|
constructor(runtime) {
|
|
20
21
|
this.runtime = runtime;
|
|
21
22
|
this.skeletonRenderer = new runtime.SkeletonRenderer();
|
|
22
|
-
this.tempColor = new Color();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
draw(renderer, skeleton) {
|
|
26
26
|
let clipper = this.clipper;
|
|
27
27
|
let drawOrder = skeleton.drawOrder;
|
|
28
28
|
let skeletonColor = skeleton.color;
|
|
29
|
+
let clippingMask = this.clippingMask;
|
|
30
|
+
let debugRendering = this.debugRendering;
|
|
29
31
|
|
|
30
32
|
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
|
31
33
|
let clippedVertexSize = clipper.isClipping() ? 2 : this.vertexSize;
|
|
32
34
|
let slot = drawOrder[i];
|
|
33
35
|
let bone = slot.bone;
|
|
36
|
+
let image;
|
|
37
|
+
let region;
|
|
34
38
|
|
|
35
39
|
if (!bone.active) {
|
|
36
40
|
clipper.clipEndWithSlot(slot);
|
|
@@ -41,8 +45,36 @@ export default class SkeletonRenderer {
|
|
|
41
45
|
let attachment = slot.getAttachment();
|
|
42
46
|
|
|
43
47
|
if (attachment instanceof RegionAttachment) {
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
attachment.computeWorldVertices(slot, worldVertices, 0, clippedVertexSize);
|
|
49
|
+
region = attachment.region;
|
|
50
|
+
image = region.texture.getImage();
|
|
51
|
+
} else if (attachment instanceof MeshAttachment) {
|
|
52
|
+
/*
|
|
53
|
+
// commenting for now as totally untested
|
|
54
|
+
let mesh = attachment;
|
|
55
|
+
mesh.computeWorldVertices(slot, 0, mesh.worldVerticesLength, worldVertices, 0, 2);
|
|
56
|
+
region = mesh.region;
|
|
57
|
+
image = mesh.region.texture.getImage();
|
|
58
|
+
*/
|
|
59
|
+
console.warn("spine-plugin: MeshAttachment is not supported yet");
|
|
60
|
+
} else if (attachment instanceof ClippingAttachment) {
|
|
61
|
+
let clip = attachment;
|
|
62
|
+
let vertices = this.clippingVertices;
|
|
63
|
+
clipper.clipStart(slot, clip);
|
|
64
|
+
clip.computeWorldVertices(slot, 0, clip.worldVerticesLength, vertices, 0, 2);
|
|
65
|
+
clippingMask.setVertices(vertices, clip.worldVerticesLength);
|
|
66
|
+
if (debugRendering === true) {
|
|
67
|
+
renderer.setColor(clipDebugColor);
|
|
68
|
+
renderer.stroke(clippingMask);
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
} else {
|
|
72
|
+
clipper.clipEndWithSlot(slot);
|
|
73
|
+
renderer.clearMask();
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (typeof image !== "undefined") {
|
|
46
78
|
let slotColor = slot.color;
|
|
47
79
|
let regionColor = attachment.color;
|
|
48
80
|
let blendMode = slot.data.blendMode;
|
|
@@ -53,8 +85,6 @@ export default class SkeletonRenderer {
|
|
|
53
85
|
skeletonColor.b * slotColor.b * regionColor.b,
|
|
54
86
|
skeletonColor.a * slotColor.a * regionColor.a);
|
|
55
87
|
|
|
56
|
-
attachment.computeWorldVertices(slot, worldVertices, 0, clippedVertexSize);
|
|
57
|
-
|
|
58
88
|
renderer.save();
|
|
59
89
|
renderer.transform(bone.a, bone.c, bone.b, bone.d, bone.worldX, bone.worldY);
|
|
60
90
|
renderer.translate(attachment.offset[0], attachment.offset[1]);
|
|
@@ -79,34 +109,17 @@ export default class SkeletonRenderer {
|
|
|
79
109
|
renderer.setGlobalAlpha(color.a);
|
|
80
110
|
|
|
81
111
|
if (clipper.isClipping()) {
|
|
82
|
-
renderer.setMask(
|
|
112
|
+
renderer.setMask(clippingMask);
|
|
83
113
|
}
|
|
84
114
|
|
|
85
115
|
renderer.drawImage(image, image.width * region.u, image.height * region.v, w, h, 0, 0, w, h);
|
|
86
116
|
|
|
87
|
-
if (
|
|
88
|
-
renderer.setColor(
|
|
117
|
+
if (debugRendering === true) {
|
|
118
|
+
renderer.setColor(regionDebugColor);
|
|
89
119
|
renderer.strokeRect(0, 0, w, h);
|
|
90
120
|
}
|
|
91
121
|
|
|
92
122
|
renderer.restore();
|
|
93
|
-
} else if (attachment instanceof MeshAttachment) {
|
|
94
|
-
// do nothing for now;
|
|
95
|
-
} else if (attachment instanceof ClippingAttachment) {
|
|
96
|
-
let clip = attachment;
|
|
97
|
-
let vertices = this.clippingVertices;
|
|
98
|
-
clipper.clipStart(slot, clip);
|
|
99
|
-
clip.computeWorldVertices(slot, 0, clip.worldVerticesLength, vertices, 0, 2);
|
|
100
|
-
this.clippingMask.setVertices(vertices, clip.worldVerticesLength);
|
|
101
|
-
if (this.debugRendering === true) {
|
|
102
|
-
renderer.setColor("blue");
|
|
103
|
-
renderer.stroke(this.clippingMask);
|
|
104
|
-
}
|
|
105
|
-
continue;
|
|
106
|
-
} else {
|
|
107
|
-
clipper.clipEndWithSlot(slot);
|
|
108
|
-
renderer.clearMask();
|
|
109
|
-
continue;
|
|
110
123
|
}
|
|
111
124
|
clipper.clipEndWithSlot(slot);
|
|
112
125
|
renderer.clearMask();
|