From 6b0af2fa4d1f1d153958f2d52f3633b2a556f1c4 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 20:55:08 -0700 Subject: [PATCH 01/14] added functions --- scripts/startup/bl_ui/space_graph.py | 1 + .../editors/animation/keyframes_general.c | 82 ++++++++++++ .../editors/include/ED_keyframes_edit.h | 1 + .../editors/space_graph/graph_intern.h | 1 + .../blender/editors/space_graph/graph_ops.c | 1 + .../editors/space_graph/graph_slider_ops.c | 124 ++++++++++++++++++ 6 files changed, 210 insertions(+) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 999a9e3cef7..d290aad55d3 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -329,6 +329,7 @@ class GRAPH_MT_slider(Menu): layout.operator("graph.breakdown", text="Breakdown") layout.operator("graph.blend_to_neighbor", text="Blend to Neighbor") layout.operator("graph.blend_to_default", text="Blend to Default Value") + layout.operator("graph.blend_to_infinity", text="Blend to Infinity") layout.operator("graph.ease", text="Ease") layout.operator("graph.gaussian_smooth", text="Smooth") diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index f1848e4cc42..da4f9ebc1fc 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,6 +491,88 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ +void blend_to_infinity_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]; + + /* We need the one key on the outside side of the neighboring keys 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]; + + 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]; + const float beyond_right_y = beyond_right_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; + const bool slider_left_side = factor < 0.5; + + /* 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 = 0; + 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){ + y_delta = beyond_right_y - right_y; + x_delta = beyond_right_x - right_x; + } + else if(slider_left_side){ + y_delta = beyond_left_y - left_y; + x_delta = beyond_left_x - left_x; + } + else { + y_delta = 1; + x_delta = 1; + } + + for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { + + 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. */ + if (slider_right_side) { + new_x_delta = fcu->bezt[i].vec[1][0] - right_x; + refe = right_y; + } + else { + new_x_delta = fcu->bezt[i].vec[1][0] - left_x; + refe = left_key->vec[1][1]; + } + + /* we use compound rule of 3 to find the "Y" delta we are missing using the other deltas we know. */ + if(x_delta != 0){ + new_y_delta = new_x_delta * y_delta / x_delta; + } + + float delta = refe + new_y_delta - fcu->bezt[i].vec[1][1]; + + const float key_y_value = fcu->bezt[i].vec[1][1] + delta * ping_pong_factor; + move_key(&fcu->bezt[i], key_y_value); + } +} + +/* ---------------- */ + void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { const BezTriple *left_bezt = fcurve_segment_start_get(fcu, segment->start_index); diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 69f103c6cba..685fc76e927 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -437,6 +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, struct FCurveSegment *segment, float factor); bool decimate_fcurve(struct bAnimListElem *ale, float remove_ratio, float error_sq_max); void blend_to_default_fcurve(struct PointerRNA *id_ptr, struct FCurve *fcu, float factor); /** diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h index 7128f805a23..5d6640baaf6 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -114,6 +114,7 @@ void GRAPH_OT_clean(struct wmOperatorType *ot); void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot); void GRAPH_OT_breakdown(struct wmOperatorType *ot); void GRAPH_OT_ease(struct wmOperatorType *ot); +void GRAPH_OT_blend_to_infinity(struct wmOperatorType *ot); void GRAPH_OT_decimate(struct wmOperatorType *ot); void GRAPH_OT_blend_to_default(struct wmOperatorType *ot); void GRAPH_OT_gaussian_smooth(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index b64884da06c..20197c76077 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -463,6 +463,7 @@ void graphedit_operatortypes(void) WM_operatortype_append(GRAPH_OT_blend_to_neighbor); WM_operatortype_append(GRAPH_OT_breakdown); WM_operatortype_append(GRAPH_OT_ease); + WM_operatortype_append(GRAPH_OT_blend_to_infinity); WM_operatortype_append(GRAPH_OT_blend_to_default); WM_operatortype_append(GRAPH_OT_gaussian_smooth); WM_operatortype_append(GRAPH_OT_euler_filter); diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 184bd8329e8..464ac258df2 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1060,6 +1060,130 @@ void GRAPH_OT_ease(wmOperatorType *ot) 1.0f); } +/* -------------------------------------------------------------------- */ +/** \name Blend to Infinity + * \{ */ + +static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor) +{ + ListBase anim_data = {NULL, NULL}; + + 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) { + blend_to_infinity_fcurve_segment(fcu, segment, factor); + } + + ale->update |= ANIM_UPDATE_DEFAULT; + BLI_freelistN(&segments); + } + + ANIM_animdata_update(ac, &anim_data); + ANIM_animdata_freelist(&anim_data); +} + +static void blend_to_infinity_draw_status_header(bContext *C, tGraphSliderOp *gso) +{ + char status_str[UI_MAX_DRAW_STR]; + char mode_str[32]; + char slider_string[UI_MAX_DRAW_STR]; + + ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR); + + strcpy(mode_str, TIP_("Blend to Infinity Keys")); + + if (hasNumInput(&gso->num)) { + char str_ofs[NUM_STR_REP_LEN]; + + outputNumInput(&gso->num, str_ofs, &gso->scene->unit); + + BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, str_ofs); + } + else { + BLI_snprintf(status_str, sizeof(status_str), "%s: %s", mode_str, slider_string); + } + + ED_workspace_status_text(C, status_str); +} + +static void blend_to_infinity_modal_update(bContext *C, wmOperator *op) +{ + tGraphSliderOp *gso = op->customdata; + + blend_to_infinity_draw_status_header(C, gso); + + /* Reset keyframes to the state at invoke. */ + reset_bezts(gso); + const float factor = slider_factor_get_and_remember(op); + blend_to_infinity_graph_keys(&gso->ac, factor); + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); +} + +static int blend_to_infinity_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + const int invoke_result = graph_slider_invoke(C, op, event); + + if (invoke_result == OPERATOR_CANCELLED) { + return invoke_result; + } + + tGraphSliderOp *gso = op->customdata; + gso->modal_update = blend_to_infinity_modal_update; + gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); + blend_to_infinity_draw_status_header(C, gso); + + return invoke_result; +} + +static int blend_to_infinity_exec(bContext *C, wmOperator *op) +{ + bAnimContext ac; + + /* Get editor data. */ + if (ANIM_animdata_get_context(C, &ac) == 0) { + return OPERATOR_CANCELLED; + } + + const float factor = RNA_float_get(op->ptr, "factor"); + + blend_to_infinity_graph_keys(&ac, factor); + + /* Set notifier that keyframes have changed. */ + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); + + return OPERATOR_FINISHED; +} + +void GRAPH_OT_blend_to_infinity(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Blend to Infinity Keyframes"; + ot->idname = "GRAPH_OT_blend_to_infinity"; + ot->description = "Blend selected keys to the slant of neighboring ones"; + + /* API callbacks. */ + ot->invoke = blend_to_infinity_invoke; + ot->modal = graph_slider_modal; + ot->exec = blend_to_infinity_exec; + ot->poll = graphop_editable_keyframes_poll; + + /* Flags. */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_float_factor(ot->srna, + "factor", + 0.5f, + -FLT_MAX, + FLT_MAX, + "Curve Bend", + "Control the bend of the curve", + 0.0f, + 1.0f); +} + /** \} */ /* -------------------------------------------------------------------- */ /** \name Gauss Smooth Operator -- 2.30.2 From c13f51e13ea3466c9d67134c5c89523ad7815af0 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 22:53:05 -0700 Subject: [PATCH 02/14] changed "delta variable" to constant --- source/blender/editors/animation/keyframes_general.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index da4f9ebc1fc..15a5941727d 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -564,7 +564,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const new_y_delta = new_x_delta * y_delta / x_delta; } - float delta = refe + new_y_delta - fcu->bezt[i].vec[1][1]; + const float delta = refe + new_y_delta - fcu->bezt[i].vec[1][1]; const float key_y_value = fcu->bezt[i].vec[1][1] + delta * ping_pong_factor; move_key(&fcu->bezt[i], key_y_value); -- 2.30.2 From aaf9ae70e001e967499ecb5bcce3c07a09913ce7 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 23:04:36 -0700 Subject: [PATCH 03/14] changed declaration of some variables --- source/blender/editors/animation/keyframes_general.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 15a5941727d..3edcecf10ac 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -525,8 +525,8 @@ 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 = 0; - float y_delta = 0; + float x_delta; + float y_delta; /* This delta values are used to know the relationship between the bookend keys and the * reference keys beyong those. */ @@ -545,9 +545,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 = 0; - float new_y_delta = 0; - float refe = 0; + float new_x_delta; + float new_y_delta; + float refe; /* This new deltas are used to determin the relationship between the current key and the bookend ones. */ if (slider_right_side) { -- 2.30.2 From 74e78bfef69e24d79bba14a37996110590964daa Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 3 Apr 2023 01:31:37 -0700 Subject: [PATCH 04/14] fixed a bug when there is no key beyond the neighboring ones --- .../editors/animation/keyframes_general.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 3edcecf10ac..ce02d40ca65 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -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]; 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]; 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; + 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; + } y_delta = beyond_right_y - right_y; x_delta = beyond_right_x - right_x; } 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. */ if (slider_right_side) { -- 2.30.2 From 0c3f7500beec97d78556da4c658826feb79aa564 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 3 Apr 2023 11:55:33 -0700 Subject: [PATCH 05/14] Fixed some formating --- .../editors/animation/keyframes_general.c | 32 +++++++++++-------- .../editors/include/ED_keyframes_edit.h | 4 ++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index ce02d40ca65..52de4e1a034 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -500,7 +500,7 @@ 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]; const float right_y = right_key->vec[1][1]; - + /* 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); @@ -508,7 +508,8 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const 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 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]; const float beyond_right_y = beyond_right_key->vec[1][1]; @@ -525,26 +526,27 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const const bool slider_right_side = factor >= 0.5; const bool slider_left_side = factor < 0.5; - /* 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. */ + /* 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 = 0; float y_delta = 0; - /* This delta values are used to know the relationship between the bookend keys and the + /* This delta values are used to know the relationship between the bookend keys and the * reference keys beyong those. */ - if(slider_right_side){ + 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; + if (segment->start_index + segment->length == fcu->totvert) { + return; } y_delta = beyond_right_y - right_y; x_delta = beyond_right_x - right_x; } - else if(slider_left_side){ + else if (slider_left_side) { /* Stop the fucntion if there is no key beyond the left neighboring one. */ - if(segment->start_index == 0) { - return; + if (segment->start_index == 0) { + return; } y_delta = beyond_left_y - left_y; x_delta = beyond_left_x - left_x; @@ -555,12 +557,13 @@ 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 = 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. */ + /* This new deltas are used to determin the relationship between the current key and the + * bookend ones. */ if (slider_right_side) { new_x_delta = fcu->bezt[i].vec[1][0] - right_x; refe = right_y; @@ -570,8 +573,9 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const refe = left_key->vec[1][1]; } - /* we use compound rule of 3 to find the "Y" delta we are missing using the other deltas we know. */ - if(x_delta != 0){ + /* we use compound rule of 3 to find the "Y" delta we are missing using the other deltas we + * know. */ + if (x_delta != 0) { new_y_delta = new_x_delta * y_delta / x_delta; } diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 685fc76e927..72788d30064 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -437,7 +437,9 @@ 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, struct FCurveSegment *segment, float factor); +void 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); void blend_to_default_fcurve(struct PointerRNA *id_ptr, struct FCurve *fcu, float factor); /** -- 2.30.2 From c3f8c3a35df172b370bf4584ff3bd9069a707fde Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 10 Apr 2023 15:36:17 -0700 Subject: [PATCH 06/14] eliminated vertor split in elements --- .../editors/animation/keyframes_general.c | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 52de4e1a034..0b35b84c2d6 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -494,34 +494,13 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor void blend_to_infinity_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]; - /* One key on the outside left side of the neighboring keys is needed to use as reference. */ + /* One key on the outside 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]; - const float beyond_right_y = beyond_right_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; const bool slider_left_side = factor < 0.5; @@ -540,16 +519,16 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const if (segment->start_index + segment->length == fcu->totvert) { return; } - y_delta = beyond_right_y - right_y; - x_delta = beyond_right_x - right_x; + y_delta = beyond_right_key->vec[1][1] - right_key->vec[1][1]; + x_delta = beyond_right_key->vec[1][0] - right_key->vec[1][0]; } 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; + y_delta = beyond_left_key->vec[1][1] - left_key->vec[1][1]; + x_delta = beyond_left_key->vec[1][0] - left_key->vec[1][0]; } else { y_delta = 1; @@ -560,26 +539,26 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float new_x_delta = 0; float new_y_delta = 0; - float refe = 0; + float reference_y = 0; - /* This new deltas are used to determin the relationship between the current key and the + /* These new deltas are used to determine the relationship between the current key and the * bookend ones. */ if (slider_right_side) { - new_x_delta = fcu->bezt[i].vec[1][0] - right_x; - refe = right_y; + new_x_delta = fcu->bezt[i].vec[1][0] - right_key->vec[1][0]; + reference_y = right_key->vec[1][1]; } else { - new_x_delta = fcu->bezt[i].vec[1][0] - left_x; - refe = left_key->vec[1][1]; + new_x_delta = fcu->bezt[i].vec[1][0] - left_key->vec[1][0]; + reference_y = left_key->vec[1][1]; } - /* we use compound rule of 3 to find the "Y" delta we are missing using the other deltas we + /* We use compound rule of 3 to find the "Y" delta we are missing using the other deltas we * know. */ if (x_delta != 0) { new_y_delta = new_x_delta * y_delta / x_delta; } - const float delta = refe + new_y_delta - fcu->bezt[i].vec[1][1]; + const float delta = reference_y + new_y_delta - fcu->bezt[i].vec[1][1]; const float key_y_value = fcu->bezt[i].vec[1][1] + delta * ping_pong_factor; move_key(&fcu->bezt[i], key_y_value); -- 2.30.2 From 5a4881e5293fd46affb6289f4bcd69448e92aa8c Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Thu, 13 Apr 2023 21:00:11 -0700 Subject: [PATCH 07/14] rearranged the code to avoid possible "index our of range" error, and simplified the code a bit --- .../editors/animation/keyframes_general.c | 55 +++++++++---------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 0b35b84c2d6..0e8bda93bc2 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -496,69 +496,64 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); - /* One key on the outside 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 BezTriple *beyond_right_key = fcurve_segment_end_get( - fcu, segment->start_index + segment->length + 1); - - /* The calculation needs diferent values for each side of the slider. */ - const bool slider_right_side = factor >= 0.5; - const bool slider_left_side = factor < 0.5; - /* 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 = 0; - float y_delta = 0; + float x_delta = 1; + float y_delta = 1; - /* This delta values are used to know the relationship between the bookend keys and the + /* This delta values are used to get 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 (factor >= 0.5) { + /* Stop the function if there is no key beyond the the right neighboring one. */ if (segment->start_index + segment->length == fcu->totvert) { return; } + const BezTriple *beyond_right_key = fcurve_segment_end_get( + fcu, segment->start_index + segment->length + 1); + y_delta = beyond_right_key->vec[1][1] - right_key->vec[1][1]; x_delta = beyond_right_key->vec[1][0] - right_key->vec[1][0]; } - else if (slider_left_side) { - /* Stop the fucntion if there is no key beyond the left neighboring one. */ + else { + /* Stop the function if there is no key beyond the left neighboring one. */ if (segment->start_index == 0) { return; } + const BezTriple *beyond_left_key = fcurve_segment_start_get(fcu, segment->start_index - 1); + y_delta = beyond_left_key->vec[1][1] - left_key->vec[1][1]; x_delta = beyond_left_key->vec[1][0] - left_key->vec[1][0]; } - else { - y_delta = 1; - x_delta = 1; + + /* Avoids dividing by 0. */ + if (x_delta == 0) { + return; } for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { - float new_x_delta = 0; - float new_y_delta = 0; - float reference_y = 0; + float new_x_delta; + float new_y_delta; + const BezTriple *reference_key; /* These new deltas are used to determine the relationship between the current key and the * bookend ones. */ - if (slider_right_side) { + if (factor >= 0.5) { new_x_delta = fcu->bezt[i].vec[1][0] - right_key->vec[1][0]; - reference_y = right_key->vec[1][1]; + reference_key = right_key; } else { new_x_delta = fcu->bezt[i].vec[1][0] - left_key->vec[1][0]; - reference_y = left_key->vec[1][1]; + reference_key = left_key; } /* We use compound rule of 3 to find the "Y" delta we are missing using the other deltas we - * know. */ - if (x_delta != 0) { - new_y_delta = new_x_delta * y_delta / x_delta; - } + * know. */ + new_y_delta = new_x_delta * y_delta / x_delta; - const float delta = reference_y + new_y_delta - fcu->bezt[i].vec[1][1]; + const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1]; const float key_y_value = fcu->bezt[i].vec[1][1] + delta * ping_pong_factor; move_key(&fcu->bezt[i], key_y_value); -- 2.30.2 From 227980c797ebabb7f93d1e8f8060acfb6403b58a Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Thu, 13 Apr 2023 23:05:30 -0700 Subject: [PATCH 08/14] formating error --- source/blender/editors/animation/keyframes_general.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 0e8bda93bc2..190e91673d5 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -511,7 +511,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const return; } const BezTriple *beyond_right_key = fcurve_segment_end_get( - fcu, segment->start_index + segment->length + 1); + fcu, segment->start_index + segment->length + 1); y_delta = beyond_right_key->vec[1][1] - right_key->vec[1][1]; x_delta = beyond_right_key->vec[1][0] - right_key->vec[1][0]; @@ -550,7 +550,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const } /* We use compound rule of 3 to find the "Y" delta we are missing using the other deltas we - * know. */ + * know. */ new_y_delta = new_x_delta * y_delta / x_delta; const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1]; -- 2.30.2 From f54038122521e7ffa5f9ad90246f5999cf666989 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Fri, 14 Apr 2023 04:35:26 -0700 Subject: [PATCH 09/14] a lot of simplification --- .../editors/animation/keyframes_general.c | 52 +++++++++---------- .../editors/space_graph/graph_slider_ops.c | 5 ++ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 190e91673d5..409cfd46200 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -498,64 +498,64 @@ 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); + const float bidirectional_factor = fabs(factor * 2 - 1); float x_delta = 1; float y_delta = 1; + BezTriple beyond_key; + const BezTriple *reference_key; /* This delta values are used to get the relationship between the bookend keys and the * reference keys beyong those. */ if (factor >= 0.5) { + /* Stop the function if there is no key beyond the the right neighboring one. */ - if (segment->start_index + segment->length == fcu->totvert) { + if (segment->start_index + segment->length >= fcu->totvert - 1) { return; } - const BezTriple *beyond_right_key = fcurve_segment_end_get( - fcu, segment->start_index + segment->length + 1); - y_delta = beyond_right_key->vec[1][1] - right_key->vec[1][1]; - x_delta = beyond_right_key->vec[1][0] - right_key->vec[1][0]; + reference_key = right_key; + beyond_key = fcu->bezt[segment->start_index + segment->length + 1]; } else { + /* Stop the function if there is no key beyond the left neighboring one. */ - if (segment->start_index == 0) { + if (segment->start_index <= 1) { return; } - const BezTriple *beyond_left_key = fcurve_segment_start_get(fcu, segment->start_index - 1); - y_delta = beyond_left_key->vec[1][1] - left_key->vec[1][1]; - x_delta = beyond_left_key->vec[1][0] - left_key->vec[1][0]; + reference_key = left_key; + beyond_key = fcu->bezt[segment->start_index - 2]; } + y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1]; + x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0]; + /* Avoids dividing by 0. */ if (x_delta == 0) { return; } - for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { + float new_x_delta; + float new_y_delta; - float new_x_delta; - float new_y_delta; - const BezTriple *reference_key; + if (factor >= 0.5) { + reference_key = right_key; + } + else { + reference_key = left_key; + } + + for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { /* These new deltas are used to determine the relationship between the current key and the * bookend ones. */ - if (factor >= 0.5) { - new_x_delta = fcu->bezt[i].vec[1][0] - right_key->vec[1][0]; - reference_key = right_key; - } - else { - new_x_delta = fcu->bezt[i].vec[1][0] - left_key->vec[1][0]; - reference_key = left_key; - } - - /* We use compound rule of 3 to find the "Y" delta we are missing using the other deltas we - * know. */ + new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0]; new_y_delta = new_x_delta * y_delta / x_delta; const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1]; - const float key_y_value = fcu->bezt[i].vec[1][1] + delta * ping_pong_factor; + const float key_y_value = fcu->bezt[i].vec[1][1] + delta * bidirectional_factor; move_key(&fcu->bezt[i], key_y_value); } } diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 464ac258df2..e2f60f2e6e7 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1074,6 +1074,11 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { + if (segment->start_index + segment->length >= fcu->totvert - 1 || + segment->start_index <= 1) { + WM_report(RPT_WARNING, + "This operator needs at least 2 keys to either side of the selection!"); + } blend_to_infinity_fcurve_segment(fcu, segment, factor); } -- 2.30.2 From a0e005c3f64f0954927100af3026a99e74e399ea Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Fri, 14 Apr 2023 10:10:57 -0700 Subject: [PATCH 10/14] added warning --- source/blender/editors/space_graph/graph_slider_ops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index e2f60f2e6e7..3d3723ee82e 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1076,8 +1076,7 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor) LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { if (segment->start_index + segment->length >= fcu->totvert - 1 || segment->start_index <= 1) { - WM_report(RPT_WARNING, - "This operator needs at least 2 keys to either side of the selection!"); + WM_report(RPT_WARNING, "You need at least 2 keys to eider side of the selection."); } blend_to_infinity_fcurve_segment(fcu, segment, factor); } -- 2.30.2 From 5761ec49be9420629a70cef85d99fcfeadb1a978 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 17 Apr 2023 18:45:21 -0700 Subject: [PATCH 11/14] cleaned the code a bit --- .../editors/animation/keyframes_general.c | 17 ++++++----------- .../editors/space_graph/graph_slider_ops.c | 14 +++++++++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 409cfd46200..146d2ad4df1 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -500,8 +500,6 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const * slider. */ const float bidirectional_factor = fabs(factor * 2 - 1); - float x_delta = 1; - float y_delta = 1; BezTriple beyond_key; const BezTriple *reference_key; @@ -510,7 +508,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const if (factor >= 0.5) { /* Stop the function if there is no key beyond the the right neighboring one. */ - if (segment->start_index + segment->length >= fcu->totvert - 1) { + if (segment->start_index + segment->length > fcu->totvert - 1) { return; } @@ -520,7 +518,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const else { /* Stop the function if there is no key beyond the left neighboring one. */ - if (segment->start_index <= 1) { + if (segment->start_index == 1) { return; } @@ -528,17 +526,14 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const beyond_key = fcu->bezt[segment->start_index - 2]; } - y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1]; - x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0]; + const float y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1]; + const float x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0]; /* Avoids dividing by 0. */ if (x_delta == 0) { return; } - float new_x_delta; - float new_y_delta; - if (factor >= 0.5) { reference_key = right_key; } @@ -550,8 +545,8 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const /* These new deltas are used to determine the relationship between the current key and the * bookend ones. */ - new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0]; - new_y_delta = new_x_delta * y_delta / x_delta; + const float new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0]; + const float new_y_delta = new_x_delta * y_delta / x_delta; const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1]; diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 3d3723ee82e..cf8d2ebcb79 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1074,9 +1074,17 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { - if (segment->start_index + segment->length >= fcu->totvert - 1 || - segment->start_index <= 1) { - WM_report(RPT_WARNING, "You need at least 2 keys to eider side of the selection."); + if (factor >= 0.5){ + 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); } -- 2.30.2 From f231c18d95b2b0ac1fd50cce7b57f8138cd8936d Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 17 Apr 2023 21:26:37 -0700 Subject: [PATCH 12/14] deleted lines that were not deeded and added bidirectional slider --- .../editors/animation/keyframes_general.c | 27 +++++-------------- .../editors/space_graph/graph_slider_ops.c | 5 +++- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 146d2ad4df1..6ac9d9df286 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -496,36 +496,28 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); - /* 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 bidirectional_factor = fabs(factor * 2 - 1); - BezTriple beyond_key; const BezTriple *reference_key; - /* This delta values are used to get the relationship between the bookend keys and the - * reference keys beyong those. */ - if (factor >= 0.5) { - + if (factor >= 0) { /* Stop the function if there is no key beyond the the right neighboring one. */ - if (segment->start_index + segment->length > fcu->totvert - 1) { + if (segment->start_index + segment->length >= fcu->totvert - 1) { return; } - reference_key = right_key; beyond_key = fcu->bezt[segment->start_index + segment->length + 1]; } else { - /* Stop the function if there is no key beyond the left neighboring one. */ - if (segment->start_index == 1) { + if (segment->start_index <= 1) { return; } - reference_key = left_key; beyond_key = fcu->bezt[segment->start_index - 2]; } + /* This delta values are used to get the relationship between the bookend keys and the + * reference keys beyong those. */ const float y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1]; const float x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0]; @@ -534,13 +526,6 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const return; } - if (factor >= 0.5) { - reference_key = right_key; - } - else { - reference_key = left_key; - } - for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { /* These new deltas are used to determine the relationship between the current key and the @@ -550,7 +535,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1]; - const float key_y_value = fcu->bezt[i].vec[1][1] + delta * bidirectional_factor; + const float key_y_value = fcu->bezt[i].vec[1][1] + delta * fabs(factor); move_key(&fcu->bezt[i], key_y_value); } } diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index cf8d2ebcb79..422c589ea38 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1074,7 +1074,7 @@ static void blend_to_infinity_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { - if (factor >= 0.5){ + 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; @@ -1146,6 +1146,9 @@ static int blend_to_infinity_invoke(bContext *C, wmOperator *op, const wmEvent * gso->modal_update = blend_to_infinity_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); blend_to_infinity_draw_status_header(C, gso); + ED_slider_allow_overshoot_set(gso->slider, false); + ED_slider_is_bidirectional_set(gso->slider, true); + ED_slider_factor_set(gso->slider, 0.0f); return invoke_result; } -- 2.30.2 From 7b2561452c08dd6e601f3c3d5bc91a66574a48db Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Thu, 20 Apr 2023 12:35:27 -0700 Subject: [PATCH 13/14] blend_to_infinity function returns a boolean now. Took the warning out of the loop in the operator. --- .../editors/animation/keyframes_general.c | 9 +++--- .../editors/include/ED_keyframes_edit.h | 2 +- .../editors/space_graph/graph_slider_ops.c | 29 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 6ac9d9df286..b25d1035151 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,7 +491,7 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ -void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) +bool blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor) { const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index); const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length); @@ -502,7 +502,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const if (factor >= 0) { /* Stop the function if there is no key beyond the the right neighboring one. */ if (segment->start_index + segment->length >= fcu->totvert - 1) { - return; + return false; } reference_key = right_key; beyond_key = fcu->bezt[segment->start_index + segment->length + 1]; @@ -510,7 +510,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const else { /* Stop the function if there is no key beyond the left neighboring one. */ if (segment->start_index <= 1) { - return; + return false; } reference_key = left_key; beyond_key = fcu->bezt[segment->start_index - 2]; @@ -523,7 +523,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const /* Avoids dividing by 0. */ if (x_delta == 0) { - return; + return true; } for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { @@ -538,6 +538,7 @@ void blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const const float key_y_value = fcu->bezt[i].vec[1][1] + delta * fabs(factor); move_key(&fcu->bezt[i], key_y_value); } + return true; } /* ---------------- */ diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index 72788d30064..ffa032d0475 100644 --- a/source/blender/editors/include/ED_keyframes_edit.h +++ b/source/blender/editors/include/ED_keyframes_edit.h @@ -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); diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 422c589ea38..c0014168528 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -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); } 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); } -- 2.30.2 From c2111305f4c892ce01fb75d88eb1e3cc677abe41 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 30 Apr 2023 21:20:04 -0700 Subject: [PATCH 14/14] if x_delta = 0 should return "false" --- source/blender/editors/animation/keyframes_general.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index b25d1035151..e4a296f40f6 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -523,7 +523,7 @@ bool blend_to_infinity_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const /* Avoids dividing by 0. */ if (x_delta == 0) { - return true; + return false; } for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { -- 2.30.2