From 3fd5ed2287f69a13f30128a6020dae0b57a3247b Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Tue, 4 Apr 2023 20:07:21 -0400 Subject: [PATCH 01/17] Fixed IK constraint NaN when a parent bone has zero scale. --- .../src/com/esotericsoftware/spine/IkConstraint.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java index f4f1987eb..ef8545d8a 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java @@ -186,7 +186,7 @@ public class IkConstraint implements Updatable { ty = targetY - bone.worldY; break; case noRotationOrReflection: - float s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + float s = Math.abs(pa * pd - pb * pc) / Math.max(0.0001f, pa * pa + pc * pc); float sa = pa / bone.skeleton.scaleX; float sc = pc / bone.skeleton.scaleY; pb = -sc * s * bone.skeleton.scaleX; @@ -195,7 +195,7 @@ public class IkConstraint implements Updatable { // Fall through. default: float x = targetX - p.worldX, y = targetY - p.worldY; - float d = pa * pd - pb * pc; + float d = Math.max(0.0001f, pa * pd - pb * pc); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; } @@ -264,7 +264,7 @@ public class IkConstraint implements Updatable { b = pp.b; c = pp.c; d = pp.d; - float id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + float id = 1 / Math.max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From f5fb9b5aa2d05ed0b3f6b8692c8450e23e5cfee4 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 5 Apr 2023 10:43:58 +0200 Subject: [PATCH 02/17] [csharp] Port of commit 3fd5ed22 - Fixed IK constraint NaN when a parent bone has zero scale. --- spine-csharp/src/IkConstraint.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index b54773ecd..3d3ed93c7 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -172,7 +172,7 @@ namespace Spine { ty = targetY - bone.worldY; break; case TransformMode.NoRotationOrReflection: { - float s = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + float s = Math.Abs(pa * pd - pb * pc) / Math.Max(0.0001f, pa * pa + pc * pc); float sa = pa / bone.skeleton.ScaleX; float sc = pc / bone.skeleton.ScaleY; pb = -sc * s * bone.skeleton.ScaleX; @@ -182,7 +182,7 @@ namespace Spine { } default: { float x = targetX - p.worldX, y = targetY - p.worldY; - float d = pa * pd - pb * pc; + float d = Math.Max(0.0001f, pa * pd - pb * pc); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; break; @@ -256,7 +256,7 @@ namespace Spine { b = pp.b; c = pp.c; d = pp.d; - float id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + float id = 1 / Math.Max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From 22603c3f0791dfa174e04ca6b8a113996d8abe36 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:05:33 +0200 Subject: [PATCH 03/17] [ts] Fixed IK constraint NaN when a parent bone has zero scale. --- spine-ts/index.html | 2 +- spine-ts/spine-core/src/IkConstraint.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spine-ts/index.html b/spine-ts/index.html index 02607684a..bb13ebed6 100644 --- a/spine-ts/index.html +++ b/spine-ts/index.html @@ -18,7 +18,7 @@
  • Phaser
  • Player
    • diff --git a/spine-ts/spine-core/src/IkConstraint.ts b/spine-ts/spine-core/src/IkConstraint.ts index c17cfe0fe..215ce4a2a 100644 --- a/spine-ts/spine-core/src/IkConstraint.ts +++ b/spine-ts/spine-core/src/IkConstraint.ts @@ -117,7 +117,10 @@ export class IkConstraint implements Updatable { ty = targetY - bone.worldY; break; case TransformMode.NoRotationOrReflection: - let s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + let t = pa * pa + pc * pc; + if (t > 0) t = Math.max(0.0001, t); + else t = Math.min(-0.0001, t); + let s = Math.abs(pa * pd - pb * pc) / t; let sa = pa / bone.skeleton.scaleX; let sc = pc / bone.skeleton.scaleY; pb = -sc * s * bone.skeleton.scaleX; @@ -127,6 +130,8 @@ export class IkConstraint implements Updatable { default: let x = targetX - p.worldX, y = targetY - p.worldY; let d = pa * pd - pb * pc; + if (d > 0) t = Math.max(0.0001, d); + else t = Math.min(-0.0001, d); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; } @@ -194,7 +199,9 @@ export class IkConstraint implements Updatable { b = pp.b; c = pp.c; d = pp.d; - let id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + let id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; + if (id > 0) id = 1 / Math.max(0.0001, id); + else id = 1 / Math.min(-0.0001, id); let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001) { From de52f2a9e3c26a536c7f9b30be9b242fef60a2ef Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:06:03 +0200 Subject: [PATCH 04/17] [c] Formatting. --- spine-c/spine-c/src/spine/Atlas.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spine-c/spine-c/src/spine/Atlas.c b/spine-c/spine-c/src/spine/Atlas.c index 92efd9091..63671e18d 100644 --- a/spine-c/spine-c/src/spine/Atlas.c +++ b/spine-c/spine-c/src/spine/Atlas.c @@ -99,11 +99,11 @@ spAtlasPage *spAtlasPage_create(spAtlas *atlas, const char *name) { spAtlasPage *self = NEW(spAtlasPage); CONST_CAST(spAtlas *, self->atlas) = atlas; MALLOC_STR(self->name, name); - self->minFilter = SP_ATLAS_NEAREST; - self->magFilter = SP_ATLAS_NEAREST; - self->format = SP_ATLAS_RGBA8888; - self->uWrap = SP_ATLAS_CLAMPTOEDGE; - self->vWrap = SP_ATLAS_CLAMPTOEDGE; + self->minFilter = SP_ATLAS_NEAREST; + self->magFilter = SP_ATLAS_NEAREST; + self->format = SP_ATLAS_RGBA8888; + self->uWrap = SP_ATLAS_CLAMPTOEDGE; + self->vWrap = SP_ATLAS_CLAMPTOEDGE; return self; } From 09c14b7b31c19781d8d17e9e3b734e80948f69bc Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:09:29 +0200 Subject: [PATCH 05/17] [ts] Fixed IK constraint NaN when a parent bone has zero scale. --- spine-ts/spine-core/src/IkConstraint.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spine-ts/spine-core/src/IkConstraint.ts b/spine-ts/spine-core/src/IkConstraint.ts index 215ce4a2a..98ae43392 100644 --- a/spine-ts/spine-core/src/IkConstraint.ts +++ b/spine-ts/spine-core/src/IkConstraint.ts @@ -116,11 +116,8 @@ export class IkConstraint implements Updatable { tx = targetX - bone.worldX; ty = targetY - bone.worldY; break; - case TransformMode.NoRotationOrReflection: - let t = pa * pa + pc * pc; - if (t > 0) t = Math.max(0.0001, t); - else t = Math.min(-0.0001, t); - let s = Math.abs(pa * pd - pb * pc) / t; + case TransformMode.NoRotationOrReflection: + let s = Math.abs(pa * pd - pb * pc) / Math.max(0.0001, pa * pa + pc * pc); let sa = pa / bone.skeleton.scaleX; let sc = pc / bone.skeleton.scaleY; pb = -sc * s * bone.skeleton.scaleX; @@ -130,8 +127,8 @@ export class IkConstraint implements Updatable { default: let x = targetX - p.worldX, y = targetY - p.worldY; let d = pa * pd - pb * pc; - if (d > 0) t = Math.max(0.0001, d); - else t = Math.min(-0.0001, d); + if (d > 0) d = Math.max(0.0001, d); + else d = Math.min(-0.0001, d); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; } From db90982453971744d42a5cac21bbe78d92f326de Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:10:31 +0200 Subject: [PATCH 06/17] [ts] Formatting. --- spine-ts/spine-core/src/IkConstraint.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-ts/spine-core/src/IkConstraint.ts b/spine-ts/spine-core/src/IkConstraint.ts index 98ae43392..04874bd4e 100644 --- a/spine-ts/spine-core/src/IkConstraint.ts +++ b/spine-ts/spine-core/src/IkConstraint.ts @@ -116,7 +116,7 @@ export class IkConstraint implements Updatable { tx = targetX - bone.worldX; ty = targetY - bone.worldY; break; - case TransformMode.NoRotationOrReflection: + case TransformMode.NoRotationOrReflection: let s = Math.abs(pa * pd - pb * pc) / Math.max(0.0001, pa * pa + pc * pc); let sa = pa / bone.skeleton.scaleX; let sc = pc / bone.skeleton.scaleY; From 6f63f76600778db61eded0f8d0b213eed68a42d4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:30:10 +0200 Subject: [PATCH 07/17] [c] Fixed IK constraint NaN when a parent bone has zero scale. --- spine-c/spine-c/src/spine/IkConstraint.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spine-c/spine-c/src/spine/IkConstraint.c b/spine-c/spine-c/src/spine/IkConstraint.c index 5d572c457..a5b7551d2 100644 --- a/spine-c/spine-c/src/spine/IkConstraint.c +++ b/spine-c/spine-c/src/spine/IkConstraint.c @@ -84,7 +84,7 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo ty = targetY - bone->worldY; break; case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: { - s = ABS(pa * pd - pb * pc) / (pa * pa + pc * pc); + s = ABS(pa * pd - pb * pc) / MAX(0.0001f, pa * pa + pc * pc); sa = pa / bone->skeleton->scaleX; sc = pc / bone->skeleton->scaleY; pb = -sc * s * bone->skeleton->scaleX; @@ -94,6 +94,8 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo default: { float x = targetX - p->worldX, y = targetY - p->worldY; float d = pa * pd - pb * pc; + if (d > 0) d = MAX(0.0001f, d); + else d = MIN(-0.0001f, d); tx = (x * pd - y * pb) / d - bone->ax; ty = (y * pa - x * pc) / d - bone->ay; } @@ -177,7 +179,9 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t b = pp->b; c = pp->c; d = pp->d; - id = 1 / (a * d - b * c); + id = a * d - b * c; + if (id > 0) id = 1 / MAX(0.0001f, id); + else id = 1 / MIN(0.0001f, id); x = cwx - pp->worldX; y = cwy - pp->worldY; dx = (x * d - y * b) * id - px; From fb59ba45b31bf8507e72134adec67c2740c40b44 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 5 Apr 2023 15:42:26 +0200 Subject: [PATCH 08/17] [csharp] Fix of incorrect bugfix commit f5fb9b5a. Fixed IK constraint NaN when a parent bone has zero scale. --- spine-csharp/src/IkConstraint.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index 3d3ed93c7..6a6955ce0 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -182,7 +182,9 @@ namespace Spine { } default: { float x = targetX - p.worldX, y = targetY - p.worldY; - float d = Math.Max(0.0001f, pa * pd - pb * pc); + float d = pa * pd - pb * pc; + if (d > 0) d = Math.Max(0.0001f, d); + else d = Math.Min(-0.0001f, d); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; break; @@ -256,7 +258,9 @@ namespace Spine { b = pp.b; c = pp.c; d = pp.d; - float id = 1 / Math.Max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + float id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; + if (id > 0) id = 1 / Math.Max(0.0001f, id); + else id = 1 / Math.Min(-0.0001f, id); float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From c858b1a9f3e07449d08b7019ef582d33e1beea82 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:48:23 +0200 Subject: [PATCH 09/17] Fix .git-blame-ignore-revs --- .git-blame-ignore-revs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 4bc3dc693..fa8dc86b4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -61,14 +61,14 @@ f84ae17615c506bf98c575bb800d2cf3b793df4d # 2014-01-11 Updated license to version 2. d520addb9bfdf552881cb6871d70159a80e1ff6b -# 2013-10-03 9a347d5eb8ad095c5e739d959de485b6add7f0b3 -Updated license. +# 2013-10-03 Updated license. +9a347d5eb8ad095c5e739d959de485b6add7f0b3 # 2013-10-01 Minor update to the license to include education. 47ce2a40c18b8ea471e6004f7e2c6cbf5b36af76 -# 2013-09-20 e2fccf72d6541c598172a538d4d497e6d13340cc -License update. +# 2013-09-20 License update. +e2fccf72d6541c598172a538d4d497e6d13340cc # 2013 License headers. 4edc23ac2f1c00782b4f637fb2543d784bd8dda9 From 2b5bedd54371bf219651eeeed3641671039a7f6f Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:50:28 +0200 Subject: [PATCH 10/17] [c][cpp] Fixed IK constraint NaN when a parent bone has zero scale. --- spine-c/spine-c/src/spine/IkConstraint.c | 2 +- spine-cpp/spine-cpp/src/spine/IkConstraint.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spine-c/spine-c/src/spine/IkConstraint.c b/spine-c/spine-c/src/spine/IkConstraint.c index a5b7551d2..89e674a7f 100644 --- a/spine-c/spine-c/src/spine/IkConstraint.c +++ b/spine-c/spine-c/src/spine/IkConstraint.c @@ -181,7 +181,7 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t d = pp->d; id = a * d - b * c; if (id > 0) id = 1 / MAX(0.0001f, id); - else id = 1 / MIN(0.0001f, id); + else id = 1 / MIN(-0.0001f, id); x = cwx - pp->worldX; y = cwy - pp->worldY; dx = (x * d - y * b) * id - px; diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 8a9af567c..3ba9588ba 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -51,7 +51,7 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress ty = targetY - bone._worldY; break; case TransformMode_NoRotationOrReflection: { - float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc); + float s = MathUtil::abs(pa * pd - pb * pc) / MathUtil::max(0.0001f, pa * pa + pc * pc); float sa = pa / bone._skeleton.getScaleX(); float sc = pc / bone._skeleton.getScaleY(); pb = -sc * s * bone._skeleton.getScaleX(); @@ -61,6 +61,8 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress default: float x = targetX - p->_worldX, y = targetY - p->_worldY; float d = pa * pd - pb * pc; + if (d > 0) d = MathUtil::max(0.0001f, d); + d = MathUtil::min(-0.0001f, d); tx = (x * pd - y * pb) / d - bone._ax; ty = (y * pa - x * pc) / d - bone._ay; } @@ -140,8 +142,10 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY b = pp->_b; c = pp->_c; d = pp->_d; - id = 1 / (a * d - b * c); - x = cwx - pp->_worldX; + id = a * d - b * c; + if (id > 0) MathUtil::max(0.0001f, id); + else MathUtil::min(-0.0001f, id); + x = cwx - pp->_worldX; y = cwy - pp->_worldY; dx = (x * d - y * b) * id - px; dy = (y * a - x * c) * id - py; From 0fac0504ac738869a24281ba1c53c2018f24e4eb Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 5 Apr 2023 15:50:59 +0200 Subject: [PATCH 11/17] [cpp] Fix incorrectly referencing attachment when adding skin to another skin. --- spine-cpp/spine-cpp/src/spine/Skin.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/spine-cpp/spine-cpp/src/spine/Skin.cpp b/spine-cpp/spine-cpp/src/spine/Skin.cpp index 01dcbb2d9..ea4114c23 100644 --- a/spine-cpp/spine-cpp/src/spine/Skin.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skin.cpp @@ -164,7 +164,6 @@ void Skin::addSkin(Skin *other) { AttachmentMap::Entries entries = other->getAttachments(); while (entries.hasNext()) { AttachmentMap::Entry &entry = entries.next(); - entry._attachment->reference(); setAttachment(entry._slotIndex, entry._name, entry._attachment); } } From e04e7b58f3fd43cf87e17043a0fc8e14d2cbebaa Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Wed, 5 Apr 2023 17:58:42 -0400 Subject: [PATCH 12/17] Adjusted fix for IK constraint NaN when parent has zero scale. --- .../com/esotericsoftware/spine/IkConstraint.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java index ef8545d8a..417228bd0 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java @@ -195,9 +195,14 @@ public class IkConstraint implements Updatable { // Fall through. default: float x = targetX - p.worldX, y = targetY - p.worldY; - float d = Math.max(0.0001f, pa * pd - pb * pc); - tx = (x * pd - y * pb) / d - bone.ax; - ty = (y * pa - x * pc) / d - bone.ay; + float d = pa * pd - pb * pc; + if (Math.abs(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone.ax; + ty = (y * pa - x * pc) / d - bone.ay; + } } rotationIK += atan2(ty, tx) * radDeg; if (bone.ascaleX < 0) rotationIK += 180; @@ -264,7 +269,8 @@ public class IkConstraint implements Updatable { b = pp.b; c = pp.c; d = pp.d; - float id = 1 / Math.max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + float id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; + id = Math.abs(id) <= 0.0001f ? 0 : 1 / id; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From 463e18596c1e5c34e26e9d79b34869bcc769678c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 6 Apr 2023 11:01:51 +0200 Subject: [PATCH 13/17] Revert "[csharp] Fix of incorrect bugfix commit f5fb9b5a. Fixed IK constraint NaN when a parent bone has zero scale." This reverts commit fb59ba45b31bf8507e72134adec67c2740c40b44. --- spine-csharp/src/IkConstraint.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index 6a6955ce0..3d3ed93c7 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -182,9 +182,7 @@ namespace Spine { } default: { float x = targetX - p.worldX, y = targetY - p.worldY; - float d = pa * pd - pb * pc; - if (d > 0) d = Math.Max(0.0001f, d); - else d = Math.Min(-0.0001f, d); + float d = Math.Max(0.0001f, pa * pd - pb * pc); tx = (x * pd - y * pb) / d - bone.ax; ty = (y * pa - x * pc) / d - bone.ay; break; @@ -258,9 +256,7 @@ namespace Spine { b = pp.b; c = pp.c; d = pp.d; - float id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; - if (id > 0) id = 1 / Math.Max(0.0001f, id); - else id = 1 / Math.Min(-0.0001f, id); + float id = 1 / Math.Max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From 210dc04109f3ace98f2e387deaf717e1c0704552 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 6 Apr 2023 11:05:14 +0200 Subject: [PATCH 14/17] [csharp] Port of commit e04e7b5. Adjusted fix for IK constraint NaN when parent has zero scale. --- spine-csharp/src/IkConstraint.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index 3d3ed93c7..043be5db2 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -182,9 +182,14 @@ namespace Spine { } default: { float x = targetX - p.worldX, y = targetY - p.worldY; - float d = Math.Max(0.0001f, pa * pd - pb * pc); - tx = (x * pd - y * pb) / d - bone.ax; - ty = (y * pa - x * pc) / d - bone.ay; + float d = pa * pd - pb * pc; + if (Math.Abs(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone.ax; + ty = (y * pa - x * pc) / d - bone.ay; + } break; } } @@ -256,7 +261,8 @@ namespace Spine { b = pp.b; c = pp.c; d = pp.d; - float id = 1 / Math.Max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; + float id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; + id = Math.Abs(id) <= 0.0001f ? 0 : 1 / id; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001f) { From 9382265484ff44b4ee15f904aaa4431949452a6c Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Apr 2023 13:21:44 +0200 Subject: [PATCH 15/17] [ts] Port of commit e04e7b5. Adjusted fix for IK constraint NaN when parent has zero scale. --- spine-ts/spine-core/src/IkConstraint.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spine-ts/spine-core/src/IkConstraint.ts b/spine-ts/spine-core/src/IkConstraint.ts index 04874bd4e..6cc154555 100644 --- a/spine-ts/spine-core/src/IkConstraint.ts +++ b/spine-ts/spine-core/src/IkConstraint.ts @@ -127,10 +127,13 @@ export class IkConstraint implements Updatable { default: let x = targetX - p.worldX, y = targetY - p.worldY; let d = pa * pd - pb * pc; - if (d > 0) d = Math.max(0.0001, d); - else d = Math.min(-0.0001, d); - tx = (x * pd - y * pb) / d - bone.ax; - ty = (y * pa - x * pc) / d - bone.ay; + if (Math.abs(d) <= 0.0001) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone.ax; + ty = (y * pa - x * pc) / d - bone.ay; + } } rotationIK += Math.atan2(ty, tx) * MathUtils.radDeg; if (bone.ascaleX < 0) rotationIK += 180; @@ -197,8 +200,7 @@ export class IkConstraint implements Updatable { c = pp.c; d = pp.d; let id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY; - if (id > 0) id = 1 / Math.max(0.0001, id); - else id = 1 / Math.min(-0.0001, id); + id = Math.abs(id) <= 0.0001 ? 0 : 1 / id; let dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; let l1 = Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; if (l1 < 0.0001) { From 1fb89b6e89b70bbdfdf5123b96495db9b4f00a41 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Apr 2023 13:25:13 +0200 Subject: [PATCH 16/17] [c][cpp] Port of commit e04e7b5. Adjusted fix for IK constraint NaN when parent has zero scale. --- spine-c/spine-c/src/spine/IkConstraint.c | 14 ++++++++------ spine-cpp/spine-cpp/src/spine/IkConstraint.cpp | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/spine-c/spine-c/src/spine/IkConstraint.c b/spine-c/spine-c/src/spine/IkConstraint.c index 89e674a7f..337f8e96a 100644 --- a/spine-c/spine-c/src/spine/IkConstraint.c +++ b/spine-c/spine-c/src/spine/IkConstraint.c @@ -94,10 +94,13 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo default: { float x = targetX - p->worldX, y = targetY - p->worldY; float d = pa * pd - pb * pc; - if (d > 0) d = MAX(0.0001f, d); - else d = MIN(-0.0001f, d); - tx = (x * pd - y * pb) / d - bone->ax; - ty = (y * pa - x * pc) / d - bone->ay; + if (ABS(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone->ax; + ty = (y * pa - x * pc) / d - bone->ay; + } } } rotationIK += ATAN2(ty, tx) * RAD_DEG; @@ -180,8 +183,7 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t c = pp->c; d = pp->d; id = a * d - b * c; - if (id > 0) id = 1 / MAX(0.0001f, id); - else id = 1 / MIN(-0.0001f, id); + id = ABS(id) <= 0.0001f ? 0 : 1 / id; x = cwx - pp->worldX; y = cwy - pp->worldY; dx = (x * d - y * b) * id - px; diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 3ba9588ba..1d3a0dd8e 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -61,10 +61,13 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress default: float x = targetX - p->_worldX, y = targetY - p->_worldY; float d = pa * pd - pb * pc; - if (d > 0) d = MathUtil::max(0.0001f, d); - d = MathUtil::min(-0.0001f, d); - tx = (x * pd - y * pb) / d - bone._ax; - ty = (y * pa - x * pc) / d - bone._ay; + if (MathUtil::abs(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone._ax; + ty = (y * pa - x * pc) / d - bone._ay; + } } rotationIK += MathUtil::atan2(ty, tx) * MathUtil::Rad_Deg; if (bone._ascaleX < 0) rotationIK += 180; @@ -143,8 +146,7 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY c = pp->_c; d = pp->_d; id = a * d - b * c; - if (id > 0) MathUtil::max(0.0001f, id); - else MathUtil::min(-0.0001f, id); + id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id; x = cwx - pp->_worldX; y = cwy - pp->_worldY; dx = (x * d - y * b) * id - px; From da68e66e9c173c9b99ef0f566e4ddc1aab5f1b17 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Apr 2023 13:26:25 +0200 Subject: [PATCH 17/17] [c][cpp] Formatting. --- spine-c/spine-c/src/spine/IkConstraint.c | 16 ++++++++-------- spine-cpp/spine-cpp/src/spine/IkConstraint.cpp | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spine-c/spine-c/src/spine/IkConstraint.c b/spine-c/spine-c/src/spine/IkConstraint.c index 337f8e96a..a296f8dad 100644 --- a/spine-c/spine-c/src/spine/IkConstraint.c +++ b/spine-c/spine-c/src/spine/IkConstraint.c @@ -94,13 +94,13 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo default: { float x = targetX - p->worldX, y = targetY - p->worldY; float d = pa * pd - pb * pc; - if (ABS(d) <= 0.0001f) { - tx = 0; - ty = 0; - } else { - tx = (x * pd - y * pb) / d - bone->ax; - ty = (y * pa - x * pc) / d - bone->ay; - } + if (ABS(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone->ax; + ty = (y * pa - x * pc) / d - bone->ay; + } } } rotationIK += ATAN2(ty, tx) * RAD_DEG; @@ -183,7 +183,7 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t c = pp->c; d = pp->d; id = a * d - b * c; - id = ABS(id) <= 0.0001f ? 0 : 1 / id; + id = ABS(id) <= 0.0001f ? 0 : 1 / id; x = cwx - pp->worldX; y = cwy - pp->worldY; dx = (x * d - y * b) * id - px; diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 1d3a0dd8e..19b602428 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -61,13 +61,13 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress default: float x = targetX - p->_worldX, y = targetY - p->_worldY; float d = pa * pd - pb * pc; - if (MathUtil::abs(d) <= 0.0001f) { - tx = 0; - ty = 0; - } else { - tx = (x * pd - y * pb) / d - bone._ax; - ty = (y * pa - x * pc) / d - bone._ay; - } + if (MathUtil::abs(d) <= 0.0001f) { + tx = 0; + ty = 0; + } else { + tx = (x * pd - y * pb) / d - bone._ax; + ty = (y * pa - x * pc) / d - bone._ay; + } } rotationIK += MathUtil::atan2(ty, tx) * MathUtil::Rad_Deg; if (bone._ascaleX < 0) rotationIK += 180; @@ -146,8 +146,8 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY c = pp->_c; d = pp->_d; id = a * d - b * c; - id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id; - x = cwx - pp->_worldX; + id = MathUtil::abs(id) <= 0.0001f ? 0 : 1 / id; + x = cwx - pp->_worldX; y = cwy - pp->_worldY; dx = (x * d - y * b) * id - px; dy = (y * a - x * c) * id - py;