From 52a9e6554846eaaa92ab603e9f180ade4ddb8e6e Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 21:23:32 -0700 Subject: [PATCH 01/10] added functions --- scripts/startup/bl_ui/space_graph.py | 1 + .../editors/animation/keyframes_general.c | 47 +++++++ .../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, 175 insertions(+) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index 999a9e3cef7..f1109693d66 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_offset", text="Blend to Offset") 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..ff52120234d 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -491,6 +491,53 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor /* ---------------- */ +void blend_to_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; + + /* For this tool the calculations are made easier if each side of the slider goes from 0 to porisive 1. */ + const float ping_pong_factor = fabs(factor * 2 - 1); + + float y_delta = 0; + + if (slider_right_side) { + y_delta = right_y - segment_last_key_y; + } + else { + y_delta = left_y - segment_first_key_y; + } + + for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { + const float key_y_value = fcu->bezt[i].vec[1][1] + y_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..dd89d8e7691 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_offset_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..19e880298cd 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_offset(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..a287fa1768e 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_offset); 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..4dbd2c02f85 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 Offset Operator + * \{ */ + +static void blend_to_offset_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_offset_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_offset_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 Offset 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_offset_modal_update(bContext *C, wmOperator *op) +{ + tGraphSliderOp *gso = op->customdata; + + blend_to_offset_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_offset_graph_keys(&gso->ac, factor); + WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); +} + +static int blend_to_offset_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_offset_modal_update; + gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); + blend_to_offset_draw_status_header(C, gso); + + return invoke_result; +} + +static int blend_to_offset_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_offset_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_offset(wmOperatorType *ot) +{ + /* Identifiers. */ + ot->name = "Blend to Offset Keyframes"; + ot->idname = "GRAPH_OT_blend_to_offset"; + ot->description = "Shift selected keys to the value of the neighboring keys as a block"; + + /* API callbacks. */ + ot->invoke = blend_to_offset_invoke; + ot->modal = graph_slider_modal; + ot->exec = blend_to_offset_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 6c90f32d7e2e69c453ca9abcba376f831f0b1dcb Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 22:00:20 -0700 Subject: [PATCH 02/10] took away the "to" in the name --- scripts/startup/bl_ui/space_graph.py | 2 +- .../editors/animation/keyframes_general.c | 2 +- .../editors/include/ED_keyframes_edit.h | 2 +- .../editors/space_graph/graph_intern.h | 2 +- .../blender/editors/space_graph/graph_ops.c | 2 +- .../editors/space_graph/graph_slider_ops.c | 36 +++++++++---------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/startup/bl_ui/space_graph.py b/scripts/startup/bl_ui/space_graph.py index f1109693d66..f61db21dc88 100644 --- a/scripts/startup/bl_ui/space_graph.py +++ b/scripts/startup/bl_ui/space_graph.py @@ -329,7 +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_offset", text="Blend to Offset") + layout.operator("graph.blend_offset", text="Blend Offset") 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 ff52120234d..d6d1bbf9933 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_offset_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]; diff --git a/source/blender/editors/include/ED_keyframes_edit.h b/source/blender/editors/include/ED_keyframes_edit.h index dd89d8e7691..4bcd5b8486d 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_offset_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor); +void blend_offset_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 19e880298cd..6604004a7d4 100644 --- a/source/blender/editors/space_graph/graph_intern.h +++ b/source/blender/editors/space_graph/graph_intern.h @@ -114,7 +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_offset(struct wmOperatorType *ot); +void GRAPH_OT_blend_offset(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 a287fa1768e..954277f2c67 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -463,7 +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_offset); + WM_operatortype_append(GRAPH_OT_blend_offset); 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 4dbd2c02f85..ce4afa960c6 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1061,10 +1061,10 @@ void GRAPH_OT_ease(wmOperatorType *ot) } /* -------------------------------------------------------------------- */ -/** \name Blend to Offset Operator +/** \name Blend Offset Operator * \{ */ -static void blend_to_offset_graph_keys(bAnimContext *ac, const float factor) +static void blend_offset_graph_keys(bAnimContext *ac, const float factor) { ListBase anim_data = {NULL, NULL}; @@ -1074,7 +1074,7 @@ static void blend_to_offset_graph_keys(bAnimContext *ac, const float factor) ListBase segments = find_fcurve_segments(fcu); LISTBASE_FOREACH (FCurveSegment *, segment, &segments) { - blend_to_offset_fcurve_segment(fcu, segment, factor); + blend_offset_fcurve_segment(fcu, segment, factor); } ale->update |= ANIM_UPDATE_DEFAULT; @@ -1085,7 +1085,7 @@ static void blend_to_offset_graph_keys(bAnimContext *ac, const float factor) ANIM_animdata_freelist(&anim_data); } -static void blend_to_offset_draw_status_header(bContext *C, tGraphSliderOp *gso) +static void blend_offset_draw_status_header(bContext *C, tGraphSliderOp *gso) { char status_str[UI_MAX_DRAW_STR]; char mode_str[32]; @@ -1093,7 +1093,7 @@ static void blend_to_offset_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR); - strcpy(mode_str, TIP_("Blend to Offset Keys")); + strcpy(mode_str, TIP_("Blend Offset Keys")); if (hasNumInput(&gso->num)) { char str_ofs[NUM_STR_REP_LEN]; @@ -1109,20 +1109,20 @@ static void blend_to_offset_draw_status_header(bContext *C, tGraphSliderOp *gso) ED_workspace_status_text(C, status_str); } -static void blend_to_offset_modal_update(bContext *C, wmOperator *op) +static void blend_offset_modal_update(bContext *C, wmOperator *op) { tGraphSliderOp *gso = op->customdata; - blend_to_offset_draw_status_header(C, gso); + blend_offset_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_offset_graph_keys(&gso->ac, factor); + blend_offset_graph_keys(&gso->ac, factor); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } -static int blend_to_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event) +static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event) { const int invoke_result = graph_slider_invoke(C, op, event); @@ -1131,14 +1131,14 @@ static int blend_to_offset_invoke(bContext *C, wmOperator *op, const wmEvent *ev } tGraphSliderOp *gso = op->customdata; - gso->modal_update = blend_to_offset_modal_update; + gso->modal_update = blend_offset_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); - blend_to_offset_draw_status_header(C, gso); + blend_offset_draw_status_header(C, gso); return invoke_result; } -static int blend_to_offset_exec(bContext *C, wmOperator *op) +static int blend_offset_exec(bContext *C, wmOperator *op) { bAnimContext ac; @@ -1149,7 +1149,7 @@ static int blend_to_offset_exec(bContext *C, wmOperator *op) const float factor = RNA_float_get(op->ptr, "factor"); - blend_to_offset_graph_keys(&ac, factor); + blend_offset_graph_keys(&ac, factor); /* Set notifier that keyframes have changed. */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); @@ -1157,17 +1157,17 @@ static int blend_to_offset_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void GRAPH_OT_blend_to_offset(wmOperatorType *ot) +void GRAPH_OT_blend_offset(wmOperatorType *ot) { /* Identifiers. */ - ot->name = "Blend to Offset Keyframes"; - ot->idname = "GRAPH_OT_blend_to_offset"; + ot->name = "Blend Offset Keyframes"; + ot->idname = "GRAPH_OT_blend_offset"; ot->description = "Shift selected keys to the value of the neighboring keys as a block"; /* API callbacks. */ - ot->invoke = blend_to_offset_invoke; + ot->invoke = blend_offset_invoke; ot->modal = graph_slider_modal; - ot->exec = blend_to_offset_exec; + ot->exec = blend_offset_exec; ot->poll = graphop_editable_keyframes_poll; /* Flags. */ -- 2.30.2 From cf7810c00acd190dc0d99684b9ea8d0ce25dce26 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Sun, 2 Apr 2023 23:09:08 -0700 Subject: [PATCH 03/10] changed declarations of y_delta --- 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 d6d1bbf9933..f3363bcf648 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -521,7 +521,7 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa /* For this tool the calculations are made easier if each side of the slider goes from 0 to porisive 1. */ const float ping_pong_factor = fabs(factor * 2 - 1); - float y_delta = 0; + float y_delta; if (slider_right_side) { y_delta = right_y - segment_last_key_y; -- 2.30.2 From 6cdaa215578d402e535e27b3866fa7e300d3950c Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 3 Apr 2023 11:00:24 -0700 Subject: [PATCH 04/10] Fixed some formating --- .../editors/animation/keyframes_general.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index f3363bcf648..551216ca0be 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -504,7 +504,8 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa 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 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; @@ -518,17 +519,18 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa /* The calculation needs diferent values for each side of the slider. */ const bool slider_right_side = factor > 0.5; - /* For this tool the calculations are made easier if each side of the slider goes from 0 to porisive 1. */ + /* For this tool the calculations are made easier if each side of the slider goes from 0 to + * porisive 1. */ const float ping_pong_factor = fabs(factor * 2 - 1); - + float y_delta; if (slider_right_side) { - y_delta = right_y - segment_last_key_y; - } - else { - y_delta = left_y - segment_first_key_y; - } + y_delta = right_y - segment_last_key_y; + } + else { + y_delta = left_y - segment_first_key_y; + } for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * ping_pong_factor; -- 2.30.2 From 4fefa0dda6b3c17854435938fcd61f77033c2a50 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 10 Apr 2023 15:44:28 -0700 Subject: [PATCH 05/10] deleted the split on the vectors --- .../editors/animation/keyframes_general.c | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 551216ca0be..1b92d90e620 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -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) { - 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++) { -- 2.30.2 From 960b6c41e206fd87e01262860888ebcc17b7be42 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Fri, 14 Apr 2023 02:18:05 -0700 Subject: [PATCH 06/10] another round of simplification --- .../editors/animation/keyframes_general.c | 20 ++++++++----------- .../editors/space_graph/graph_slider_ops.c | 3 +++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 1b92d90e620..49c4949ecf9 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -496,28 +496,24 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa 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); - const BezTriple *segment_first_key = fcurve_segment_start_get(fcu, segment->start_index + 1); - const BezTriple *segment_last_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 BezTriple segment_first_key = fcu->bezt[segment->start_index]; + const BezTriple segment_last_key = fcu->bezt[segment->start_index + segment->length - 1]; /* For this tool the calculations are made easier if each side of the slider goes from 0 to - * porisive 1. */ - const float ping_pong_factor = fabs(factor * 2 - 1); + * positive 1. */ + const float bidirectional_factor = fabs(factor * 2 - 1); float y_delta; - if (slider_right_side) { - y_delta = right_key->vec[1][1] - segment_last_key->vec[1][1]; + if (factor > 0.5) { + y_delta = right_key->vec[1][1] - segment_last_key.vec[1][1]; } else { - y_delta = left_key->vec[1][1] - segment_first_key->vec[1][1]; + 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++) { - const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * ping_pong_factor; + const float key_y_value = fcu->bezt[i].vec[1][1] + y_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 ce4afa960c6..9b2e6b6c36c 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1135,6 +1135,9 @@ static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); blend_offset_draw_status_header(C, gso); + // ED_slider_is_bidirectional_set(gso->slider, true); + // ED_slider_factor_set(gso->slider, 0.0f); + return invoke_result; } -- 2.30.2 From fab764a6cf2843d1daf1a1be798ec6d6396d0720 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Fri, 14 Apr 2023 02:20:12 -0700 Subject: [PATCH 07/10] deleted 2 likes that I added to test the bidirectional slider --- source/blender/editors/space_graph/graph_slider_ops.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 9b2e6b6c36c..ce4afa960c6 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1135,9 +1135,6 @@ static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); blend_offset_draw_status_header(C, gso); - // ED_slider_is_bidirectional_set(gso->slider, true); - // ED_slider_factor_set(gso->slider, 0.0f); - return invoke_result; } -- 2.30.2 From c038ce005ff4af77e5dd8a9af475dcc6f22aca23 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Mon, 17 Apr 2023 21:04:26 -0700 Subject: [PATCH 08/10] added bidirectional sliders --- source/blender/editors/animation/keyframes_general.c | 9 ++------- source/blender/editors/space_graph/graph_slider_ops.c | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 49c4949ecf9..4f9e76ebf24 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -498,14 +498,9 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa const BezTriple segment_first_key = fcu->bezt[segment->start_index]; const BezTriple segment_last_key = fcu->bezt[segment->start_index + segment->length - 1]; - - /* For this tool the calculations are made easier if each side of the slider goes from 0 to - * positive 1. */ - const float bidirectional_factor = fabs(factor * 2 - 1); - float y_delta; - if (factor > 0.5) { + if (factor > 0) { y_delta = right_key->vec[1][1] - segment_last_key.vec[1][1]; } else { @@ -513,7 +508,7 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa } for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { - const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * bidirectional_factor; + const float key_y_value = fcu->bezt[i].vec[1][1] + y_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 ce4afa960c6..e464a3930d8 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1134,6 +1134,8 @@ static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event gso->modal_update = blend_offset_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); blend_offset_draw_status_header(C, gso); + ED_slider_is_bidirectional_set(gso->slider, true); + ED_slider_factor_set(gso->slider, 0.0f); return invoke_result; } -- 2.30.2 From 45de734e6ba48b7d946f9bc0df21dec6bee65ed6 Mon Sep 17 00:00:00 2001 From: Ares Deveaux Date: Thu, 20 Apr 2023 12:46:52 -0700 Subject: [PATCH 09/10] corrected a small error in the operator --- source/blender/editors/space_graph/graph_slider_ops.c | 4 ++-- 1 file changed, 2 insertions(+), 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 e464a3930d8..2cb532fd904 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1177,12 +1177,12 @@ void GRAPH_OT_blend_offset(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 5c93d1f2cffad40cfd8895a1ed6ccf8fbdfff782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 9 May 2023 15:55:26 +0200 Subject: [PATCH 10/10] Fixes for recent graph slider updates --- source/blender/editors/animation/keyframes_general.c | 2 +- source/blender/editors/space_graph/graph_slider_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c index 539cbfc5092..5279636ba04 100644 --- a/source/blender/editors/animation/keyframes_general.c +++ b/source/blender/editors/animation/keyframes_general.c @@ -497,7 +497,7 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const floa for (int i = segment->start_index; i < segment->start_index + segment->length; i++) { const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * fabs(factor); - move_key(&fcu->bezt[i], key_y_value); + BKE_fcurve_keyframe_move_value_with_handles(&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 272f8f2d42b..999e496cade 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -1041,7 +1041,7 @@ static int blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event gso->modal_update = blend_offset_modal_update; gso->factor_prop = RNA_struct_find_property(op->ptr, "factor"); blend_offset_draw_status_header(C, gso); - ED_slider_is_bidirectional_set(gso->slider, true); + ED_slider_factor_bounds_set(gso->slider, -1, 1); ED_slider_factor_set(gso->slider, 0.0f); return invoke_result; -- 2.30.2