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.
1 changed files with 18 additions and 7 deletions
Showing only changes of commit 74e78bfef6 - Show all commits

View File

@ -500,13 +500,16 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
const float right_x = right_key->vec[1][0];

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.
const float right_y = right_key->vec[1][1];
/* We need the one key on the outside side of the neighboring keys to use as reference. */
/* One key on the outside left side of the neighboring keys is needed to use as reference. */
const BezTriple *beyond_left_key = fcurve_segment_start_get(fcu, segment->start_index - 1);
const float beyond_left_x = beyond_left_key->vec[1][0];
const float beyond_left_y = beyond_left_key->vec[1][1];
/* One key on the outside right side of the neighboring keys is needed to use as reference. */
const BezTriple *beyond_right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length + 1);
const float beyond_right_x = beyond_right_key->vec[1][0];

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.
const float beyond_right_y = beyond_right_key->vec[1][1];
@ -525,16 +528,24 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
/* The factor goes from 0 to 1, but for this tool it needs to go from 0 to 1 on each side of the slider. */
const float ping_pong_factor = fabs(factor * 2 - 1);
float x_delta;
float y_delta;
float x_delta = 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
float y_delta = 0;
/* This delta values are used to know the relationship between the bookend keys and the
* reference keys beyong those. */
if(slider_right_side){
/* Stop the fucntion if there is no key beyond the the right neighboring one. */
if(segment->start_index + segment->length == fcu->totvert) {
return;

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 = ...`
}
y_delta = beyond_right_y - right_y;
x_delta = beyond_right_x - right_x;

this code can be moved to the first if else

this code can be moved to the first `if else`
}
else if(slider_left_side){
/* Stop the fucntion if there is no key beyond the left neighboring one. */
if(segment->start_index == 0) {
return;
}
y_delta = beyond_left_y - left_y;
x_delta = beyond_left_x - left_x;
}
@ -545,9 +556,9 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
float new_x_delta;
float new_y_delta;
float refe;
float new_x_delta = 0;
float new_y_delta = 0;
float refe = 0;
/* This new deltas are used to determin the relationship between the current key and the bookend ones. */

generally it is better to not shorten variables. I assume this means reference
I think it would be even better to be more concrete and call it reference_y

Also I think this, including the if(slider_right_side), can be moved outside of the for loop.
It seems to not change within the for loop

generally it is better to not shorten variables. I assume this means `reference` I think it would be even better to be more concrete and call it `reference_y` Also I think this, including the `if(slider_right_side)`, can be moved outside of the for loop. It seems to not change within the for loop
if (slider_right_side) {