mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts] More 4.0 porting, SkeletonJson and SkeletonBinary still broken.
This commit is contained in:
parent
1d59409bde
commit
cf728e25dc
File diff suppressed because it is too large
Load Diff
@ -406,9 +406,9 @@ module spine {
|
||||
}
|
||||
|
||||
let rotateTimeline = timeline as RotateTimeline;
|
||||
let frames = rotateTimeline.frames;
|
||||
let bone = skeleton.bones[rotateTimeline.boneIndex];
|
||||
if (!bone.active) return;
|
||||
let frames = rotateTimeline.frames;
|
||||
let r1 = 0, r2 = 0;
|
||||
if (time < frames[0]) {
|
||||
switch (blend) {
|
||||
@ -481,7 +481,7 @@ module spine {
|
||||
for (; i < n; i++) {
|
||||
let event = events[i];
|
||||
if (event.time < animationStart) continue; // Discard events outside animation start/end.
|
||||
this.queue.event(entry, events[i]);
|
||||
this.queue.event(entry, event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1029,7 +1029,7 @@ module spine {
|
||||
getTrackComplete() {
|
||||
let duration = this.animationEnd - this.animationStart;
|
||||
if (duration != 0) {
|
||||
if (this.loop) return duration * (1 + Math.floor(this.trackTime / duration)); // Completion of next loop.
|
||||
if (this.loop) return duration * (1 + ((this.trackTime / duration) | 0)); // Completion of next loop.
|
||||
if (this.trackTime < duration) return duration; // Before duration.
|
||||
}
|
||||
return this.trackTime; // Next update.
|
||||
|
||||
@ -339,11 +339,10 @@ module spine {
|
||||
|
||||
/** Transforms a point from world coordinates to the bone's local coordinates. */
|
||||
worldToLocal (world: Vector2) {
|
||||
let a = this.a, b = this.b, c = this.c, d = this.d;
|
||||
let det = a * d - b * c;
|
||||
let invDet = 1 / (this.a * this.d - this.b * this.c);
|
||||
let x = world.x - this.worldX, y = world.y - this.worldY;
|
||||
world.x = (x * d - y * b) / det;
|
||||
world.y = (y * a - x * c) / det;
|
||||
world.x = x * this.d * invDet - y * this.b * invDet;
|
||||
world.y = y * this.a * invDet - x * this.c * invDet;
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
@ -80,11 +80,6 @@ module spine {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
/** Applies the constraint to the constrained bones. */
|
||||
apply () {
|
||||
this.update();
|
||||
}
|
||||
|
||||
update () {
|
||||
if (this.mix == 0) return;
|
||||
let target = this.target;
|
||||
|
||||
@ -52,11 +52,11 @@ module spine {
|
||||
/** The spacing between bones. */
|
||||
spacing = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
|
||||
rotateMix = 0;
|
||||
mixRotate = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translations. */
|
||||
translateMix = 0;
|
||||
mixX = 0;
|
||||
|
||||
mixY = 0;
|
||||
|
||||
spaces = new Array<number>(); positions = new Array<number>();
|
||||
world = new Array<number>(); curves = new Array<number>(); lengths = new Array<number>();
|
||||
@ -74,8 +74,9 @@ module spine {
|
||||
this.target = skeleton.findSlot(data.target.name);
|
||||
this.position = data.position;
|
||||
this.spacing = data.spacing;
|
||||
this.rotateMix = data.rotateMix;
|
||||
this.translateMix = data.translateMix;
|
||||
this.mixRotate = data.mixRotate;
|
||||
this.mixX = data.mixX;
|
||||
this.mixY = data.mixY;
|
||||
}
|
||||
|
||||
isActive () {
|
||||
@ -86,52 +87,77 @@ module spine {
|
||||
let attachment = this.target.getAttachment();
|
||||
if (!(attachment instanceof PathAttachment)) return;
|
||||
|
||||
let rotateMix = this.rotateMix, translateMix = this.translateMix;
|
||||
let translate = translateMix > 0, rotate = rotateMix > 0;
|
||||
if (!translate && !rotate) return;
|
||||
let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY;
|
||||
if (mixRotate == 0 && mixX == 0 && mixY == 0) return;
|
||||
|
||||
let data = this.data;
|
||||
let percentSpacing = data.spacingMode == SpacingMode.Percent;
|
||||
let rotateMode = data.rotateMode;
|
||||
let tangents = rotateMode == RotateMode.Tangent, scale = rotateMode == RotateMode.ChainScale;
|
||||
let tangents = data.rotateMode == RotateMode.Tangent, scale = data.rotateMode == RotateMode.ChainScale;
|
||||
|
||||
let boneCount = this.bones.length, spacesCount = tangents ? boneCount : boneCount + 1;
|
||||
let bones = this.bones;
|
||||
let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths: Array<number> = null;
|
||||
let spaces = Utils.setArraySize(this.spaces, spacesCount), lengths: Array<number> = scale ? this.lengths = Utils.setArraySize(this.lengths, boneCount) : null;
|
||||
let spacing = this.spacing;
|
||||
if (scale || !percentSpacing) {
|
||||
if (scale) lengths = Utils.setArraySize(this.lengths, boneCount);
|
||||
let lengthSpacing = data.spacingMode == SpacingMode.Length;
|
||||
for (let i = 0, n = spacesCount - 1; i < n;) {
|
||||
let bone = bones[i];
|
||||
let setupLength = bone.data.length;
|
||||
if (setupLength < PathConstraint.epsilon) {
|
||||
if (scale) lengths[i] = 0;
|
||||
spaces[++i] = 0;
|
||||
} else if (percentSpacing) {
|
||||
if (scale) {
|
||||
|
||||
switch (data.spacingMode) {
|
||||
case SpacingMode.Percent:
|
||||
if (scale) {
|
||||
for (let i = 0, n = spacesCount - 1; i < n; i++) {
|
||||
let bone = bones[i];
|
||||
let setupLength = bone.data.length;
|
||||
if (setupLength < PathConstraint.epsilon)
|
||||
lengths[i] = 0;
|
||||
else {
|
||||
let x = setupLength * bone.a, y = setupLength * bone.c;
|
||||
lengths[i] = Math.sqrt(x * x + y * y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils.arrayFill(spaces, 1, spacesCount, spacing);
|
||||
break;
|
||||
case SpacingMode.Proportional:
|
||||
let sum = 0;
|
||||
for (let i = 0; i < boneCount;) {
|
||||
let bone = bones[i];
|
||||
let setupLength = bone.data.length;
|
||||
if (setupLength < PathConstraint.epsilon) {
|
||||
if (scale) lengths[i] = 0;
|
||||
spaces[++i] = spacing;
|
||||
} else {
|
||||
let x = setupLength * bone.a, y = setupLength * bone.c;
|
||||
let length = Math.sqrt(x * x + y * y);
|
||||
lengths[i] = length;
|
||||
if (scale) lengths[i] = length;
|
||||
spaces[++i] = length;
|
||||
sum += length;
|
||||
}
|
||||
}
|
||||
if (sum > 0) {
|
||||
sum = spacesCount / sum * spacing;
|
||||
for (let i = 1; i < spacesCount; i++)
|
||||
spaces[i] *= sum;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
let lengthSpacing = data.spacingMode == SpacingMode.Length;
|
||||
for (let i = 0, n = spacesCount - 1; i < n;) {
|
||||
let bone = bones[i];
|
||||
let setupLength = bone.data.length;
|
||||
if (setupLength < PathConstraint.epsilon) {
|
||||
if (scale) lengths[i] = 0;
|
||||
spaces[++i] = spacing;
|
||||
} else {
|
||||
let x = setupLength * bone.a, y = setupLength * bone.c;
|
||||
let length = Math.sqrt(x * x + y * y);
|
||||
if (scale) lengths[i] = length;
|
||||
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
|
||||
}
|
||||
spaces[++i] = spacing;
|
||||
} else {
|
||||
let x = setupLength * bone.a, y = setupLength * bone.c;
|
||||
let length = Math.sqrt(x * x + y * y);
|
||||
if (scale) lengths[i] = length;
|
||||
spaces[++i] = (lengthSpacing ? setupLength + spacing : spacing) * length / setupLength;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let i = 1; i < spacesCount; i++)
|
||||
spaces[i] = spacing;
|
||||
}
|
||||
|
||||
let positions = this.computeWorldPositions(<PathAttachment>attachment, spacesCount, tangents,
|
||||
data.positionMode == PositionMode.Percent, percentSpacing);
|
||||
let positions = this.computeWorldPositions(<PathAttachment>attachment, spacesCount, tangents);
|
||||
let boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation;
|
||||
let tip = false;
|
||||
if (offsetRotation == 0)
|
||||
tip = rotateMode == RotateMode.Chain;
|
||||
tip = data.rotateMode == RotateMode.Chain;
|
||||
else {
|
||||
tip = false;
|
||||
let p = this.target.bone;
|
||||
@ -139,20 +165,20 @@ module spine {
|
||||
}
|
||||
for (let i = 0, p = 3; i < boneCount; i++, p += 3) {
|
||||
let bone = bones[i];
|
||||
bone.worldX += (boneX - bone.worldX) * translateMix;
|
||||
bone.worldY += (boneY - bone.worldY) * translateMix;
|
||||
bone.worldX += (boneX - bone.worldX) * mixX;
|
||||
bone.worldY += (boneY - bone.worldY) * mixY;
|
||||
let x = positions[p], y = positions[p + 1], dx = x - boneX, dy = y - boneY;
|
||||
if (scale) {
|
||||
let length = lengths[i];
|
||||
if (length != 0) {
|
||||
let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1;
|
||||
let s = (Math.sqrt(dx * dx + dy * dy) / length - 1) * mixRotate + 1;
|
||||
bone.a *= s;
|
||||
bone.c *= s;
|
||||
}
|
||||
}
|
||||
boneX = x;
|
||||
boneY = y;
|
||||
if (rotate) {
|
||||
if (mixRotate > 0) {
|
||||
let a = bone.a, b = bone.b, c = bone.c, d = bone.d, r = 0, cos = 0, sin = 0;
|
||||
if (tangents)
|
||||
r = positions[p - 1];
|
||||
@ -165,8 +191,8 @@ module spine {
|
||||
cos = Math.cos(r);
|
||||
sin = Math.sin(r);
|
||||
let length = bone.data.length;
|
||||
boneX += (length * (cos * a - sin * c) - dx) * rotateMix;
|
||||
boneY += (length * (sin * a + cos * c) - dy) * rotateMix;
|
||||
boneX += (length * (cos * a - sin * c) - dx) * mixRotate;
|
||||
boneY += (length * (sin * a + cos * c) - dy) * mixRotate;
|
||||
} else {
|
||||
r += offsetRotation;
|
||||
}
|
||||
@ -174,7 +200,7 @@ module spine {
|
||||
r -= MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI) //
|
||||
r += MathUtils.PI2;
|
||||
r *= rotateMix;
|
||||
r *= mixRotate;
|
||||
cos = Math.cos(r);
|
||||
sin = Math.sin(r);
|
||||
bone.a = cos * a - sin * c;
|
||||
@ -186,8 +212,7 @@ module spine {
|
||||
}
|
||||
}
|
||||
|
||||
computeWorldPositions (path: PathAttachment, spacesCount: number, tangents: boolean, percentPosition: boolean,
|
||||
percentSpacing: boolean) {
|
||||
computeWorldPositions (path: PathAttachment, spacesCount: number, tangents: boolean) {
|
||||
let target = this.target;
|
||||
let position = this.position;
|
||||
let spaces = this.spaces, out = Utils.setArraySize(this.positions, spacesCount * 3 + 2), world: Array<number> = null;
|
||||
@ -198,14 +223,22 @@ module spine {
|
||||
let lengths = path.lengths;
|
||||
curveCount -= closed ? 1 : 2;
|
||||
let pathLength = lengths[curveCount];
|
||||
if (percentPosition) position *= pathLength;
|
||||
if (percentSpacing) {
|
||||
for (let i = 1; i < spacesCount; i++)
|
||||
spaces[i] *= pathLength;
|
||||
if (this.data.positionMode == PositionMode.Percent) position *= pathLength;
|
||||
|
||||
let multiplier;
|
||||
switch (this.data.spacingMode) {
|
||||
case SpacingMode.Percent:
|
||||
multiplier = pathLength;
|
||||
break;
|
||||
case SpacingMode.Proportional:
|
||||
multiplier = pathLength / spacesCount;
|
||||
break;
|
||||
default:
|
||||
multiplier = 1;
|
||||
}
|
||||
world = Utils.setArraySize(this.world, 8);
|
||||
for (let i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
|
||||
let space = spaces[i];
|
||||
let space = spaces[i] * multiplier;
|
||||
position += space;
|
||||
let p = position;
|
||||
|
||||
@ -306,19 +339,25 @@ module spine {
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
if (percentPosition)
|
||||
position *= pathLength;
|
||||
else
|
||||
position *= pathLength / path.lengths[curveCount - 1];
|
||||
if (percentSpacing) {
|
||||
for (let i = 1; i < spacesCount; i++)
|
||||
spaces[i] *= pathLength;
|
||||
|
||||
if (this.data.positionMode == PositionMode.Percent) position *= pathLength;
|
||||
|
||||
let multiplier = 0;
|
||||
switch (this.data.spacingMode) {
|
||||
case SpacingMode.Percent:
|
||||
multiplier = pathLength;
|
||||
break;
|
||||
case SpacingMode.Proportional:
|
||||
multiplier = pathLength / spacesCount;
|
||||
break;
|
||||
default:
|
||||
multiplier = 1;
|
||||
}
|
||||
|
||||
let segments = this.segments;
|
||||
let curveLength = 0;
|
||||
for (let i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
|
||||
let space = spaces[i];
|
||||
let space = spaces[i] * multiplier;
|
||||
position += space;
|
||||
let p = position;
|
||||
|
||||
|
||||
@ -58,11 +58,9 @@ module spine {
|
||||
/** The spacing between bones. */
|
||||
spacing: number;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
|
||||
rotateMix: number;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translations. */
|
||||
translateMix: number;
|
||||
mixRotate = 0;
|
||||
mixX = 0;
|
||||
mixY = 0;
|
||||
|
||||
constructor (name: string) {
|
||||
super(name, 0, false);
|
||||
@ -80,7 +78,7 @@ module spine {
|
||||
*
|
||||
* [Spacing mode](http://esotericsoftware.com/spine-path-constraints#Spacing-mode) in the Spine User Guide. */
|
||||
export enum SpacingMode {
|
||||
Length, Fixed, Percent
|
||||
Length, Fixed, Percent, Proportional
|
||||
}
|
||||
|
||||
/** Controls how bones are rotated, translated, and scaled to match the path.
|
||||
|
||||
@ -269,10 +269,10 @@ module spine {
|
||||
|
||||
this._updateCache.push(constraint);
|
||||
|
||||
for (let ii = 0; ii < boneCount; ii++)
|
||||
this.sortReset(constrained[ii].children);
|
||||
for (let ii = 0; ii < boneCount; ii++)
|
||||
constrained[ii].sorted = true;
|
||||
for (let i = 0; i < boneCount; i++)
|
||||
this.sortReset(constrained[i].children);
|
||||
for (let i = 0; i < boneCount; i++)
|
||||
constrained[i].sorted = true;
|
||||
}
|
||||
|
||||
sortPathConstraintAttachment (skin: Skin, slotIndex: number, slotBone: Bone) {
|
||||
@ -290,13 +290,11 @@ module spine {
|
||||
this.sortBone(slotBone);
|
||||
else {
|
||||
let bones = this.bones;
|
||||
let i = 0;
|
||||
while (i < pathBones.length) {
|
||||
let boneCount = pathBones[i++];
|
||||
for (let n = i + boneCount; i < n; i++) {
|
||||
let boneIndex = pathBones[i];
|
||||
this.sortBone(bones[boneIndex]);
|
||||
}
|
||||
for (let i = 0, n = pathBones.length; i < n;) {
|
||||
let nn = pathBones[i++];
|
||||
nn += i;
|
||||
while (i < nn)
|
||||
this.sortBone(bones[pathBones[i++]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,10 +377,12 @@ module spine {
|
||||
for (let i = 0, n = transformConstraints.length; i < n; i++) {
|
||||
let constraint = transformConstraints[i];
|
||||
let data = constraint.data;
|
||||
constraint.rotateMix = data.rotateMix;
|
||||
constraint.translateMix = data.translateMix;
|
||||
constraint.scaleMix = data.scaleMix;
|
||||
constraint.shearMix = data.shearMix;
|
||||
constraint.mixRotate = data.mixRotate;
|
||||
constraint.mixX = data.mixX;
|
||||
constraint.mixY = data.mixY;
|
||||
constraint.mixScaleX = data.mixScaleX;
|
||||
constraint.mixScaleY = data.mixScaleY;
|
||||
constraint.mixShearY = data.mixShearY;
|
||||
}
|
||||
|
||||
let pathConstraints = this.pathConstraints;
|
||||
@ -391,8 +391,9 @@ module spine {
|
||||
let data = constraint.data;
|
||||
constraint.position = data.position;
|
||||
constraint.spacing = data.spacing;
|
||||
constraint.rotateMix = data.rotateMix;
|
||||
constraint.translateMix = data.translateMix;
|
||||
constraint.mixRotate = data.mixRotate;
|
||||
constraint.mixX = data.mixX;
|
||||
constraint.mixY = data.mixY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -44,17 +44,7 @@ module spine {
|
||||
/** The target bone whose world transform will be copied to the constrained bones. */
|
||||
target: Bone;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
|
||||
rotateMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translations. */
|
||||
translateMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained scales. */
|
||||
scaleMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained scales. */
|
||||
shearMix = 0;
|
||||
mixRotate = 0; mixX = 0; mixY = 0; mixScaleX = 0; mixScaleY = 0; mixShearY = 0;
|
||||
|
||||
temp = new Vector2();
|
||||
active = false;
|
||||
@ -63,10 +53,12 @@ module spine {
|
||||
if (data == null) throw new Error("data cannot be null.");
|
||||
if (skeleton == null) throw new Error("skeleton cannot be null.");
|
||||
this.data = data;
|
||||
this.rotateMix = data.rotateMix;
|
||||
this.translateMix = data.translateMix;
|
||||
this.scaleMix = data.scaleMix;
|
||||
this.shearMix = data.shearMix;
|
||||
this.mixRotate = data.mixRotate;
|
||||
this.mixX = data.mixX;
|
||||
this.mixY = data.mixY;
|
||||
this.mixScaleX = data.mixScaleX;
|
||||
this.mixScaleY = data.mixScaleY;
|
||||
this.mixShearY = data.mixShearY;
|
||||
this.bones = new Array<Bone>();
|
||||
for (let i = 0; i < data.bones.length; i++)
|
||||
this.bones.push(skeleton.findBone(data.bones[i].name));
|
||||
@ -78,7 +70,7 @@ module spine {
|
||||
}
|
||||
|
||||
update () {
|
||||
if (this.rotateMix == 0 && this.translateMix == 0 && this.scaleMix == 0 && this.shearMix == 0) return;
|
||||
if (this.mixRotate == 0 && this.mixX == 0 && this.mixY == 0 && this.mixScaleX == 0 && this.mixScaleX == 0 && this.mixShearY == 0) return;
|
||||
|
||||
if (this.data.local) {
|
||||
if (this.data.relative)
|
||||
@ -95,24 +87,27 @@ module spine {
|
||||
}
|
||||
|
||||
applyAbsoluteWorld () {
|
||||
let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||
let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
|
||||
mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
|
||||
let translate = mixX != 0 || mixY != 0;
|
||||
let target = this.target;
|
||||
let ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
||||
let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
|
||||
let offsetRotation = this.data.offsetRotation * degRadReflect;
|
||||
let offsetShearY = this.data.offsetShearY * degRadReflect;
|
||||
|
||||
let bones = this.bones;
|
||||
for (let i = 0, n = bones.length; i < n; i++) {
|
||||
let bone = bones[i];
|
||||
|
||||
if (rotateMix != 0) {
|
||||
if (mixRotate != 0) {
|
||||
let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||
let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
|
||||
if (r > MathUtils.PI)
|
||||
r -= MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI)
|
||||
else if (r < -MathUtils.PI) //
|
||||
r += MathUtils.PI2;
|
||||
r *= rotateMix;
|
||||
r *= mixRotate;
|
||||
let cos = Math.cos(r), sin = Math.sin(r);
|
||||
bone.a = cos * a - sin * c;
|
||||
bone.b = cos * b - sin * d;
|
||||
@ -120,38 +115,40 @@ module spine {
|
||||
bone.d = sin * b + cos * d;
|
||||
}
|
||||
|
||||
if (translateMix != 0) {
|
||||
if (translate) {
|
||||
let temp = this.temp;
|
||||
target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
|
||||
bone.worldX += (temp.x - bone.worldX) * translateMix;
|
||||
bone.worldY += (temp.y - bone.worldY) * translateMix;
|
||||
bone.worldX += (temp.x - bone.worldX) * mixX;
|
||||
bone.worldY += (temp.y - bone.worldY) * mixY;
|
||||
}
|
||||
|
||||
if (scaleMix > 0) {
|
||||
if (mixScaleX != 0) {
|
||||
let s = Math.sqrt(bone.a * bone.a + bone.c * bone.c);
|
||||
let ts = Math.sqrt(ta * ta + tc * tc);
|
||||
if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleX) * scaleMix) / s;
|
||||
if (s != 0) s = (s + (Math.sqrt(ta * ta + tc * tc) - s + this.data.offsetScaleX) * mixScaleX) / s;
|
||||
bone.a *= s;
|
||||
bone.c *= s;
|
||||
s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
|
||||
ts = Math.sqrt(tb * tb + td * td);
|
||||
if (s > 0.00001) s = (s + (ts - s + this.data.offsetScaleY) * scaleMix) / s;
|
||||
}
|
||||
if (mixScaleY != 0) {
|
||||
let s = Math.sqrt(bone.b * bone.b + bone.d * bone.d);
|
||||
if (s != 0) s = (s + (Math.sqrt(tb * tb + td * td) - s + this.data.offsetScaleY) * mixScaleY) / s;
|
||||
bone.b *= s;
|
||||
bone.d *= s;
|
||||
|
||||
}
|
||||
|
||||
if (shearMix > 0) {
|
||||
if (mixShearY > 0) {
|
||||
let b = bone.b, d = bone.d;
|
||||
let by = Math.atan2(d, b);
|
||||
let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
|
||||
if (r > MathUtils.PI)
|
||||
r -= MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI)
|
||||
else if (r < -MathUtils.PI) //
|
||||
r += MathUtils.PI2;
|
||||
r = by + (r + offsetShearY) * shearMix;
|
||||
r = by + (r + offsetShearY) * mixShearY;
|
||||
let s = Math.sqrt(b * b + d * d);
|
||||
bone.b = Math.cos(r) * s;
|
||||
bone.d = Math.sin(r) * s;
|
||||
|
||||
}
|
||||
|
||||
bone.appliedValid = false;
|
||||
@ -159,55 +156,59 @@ module spine {
|
||||
}
|
||||
|
||||
applyRelativeWorld () {
|
||||
let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||
let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
|
||||
mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
|
||||
let translate = mixX != 0 || mixY != 0;
|
||||
|
||||
let target = this.target;
|
||||
let ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
||||
let degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
|
||||
let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
|
||||
|
||||
let bones = this.bones;
|
||||
for (let i = 0, n = bones.length; i < n; i++) {
|
||||
let bone = bones[i];
|
||||
|
||||
if (rotateMix != 0) {
|
||||
if (mixRotate != 0) {
|
||||
let a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||
let r = Math.atan2(tc, ta) + offsetRotation;
|
||||
if (r > MathUtils.PI)
|
||||
r -= MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI) r += MathUtils.PI2;
|
||||
r *= rotateMix;
|
||||
else if (r < -MathUtils.PI) //
|
||||
r += MathUtils.PI2;
|
||||
r *= mixRotate;
|
||||
let cos = Math.cos(r), sin = Math.sin(r);
|
||||
bone.a = cos * a - sin * c;
|
||||
bone.b = cos * b - sin * d;
|
||||
bone.c = sin * a + cos * c;
|
||||
bone.d = sin * b + cos * d;
|
||||
|
||||
}
|
||||
|
||||
if (translateMix != 0) {
|
||||
let temp = this.temp;
|
||||
target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
|
||||
bone.worldX += temp.x * translateMix;
|
||||
bone.worldY += temp.y * translateMix;
|
||||
}
|
||||
|
||||
if (scaleMix > 0) {
|
||||
let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * scaleMix + 1;
|
||||
if (mixScaleX != 0) {
|
||||
let s = (Math.sqrt(ta * ta + tc * tc) - 1 + this.data.offsetScaleX) * mixScaleX + 1;
|
||||
bone.a *= s;
|
||||
bone.c *= s;
|
||||
s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * scaleMix + 1;
|
||||
}
|
||||
if (mixScaleY != 0) {
|
||||
let s = (Math.sqrt(tb * tb + td * td) - 1 + this.data.offsetScaleY) * mixScaleY + 1;
|
||||
bone.b *= s;
|
||||
bone.d *= s;
|
||||
|
||||
}
|
||||
|
||||
if (shearMix > 0) {
|
||||
if (mixShearY > 0) {
|
||||
let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
|
||||
if (r > MathUtils.PI)
|
||||
r -= MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI) r += MathUtils.PI2;
|
||||
else if (r < -MathUtils.PI) //
|
||||
r += MathUtils.PI2;
|
||||
let b = bone.b, d = bone.d;
|
||||
r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * shearMix;
|
||||
r = Math.atan2(d, b) + (r - MathUtils.PI / 2 + offsetShearY) * mixShearY;
|
||||
let s = Math.sqrt(b * b + d * d);
|
||||
bone.b = Math.cos(r) * s;
|
||||
bone.d = Math.sin(r) * s;
|
||||
|
||||
}
|
||||
|
||||
bone.appliedValid = false;
|
||||
@ -215,38 +216,39 @@ module spine {
|
||||
}
|
||||
|
||||
applyAbsoluteLocal () {
|
||||
let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||
let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
|
||||
mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
|
||||
|
||||
let target = this.target;
|
||||
if (!target.appliedValid) target.updateAppliedTransform();
|
||||
|
||||
let bones = this.bones;
|
||||
for (let i = 0, n = bones.length; i < n; i++) {
|
||||
let bone = bones[i];
|
||||
if (!bone.appliedValid) bone.updateAppliedTransform();
|
||||
|
||||
let rotation = bone.arotation;
|
||||
if (rotateMix != 0) {
|
||||
if (mixRotate != 0) {
|
||||
let r = target.arotation - rotation + this.data.offsetRotation;
|
||||
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
|
||||
rotation += r * rotateMix;
|
||||
rotation += r * mixRotate;
|
||||
}
|
||||
|
||||
let x = bone.ax, y = bone.ay;
|
||||
if (translateMix != 0) {
|
||||
x += (target.ax - x + this.data.offsetX) * translateMix;
|
||||
y += (target.ay - y + this.data.offsetY) * translateMix;
|
||||
}
|
||||
x += (target.ax - x + this.data.offsetX) * mixX;
|
||||
y += (target.ay - y + this.data.offsetY) * mixY;
|
||||
|
||||
let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
|
||||
if (scaleMix != 0) {
|
||||
if (scaleX > 0.00001) scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * scaleMix) / scaleX;
|
||||
if (scaleY > 0.00001) scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * scaleMix) / scaleY;
|
||||
}
|
||||
if (mixScaleX != 0 && scaleX != 0)
|
||||
scaleX = (scaleX + (target.ascaleX - scaleX + this.data.offsetScaleX) * mixScaleX) / scaleX;
|
||||
if (mixScaleY != 0 && scaleY != 0)
|
||||
scaleY = (scaleY + (target.ascaleY - scaleY + this.data.offsetScaleY) * mixScaleY) / scaleY;
|
||||
|
||||
let shearY = bone.ashearY;
|
||||
if (shearMix != 0) {
|
||||
if (mixShearY != 0) {
|
||||
let r = target.ashearY - shearY + this.data.offsetShearY;
|
||||
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
|
||||
bone.shearY += r * shearMix;
|
||||
shearY += r * mixShearY;
|
||||
}
|
||||
|
||||
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
|
||||
@ -254,7 +256,9 @@ module spine {
|
||||
}
|
||||
|
||||
applyRelativeLocal () {
|
||||
let rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix;
|
||||
let mixRotate = this.mixRotate, mixX = this.mixX, mixY = this.mixY, mixScaleX = this.mixScaleX,
|
||||
mixScaleY = this.mixScaleY, mixShearY = this.mixShearY;
|
||||
|
||||
let target = this.target;
|
||||
if (!target.appliedValid) target.updateAppliedTransform();
|
||||
let bones = this.bones;
|
||||
@ -262,23 +266,12 @@ module spine {
|
||||
let bone = bones[i];
|
||||
if (!bone.appliedValid) bone.updateAppliedTransform();
|
||||
|
||||
let rotation = bone.arotation;
|
||||
if (rotateMix != 0) rotation += (target.arotation + this.data.offsetRotation) * rotateMix;
|
||||
|
||||
let x = bone.ax, y = bone.ay;
|
||||
if (translateMix != 0) {
|
||||
x += (target.ax + this.data.offsetX) * translateMix;
|
||||
y += (target.ay + this.data.offsetY) * translateMix;
|
||||
}
|
||||
|
||||
let scaleX = bone.ascaleX, scaleY = bone.ascaleY;
|
||||
if (scaleMix != 0) {
|
||||
if (scaleX > 0.00001) scaleX *= ((target.ascaleX - 1 + this.data.offsetScaleX) * scaleMix) + 1;
|
||||
if (scaleY > 0.00001) scaleY *= ((target.ascaleY - 1 + this.data.offsetScaleY) * scaleMix) + 1;
|
||||
}
|
||||
|
||||
let shearY = bone.ashearY;
|
||||
if (shearMix != 0) shearY += (target.ashearY + this.data.offsetShearY) * shearMix;
|
||||
let rotation = bone.arotation + (target.arotation + this.data.offsetRotation) * mixRotate;
|
||||
let x = bone.ax + (target.ax + this.data.offsetX) * mixX;
|
||||
let y = bone.ay + (target.ay + this.data.offsetY) * mixY;
|
||||
let scaleX = (bone.ascaleX * ((target.ascaleX - 1 + this.data.offsetScaleX) * mixScaleX) + 1);
|
||||
let scaleY = (bone.ascaleY * ((target.ascaleY - 1 + this.data.offsetScaleY) * mixScaleY) + 1);
|
||||
let shearY = bone.ashearY + (target.ashearY + this.data.offsetShearY) * mixShearY;
|
||||
|
||||
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
|
||||
}
|
||||
|
||||
@ -40,17 +40,12 @@ module spine {
|
||||
/** The target bone whose world transform will be copied to the constrained bones. */
|
||||
target: BoneData;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained rotations. */
|
||||
rotateMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained translations. */
|
||||
translateMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained scales. */
|
||||
scaleMix = 0;
|
||||
|
||||
/** A percentage (0-1) that controls the mix between the constrained and unconstrained shears. */
|
||||
shearMix = 0;
|
||||
mixRotate = 0;
|
||||
mixX = 0;
|
||||
mixY = 0;
|
||||
mixScaleX = 0;
|
||||
mixScaleY = 0;
|
||||
mixShearY = 0;
|
||||
|
||||
/** An offset added to the constrained bone rotation. */
|
||||
offsetRotation = 0;
|
||||
|
||||
@ -253,6 +253,11 @@ module spine {
|
||||
}
|
||||
}
|
||||
|
||||
static arrayFill<T> (array: ArrayLike<T>, fromIndex: number, toIndex: number, value: T) {
|
||||
for (let i = fromIndex; i < toIndex; i++)
|
||||
array[i] = value;
|
||||
}
|
||||
|
||||
static setArraySize<T> (array: Array<T>, size: number, value: any = 0): Array<T> {
|
||||
let oldSize = array.length;
|
||||
if (oldSize == size) return array;
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
*****************************************************************************/
|
||||
|
||||
module spine {
|
||||
|
||||
/** An attachment with vertices that make up a polygon. Can be used for hit detection, creating physics bodies, spawning particle
|
||||
* effects, and more.
|
||||
*
|
||||
@ -42,7 +41,7 @@ module spine {
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new BoundingBoxAttachment(name);
|
||||
let copy = new BoundingBoxAttachment(this.name);
|
||||
this.copyTo(copy);
|
||||
copy.color.setFromColor(this.color);
|
||||
return copy;
|
||||
|
||||
@ -44,7 +44,7 @@ module spine {
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new ClippingAttachment(name);
|
||||
let copy = new ClippingAttachment(this.name);
|
||||
this.copyTo(copy);
|
||||
copy.endSlot = this.endSlot;
|
||||
copy.color.setFromColor(this.color);
|
||||
|
||||
@ -53,7 +53,7 @@ module spine {
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PathAttachment(name);
|
||||
let copy = new PathAttachment(this.name);
|
||||
this.copyTo(copy);
|
||||
copy.lengths = new Array<number>(this.lengths.length);
|
||||
Utils.arrayCopy(this.lengths, 0, copy.lengths, 0, this.lengths.length);
|
||||
|
||||
@ -58,7 +58,7 @@ module spine {
|
||||
}
|
||||
|
||||
copy (): Attachment {
|
||||
let copy = new PointAttachment(name);
|
||||
let copy = new PointAttachment(this.name);
|
||||
copy.x = this.x;
|
||||
copy.y = this.y;
|
||||
copy.rotation = this.rotation;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user