From 33b31aeadd0c70c5b88f4ef59d02d0814ab013b6 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Oct 2022 16:23:37 +0200 Subject: [PATCH] [ts] Port of commit 3ea4f66. AnimationState, fixed rotation mix when direction changes. See #2158. --- spine-ts/spine-core/src/AnimationState.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/spine-ts/spine-core/src/AnimationState.ts b/spine-ts/spine-core/src/AnimationState.ts index 1435960ee..03a020ecd 100644 --- a/spine-ts/spine-core/src/AnimationState.ts +++ b/spine-ts/spine-core/src/AnimationState.ts @@ -394,17 +394,21 @@ export class AnimationState { lastTotal = 0; lastDiff = diff; } else { - lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops. - lastDiff = timelinesRotation[i + 1]; // Difference between bones. + lastTotal = timelinesRotation[i]; + lastDiff = timelinesRotation[i + 1]; } - let current = diff > 0, dir = lastTotal >= 0; - // Detect cross at 0 (not 180). - if (MathUtils.signum(lastDiff) != MathUtils.signum(diff) && Math.abs(lastDiff) <= 90) { - // A cross after a 360 rotation is a loop. - if (Math.abs(lastTotal) > 180) lastTotal += 360 * MathUtils.signum(lastTotal); - dir = current; + let loops = lastTotal - lastTotal % 360; + total = diff + loops; + let current = diff >= 0, dir = lastTotal >= 0; + if (Math.abs(lastDiff) <= 90 && MathUtils.signum(lastDiff) != MathUtils.signum(diff)) { + if (Math.abs(lastTotal - loops) > 180) { + total += 360 * MathUtils.signum(lastTotal); + dir = current; + } else if (loops != 0) + total -= 360 * MathUtils.signum(lastTotal); + else + dir = current; } - total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal. if (dir != current) total += 360 * MathUtils.signum(lastTotal); timelinesRotation[i] = total; }