diff --git a/spine-csharp/src/Bone.cs b/spine-csharp/src/Bone.cs index b0065d0a8..4c4c9bc98 100644 --- a/spine-csharp/src/Bone.cs +++ b/spine-csharp/src/Bone.cs @@ -47,7 +47,6 @@ namespace Spine { internal ExposedList children = new ExposedList(); internal float x, y, rotation, scaleX, scaleY, shearX, shearY; internal float ax, ay, arotation, ascaleX, ascaleY, ashearX, ashearY; - internal bool appliedValid; internal float a, b, worldX; internal float c, d, worldY; @@ -101,13 +100,19 @@ namespace Spine { /// The applied local shearY. public float AShearY { get { return ashearY; } set { ashearY = value; } } - public float A { get { return a; } } - public float B { get { return b; } } - public float C { get { return c; } } - public float D { get { return d; } } + /// Part of the world transform matrix for the X axis. If changed, should be called. + public float A { get { return a; } set { a = value; } } + /// Part of the world transform matrix for the Y axis. If changed, should be called. + public float B { get { return b; } set { b = value; } } + /// Part of the world transform matrix for the X axis. If changed, should be called. + public float C { get { return c; } set { c = value; } } + /// Part of the world transform matrix for the Y axis. If changed, should be called. + public float D { get { return d; } set { d = value; } } - public float WorldX { get { return worldX; } } - public float WorldY { get { return worldY; } } + /// The world X position. If changed, should be called. + public float WorldX { get { return worldX; } set { worldX = value; } } + /// The world Y position. If changed, should be called. + public float WorldY { get { return worldY; } set { worldY = value; } } public float WorldRotationX { get { return MathUtils.Atan2(c, a) * MathUtils.RadDeg; } } public float WorldRotationY { get { return MathUtils.Atan2(d, b) * MathUtils.RadDeg; } } @@ -127,9 +132,9 @@ namespace Spine { SetToSetupPose(); } - /// Same as . This method exists for Bone to implement . + /// Computes the world transform using the parent bone and this bone's local applied transform. public void Update () { - UpdateWorldTransform(x, y, rotation, scaleX, scaleY, shearX, shearY); + UpdateWorldTransform(ax, ay, arotation, ascaleX, ascaleY, ashearX, ashearY); } /// Computes the world transform using the parent bone and this bone's local transform. @@ -137,7 +142,11 @@ namespace Spine { UpdateWorldTransform(x, y, rotation, scaleX, scaleY, shearX, shearY); } - /// Computes the world transform using the parent bone and the specified local transform. + /// Computes the world transform using the parent bone and the specified local transform. The applied transform is set to the + /// specified local transform. Child bones are not updated. + /// + /// See World transforms in the Spine + /// Runtimes Guide. public void UpdateWorldTransform (float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) { ax = x; ay = y; @@ -146,8 +155,6 @@ namespace Spine { ascaleY = scaleY; ashearX = shearX; ashearY = shearY; - appliedValid = true; - Skeleton skeleton = this.skeleton; Bone parent = this.parent; if (parent == null) { // Root bone. @@ -258,13 +265,16 @@ namespace Spine { } /// - /// Computes the individual applied transform values from the world transform. This can be useful to perform processing using - /// the applied transform after the world transform has been modified directly (eg, by a constraint).. - /// - /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. - /// + /// Computes the applied transform values from the world transform. + /// + /// If the world transform is modified (by a constraint, , etc) then this method should be called so + /// the applied transform matches the world transform. The applied transform may be needed by other code (eg to apply another + /// constraint). + /// + /// Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. The applied transform after + /// calling this method is equivalent to the local transform used to compute the world transform, but may not be identical. + /// internal void UpdateAppliedTransform () { - appliedValid = true; Bone parent = this.parent; if (parent == null) { ax = worldX; @@ -347,9 +357,11 @@ namespace Spine { } /// - /// Rotates the world transform the specified amount and sets isAppliedValid to false. - /// - /// Degrees. + /// Rotates the world transform the specified amount. + /// + /// After changes are made to the world transform, should be called and will + /// need to be called on any child bones, recursively. + /// public void RotateWorld (float degrees) { float a = this.a, b = this.b, c = this.c, d = this.d; float cos = MathUtils.CosDeg(degrees), sin = MathUtils.SinDeg(degrees); @@ -357,7 +369,6 @@ namespace Spine { this.b = cos * b - sin * d; this.c = sin * a + cos * c; this.d = sin * b + cos * d; - appliedValid = false; } override public string ToString () { diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index abe510766..ecc3c796a 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -160,7 +160,6 @@ namespace Spine { static public void Apply (Bone bone, float targetX, float targetY, bool compress, bool stretch, bool uniform, float alpha) { if (bone == null) throw new ArgumentNullException("bone", "bone cannot be null."); - if (!bone.appliedValid) bone.UpdateAppliedTransform(); Bone p = bone.parent; float pa = p.a, pb = p.b, pc = p.c, pd = p.d; @@ -222,8 +221,6 @@ namespace Spine { float softness, float alpha) { if (parent == null) throw new ArgumentNullException("parent", "parent cannot be null."); if (child == null) throw new ArgumentNullException("child", "child cannot be null."); - if (!parent.appliedValid) parent.UpdateAppliedTransform(); - if (!child.appliedValid) child.UpdateAppliedTransform(); float px = parent.ax, py = parent.ay, psx = parent.ascaleX, psy = parent.ascaleY, sx = psx, sy = psy, csx = child.ascaleX; int os1, os2, s2; if (psx < 0) { diff --git a/spine-csharp/src/PathConstraint.cs b/spine-csharp/src/PathConstraint.cs index 76ee2e1fe..275620b8f 100644 --- a/spine-csharp/src/PathConstraint.cs +++ b/spine-csharp/src/PathConstraint.cs @@ -216,7 +216,7 @@ namespace Spine { bone.c = sin * a + cos * c; bone.d = sin * b + cos * d; } - bone.appliedValid = false; + bone.UpdateAppliedTransform(); } } diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index d3257864a..a9b482d29 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -316,6 +316,18 @@ namespace Spine { /// Runtimes Guide. /// public void UpdateWorldTransform () { + Object[] bones = this.bones.Items; + for (int i = 0, n = this.bones.Count; i < n; i++) { + Bone bone = (Bone)bones[i]; + bone.ax = bone.x; + bone.ay = bone.y; + bone.arotation = bone.rotation; + bone.ascaleX = bone.scaleX; + bone.ascaleY = bone.scaleY; + bone.ashearX = bone.shearX; + bone.ashearY = bone.shearY; + } + var updateCache = this.updateCache.Items; for (int i = 0, n = this.updateCache.Count; i < n; i++) updateCache[i].Update(); diff --git a/spine-csharp/src/TransformConstraint.cs b/spine-csharp/src/TransformConstraint.cs index 0985a53fb..804c61f44 100644 --- a/spine-csharp/src/TransformConstraint.cs +++ b/spine-csharp/src/TransformConstraint.cs @@ -157,7 +157,7 @@ namespace Spine { bone.d = MathUtils.Sin(r) * s; } - bone.appliedValid = false; + bone.UpdateAppliedTransform(); } } @@ -221,7 +221,7 @@ namespace Spine { bone.d = MathUtils.Sin(r) * s; } - bone.appliedValid = false; + bone.UpdateAppliedTransform(); } } @@ -230,12 +230,10 @@ namespace Spine { mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; Bone target = this.target; - if (!target.appliedValid) target.UpdateAppliedTransform(); var bones = this.bones.Items; for (int i = 0, n = this.bones.Count; i < n; i++) { Bone bone = bones[i]; - if (!bone.appliedValid) bone.UpdateAppliedTransform(); float rotation = bone.arotation; if (mixRotate != 0) { @@ -270,12 +268,10 @@ namespace Spine { mixScaleY = this.mixScaleY, mixShearY = this.mixShearY; Bone target = this.target; - if (!target.appliedValid) target.UpdateAppliedTransform(); var bones = this.bones.Items; for (int i = 0, n = this.bones.Count; i < n; i++) { Bone bone = bones[i]; - if (!bone.appliedValid) bone.UpdateAppliedTransform(); float rotation = bone.arotation + (target.arotation + data.offsetRotation) * mixRotate; float x = bone.ax + (target.ax + data.offsetX) * mixX; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtilityBone.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtilityBone.cs index c3e16f283..db59a46d1 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtilityBone.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtilityBone.cs @@ -148,11 +148,6 @@ namespace Spine.Unity { break; case UpdatePhase.World: case UpdatePhase.Complete: - // Use Applied transform values (ax, ay, AppliedRotation, ascale) if world values were modified by constraints. - if (!bone.appliedValid) { - bone.UpdateAppliedTransform(); - } - if (position) thisTransform.localPosition = new Vector3(bone.ax * positionScale, bone.ay * positionScale, 0);