Skip to content

Commit 404272d

Browse files
Prevents introducing a NAN in two bone IK computation, which was causing instability when softening target position.
1 parent 875728a commit 404272d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
Release version next
3+
----------------------
4+
5+
* Library
6+
- [animation] Prevents introducing a NAN in two bone IK computation, which was causing instability when softening target position.
7+
18
Release version 0.16.0
29
----------------------
310

src/animation/runtime/ik_two_bone_job.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ bool SoftenTarget(const IKTwoBoneJob& _job, const IKConstantSetup& _setup,
121121
const SimdFloat4 lengths =
122122
Sqrt(SetZ(SetY(_setup.start_mid_ss_len2, _setup.mid_end_ss_len2),
123123
start_target_original_ss_len2));
124-
const SimdFloat4 start_mid_ss_len = lengths;
124+
const SimdFloat4 start_mid_ss_len =
125+
SplatX(lengths); // Makes sure no NAN in .yzw
125126
const SimdFloat4 mid_end_ss_len = SplatY(lengths);
126127
const SimdFloat4 start_target_original_ss_len = SplatZ(lengths);
127128
const SimdFloat4 bone_len_diff_abs =
@@ -149,6 +150,7 @@ bool SoftenTarget(const IKTwoBoneJob& _job, const IKConstantSetup& _setup,
149150
if ((comp_mask & 0xb) == 0xb) {
150151
// Finds interpolation ratio (aka alpha).
151152
const SimdFloat4 alpha = (start_target_original_ss_len - da) * RcpEstX(ds);
153+
152154
// Approximate an exponential function with : 1-(3^4)/(alpha+3)^4
153155
// The derivative must be 1 for x = 0, and y must never exceeds 1.
154156
// Negative x aren't used.
@@ -171,8 +173,8 @@ bool SoftenTarget(const IKTwoBoneJob& _job, const IKConstantSetup& _setup,
171173

172174
// The maximum distance we can reach is the soften bone chain length: da
173175
// (stored in !x). The minimum distance we can reach is the absolute value of
174-
// the difference of the 2 bone lengths, |d1-d2| (stored in z). x is 0 and z
175-
// is 1, yw are untested.
176+
// the difference of the 2 bone lengths, |d1-d2| (stored in z).
177+
// Hence: x is 0 and z is 1, yw are untested.
176178
return (comp_mask & 0x5) == 0x4;
177179
}
178180

0 commit comments

Comments
 (0)