[ts] Fixed IK constraint NaN when a parent bone has zero scale.

This commit is contained in:
Mario Zechner 2023-04-05 15:05:33 +02:00
parent 5bea236326
commit 22603c3f07
2 changed files with 10 additions and 3 deletions

View File

@ -18,7 +18,7 @@
</ul>
<li>Phaser</li>
<ul>
<li><a href="/spine-phaser/example/index.html">Example</a></li>
<li><a href="/spine-phaser/example/index.html">Examples</a></li>
</ul>
<li>Player</li>
<ul>

View File

@ -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) {