Эх сурвалжийг харах

[csharp] Ported commit 4f73fbb, "Fixed applying a constraint reverting changes from other constraints.", see #1896.

Harald Csaszar 4 жил өмнө
parent
commit
7b1469c32b

+ 34 - 23
spine-csharp/src/Bone.cs

@@ -47,7 +47,6 @@ namespace Spine {
 		internal ExposedList<Bone> children = new ExposedList<Bone>();
 		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 {
 		/// <summary>The applied local shearY.</summary>
 		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; } }
-
-		public float WorldX { get { return worldX; } }
-		public float WorldY { get { return worldY; } }
+		/// <summary>Part of the world transform matrix for the X axis. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		public float A { get { return a; } set { a = value; } }
+		/// <summary>Part of the world transform matrix for the Y axis. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		public float B { get { return b; } set { b = value; } }
+		/// <summary>Part of the world transform matrix for the X axis. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		public float C { get { return c; } set { c = value; } }
+		/// <summary>Part of the world transform matrix for the Y axis. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		public float D { get { return d; } set { d = value; } }
+
+		/// <summary>The world X position. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		public float WorldX { get { return worldX; } set { worldX = value; } }
+		/// <summary>The world Y position. If changed, <see cref="UpdateAppliedTransform()"/> should be called.</summary>
+		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();
 		}
 
-		/// <summary>Same as <see cref="UpdateWorldTransform"/>. This method exists for Bone to implement <see cref="Spine.IUpdatable"/>.</summary>
+		/// <summary>Computes the world transform using the parent bone and this bone's local applied transform.</summary>
 		public void Update () {
-			UpdateWorldTransform(x, y, rotation, scaleX, scaleY, shearX, shearY);
+			UpdateWorldTransform(ax, ay, arotation, ascaleX, ascaleY, ashearX, ashearY);
 		}
 
 		/// <summary>Computes the world transform using the parent bone and this bone's local transform.</summary>
@@ -137,7 +142,11 @@ namespace Spine {
 			UpdateWorldTransform(x, y, rotation, scaleX, scaleY, shearX, shearY);
 		}
 
-		/// <summary>Computes the world transform using the parent bone and the specified local transform.</summary>
+		/// <summary>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.
+		/// <para>
+		/// See <a href="http://esotericsoftware.com/spine-runtime-skeletons#World-transforms">World transforms</a> in the Spine
+		/// Runtimes Guide.</para></summary>
 		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 {
 		}
 
 		/// <summary>
-		/// 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.
-		/// </summary>
+		/// Computes the applied transform values from the world transform.
+		/// <para>
+		/// If the world transform is modified (by a constraint, <see cref="RotateWorld(float)"/>, 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).
+		/// </para><para>
+		///  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.
+		/// </para></summary>
 		internal void UpdateAppliedTransform () {
-			appliedValid = true;
 			Bone parent = this.parent;
 			if (parent == null) {
 				ax = worldX;
@@ -347,9 +357,11 @@ namespace Spine {
 		}
 
 		/// <summary>
-		/// Rotates the world transform the specified amount and sets isAppliedValid to false.
-		/// </summary>
-		/// <param name="degrees">Degrees.</param>
+		/// Rotates the world transform the specified amount.
+		/// <para>
+		/// After changes are made to the world transform, <see cref="UpdateAppliedTransform()"/> should be called and <see cref="Update()"/> will
+		/// need to be called on any child bones, recursively.
+		/// </para></summary>
 		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 () {

+ 0 - 3
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) {

+ 1 - 1
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();
 			}
 		}
 

+ 12 - 0
spine-csharp/src/Skeleton.cs

@@ -316,6 +316,18 @@ namespace Spine {
 		/// Runtimes Guide.</para>
 		/// </summary>
 		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();

+ 2 - 6
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;

+ 0 - 5
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);