Animation: blend offset slider #106518
@ -494,27 +494,11 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor
|
||||
void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
||||
{
|
||||
const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
const float left_x = left_key->vec[1][0];
|
||||
const float left_y = left_key->vec[1][1];
|
||||
|
||||
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
|
||||
const float right_x = right_key->vec[1][0];
|
||||
const float right_y = right_key->vec[1][1];
|
||||
|
||||
const BezTriple *segment_first_key = fcurve_segment_start_get(fcu, segment->start_index + 1);
|
||||
|
||||
const float segment_first_key_y = segment_first_key->vec[1][1];
|
||||
|
||||
const BezTriple *segment_last_key = fcurve_segment_end_get(
|
||||
fcu, segment->start_index + segment->length - 1);
|
||||
const float segment_last_key_y = segment_last_key->vec[1][1];
|
||||
|
||||
const float key_x_range = right_x - left_x;
|
||||
|
||||
/* Happens if there is only 1 key on the FCurve. Needs to be skipped because it
|
||||
* would be a divide by 0. */
|
||||
if (IS_EQF(key_x_range, 0.0f)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* The calculation needs diferent values for each side of the slider. */
|
||||
const bool slider_right_side = factor > 0.5;
|
||||
@ -526,10 +510,10 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa
|
||||
float y_delta;
|
||||
|
||||
if (slider_right_side) {
|
||||
if you use if you use `ED_slider_is_bidirectional_set` you can just say `factor > 0` and remove the boolean
That way this function doesn't even need to have an implicit notion of where the value came from
AresDeveaux
commented
I just tried this. One problem with a bidirectional slider is that the factor is always going to be more than zero, so the If there is a way to know what side of the slider the value is coming from I could use I just tried this. One problem with a bidirectional slider is that the factor is always going to be more than zero, so the `else` part of the if statement is never executed. I still need to know what side of the slider the value is coming from. If the factor is from 0 to 1 I can, and by using `ping_pong_factor = fabs(factor * 2 - 1)` I have been simulating what now I should call "bidirectional_factor" instead of "ping_pong_factor"
If there is a way to know what side of the slider the value is coming from I could use `ED_slider_is_bidirectional_set`
hm sorry I think that was my bad. I thought this would set the slider to a -1/1 range but it does not. It just allows negative values. hm sorry I think that was my bad. I thought this would set the slider to a -1/1 range but it does not. It just allows negative values.
In that case your implementation is correct until we add that feature to the slider :)
|
||||
y_delta = right_y - segment_last_key_y;
|
||||
y_delta = right_key->vec[1][1] - segment_last_key->vec[1][1];
|
||||
}
|
||||
else {
|
||||
y_delta = left_y - segment_first_key_y;
|
||||
y_delta = left_key->vec[1][1] - segment_first_key->vec[1][1];
|
||||
}
|
||||
|
||||
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
|
||||
|
this can be simplified to
fcu->bezt[segment->start_index]
same for getting the segment end
Since ``y_delta * fabs(factor)` doesnt' change over the course of this loop, take it out of the loop: