Animation: blend to infinity slider #106517
|
@ -437,7 +437,7 @@ void smooth_fcurve_segment(struct FCurve *fcu,
|
|||
int kernel_size,
|
||||
double *kernel);
|
||||
void ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor);
|
||||
void blend_to_infinity_fcurve_segment(struct FCurve *fcu,
|
||||
bool blend_to_infinity_fcurve_segment(struct FCurve *fcu,
|
||||
struct FCurveSegment *segment,
|
||||
float factor);
|
||||
bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max);
|
||||
|
|
|
@ -1068,31 +1068,30 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor)
|
|||
{
|
||||
ListBase anim_data = {NULL, NULL};
|
||||
|
||||
bool all_segments_valid = true;
|
||||
|
||||
ANIM_animdata_filter(ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, ac->datatype);
|
||||
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
|
||||
FCurve *fcu = (FCurve *)ale->key_data;
|
||||
ListBase segments = find_fcurve_segments(fcu);
|
||||
|
||||
LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
|
||||
if (factor >= 0){
|
||||
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.");
|
||||
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);
|
||||
all_segments_valid = blend_to_infinity_fcurve_segment(fcu, segment, factor);
|
||||
the conditions can also be simplified like above the conditions can also be simplified like above
you can also `continue` after the warning because the code cannot run anyway
AresDeveaux
commented
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 then after the 2 loops do a 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)`
|
||||
}
|
||||
|
||||
ale->update |= ANIM_UPDATE_DEFAULT;
|
||||
BLI_freelistN(&segments);
|
||||
}
|
||||
|
||||
if(!all_segments_valid) {
|
||||
if (factor >= 0){
|
||||
WM_report(RPT_WARNING, "You need at least 2 keys to the right side of the selection.");
|
||||
}
|
||||
else {
|
||||
WM_report(RPT_WARNING, "You need at least 2 keys to the left side of the selection.");
|
||||
}
|
||||
}
|
||||
|
||||
ANIM_animdata_update(ac, &anim_data);
|
||||
ANIM_animdata_freelist(&anim_data);
|
||||
}
|
||||
|
@ -1190,12 +1189,12 @@ void GRAPH_OT_blend_to_infinity(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);
|
||||
}
|
||||
|
||||
|
|
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.