@esotericsoftware/spine-webgl 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/esm/spine-webgl.mjs
CHANGED
|
@@ -11033,7 +11033,7 @@ var SkeletonClipping = class {
|
|
|
11033
11033
|
t = triangles[i + 2];
|
|
11034
11034
|
const x3 = vertices[t * stride], y3 = vertices[t * stride + 1];
|
|
11035
11035
|
const u3 = uvs[t << 1], v3 = uvs[(t << 1) + 1];
|
|
11036
|
-
|
|
11036
|
+
let d0 = 0, d1 = 0, d2 = 0, d4 = 0, d = 0;
|
|
11037
11037
|
for (let p = 0; p < polygonsCount; p++) {
|
|
11038
11038
|
let s = clippedVertices.length;
|
|
11039
11039
|
if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p])) {
|
|
@@ -11041,6 +11041,13 @@ var SkeletonClipping = class {
|
|
|
11041
11041
|
const clipOutputLength = clipOutput.length;
|
|
11042
11042
|
if (clipOutputLength === 0) continue;
|
|
11043
11043
|
let clipOutputCount = clipOutputLength >> 1;
|
|
11044
|
+
if (d === 0) {
|
|
11045
|
+
d0 = y2 - y3;
|
|
11046
|
+
d1 = x3 - x2;
|
|
11047
|
+
d2 = x1 - x3;
|
|
11048
|
+
d4 = y3 - y1;
|
|
11049
|
+
d = 1 / (d0 * d2 - d1 * d4);
|
|
11050
|
+
}
|
|
11044
11051
|
const cv = Utils.setArraySize(clippedVertices, s + clipOutputCount * stride);
|
|
11045
11052
|
for (let ii = 0; ii < clipOutputLength; ii += 2, s += stride) {
|
|
11046
11053
|
const x = clipOutputItems[ii], y = clipOutputItems[ii + 1];
|
|
@@ -11240,7 +11247,7 @@ var SkeletonClipping = class {
|
|
|
11240
11247
|
const x3 = vertices[vertexStart + v], y3 = vertices[vertexStart + v + 1];
|
|
11241
11248
|
uv = t << 1;
|
|
11242
11249
|
const u3 = uvs[uv], v3 = uvs[uv + 1];
|
|
11243
|
-
|
|
11250
|
+
let d0 = 0, d1 = 0, d2 = 0, d4 = 0, d = 0;
|
|
11244
11251
|
for (let p = 0; p < polygonsCount; p++) {
|
|
11245
11252
|
let s = this.clippedVerticesLength;
|
|
11246
11253
|
if (this.clip(x1, y1, x2, y2, x3, y3, polygons[p])) {
|
|
@@ -11248,6 +11255,13 @@ var SkeletonClipping = class {
|
|
|
11248
11255
|
const clipOutputLength = clipOutput.length;
|
|
11249
11256
|
if (clipOutputLength === 0) continue;
|
|
11250
11257
|
let clipOutputCount = clipOutputLength >> 1;
|
|
11258
|
+
if (d === 0) {
|
|
11259
|
+
d0 = y2 - y3;
|
|
11260
|
+
d1 = x3 - x2;
|
|
11261
|
+
d2 = x1 - x3;
|
|
11262
|
+
d4 = y3 - y1;
|
|
11263
|
+
d = 1 / (d0 * d2 - d1 * d4);
|
|
11264
|
+
}
|
|
11251
11265
|
const newLength = s + clipOutputCount * stride;
|
|
11252
11266
|
if (clippedVertices.length < newLength) {
|
|
11253
11267
|
this._clippedVerticesTyped = new Float32Array(newLength * 2);
|
|
@@ -11364,16 +11378,15 @@ var SkeletonClipping = class {
|
|
|
11364
11378
|
const edgeX = v[i], edgeY = v[i + 1], ex = edgeX - v[i + 2], ey = edgeY - v[i + 3];
|
|
11365
11379
|
const outputStart = output.length;
|
|
11366
11380
|
const iv2 = input;
|
|
11367
|
-
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11381
|
+
x1 = iv2[0];
|
|
11382
|
+
y1 = iv2[1];
|
|
11383
|
+
let s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11384
|
+
for (let ii = 2, nn = input.length - 2; ii <= nn; ii += 2) {
|
|
11371
11385
|
x2 = iv2[ii];
|
|
11372
11386
|
y2 = iv2[ii + 1];
|
|
11373
|
-
const s2 = ey * (edgeX - x2)
|
|
11374
|
-
const s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11387
|
+
const s2 = ey * (edgeX - x2) - ex * (edgeY - y2);
|
|
11375
11388
|
if (s1 > 0) {
|
|
11376
|
-
if (s2)
|
|
11389
|
+
if (s2 > 0)
|
|
11377
11390
|
output.push(x2, y2);
|
|
11378
11391
|
else {
|
|
11379
11392
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
@@ -11383,7 +11396,7 @@ var SkeletonClipping = class {
|
|
|
11383
11396
|
} else
|
|
11384
11397
|
output.push(x2, y2);
|
|
11385
11398
|
}
|
|
11386
|
-
} else if (s2) {
|
|
11399
|
+
} else if (s2 > 0) {
|
|
11387
11400
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
11388
11401
|
if (t >= 0 && t <= 1) {
|
|
11389
11402
|
output.push(x1 + ix * t, y1 + iy * t, x2, y2);
|
|
@@ -11392,6 +11405,9 @@ var SkeletonClipping = class {
|
|
|
11392
11405
|
output.push(x2, y2);
|
|
11393
11406
|
} else
|
|
11394
11407
|
clipped = true;
|
|
11408
|
+
x1 = x2;
|
|
11409
|
+
y1 = y2;
|
|
11410
|
+
s1 = s2;
|
|
11395
11411
|
}
|
|
11396
11412
|
if (outputStart === output.length) {
|
|
11397
11413
|
originalOutput.length = 0;
|
|
@@ -11439,16 +11455,15 @@ var SkeletonClipping = class {
|
|
|
11439
11455
|
const outputStart = output.length, fragmentStart = this.inverseVertices.length;
|
|
11440
11456
|
this.inverseVertices.push(0);
|
|
11441
11457
|
iv = input;
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11458
|
+
x1 = iv[0];
|
|
11459
|
+
y1 = iv[1];
|
|
11460
|
+
let s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11461
|
+
for (let ii = 2, nn = input.length - 2; ii <= nn; ii += 2) {
|
|
11446
11462
|
x2 = iv[ii];
|
|
11447
11463
|
y2 = iv[ii + 1];
|
|
11448
|
-
const s2 = ey * (edgeX - x2)
|
|
11449
|
-
const s1 = ey * (edgeX - x1) - ex * (edgeY - y1);
|
|
11464
|
+
const s2 = ey * (edgeX - x2) - ex * (edgeY - y2);
|
|
11450
11465
|
if (s1 > 0) {
|
|
11451
|
-
if (s2)
|
|
11466
|
+
if (s2 > 0)
|
|
11452
11467
|
output.push(x2, y2);
|
|
11453
11468
|
else {
|
|
11454
11469
|
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
@@ -11459,16 +11474,19 @@ var SkeletonClipping = class {
|
|
|
11459
11474
|
} else
|
|
11460
11475
|
output.push(x2, y2);
|
|
11461
11476
|
}
|
|
11462
|
-
} else if (s2) {
|
|
11463
|
-
const
|
|
11477
|
+
} else if (s2 > 0) {
|
|
11478
|
+
const ix = x2 - x1, iy = y2 - y1, t = s1 / (ix * ey - iy * ex);
|
|
11464
11479
|
if (t >= 0 && t <= 1) {
|
|
11465
|
-
const cx = x1 +
|
|
11480
|
+
const cx = x1 + ix * t, cy = y1 + iy * t;
|
|
11466
11481
|
this.inverseVertices.push(cx, cy);
|
|
11467
11482
|
output.push(cx, cy, x2, y2);
|
|
11468
11483
|
} else
|
|
11469
11484
|
output.push(x2, y2);
|
|
11470
11485
|
} else
|
|
11471
11486
|
this.inverseVertices.push(x2, y2);
|
|
11487
|
+
x1 = x2;
|
|
11488
|
+
y1 = y2;
|
|
11489
|
+
s1 = s2;
|
|
11472
11490
|
}
|
|
11473
11491
|
const fragmentSize = this.inverseVertices.length - fragmentStart - 1;
|
|
11474
11492
|
if (fragmentSize >= 6)
|
|
@@ -12823,6 +12841,151 @@ function getValue(map, property, defaultValue) {
|
|
|
12823
12841
|
return map[property] !== void 0 ? map[property] : defaultValue;
|
|
12824
12842
|
}
|
|
12825
12843
|
|
|
12844
|
+
// spine-core/src/SkeletonPhysicsMovement.ts
|
|
12845
|
+
var SkeletonPhysicsMovement = class {
|
|
12846
|
+
/**
|
|
12847
|
+
* Creates a movement tracker for a skeleton displayed by a host runtime object.
|
|
12848
|
+
* @param skeleton The skeleton whose physics constraints receive inherited movement.
|
|
12849
|
+
* @param adapter Runtime-specific hooks used to read and convert the host object's transform.
|
|
12850
|
+
* @param options Initial movement inheritance values.
|
|
12851
|
+
*/
|
|
12852
|
+
constructor(skeleton, adapter, options = {}) {
|
|
12853
|
+
this.skeleton = skeleton;
|
|
12854
|
+
this.adapter = adapter;
|
|
12855
|
+
this.positionInheritanceFactorX = options.positionInheritanceX ?? 0;
|
|
12856
|
+
this.positionInheritanceFactorY = options.positionInheritanceY ?? 0;
|
|
12857
|
+
this.rotationInheritanceFactor = options.rotationInheritance ?? 0;
|
|
12858
|
+
}
|
|
12859
|
+
positionInheritanceFactorX = 0;
|
|
12860
|
+
positionInheritanceFactorY = 0;
|
|
12861
|
+
rotationInheritanceFactor = 0;
|
|
12862
|
+
hasLastTransform = false;
|
|
12863
|
+
lastX = 0;
|
|
12864
|
+
lastY = 0;
|
|
12865
|
+
lastZ = 0;
|
|
12866
|
+
lastRotation = 0;
|
|
12867
|
+
currentTransform = { x: 0, y: 0, z: 0, rotation: 0 };
|
|
12868
|
+
currentPosition = { x: 0, y: 0, z: 0 };
|
|
12869
|
+
lastPosition = { x: 0, y: 0, z: 0 };
|
|
12870
|
+
/** Horizontal position inheritance factor. `0` disables horizontal position inheritance. */
|
|
12871
|
+
get positionInheritanceX() {
|
|
12872
|
+
return this.positionInheritanceFactorX;
|
|
12873
|
+
}
|
|
12874
|
+
/** Vertical position inheritance factor. `0` disables vertical position inheritance. */
|
|
12875
|
+
get positionInheritanceY() {
|
|
12876
|
+
return this.positionInheritanceFactorY;
|
|
12877
|
+
}
|
|
12878
|
+
/**
|
|
12879
|
+
* Sets how much host object translation is inherited by skeleton physics constraints.
|
|
12880
|
+
* Use `(1, 1)` for normal inheritance, or `(0, 0)` to disable position inheritance.
|
|
12881
|
+
* @param x The horizontal position inheritance factor.
|
|
12882
|
+
* @param y The vertical position inheritance factor.
|
|
12883
|
+
*/
|
|
12884
|
+
setPositionInheritance(x, y) {
|
|
12885
|
+
const wasDisabled = this.positionInheritanceFactorX === 0 && this.positionInheritanceFactorY === 0;
|
|
12886
|
+
const isEnabled = x !== 0 || y !== 0;
|
|
12887
|
+
this.positionInheritanceFactorX = x;
|
|
12888
|
+
this.positionInheritanceFactorY = y;
|
|
12889
|
+
if (wasDisabled && isEnabled) this.resetPosition();
|
|
12890
|
+
}
|
|
12891
|
+
/** Rotation inheritance factor. `0` disables rotation inheritance. */
|
|
12892
|
+
get rotationInheritance() {
|
|
12893
|
+
return this.rotationInheritanceFactor;
|
|
12894
|
+
}
|
|
12895
|
+
/**
|
|
12896
|
+
* Sets how much host object rotation is inherited by skeleton physics constraints.
|
|
12897
|
+
* @param value The rotation inheritance factor.
|
|
12898
|
+
*/
|
|
12899
|
+
set rotationInheritance(value) {
|
|
12900
|
+
const wasDisabled = this.rotationInheritanceFactor === 0;
|
|
12901
|
+
this.rotationInheritanceFactor = value;
|
|
12902
|
+
if (wasDisabled && value !== 0) this.resetRotation();
|
|
12903
|
+
}
|
|
12904
|
+
/** Resets the previous position used to calculate inherited translation. */
|
|
12905
|
+
resetPosition() {
|
|
12906
|
+
const transform = this.currentTransform;
|
|
12907
|
+
const readRotation = !this.hasLastTransform && this.rotationInheritanceFactor !== 0;
|
|
12908
|
+
this.adapter.readTransform(transform, readRotation);
|
|
12909
|
+
this.lastX = transform.x;
|
|
12910
|
+
this.lastY = transform.y;
|
|
12911
|
+
this.lastZ = transform.z;
|
|
12912
|
+
if (readRotation) this.lastRotation = transform.rotation;
|
|
12913
|
+
this.hasLastTransform = true;
|
|
12914
|
+
}
|
|
12915
|
+
/** Resets the previous rotation used to calculate inherited rotation. */
|
|
12916
|
+
resetRotation() {
|
|
12917
|
+
const transform = this.currentTransform;
|
|
12918
|
+
this.adapter.readTransform(transform, true);
|
|
12919
|
+
this.lastRotation = transform.rotation;
|
|
12920
|
+
if (!this.hasLastTransform) {
|
|
12921
|
+
this.lastX = transform.x;
|
|
12922
|
+
this.lastY = transform.y;
|
|
12923
|
+
this.lastZ = transform.z;
|
|
12924
|
+
}
|
|
12925
|
+
this.hasLastTransform = true;
|
|
12926
|
+
}
|
|
12927
|
+
/** Resets both previous position and previous rotation. */
|
|
12928
|
+
resetTransform() {
|
|
12929
|
+
const transform = this.currentTransform;
|
|
12930
|
+
this.adapter.readTransform(transform, true);
|
|
12931
|
+
this.setLastTransform(transform.x, transform.y, transform.z, transform.rotation);
|
|
12932
|
+
}
|
|
12933
|
+
/**
|
|
12934
|
+
* Applies host object transform movement since the previous call to the skeleton's physics constraints.
|
|
12935
|
+
*
|
|
12936
|
+
* The first call records the current transform as the baseline and does not apply movement.
|
|
12937
|
+
*/
|
|
12938
|
+
applyTransformMovement() {
|
|
12939
|
+
const inheritPosition = this.positionInheritanceFactorX !== 0 || this.positionInheritanceFactorY !== 0;
|
|
12940
|
+
const inheritRotation = this.rotationInheritanceFactor !== 0;
|
|
12941
|
+
if (!inheritPosition && !inheritRotation) return;
|
|
12942
|
+
const transform = this.currentTransform;
|
|
12943
|
+
this.adapter.readTransform(transform, inheritRotation);
|
|
12944
|
+
const { x, y, z } = transform;
|
|
12945
|
+
const currentRotation = inheritRotation ? transform.rotation : this.lastRotation;
|
|
12946
|
+
const positionChanged = x !== this.lastX || y !== this.lastY || z !== this.lastZ;
|
|
12947
|
+
if (this.hasLastTransform) {
|
|
12948
|
+
if (!positionChanged && currentRotation === this.lastRotation) return;
|
|
12949
|
+
if (inheritPosition && positionChanged) this.applyPositionMovement(x, y, z);
|
|
12950
|
+
if (inheritRotation && currentRotation !== this.lastRotation) this.applyRotationMovement(currentRotation);
|
|
12951
|
+
}
|
|
12952
|
+
this.setLastTransform(x, y, z, currentRotation);
|
|
12953
|
+
}
|
|
12954
|
+
applyPositionMovement(currentX, currentY, currentZ) {
|
|
12955
|
+
const currentPosition = this.currentPosition;
|
|
12956
|
+
currentPosition.x = currentX;
|
|
12957
|
+
currentPosition.y = currentY;
|
|
12958
|
+
currentPosition.z = currentZ;
|
|
12959
|
+
this.adapter.worldToSkeleton(currentPosition);
|
|
12960
|
+
const lastPosition = this.lastPosition;
|
|
12961
|
+
lastPosition.x = this.lastX;
|
|
12962
|
+
lastPosition.y = this.lastY;
|
|
12963
|
+
lastPosition.z = this.lastZ;
|
|
12964
|
+
this.adapter.worldToSkeleton(lastPosition);
|
|
12965
|
+
this.skeleton.physicsTranslate(
|
|
12966
|
+
(currentPosition.x - lastPosition.x) * this.positionInheritanceFactorX,
|
|
12967
|
+
(currentPosition.y - lastPosition.y) * this.positionInheritanceFactorY
|
|
12968
|
+
);
|
|
12969
|
+
}
|
|
12970
|
+
applyRotationMovement(currentRotation) {
|
|
12971
|
+
const rotationFactor = this.rotationInheritanceFactor;
|
|
12972
|
+
if (rotationFactor === 0) return;
|
|
12973
|
+
this.skeleton.physicsRotate(0, 0, this.getRotationDelta(currentRotation, this.lastRotation) * rotationFactor);
|
|
12974
|
+
}
|
|
12975
|
+
setLastTransform(x, y, z, rotation) {
|
|
12976
|
+
this.lastX = x;
|
|
12977
|
+
this.lastY = y;
|
|
12978
|
+
this.lastZ = z;
|
|
12979
|
+
this.lastRotation = rotation;
|
|
12980
|
+
this.hasLastTransform = true;
|
|
12981
|
+
}
|
|
12982
|
+
getRotationDelta(current, previous) {
|
|
12983
|
+
let delta = current - previous;
|
|
12984
|
+
delta = (delta + 180) % 360 - 180;
|
|
12985
|
+
return delta < -180 ? delta + 360 : delta;
|
|
12986
|
+
}
|
|
12987
|
+
};
|
|
12988
|
+
|
|
12826
12989
|
// spine-core/src/SkeletonRendererCore.ts
|
|
12827
12990
|
var SkeletonRendererCore = class {
|
|
12828
12991
|
commandPool = new CommandPool();
|
|
@@ -12835,17 +12998,21 @@ var SkeletonRendererCore = class {
|
|
|
12835
12998
|
this.renderCommands.length = 0;
|
|
12836
12999
|
const clipper = this.clipping;
|
|
12837
13000
|
const drawOrder = skeleton.drawOrder.appliedPose;
|
|
12838
|
-
for (let i = 0; i <
|
|
13001
|
+
for (let i = 0, n = drawOrder.length; i < n; i++) {
|
|
12839
13002
|
const slot = drawOrder[i];
|
|
12840
|
-
|
|
12841
|
-
if (!attachment) {
|
|
13003
|
+
if (!slot.bone.active) {
|
|
12842
13004
|
clipper.clipEnd(slot);
|
|
12843
13005
|
continue;
|
|
12844
13006
|
}
|
|
12845
13007
|
const pose = slot.appliedPose;
|
|
13008
|
+
const attachment = pose.attachment;
|
|
13009
|
+
if (!attachment) {
|
|
13010
|
+
clipper.clipEnd(slot);
|
|
13011
|
+
continue;
|
|
13012
|
+
}
|
|
12846
13013
|
const slotColor = pose.color;
|
|
12847
13014
|
const alpha = slotColor.a;
|
|
12848
|
-
if (
|
|
13015
|
+
if (alpha === 0 && !(attachment instanceof ClippingAttachment)) {
|
|
12849
13016
|
clipper.clipEnd(slot);
|
|
12850
13017
|
continue;
|
|
12851
13018
|
}
|
|
@@ -12889,9 +13056,15 @@ var SkeletonRendererCore = class {
|
|
|
12889
13056
|
indicesCount = indices.length;
|
|
12890
13057
|
texture = sequence.regions[sequenceIndex]?.texture;
|
|
12891
13058
|
} else if (attachment instanceof ClippingAttachment) {
|
|
13059
|
+
clipper.clipEnd(slot);
|
|
12892
13060
|
clipper.clipStart(skeleton, slot, attachment);
|
|
12893
13061
|
continue;
|
|
12894
13062
|
} else {
|
|
13063
|
+
clipper.clipEnd(slot);
|
|
13064
|
+
continue;
|
|
13065
|
+
}
|
|
13066
|
+
if (!texture) {
|
|
13067
|
+
clipper.clipEnd(slot);
|
|
12895
13068
|
continue;
|
|
12896
13069
|
}
|
|
12897
13070
|
const skelColor = skeleton.color;
|
|
@@ -15902,6 +16075,7 @@ export {
|
|
|
15902
16075
|
SkeletonData,
|
|
15903
16076
|
SkeletonDebugRenderer,
|
|
15904
16077
|
SkeletonJson,
|
|
16078
|
+
SkeletonPhysicsMovement,
|
|
15905
16079
|
SkeletonRenderer,
|
|
15906
16080
|
SkeletonRendererCore,
|
|
15907
16081
|
Skin,
|