Animation: Blend To Ease Slider #110566

Merged
Christoph Lendenfeld merged 21 commits from ChrisLend/blender:blend_to_ease_slider into main 2023-08-10 17:51:20 +02:00
6 changed files with 40 additions and 39 deletions
Showing only changes of commit cb45fcb306 - Show all commits

View File

@ -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_ease", text="Blend to Ease")
layout.operator("graph.blend_to_ease", text="Blend to Ease")
layout.operator("graph.ease", text="Ease")
layout.operator("graph.gaussian_smooth", text="Smooth")

View File

@ -506,7 +506,7 @@ float s_curve(float x, float slope, float width, float height, float xshift, flo
return curve;
}
void ease_b_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
void blend_to_ease_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];
@ -515,7 +515,7 @@ void ease_b_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float fact
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
const float key_x_range = right_key->vec[1][0] - left_x;
const float key_y_range = right_key->vec[1][1] - left_y;
const float key_y_range = right_key->vec[1][1] - left_x;
/* Happens if there is only 1 key on the FCurve. Needs to be skipped because it
* would be a divide by 0. */
@ -526,29 +526,30 @@ void ease_b_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float fact
/* The calculation needs diferent values for each side of the slider. */
const bool slider_right_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) * 5;
/* The factor goes from 0 to 1, but for this tool it needs to go from -1 to 1. */
const float long_factor = factor * 2 - 1;
float y_delta = 0;
float base = 0;
/* By duplicating the size of the curve we get only half of the "S" shape (kind of a "C" shape). */
const float width = 2.0;
const float height = 2.0;
float xshift = 0.0;
float yshift = 0.0;
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
/* For easy calculation of the curve, the values are normalized. */
const float normalized_x = (fcu->bezt[i].vec[1][0] - left_key->vec[1][0]) / key_x_range;
/* For values on the right side of the slider we need the other half of the "S" shape. */
if (slider_right_side) {
xshift = -1.0;
yshift = -1.0;
float ease = s_curve(normalized_x, 3, 2.0, 2.0, -1.0, -1.0);
base = left_key->vec[1][1] + key_y_range * ease;
y_delta = base - fcu->bezt[i].vec[1][1];
}
else {
float ease = s_curve(normalized_x, 3, 2.0, 2.0, 0.0, 0.0);
base = left_key->vec[1][1] + key_y_range * ease;
y_delta = fcu->bezt[i].vec[1][1] - base;
}
/* The factor is used to affect the slope of the the "C" shape. */
float ease = s_curve(normalized_x, ping_pong_factor, width, height, xshift, yshift);
const float key_y_value = left_key->vec[1][1] + key_y_range * ease;
const float key_y_value = fcu->bezt[i].vec[1][1] + y_delta * long_factor;
move_key(&fcu->bezt[i], key_y_value);
}
}

View File

@ -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_ease_fcurve_segment(struct FCurve *fcu, struct FCurveSegment *segment, float factor);
void blend_to_ease_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);
/**

View File

@ -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_ease(struct wmOperatorType *ot);
void GRAPH_OT_blend_to_ease(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);

View File

@ -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_ease);
WM_operatortype_append(GRAPH_OT_blend_to_ease);
WM_operatortype_append(GRAPH_OT_blend_to_default);
WM_operatortype_append(GRAPH_OT_gaussian_smooth);
WM_operatortype_append(GRAPH_OT_euler_filter);

View File

@ -1061,10 +1061,10 @@ void GRAPH_OT_ease(wmOperatorType *ot)
}
/* -------------------------------------------------------------------- */
/** \name Blend Ease Operator
/** \name Blend to Ease Operator
* \{ */
static void blend_ease_graph_keys(bAnimContext *ac, const float factor)
static void blend_to_ease_graph_keys(bAnimContext *ac, const float factor)
{
ListBase anim_data = {NULL, NULL};
@ -1074,7 +1074,7 @@ static void blend_ease_graph_keys(bAnimContext *ac, const float factor)
ListBase segments = find_fcurve_segments(fcu);
LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
blend_ease_fcurve_segment(fcu, segment, factor);
blend_to_ease_fcurve_segment(fcu, segment, factor);
}
ale->update |= ANIM_UPDATE_DEFAULT;
@ -1085,7 +1085,7 @@ static void blend_ease_graph_keys(bAnimContext *ac, const float factor)
ANIM_animdata_freelist(&anim_data);
}
static void blend_ease_draw_status_header(bContext *C, tGraphSliderOp *gso)
static void blend_to_ease_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_ease_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 Ease Keys"));
strcpy(mode_str, TIP_("Blend to Ease Keys"));
if (hasNumInput(&gso->num)) {
char str_ofs[NUM_STR_REP_LEN];
@ -1109,20 +1109,20 @@ static void blend_ease_draw_status_header(bContext *C, tGraphSliderOp *gso)
ED_workspace_status_text(C, status_str);
}
static void blend_ease_modal_update(bContext *C, wmOperator *op)
static void blend_to_ease_modal_update(bContext *C, wmOperator *op)
{
tGraphSliderOp *gso = op->customdata;
blend_ease_draw_status_header(C, gso);
blend_to_ease_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_ease_graph_keys(&gso->ac, factor);
blend_to_ease_graph_keys(&gso->ac, factor);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
}
static int blend_ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int blend_to_ease_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_ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
tGraphSliderOp *gso = op->customdata;
gso->modal_update = blend_ease_modal_update;
gso->modal_update = blend_to_ease_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
blend_ease_draw_status_header(C, gso);
blend_to_ease_draw_status_header(C, gso);
return invoke_result;
}
static int blend_ease_exec(bContext *C, wmOperator *op)
static int blend_to_ease_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
@ -1149,7 +1149,7 @@ static int blend_ease_exec(bContext *C, wmOperator *op)
const float factor = RNA_float_get(op->ptr, "factor");
blend_ease_graph_keys(&ac, factor);
blend_to_ease_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_ease_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
void GRAPH_OT_blend_ease(wmOperatorType *ot)
void GRAPH_OT_blend_to_ease(wmOperatorType *ot)
{
/* Identifiers. */
ot->name = "Blend Ease Keyframes";
ot->idname = "GRAPH_OT_blend_ease";
ot->description = "Align keyframes on a ease-in or ease-out curve";
ot->name = "Blend to Ease Keyframes";
ot->idname = "GRAPH_OT_blend_to_ease";
ot->description = "Blends keyframes from current state to an ease-in or ease-out curve";
/* API callbacks. */
ot->invoke = blend_ease_invoke;
ot->invoke = blend_to_ease_invoke;
ot->modal = graph_slider_modal;
ot->exec = blend_ease_exec;
ot->exec = blend_to_ease_exec;
ot->poll = graphop_editable_keyframes_poll;
/* Flags. */