|
@@ -44,17 +44,7 @@ module spine {
|
|
/** The target bone whose world transform will be copied to the constrained bones. */
|
|
/** The target bone whose world transform will be copied to the constrained bones. */
|
|
target: Bone;
|
|
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();
|
|
temp = new Vector2();
|
|
active = false;
|
|
active = false;
|
|
@@ -63,10 +53,12 @@ module spine {
|
|
if (data == null) throw new Error("data cannot be null.");
|
|
if (data == null) throw new Error("data cannot be null.");
|
|
if (skeleton == null) throw new Error("skeleton cannot be null.");
|
|
if (skeleton == null) throw new Error("skeleton cannot be null.");
|
|
this.data = data;
|
|
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>();
|
|
this.bones = new Array<Bone>();
|
|
for (let i = 0; i < data.bones.length; i++)
|
|
for (let i = 0; i < data.bones.length; i++)
|
|
this.bones.push(skeleton.findBone(data.bones[i].name));
|
|
this.bones.push(skeleton.findBone(data.bones[i].name));
|
|
@@ -78,7 +70,7 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
update () {
|
|
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.local) {
|
|
if (this.data.relative)
|
|
if (this.data.relative)
|
|
@@ -95,24 +87,27 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
applyAbsoluteWorld () {
|
|
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 target = this.target;
|
|
let ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
|
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 degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
|
|
let offsetRotation = this.data.offsetRotation * degRadReflect;
|
|
let offsetRotation = this.data.offsetRotation * degRadReflect;
|
|
let offsetShearY = this.data.offsetShearY * degRadReflect;
|
|
let offsetShearY = this.data.offsetShearY * degRadReflect;
|
|
|
|
+
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
let bone = bones[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 a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
|
let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
|
|
let r = Math.atan2(tc, ta) - Math.atan2(c, a) + offsetRotation;
|
|
if (r > MathUtils.PI)
|
|
if (r > MathUtils.PI)
|
|
r -= MathUtils.PI2;
|
|
r -= MathUtils.PI2;
|
|
- else if (r < -MathUtils.PI)
|
|
|
|
|
|
+ else if (r < -MathUtils.PI) //
|
|
r += MathUtils.PI2;
|
|
r += MathUtils.PI2;
|
|
- r *= rotateMix;
|
|
|
|
|
|
+ r *= mixRotate;
|
|
let cos = Math.cos(r), sin = Math.sin(r);
|
|
let cos = Math.cos(r), sin = Math.sin(r);
|
|
bone.a = cos * a - sin * c;
|
|
bone.a = cos * a - sin * c;
|
|
bone.b = cos * b - sin * d;
|
|
bone.b = cos * b - sin * d;
|
|
@@ -120,38 +115,40 @@ module spine {
|
|
bone.d = sin * b + cos * d;
|
|
bone.d = sin * b + cos * d;
|
|
}
|
|
}
|
|
|
|
|
|
- if (translateMix != 0) {
|
|
|
|
|
|
+ if (translate) {
|
|
let temp = this.temp;
|
|
let temp = this.temp;
|
|
target.localToWorld(temp.set(this.data.offsetX, this.data.offsetY));
|
|
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 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.a *= s;
|
|
bone.c *= 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.b *= s;
|
|
bone.d *= s;
|
|
bone.d *= s;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- if (shearMix > 0) {
|
|
|
|
|
|
+ if (mixShearY > 0) {
|
|
let b = bone.b, d = bone.d;
|
|
let b = bone.b, d = bone.d;
|
|
let by = Math.atan2(d, b);
|
|
let by = Math.atan2(d, b);
|
|
let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
|
|
let r = Math.atan2(td, tb) - Math.atan2(tc, ta) - (by - Math.atan2(bone.c, bone.a));
|
|
if (r > MathUtils.PI)
|
|
if (r > MathUtils.PI)
|
|
r -= MathUtils.PI2;
|
|
r -= MathUtils.PI2;
|
|
- else if (r < -MathUtils.PI)
|
|
|
|
|
|
+ else if (r < -MathUtils.PI) //
|
|
r += MathUtils.PI2;
|
|
r += MathUtils.PI2;
|
|
- r = by + (r + offsetShearY) * shearMix;
|
|
|
|
|
|
+ r = by + (r + offsetShearY) * mixShearY;
|
|
let s = Math.sqrt(b * b + d * d);
|
|
let s = Math.sqrt(b * b + d * d);
|
|
bone.b = Math.cos(r) * s;
|
|
bone.b = Math.cos(r) * s;
|
|
bone.d = Math.sin(r) * s;
|
|
bone.d = Math.sin(r) * s;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
bone.appliedValid = false;
|
|
bone.appliedValid = false;
|
|
@@ -159,55 +156,59 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
applyRelativeWorld () {
|
|
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 target = this.target;
|
|
let ta = target.a, tb = target.b, tc = target.c, td = target.d;
|
|
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 degRadReflect = ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
|
|
let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
|
|
let offsetRotation = this.data.offsetRotation * degRadReflect, offsetShearY = this.data.offsetShearY * degRadReflect;
|
|
|
|
+
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
let bone = bones[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 a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
|
let r = Math.atan2(tc, ta) + offsetRotation;
|
|
let r = Math.atan2(tc, ta) + offsetRotation;
|
|
if (r > MathUtils.PI)
|
|
if (r > MathUtils.PI)
|
|
r -= MathUtils.PI2;
|
|
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);
|
|
let cos = Math.cos(r), sin = Math.sin(r);
|
|
bone.a = cos * a - sin * c;
|
|
bone.a = cos * a - sin * c;
|
|
bone.b = cos * b - sin * d;
|
|
bone.b = cos * b - sin * d;
|
|
bone.c = sin * a + cos * c;
|
|
bone.c = sin * a + cos * c;
|
|
bone.d = sin * b + cos * d;
|
|
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.a *= s;
|
|
bone.c *= 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.b *= s;
|
|
bone.d *= s;
|
|
bone.d *= s;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- if (shearMix > 0) {
|
|
|
|
|
|
+ if (mixShearY > 0) {
|
|
let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
|
|
let r = Math.atan2(td, tb) - Math.atan2(tc, ta);
|
|
if (r > MathUtils.PI)
|
|
if (r > MathUtils.PI)
|
|
r -= MathUtils.PI2;
|
|
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;
|
|
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);
|
|
let s = Math.sqrt(b * b + d * d);
|
|
bone.b = Math.cos(r) * s;
|
|
bone.b = Math.cos(r) * s;
|
|
bone.d = Math.sin(r) * s;
|
|
bone.d = Math.sin(r) * s;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
bone.appliedValid = false;
|
|
bone.appliedValid = false;
|
|
@@ -215,38 +216,39 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
applyAbsoluteLocal () {
|
|
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;
|
|
let target = this.target;
|
|
if (!target.appliedValid) target.updateAppliedTransform();
|
|
if (!target.appliedValid) target.updateAppliedTransform();
|
|
|
|
+
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
let bone = bones[i];
|
|
let bone = bones[i];
|
|
if (!bone.appliedValid) bone.updateAppliedTransform();
|
|
if (!bone.appliedValid) bone.updateAppliedTransform();
|
|
|
|
|
|
let rotation = bone.arotation;
|
|
let rotation = bone.arotation;
|
|
- if (rotateMix != 0) {
|
|
|
|
|
|
+ if (mixRotate != 0) {
|
|
let r = target.arotation - rotation + this.data.offsetRotation;
|
|
let r = target.arotation - rotation + this.data.offsetRotation;
|
|
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
|
|
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
|
|
- rotation += r * rotateMix;
|
|
|
|
|
|
+ rotation += r * mixRotate;
|
|
}
|
|
}
|
|
|
|
|
|
let x = bone.ax, y = bone.ay;
|
|
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;
|
|
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;
|
|
let shearY = bone.ashearY;
|
|
- if (shearMix != 0) {
|
|
|
|
|
|
+ if (mixShearY != 0) {
|
|
let r = target.ashearY - shearY + this.data.offsetShearY;
|
|
let r = target.ashearY - shearY + this.data.offsetShearY;
|
|
r -= (16384 - ((16384.499999999996 - r / 360) | 0)) * 360;
|
|
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);
|
|
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
|
|
@@ -254,7 +256,9 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
applyRelativeLocal () {
|
|
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;
|
|
let target = this.target;
|
|
if (!target.appliedValid) target.updateAppliedTransform();
|
|
if (!target.appliedValid) target.updateAppliedTransform();
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
@@ -262,23 +266,12 @@ module spine {
|
|
let bone = bones[i];
|
|
let bone = bones[i];
|
|
if (!bone.appliedValid) bone.updateAppliedTransform();
|
|
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);
|
|
bone.updateWorldTransformWith(x, y, rotation, scaleX, scaleY, bone.ashearX, shearY);
|
|
}
|
|
}
|