Forráskód Böngészése

Merge branch '4.2' into spine-android

Denis Andrasec 1 éve
szülő
commit
e2bdecd9ef

+ 3 - 1
CHANGELOG.md

@@ -122,7 +122,7 @@
 
 ### Unity
 
-- **Officially supported Unity versions are 2017.1-2022.1**.
+- **Officially supported Unity versions are 2017.1-2023.1**.
 
 - **Additions**
 
@@ -161,6 +161,7 @@
   - Added support for BlendModeMaterials at runtime instantiation from files via an additional method `SkeletonDataAsset.SetupRuntimeBlendModeMaterials`. See example scene `Spine Examples/Other Examples/Instantiate from Script` for a usage example.
   - SkeletonGraphic: You can now offset the skeleton mesh relative to the pivot via a newly added green circle handle. This allows you to e.g. frame only the face of a skeleton inside a masked frame. Previously offsetting the pivot downwards fails when `Layout Scale Mode` scales the mesh smaller and towards the pivot (e.g. the feet) and thus out of the frame. Now you can keep the pivot in the center of the `RectTransform` while offsetting only the mesh downwards, keeping the desired skeleton area (e.g. the face) centered while resizing. Moving the new larger green circle handle moves the mesh offset, while moving the blue pivot circle handle moves the pivot as usual.
   - `Universal Render Pipeline/Spine/Skeleton` shader now performs proper alpha-testing when `Depth Write` is enabled, using the existing `Shadow alpha cutoff` parameter.
+  - `SkeletonRootMotion` components now provide a public `Initialize()` method which is automatically called when calling `skeletonAnimation.Initialize(true)` to update the necessary skeleton references. If a different root bone shall be used, be sure to set `skeletonRootMotion.rootMotionBoneName` before calling `skeletonAnimation.Initialize(true)`.
 
 - **Breaking changes**
 
@@ -173,6 +174,7 @@
   - Inspector: String attribute `SpineSkin()` now allows to include `<None>` in the list of parameters. Previously the `includeNone=true` parameter of the `SpineSkin()` attribute defaulted to `true` but was ignored. Now it defaults to `false` and has an effect on the list. Only the Inspector GUI is affected by this behaviour change.
   - `SkeletonGraphicRenderTexture` example component: `protected RawImage quadRawImage` was changed to `protected SkeletonSubmeshGraphic quadMaskableGraphic` for a bugfix. This is only relevant for subclasses of `SkeletonGraphicRenderTexture` or when querying the `RawImage` component via e.g. `skeletonGraphicRenderTexture.quad.GetComponent<RawImage>()`.
   - Fixed a bug where when Linear color space is used and `PMA vertex colors` enabled, additive slots add a too dark (too transparent) color value. If you want the old incorrect behaviour (darker additive slots) or are not using Linear but Gamma color space, you can comment-out the define `LINEAR_COLOR_SPACE_FIX_ADDITIVE_ALPHA` in `MeshGenerator.cs` to deactivate the fix or just to skip unnecessary instructions.
+  - Fixed SkeletonRootMotion components ignoring parent bone scale when set by transform constraints. Using applied scale of parent bone now. If you need the old behaviour, comment out the line `#define USE_APPLIED_PARENT_SCALE` in SkeletonRootMotionBase.cs.
 
 - **Changes of default values**
 

+ 21 - 17
spine-csharp/src/PhysicsConstraint.cs

