Refactor: Bidirectionality on Graph Editor Sliders #107173

Merged
Christoph Lendenfeld merged 5 commits from ChrisLend/blender:fix_slider_range into main 2023-06-02 12:22:38 +02:00
2 changed files with 22 additions and 15 deletions

View File

@ -308,19 +308,18 @@ static const BezTriple *fcurve_segment_end_get(FCurve *fcu, int index)
void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
{
const float blend_factor = fabs(factor * 2 - 1);
const BezTriple *target_bezt;
/* Find which key to blend towards. */
if (factor < 0.5f) {
if (factor < 0) {
target_bezt = fcurve_segment_start_get(fcu, segment->start_index);
}
else {
target_bezt = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
}
const float lerp_factor = fabs(factor);
/* Blend each key individually. */
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
const float key_y_value = interpf(
target_bezt->vec[1][1], fcu->bezt[i].vec[1][1], blend_factor);
const float key_y_value = interpf(target_bezt->vec[1][1], fcu->bezt[i].vec[1][1], lerp_factor);
BKE_fcurve_keyframe_move_value_with_handles(&fcu->bezt[i], key_y_value);
}
}
@ -457,8 +456,8 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor
/* In order to have a curve that favors the right key, the curve needs to be mirrored in x and y.
* Having an exponent that is a fraction of 1 would produce a similar but inferior result. */
const bool inverted = factor > 0.5;
const float exponent = 1 + fabs(factor * 2 - 1) * 4;
const bool inverted = factor > 0;
const float exponent = 1 + fabs(factor) * 4;
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
/* For easy calculation of the curve, the values are normalized. */
@ -485,8 +484,9 @@ void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float f
const BezTriple *right_bezt = fcurve_segment_end_get(fcu,
segment->start_index + segment->length);
const float lerp_factor = (factor + 1) / 2;
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
const float key_y_value = interpf(right_bezt->vec[1][1], left_bezt->vec[1][1], factor);
const float key_y_value = interpf(right_bezt->vec[1][1], left_bezt->vec[1][1], lerp_factor);
BKE_fcurve_keyframe_move_value_with_handles(&fcu->bezt[i], key_y_value);
}
}

View File

@ -643,6 +643,8 @@ static int blend_to_neighbor_invoke(bContext *C, wmOperator *op, const wmEvent *
gso->modal_update = blend_to_neighbor_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
common_draw_status_header(C, gso, "Blend to Neighbor");
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}
@ -683,12 +685,12 @@ void GRAPH_OT_blend_to_neighbor(wmOperatorType *ot)
RNA_def_float_factor(ot->srna,
"factor",
1.0f / 3.0f,
0.0f,
-FLT_MAX,
FLT_MAX,
"Blend",
"The blend factor with 0.5 being the current frame",
0.0f,
"The blend factor with 0 being the current frame",
-1.0f,
1.0f);
}
@ -728,6 +730,8 @@ static int breakdown_invoke(bContext *C, wmOperator *op, const wmEvent *event)
gso->modal_update = breakdown_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
common_draw_status_header(C, gso, "Breakdown");
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}
@ -768,12 +772,12 @@ void GRAPH_OT_breakdown(wmOperatorType *ot)
RNA_def_float_factor(ot->srna,
"factor",
1.0f / 3.0f,
0.0f,
-FLT_MAX,
FLT_MAX,
"Factor",
"Favor either the left or the right key",
0.0f,
-1.0f,
1.0f);
}
@ -833,6 +837,7 @@ static int blend_to_default_invoke(bContext *C, wmOperator *op, const wmEvent *e
gso->modal_update = blend_to_default_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
common_draw_status_header(C, gso, "Blend to Default Value");
ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}
@ -873,7 +878,7 @@ void GRAPH_OT_blend_to_default(wmOperatorType *ot)
RNA_def_float_factor(ot->srna,
"factor",
1.0f / 3.0f,
0.0f,
-FLT_MAX,
FLT_MAX,
"Factor",
@ -917,6 +922,8 @@ static int ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
gso->modal_update = ease_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
common_draw_status_header(C, gso, "Ease Keys");
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}
@ -958,12 +965,12 @@ void GRAPH_OT_ease(wmOperatorType *ot)
RNA_def_float_factor(ot->srna,
"factor",
0.5f,
0.0f,
-FLT_MAX,
FLT_MAX,
"Curve Bend",
"Control the bend of the curve",
0.0f,
-1.0f,
1.0f);
}