Animation: Blend Offset Slider
Adds an operator to the Graph Editor that moves the selected segment up/down so it aligns with the keys before/after the segment. Co-authored-by: Ares Deveaux <aresdevo@gmail.com> Co-authored-by: Sybren A. Stüvel <sybren@blender.org> Pull Request: https://projects.blender.org/blender/blender/pulls/110544
This commit is contained in:
parent
4f66031714
commit
a0aa5480b1
@ -299,6 +299,7 @@ class GRAPH_MT_key_blending(Menu):
|
|||||||
layout.operator("graph.blend_to_neighbor", text="Blend to Neighbor")
|
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_default", text="Blend to Default Value")
|
||||||
layout.operator("graph.ease", text="Ease")
|
layout.operator("graph.ease", text="Ease")
|
||||||
|
layout.operator("graph.blend_offset", text="Blend Offset")
|
||||||
|
|
||||||
|
|
||||||
class GRAPH_MT_key_smoothing(Menu):
|
class GRAPH_MT_key_smoothing(Menu):
|
||||||
|
@ -679,6 +679,31 @@ 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 BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
|
||||||
|
|
||||||
|
float y_delta;
|
||||||
|
|
||||||
|
if (factor > 0) {
|
||||||
|
const BezTriple segment_last_key = fcu->bezt[segment->start_index + segment->length - 1];
|
||||||
|
y_delta = right_key->vec[1][1] - segment_last_key.vec[1][1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const BezTriple segment_first_key = fcu->bezt[segment->start_index];
|
||||||
|
y_delta = left_key->vec[1][1] - segment_first_key.vec[1][1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const float offset_value = y_delta * fabs(factor);
|
||||||
|
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
|
||||||
|
const float key_y_value = fcu->bezt[i].vec[1][1] + offset_value;
|
||||||
|
BKE_fcurve_keyframe_move_value_with_handles(&fcu->bezt[i], key_y_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------- */
|
||||||
|
|
||||||
void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
||||||
{
|
{
|
||||||
const BezTriple *left_bezt = fcurve_segment_start_get(fcu, segment->start_index);
|
const BezTriple *left_bezt = fcurve_segment_start_get(fcu, segment->start_index);
|
||||||
|
@ -458,6 +458,14 @@ void smooth_fcurve_segment(FCurve *fcu,
|
|||||||
int kernel_size,
|
int kernel_size,
|
||||||
double *kernel);
|
double *kernel);
|
||||||
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
|
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
|
||||||
|
/**
|
||||||
|
* Shift the FCurve segment up/down so that it aligns with the key before/after
|
||||||
|
* the segment.
|
||||||
|
*
|
||||||
|
* \param factor blend factor from -1.0 to 1.0. The sign determines whether the
|
||||||
|
* segment is aligned with the key before or after the segment.
|
||||||
|
*/
|
||||||
|
void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
|
||||||
bool decimate_fcurve(bAnimListElem *ale, float remove_ratio, float error_sq_max);
|
bool decimate_fcurve(bAnimListElem *ale, float remove_ratio, float error_sq_max);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,6 +119,7 @@ void GRAPH_OT_clean(struct wmOperatorType *ot);
|
|||||||
void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot);
|
void GRAPH_OT_blend_to_neighbor(struct wmOperatorType *ot);
|
||||||
void GRAPH_OT_breakdown(struct wmOperatorType *ot);
|
void GRAPH_OT_breakdown(struct wmOperatorType *ot);
|
||||||
void GRAPH_OT_ease(struct wmOperatorType *ot);
|
void GRAPH_OT_ease(struct wmOperatorType *ot);
|
||||||
|
void GRAPH_OT_blend_offset(struct wmOperatorType *ot);
|
||||||
void GRAPH_OT_decimate(struct wmOperatorType *ot);
|
void GRAPH_OT_decimate(struct wmOperatorType *ot);
|
||||||
void GRAPH_OT_blend_to_default(struct wmOperatorType *ot);
|
void GRAPH_OT_blend_to_default(struct wmOperatorType *ot);
|
||||||
void GRAPH_OT_butterworth_smooth(struct wmOperatorType *ot);
|
void GRAPH_OT_butterworth_smooth(struct wmOperatorType *ot);
|
||||||
|
@ -469,6 +469,7 @@ void graphedit_operatortypes()
|
|||||||
WM_operatortype_append(GRAPH_OT_blend_to_neighbor);
|
WM_operatortype_append(GRAPH_OT_blend_to_neighbor);
|
||||||
WM_operatortype_append(GRAPH_OT_breakdown);
|
WM_operatortype_append(GRAPH_OT_breakdown);
|
||||||
WM_operatortype_append(GRAPH_OT_ease);
|
WM_operatortype_append(GRAPH_OT_ease);
|
||||||
|
WM_operatortype_append(GRAPH_OT_blend_offset);
|
||||||
WM_operatortype_append(GRAPH_OT_blend_to_default);
|
WM_operatortype_append(GRAPH_OT_blend_to_default);
|
||||||
WM_operatortype_append(GRAPH_OT_gaussian_smooth);
|
WM_operatortype_append(GRAPH_OT_gaussian_smooth);
|
||||||
WM_operatortype_append(GRAPH_OT_butterworth_smooth);
|
WM_operatortype_append(GRAPH_OT_butterworth_smooth);
|
||||||
|
@ -983,6 +983,97 @@ void GRAPH_OT_ease(wmOperatorType *ot)
|
|||||||
1.0f);
|
1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
/** \name Blend Offset Operator
|
||||||
|
* \{ */
|
||||||
|
|
||||||
|
static void blend_offset_graph_keys(bAnimContext *ac, const float factor)
|
||||||
|
{
|
||||||
|
apply_fcu_segment_function(ac, factor, blend_offset_fcurve_segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void blend_offset_draw_status_header(bContext *C, tGraphSliderOp *gso)
|
||||||
|
{
|
||||||
|
common_draw_status_header(C, gso, "Blend Offset Keys");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void blend_offset_modal_update(bContext *C, wmOperator *op)
|
||||||
|
{
|
||||||
|
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
|
||||||
|
|
||||||
|
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_offset_graph_keys(&gso->ac, factor);
|
||||||
|
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int blend_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 = static_cast<tGraphSliderOp *>(op->customdata);
|
||||||
|
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_factor_bounds_set(gso->slider, -1, 1);
|
||||||
|
ED_slider_factor_set(gso->slider, 0.0f);
|
||||||
|
|
||||||
|
return invoke_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int blend_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_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_offset(wmOperatorType *ot)
|
||||||
|
{
|
||||||
|
/* Identifiers. */
|
||||||
|
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_offset_invoke;
|
||||||
|
ot->modal = graph_slider_modal;
|
||||||
|
ot->exec = blend_offset_exec;
|
||||||
|
ot->poll = graphop_editable_keyframes_poll;
|
||||||
|
|
||||||
|
/* Flags. */
|
||||||
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
|
|
||||||
|
RNA_def_float_factor(ot->srna,
|
||||||
|
"factor",
|
||||||
|
0.0f,
|
||||||
|
-FLT_MAX,
|
||||||
|
FLT_MAX,
|
||||||
|
"Curve Bend",
|
||||||
|
"Control the bend of the curve",
|
||||||
|
-1.0f,
|
||||||
|
1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/** \name Gauss Smooth Operator
|
/** \name Gauss Smooth Operator
|
||||||
|
Loading…
Reference in New Issue
Block a user