Blender V5.3
graph_slider_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14
15#include <cfloat>
16#include <cstring>
17
18#include "MEM_guardedalloc.h"
19
20#include "BLI_listbase.hh"
21#include "BLI_math_base_c.hh"
22
23#include "DEG_depsgraph.hh"
24#include "DNA_anim_types.h"
25#include "DNA_curve_types.h"
26#include "DNA_scene_types.h"
27
28#include "RNA_access.hh"
29#include "RNA_define.hh"
30
31#include "BLT_translation.hh"
32
33#include "BKE_context.hh"
34#include "BKE_report.hh"
35
36#include "UI_interface.hh"
37
38#include "ED_anim_api.hh"
39#include "ED_keyframes_edit.hh"
40#include "ED_numinput.hh"
41#include "ED_screen.hh"
42#include "ED_util.hh"
43
44#include "WM_api.hh"
45#include "WM_types.hh"
46
47#include "ANIM_fcurve.hh"
48
49#include <fmt/format.h>
50
51#include "graph_intern.hh"
52
53namespace blender {
54
55/* -------------------------------------------------------------------- */
58
59/* Used to obtain a list of animation channels for the operators to work on. */
60#define OPERATOR_DATA_FILTER \
61 (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | \
62 ANIMFILTER_FOREDIT | ANIMFILTER_SEL | ANIMFILTER_NODUPLIS)
63
64/* This data type is only used for modal operation. */
70
73
75 ListBaseT<LinkData> bezt_arr_list;
76
78
79 /* Each operator has a specific update function. */
81
82 /* If an operator stores custom data, it also needs to provide the function to clean it up. */
85
87};
88
93
95
96/* -------------------------------------------------------------------- */
99
105 const float factor,
106 void (*segment_function)(FCurve *fcu,
107 FCurveSegment *segment,
108 const float factor))
109{
110 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
111
113 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
114 for (bAnimListElem &ale : anim_data) {
115 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
116 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
117
118 for (FCurveSegment &segment : segments) {
119 segment_function(fcu, &segment, factor);
120 }
121
122 ale.update |= ANIM_UPDATE_DEFAULT;
123 segments.free_no_destruct();
124 }
125
126 ANIM_animdata_update(ac, &anim_data);
127 ANIM_animdata_freelist(&anim_data);
128}
129
131{
132 WorkspaceStatus status(C);
133 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
134 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
135 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
136 if (hasNumInput(&gso->num)) {
137 char str_ofs[NUM_STR_REP_LEN];
138 outputNumInput(&gso->num, str_ofs, gso->scene->unit);
139 status.item(str_ofs, ICON_NONE);
140 }
141 else {
142 ED_slider_status_get(gso->slider, status);
143 }
144}
145
151{
152 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
153 bAnimContext *ac = &gso->ac;
154
156 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
157
158 /* Loop through filtered data and copy the curves. */
159 for (bAnimListElem &ale : anim_data) {
160 const FCurve *fcu = static_cast<const FCurve *>(ale.key_data);
161
162 if (fcu->bezt == nullptr) {
163 /* This curve is baked, skip it. */
164 continue;
165 }
166
169 "bezts_copy_array");
170
171 copy->tot_vert = fcu->totvert;
172 memcpy(bezts_copy, fcu->bezt, sizeof(BezTriple) * fcu->totvert);
173
174 copy->bezt = bezts_copy;
175
176 LinkData *link = nullptr;
177
178 link = MEM_new_zeroed<LinkData>("Bezt Link");
179 link->data = copy;
180
181 BLI_addtail(&gso->bezt_arr_list, link);
182 }
183
184 ANIM_animdata_freelist(&anim_data);
185}
186
187/* Overwrite the current bezts arrays with the original data. */
189{
190 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
191 LinkData *link_bezt;
192 bAnimListElem *ale;
193
194 bAnimContext *ac = &gso->ac;
195
196 /* Filter data. */
198 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
199
200 /* Loop through filtered data and reset bezts. */
201 for (ale = anim_data.first(), link_bezt = gso->bezt_arr_list.first(); ale; ale = ale->next) {
202 FCurve *fcu = static_cast<FCurve *>(ale->key_data);
203
204 if (fcu->bezt == nullptr) {
205 /* This curve is baked, skip it. */
206 continue;
207 }
208
209 tBeztCopyData *data = static_cast<tBeztCopyData *>(link_bezt->data);
210
211 MEM_delete(fcu->bezt);
212
213 fcu->bezt = MEM_new_array_uninitialized<BezTriple>(data->tot_vert, __func__);
214 fcu->totvert = data->tot_vert;
215
216 memcpy(fcu->bezt, data->bezt, sizeof(BezTriple) * data->tot_vert);
217
218 link_bezt = link_bezt->next;
219 }
220
221 ANIM_animdata_freelist(&anim_data);
222}
223
229{
230 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
231 const float factor = ED_slider_factor_get(gso->slider);
232 RNA_property_float_set(op->ptr, gso->factor_prop, factor);
233 return factor;
234}
235
237
238/* -------------------------------------------------------------------- */
241
243{
244 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
245 wmWindow *win = CTX_wm_window(C);
246
247 /* If data exists, clear its data and exit. */
248 if (gso == nullptr) {
249 return;
250 }
251
252 if (gso->free_operator_data != nullptr) {
254 }
255
256 ScrArea *area = gso->area;
257 LinkData *link;
258
260
261 for (link = gso->bezt_arr_list.first(); link != nullptr; link = link->next) {
262 tBeztCopyData *copy = static_cast<tBeztCopyData *>(link->data);
263 MEM_delete(copy->bezt);
264 MEM_delete_void(link->data);
265 }
266
267 gso->bezt_arr_list.free_no_destruct();
268 MEM_delete(gso);
269
270 /* Return to normal cursor and header status. */
272 ED_area_status_text(area, nullptr);
273
274 /* cleanup */
275 op->customdata = nullptr;
276}
277
279{
280 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
281
282 bAnimContext *ac = &gso->ac;
284 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
285 for (bAnimListElem &ale : anim_data) {
286 DEG_id_tag_update(ale.fcurve_owner_id, ID_RECALC_ANIMATION);
287 }
288
289 ANIM_animdata_freelist(&anim_data);
290}
291
293{
294 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
295
296 const bool has_numinput = hasNumInput(&gso->num);
297
299 fmt::format("{} ({})",
300 WM_operatortype_name(op->type, op->ptr),
302 .c_str());
303
304 ED_slider_modal(gso->slider, event);
305
306 switch (event->type) {
307 /* Confirm */
308 case LEFTMOUSE:
309 case EVT_RETKEY:
310 case EVT_PADENTER: {
311 if (event->val == KM_PRESS) {
312 graph_slider_exit(C, op);
313
314 return OPERATOR_FINISHED;
315 }
316 break;
317 }
318
319 /* Cancel */
320 case EVT_ESCKEY:
321 case RIGHTMOUSE: {
322 if (event->val == KM_PRESS) {
323 reset_bezts(gso);
324
325 /* The owner id's of the FCurves need to be updated, else the animation will be stuck in
326 * the state prior to calling reset_bezt. */
327 update_depsgraph(gso);
328
330
331 graph_slider_exit(C, op);
332
333 return OPERATOR_CANCELLED;
334 }
335 break;
336 }
337
338 case EVT_TABKEY:
339 /* Switch between acting on different properties. If this is not handled
340 * by the caller, it's explicitly gobbled up here to avoid it being passed
341 * through via the 'default' case. */
342 break;
343
344 /* When the mouse is moved, the percentage and the keyframes update. */
345 case MOUSEMOVE: {
346 if (has_numinput == false) {
347 /* Do the update as specified by the operator. */
348 gso->modal_update(C, op);
349 }
350 break;
351 }
352 default: {
353 if ((event->val == KM_PRESS) || (ISKEYMODIFIER(event->type) && event->val == KM_RELEASE)) {
354
355 if (handleNumInput(C, &gso->num, event)) {
356 float value;
357 applyNumInput(&gso->num, &value);
358
359 /* Grab percentage from numeric input, and store this new value for redo
360 * NOTE: users see ints, while internally we use a 0-1 float. */
362 value = value / 100.0f;
363 }
364 ED_slider_factor_set(gso->slider, value);
365 RNA_property_float_set(op->ptr, gso->factor_prop, value);
366 }
367
368 gso->modal_update(C, op);
369 break;
370 }
371
372 /* Unhandled event - maybe it was some view manipulation? */
373 /* Allow to pass through. */
375 }
376 }
377
379}
380
381/* Allocate tGraphSliderOp and assign to op->customdata. */
383{
384 tGraphSliderOp *gso;
385
387
388 /* Init slide-op data. */
389 op->customdata = gso = MEM_new_zeroed<tGraphSliderOp>("tGraphSliderOp");
390
391 /* Get editor data. */
392 if (ANIM_animdata_get_context(C, &gso->ac) == 0) {
393 graph_slider_exit(C, op);
394 return OPERATOR_CANCELLED;
395 }
396 gso->ac.reports = op->reports;
397
398 gso->scene = CTX_data_scene(C);
399 gso->area = CTX_wm_area(C);
400 gso->region = CTX_wm_region(C);
401
403
404 gso->slider = ED_slider_create(C);
405 ED_slider_init(gso->slider, event);
406
407 if (gso->bezt_arr_list.first_ == nullptr) {
408 BKE_report(op->reports, RPT_ERROR, "Cannot find keys to operate on");
409 graph_slider_exit(C, op);
410 return OPERATOR_CANCELLED;
411 }
412
415}
416
418
419/* -------------------------------------------------------------------- */
422
427
428static void decimate_graph_keys(bAnimContext *ac, float factor, float error_sq_max)
429{
430 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
431
432 /* Filter data. */
434 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
435
436 /* Loop through filtered data and clean curves. */
437 for (bAnimListElem &ale : anim_data) {
438 if (!decimate_fcurve(&ale, factor, error_sq_max)) {
439 /* The selection contains unsupported keyframe types! */
440 BKE_report(ac->reports, RPT_WARNING, "Decimate: Skipping non linear/Bézier keyframes!");
441 }
442
443 ale.update |= ANIM_UPDATE_DEFAULT;
444 }
445
446 ANIM_animdata_update(ac, &anim_data);
447 ANIM_animdata_freelist(&anim_data);
448}
449
450/* Draw a percentage indicator in workspace footer. */
452{
453 WorkspaceStatus status(C);
454 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
455 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
456 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
457 if (hasNumInput(&gso->num)) {
458 char str_ofs[NUM_STR_REP_LEN];
459 outputNumInput(&gso->num, str_ofs, gso->scene->unit);
460 status.item(str_ofs, ICON_NONE);
461 }
462 else {
463 ED_slider_status_get(gso->slider, status);
464 }
465}
466
468{
469 /* Perform decimate updates - in response to some user action
470 * (e.g. pressing a key or moving the mouse). */
471 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
472
474
475 /* Reset keyframe data (so we get back to the original state). */
476 reset_bezts(gso);
477
478 /* Apply... */
479 const float factor = slider_factor_get_and_remember(op);
480 /* We don't want to limit the decimation to a certain error margin. */
481 const float error_sq_max = FLT_MAX;
482 decimate_graph_keys(&gso->ac, factor, error_sq_max);
484}
485
487{
488 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
489
490 if (invoke_result == OPERATOR_CANCELLED) {
491 return OPERATOR_CANCELLED;
492 }
493
494 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
495 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
497 ED_slider_allow_overshoot_set(gso->slider, false, false);
498
499 return invoke_result;
500}
501
503{
504 bAnimContext ac;
505
506 /* Get editor data. */
507 if (ANIM_animdata_get_context(C, &ac) == 0) {
508 return OPERATOR_CANCELLED;
509 }
510
511 tDecimModes mode = tDecimModes(RNA_enum_get(op->ptr, "mode"));
512 /* We want to be able to work on all available keyframes. */
513 float factor = 1.0f;
514 /* We don't want to limit the decimation to a certain error margin. */
515 float error_sq_max = FLT_MAX;
516
517 switch (mode) {
518 case DECIM_RATIO:
519 factor = RNA_float_get(op->ptr, "factor");
520 break;
521 case DECIM_ERROR:
522 error_sq_max = RNA_float_get(op->ptr, "remove_error_margin");
523 /* The decimate algorithm expects the error to be squared. */
524 error_sq_max *= error_sq_max;
525
526 break;
527 }
528
529 if (factor == 0.0f || error_sq_max == 0.0f) {
530 /* Nothing to remove. */
531 return OPERATOR_FINISHED;
532 }
533
534 decimate_graph_keys(&ac, factor, error_sq_max);
535
536 /* Set notifier that keyframes have changed. */
538
539 return OPERATOR_FINISHED;
540}
541
542static bool decimate_poll_property(const bContext * /*C*/, wmOperator *op, const PropertyRNA *prop)
543{
544 const char *prop_id = RNA_property_identifier(prop);
545 const int mode = RNA_enum_get(op->ptr, "mode");
546
547 if (STREQ(prop_id, "factor") && mode != DECIM_RATIO) {
548 return false;
549 }
550 if (STREQ(prop_id, "remove_error_margin") && mode != DECIM_ERROR) {
551 return false;
552 }
553
554 return true;
555}
556
557static std::string decimate_get_description(bContext * /*C*/,
558 wmOperatorType * /*ot*/,
559 PointerRNA *ptr)
560{
561
562 if (RNA_enum_get(ptr, "mode") == DECIM_ERROR) {
563 return TIP_(
564 "Decimate F-Curves by specifying how much they can deviate from the original curve");
565 }
566
567 /* Use default description. */
568 return "";
569}
570
573 "RATIO",
574 0,
575 "Ratio",
576 "Use a percentage to specify how many keyframes you want to remove"},
578 "ERROR",
579 0,
580 "Error Margin",
581 "Use an error margin to specify how much the curve is allowed to deviate from the original "
582 "path"},
583 {0, nullptr, 0, nullptr, nullptr},
584};
585
587{
588 /* Identifiers */
589 ot->name = "Decimate Keyframes";
590 ot->idname = "GRAPH_OT_decimate";
591 ot->description =
592 "Decimate F-Curves by removing keyframes that influence the curve shape the least";
593
594 /* API callbacks */
599 ot->exec = decimate_exec;
601
602 /* Flags */
604
605 /* Properties */
606 RNA_def_enum(ot->srna,
607 "mode",
610 "Mode",
611 "Which mode to use for decimation");
612
614 "factor",
615 1.0f / 3.0f,
616 0.0f,
617 1.0f,
618 "Factor",
619 "The ratio of keyframes to remove",
620 0.0f,
621 1.0f);
623 "remove_error_margin",
624 0.0f,
625 0.0f,
626 FLT_MAX,
627 "Max Error Margin",
628 "How much the new decimated curve is allowed to deviate from the original",
629 0.0f,
630 10.0f);
631}
632
634
635/* -------------------------------------------------------------------- */
638
639static void blend_to_neighbor_graph_keys(bAnimContext *ac, const float factor)
640{
642}
643
645{
646 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
647
649
650 /* Reset keyframe data to the state at invoke. */
651 reset_bezts(gso);
652
653 const float factor = slider_factor_get_and_remember(op);
654 blend_to_neighbor_graph_keys(&gso->ac, factor);
655
657}
658
660{
661 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
662
663 if (invoke_result == OPERATOR_CANCELLED) {
664 return invoke_result;
665 }
666
667 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
669 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
672 ED_slider_factor_set(gso->slider, 0.0f);
673
674 return invoke_result;
675}
676
678{
679 bAnimContext ac;
680
681 if (ANIM_animdata_get_context(C, &ac) == 0) {
682 return OPERATOR_CANCELLED;
683 }
684
685 const float factor = RNA_float_get(op->ptr, "factor");
686
687 blend_to_neighbor_graph_keys(&ac, factor);
688
689 /* Set notifier that keyframes have changed. */
691
692 return OPERATOR_FINISHED;
693}
694
696{
697 /* Identifiers. */
698 ot->name = "Blend to Neighbor";
699 ot->idname = "GRAPH_OT_blend_to_neighbor";
700 ot->description = "Blend selected keyframes to their left or right neighbor";
701
702 /* API callbacks. */
707
708 /* Flags. */
710
712 "factor",
713 0.0f,
714 -FLT_MAX,
715 FLT_MAX,
716 "Blend",
717 "The blend factor with 0 being the current frame",
718 -1.0f,
719 1.0f);
720}
721
723
724/* -------------------------------------------------------------------- */
727
728static void breakdown_graph_keys(bAnimContext *ac, float factor)
729{
731}
732
734{
735 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
736
738
739 /* Reset keyframe data to the state at invoke. */
740 reset_bezts(gso);
741 const float factor = slider_factor_get_and_remember(op);
742 breakdown_graph_keys(&gso->ac, factor);
744}
745
747{
748 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
749
750 if (invoke_result == OPERATOR_CANCELLED) {
751 return invoke_result;
752 }
753
754 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
756 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
759 ED_slider_factor_set(gso->slider, 0.0f);
760
761 return invoke_result;
762}
763
765{
766 bAnimContext ac;
767
768 if (ANIM_animdata_get_context(C, &ac) == 0) {
769 return OPERATOR_CANCELLED;
770 }
771
772 const float factor = RNA_float_get(op->ptr, "factor");
773
774 breakdown_graph_keys(&ac, factor);
775
776 /* Set notifier that keyframes have changed. */
778
779 return OPERATOR_FINISHED;
780}
781
783{
784 /* Identifiers. */
785 ot->name = "Breakdown";
786 ot->idname = "GRAPH_OT_breakdown";
787 ot->description = "Move selected keyframes to an inbetween position relative to adjacent keys";
788
789 /* API callbacks. */
792 ot->exec = breakdown_exec;
794
795 /* Flags. */
797
799 "factor",
800 0.0f,
801 -FLT_MAX,
802 FLT_MAX,
803 "Factor",
804 "Favor either the left or the right key",
805 -1.0f,
806 1.0f);
807}
808
810
811/* -------------------------------------------------------------------- */
814
815static void blend_to_default_graph_keys(bAnimContext *ac, const float factor)
816{
817 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
819 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
820
821 for (bAnimListElem &ale : anim_data) {
822 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
823
824 /* Check if the curves actually have any points. */
825 if (fcu == nullptr || fcu->bezt == nullptr || fcu->totvert == 0) {
826 continue;
827 }
828
829 PointerRNA id_ptr = RNA_id_pointer_create(ale.id);
830
831 blend_to_default_fcurve(&id_ptr, fcu, factor);
832 ale.update |= ANIM_UPDATE_DEFAULT;
833 }
834
835 ANIM_animdata_update(ac, &anim_data);
836 ANIM_animdata_freelist(&anim_data);
837}
838
840{
841 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
842
844
845 /* Set notifier that keyframes have changed. */
846 reset_bezts(gso);
847 const float factor = ED_slider_factor_get(gso->slider);
848 RNA_property_float_set(op->ptr, gso->factor_prop, factor);
849 blend_to_default_graph_keys(&gso->ac, factor);
851}
852
854{
855 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
856
857 if (invoke_result == OPERATOR_CANCELLED) {
858 return invoke_result;
859 }
860
861 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
863 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
865 ED_slider_factor_set(gso->slider, 0.0f);
866
867 return invoke_result;
868}
869
871{
872 bAnimContext ac;
873
874 if (ANIM_animdata_get_context(C, &ac) == 0) {
875 return OPERATOR_CANCELLED;
876 }
877
878 const float factor = RNA_float_get(op->ptr, "factor");
879
880 blend_to_default_graph_keys(&ac, factor);
881
882 /* Set notifier that keyframes have changed. */
884
885 return OPERATOR_FINISHED;
886}
887
889{
890 /* Identifiers. */
891 ot->name = "Blend to Default Value";
892 ot->idname = "GRAPH_OT_blend_to_default";
893 ot->description = "Blend selected keys to their default value from their current position";
894
895 /* API callbacks. */
900
901 /* Flags. */
903
905 "factor",
906 0.0f,
907 -FLT_MAX,
908 FLT_MAX,
909 "Factor",
910 "How much to blend to the default value",
911 0.0f,
912 1.0f);
913}
914
915
916/* -------------------------------------------------------------------- */
919
920static void ease_graph_keys(bAnimContext *ac, const float factor, const float width)
921{
922 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
923
925 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
926 for (bAnimListElem &ale : anim_data) {
927 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
928 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
929
930 for (FCurveSegment &segment : segments) {
931 ease_fcurve_segment(fcu, &segment, factor, width);
932 }
933
934 ale.update |= ANIM_UPDATE_DEFAULT;
935 segments.free_no_destruct();
936 }
937
938 ANIM_animdata_update(ac, &anim_data);
939 ANIM_animdata_freelist(&anim_data);
940}
941
943{
944 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
945 WorkspaceStatus status(C);
946 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
947 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
948 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
949 if (hasNumInput(&gso->num)) {
950 char str_ofs[NUM_STR_REP_LEN];
951 outputNumInput(&gso->num, str_ofs, gso->scene->unit);
952 status.item(str_ofs, ICON_NONE);
953 }
954 else {
955 ED_slider_status_get(gso->slider, status);
956 /* Operator specific functionality that extends beyond the slider. */
957 if (STREQ(RNA_property_identifier(gso->factor_prop), "factor")) {
958 status.item(IFACE_("Modify Sharpness"), ICON_EVENT_TAB);
959 }
960 else {
961 status.item(IFACE_("Modify Curve Bend"), ICON_EVENT_TAB);
962 }
963 }
964}
965
967{
968 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
969
971
972 /* Reset keyframes to the state at invoke. */
973 reset_bezts(gso);
974 float factor;
975 float width;
976 if (STREQ(RNA_property_identifier(gso->factor_prop), "factor")) {
978 width = RNA_float_get(op->ptr, "sharpness");
979 }
980 else {
981 factor = RNA_float_get(op->ptr, "factor");
983 }
984
985 ease_graph_keys(&gso->ac, factor, width);
987}
988
990{
991 if (event->val != KM_PRESS) {
992 return graph_slider_modal(C, op, event);
993 }
994
995 switch (event->type) {
996 case EVT_TABKEY: {
997 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
998 if (STREQ(RNA_property_identifier(gso->factor_prop), "factor")) {
999 /* Switch to sharpness. */
1000 ED_slider_allow_overshoot_set(gso->slider, false, true);
1001 ED_slider_factor_bounds_set(gso->slider, 0.001f, 10);
1002 ED_slider_factor_set(gso->slider, RNA_float_get(op->ptr, "sharpness"));
1004 ED_slider_unit_set(gso->slider, "");
1005 gso->factor_prop = RNA_struct_find_property(op->ptr, "sharpness");
1006 }
1007 else {
1008 ED_slider_allow_overshoot_set(gso->slider, false, false);
1010 ED_slider_factor_set(gso->slider, 0.0f);
1011 ED_slider_factor_set(gso->slider, RNA_float_get(op->ptr, "factor"));
1013 ED_slider_unit_set(gso->slider, "%");
1014 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1015 }
1016 ease_modal_update(C, op);
1017 break;
1018 }
1019
1020 default:
1021 return graph_slider_modal(C, op, event);
1022 }
1024}
1025
1027{
1028 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1029
1030 if (invoke_result == OPERATOR_CANCELLED) {
1031 return invoke_result;
1032 }
1033
1034 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1036 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1038 ED_slider_allow_overshoot_set(gso->slider, false, false);
1040 ED_slider_factor_set(gso->slider, 0.0f);
1042
1043 return invoke_result;
1044}
1045
1047{
1048 bAnimContext ac;
1049
1050 if (ANIM_animdata_get_context(C, &ac) == 0) {
1051 return OPERATOR_CANCELLED;
1052 }
1053
1054 const float factor = RNA_float_get(op->ptr, "factor");
1055 const float width = RNA_float_get(op->ptr, "sharpness");
1056
1057 ease_graph_keys(&ac, factor, width);
1058
1060
1061 return OPERATOR_FINISHED;
1062}
1063
1065{
1066 /* Identifiers. */
1067 ot->name = "Ease Keyframes";
1068 ot->idname = "GRAPH_OT_ease";
1069 ot->description = "Align keyframes on a ease-in or ease-out curve";
1070
1071 /* API callbacks. */
1072 ot->invoke = ease_invoke;
1073 ot->modal = ease_modal;
1074 ot->exec = ease_exec;
1076
1077 /* Flags. */
1079
1081 "factor",
1082 0.0f,
1083 -FLT_MAX,
1084 FLT_MAX,
1085 "Curve Bend",
1086 "Defines if the keys should be aligned on an ease-in or ease-out curve",
1087 -1.0f,
1088 1.0f);
1089
1090 RNA_def_float(ot->srna,
1091 "sharpness",
1092 2.0f,
1093 0.001f,
1094 FLT_MAX,
1095 "Sharpness",
1096 "Higher values make the change more abrupt",
1097 0.01f,
1098 16.0f);
1099}
1100
1102
1103/* -------------------------------------------------------------------- */
1106
1107static void blend_offset_graph_keys(bAnimContext *ac, const float factor)
1108{
1110}
1111
1116
1118{
1119 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1120
1122
1123 /* Reset keyframes to the state at invoke. */
1124 reset_bezts(gso);
1125 const float factor = slider_factor_get_and_remember(op);
1126 blend_offset_graph_keys(&gso->ac, factor);
1128}
1129
1131{
1132 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1133
1134 if (invoke_result == OPERATOR_CANCELLED) {
1135 return invoke_result;
1136 }
1137
1138 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1140 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1143 ED_slider_factor_set(gso->slider, 0.0f);
1144
1145 return invoke_result;
1146}
1147
1149{
1150 bAnimContext ac;
1151
1152 /* Get editor data. */
1153 if (ANIM_animdata_get_context(C, &ac) == 0) {
1154 return OPERATOR_CANCELLED;
1155 }
1156
1157 const float factor = RNA_float_get(op->ptr, "factor");
1158
1159 blend_offset_graph_keys(&ac, factor);
1160
1161 /* Set notifier that keyframes have changed. */
1163
1164 return OPERATOR_FINISHED;
1165}
1166
1168{
1169 /* Identifiers. */
1170 ot->name = "Blend Offset Keyframes";
1171 ot->idname = "GRAPH_OT_blend_offset";
1172 ot->description = "Shift selected keys to the value of the neighboring keys as a block";
1173
1174 /* API callbacks. */
1177 ot->exec = blend_offset_exec;
1179
1180 /* Flags. */
1182
1184 "factor",
1185 0.0f,
1186 -FLT_MAX,
1187 FLT_MAX,
1188 "Offset Factor",
1189 "Control which key to offset towards and how far",
1190 -1.0f,
1191 1.0f);
1192}
1193
1195
1196/* -------------------------------------------------------------------- */
1199
1200static void blend_to_ease_graph_keys(bAnimContext *ac, const float factor)
1201{
1203}
1204
1209
1211{
1212 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1213
1215
1216 /* Reset keyframes to the state at invoke. */
1217 reset_bezts(gso);
1218 const float factor = slider_factor_get_and_remember(op);
1219 blend_to_ease_graph_keys(&gso->ac, factor);
1221}
1222
1224{
1225 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1226
1227 if (invoke_result == OPERATOR_CANCELLED) {
1228 return invoke_result;
1229 }
1230
1231 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1233 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1235 ED_slider_allow_overshoot_set(gso->slider, false, false);
1237 ED_slider_factor_set(gso->slider, 0.0f);
1238
1239 return invoke_result;
1240}
1241
1243{
1244 bAnimContext ac;
1245
1246 /* Get editor data. */
1247 if (ANIM_animdata_get_context(C, &ac) == 0) {
1248 return OPERATOR_CANCELLED;
1249 }
1250
1251 const float factor = RNA_float_get(op->ptr, "factor");
1252
1253 blend_to_ease_graph_keys(&ac, factor);
1254
1255 /* Set notifier that keyframes have changed. */
1257
1258 return OPERATOR_FINISHED;
1259}
1260
1262{
1263 /* Identifiers. */
1264 ot->name = "Blend to Ease Keyframes";
1265 ot->idname = "GRAPH_OT_blend_to_ease";
1266 ot->description = "Blends keyframes from current state to an ease-in or ease-out curve";
1267
1268 /* API callbacks. */
1273
1274 /* Flags. */
1276
1278 "factor",
1279 0.0f,
1280 -FLT_MAX,
1281 FLT_MAX,
1282 "Blend",
1283 "Favor either original data or ease curve",
1284 -1.0f,
1285 1.0f);
1286}
1287
1289
1290/* -------------------------------------------------------------------- */
1293
1294static void match_slope_graph_keys(bAnimContext *ac, const float factor)
1295{
1296 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1297
1298 bool all_segments_valid = true;
1299
1301 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
1302 for (bAnimListElem &ale : anim_data) {
1303 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1304 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
1305
1306 for (FCurveSegment &segment : segments) {
1307 all_segments_valid = match_slope_fcurve_segment(fcu, &segment, factor);
1308 }
1309
1310 ale.update |= ANIM_UPDATE_DEFAULT;
1311 segments.free_no_destruct();
1312 }
1313
1314 if (!all_segments_valid) {
1315 if (factor >= 0) {
1316 BKE_report(
1317 ac->reports, RPT_WARNING, "You need at least 2 keys to the right side of the selection");
1318 }
1319 else {
1320 BKE_report(
1321 ac->reports, RPT_WARNING, "You need at least 2 keys to the left side of the selection");
1322 }
1323 }
1324
1325 ANIM_animdata_update(ac, &anim_data);
1326 ANIM_animdata_freelist(&anim_data);
1327}
1328
1333
1335{
1336 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1337
1339
1340 /* Reset keyframes to the state at invoke. */
1341 reset_bezts(gso);
1342 const float factor = slider_factor_get_and_remember(op);
1343 match_slope_graph_keys(&gso->ac, factor);
1345}
1346
1348{
1349 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1350
1351 if (invoke_result == OPERATOR_CANCELLED) {
1352 return invoke_result;
1353 }
1354
1355 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1357 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1359 ED_slider_allow_overshoot_set(gso->slider, false, false);
1361 ED_slider_factor_set(gso->slider, 0.0f);
1362
1363 return invoke_result;
1364}
1365
1367{
1368 bAnimContext ac;
1369
1370 /* Get editor data. */
1371 if (ANIM_animdata_get_context(C, &ac) == 0) {
1372 return OPERATOR_CANCELLED;
1373 }
1374 ac.reports = op->reports;
1375
1376 const float factor = RNA_float_get(op->ptr, "factor");
1377
1378 match_slope_graph_keys(&ac, factor);
1379
1380 /* Set notifier that keyframes have changed. */
1382
1383 return OPERATOR_FINISHED;
1384}
1385
1387{
1388 /* Identifiers. */
1389 ot->name = "Match Slope";
1390 ot->idname = "GRAPH_OT_match_slope";
1391 ot->description = "Blend selected keys to the slope of neighboring ones";
1392
1393 /* API callbacks. */
1396 ot->exec = match_slope_exec;
1398
1399 /* Flags. */
1401
1403 "factor",
1404 0.0f,
1405 -FLT_MAX,
1406 FLT_MAX,
1407 "Factor",
1408 "Defines which keys to use as slope and how much to blend towards them",
1409 -1.0f,
1410 1.0f);
1411}
1412
1414
1415/* -------------------------------------------------------------------- */
1418
1419static void time_offset_graph_keys(bAnimContext *ac, const float factor)
1420{
1422}
1423
1428
1430{
1431 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1432
1434
1435 /* Reset keyframes to the state at invoke. */
1436 reset_bezts(gso);
1437 const float factor = slider_factor_get_and_remember(op);
1438 time_offset_graph_keys(&gso->ac, factor);
1440}
1441
1443{
1444 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1445
1446 if (invoke_result == OPERATOR_CANCELLED) {
1447 return invoke_result;
1448 }
1449
1450 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1452 gso->factor_prop = RNA_struct_find_property(op->ptr, "frame_offset");
1454 ED_slider_factor_bounds_set(gso->slider, -10, 10);
1456 ED_slider_factor_set(gso->slider, 0.0f);
1458 ED_slider_unit_set(gso->slider, "Frames");
1459
1460 return invoke_result;
1461}
1462
1464{
1465 bAnimContext ac;
1466
1467 /* Get editor data. */
1468 if (ANIM_animdata_get_context(C, &ac) == 0) {
1469 return OPERATOR_CANCELLED;
1470 }
1471
1472 const float factor = RNA_float_get(op->ptr, "frame_offset");
1473
1474 time_offset_graph_keys(&ac, factor);
1475
1476 /* Set notifier that keyframes have changed. */
1478
1479 return OPERATOR_FINISHED;
1480}
1481
1483{
1484 /* Identifiers. */
1485 ot->name = "Time Offset Keyframes";
1486 ot->idname = "GRAPH_OT_time_offset";
1487 ot->description = "Shifts the value of selected keys in time";
1488
1489 /* API callbacks. */
1492 ot->exec = time_offset_exec;
1494
1495 /* Flags. */
1497
1499 "frame_offset",
1500 0.0f,
1501 -FLT_MAX,
1502 FLT_MAX,
1503 "Frame Offset",
1504 "How far in frames to offset the animation",
1505 -10.0f,
1506 10.0f);
1507}
1508
1510
1511/* -------------------------------------------------------------------- */
1514
1517 "FROM_LEFT",
1518 0,
1519 "From Left",
1520 "Shear the keys using the left key as reference"},
1522 "FROM_RIGHT",
1523 0,
1524 "From Right",
1525 "Shear the keys using the right key as reference"},
1526 {0, nullptr, 0, nullptr, nullptr},
1527};
1528
1529static void shear_graph_keys(bAnimContext *ac, const float factor, tShearDirection direction)
1530{
1531 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1532
1534 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
1535 for (bAnimListElem &ale : anim_data) {
1536 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1537 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
1538
1539 for (FCurveSegment &segment : segments) {
1540 shear_fcurve_segment(fcu, &segment, factor, direction);
1541 }
1542
1543 ale.update |= ANIM_UPDATE_DEFAULT;
1544 segments.free_no_destruct();
1545 }
1546
1547 ANIM_animdata_update(ac, &anim_data);
1548 ANIM_animdata_freelist(&anim_data);
1549}
1550
1552{
1553 WorkspaceStatus status(C);
1554 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
1555 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
1556 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
1557 if (hasNumInput(&gso->num)) {
1558 char str_ofs[NUM_STR_REP_LEN];
1559 outputNumInput(&gso->num, str_ofs, gso->scene->unit);
1560 status.item(str_ofs, ICON_NONE);
1561 }
1562 else {
1563 ED_slider_status_get(gso->slider, status);
1564 status.item(
1565 fmt::format("{} ({})",
1566 IFACE_("Direction"),
1567 direction == SHEAR_FROM_LEFT ? IFACE_("From Left") : IFACE_("From Right")),
1568 ICON_EVENT_D);
1569 }
1570}
1571
1573{
1574 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1575
1576 /* Reset keyframes to the state at invoke. */
1577 reset_bezts(gso);
1578 const float factor = slider_factor_get_and_remember(op);
1579 const tShearDirection direction = tShearDirection(RNA_enum_get(op->ptr, "direction"));
1580
1581 shear_draw_status_header(C, gso, direction);
1582
1583 shear_graph_keys(&gso->ac, factor, direction);
1585}
1586
1588{
1589 if (event->val != KM_PRESS) {
1590 return graph_slider_modal(C, op, event);
1591 }
1592
1593 switch (event->type) {
1594 case EVT_DKEY: {
1595 tShearDirection direction = tShearDirection(RNA_enum_get(op->ptr, "direction"));
1596 RNA_enum_set(op->ptr,
1597 "direction",
1599 shear_modal_update(C, op);
1600 break;
1601 }
1602
1603 default:
1604 return graph_slider_modal(C, op, event);
1605 break;
1606 }
1608}
1609
1611{
1612 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1613
1614 if (invoke_result == OPERATOR_CANCELLED) {
1615 return invoke_result;
1616 }
1617
1618 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1620 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1621 const tShearDirection direction = tShearDirection(RNA_enum_get(op->ptr, "direction"));
1622
1623 shear_draw_status_header(C, gso, direction);
1625 ED_slider_factor_set(gso->slider, 0.0f);
1626
1627 return invoke_result;
1628}
1629
1631{
1632 bAnimContext ac;
1633
1634 /* Get editor data. */
1635 if (ANIM_animdata_get_context(C, &ac) == 0) {
1636 return OPERATOR_CANCELLED;
1637 }
1638
1639 const float factor = RNA_float_get(op->ptr, "factor");
1640 const tShearDirection direction = tShearDirection(RNA_enum_get(op->ptr, "direction"));
1641
1642 shear_graph_keys(&ac, factor, direction);
1643
1644 /* Set notifier that keyframes have changed. */
1646
1647 return OPERATOR_FINISHED;
1648}
1649
1651{
1652 /* Identifiers. */
1653 ot->name = "Shear Keyframes";
1654 ot->idname = "GRAPH_OT_shear";
1655 ot->description =
1656 "Affect the value of the keys linearly, keeping the same relationship between them using "
1657 "either the left or the right key as reference";
1658
1659 /* API callbacks. */
1660 ot->invoke = shear_invoke;
1661 ot->modal = shear_modal;
1662 ot->exec = shear_exec;
1664
1665 /* Flags. */
1667
1669 "factor",
1670 0.0f,
1671 -FLT_MAX,
1672 FLT_MAX,
1673 "Shear Factor",
1674 "The amount of shear to apply",
1675 -1.0f,
1676 1.0f);
1677
1678 RNA_def_enum(ot->srna,
1679 "direction",
1682 "Direction",
1683 "Which end of the segment to use as a reference to shear from");
1684}
1685
1687
1688/* -------------------------------------------------------------------- */
1691
1692static void scale_average_graph_keys(bAnimContext *ac, const float factor)
1693{
1695}
1696
1698{
1699 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1700
1702
1703 /* Reset keyframes to the state at invoke. */
1704 reset_bezts(gso);
1705 const float factor = slider_factor_get_and_remember(op);
1706 scale_average_graph_keys(&gso->ac, factor);
1708}
1709
1711{
1712 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1713
1714 if (invoke_result == OPERATOR_CANCELLED) {
1715 return invoke_result;
1716 }
1717
1718 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1720 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1723 ED_slider_factor_set(gso->slider, 1.0f);
1724
1725 return invoke_result;
1726}
1727
1729{
1730 bAnimContext ac;
1731
1732 /* Get editor data. */
1733 if (ANIM_animdata_get_context(C, &ac) == 0) {
1734 return OPERATOR_CANCELLED;
1735 }
1736
1737 const float factor = RNA_float_get(op->ptr, "factor");
1738
1739 scale_average_graph_keys(&ac, factor);
1740
1741 /* Set notifier that keyframes have changed. */
1743
1744 return OPERATOR_FINISHED;
1745}
1746
1748{
1749 /* Identifiers. */
1750 ot->name = "Scale Average Keyframes";
1751 ot->idname = "GRAPH_OT_scale_average";
1752 ot->description = "Scale selected key values by their combined average";
1753
1754 /* API callbacks. */
1759
1760 /* Flags. */
1762
1764 "factor",
1765 1.0f,
1766 -FLT_MAX,
1767 FLT_MAX,
1768 "Scale Factor",
1769 "The scale factor applied to the curve segments",
1770 0.0f,
1771 2.0f);
1772}
1773
1775
1776/* -------------------------------------------------------------------- */
1779
1780/* Store data to smooth an FCurve segment. */
1785 /* Array of y-values. The length of the array equals the length of the
1786 * segment. */
1788 /* Array of y-values of the FCurve segment at regular intervals. */
1789 float *samples;
1791};
1792
1793/* It is necessary to store data for smoothing when running in modal, because the sampling of
1794 * FCurves shouldn't be done on every update. */
1796 double *kernel;
1797 ListBaseT<tFCurveSegmentLink> segment_links;
1798 ListBaseT<bAnimListElem> anim_data;
1799};
1800
1801/* Allocates data that has to be freed after. */
1802static float *back_up_key_y_values(const FCurveSegment *segment, const FCurve *fcu)
1803{
1804 float *original_y_values = MEM_new_array_zeroed<float>(segment->length,
1805 "Smooth FCurve original values");
1806 for (int i = 0; i < segment->length; i++) {
1807 original_y_values[i] = fcu->bezt[i + segment->start_index].vec[1][1];
1808 }
1809 return original_y_values;
1810}
1811
1813 const int filter_width,
1814 const float sigma)
1815{
1816 tGaussOperatorData *operator_data = MEM_new_zeroed<tGaussOperatorData>("tGaussOperatorData");
1817 const int kernel_size = filter_width + 1;
1818 double *kernel = MEM_new_array_zeroed<double>(kernel_size, "Gauss Kernel");
1819 ED_ANIM_get_1d_gauss_kernel(sigma, kernel_size, kernel);
1820 operator_data->kernel = kernel;
1821
1822 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1824 &gso->ac, &anim_data, OPERATOR_DATA_FILTER, gso->ac.data, eAnimCont_Types(gso->ac.datatype));
1825
1826 ListBaseT<tFCurveSegmentLink> segment_links = {nullptr, nullptr};
1827 for (bAnimListElem &ale : anim_data) {
1828 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1829 ListBaseT<FCurveSegment> fcu_segments = find_fcurve_segments(fcu);
1830 for (FCurveSegment &segment : fcu_segments) {
1831 tFCurveSegmentLink *segment_link = MEM_new_zeroed<tFCurveSegmentLink>("FCurve Segment Link");
1832 segment_link->fcu = fcu;
1833 segment_link->segment = &segment;
1834 segment_link->original_y_values = back_up_key_y_values(&segment, fcu);
1835 BezTriple left_bezt = fcu->bezt[segment.start_index];
1836 BezTriple right_bezt = fcu->bezt[segment.start_index + segment.length - 1];
1837 const int sample_count = int(right_bezt.vec[1][0] - left_bezt.vec[1][0]) +
1838 (filter_width * 2 + 1);
1839 float *samples = MEM_new_array_zeroed<float>(sample_count, "Smooth FCurve Op Samples");
1841 fcu, left_bezt.vec[1][0] - filter_width, 1, samples, sample_count);
1842 segment_link->samples = samples;
1843 segment_link->sample_count = sample_count;
1844 BLI_addtail(&segment_links, segment_link);
1845 }
1846 }
1847
1848 operator_data->anim_data = anim_data;
1849 operator_data->segment_links = segment_links;
1850 gso->operator_data = operator_data;
1851}
1852
1853static void gaussian_smooth_free_operator_data(void *operator_data)
1854{
1855 tGaussOperatorData *gauss_data = static_cast<tGaussOperatorData *>(operator_data);
1856 for (tFCurveSegmentLink &segment_link : gauss_data->segment_links) {
1857 MEM_delete(segment_link.samples);
1858 MEM_delete(segment_link.segment);
1859 MEM_delete(segment_link.original_y_values);
1860 }
1861 MEM_delete(gauss_data->kernel);
1862 gauss_data->segment_links.free_no_destruct();
1863 ANIM_animdata_freelist(&gauss_data->anim_data);
1864 MEM_delete(gauss_data);
1865}
1866
1868{
1869 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1870
1871 bAnimContext ac;
1872
1873 if (ANIM_animdata_get_context(C, &ac) == 0) {
1874 return;
1875 }
1876
1878
1879 const float factor = slider_factor_get_and_remember(op);
1880 tGaussOperatorData *operator_data = static_cast<tGaussOperatorData *>(gso->operator_data);
1881 const int filter_width = RNA_int_get(op->ptr, "filter_width");
1882
1883 for (tFCurveSegmentLink &segment : operator_data->segment_links) {
1884 smooth_fcurve_segment(segment.fcu,
1885 segment.segment,
1886 segment.original_y_values,
1887 segment.samples,
1888 segment.sample_count,
1889 factor,
1890 filter_width,
1891 operator_data->kernel);
1892 }
1893
1894 for (bAnimListElem &ale : operator_data->anim_data) {
1896 }
1897
1898 ANIM_animdata_update(&ac, &operator_data->anim_data);
1900}
1901
1903{
1904 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
1905
1906 if (invoke_result == OPERATOR_CANCELLED) {
1907 return invoke_result;
1908 }
1909
1910 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
1912 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
1913
1914 const float sigma = RNA_float_get(op->ptr, "sigma");
1915 const int filter_width = RNA_int_get(op->ptr, "filter_width");
1916
1917 gaussian_smooth_allocate_operator_data(gso, filter_width, sigma);
1919
1920 ED_slider_allow_overshoot_set(gso->slider, false, false);
1921 ED_slider_factor_set(gso->slider, 0.0f);
1923
1924 return invoke_result;
1925}
1926
1928 const float factor,
1929 double *kernel,
1930 const int filter_width)
1931{
1932 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1934 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
1935
1936 for (bAnimListElem &ale : anim_data) {
1937 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1938 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
1939
1940 for (FCurveSegment &segment : segments) {
1941 BezTriple left_bezt = fcu->bezt[segment.start_index];
1942 BezTriple right_bezt = fcu->bezt[segment.start_index + segment.length - 1];
1943 const int sample_count = int(right_bezt.vec[1][0] - left_bezt.vec[1][0]) +
1944 (filter_width * 2 + 1);
1945 float *samples = MEM_new_array_zeroed<float>(sample_count, "Smooth FCurve Op Samples");
1946 float *original_y_values = back_up_key_y_values(&segment, fcu);
1948 fcu, left_bezt.vec[1][0] - filter_width, 1, samples, sample_count);
1950 fcu, &segment, original_y_values, samples, sample_count, factor, filter_width, kernel);
1951 MEM_delete(samples);
1952 MEM_delete(original_y_values);
1953 }
1954
1955 segments.free_no_destruct();
1956 ale.update |= ANIM_UPDATE_DEFAULT;
1957 }
1958
1959 ANIM_animdata_update(ac, &anim_data);
1960 ANIM_animdata_freelist(&anim_data);
1961}
1962
1964{
1965 bAnimContext ac;
1966
1967 if (ANIM_animdata_get_context(C, &ac) == 0) {
1968 return OPERATOR_CANCELLED;
1969 }
1970 const float factor = RNA_float_get(op->ptr, "factor");
1971 const int filter_width = RNA_int_get(op->ptr, "filter_width");
1972 const int kernel_size = filter_width + 1;
1973 double *kernel = MEM_new_array_zeroed<double>(kernel_size, "Gauss Kernel");
1974 ED_ANIM_get_1d_gauss_kernel(RNA_float_get(op->ptr, "sigma"), kernel_size, kernel);
1975
1976 gaussian_smooth_graph_keys(&ac, factor, kernel, filter_width);
1977
1978 MEM_delete(kernel);
1979
1980 /* Set notifier that keyframes have changed. */
1982
1983 return OPERATOR_FINISHED;
1984}
1985
1987{
1988 /* Identifiers. */
1989 ot->name = "Gaussian Smooth";
1990 ot->idname = "GRAPH_OT_gaussian_smooth";
1991 ot->description = "Smooth the curve using a Gaussian filter";
1992
1993 /* API callbacks. */
1998
1999 /* Flags. */
2001
2003 "factor",
2004 1.0f,
2005 0.0f,
2006 FLT_MAX,
2007 "Factor",
2008 "How much to blend to the default value",
2009 0.0f,
2010 1.0f);
2011
2012 RNA_def_float(ot->srna,
2013 "sigma",
2014 0.33f,
2015 0.001f,
2016 FLT_MAX,
2017 "Sigma",
2018 "The shape of the gaussian distribution, lower values make it sharper",
2019 0.001f,
2020 100.0f);
2021
2022 RNA_def_int(ot->srna,
2023 "filter_width",
2024 6,
2025 1,
2026 64,
2027 "Filter Width",
2028 "How far to each side the operator will average the key values",
2029 1,
2030 32);
2031}
2032
2033
2034/* -------------------------------------------------------------------- */
2037
2040 ListBaseT<tFCurveSegmentLink> segment_links;
2041 ListBaseT<bAnimListElem> anim_data;
2042};
2043
2044static int btw_calculate_sample_count(const BezTriple *right_bezt,
2045 const BezTriple *left_bezt,
2046 const int filter_order,
2047 const int samples_per_frame)
2048{
2049 /* Adding a constant 60 frames to combat the issue that the phase delay is shifting data out of
2050 * the sample count range. This becomes an issue when running the filter backwards. */
2051 const int sample_count = (int(right_bezt->vec[1][0] - left_bezt->vec[1][0]) + 1 +
2052 (filter_order * 2)) *
2053 samples_per_frame +
2054 60;
2055 return sample_count;
2056}
2057
2059 const int filter_order,
2060 const int samples_per_frame)
2061{
2062 tBtwOperatorData *operator_data = MEM_new_zeroed<tBtwOperatorData>("tBtwOperatorData");
2063
2064 operator_data->coefficients = ED_anim_allocate_butterworth_coefficients(filter_order);
2065
2066 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2068 &gso->ac, &anim_data, OPERATOR_DATA_FILTER, gso->ac.data, eAnimCont_Types(gso->ac.datatype));
2069
2070 ListBaseT<tFCurveSegmentLink> segment_links = {nullptr, nullptr};
2071 for (bAnimListElem &ale : anim_data) {
2072 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
2073 ListBaseT<FCurveSegment> fcu_segments = find_fcurve_segments(fcu);
2074
2075 for (FCurveSegment &segment : fcu_segments) {
2076
2077 tFCurveSegmentLink *segment_link = MEM_new_zeroed<tFCurveSegmentLink>("FCurve Segment Link");
2078 segment_link->fcu = fcu;
2079 segment_link->segment = &segment;
2080 BezTriple left_bezt = fcu->bezt[segment.start_index];
2081 BezTriple right_bezt = fcu->bezt[segment.start_index + segment.length - 1];
2082 const int sample_count = btw_calculate_sample_count(
2083 &right_bezt, &left_bezt, filter_order, samples_per_frame);
2084 float *samples = MEM_new_array_zeroed<float>(sample_count, "Btw Smooth FCurve Op Samples");
2086 fcu, left_bezt.vec[1][0] - filter_order, samples_per_frame, samples, sample_count);
2087 segment_link->samples = samples;
2088 segment_link->sample_count = sample_count;
2089 BLI_addtail(&segment_links, segment_link);
2090 }
2091 }
2092
2093 operator_data->anim_data = anim_data;
2094 operator_data->segment_links = segment_links;
2095 gso->operator_data = operator_data;
2096}
2097
2098static void btw_smooth_free_operator_data(void *operator_data)
2099{
2100 tBtwOperatorData *btw_data = static_cast<tBtwOperatorData *>(operator_data);
2101 for (tFCurveSegmentLink &segment_link : btw_data->segment_links) {
2102 MEM_delete(segment_link.samples);
2103 MEM_delete(segment_link.segment);
2104 }
2106 btw_data->segment_links.free_no_destruct();
2108 MEM_delete(btw_data);
2109}
2110
2112{
2113 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2114
2115 bAnimContext ac;
2116
2117 if (ANIM_animdata_get_context(C, &ac) == 0) {
2118 return;
2119 }
2120
2122
2123 tBtwOperatorData *operator_data = static_cast<tBtwOperatorData *>(gso->operator_data);
2124
2125 const float frame_rate = float(ac.scene->r.frs_sec) / ac.scene->r.frs_sec_base;
2126 const int samples_per_frame = RNA_int_get(op->ptr, "samples_per_frame");
2127 const float sampling_frequency = frame_rate * samples_per_frame;
2128
2129 const float cutoff_frequency = slider_factor_get_and_remember(op);
2130 const int blend_in_out = RNA_int_get(op->ptr, "blend_in_out");
2131
2133 cutoff_frequency, sampling_frequency, operator_data->coefficients);
2134
2135 for (tFCurveSegmentLink &segment : operator_data->segment_links) {
2137 segment.segment,
2138 segment.samples,
2139 segment.sample_count,
2140 1,
2141 blend_in_out,
2142 samples_per_frame,
2143 operator_data->coefficients);
2144 }
2145
2146 for (bAnimListElem &ale : operator_data->anim_data) {
2148 }
2149
2150 ANIM_animdata_update(&ac, &operator_data->anim_data);
2152}
2153
2155{
2156 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
2157
2158 if (invoke_result == OPERATOR_CANCELLED) {
2159 return invoke_result;
2160 }
2161
2162 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2164 gso->factor_prop = RNA_struct_find_property(op->ptr, "cutoff_frequency");
2165
2166 const int filter_order = RNA_int_get(op->ptr, "filter_order");
2167 const int samples_per_frame = RNA_int_get(op->ptr, "samples_per_frame");
2168
2169 btw_smooth_allocate_operator_data(gso, filter_order, samples_per_frame);
2171
2172 const float frame_rate = float(gso->scene->r.frs_sec) / gso->scene->r.frs_sec_base;
2173 const float sampling_frequency = frame_rate * samples_per_frame;
2174 ED_slider_factor_bounds_set(gso->slider, 0, sampling_frequency / 2);
2175 ED_slider_increment_step_set(gso->slider, sampling_frequency / 20);
2176 ED_slider_factor_set(gso->slider, RNA_float_get(op->ptr, "cutoff_frequency"));
2177 ED_slider_allow_overshoot_set(gso->slider, false, false);
2179 ED_slider_unit_set(gso->slider, "Hz");
2181
2182 return invoke_result;
2183}
2184
2186 const float factor,
2187 const int blend_in_out,
2188 float cutoff_frequency,
2189 const int filter_order,
2190 const int samples_per_frame)
2191{
2192 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2194 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
2195
2197
2198 const float frame_rate = float(ac->scene->r.frs_sec) / ac->scene->r.frs_sec_base;
2199 const float sampling_frequency = frame_rate * samples_per_frame;
2200 /* Clamp cutoff frequency to Nyquist Frequency. */
2201 cutoff_frequency = min_ff(cutoff_frequency, sampling_frequency / 2);
2202 ED_anim_calculate_butterworth_coefficients(cutoff_frequency, sampling_frequency, bw_coeff);
2203
2204 for (bAnimListElem &ale : anim_data) {
2205 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
2206 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
2207
2208 for (FCurveSegment &segment : segments) {
2209 BezTriple left_bezt = fcu->bezt[segment.start_index];
2210 BezTriple right_bezt = fcu->bezt[segment.start_index + segment.length - 1];
2211 const int sample_count = btw_calculate_sample_count(
2212 &right_bezt, &left_bezt, filter_order, samples_per_frame);
2213 float *samples = MEM_new_array_zeroed<float>(sample_count, "Smooth FCurve Op Samples");
2215 fcu, left_bezt.vec[1][0] - filter_order, samples_per_frame, samples, sample_count);
2217 fcu, &segment, samples, sample_count, factor, blend_in_out, samples_per_frame, bw_coeff);
2218 MEM_delete(samples);
2219 }
2220
2221 segments.free_no_destruct();
2222 ale.update |= ANIM_UPDATE_DEFAULT;
2223 }
2224
2226 ANIM_animdata_update(ac, &anim_data);
2227 ANIM_animdata_freelist(&anim_data);
2228}
2229
2231{
2232 bAnimContext ac;
2233
2234 if (ANIM_animdata_get_context(C, &ac) == 0) {
2235 return OPERATOR_CANCELLED;
2236 }
2237 const float blend = RNA_float_get(op->ptr, "blend");
2238 const float cutoff_frequency = RNA_float_get(op->ptr, "cutoff_frequency");
2239 const int filter_order = RNA_int_get(op->ptr, "filter_order");
2240 const int samples_per_frame = RNA_int_get(op->ptr, "samples_per_frame");
2241 const int blend_in_out = RNA_int_get(op->ptr, "blend_in_out");
2243 &ac, blend, blend_in_out, cutoff_frequency, filter_order, samples_per_frame);
2244
2245 /* Set notifier that keyframes have changed. */
2247
2248 return OPERATOR_FINISHED;
2249}
2250
2252{
2253 /* Identifiers. */
2254 ot->name = "Butterworth Smooth";
2255 ot->idname = "GRAPH_OT_butterworth_smooth";
2256 ot->description = "Smooth an F-Curve while maintaining the general shape of the curve";
2257
2258 /* API callbacks. */
2261 ot->exec = btw_smooth_exec;
2263
2264 /* Flags. */
2266
2267 RNA_def_float(ot->srna,
2268 "cutoff_frequency",
2269 3.0f,
2270 0.0f,
2271 FLT_MAX,
2272 "Frequency Cutoff (Hz)",
2273 "Lower values give a smoother curve",
2274 0.0f,
2275 FLT_MAX);
2276
2277 RNA_def_int(ot->srna,
2278 "filter_order",
2279 4,
2280 1,
2281 32,
2282 "Filter Order",
2283 "Higher values produce a harder frequency cutoff",
2284 1,
2285 16);
2286
2287 RNA_def_int(ot->srna,
2288 "samples_per_frame",
2289 1,
2290 1,
2291 64,
2292 "Samples per Frame",
2293 "How many samples to calculate per frame, helps with subframe data",
2294 1,
2295 16);
2296
2298 "blend",
2299 1.0f,
2300 0,
2301 FLT_MAX,
2302 "Blend",
2303 "How much to blend to the smoothed curve",
2304 0.0f,
2305 1.0f);
2306
2307 RNA_def_int(ot->srna,
2308 "blend_in_out",
2309 1,
2310 0,
2311 INT_MAX,
2312 "Blend In/Out",
2313 "Linearly blend the smooth data to the border frames of the selection",
2314 0,
2315 128);
2316}
2317
2318
2319/* -------------------------------------------------------------------- */
2322
2323static void push_pull_graph_keys(bAnimContext *ac, const float factor)
2324{
2326}
2327
2329{
2330 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2331
2333
2334 /* Reset keyframes to the state at invoke. */
2335 reset_bezts(gso);
2336 const float factor = slider_factor_get_and_remember(op);
2337 push_pull_graph_keys(&gso->ac, factor);
2339}
2340
2342{
2343 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
2344
2345 if (invoke_result == OPERATOR_CANCELLED) {
2346 return invoke_result;
2347 }
2348
2349 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2351 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
2355
2356 return invoke_result;
2357}
2358
2360{
2361 bAnimContext ac;
2362
2363 /* Get editor data. */
2364 if (ANIM_animdata_get_context(C, &ac) == 0) {
2365 return OPERATOR_CANCELLED;
2366 }
2367
2368 const float factor = RNA_float_get(op->ptr, "factor");
2369
2370 push_pull_graph_keys(&ac, factor);
2371
2372 /* Set notifier that keyframes have changed. */
2374
2375 return OPERATOR_FINISHED;
2376}
2377
2379{
2380 /* Identifiers. */
2381 ot->name = "Push Pull Keyframes";
2382 ot->idname = "GRAPH_OT_push_pull";
2383 ot->description = "Exaggerate or minimize the value of the selected keys";
2384
2385 /* API callbacks. */
2388 ot->exec = push_pull_exec;
2390
2391 /* Flags. */
2393
2395 "factor",
2396 1.0f,
2397 -FLT_MAX,
2398 FLT_MAX,
2399 "Factor",
2400 "Control how far to push or pull the keys",
2401 0.0f,
2402 2.0f);
2403}
2404
2405
2406/* -------------------------------------------------------------------- */
2409
2411 {int(FCurveSegmentAnchor::LEFT), "LEFT", 0, "From Left", ""},
2412 {int(FCurveSegmentAnchor::RIGHT), "RIGHT", 0, "From Right", ""},
2413 {0, nullptr, 0, nullptr, nullptr},
2414};
2415
2417 const float factor,
2418 const FCurveSegmentAnchor anchor)
2419{
2420 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2421
2423 ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
2424 for (bAnimListElem &ale : anim_data) {
2425 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
2426 ListBaseT<FCurveSegment> segments = find_fcurve_segments(fcu);
2427
2428 for (FCurveSegment &segment : segments) {
2429 scale_from_fcurve_segment_neighbor(fcu, &segment, factor, anchor);
2430 }
2431
2432 ale.update |= ANIM_UPDATE_DEFAULT;
2433 segments.free_no_destruct();
2434 }
2435
2436 ANIM_animdata_update(ac, &anim_data);
2437 ANIM_animdata_freelist(&anim_data);
2438}
2439
2441{
2442 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2443 WorkspaceStatus status(C);
2444 status.item(IFACE_("Confirm"), ICON_MOUSE_LMB);
2445 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
2446 status.item(IFACE_("Adjust"), ICON_MOUSE_MOVE);
2447
2448 if (hasNumInput(&gso->num)) {
2449 char str_ofs[NUM_STR_REP_LEN];
2450 outputNumInput(&gso->num, str_ofs, gso->scene->unit);
2451 status.item(str_ofs, ICON_NONE);
2452 }
2453 else {
2454 ED_slider_status_get(gso->slider, status);
2455 /* Operator specific functionality that extends beyond the slider. */
2456 const FCurveSegmentAnchor anchor = FCurveSegmentAnchor(RNA_enum_get(op->ptr, "anchor"));
2457 ED_slider_status_get(gso->slider, status);
2458 status.item(fmt::format("{} ({})",
2459 IFACE_("Direction"),
2460 anchor == FCurveSegmentAnchor::LEFT ? IFACE_("From Left") :
2461 IFACE_("From Right")),
2462 ICON_EVENT_D);
2463 }
2464}
2465
2467{
2468 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2469
2471
2472 /* Reset keyframes to the state at invoke. */
2473 reset_bezts(gso);
2474 const float factor = slider_factor_get_and_remember(op);
2475 const FCurveSegmentAnchor anchor = FCurveSegmentAnchor(RNA_enum_get(op->ptr, "anchor"));
2476 scale_from_neighbor_graph_keys(&gso->ac, factor, anchor);
2478}
2479
2481 wmOperator *op,
2482 const wmEvent *event)
2483{
2484 if (event->val != KM_PRESS) {
2485 return graph_slider_modal(C, op, event);
2486 }
2487
2488 switch (event->type) {
2489 case EVT_DKEY: {
2491 switch (anchor) {
2493 RNA_enum_set(op->ptr, "anchor", int(FCurveSegmentAnchor::RIGHT));
2494 break;
2495
2497 RNA_enum_set(op->ptr, "anchor", int(FCurveSegmentAnchor::LEFT));
2498 break;
2499 }
2501 break;
2502 }
2503
2504 default:
2505 return graph_slider_modal(C, op, event);
2506 }
2508}
2509
2511 wmOperator *op,
2512 const wmEvent *event)
2513{
2514 const wmOperatorStatus invoke_result = graph_slider_invoke(C, op, event);
2515
2516 if (invoke_result == OPERATOR_CANCELLED) {
2517 return OPERATOR_CANCELLED;
2518 }
2519
2520 tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
2522 gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
2525 ED_slider_factor_set(gso->slider, 1.0f);
2526
2527 return invoke_result;
2528}
2529
2531{
2532 bAnimContext ac;
2533
2534 /* Get editor data. */
2535 if (ANIM_animdata_get_context(C, &ac) == 0) {
2536 return OPERATOR_CANCELLED;
2537 }
2538
2539 const float factor = RNA_float_get(op->ptr, "factor");
2540
2541 const FCurveSegmentAnchor anchor = FCurveSegmentAnchor(RNA_enum_get(op->ptr, "anchor"));
2542 scale_from_neighbor_graph_keys(&ac, factor, anchor);
2543
2544 /* Set notifier that keyframes have changed. */
2546
2547 return OPERATOR_FINISHED;
2548}
2549
2551{
2552 /* Identifiers. */
2553 ot->name = "Scale from Neighbor";
2554 ot->idname = "GRAPH_OT_scale_from_neighbor";
2555 ot->description =
2556 "Increase or decrease the value of selected keys in relationship to the neighboring one";
2557
2558 /* API callbacks. */
2563
2564 /* Flags. */
2566
2568 "factor",
2569 0.0f,
2570 -FLT_MAX,
2571 FLT_MAX,
2572 "Factor",
2573 "The factor to scale keys with",
2574 -1.0f,
2575 1.0f);
2576
2577 RNA_def_enum(ot->srna,
2578 "anchor",
2581 "Reference Key",
2582 "Which end of the segment to use as a reference to scale from");
2583}
2584
2586
2587} // namespace blender
Functions to modify FCurves.
#define TIP_(msgid)
#define IFACE_(msgid)
#define ANIM_UPDATE_DEFAULT
#define NUM_STR_REP_LEN
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_ANIMATION
Definition WM_types.hh:401
#define NA_EDITED
Definition WM_types.hh:634
#define ND_KEYFRAME
Definition WM_types.hh:537
#define STREQ(a, b)
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
#define FLT_MAX
#define INT_MAX
#define OPERATOR_DATA_FILTER
void sample_fcurve_segment(const FCurve *fcu, float start_frame, float sample_rate, float *samples, int sample_count)
BMesh Iterators.
ButterworthCoefficients * ED_anim_allocate_butterworth_coefficients(const int filter_order)
MINLINE float min_ff(float a, float b)
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor, const float width)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static const EnumPropertyItem scale_anchor_items[]
static wmOperatorStatus push_pull_exec(bContext *C, wmOperator *op)
static void reset_bezts(tGraphSliderOp *gso)
bool ED_slider_modal(tSlider *slider, const wmEvent *event)
Definition ed_draw.cc:492
static void decimate_graph_keys(bAnimContext *ac, float factor, float error_sq_max)
static int btw_calculate_sample_count(const BezTriple *right_bezt, const BezTriple *left_bezt, const int filter_order, const int samples_per_frame)
static void apply_fcu_segment_function(bAnimContext *ac, const float factor, void(*segment_function)(FCurve *fcu, FCurveSegment *segment, const float factor))
void GRAPH_OT_blend_to_default(wmOperatorType *ot)
static void blend_to_default_modal_update(bContext *C, wmOperator *op)
ScrArea * CTX_wm_area(const bContext *C)
static wmOperatorStatus blend_to_default_exec(bContext *C, wmOperator *op)
void GRAPH_OT_match_slope(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus scale_from_neighbor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void scale_from_fcurve_segment_neighbor(FCurve *fcu, FCurveSegment *segment, const float factor, const FCurveSegmentAnchor anchor)
@ RPT_WARNING
Definition BKE_report.hh:40
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GRAPH_OT_blend_offset(wmOperatorType *ot)
static wmOperatorStatus gaussian_smooth_exec(bContext *C, wmOperator *op)
static void match_slope_modal_update(bContext *C, wmOperator *op)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Definition numinput.cc:344
static void btw_smooth_free_operator_data(void *operator_data)
void ED_slider_init(tSlider *slider, const wmEvent *event)
Definition ed_draw.cc:487
void ED_anim_calculate_butterworth_coefficients(const float cutoff_frequency, const float sampling_frequency, ButterworthCoefficients *bw_coeff)
PointerRNA RNA_id_pointer_create(ID *id)
static std::string decimate_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
static void common_draw_status_header(bContext *C, tGraphSliderOp *gso)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
static wmOperatorStatus ease_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus scale_from_neighbor_modal(bContext *C, wmOperator *op, const wmEvent *event)
const char * RNA_property_identifier(const PropertyRNA *prop)
void GRAPH_OT_ease(wmOperatorType *ot)
void GRAPH_OT_blend_to_ease(wmOperatorType *ot)
void ED_slider_factor_set(tSlider *slider, float factor)
Definition ed_draw.cc:607
float ED_slider_factor_get(const tSlider *slider)
Definition ed_draw.cc:602
void WM_cursor_modal_set(wmWindow *win, int val)
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
void GRAPH_OT_breakdown(wmOperatorType *ot)
static void breakdown_graph_keys(bAnimContext *ac, float factor)
static void push_pull_graph_keys(bAnimContext *ac, const float factor)
static void update_depsgraph(tGraphSliderOp *gso)
static void blend_to_neighbor_modal_update(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void butterworth_smooth_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float *samples, const int sample_count, const float factor, const int blend_in_out, const int sample_rate, ButterworthCoefficients *bw_coeff)
static void decimate_modal_update(bContext *C, wmOperator *op)
void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
void ED_slider_mode_set(tSlider *slider, SliderMode mode)
Definition ed_draw.cc:650
static void btw_smooth_graph_keys(bAnimContext *ac, const float factor, const int blend_in_out, float cutoff_frequency, const int filter_order, const int samples_per_frame)
static wmOperatorStatus scale_average_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
static void match_slope_graph_keys(bAnimContext *ac, const float factor)
wmWindow * CTX_wm_window(const bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
static wmOperatorStatus graph_slider_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void shear_modal_update(bContext *C, wmOperator *op)
void GRAPH_OT_blend_to_neighbor(wmOperatorType *ot)
static void blend_offset_modal_update(bContext *C, wmOperator *op)
static const EnumPropertyItem shear_direction_items[]
static wmOperatorStatus graph_slider_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus shear_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void blend_to_ease_graph_keys(bAnimContext *ac, const float factor)
static void graph_slider_exit(bContext *C, wmOperator *op)
static void shear_draw_status_header(bContext *C, tGraphSliderOp *gso, tShearDirection direction)
void MEM_delete_void(void *vmemh)
static wmOperatorStatus breakdown_exec(bContext *C, wmOperator *op)
void GRAPH_OT_gaussian_smooth(wmOperatorType *ot)
void ANIM_animdata_update(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:365
void time_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float frame_offset)
void push_pull_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
static void scale_average_graph_keys(bAnimContext *ac, const float factor)
static wmOperatorStatus match_slope_exec(bContext *C, wmOperator *op)
ListBaseT< FCurveSegment > find_fcurve_segments(FCurve *fcu)
static const EnumPropertyItem decimate_mode_items[]
static wmOperatorStatus ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
tSlider * ED_slider_create(bContext *C)
Definition ed_draw.cc:438
SliderMode ED_slider_mode_get(const tSlider *slider)
Definition ed_draw.cc:655
static void time_offset_modal_update(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static wmOperatorStatus decimate_exec(bContext *C, wmOperator *op)
static void ease_graph_keys(bAnimContext *ac, const float factor, const float width)
static void scale_from_neighbor_draw_status_header(bContext *C, wmOperator *op)
static void ease_modal_update(bContext *C, wmOperator *op)
static void breakdown_modal_update(bContext *C, wmOperator *op)
void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
static void blend_offset_draw_status_header(bContext *C, tGraphSliderOp *gso)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static wmOperatorStatus scale_average_exec(bContext *C, wmOperator *op)
static void blend_to_default_graph_keys(bAnimContext *ac, const float factor)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
void ED_slider_unit_set(tSlider *slider, const char *unit)
Definition ed_draw.cc:660
static void decimate_draw_status(bContext *C, tGraphSliderOp *gso)
static float * back_up_key_y_values(const FCurveSegment *segment, const FCurve *fcu)
static wmOperatorStatus decimate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void blend_to_neighbor_graph_keys(bAnimContext *ac, const float factor)
void scale_average_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
void WM_cursor_modal_restore(wmWindow *win)
static wmOperatorStatus time_offset_exec(bContext *C, wmOperator *op)
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
static void gaussian_smooth_modal_update(bContext *C, wmOperator *op)
static wmOperatorStatus blend_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool match_slope_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static void blend_offset_graph_keys(bAnimContext *ac, const float factor)
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
void ED_slider_allow_overshoot_set(tSlider *slider, bool lower, bool upper)
Definition ed_draw.cc:626
static wmOperatorStatus blend_to_neighbor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void btw_smooth_modal_update(bContext *C, wmOperator *op)
static void scale_from_neighbor_graph_keys(bAnimContext *ac, const float factor, const FCurveSegmentAnchor anchor)
static void gaussian_smooth_free_operator_data(void *operator_data)
static wmOperatorStatus shear_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
static void time_offset_graph_keys(bAnimContext *ac, const float factor)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void ED_slider_factor_bounds_set(tSlider *slider, float factor_bound_lower, float factor_bound_upper)
Definition ed_draw.cc:642
void GRAPH_OT_shear(wmOperatorType *ot)
void blend_to_default_fcurve(PointerRNA *id_ptr, FCurve *fcu, const float factor)
static bool decimate_poll_property(const bContext *, wmOperator *op, const PropertyRNA *prop)
void smooth_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float *original_values, float *samples, const int sample_count, const float factor, const int kernel_size, const double *kernel)
@ WM_CURSOR_EW_SCROLL
Definition wm_cursors.hh:56
void shear_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor, tShearDirection direction)
static wmOperatorStatus blend_to_ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void ED_anim_free_butterworth_coefficients(ButterworthCoefficients *bw_coeff)
void GRAPH_OT_butterworth_smooth(wmOperatorType *ot)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
static wmOperatorStatus match_slope_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus blend_to_default_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_ANIM_get_1d_gauss_kernel(const float sigma, const int kernel_size, double *r_kernel)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
void GRAPH_OT_scale_from_neighbor(wmOperatorType *ot)
static void gaussian_smooth_allocate_operator_data(tGraphSliderOp *gso, const int filter_width, const float sigma)
void GRAPH_OT_decimate(wmOperatorType *ot)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
static void shear_graph_keys(bAnimContext *ac, const float factor, tShearDirection direction)
static void time_offset_draw_status_header(bContext *C, tGraphSliderOp *gso)
static void btw_smooth_allocate_operator_data(tGraphSliderOp *gso, const int filter_order, const int samples_per_frame)
void GRAPH_OT_time_offset(wmOperatorType *ot)
static wmOperatorStatus push_pull_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_slider_status_get(const tSlider *slider, WorkspaceStatus &status)
Definition ed_draw.cc:573
@ KM_RELEASE
Definition WM_types.hh:325
static void store_original_bezt_arrays(tGraphSliderOp *gso)
static wmOperatorStatus time_offset_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus blend_to_ease_exec(bContext *C, wmOperator *op)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:198
void GRAPH_OT_scale_average(wmOperatorType *ot)
static wmOperatorStatus btw_smooth_exec(bContext *C, wmOperator *op)
static wmOperatorStatus ease_exec(bContext *C, wmOperator *op)
static void push_pull_modal_update(bContext *C, wmOperator *op)
void GRAPH_OT_push_pull(wmOperatorType *ot)
static void match_slope_draw_status_header(bContext *C, tGraphSliderOp *gso)
static void blend_to_ease_modal_update(bContext *C, wmOperator *op)
static float slider_factor_get_and_remember(wmOperator *op)
static wmOperatorStatus scale_from_neighbor_exec(bContext *C, wmOperator *op)
void ED_slider_property_label_set(tSlider *slider, const char *property_label)
Definition ed_draw.cc:665
void ED_slider_increment_step_set(tSlider *slider, float increment_step)
Definition ed_draw.cc:616
static wmOperatorStatus blend_offset_exec(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
ARegion * CTX_wm_region(const bContext *C)
static wmOperatorStatus btw_smooth_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus gaussian_smooth_invoke(bContext *C, wmOperator *op, const wmEvent *event)
float RNA_float_get(PointerRNA *ptr, const char *name)
void ED_slider_destroy(bContext *C, tSlider *slider)
Definition ed_draw.cc:589
static void ease_draw_status_header(bContext *C, wmOperator *op)
static void scale_from_neighbor_modal_update(bContext *C, wmOperator *op)
@ SLIDER_MODE_PERCENT
Definition ED_util.hh:90
@ SLIDER_MODE_FLOAT
Definition ED_util.hh:90
static void gaussian_smooth_graph_keys(bAnimContext *ac, const float factor, double *kernel, const int filter_width)
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
bool decimate_fcurve(bAnimListElem *ale, float remove_ratio, float error_sq_max)
static void blend_to_ease_draw_status_header(bContext *C, tGraphSliderOp *gso)
static wmOperatorStatus blend_to_neighbor_exec(bContext *C, wmOperator *op)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void scale_average_modal_update(bContext *C, wmOperator *op)
void blend_to_ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
bool graphop_editable_keyframes_poll(bContext *C)
static wmOperatorStatus shear_exec(bContext *C, wmOperator *op)
static wmOperatorStatus breakdown_invoke(bContext *C, wmOperator *op, const wmEvent *event)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
unsigned int totvert
struct LinkData * next
struct UnitSettings unit
struct RenderData r
eAnimCont_Types datatype
eAnim_Update_Flags update
bAnimListElem * next
ListBaseT< bAnimListElem > anim_data
ButterworthCoefficients * coefficients
ListBaseT< tFCurveSegmentLink > segment_links
ListBaseT< bAnimListElem > anim_data
ListBaseT< tFCurveSegmentLink > segment_links
void(*) modal_update(bContext *, wmOperator *)
ListBaseT< LinkData > bezt_arr_list
void(*) free_operator_data(void *operator_data)
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) poll_property(const bContext *C, wmOperator *op, const PropertyRNA *prop) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1171
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports
struct wmOperatorType * type
#define ISKEYMODIFIER(event_type)