Refactor: Bidirectionality on Graph Editor Sliders
This PR changes the ranges of some of the operators in the Graph Editor to be more logical The following operators have been modified to with a range of -1/1 with the default of 0 * Blend to Neighbor * Breakdown * Ease This is a breaking change because python calls to these operators will now yield different results (e.g. Blend To Neighbor at 0 does nothing now, while before it did blend to the left neighbor) Pull Request: https://projects.blender.org/blender/blender/pulls/107173
This commit is contained in:
committed by
Christoph Lendenfeld
parent
390f8fef76
commit
e73b9c95f5
@@ -309,19 +309,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);
|
||||
}
|
||||
}
|
||||
@@ -458,8 +457,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. */
|
||||
@@ -486,8 +485,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,6 +644,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;
|
||||
}
|
||||
@@ -684,12 +686,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);
|
||||
}
|
||||
|
||||
@@ -729,6 +731,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;
|
||||
}
|
||||
@@ -769,12 +773,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);
|
||||
}
|
||||
|
||||
@@ -834,6 +838,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;
|
||||
}
|
||||
@@ -874,7 +879,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",
|
||||
@@ -918,6 +923,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;
|
||||
}
|
||||
@@ -959,12 +966,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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user