@esotericsoftware/spine-core 4.3.10 → 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/SkeletonCoordinateConverter.d.ts +57 -0
- package/dist/SkeletonCoordinateConverter.js +30 -0
- package/dist/SkeletonPhysicsMovement.d.ts +134 -0
- package/dist/SkeletonPhysicsMovement.js +189 -0
- package/dist/esm/spine-core.min.mjs +2 -2
- package/dist/esm/spine-core.mjs +146 -0
- package/dist/esm/spine-core.mjs.map +3 -3
- package/dist/iife/spine-core.js +146 -0
- 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,
|
|
@@ -13027,6 +13028,151 @@ ${error}` : ""}`);
|
|
|
13027
13028
|
return map[property] !== void 0 ? map[property] : defaultValue;
|
|
13028
13029
|
}
|
|
13029
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
|
+
|
|
13030
13176
|
// spine-core/src/SkeletonRendererCore.ts
|
|
13031
13177
|
var SkeletonRendererCore = class {
|
|
13032
13178
|
commandPool = new CommandPool();
|