@@ -147,6 +147,7 @@ namespace Spine {
 				Reset();
 				goto case Physics.Update; // Fall through.
 			case Physics.Update:
+				Skeleton skeleton = this.skeleton;
 				float delta = Math.Max(skeleton.time - lastTime, 0);
 				remaining += delta;
 				lastTime = skeleton.time;
@@ -157,21 +158,24 @@ namespace Spine {
 					ux = bx;
 					uy = by;
 				} else {
-					float a = this.remaining, i = inertia, q = data.limit * delta, t = data.step, f = skeleton.data.referenceScale;
+					float a = remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale, d = -1;
+					float qx = data.limit * delta, qy = qx * Math.Abs(skeleton.ScaleY);
+					qx *= Math.Abs(skeleton.ScaleX);
+
 					if (x || y) {
 						if (x) {
 							float u = (ux - bx) * i;
-							xOffset += u > q ? q : u < -q ? -q : u;
+							xOffset += u > qx ? qx : u < -qx ? -qx : u;
 							ux = bx;
 						}
 						if (y) {
 							float u = (uy - by) * i;
-							yOffset += u > q ? q : u < -q ? -q : u;
+							yOffset += u > qy ? qy : u < -qy ? -qy : u;
 							uy = by;
 						}
 						if (a >= t) {
+							d = (float)Math.Pow(damping, 60 * t);
 							float m = massInverse * t, e = strength, w = wind * f, g = (Bone.yDown ? -gravity : gravity) * f;
-							float d = (float)Math.Pow(damping, 60 * t);
 							do {
 								if (x) {
 									xVelocity += (w - xOffset * e) * m;
@@ -192,14 +196,14 @@ namespace Spine {
 					if (rotateOrShearX || scaleX) {
 						float ca = (float)Math.Atan2(bone.c, bone.a), c, s, mr = 0;
 						float dx = cx - bone.worldX, dy = cy - bone.worldY;
-						if (dx > q)
-							dx = q;
-						else if (dx < -q)
-							dx = -q;
-						if (dy > q)
-							dy = q;
-						else if (dy < -q)
-							dy = -q;
+						if (dx > qx)
+							dx = qx;
+						else if (dx < -qx)
+							dx = -qx;
+						if (dy > qy)
+							dy = qy;
+						else if (dy < -qy)
+							dy = -qy;
 						if (rotateOrShearX) {
 							mr = (data.rotate + data.shearX) * mix;
 							float r = (float)Math.Atan2(dy + ty, dx + tx) - ca - rotateOffset * mr;
@@ -217,10 +221,10 @@ namespace Spine {
 							float r = l * bone.WorldScaleX;
 							if (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
 						}
-						a = this.remaining;
+						a = remaining;
 						if (a >= t) {
-							float m = massInverse * t, e = strength, w = wind, g = (Bone.yDown ? -gravity : gravity);
-							float d = (float)Math.Pow(damping, 60 * t), h = l / f;
+							if (d == -1) d = (float)Math.Pow(damping, 60 * t);
+							float m = massInverse * t, e = strength, w = wind, g = (Bone.yDown ? -gravity : gravity), h = l / f;
 							while (true) {
 								a -= t;
 								if (scaleX) {
@@ -241,7 +245,7 @@ namespace Spine {
 							}
 						}
 					}
-					this.remaining = a;
+					remaining = a;
 				}
 				cx = bone.worldX;
 				cy = bone.worldY;
@@ -295,7 +299,7 @@ namespace Spine {
 		}
 
 		/// <summary>The bone constrained by this physics constraint.</summary>
-		public Bone Bone { get {return bone;} set { bone = value; } }
+		public Bone Bone { get { return bone; } set { bone = value; } }
 		public float Inertia { get { return inertia; } set { inertia = value; } }
 		public float Strength { get { return strength; } set { strength = value; } }
 		public float Damping { get { return damping; } set { damping = value; } }

+ 1 - 1
spine-csharp/src/package.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.spine-csharp",
 	"displayName": "spine-csharp Runtime",
 	"description": "This plugin provides the spine-csharp core runtime.",
-	"version": "4.2.25",
+	"version": "4.2.27",
 	"unity": "2018.3",
 	"author": {
 		"name": "Esoteric Software",

+ 17 - 14
spine-haxe/spine-haxe/spine/PhysicsConstraint.hx

@@ -32,7 +32,7 @@ package spine;
 class PhysicsConstraint implements Updatable {
 	private var _data:PhysicsConstraintData;
 	private var _bone:Bone = null;
-	
+
 	public var inertia:Float = 0;
 	public var strength:Float = 0;
 	public var damping:Float = 0;
@@ -63,7 +63,7 @@ class PhysicsConstraint implements Updatable {
 	private var _skeleton:Skeleton;
 	public var remaining:Float = 0;
 	public var lastTime:Float = 0;
-	
+
 	public function new(data: PhysicsConstraintData, skeleton: Skeleton) {
 		_data = data;
 		_skeleton = skeleton;
@@ -123,7 +123,7 @@ class PhysicsConstraint implements Updatable {
 				return;
 			case Physics.reset, Physics.update:
 				if (physics == Physics.reset) reset();
-				
+
 				var delta:Float = Math.max(skeleton.time - lastTime, 0);
 				remaining += delta;
 				lastTime = _skeleton.time;
@@ -136,19 +136,22 @@ class PhysicsConstraint implements Updatable {
 				} else {
 					var a:Float = remaining,
 						i:Float = inertia,
-						q:Float = _data.limit * delta,
 						t:Float = _data.step,
 						f:Float = skeleton.data.referenceScale,
 						d:Float = -1;
+
+					var qx:Float = _data.limit * delta,
+						qy:Float = qx * Math.abs(skeleton.scaleY);
+					qx *= Math.abs(skeleton.scaleX);
 					if (x || y) {
 						if (x) {
 							var u:Float = (ux - bx) * i;
-							xOffset += u > q ? q : u < -q ? -q : u;
+							xOffset += u > qx ? qx : u < -qx ? -qx : u;
 							ux = bx;
 						}
 						if (y) {
 							var u:Float = (uy - by) * i;
-							yOffset += u > q ? q : u < -q ? -q : u;
+							yOffset += u > qy ? qy : u < -qy ? -qy : u;
 							uy = by;
 						}
 						if (a >= t) {
@@ -181,14 +184,14 @@ class PhysicsConstraint implements Updatable {
 							mr:Float = 0;
 						var dx:Float = cx - bone.worldX,
 							dy:Float = cy - bone.worldY;
-						if (dx > q)
-							dx = q;
-						else if (dx < -q) //
-							dx = -q;
-						if (dy > q)
-							dy = q;
-						else if (dy < -q) //
-							dy = -q;
+						if (dx > qx)
+							dx = qx;
+						else if (dx < -qx) //
+							dx = -qx;
+						if (dy > qy)
+							dy = qy;
+						else if (dy < -qy) //
+							dy = -qy;
 						if (rotateOrShearX) {
 							mr = (_data.rotate + _data.shearX) * mix;
 							var r:Float = Math.atan2(dy + ty, dx + tx) - ca - rotateOffset * mr;

+ 14 - 11
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java

@@ -141,6 +141,7 @@ public class PhysicsConstraint implements Updatable {
 			reset();
 			// Fall through.
 		case update:
+			Skeleton skeleton = this.skeleton;
 			float delta = Math.max(skeleton.time - lastTime, 0);
 			remaining += delta;
 			lastTime = skeleton.time;
@@ -151,16 +152,18 @@ public class PhysicsConstraint implements Updatable {
 				ux = bx;
 				uy = by;
 			} else {
-				float a = remaining, i = inertia, q = data.limit * delta, t = data.step, f = skeleton.data.referenceScale, d = -1;
+				float a = remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale, d = -1;
+				float qx = data.limit * delta, qy = qx * Math.abs(skeleton.scaleY);
+				qx *= Math.abs(skeleton.scaleX);
 				if (x || y) {
 					if (x) {
 						float u = (ux - bx) * i;
-						xOffset += u > q ? q : u < -q ? -q : u;
+						xOffset += u > qx ? qx : u < -qx ? -qx : u;
 						ux = bx;
 					}
 					if (y) {
 						float u = (uy - by) * i;
-						yOffset += u > q ? q : u < -q ? -q : u;
+						yOffset += u > qy ? qy : u < -qy ? -qy : u;
 						uy = by;
 					}
 					if (a >= t) {
@@ -186,14 +189,14 @@ public class PhysicsConstraint implements Updatable {
 				if (rotateOrShearX || scaleX) {
 					float ca = atan2(bone.c, bone.a), c, s, mr = 0;
 					float dx = cx - bone.worldX, dy = cy - bone.worldY;
-					if (dx > q)
-						dx = q;
-					else if (dx < -q) //
-						dx = -q;
-					if (dy > q)
-						dy = q;
-					else if (dy < -q) //
-						dy = -q;
+					if (dx > qx)
+						dx = qx;
+					else if (dx < -qx) //
+						dx = -qx;
+					if (dy > qy)
+						dy = qy;
+					else if (dy < -qy) //
+						dy = -qy;
 					if (rotateOrShearX) {
 						mr = (data.rotate + data.shearX) * mix;
 						float r = atan2(dy + ty, dx + tx) - ca - rotateOffset * mr;

+ 15 - 12
spine-ts/spine-core/src/PhysicsConstraint.ts

@@ -136,9 +136,10 @@ export class PhysicsConstraint implements Updatable {
 				this.reset();
 			// Fall through.
 			case Physics.update:
+				const skeleton = this.skeleton;
 				const delta = Math.max(this.skeleton.time - this.lastTime, 0);
 				this.remaining += delta;
-				this.lastTime = this.skeleton.time;
+				this.lastTime = skeleton.time;
 
 				const bx = bone.worldX, by = bone.worldY;
 				if (this._reset) {
@@ -146,16 +147,18 @@ export class PhysicsConstraint implements Updatable {
 					this.ux = bx;
 					this.uy = by;
 				} else {
-					let a = this.remaining, i = this.inertia, q = this.data.limit * delta, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1;
+					let a = this.remaining, i = this.inertia, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1;
+					let qx = this.data.limit * delta, qy = qx * Math.abs(skeleton.scaleY);
+					qx *= Math.abs(skeleton.scaleX);
 					if (x || y) {
 						if (x) {
 							const u = (this.ux - bx) * i;
-							this.xOffset += u > q ? q : u < -q ? -q : u;
+							this.xOffset += u > qx ? qx : u < -qx ? -qx : u;
 							this.ux = bx;
 						}
 						if (y) {
 							const u = (this.uy - by) * i;
-							this.yOffset += u > q ? q : u < -q ? -q : u;
+							this.yOffset += u > qy ? qy : u < -qy ? -qy : u;
 							this.uy = by;
 						}
 						if (a >= t) {
@@ -181,14 +184,14 @@ export class PhysicsConstraint implements Updatable {
 					if (rotateOrShearX || scaleX) {
 						let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0;
 						let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY;
-						if (dx > q)
-							dx = q;
-						else if (dx < -q) //
-							dx = -q;
-						if (dy > q)
-							dy = q;
-						else if (dy < -q) //
-							dy = -q;
+						if (dx > qx)
+							dx = qx;
+						else if (dx < -qx) //
+							dx = -qx;
+						if (dy > qy)
+							dy = qy;
+						else if (dy < -qy) //
+							dy = -qy;
 						if (rotateOrShearX) {
 							mr = (this.data.rotate + this.data.shearX) * mix;
 							let r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr;

+ 2 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs

@@ -88,8 +88,8 @@ namespace Spine.Unity {
 			mecanimLayerFlags = DefaultMecanimLayerFlags;
 		}
 
-		protected override void Start () {
-			base.Start();
+		public override void Initialize () {
+			base.Initialize();
 			skeletonMecanim = GetComponent<SkeletonMecanim>();
 			if (skeletonMecanim) {
 				skeletonMecanim.Translator.OnClipApplied -= OnClipApplied;

+ 2 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs

@@ -88,8 +88,8 @@ namespace Spine.Unity {
 			animationTrackFlags = DefaultAnimationTrackFlags;
 		}
 
-		protected override void Start () {
-			base.Start();
+		public override void Initialize () {
+			base.Initialize();
 			IAnimationStateComponent animstateComponent = skeletonComponent as IAnimationStateComponent;
 			this.animationState = (animstateComponent != null) ? animstateComponent.AnimationState : null;
 

+ 32 - 3
spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs

@@ -27,6 +27,12 @@
  * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *****************************************************************************/
 
+// In order to respect TransformConstraints modifying the scale of parent bones,
+// GetScaleAffectingRootMotion() now uses parentBone.AScaleX and AScaleY instead
+// of previously used ScaleX and ScaleY. If you require the previous behaviour,
+// comment out the define below.
+#define USE_APPLIED_PARENT_SCALE
+
 using Spine.Unity.AnimationTools;
 using System;
 using System.Collections.Generic;
@@ -42,8 +48,7 @@ namespace Spine.Unity {
 
 		#region Inspector
 		[SpineBone]
-		[SerializeField]
-		protected string rootMotionBoneName = "root";
+		public string rootMotionBoneName = "root";
 		public bool transformPositionX = true;
 		public bool transformPositionY = true;
 		public bool transformRotation = false;
@@ -155,6 +160,14 @@ namespace Spine.Unity {
 		}
 
 		protected virtual void Start () {
+			Initialize();
+		}
+
+		protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) {
+			Initialize();
+		}
+
+		public virtual void Initialize () {
 			skeletonComponent = GetComponent<ISkeletonComponent>();
 			GatherTopLevelBones();
 			SetRootMotionBone(rootMotionBoneName);
@@ -167,6 +180,9 @@ namespace Spine.Unity {
 			if (skeletonAnimation != null) {
 				skeletonAnimation.UpdateLocal -= HandleUpdateLocal;
 				skeletonAnimation.UpdateLocal += HandleUpdateLocal;
+
+				skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild;
+				skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild;
 			}
 		}
 
@@ -198,6 +214,13 @@ namespace Spine.Unity {
 					}
 
 					Vector2 rigidbodyDisplacement2D = new Vector2(rigidbodyDisplacement.x, rigidbodyDisplacement.y);
+					// Note: MovePosition seems to be the only precise and reliable way to set movement delta,
+					// for both 2D and 3D rigidbodies.
+					// Setting velocity like "rigidBody2D.velocity = movement/deltaTime" works perfectly in mid-air
+					// without gravity and ground collision, unfortunately when on the ground, friction causes severe
+					// slowdown. Using a zero-friction PhysicsMaterial leads to sliding endlessly along the ground as
+					// soon as forces are applied. Additionally, there is no rigidBody2D.isGrounded, requiring our own
+					// checks.
 					rigidBody2D.MovePosition(gravityAndVelocityMovement + new Vector2(rigidBody2D.position.x, rigidBody2D.position.y)
 						+ rigidbodyDisplacement2D + additionalRigidbody2DMovement);
 					rigidBody2D.MoveRotation(rigidbody2DRotation + rigidBody2D.rotation);
@@ -271,7 +294,8 @@ namespace Spine.Unity {
 				this.rootMotionBone = bone;
 				FindTransformConstraintsAffectingBone();
 			} else {
-				Debug.Log("Bone named \"" + name + "\" could not be found.");
+				Debug.Log("Bone named \"" + name + "\" could not be found. " +
+					"Set 'skeletonRootMotion.rootMotionBoneName' before calling 'skeletonAnimation.Initialize(true)'.");
 				this.rootMotionBoneIndex = 0;
 				this.rootMotionBone = skeleton.RootBone;
 			}
@@ -623,8 +647,13 @@ namespace Spine.Unity {
 			parentBoneScale = Vector2.one;
 			Bone scaleBone = rootMotionBone;
 			while ((scaleBone = scaleBone.Parent) != null) {
+#if USE_APPLIED_PARENT_SCALE
+				parentBoneScale.x *= scaleBone.AScaleX;
+				parentBoneScale.y *= scaleBone.AScaleY;
+#else
 				parentBoneScale.x *= scaleBone.ScaleX;
 				parentBoneScale.y *= scaleBone.ScaleY;
+#endif
 			}
 			totalScale = Vector2.Scale(totalScale, parentBoneScale);
 			totalScale *= AdditionalScale;

+ 1 - 1
spine-unity/Assets/Spine/package.json

@@ -2,7 +2,7 @@
 	"name": "com.esotericsoftware.spine.spine-unity",
 	"displayName": "spine-unity Runtime",
 	"description": "This plugin provides the spine-unity runtime core.",
-	"version": "4.2.76",
+	"version": "4.2.78",
 	"unity": "2018.3",
 	"author": {
 		"name": "Esoteric Software",