Animation: blend to infinity slider #106517

Closed
AresDeveaux wants to merge 15 commits from AresDeveaux/blender:blend_to_infinity_slider into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 17 additions and 14 deletions
Showing only changes of commit 5761ec49be - Show all commits

View File

@ -500,8 +500,6 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
* slider. */
const float bidirectional_factor = fabs(factor * 2 - 1);

I think instead of splitting the vector into its two components it would be better to keep it as a vector and use the functions in math_vector_inline.c

This will potentially simplify your code quite a lot.

I think instead of splitting the vector into its two components it would be better to keep it as a vector and use the functions in `math_vector_inline.c` This will potentially simplify your code quite a lot.
float x_delta = 1;
float y_delta = 1;
BezTriple beyond_key;
const BezTriple *reference_key;
@ -510,7 +508,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
if (factor >= 0.5) {
/* Stop the function if there is no key beyond the the right neighboring one. */
if (segment->start_index + segment->length >= fcu->totvert - 1) {
if (segment->start_index + segment->length > fcu->totvert - 1) {
return;
}

this can also be clearer.
segment->start_index + segment->length > fcu->totvert

this can also be clearer. `segment->start_index + segment->length > fcu->totvert`

I tried this change as well as the next one and it doesn't work as it should. Remember, we need 2 keys before and after the segment, the way you suggest just account for one. If I don't prevent not having 2 keys at each side of the segment the tool goes crazy.

I tried this change as well as the next one and it doesn't work as it should. Remember, we need 2 keys before and after the segment, the way you suggest just account for one. If I don't prevent not having 2 keys at each side of the segment the tool goes crazy.
@ -520,7 +518,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
else {
/* Stop the function if there is no key beyond the left neighboring one. */
if (segment->start_index <= 1) {
if (segment->start_index == 1) {
return;
}

This would be clearer if you checked explicitly to 0
segment->start_index == 0

the start index will never be smaller than 0

This would be clearer if you checked explicitly to 0 `segment->start_index == 0` the start index will never be smaller than 0

I am glad you didn't listen to me here, because I just realized what I suggested is wrong 🤦

I am glad you didn't listen to me here, because I just realized what I suggested is wrong 🤦
@ -528,17 +526,14 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
beyond_key = fcu->bezt[segment->start_index - 2];

shouldn't this return false?
also now that I think about it, I am not sure x_delta can ever be 0. It would only be 0 if the beyond key and the reference key are the same, which they cannot be since you are getting different indices.
Hm ok writing this now, you can have the curve in a state where two keys are at the same point in time. Shouldn't happen, but could...

Anyway, the function should return true if it ran and false if it didn't. Since you are exiting early here, I think it should return false.

shouldn't this return false? also now that I think about it, I am not sure x_delta can ever be 0. It would only be 0 if the beyond key and the reference key are the same, which they cannot be since you are getting different indices. Hm ok writing this now, you can have the curve in a state where two keys are at the same point in time. Shouldn't happen, but could... Anyway, the function should return true if it ran and false if it didn't. Since you are exiting early here, I think it should return false.
}
y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1];
x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0];
const float y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1];
const float x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0];

since this is now outside of the if else, you can to
const float y_delta = ...
and then remove the lines 503 and 504

since this is now outside of the if else, you can to `const float y_delta = ...` and then remove the lines 503 and 504
/* Avoids dividing by 0. */
if (x_delta == 0) {
return;
}
float new_x_delta;
float new_y_delta;
if (factor >= 0.5) {
reference_key = right_key;
}

this can move into the for loop and you can then call it
const float new_x_delta = ...

this can move into the for loop and you can then call it `const float new_x_delta = ...`
@ -550,8 +545,8 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
/* These new deltas are used to determine the relationship between the current key and the
* bookend ones. */
new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0];
new_y_delta = new_x_delta * y_delta / x_delta;
const float new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0];
const float new_y_delta = new_x_delta * y_delta / x_delta;
const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1];

View File

@ -1074,9 +1074,17 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor)
ListBase segments = find_fcurve_segments(fcu);
LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
if (segment->start_index + segment->length >= fcu->totvert - 1 ||
segment->start_index <= 1) {
WM_report(RPT_WARNING, "You need at least 2 keys to eider side of the selection.");
if (factor >= 0.5){
if (segment->start_index + segment->length >= fcu->totvert - 1) {
WM_report(RPT_WARNING, "You need at least 2 keys to the right side of the selection.");

the conditions can also be simplified like above
you can also continue after the warning because the code cannot run anyway

the conditions can also be simplified like above you can also `continue` after the warning because the code cannot run anyway

your suggestion of adding continue to the condition for the warning works, but made me realize 2 things:

1.- I need to split the warning into two possibilities. One when we don't have two reference keys on the left, and another if we don't have two reference keys on the right. As it is now it locks the function even if one of the sides has all it needs (I added this)

2.- If we put continue on the condition in graph_slider_ops.c we don't need the same if statements in `keyframes_general.c' since it will never be executed. (I didn't delete them until you take a look at it)

By the way, doesn't it bother you the warning is blinking? I'm thinking it's doing that because of where I put it. I think it is refreshing as the function is called back when the slider is modified, but don't know in what function I should put it to avoid it.

your suggestion of adding continue to the condition for the warning works, but made me realize 2 things: 1.- I need to split the warning into two possibilities. One when we don't have two reference keys on the left, and another if we don't have two reference keys on the right. As it is now it locks the function even if one of the sides has all it needs (I added this) 2.- If we put continue on the condition in graph_slider_ops.c we don't need the same if statements in `keyframes_general.c' since it will never be executed. (I didn't delete them until you take a look at it) By the way, doesn't it bother you the warning is blinking? I'm thinking it's doing that because of where I put it. I think it is refreshing as the function is called back when the slider is modified, but don't know in what function I should put it to avoid it.

Let's have the warning outside of the for-loop so it's only displayed once per modal cycle
so make a bool all_segments_valid = true
and where the warning is now, set it to false

then after the 2 loops do a if(!all_segments_valid)

Let's have the warning outside of the for-loop so it's only displayed once per modal cycle so make a `bool all_segments_valid = true` and where the warning is now, set it to false then after the 2 loops do a `if(!all_segments_valid)`
continue;
}
}
else {
if (segment->start_index <= 1) {
WM_report(RPT_WARNING, "You need at least 2 keys to the left side of the selection.");
continue;
}
}
blend_to_infinity_fcurve_segment(fcu, segment, factor);
}