Merge pull request #1725 from MellowArpeggiation/master

Fixes to bezier fcurves
This commit is contained in:
HbmMods 2024-10-08 20:13:25 +02:00 committed by GitHub
commit 7b127888c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 9 deletions

Binary file not shown.

View File

@ -120,6 +120,31 @@ public class BusAnimationKeyframe {
double v4x = startTime + duration;
double v4y = value;
// correct beziers into non-looping fcurves
double h1x = v1x - v2x;
double h1y = v1y - v2y;
double h2x = v4x - v3x;
double h2y = v4y - v3y;
double len = v4x - v1x;
double len1 = Math.abs(h1x);
double len2 = Math.abs(h2x);
if(len1 + len2 != 0) {
if(len1 > len) {
double fac = len / len1;
v2x = v1x - fac * h1x;
v2y = v1y - fac * h1y;
}
if(len2 > len) {
double fac = len / len2;
v3x = v4x - fac * h2x;
v3y = v4y - fac * h2y;
}
}
double curveT = findZero(currentTime, v1x, v2x, v3x, v4x);
return cubicBezier(v1y, v2y, v3y, v4y, curveT);
} else if(previous.interpolationType == IType.BACK) {
@ -200,7 +225,7 @@ public class BusAnimationKeyframe {
// Blender bezier solvers, but rewritten (pain)
private double solveCubic(double c0, double c1, double c2, double c3) {
if(c3 != 0) {
if(c3 > 0.000001) {
double a = c2 / c3;
double b = c1 / c3;
double c = c0 / c3;
@ -242,10 +267,10 @@ public class BusAnimationKeyframe {
double b = c1;
double c = c0;
if(a != 0) {
if(a > 0.000001) {
double p = b * b - 4 * a * c;
if(p > 0) {
if(p > 0.000001) {
p = Math.sqrt(p);
double result = (-b - p) / (2 * a);
if(result < 0.000001 || result > 1.000001) {
@ -259,14 +284,10 @@ public class BusAnimationKeyframe {
}
}
if(b != 0) {
if(b > 0.000001) {
return -c / b;
}
if(c == 0) {
return 0;
}
return 0;
}

File diff suppressed because one or more lines are too long