@esotericsoftware/spine-core 4.3.9 → 4.3.11
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/dist/Skeleton.d.ts +1 -1
- package/dist/Skeleton.js +1 -1
- package/dist/SkeletonClipping.js +40 -23
- package/dist/SkeletonCoordinateConverter.d.ts +57 -0
- package/dist/SkeletonCoordinateConverter.js +30 -0
- package/dist/SkeletonData.d.ts +1 -1
- package/dist/SkeletonData.js +1 -1
- package/dist/SkeletonPhysicsMovement.d.ts +134 -0
- package/dist/SkeletonPhysicsMovement.js +189 -0
- package/dist/SkeletonRendererCore.js +15 -5
- package/dist/esm/spine-core.min.mjs +2 -2
- package/dist/esm/spine-core.mjs +198 -24
- package/dist/esm/spine-core.mjs.map +3 -3
- package/dist/iife/spine-core.js +198 -24
- package/dist/iife/spine-core.js.map +3 -3
- package/dist/iife/spine-core.min.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/iife/spine-core.js
CHANGED
|
@@ -136,6 +136,7 @@ var spine = (() => {
|
|
|
136
136
|
SkeletonClipping: () => SkeletonClipping,
|
|
137
137
|
SkeletonData: () => SkeletonData,
|
|
138
138
|
SkeletonJson: () => SkeletonJson,
|
|
139
|
+
SkeletonPhysicsMovement: () => SkeletonPhysicsMovement,
|
|
139
140
|
SkeletonRendererCore: () => SkeletonRendererCore,
|
|
140
141
|
Skin: () => Skin,
|
|
141
142
|
SkinEntry: () => SkinEntry,
|
|
@@ -11219,7 +11220,7 @@ ${error}` : ""}`);
|
|
|
11219
11220
|
t = triangles[i + 2];
|
|
11220
11221
|
const x3 = vertices[t * stride], y3 = vertices[t * stride + 1];
|
|
11221
11222
|
const u3 = uvs[t << 1], v3 = uvs[(t << 1) + 1];
|
|
11222
|
-
|
|
11223
|
+
let d0 = 0, d1 = 0, d2 = 0, d4 = 0, d = 0;
|
|
11223
11224
|
for (let p = 0; p < polygonsCount; p++) {
|
|
11224
11225
|
let s = clippedVertices.length;
|
|
11225
11226
|
if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p])) {
|
|
@@ -11227,6 +11228,13 @@ ${error}` : ""}`);
|
|
|
11227
11228
|
const clipOutputLength = clipOutput.length;
|
|
11228
11229
|
if (clipOutputLength === 0) continue;
|
|
11229
11230
|
let clipOutputCount = clipOutputLength >> 1;
|
|
11231
|
+
if (d === 0) {
|
|
11232
|
+
d0 = y2 - y3;
|
|
11233
|
+
d1 = x3 - x2;
|
|
11234
|
+
d2 = x1 - x3;
|
|
11235
|
+
d4 = y3 - y1;
|
|
11236
|
+
d = 1 / (d0 * d2 - d1 * d4);
|
|
11237
|
+
}
|
|
11230
11238
|
const cv = Utils.setArraySize(clippedVertices, s + clipOutputCount * stride);
|
|
11231
11239
|
for (let ii = 0; ii < clipOutputLength; ii += 2, s += stride) {
|
|
11232
11240
|
const x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
|
|
@@ -11426,7 +11434,7 @@ ${error}` : ""}`);
|
|
|
11426
11434
|
const x3 = vertices[vertexStart + v], y3 = vertices[vertexStart + v + 1];
|
|
11427
11435
|
uv = t << 1;
|
|
11428
11436
|
const u3 = uvs[uv], v3 = uvs[uv + 1];
|
|
11429
|
-
|
|
11437
|
+
let d0 = 0, d1 = 0, d2 = 0, d4 = 0, d = 0;
|
|
11430
11438
|
for (let p = 0; p < polygonsCount; p++) {
|
|
11431
11439
|
let s = this.clippedVerticesLength;
|
|
11432
11440
|
if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p])) {
|
|
@@ -11434,6 +11442,13 @@ ${error}` : ""}`);
|
|
|
11434
11442
|
const clipOutputLength = clipOutput.length;
|
|
11435
11443
|
if (clipOutputLength === 0) continue;
|
|
11436
11444
|
let clipOutputCount = clipOutputLength >> 1;
|
|
11445
|
+
if (d === 0) {
|
|
11446
|
+
d0 = y2 - y3;
|
|
11447
|
+
d1 = x3 - x2;
|
|
11448
|
+
d2 = x1 - x3;
|
|
11449
|
+
d4 = y3 - y1;
|
|
11450
|
+
d = 1 / (d0 * d2 - d1 * d4);
|
|
11451
|
+
}
|
|
11437
11452
|
const newLength = s + clipOutputCount * stride;
|
|
11438
11453
|
if (clippedVertices.length < newLength) {
|
|
11439
11454
|
this._clippedVerticesTyped = new Float32Array(newLength * 2);
|
|
@@ -11550,16 +11565,15 @@ ${error}` : ""}`);
|
|
|
11550
11565
|
const edgeX = v[i], edgeY = v[i + 1], ex = edgeX - v[i + 2], ey = edgeY - v[i + 3];
|
|
11551
11566
|
const outputStart = output.length;
|
|
11552
11567
|
const iv2 = input;
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11568
|
+
x1 = iv2[0];
|
|
11569
|
+
y1 = iv2[1];
|
|
11570
|
+
let s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11571
|
+
for (let ii = 2, nn = input.length - 2; ii <= nn; ii += 2) {
|
|
11557
11572
|
x2 = iv2[ii];
|
|
11558
11573
|
y2 = iv2[ii + 1];
|
|
11559
|
-
const s2 = ey * (edgeX - x2)
|
|
11560
|
-
const s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11574
|
+
const s2 = ey * (edgeX - x2) - ex * (edgeY - y2);
|
|
11561
11575
|
if (s1 > 0) {
|
|
11562
|
-
if (s2)
|
|
11576
|
+
if (s2 > 0)
|
|
11563
11577
|
output.push(x2, y2);
|
|
11564
11578
|
else {
|
|
11565
11579
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
@@ -11569,7 +11583,7 @@ ${error}` : ""}`);
|
|
|
11569
11583
|
} else
|
|
11570
11584
|
output.push(x2, y2);
|
|
11571
11585
|
}
|
|
11572
|
-
} else if (s2) {
|
|
11586
|
+
} else if (s2 > 0) {
|
|
11573
11587
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
11574
11588
|
if (t >= 0 && t <= 1) {
|
|
11575
11589
|
output.push(x1 + ix * t, y1 + iy * t, x2, y2);
|
|
@@ -11578,6 +11592,9 @@ ${error}` : ""}`);
|
|
|
11578
11592
|
output.push(x2, y2);
|
|
11579
11593
|
} else
|
|
11580
11594
|
clipped = true;
|
|
11595
|
+
x1 = x2;
|
|
11596
|
+
y1 = y2;
|
|
11597
|
+
s1 = s2;
|
|
11581
11598
|
}
|
|
11582
11599
|
if (outputStart === output.length) {
|
|
11583
11600
|
originalOutput.length = 0;
|
|
@@ -11625,16 +11642,15 @@ ${error}` : ""}`);
|
|
|
11625
11642
|
const outputStart = output.length, fragmentStart = this.inverseVertices.length;
|
|
11626
11643
|
this.inverseVertices.push(0);
|
|
11627
11644
|
iv = input;
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11645
|
+
x1 = iv[0];
|
|
11646
|
+
y1 = iv[1];
|
|
11647
|
+
let s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11648
|
+
for (let ii = 2, nn = input.length - 2; ii <= nn; ii += 2) {
|
|
11632
11649
|
x2 = iv[ii];
|
|
11633
11650
|
y2 = iv[ii + 1];
|
|
11634
|
-
const s2 = ey * (edgeX - x2)
|
|
11635
|
-
const s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11651
|
+
const s2 = ey * (edgeX - x2) - ex * (edgeY - y2);
|
|
11636
11652
|
if (s1 > 0) {
|
|
11637
|
-
if (s2)
|
|
11653
|
+
if (s2 > 0)
|
|
11638
11654
|
output.push(x2, y2);
|
|
11639
11655
|
else {
|
|
11640
11656
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
@@ -11645,16 +11661,19 @@ ${error}` : ""}`);
|
|
|
11645
11661
|
} else
|
|
11646
11662
|
output.push(x2, y2);
|
|
11647
11663
|
}
|
|
11648
|
-
} else if (s2) {
|
|
11649
|
-
const
|
|
11664
|
+
} else if (s2 > 0) {
|
|
11665
|
+
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
11650
11666
|
if (t >= 0 && t <= 1) {
|
|
11651
|
-
const cx = x1 +
|
|
11667
|
+
const cx = x1 + ix * t, cy = y1 + iy * t;
|
|
11652
11668
|
this.inverseVertices.push(cx, cy);
|
|
11653
11669
|
output.push(cx, cy, x2, y2);
|
|
11654
11670
|
} else
|
|
11655
11671
|
output.push(x2, y2);
|
|
11656
11672
|
} else
|
|
11657
11673
|
this.inverseVertices.push(x2, y2);
|
|
11674
|
+
x1 = x2;
|
|
11675
|
+
y1 = y2;
|
|
11676
|
+
s1 = s2;
|
|
11658
11677
|
}
|
|
11659
11678
|
const fragmentSize = this.inverseVertices.length - fragmentStart - 1;
|
|
11660
11679
|
if (fragmentSize >= 6)
|
|
@@ -13009,6 +13028,151 @@ ${error}` : ""}`);
|
|
|
13009
13028
|
return map[property] !== void 0 ? map[property] : defaultValue;
|
|
13010
13029
|
}
|
|
13011
13030
|
|
|
13031
|
+
// spine-core/src/SkeletonPhysicsMovement.ts
|
|
13032
|
+
var SkeletonPhysicsMovement = class {
|
|
13033
|
+
/**
|
|
13034
|
+
* Creates a movement tracker for a skeleton displayed by a host runtime object.
|
|
13035
|
+
* @param skeleton The skeleton whose physics constraints receive inherited movement.
|
|
13036
|
+
* @param adapter Runtime-specific hooks used to read and convert the host object's transform.
|
|
13037
|
+
* @param options Initial movement inheritance values.
|
|
13038
|
+
*/
|
|
13039
|
+
constructor(skeleton, adapter, options = {}) {
|
|
13040
|
+
this.skeleton = skeleton;
|
|
13041
|
+
this.adapter = adapter;
|
|
13042
|
+
this.positionInheritanceFactorX = options.positionInheritanceX ?? 0;
|
|
13043
|
+
this.positionInheritanceFactorY = options.positionInheritanceY ?? 0;
|
|
13044
|
+
this.rotationInheritanceFactor = options.rotationInheritance ?? 0;
|
|
13045
|
+
}
|
|
13046
|
+
positionInheritanceFactorX = 0;
|
|
13047
|
+
positionInheritanceFactorY = 0;
|
|
13048
|
+
rotationInheritanceFactor = 0;
|
|
13049
|
+
hasLastTransform = false;
|
|
13050
|
+
lastX = 0;
|
|
13051
|
+
lastY = 0;
|
|
13052
|
+
lastZ = 0;
|
|
13053
|
+
lastRotation = 0;
|
|
13054
|
+
currentTransform = { x: 0, y: 0, z: 0, rotation: 0 };
|
|
13055
|
+
currentPosition = { x: 0, y: 0, z: 0 };
|
|
13056
|
+
lastPosition = { x: 0, y: 0, z: 0 };
|
|
13057
|
+
/** Horizontal position inheritance factor. `0` disables horizontal position inheritance. */
|
|
13058
|
+
get positionInheritanceX() {
|
|
13059
|
+
return this.positionInheritanceFactorX;
|
|
13060
|
+
}
|
|
13061
|
+
/** Vertical position inheritance factor. `0` disables vertical position inheritance. */
|
|
13062
|
+
get positionInheritanceY() {
|
|
13063
|
+
return this.positionInheritanceFactorY;
|
|
13064
|
+
}
|
|
13065
|
+
/**
|
|
13066
|
+
* Sets how much host object translation is inherited by skeleton physics constraints.
|
|
13067
|
+
* Use `(1, 1)` for normal inheritance, or `(0, 0)` to disable position inheritance.
|
|
13068
|
+
* @param x The horizontal position inheritance factor.
|
|
13069
|
+
* @param y The vertical position inheritance factor.
|
|
13070
|
+
*/
|
|
13071
|
+
setPositionInheritance(x, y) {
|
|
13072
|
+
const wasDisabled = this.positionInheritanceFactorX === 0 && this.positionInheritanceFactorY === 0;
|
|
13073
|
+
const isEnabled = x !== 0 || y !== 0;
|
|
13074
|
+
this.positionInheritanceFactorX = x;
|
|
13075
|
+
this.positionInheritanceFactorY = y;
|
|
13076
|
+
if (wasDisabled && isEnabled) this.resetPosition();
|
|
13077
|
+
}
|
|
13078
|
+
/** Rotation inheritance factor. `0` disables rotation inheritance. */
|
|
13079
|
+
get rotationInheritance() {
|
|
13080
|
+
return this.rotationInheritanceFactor;
|
|
13081
|
+
}
|
|
13082
|
+
/**
|
|
13083
|
+
* Sets how much host object rotation is inherited by skeleton physics constraints.
|
|
13084
|
+
* @param value The rotation inheritance factor.
|
|
13085
|
+
*/
|
|
13086
|
+
set rotationInheritance(value) {
|
|
13087
|
+
const wasDisabled = this.rotationInheritanceFactor === 0;
|
|
13088
|
+
this.rotationInheritanceFactor = value;
|
|
13089
|
+
if (wasDisabled && value !== 0) this.resetRotation();
|
|
13090
|
+
}
|
|
13091
|
+
/** Resets the previous position used to calculate inherited translation. */
|
|
13092
|
+
resetPosition() {
|
|
13093
|
+
const transform = this.currentTransform;
|
|
13094
|
+
const readRotation = !this.hasLastTransform && this.rotationInheritanceFactor !== 0;
|
|
13095
|
+
this.adapter.readTransform(transform, readRotation);
|
|
13096
|
+
this.lastX = transform.x;
|
|
13097
|
+
this.lastY = transform.y;
|
|
13098
|
+
this.lastZ = transform.z;
|
|
13099
|
+
if (readRotation) this.lastRotation = transform.rotation;
|
|
13100
|
+
this.hasLastTransform = true;
|
|
13101
|
+
}
|
|
13102
|
+
/** Resets the previous rotation used to calculate inherited rotation. */
|
|
13103
|
+
resetRotation() {
|
|
13104
|
+
const transform = this.currentTransform;
|
|
13105
|
+
this.adapter.readTransform(transform, true);
|
|
13106
|
+
this.lastRotation = transform.rotation;
|
|
13107
|
+
if (!this.hasLastTransform) {
|
|
13108
|
+
this.lastX = transform.x;
|
|
13109
|
+
this.lastY = transform.y;
|
|
13110
|
+
this.lastZ = transform.z;
|
|
13111
|
+
}
|
|
13112
|
+
this.hasLastTransform = true;
|
|
13113
|
+
}
|
|
13114
|
+
/** Resets both previous position and previous rotation. */
|
|
13115
|
+
resetTransform() {
|
|
13116
|
+
const transform = this.currentTransform;
|
|
13117
|
+
this.adapter.readTransform(transform, true);
|
|
13118
|
+
this.setLastTransform(transform.x, transform.y, transform.z, transform.rotation);
|
|
13119
|
+
}
|
|
13120
|
+
/**
|
|
13121
|
+
* Applies host object transform movement since the previous call to the skeleton's physics constraints.
|
|
13122
|
+
*
|
|
13123
|
+
* The first call records the current transform as the baseline and does not apply movement.
|
|
13124
|
+
*/
|
|
13125
|
+
applyTransformMovement() {
|
|
13126
|
+
const inheritPosition = this.positionInheritanceFactorX !== 0 || this.positionInheritanceFactorY !== 0;
|
|
13127
|
+
const inheritRotation = this.rotationInheritanceFactor !== 0;
|
|
13128
|
+
if (!inheritPosition && !inheritRotation) return;
|
|
13129
|
+
const transform = this.currentTransform;
|
|
13130
|
+
this.adapter.readTransform(transform, inheritRotation);
|
|
13131
|
+
const { x, y, z } = transform;
|
|
13132
|
+
const currentRotation = inheritRotation ? transform.rotation : this.lastRotation;
|
|
13133
|
+
const positionChanged = x !== this.lastX || y !== this.lastY || z !== this.lastZ;
|
|
13134
|
+
if (this.hasLastTransform) {
|
|
13135
|
+
if (!positionChanged && currentRotation === this.lastRotation) return;
|
|
13136
|
+
if (inheritPosition && positionChanged) this.applyPositionMovement(x, y, z);
|
|
13137
|
+
if (inheritRotation && currentRotation !== this.lastRotation) this.applyRotationMovement(currentRotation);
|
|
13138
|
+
}
|
|
13139
|
+
this.setLastTransform(x, y, z, currentRotation);
|
|
13140
|
+
}
|
|
13141
|
+
applyPositionMovement(currentX, currentY, currentZ) {
|
|
13142
|
+
const currentPosition = this.currentPosition;
|
|
13143
|
+
currentPosition.x = currentX;
|
|
13144
|
+
currentPosition.y = currentY;
|
|
13145
|
+
currentPosition.z = currentZ;
|
|
13146
|
+
this.adapter.worldToSkeleton(currentPosition);
|
|
13147
|
+
const lastPosition = this.lastPosition;
|
|
13148
|
+
lastPosition.x = this.lastX;
|
|
13149
|
+
lastPosition.y = this.lastY;
|
|
13150
|
+
lastPosition.z = this.lastZ;
|
|
13151
|
+
this.adapter.worldToSkeleton(lastPosition);
|
|
13152
|
+
this.skeleton.physicsTranslate(
|
|
13153
|
+
(currentPosition.x - lastPosition.x) * this.positionInheritanceFactorX,
|
|
13154
|
+
(currentPosition.y - lastPosition.y) * this.positionInheritanceFactorY
|
|
13155
|
+
);
|
|
13156
|
+
}
|
|
13157
|
+
applyRotationMovement(currentRotation) {
|
|
13158
|
+
const rotationFactor = this.rotationInheritanceFactor;
|
|
13159
|
+
if (rotationFactor === 0) return;
|
|
13160
|
+
this.skeleton.physicsRotate(0, 0, this.getRotationDelta(currentRotation, this.lastRotation) * rotationFactor);
|
|
13161
|
+
}
|
|
13162
|
+
setLastTransform(x, y, z, rotation) {
|
|
13163
|
+
this.lastX = x;
|
|
13164
|
+
this.lastY = y;
|
|
13165
|
+
this.lastZ = z;
|
|
13166
|
+
this.lastRotation = rotation;
|
|
13167
|
+
this.hasLastTransform = true;
|
|
13168
|
+
}
|
|
13169
|
+
getRotationDelta(current, previous) {
|
|
13170
|
+
let delta = current - previous;
|
|
13171
|
+
delta = (delta + 180) % 360 - 180;
|
|
13172
|
+
return delta < -180 ? delta + 360 : delta;
|
|
13173
|
+
}
|
|
13174
|
+
};
|
|
13175
|
+
|
|
13012
13176
|
// spine-core/src/SkeletonRendererCore.ts
|
|
13013
13177
|
var SkeletonRendererCore = class {
|
|
13014
13178
|
commandPool = new CommandPool();
|
|
@@ -13021,17 +13185,21 @@ ${error}` : ""}`);
|
|
|
13021
13185
|
this.renderCommands.length = 0;
|
|
13022
13186
|
const clipper = this.clipping;
|
|
13023
13187
|
const drawOrder = skeleton.drawOrder.appliedPose;
|
|
13024
|
-
for (let i = 0; i <
|
|
13188
|
+
for (let i = 0, n = drawOrder.length; i < n; i++) {
|
|
13025
13189
|
const slot = drawOrder[i];
|
|
13026
|
-
|
|
13027
|
-
if (!attachment) {
|
|
13190
|
+
if (!slot.bone.active) {
|
|
13028
13191
|
clipper.clipEnd(slot);
|
|
13029
13192
|
continue;
|
|
13030
13193
|
}
|
|
13031
13194
|
const pose = slot.appliedPose;
|
|
13195
|
+
const attachment = pose.attachment;
|
|
13196
|
+
if (!attachment) {
|
|
13197
|
+
clipper.clipEnd(slot);
|
|
13198
|
+
continue;
|
|
13199
|
+
}
|
|
13032
13200
|
const slotColor = pose.color;
|
|
13033
13201
|
const alpha = slotColor.a;
|
|
13034
|
-
if (
|
|
13202
|
+
if (alpha === 0 && !(attachment instanceof ClippingAttachment)) {
|
|
13035
13203
|
clipper.clipEnd(slot);
|
|
13036
13204
|
continue;
|
|
13037
13205
|
}
|
|
@@ -13075,9 +13243,15 @@ ${error}` : ""}`);
|
|
|
13075
13243
|
indicesCount = indices.length;
|
|
13076
13244
|
texture = sequence.regions[sequenceIndex]?.texture;
|
|
13077
13245
|
} else if (attachment instanceof ClippingAttachment) {
|
|
13246
|
+
clipper.clipEnd(slot);
|
|
13078
13247
|
clipper.clipStart(skeleton, slot, attachment);
|
|
13079
13248
|
continue;
|
|
13080
13249
|
} else {
|
|
13250
|
+
clipper.clipEnd(slot);
|
|
13251
|
+
continue;
|
|
13252
|
+
}
|
|
13253
|
+
if (!texture) {
|
|
13254
|
+
clipper.clipEnd(slot);
|
|
13081
13255
|
continue;
|
|
13082
13256
|
}
|
|
13083
13257
|
const skelColor = skeleton.color;
|