From d2953d6053b0ae9f3634cedb94687b84481ab445 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 10 Jul 2024 17:36:04 +0200 Subject: [PATCH 01/11] [unity] Automatically updating SkeletonRootMotion references after SkeletonDataAsset change. Exposed `rootMotionBoneName`. Closes #2575. --- CHANGELOG.md | 1 + .../RootMotion/SkeletonMecanimRootMotion.cs | 4 ++-- .../Components/RootMotion/SkeletonRootMotion.cs | 4 ++-- .../RootMotion/SkeletonRootMotionBase.cs | 17 ++++++++++++++--- spine-unity/Assets/Spine/package.json | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1be6312..e71f765f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs index 4dbc7d2f1..4e031166e 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs +++ b/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(); if (skeletonMecanim) { skeletonMecanim.Translator.OnClipApplied -= OnClipApplied; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs index 6bc6c0b60..2086c3e2a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs +++ b/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; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index a85b077ba..0e88ad732 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -42,8 +42,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 +154,14 @@ namespace Spine.Unity { } protected virtual void Start () { + Initialize(); + } + + protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) { + Initialize(); + } + + public virtual void Initialize () { skeletonComponent = GetComponent(); GatherTopLevelBones(); SetRootMotionBone(rootMotionBoneName); @@ -167,6 +174,9 @@ namespace Spine.Unity { if (skeletonAnimation != null) { skeletonAnimation.UpdateLocal -= HandleUpdateLocal; skeletonAnimation.UpdateLocal += HandleUpdateLocal; + + skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild; + skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild; } } @@ -271,7 +281,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; } diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index a94a81c48..5150344c7 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/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.77", "unity": "2018.3", "author": { "name": "Esoteric Software", From be3aa5f70ea688f16b5214b8787682e52db2efcd Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 11 Jul 2024 18:56:27 -1000 Subject: [PATCH 02/11] [libgdx] Scale physics constraint limits with skeleton scale. --- .../spine/PhysicsConstraint.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index dcb28f684..ce3720a6f 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/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 * skeleton.scaleY; + qx *= 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; From cbed5fbf40f17f4392542725ab8a06845d84a830 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Fri, 12 Jul 2024 09:00:01 +0200 Subject: [PATCH 03/11] [ts] Port: Scale physics constraint limits with skeleton scale. See #2576. --- spine-ts/spine-core/src/PhysicsConstraint.ts | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/spine-ts/spine-core/src/PhysicsConstraint.ts b/spine-ts/spine-core/src/PhysicsConstraint.ts index d90493e53..4af8a62e7 100644 --- a/spine-ts/spine-core/src/PhysicsConstraint.ts +++ b/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 * skeleton.scaleY; + qx *= 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; From d08f346deaede224b5765b4f1b8753bbbac87130 Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Fri, 12 Jul 2024 09:13:51 +0200 Subject: [PATCH 04/11] [haxe] Port: Scale physics constraint limits with skeleton scale. See #2576. --- .../spine-haxe/spine/PhysicsConstraint.hx | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx b/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx index e660d1563..a299fdd84 100644 --- a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx +++ b/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 * skeleton.scaleY; + qx *= 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; From cc55a2eeba44b95108e6c9c18cab3863c8bbf5ea Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 12 Jul 2024 17:52:52 +0200 Subject: [PATCH 05/11] [unity] Minor: RootMotion: commented failed experiments with setting velocity instead of MovePosition. --- .../Components/RootMotion/SkeletonRootMotionBase.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index 0e88ad732..1a260768f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -208,6 +208,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); From 112bea0603fa835787e46cb959c07e1ed5b09dfa Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Fri, 12 Jul 2024 07:08:43 -1000 Subject: [PATCH 06/11] [libgdx] Fixed physics constraint limit with negative skeleton scale. ref #2576 --- .../src/com/esotericsoftware/spine/PhysicsConstraint.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index ce3720a6f..87fb116d5 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -153,8 +153,8 @@ public class PhysicsConstraint implements Updatable { uy = by; } else { float a = remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale, d = -1; - float qx = data.limit * delta, qy = qx * skeleton.scaleY; - qx *= skeleton.scaleX; + 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; From 884af914a2c5b7ffb1e7dda3b6a953b6741ee8f5 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 12 Jul 2024 19:08:54 +0200 Subject: [PATCH 07/11] [csharp] Port of be3aa5f: Scale physics constraint limits with skeleton scale. Includes additional abs(skeleton.ScaleXY) fix. See #2576. --- spine-csharp/src/PhysicsConstraint.cs | 26 +++++++++++++++----------- spine-csharp/src/package.json | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/spine-csharp/src/PhysicsConstraint.cs b/spine-csharp/src/PhysicsConstraint.cs index 4221b0aec..50c601cdf 100644 --- a/spine-csharp/src/PhysicsConstraint.cs +++ b/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,16 +158,19 @@ 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; + 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) { @@ -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; diff --git a/spine-csharp/src/package.json b/spine-csharp/src/package.json index c52b7612f..45e4e0f79 100644 --- a/spine-csharp/src/package.json +++ b/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.26", "unity": "2018.3", "author": { "name": "Esoteric Software", From 520c0750f55d430f439a85eb87e7c360aa6d4bcc Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Fri, 12 Jul 2024 10:18:03 +0200 Subject: [PATCH 08/11] [ts] Port: Scale physics constraint limits with skeleton scale. See #2576. --- spine-ts/spine-core/src/PhysicsConstraint.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-ts/spine-core/src/PhysicsConstraint.ts b/spine-ts/spine-core/src/PhysicsConstraint.ts index 4af8a62e7..2870ecbf7 100644 --- a/spine-ts/spine-core/src/PhysicsConstraint.ts +++ b/spine-ts/spine-core/src/PhysicsConstraint.ts @@ -148,8 +148,8 @@ export class PhysicsConstraint implements Updatable { this.uy = by; } else { 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 * skeleton.scaleY; - qx *= skeleton.scaleX; + 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; From 42079d1d2307b362bb9b5fc25f0bebc4f132ca5c Mon Sep 17 00:00:00 2001 From: Davide Tantillo Date: Fri, 12 Jul 2024 10:22:26 +0200 Subject: [PATCH 09/11] [haxe] Port: Scale physics constraint limits with skeleton scale. See #2576. --- spine-haxe/spine-haxe/spine/PhysicsConstraint.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx b/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx index a299fdd84..19d92c384 100644 --- a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx +++ b/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx @@ -141,8 +141,8 @@ class PhysicsConstraint implements Updatable { d:Float = -1; var qx:Float = _data.limit * delta, - qy:Float = qx * skeleton.scaleY; - qx *= skeleton.scaleX; + qy:Float = qx * Math.abs(skeleton.scaleY); + qx *= Math.abs(skeleton.scaleX); if (x || y) { if (x) { var u:Float = (ux - bx) * i; From 59bcffcf42654465903638811e18c51c87a5c240 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 16 Jul 2024 11:43:54 +0200 Subject: [PATCH 10/11] [csharp] Port of commit ad71a986a, PhysicsConstraint clean up. --- spine-csharp/src/PhysicsConstraint.cs | 14 +++++++------- spine-csharp/src/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spine-csharp/src/PhysicsConstraint.cs b/spine-csharp/src/PhysicsConstraint.cs index 50c601cdf..1ab3000a9 100644 --- a/spine-csharp/src/PhysicsConstraint.cs +++ b/spine-csharp/src/PhysicsConstraint.cs @@ -158,7 +158,7 @@ namespace Spine { ux = bx; uy = by; } else { - float a = remaining, i = inertia, 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); @@ -174,8 +174,8 @@ namespace Spine { 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; @@ -221,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) { @@ -245,7 +245,7 @@ namespace Spine { } } } - this.remaining = a; + remaining = a; } cx = bone.worldX; cy = bone.worldY; @@ -299,7 +299,7 @@ namespace Spine { } /// The bone constrained by this physics constraint. - 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; } } diff --git a/spine-csharp/src/package.json b/spine-csharp/src/package.json index 45e4e0f79..967424a88 100644 --- a/spine-csharp/src/package.json +++ b/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.26", + "version": "4.2.27", "unity": "2018.3", "author": { "name": "Esoteric Software", From 3e8c9dfa6681a8d3fab736158eda4402bc85ea80 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 16 Jul 2024 18:14:17 +0200 Subject: [PATCH 11/11] [unity] Fixed SkeletonRootMotion ignoring parent bone scale set via transform constraints. Closes #2580. --- CHANGELOG.md | 3 ++- .../Components/RootMotion/SkeletonRootMotionBase.cs | 11 +++++++++++ spine-unity/Assets/Spine/package.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e71f765f2..f504cf432 100644 --- a/CHANGELOG.md +++ b/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** @@ -174,6 +174,7 @@ - Inspector: String attribute `SpineSkin()` now allows to include `` 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()`. - 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** diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index 1a260768f..7559a7039 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/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; @@ -641,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; diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index 5150344c7..4e722c65b 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/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.77", + "version": "4.2.78", "unity": "2018.3", "author": { "name": "Esoteric Software",