Blender V5.3
graph_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cfloat>
12#include <cmath>
13#include <cstdlib>
14#include <cstring>
15
16#ifdef WITH_AUDASPACE
17# include "BKE_sound.hh"
18#endif
19
20#include "MEM_guardedalloc.h"
21
22#include "BLI_fileops.hh"
23#include "BLI_listbase.hh"
25#include "BLI_utildefines.hh"
26
27#include "DNA_anim_types.h"
28#include "DNA_scene_types.h"
29
30#include "RNA_access.hh"
31#include "RNA_define.hh"
32#include "RNA_enum_types.hh"
33#include "RNA_prototypes.hh"
34
35#include "BLT_translation.hh"
36
37#include "BKE_animsys.hh"
38#include "BKE_context.hh"
39#include "BKE_fcurve.hh"
40#include "BKE_global.hh"
41#include "BKE_nla.hh"
42#include "BKE_report.hh"
43#include "BKE_scene.hh"
44
45#include "DEG_depsgraph.hh"
47
48#include "UI_interface_icons.hh"
49#include "UI_view2d.hh"
50
51#include "ANIM_animdata.hh"
52#include "ANIM_fcurve.hh"
53#include "ANIM_keyframing.hh"
54#include "ED_anim_api.hh"
55#include "ED_keyframes_edit.hh"
56#include "ED_keyframing.hh"
57#include "ED_markers.hh"
58#include "ED_screen.hh"
59#include "ED_transform.hh"
60
62#include "UI_resources.hh"
63
64#include "WM_api.hh"
65#include "WM_types.hh"
66
67#include "graph_intern.hh"
68
69namespace blender {
70
71/* -------------------------------------------------------------------- */
74
75/* Mode defines for insert keyframes tool. */
82
83/* RNA mode types for insert keyframes tool. */
86 "ALL",
87 0,
88 "All Channels",
89 "Insert a keyframe on all visible and editable F-Curves using each curve's current value"},
91 "SEL",
92 0,
93 "Only Selected Channels",
94 "Insert a keyframe on selected F-Curves using each curve's current value"},
96 "ACTIVE",
97 0,
98 "Only Active F-Curve",
99 "Insert a keyframe on the active F-Curve using the curve's current value"},
101 "CURSOR_ACTIVE",
102 0,
103 "Active Channels at Cursor",
104 "Insert a keyframe for the active F-Curve at the cursor point"},
106 "CURSOR_SEL",
107 0,
108 "Selected Channels at Cursor",
109 "Insert a keyframe for selected F-Curves at the cursor point"},
110 {0, nullptr, 0, nullptr, nullptr},
111};
112
113/* This function is responsible for snapping keyframes to frame-times. */
115{
116 using namespace blender::animrig;
117 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
118 int filter;
119 size_t num_items;
120
121 ReportList *reports = ac->reports;
122 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac->sl);
123 Scene *scene = ac->scene;
124 ToolSettings *ts = scene->toolsettings;
125
126 /* Filter data. */
129 if (mode & GRAPHKEYS_INSERTKEY_SEL) {
131 }
132 else if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) {
134 }
135
136 num_items = ANIM_animdata_filter(
137 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
138 if (num_items == 0) {
139 if (mode & GRAPHKEYS_INSERTKEY_ACTIVE) {
140 BKE_report(reports,
141 RPT_ERROR,
142 "No active F-Curve to add a keyframe to. Select an editable F-Curve first");
143 }
144 else if (mode & GRAPHKEYS_INSERTKEY_SEL) {
145 BKE_report(reports, RPT_ERROR, "No selected F-Curves to add keyframes to");
146 }
147 else {
148 BKE_report(reports, RPT_ERROR, "No channels to add keyframes to");
149 }
150
151 return;
152 }
153
154 /* Init key-framing flag. */
158
159 /* Insert keyframes. */
160 if (mode & GRAPHKEYS_INSERTKEY_CURSOR) {
161 for (bAnimListElem &ale : anim_data) {
162 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
163
164 short mapping_flag = ANIM_get_normalization_flags(ac->sl);
165 float offset;
166 float unit_scale = ANIM_unit_mapping_get_factor(
167 ac->scene, ale.id, static_cast<FCurve *>(ale.key_data), mapping_flag, &offset);
168
169 float x, y;
170
171 /* perform time remapping for x-coordinate (if necessary) */
172 if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) {
173 x = sipo->cursorTime;
174 }
175 else {
176 x = ANIM_nla_tweakedit_remap(&ale, float(scene->r.cfra), NLATIME_CONVERT_UNMAP);
177 }
178
179 /* Normalize units of cursor's value. */
180 if (sipo) {
181 y = (sipo->cursorVal / unit_scale) - offset;
182 }
183 else {
184 y = 0.0f;
185 }
186
187 /* Insert keyframe directly into the F-Curve. */
188 insert_vert_fcurve(fcu, {x, y}, settings, eInsertKeyFlags{});
189
190 ale.update |= ANIM_UPDATE_DEFAULT;
191 }
192 }
193 else {
195 ac->depsgraph, float(scene->r.cfra));
196 for (bAnimListElem &ale : anim_data) {
197 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
198
199 /* Read value from property the F-Curve represents, or from the curve only?
200 *
201 * - ale->id != nullptr:
202 * Typically, this means that we have enough info to try resolving the path.
203 * - ale->owner != nullptr:
204 * If this is set, then the path may not be resolvable from the ID alone,
205 * so it's easier for now to just read the F-Curve directly.
206 * (TODO: add the full-blown PointerRNA relative parsing case here... (Joshua Leung 2015))
207 * - fcu->driver != nullptr:
208 * If this is set, then it's a driver. If we don't check for this, we'd end
209 * up adding the keyframes on a new F-Curve in the action data instead.
210 */
211 const std::optional<StringRefNull> channel_group = fcu->grp ? std::optional(fcu->grp->name) :
212 std::nullopt;
213 if (ale.id && !ale.owner && !fcu->driver) {
214 PointerRNA id_rna_pointer = RNA_id_pointer_create(ale.id);
216 &id_rna_pointer,
217 channel_group,
218 {{fcu->rna_path(), {}, fcu->array_index}},
219 std::nullopt,
220 anim_eval_context,
222 flag);
223 if (result.get_count(SingleKeyingResult::SUCCESS) == 0) {
224 result.generate_reports(reports);
225 }
226 }
227 else {
228 /* Adjust current frame for NLA-mapping. */
229 float cfra;
230 if ((sipo) && (sipo->mode == SIPO_MODE_DRIVERS)) {
231 cfra = sipo->cursorTime;
232 }
233 else {
234 cfra = ANIM_nla_tweakedit_remap(&ale, float(scene->r.cfra), NLATIME_CONVERT_UNMAP);
235 }
236
237 const float curval = evaluate_fcurve_only_curve(fcu, cfra);
238 insert_vert_fcurve(fcu, {cfra, curval}, settings, eInsertKeyFlags{});
239 }
240
241 ale.update |= ANIM_UPDATE_DEFAULT;
242 }
243 }
244
245 ANIM_animdata_update(ac, &anim_data);
246 ANIM_animdata_freelist(&anim_data);
247}
248
249/* ------------------- */
250
252{
253 bAnimContext ac;
255
256 /* Get editor data. */
257 if (ANIM_animdata_get_context(C, &ac) == 0) {
258 return OPERATOR_CANCELLED;
259 }
260
262
263 /* Which channels to affect? */
264 mode = eGraphKeys_InsertKey_Types(RNA_enum_get(op->ptr, "type"));
265
266 /* Insert keyframes. */
267 insert_graph_keys(&ac, mode);
268
269 /* Set notifier that keyframes have changed. */
271
272 return OPERATOR_FINISHED;
273}
274
276{
277 /* Identifiers */
278 ot->name = "Insert Keyframes";
279 ot->idname = "GRAPH_OT_keyframe_insert";
280 ot->description = "Insert keyframes for the specified channels";
281
282 /* API callbacks */
286
287 /* Flags */
289
290 /* Id-props */
291 ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_insertkey_types, 0, "Type", "");
292}
293
295
296/* -------------------------------------------------------------------- */
299
301{
302 using namespace blender::animrig;
303 bAnimContext ac;
304 bAnimListElem *ale;
305 FCurve *fcu;
306
307 /* Get animation context. */
308 if (ANIM_animdata_get_context(C, &ac) == 0) {
309 return OPERATOR_CANCELLED;
310 }
311
312 /* Get active F-Curve 'anim-list-element'. */
313 ale = get_active_fcurve_channel(&ac);
314 if (ELEM(nullptr, ale, ale->data)) {
315 if (ale) {
316 MEM_delete(ale);
317 }
318 return OPERATOR_CANCELLED;
319 }
320 fcu = static_cast<FCurve *>(ale->data);
321
322 /* When there are F-Modifiers on the curve, only allow adding
323 * keyframes if these will be visible after doing so...
324 */
325 if (fcu && BKE_fcurve_is_keyframable(*fcu)) {
326 ListBaseT<bAnimListElem> anim_data;
328
329 /* Preserve selection? */
330 if (RNA_boolean_get(op->ptr, "extend") == false) {
331 /* Deselect all keyframes first,
332 * so that we can immediately start manipulating the newly added one(s)
333 * - only affect the keyframes themselves, as we don't want channels popping in and out. */
334 deselect_graph_keys(&ac, false, SELECT_SUBTRACT, false);
335 }
336
337 /* Get frame and value from props.
338 *
339 * We apply inverse NLA-mapping to `frame` to get correct time in un-scaled
340 * action. */
341 const float frame = ANIM_nla_tweakedit_remap(
342 ale, RNA_float_get(op->ptr, "frame"), NLATIME_CONVERT_UNMAP);
343 float val = RNA_float_get(op->ptr, "value");
344
345 /* Apply inverse unit-mapping to value to get correct value for F-Curves. */
346 {
347 const short mapping_flag = ANIM_get_normalization_flags(ac.sl);
348 float offset;
350 ac.scene, ale->id, fcu, mapping_flag | ANIM_UNITCONV_RESTORE, &offset);
351
352 val = val * scale - offset;
353 }
354
357
358 /* Insert keyframe on the specified frame + value. */
359 insert_vert_fcurve(fcu, {frame, val}, settings, eInsertKeyFlags{});
360
361 ale->update |= ANIM_UPDATE_DEPS;
362
363 anim_data.clear_no_delete();
364 BLI_addtail(&anim_data, ale);
365
366 ANIM_animdata_update(&ac, &anim_data);
367 }
368 else {
369 /* Warn about why this can't happen. */
370 if (fcu->fpt) {
371 BKE_report(op->reports, RPT_ERROR, "Keyframes cannot be added to sampled F-Curves");
372 }
373 else if (fcu->flag & FCURVE_PROTECTED) {
374 BKE_report(op->reports, RPT_ERROR, "Active F-Curve is not editable");
375 }
376 else {
377 BKE_report(op->reports, RPT_ERROR, "Remove F-Modifiers from F-Curve to add keyframes");
378 }
379 }
380
381 /* Free temp data. */
382 MEM_delete(ale);
383
384 /* Set notifier that keyframes have changed. */
386
387 /* Done */
388 return OPERATOR_FINISHED;
389}
390
392 wmOperator *op,
393 const wmEvent *event)
394{
395 bAnimContext ac;
396 ARegion *region;
397 View2D *v2d;
398 int mval[2];
399 float x, y;
400
401 /* Get animation context. */
402 if (ANIM_animdata_get_context(C, &ac) == 0) {
403 return OPERATOR_CANCELLED;
404 }
405
406 /* Store mouse coordinates in View2D space, into the operator's properties. */
407 region = ac.region;
408 v2d = &region->v2d;
409
410 mval[0] = (event->xy[0] - region->winrct.xmin);
411 mval[1] = (event->xy[1] - region->winrct.ymin);
412
413 ui::view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
414
415 RNA_float_set(op->ptr, "frame", x);
416 RNA_float_set(op->ptr, "value", y);
417
418 /* Run exec now. */
419 return graphkeys_click_insert_exec(C, op);
420}
421
423{
424 PropertyRNA *prop;
425
426 /* Identifiers */
427 ot->name = "Click-Insert Keyframes";
428 ot->idname = "GRAPH_OT_click_insert";
429 ot->description = "Insert new keyframe at the cursor position for the active F-Curve";
430
431 /* API callbacks */
435
436 /* Flags */
438
439 /* Properties */
441 "frame",
442 1.0f,
443 -FLT_MAX,
444 FLT_MAX,
445 "Frame Number",
446 "Frame to insert keyframe on",
447 0,
448 100);
450 ot->srna, "value", 1.0f, -FLT_MAX, FLT_MAX, "Value", "Value for keyframe on", 0, 100);
451
452 prop = RNA_def_boolean(ot->srna,
453 "extend",
454 false,
455 "Extend",
456 "Extend selection instead of deselecting everything first");
458}
459
461
462/* -------------------------------------------------------------------- */
467
469{
470 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
471 int filter;
472
473 /* Filter data
474 * - First time we try to filter more strictly, allowing only selected channels
475 * to allow copying animation between channels.
476 */
479
481 &anim_data,
483 ac->data,
484 eAnimCont_Types(ac->datatype)) == 0)
485 {
487 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
488 }
489
490 /* Copy keyframes. */
491 const bool ok = copy_animedit_keys(ac, &anim_data);
492
493 /* Clean up. */
494 ANIM_animdata_freelist(&anim_data);
495
496 return ok;
497}
498
500 const eKeyPasteOffset offset_mode,
501 const eKeyPasteValueOffset value_offset_mode,
502 const eKeyMergeMode merge_mode,
503 const bool flip)
504{
505 /* TODO: deduplicate this function and `paste_action_keys()` in `action_edit.cc`, */
506
507 /* Determine paste context. */
508 KeyframePasteContext paste_context{};
509 paste_context.offset_mode = offset_mode;
510 paste_context.value_offset_mode = value_offset_mode;
511 paste_context.merge_mode = merge_mode;
512 paste_context.flip = flip;
513 paste_context.num_slots_selected = 0; /* Graph editor doesn't show slots. */
514
515 /* Find F-Curves to paste into, in two stages.
516 * - First time we try to filter more strictly, allowing only selected channels
517 * to allow copying animation between channels
518 * - Second time, we loosen things up if nothing was found the first time, allowing
519 * users to just paste keyframes back into the original curve again #31670.
520 */
521 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
522 {
526 ac, &anim_data, filter | ANIMFILTER_SEL, ac->data, ac->datatype);
527 if (paste_context.num_fcurves_selected == 0) {
528 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
529 }
530 }
531
532 /* Paste keyframes. */
533 const eKeyPasteError ok = paste_animedit_keys(ac, &anim_data, paste_context);
534
535 /* Clean up. */
536 ANIM_animdata_freelist(&anim_data);
537
538 return ok;
539}
540
541/* ------------------- */
542
544{
545 bAnimContext ac;
546
547 /* Get editor data. */
548 if (ANIM_animdata_get_context(C, &ac) == 0) {
549 return OPERATOR_CANCELLED;
550 }
551
552 /* Copy keyframes. */
553 if (!copy_graph_keys(&ac)) {
554 BKE_report(op->reports, RPT_ERROR, "No keyframes copied to the internal clipboard");
555 return OPERATOR_CANCELLED;
556 }
557
558 /* Just return - no operator needed here (no changes). */
559 return OPERATOR_FINISHED;
560}
561
563{
564 /* Identifiers */
565 ot->name = "Copy Keyframes";
566 ot->idname = "GRAPH_OT_copy";
567 ot->description = "Copy selected keyframes to the internal clipboard";
568
569 /* API callbacks */
572
573 /* Flags */
575}
576
578{
579 bAnimContext ac;
580
581 const eKeyPasteOffset offset_mode = eKeyPasteOffset(RNA_enum_get(op->ptr, "offset"));
582 const eKeyPasteValueOffset value_offset_mode = eKeyPasteValueOffset(
583 RNA_enum_get(op->ptr, "value_offset"));
584 const eKeyMergeMode merge_mode = eKeyMergeMode(RNA_enum_get(op->ptr, "merge"));
585 const bool flipped = RNA_boolean_get(op->ptr, "flipped");
586
587 /* Get editor data. */
588 if (ANIM_animdata_get_context(C, &ac) == 0) {
589 return OPERATOR_CANCELLED;
590 }
591
592 /* Ac.reports by default will be the global reports list, which won't show warnings. */
593 ac.reports = op->reports;
594
595 const eKeyPasteError kf_empty = paste_graph_keys(
596 &ac, offset_mode, value_offset_mode, merge_mode, flipped);
597 switch (kf_empty) {
599 break;
600
602 BKE_report(op->reports, RPT_ERROR, "No selected F-Curves to paste into");
603 return OPERATOR_CANCELLED;
604
606 BKE_report(op->reports, RPT_ERROR, "No data in the internal clipboard to paste");
607 return OPERATOR_CANCELLED;
608 }
609
610 /* Set notifier that keyframes have changed. */
612
613 return OPERATOR_FINISHED;
614}
615
616static std::string graphkeys_paste_get_description(bContext * /*C*/,
617 wmOperatorType * /*ot*/,
618 PointerRNA *ptr)
619{
620 /* Custom description if the 'flipped' option is used. */
621 if (RNA_boolean_get(ptr, "flipped")) {
622 return TIP_("Paste keyframes from mirrored bones if they exist");
623 }
624
625 /* Use the default description in the other cases. */
626 return "";
627}
628
630{
631 PropertyRNA *prop;
632
633 /* Identifiers */
634 ot->name = "Paste Keyframes";
635 ot->idname = "GRAPH_OT_paste";
636 ot->description =
637 "Paste keyframes from the internal clipboard for the selected channels, starting on the "
638 "current "
639 "frame";
640
641 /* API callbacks */
642
643 // ot->invoke = WM_operator_props_popup; /* better wait for graph redo panel */
647
648 /* Flags */
650
651 /* Props */
652 RNA_def_enum(ot->srna,
653 "offset",
656 "Frame Offset",
657 "Paste time offset of keys");
658 RNA_def_enum(ot->srna,
659 "value_offset",
662 "Value Offset",
663 "Paste keys with a value offset");
664 RNA_def_enum(ot->srna,
665 "merge",
668 "Type",
669 "Method of merging pasted keys and existing");
670 prop = RNA_def_boolean(
671 ot->srna, "flipped", false, "Flipped", "Paste keyframes from mirrored bones if they exist");
673}
674
676
677/* -------------------------------------------------------------------- */
680
682{
683 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
684 int filter;
685 bool changed = false;
686
687 /* Filter data. */
691 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
692
693 /* Loop through filtered data and delete selected keys. */
694 for (bAnimListElem &ale : anim_data) {
695 changed |= duplicate_fcurve_keys(static_cast<FCurve *>(ale.key_data));
696
697 ale.update |= ANIM_UPDATE_DEFAULT;
698 }
699
700 ANIM_animdata_update(ac, &anim_data);
701 ANIM_animdata_freelist(&anim_data);
702
703 return changed;
704}
705
706/* ------------------- */
707
709{
710 bAnimContext ac;
711
712 /* Get editor data. */
713 if (ANIM_animdata_get_context(C, &ac) == 0) {
714 return OPERATOR_CANCELLED;
715 }
716
717 /* Duplicate keyframes. */
718 if (!duplicate_graph_keys(&ac)) {
719 return OPERATOR_CANCELLED;
720 }
721
722 /* Set notifier that keyframes have changed. */
724
725 return OPERATOR_FINISHED;
726}
727
729{
730 /* Identifiers */
731 ot->name = "Duplicate Keyframes";
732 ot->idname = "GRAPH_OT_duplicate";
733 ot->description = "Make a copy of all selected keyframes";
734
735 /* API callbacks */
738
739 /* Flags */
741
742 /* To give to transform. */
743 RNA_def_enum(ot->srna,
744 "mode",
747 "Mode",
748 "");
749}
750
752
753/* -------------------------------------------------------------------- */
756
758{
759 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
760 int filter;
761 bool changed_final = false;
762
763 /* Filter data. */
767 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
768
769 /* Loop through filtered data and delete selected keys. */
770 for (bAnimListElem &ale : anim_data) {
771 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
772 AnimData *adt = ale.adt;
773 bool changed = false;
774
775 /* Delete selected keyframes only. */
776 if (fcu) {
777 changed = BKE_fcurve_delete_keys_selected(*fcu);
778 }
779
780 if (changed) {
781 ale.update |= ANIM_UPDATE_DEFAULT;
782 changed_final = true;
783 }
784
785 /* Only delete curve too if it won't be doing anything anymore. */
786 if (BKE_fcurve_is_empty(fcu)) {
788 ale.key_data = nullptr;
789 }
790 }
791
792 ANIM_animdata_update(ac, &anim_data);
793 ANIM_animdata_freelist(&anim_data);
794
795 return changed_final;
796}
797
798/* ------------------- */
799
801{
802 bAnimContext ac;
803
804 /* Get editor data. */
805 if (ANIM_animdata_get_context(C, &ac) == 0) {
806 return OPERATOR_CANCELLED;
807 }
808
809 /* Delete keyframes. */
810 if (!delete_graph_keys(&ac)) {
811 return OPERATOR_CANCELLED;
812 }
813
814 /* Set notifier that keyframes have changed. */
816
817 return OPERATOR_FINISHED;
818}
819
821 wmOperator *op,
822 const wmEvent * /*event*/)
823{
824 if (RNA_boolean_get(op->ptr, "confirm")) {
826 op,
827 IFACE_("Delete selected keyframes?"),
828 nullptr,
829 IFACE_("Delete"),
831 false);
832 }
833 return graphkeys_delete_exec(C, op);
834}
835
837{
838 /* Identifiers */
839 ot->name = "Delete Keyframes";
840 ot->idname = "GRAPH_OT_delete";
841 ot->description = "Remove all selected keyframes";
842
843 /* API callbacks */
847
848 /* Flags */
851}
852
854
855/* -------------------------------------------------------------------- */
858
859static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan)
860{
861 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
862 int filter;
863
864 /* Filter data. */
867 if (clean_chan) {
869 }
871 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
872
873 const bool only_selected_keys = !clean_chan;
874 /* Loop through filtered data and clean curves. */
875 for (bAnimListElem &ale : anim_data) {
876 clean_fcurve(&ale, thresh, clean_chan, only_selected_keys);
877
878 ale.update |= ANIM_UPDATE_DEFAULT;
879 }
880
881 ANIM_animdata_update(ac, &anim_data);
882 ANIM_animdata_freelist(&anim_data);
883}
884
885/* ------------------- */
886
888{
889 bAnimContext ac;
890 float thresh;
891 bool clean_chan;
892
893 /* Get editor data. */
894 if (ANIM_animdata_get_context(C, &ac) == 0) {
895 return OPERATOR_CANCELLED;
896 }
897
898 /* Get cleaning threshold. */
899 thresh = RNA_float_get(op->ptr, "threshold");
900 clean_chan = RNA_boolean_get(op->ptr, "channels");
901 /* Clean keyframes. */
902 clean_graph_keys(&ac, thresh, clean_chan);
903
904 /* Set notifier that keyframes have changed. */
906
907 return OPERATOR_FINISHED;
908}
909
910static std::string graphkeys_clean_get_description(bContext * /*C*/,
911 wmOperatorType * /*ot*/,
912 PointerRNA *ptr)
913{
914 /* Custom description based on the 'channels' property */
915 if (RNA_boolean_get(ptr, "channels")) {
916 return TIP_("Simplify F-Curves and remove empty or redundant channels.");
917 }
918
919 /* Use the default description in the other case. */
920 return "";
921}
922
924{
925 /* Identifiers */
926 ot->name = "Clean Keyframes";
927 ot->idname = "GRAPH_OT_clean";
928 ot->description = "Simplify F-Curves by removing closely spaced keyframes";
929
930 /* API callbacks */
931 // ot->invoke = ???; /* XXX we need that number popup for this! */
935
936 /* Flags */
938
939 /* Properties */
940 ot->prop = RNA_def_float(
941 ot->srna, "threshold", 0.001f, 0.0f, FLT_MAX, "Threshold", "", 0.0f, 1000.0f);
942 RNA_def_boolean(ot->srna, "channels", false, "Channels", "");
943}
944
946
947/* -------------------------------------------------------------------- */
952
953/* Bake each F-Curve into a set of samples. */
954static void convert_keys_to_samples(bAnimContext *ac, int start, int end)
955{
956 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
957 int filter;
958
959 /* Filter data. */
963 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
964
965 /* Loop through filtered data and add keys between selected keyframes on every frame. */
966 for (bAnimListElem &ale : anim_data) {
967 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
968 ChannelDriver *driver = fcu->driver;
969
970 /* Disable driver so that it don't muck up the sampling process. */
971 fcu->driver = nullptr;
972
973 /* Create samples. */
974 fcurve_store_samples(fcu, nullptr, start, end, fcurve_samplingcb_evalcurve);
975
976 /* Restore driver. */
977 fcu->driver = driver;
978
979 ale.update |= ANIM_UPDATE_DEPS;
980 }
981
982 ANIM_animdata_update(ac, &anim_data);
983 ANIM_animdata_freelist(&anim_data);
984}
985
986/* ------------------- */
987
989{
990 bAnimContext ac;
991
992 /* Get editor data. */
993 if (ANIM_animdata_get_context(C, &ac) == 0) {
994 return OPERATOR_CANCELLED;
995 }
996
997 /* For now, init start/end from preview-range extents. */
998 /* TODO: add properties for this. (Joshua Leung 2009) */
999 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(ac.scene);
1000
1001 /* Sample keyframes. */
1002 convert_keys_to_samples(&ac, playback_range.start_frame, playback_range.end_frame);
1003
1004 /* Set notifier that keyframes have changed. */
1005 /* NOTE: some distinction between order/number of keyframes and type should be made? */
1007
1008 return OPERATOR_FINISHED;
1009}
1010
1012{
1013 /* Identifiers */
1014 ot->name = "Keys to Samples";
1015 ot->idname = "GRAPH_OT_keys_to_samples";
1016 ot->description =
1017 "Convert selected channels to an uneditable set of samples to save storage space";
1018
1019 /* API callbacks */
1022
1023 /* Flags */
1025
1026 /* TODO: add props for start/end frames (Joshua Leung 2009) */
1027}
1028
1030
1031/* -------------------------------------------------------------------- */
1036
1037/* Convert F-Points into F-Curves. */
1038static void convert_samples_to_keys(bAnimContext *ac, int start, int end)
1039{
1040 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1041
1042 /* Filter data. */
1046 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1047
1048 /* Loop through filtered data and add keys between selected keyframes on every frame. */
1049 for (bAnimListElem &ale : anim_data) {
1050 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1051
1052 fcurve_samples_to_keyframes(fcu, start, end);
1053
1054 ale.update |= ANIM_UPDATE_DEPS;
1055 }
1056
1057 ANIM_animdata_update(ac, &anim_data);
1058 ANIM_animdata_freelist(&anim_data);
1059}
1060
1061/* ------------------- */
1062
1064{
1065 bAnimContext ac;
1066
1067 /* Get editor data. */
1068 if (ANIM_animdata_get_context(C, &ac) == 0) {
1069 return OPERATOR_CANCELLED;
1070 }
1071
1072 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(ac.scene);
1073 convert_samples_to_keys(&ac, playback_range.start_frame, playback_range.end_frame);
1074
1075 /* Set notifier that keyframes have changed. */
1076 /* NOTE: some distinction between order/number of keyframes and type should be made? */
1078
1079 return OPERATOR_FINISHED;
1080}
1081
1083{
1084 /* Identifiers */
1085 ot->name = "Samples to Keys";
1086 ot->idname = "GRAPH_OT_samples_to_keys";
1087 ot->description = "Convert selected channels from samples to keyframes";
1088
1089 /* API callbacks */
1092
1093 /* Flags */
1095}
1096
1097#ifdef WITH_AUDASPACE
1098
1100
1101/* -------------------------------------------------------------------- */
1106
1107/* ------------------- */
1108
1109/* Custom data storage passed to the F-Sample-ing function,
1110 * which provides the necessary info for baking the sound.
1111 */
1112struct tSoundBakeInfo {
1113 float *samples;
1114 int length;
1115 int cfra;
1116};
1117
1118/* ------------------- */
1119
1120/* Sampling callback used to determine the value from the sound to
1121 * save in the F-Curve at the specified frame.
1122 */
1123static float fcurve_samplingcb_sound(FCurve * /*fcu*/, void *data, float evaltime)
1124{
1125 tSoundBakeInfo *sbi = static_cast<tSoundBakeInfo *>(data);
1126
1127 int position = evaltime - sbi->cfra;
1128 if ((position < 0) || (position >= sbi->length)) {
1129 return 0.0f;
1130 }
1131
1132 return sbi->samples[position];
1133}
1134
1135/* ------------------- */
1136
1138{
1139 bAnimContext ac;
1140 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1141 int filter;
1142
1143 tSoundBakeInfo sbi;
1144 Scene *scene = nullptr;
1145 int start, end;
1146
1147 char filepath[FILE_MAX];
1148
1149 /* Get editor data. */
1150 if (ANIM_animdata_get_context(C, &ac) == 0) {
1151 return OPERATOR_CANCELLED;
1152 }
1153
1154 RNA_string_get(op->ptr, "filepath", filepath);
1155
1156 if (!BLI_is_file(filepath)) {
1157 BKE_reportf(op->reports, RPT_ERROR, "File not found '%s'", filepath);
1158 return OPERATOR_CANCELLED;
1159 }
1160
1161 scene = ac.scene; /* Current scene. */
1162
1163 /* Store necessary data for the baking steps. */
1164 sbi.samples = bke::sound_read_file_buffer(filepath,
1165 RNA_float_get(op->ptr, "low"),
1166 RNA_float_get(op->ptr, "high"),
1167 RNA_float_get(op->ptr, "attack"),
1168 RNA_float_get(op->ptr, "release"),
1169 RNA_float_get(op->ptr, "threshold"),
1170 RNA_boolean_get(op->ptr, "use_accumulate"),
1171 RNA_boolean_get(op->ptr, "use_additive"),
1172 RNA_boolean_get(op->ptr, "use_square"),
1173 RNA_float_get(op->ptr, "sthreshold"),
1174 scene->frames_per_second(),
1175 0,
1176 &sbi.length);
1177
1178 if (sbi.samples == nullptr) {
1179 BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
1180 return OPERATOR_CANCELLED;
1181 }
1182
1183 /* Determine extents of the baking. */
1184 sbi.cfra = start = scene->r.cfra;
1185 end = scene->r.cfra + sbi.length - 1;
1186
1187 /* Filter anim channels. */
1191 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
1192
1193 /* Loop through all selected F-Curves, replacing its data with the sound samples. */
1194 for (bAnimListElem &ale : anim_data) {
1195 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1196
1197 /* Sample the sound. */
1198 fcurve_store_samples(fcu, &sbi, start, end, fcurve_samplingcb_sound);
1199
1200 ale.update |= ANIM_UPDATE_DEFAULT;
1201 }
1202
1203 /* Free sample data. */
1204 MEM_delete(sbi.samples);
1205
1206 /* Validate keyframes after editing. */
1207 ANIM_animdata_update(&ac, &anim_data);
1208 ANIM_animdata_freelist(&anim_data);
1209
1210 /* Set notifier that 'keyframes' have changed. */
1212
1213 return OPERATOR_FINISHED;
1214}
1215
1216#else /* WITH_AUDASPACE */
1217
1219{
1220 BKE_report(op->reports, RPT_ERROR, "Compiled without sound support");
1221
1222 return OPERATOR_CANCELLED;
1223}
1224
1225#endif /* WITH_AUDASPACE */
1226
1228 wmOperator *op,
1229 const wmEvent *event)
1230{
1231 bAnimContext ac;
1232
1233 /* Verify editor data. */
1234 if (ANIM_animdata_get_context(C, &ac) == 0) {
1235 return OPERATOR_CANCELLED;
1236 }
1237
1238 return WM_operator_filesel(C, op, event);
1239}
1240
1242{
1243 /* Identifiers */
1244 ot->name = "Sound to Samples";
1245 ot->idname = "GRAPH_OT_sound_to_samples";
1246 ot->description = "Bakes a sound wave to samples on selected channels";
1247
1248 /* API callbacks */
1252
1253 /* Flags */
1255
1256 /* Properties */
1264 RNA_def_float(ot->srna,
1265 "low",
1266 0.0f,
1267 0.0,
1268 100000.0,
1269 "Lowest Frequency",
1270 "Cutoff frequency of a high-pass filter that is applied to the audio data",
1271 0.1,
1272 1000.00);
1273 RNA_def_float(ot->srna,
1274 "high",
1275 100000.0,
1276 0.0,
1277 100000.0,
1278 "Highest Frequency",
1279 "Cutoff frequency of a low-pass filter that is applied to the audio data",
1280 0.1,
1281 1000.00);
1282 RNA_def_float(ot->srna,
1283 "attack",
1284 0.005,
1285 0.0,
1286 2.0,
1287 "Attack Time",
1288 "Value for the envelope calculation that tells how fast the envelope can rise "
1289 "(the lower the value the steeper it can rise)",
1290 0.01,
1291 0.1);
1292 RNA_def_float(ot->srna,
1293 "release",
1294 0.2,
1295 0.0,
1296 5.0,
1297 "Release Time",
1298 "Value for the envelope calculation that tells how fast the envelope can fall "
1299 "(the lower the value the steeper it can fall)",
1300 0.01,
1301 0.2);
1302 RNA_def_float(ot->srna,
1303 "threshold",
1304 0.0,
1305 0.0,
1306 1.0,
1307 "Threshold",
1308 "Minimum amplitude value needed to influence the envelope",
1309 0.01,
1310 0.1);
1312 "use_accumulate",
1313 false,
1314 "Accumulate",
1315 "Only the positive differences of the envelope amplitudes are summarized to "
1316 "produce the output");
1318 "use_additive",
1319 false,
1320 "Additive",
1321 "The amplitudes of the envelope are summarized (or, when Accumulate is enabled, "
1322 "both positive and negative differences are accumulated)");
1324 "use_square",
1325 false,
1326 "Square",
1327 "The output is a square curve (negative values always result in -1, and "
1328 "positive ones in 1)");
1329 RNA_def_float(ot->srna,
1330 "sthreshold",
1331 0.1,
1332 0.0,
1333 1.0,
1334 "Square Threshold",
1335 "Square only: all values with an absolute amplitude lower than that result in 0",
1336 0.01,
1337 0.1);
1338}
1339
1341
1342/* -------------------------------------------------------------------- */
1348
1349/* Evaluates the curves between each selected keyframe on each frame, and keys the value. */
1351{
1352 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1353 int filter;
1354
1355 /* filter data */
1359 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1360
1361 /* Loop through filtered data and add keys between selected keyframes on every frame. */
1362 for (bAnimListElem &ale : anim_data) {
1363 animrig::bake_fcurve_segments(static_cast<FCurve *>(ale.key_data));
1364
1365 ale.update |= ANIM_UPDATE_DEPS;
1366 }
1367
1368 ANIM_animdata_update(ac, &anim_data);
1369 ANIM_animdata_freelist(&anim_data);
1370}
1371
1372/* ------------------- */
1373
1375{
1376 bAnimContext ac;
1377
1378 /* Get editor data. */
1379 if (ANIM_animdata_get_context(C, &ac) == 0) {
1380 return OPERATOR_CANCELLED;
1381 }
1382
1383 /* Bake keyframes. */
1384 bake_graph_keys(&ac);
1385
1386 /* Set notifier that keyframes have changed. */
1388
1389 return OPERATOR_FINISHED;
1390}
1391
1393{
1394 /* Identifiers */
1395 ot->name = "Bake Keyframes";
1396 ot->idname = "GRAPH_OT_bake_keys";
1397 ot->description = "Add keyframes on every frame between the selected keyframes";
1398
1399 /* API callbacks */
1402
1403 /* Flags */
1405}
1406
1408
1409/* -------------------------------------------------------------------- */
1412
1413/* Defines for make/clear cyclic extrapolation tools. */
1414#define MAKE_CYCLIC_EXPO -1
1415#define CLEAR_CYCLIC_EXPO -2
1416
1417/* Defines for set extrapolation-type for selected keyframes tool. */
1420 "CONSTANT",
1421 0,
1422 "Constant Extrapolation",
1423 "Values on endpoint keyframes are held"},
1425 "LINEAR",
1426 0,
1427 "Linear Extrapolation",
1428 "Straight-line slope of end segments are extended past the endpoint keyframes"},
1429
1431 "MAKE_CYCLIC",
1432 0,
1433 "Make Cyclic (F-Modifier)",
1434 "Add Cycles F-Modifier if one does not exist already"},
1436 "CLEAR_CYCLIC",
1437 0,
1438 "Clear Cyclic (F-Modifier)",
1439 "Remove Cycles F-Modifier if not needed anymore"},
1440 {0, nullptr, 0, nullptr, nullptr},
1441};
1442
1443/* This function is responsible for setting extrapolation mode for keyframes. */
1444static void setexpo_graph_keys(bAnimContext *ac, short mode)
1445{
1446 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1447 int filter;
1448
1449 /* Filter data. */
1453 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1454
1455 /* Loop through setting mode per F-Curve. */
1456 for (bAnimListElem &ale : anim_data) {
1457 FCurve *fcu = static_cast<FCurve *>(ale.data);
1458
1459 if (mode >= 0) {
1460 /* Just set mode setting. */
1461 fcu->extend = eFCurve_Extend(mode);
1462
1463 ale.update |= ANIM_UPDATE_HANDLES;
1464 }
1465 else {
1466 /* Shortcuts for managing Cycles F-Modifiers to make it easier to toggle cyclic animation
1467 * without having to go through FModifier UI in Graph Editor to do so.
1468 */
1469 if (mode == MAKE_CYCLIC_EXPO) {
1470 /* Only add if one doesn't exist. */
1472 /* TODO: add some more preset versions which set different extrapolation options?
1473 * (Joshua Leung 2011) */
1475 }
1476 }
1477 else if (mode == CLEAR_CYCLIC_EXPO) {
1478 /* Remove all the modifiers fitting this description. */
1479 FModifier *fcm, *fcn = nullptr;
1480
1481 for (fcm = fcu->modifiers.first(); fcm; fcm = fcn) {
1482 fcn = fcm->next;
1483
1484 if (fcm->type == FMODIFIER_TYPE_CYCLES) {
1485 remove_fmodifier(&fcu->modifiers, fcm);
1486 }
1487 }
1488 }
1489 }
1490
1491 ale.update |= ANIM_UPDATE_DEPS;
1492 }
1493
1494 ANIM_animdata_update(ac, &anim_data);
1495 ANIM_animdata_freelist(&anim_data);
1496}
1497
1498/* ------------------- */
1499
1501{
1502 bAnimContext ac;
1503 short mode;
1504
1505 /* Get editor data. */
1506 if (ANIM_animdata_get_context(C, &ac) == 0) {
1507 return OPERATOR_CANCELLED;
1508 }
1509
1510 /* Get handle setting mode. */
1511 mode = RNA_enum_get(op->ptr, "type");
1512
1513 /* Set handle type. */
1514 setexpo_graph_keys(&ac, mode);
1515
1516 /* Set notifier that keyframe properties have changed. */
1518
1519 return OPERATOR_FINISHED;
1520}
1521
1523{
1524 /* Identifiers */
1525 ot->name = "Set F-Curve Extrapolation";
1526 ot->idname = "GRAPH_OT_extrapolation_type";
1527 ot->description = "Set extrapolation mode for selected F-Curves";
1528
1529 /* API callbacks */
1530 ot->invoke = WM_menu_invoke;
1533
1534 /* Flags */
1536
1537 /* Id-props */
1538 ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_expo_types, 0, "Type", "");
1539}
1540
1542
1543/* -------------------------------------------------------------------- */
1546
1547/* This function is responsible for setting interpolation mode for keyframes. */
1548static void setipo_graph_keys(bAnimContext *ac, short mode)
1549{
1550 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1551 int filter;
1553
1554 /* Filter data. */
1558 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1559
1560 /* Loop through setting BezTriple interpolation
1561 * NOTE: we do not supply KeyframeEditData to the looper yet.
1562 * Currently that's not necessary here.
1563 */
1564 for (bAnimListElem &ale : anim_data) {
1566 nullptr, static_cast<FCurve *>(ale.key_data), nullptr, set_cb, BKE_fcurve_handles_recalc);
1567
1568 ale.update |= ANIM_UPDATE_DEFAULT_NOHANDLES;
1569 }
1570
1571 ANIM_animdata_update(ac, &anim_data);
1572 ANIM_animdata_freelist(&anim_data);
1573}
1574
1575/* ------------------- */
1576
1578{
1579 bAnimContext ac;
1580 short mode;
1581
1582 /* Get editor data. */
1583 if (ANIM_animdata_get_context(C, &ac) == 0) {
1584 return OPERATOR_CANCELLED;
1585 }
1586
1587 /* Get handle setting mode. */
1588 mode = RNA_enum_get(op->ptr, "type");
1589
1590 /* Set handle type. */
1591 setipo_graph_keys(&ac, mode);
1592
1593 /* Set notifier that keyframe properties have changed. */
1595
1596 return OPERATOR_FINISHED;
1597}
1598
1600{
1601 /* Identifiers */
1602 ot->name = "Set Keyframe Interpolation";
1603 ot->idname = "GRAPH_OT_interpolation_type";
1604 ot->description =
1605 "Set interpolation mode for the F-Curve segments starting from the selected keyframes";
1606
1607 /* API callbacks */
1608 ot->invoke = WM_menu_invoke;
1611
1612 /* Flags */
1614
1615 /* Id-props */
1616 ot->prop = RNA_def_enum(
1617 ot->srna, "type", rna_enum_beztriple_interpolation_mode_items, 0, "Type", "");
1619}
1620
1622
1623/* -------------------------------------------------------------------- */
1626
1627static void seteasing_graph_keys(bAnimContext *ac, short mode)
1628{
1629 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1630 int filter;
1632
1633 /* Filter data. */
1637 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1638
1639 /* Loop through setting BezTriple easing.
1640 * NOTE: we do not supply KeyframeEditData to the looper yet.
1641 * Currently that's not necessary here.
1642 */
1643 for (bAnimListElem &ale : anim_data) {
1645 nullptr, static_cast<FCurve *>(ale.key_data), nullptr, set_cb, BKE_fcurve_handles_recalc);
1646
1647 ale.update |= ANIM_UPDATE_DEFAULT_NOHANDLES;
1648 }
1649
1650 ANIM_animdata_update(ac, &anim_data);
1651 ANIM_animdata_freelist(&anim_data);
1652}
1653
1655{
1656 bAnimContext ac;
1657 short mode;
1658
1659 /* Get editor data. */
1660 if (ANIM_animdata_get_context(C, &ac) == 0) {
1661 return OPERATOR_CANCELLED;
1662 }
1663
1664 /* Get handle setting mode. */
1665 mode = RNA_enum_get(op->ptr, "type");
1666
1667 /* Set handle type. */
1668 seteasing_graph_keys(&ac, mode);
1669
1670 /* Set notifier that keyframe properties have changed. */
1672
1673 return OPERATOR_FINISHED;
1674}
1675
1677{
1678 /* Identifiers */
1679 ot->name = "Set Keyframe Easing Type";
1680 ot->idname = "GRAPH_OT_easing_type";
1681 ot->description =
1682 "Set easing type for the F-Curve segments starting from the selected keyframes";
1683
1684 /* API callbacks */
1685 ot->invoke = WM_menu_invoke;
1688
1689 /* Flags */
1691
1692 /* Id-props */
1693 ot->prop = RNA_def_enum(
1694 ot->srna, "type", rna_enum_beztriple_interpolation_easing_items, 0, "Type", "");
1695}
1696
1698
1699/* -------------------------------------------------------------------- */
1702
1703/* This function is responsible for setting handle-type of selected keyframes. */
1704static void sethandles_graph_keys(bAnimContext *ac, short mode)
1705{
1706 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1707 int filter;
1708
1711
1712 /* Filter data. */
1716 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
1717
1718 /* Loop through setting flags for handles.
1719 * NOTE: we do not supply KeyframeEditData to the looper yet.
1720 * Currently that's not necessary here.
1721 */
1722 for (bAnimListElem &ale : anim_data) {
1723 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1724
1725 /* Any selected keyframes for editing? */
1726 if (ANIM_fcurve_keyframes_loop(nullptr, fcu, nullptr, sel_cb, nullptr)) {
1727 /* Change type of selected handles. */
1728 ANIM_fcurve_keyframes_loop(nullptr, fcu, nullptr, edit_cb, BKE_fcurve_handles_recalc);
1729
1730 ale.update |= ANIM_UPDATE_DEFAULT;
1731 }
1732 }
1733
1734 ANIM_animdata_update(ac, &anim_data);
1735 ANIM_animdata_freelist(&anim_data);
1736}
1737/* ------------------- */
1738
1740{
1741 bAnimContext ac;
1742 short mode;
1743
1744 /* Get editor data. */
1745 if (ANIM_animdata_get_context(C, &ac) == 0) {
1746 return OPERATOR_CANCELLED;
1747 }
1748
1749 /* Get handle setting mode. */
1750 mode = RNA_enum_get(op->ptr, "type");
1751
1752 /* Set handle type. */
1753 sethandles_graph_keys(&ac, mode);
1754
1755 /* Set notifier that keyframe properties have changed. */
1757
1758 return OPERATOR_FINISHED;
1759}
1760
1762{
1763 /* Identifiers */
1764 ot->name = "Set Keyframe Handle Type";
1765 ot->idname = "GRAPH_OT_handle_type";
1766 ot->description = "Set type of handle for selected keyframes";
1767
1768 /* API callbacks */
1769 ot->invoke = WM_menu_invoke;
1772
1773 /* Flags */
1775
1776 /* Id-props */
1777 ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_keyframe_handle_type_items, 0, "Type", "");
1778}
1779
1781
1782/* -------------------------------------------------------------------- */
1790
1791/* Set of three euler-rotation F-Curves. */
1802
1803static bool keyframe_time_differs(BezTriple *keyframes[3])
1804{
1805 const float precision = 1e-5;
1806 return fabs(keyframes[0]->vec[1][0] - keyframes[1]->vec[1][0]) > precision ||
1807 fabs(keyframes[1]->vec[1][0] - keyframes[2]->vec[1][0]) > precision ||
1808 fabs(keyframes[0]->vec[1][0] - keyframes[2]->vec[1][0]) > precision;
1809}
1810
1811/* Find groups of `rotation_euler` channels. */
1812static ListBaseT<tEulerFilter> euler_filter_group_channels(
1813 const ListBaseT<bAnimListElem> *anim_data, ReportList *reports, int *r_num_groups)
1814{
1815 ListBaseT<tEulerFilter> euler_groups = {nullptr, nullptr};
1816 tEulerFilter *euf = nullptr;
1817 *r_num_groups = 0;
1818
1819 for (bAnimListElem &ale : *anim_data) {
1820 FCurve *const fcu = static_cast<FCurve *>(ale.data);
1821
1822 /* Check if this is an appropriate F-Curve:
1823 * - Only rotation curves.
1824 * - For pose-channel curves, make sure we're only using the euler curves.
1825 */
1826 if (strstr(fcu->rna_path().c_str(), "rotation_euler") == nullptr) {
1827 continue;
1828 }
1829 if (ELEM(fcu->array_index, 0, 1, 2) == 0) {
1830 BKE_reportf(reports,
1832 "Euler Rotation F-Curve has invalid index (ID='%s', Path='%s', Index=%d)",
1833 (ale.id) ? ale.id->name : RPT_("<No ID>"),
1834 fcu->rna_path().c_str(),
1835 fcu->array_index);
1836 continue;
1837 }
1838
1839 /* Assume that this animation channel will be touched by the Euler filter. Doing this here
1840 * saves another loop over the animation data. */
1841 ale.update |= ANIM_UPDATE_DEFAULT;
1842
1843 /* Optimization: assume that XYZ curves will always be stored consecutively,
1844 * so if the paths or the ID's don't match up, then a curve needs to be added
1845 * to a new group.
1846 */
1847 if ((euf) && (euf->id == ale.id) && STREQ(euf->rna_path, fcu->rna_path().c_str())) {
1848 /* This should be fine to add to the existing group then. */
1849 euf->fcurves[fcu->array_index] = fcu;
1850 continue;
1851 }
1852
1853 /* Just add to a new block. */
1854 euf = MEM_new_zeroed<tEulerFilter>("tEulerFilter");
1855 BLI_addtail(&euler_groups, euf);
1856 ++*r_num_groups;
1857
1858 euf->id = ale.id;
1859 /* This should be safe, since we're only using it for a short time. */
1860 euf->rna_path = fcu->rna_path().c_str();
1861 euf->fcurves[fcu->array_index] = fcu;
1862 }
1863
1864 return euler_groups;
1865}
1866
1867/* Perform discontinuity filter based on conversion to matrix and back.
1868 * Return true if the curves were filtered (which may have been a no-op), false otherwise. */
1870{
1871 /* Sanity check: ensure that there are enough F-Curves to work on in this group. */
1872 if (ELEM(nullptr, euf->fcurves[0], euf->fcurves[1], euf->fcurves[2])) {
1873 /* Report which components are missing. */
1874 BKE_reportf(reports,
1875 RPT_INFO,
1876 "Missing %s%s%s component(s) of euler rotation for ID='%s' and RNA-Path='%s'",
1877 (euf->fcurves[0] == nullptr) ? "X" : "",
1878 (euf->fcurves[1] == nullptr) ? "Y" : "",
1879 (euf->fcurves[2] == nullptr) ? "Z" : "",
1880 euf->id->name,
1881 euf->rna_path);
1882 return false;
1883 }
1884
1885 FCurve *fcu_rot_x = euf->fcurves[0];
1886 FCurve *fcu_rot_y = euf->fcurves[1];
1887 FCurve *fcu_rot_z = euf->fcurves[2];
1888 if (fcu_rot_x->totvert != fcu_rot_y->totvert || fcu_rot_y->totvert != fcu_rot_z->totvert) {
1889 BKE_reportf(reports,
1890 RPT_INFO,
1891 "XYZ rotations not equally keyed for ID='%s' and RNA-Path='%s'",
1892 euf->id->name,
1893 euf->rna_path);
1894 return false;
1895 }
1896
1897 if (fcu_rot_x->totvert < 2) {
1898 /* Empty curves and single keyframes are trivially "filtered". */
1899 return false;
1900 }
1901
1902 float filtered_euler[3] = {
1903 fcu_rot_x->bezt[0].vec[1][1],
1904 fcu_rot_y->bezt[0].vec[1][1],
1905 fcu_rot_z->bezt[0].vec[1][1],
1906 };
1907
1908 for (int keyframe_index = 1; keyframe_index < fcu_rot_x->totvert; ++keyframe_index) {
1909 BezTriple *keyframes[3] = {
1910 &fcu_rot_x->bezt[keyframe_index],
1911 &fcu_rot_y->bezt[keyframe_index],
1912 &fcu_rot_z->bezt[keyframe_index],
1913 };
1914
1915 if (keyframe_time_differs(keyframes)) {
1916 /* The X-coordinates of the keyframes are different, so we cannot correct this key. */
1917 continue;
1918 }
1919
1920 const float unfiltered_euler[3] = {
1921 keyframes[0]->vec[1][1],
1922 keyframes[1]->vec[1][1],
1923 keyframes[2]->vec[1][1],
1924 };
1925
1926 /* The conversion back from matrix to Euler angles actually performs the filtering. */
1927 float matrix[3][3];
1928 eul_to_mat3(matrix, unfiltered_euler);
1929 mat3_normalized_to_compatible_eul(filtered_euler, filtered_euler, matrix);
1930
1931 /* TODO(Sybren): it might be a nice touch to compare `filtered_euler` with `unfiltered_euler`,
1932 * to see if there was actually a change. This could improve reporting for the artist. */
1933
1934 BKE_fcurve_keyframe_move_value_with_handles(keyframes[0], filtered_euler[0]);
1935 BKE_fcurve_keyframe_move_value_with_handles(keyframes[1], filtered_euler[1]);
1936 BKE_fcurve_keyframe_move_value_with_handles(keyframes[2], filtered_euler[2]);
1937 }
1938
1939 return true;
1940}
1941
1942/* Remove 360-degree flips from a single FCurve.
1943 * Return true if the curve was modified, false otherwise. */
1945{
1946 /* Simple method: just treat any difference between keys of greater than 180 degrees as being a
1947 * flip. */
1948 BezTriple *bezt, *prev;
1949 uint i;
1950
1951 /* Skip if not enough verts to do a decent analysis. */
1952 if (fcu->totvert <= 2) {
1953 return false;
1954 }
1955
1956 /* Skip baked FCurves. */
1957 if (fcu->bezt == nullptr) {
1958 return false;
1959 }
1960
1961 /* `prev` follows bezt, bezt = "current" point to be fixed. */
1962 /* Our method depends on determining a "difference" from the previous vert. */
1963 bool is_modified = false;
1964 for (i = 1, prev = fcu->bezt, bezt = fcu->bezt + 1; i < fcu->totvert; i++, prev = bezt++) {
1965 const float sign = (prev->vec[1][1] > bezt->vec[1][1]) ? 1.0f : -1.0f;
1966
1967 /* >= 180 degree flip? */
1968 if ((sign * (prev->vec[1][1] - bezt->vec[1][1])) < float(M_PI)) {
1969 continue;
1970 }
1971
1972 /* 360 degrees to add/subtract frame value until difference
1973 * is acceptably small that there's no more flip. */
1974 const float fac = sign * 2.0f * float(M_PI);
1975
1976 while ((sign * (prev->vec[1][1] - bezt->vec[1][1])) >= float(M_PI)) {
1977 bezt->vec[0][1] += fac;
1978 bezt->vec[1][1] += fac;
1979 bezt->vec[2][1] += fac;
1980 }
1981
1982 is_modified = true;
1983 }
1984
1985 return is_modified;
1986}
1987
1988static void euler_filter_perform_filter(ListBaseT<tEulerFilter> *eulers,
1989 ReportList *reports,
1990 int *r_curves_filtered,
1991 int *r_curves_seen)
1992{
1993 *r_curves_filtered = 0;
1994 *r_curves_seen = 0;
1995
1996 for (tEulerFilter &euf : *eulers) {
1997 int curves_filtered_this_group = 0;
1998
1999 if (euler_filter_multi_channel(&euf, reports)) {
2000 curves_filtered_this_group = 3;
2001 }
2002
2003 for (int channel_index = 0; channel_index < 3; channel_index++) {
2004 FCurve *fcu = euf.fcurves[channel_index];
2005 if (fcu == nullptr) {
2006 continue;
2007 }
2008 ++*r_curves_seen;
2009
2010 if (euler_filter_single_channel(fcu)) {
2011 ++curves_filtered_this_group;
2012 }
2013 }
2014
2015 *r_curves_filtered += min_ii(3, curves_filtered_this_group);
2016 }
2017}
2018
2020{
2021 /* Get editor data. */
2022 bAnimContext ac;
2023 if (ANIM_animdata_get_context(C, &ac) == 0) {
2024 return OPERATOR_CANCELLED;
2025 }
2026
2027 /* The process is done in two passes:
2028 * 1) Sets of three related rotation curves are identified from the selected channels,
2029 * and are stored as a single 'operation unit' for the next step.
2030 * 2) Each set of three F-Curves is processed for each keyframe, with the values being
2031 * processed as necessary.
2032 */
2033
2034 /* Step 1: extract only the rotation f-curves. */
2037 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2039 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2040
2041 int groups = 0;
2042 ListBaseT<tEulerFilter> eulers = euler_filter_group_channels(&anim_data, op->reports, &groups);
2043 BLI_assert(eulers.count() == groups);
2044
2045 if (groups == 0) {
2046 ANIM_animdata_freelist(&anim_data);
2047 BKE_report(op->reports, RPT_WARNING, "No Euler Rotation F-Curves to fix up");
2048 return OPERATOR_CANCELLED;
2049 }
2050
2051 /* Step 2: go through each set of curves, processing the values at each keyframe.
2052 * - It is assumed that there must be a full set of keyframes at each keyframe position.
2053 */
2054 int curves_filtered;
2055 int curves_seen;
2056 euler_filter_perform_filter(&eulers, op->reports, &curves_filtered, &curves_seen);
2057
2058 eulers.free_no_destruct();
2059 ANIM_animdata_update(&ac, &anim_data);
2060 ANIM_animdata_freelist(&anim_data);
2061
2062 if (curves_filtered == 0) {
2063 if (curves_seen < 3) {
2064 /* Showing the entire error message makes no sense when the artist is only trying to filter
2065 * one or two curves. */
2066 BKE_report(op->reports, RPT_WARNING, "No Euler Rotations could be corrected");
2067 }
2068 else {
2069 BKE_report(op->reports,
2070 RPT_ERROR,
2071 "No Euler Rotations could be corrected, ensure each rotation has keys for all "
2072 "components, "
2073 "and that F-Curves for these are in consecutive XYZ order and selected");
2074 }
2075 return OPERATOR_CANCELLED;
2076 }
2077
2078 if (curves_filtered != curves_seen) {
2079 BLI_assert(curves_filtered < curves_seen);
2080 BKE_reportf(op->reports,
2081 RPT_INFO,
2082 "%d of %d rotation channels were filtered (see the Info window for details)",
2083 curves_filtered,
2084 curves_seen);
2085 }
2086 else if (curves_seen == 1) {
2087 BKE_report(op->reports, RPT_INFO, "The rotation channel was filtered");
2088 }
2089 else {
2090 BKE_reportf(op->reports, RPT_INFO, "All %d rotation channels were filtered", curves_seen);
2091 }
2092
2093 /* Set notifier that keyframes have changed. */
2095
2096 /* Done at last. */
2097 return OPERATOR_FINISHED;
2098}
2099
2101{
2102 /* Identifiers */
2103 ot->name = "Euler Discontinuity Filter";
2104 ot->idname = "GRAPH_OT_euler_filter";
2105 ot->description =
2106 "Fix large jumps and flips in the selected "
2107 "Euler Rotation F-Curves arising from rotation "
2108 "values being clipped when baking physics";
2109
2110 /* API callbacks */
2113
2114 /* Flags */
2116}
2117
2119
2120/* -------------------------------------------------------------------- */
2123
2125{
2126 /* Prevent changes during render. */
2127 if (G.is_rendering) {
2128 return false;
2129 }
2130
2132}
2133
2135{
2136 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2137 int filter;
2138 KeyframeEditData ked;
2139
2140 /* Init edit data. */
2141 memset(&ked, 0, sizeof(KeyframeEditData));
2142
2143 /* Loop over action data, averaging values. */
2147 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2148
2149 for (bAnimListElem &ale : anim_data) {
2150 short mapping_flag = ANIM_get_normalization_flags(ac->sl);
2151 KeyframeEditData current_ked;
2152 float offset;
2153 float unit_scale = ANIM_unit_mapping_get_factor(ac->scene,
2154 ale.id,
2155 static_cast<FCurve *>(ale.key_data),
2156 mapping_flag | ANIM_UNITCONV_ONLYKEYS,
2157 &offset);
2158
2159 memset(&current_ked, 0, sizeof(current_ked));
2160
2162 &ale, static_cast<FCurve *>(ale.key_data), false, true);
2164 &current_ked, static_cast<FCurve *>(ale.key_data), nullptr, bezt_calc_average, nullptr);
2165 ANIM_nla_mapping_apply_if_needed_fcurve(&ale, static_cast<FCurve *>(ale.key_data), true, true);
2166
2167 if (current_ked.i1 == 0) {
2168 continue;
2169 }
2170
2171 ked.f1 += current_ked.f1;
2172 ked.i1 += current_ked.i1;
2173 ked.f2 += (current_ked.f2 + offset * current_ked.i1) * unit_scale;
2174 ked.i2 += current_ked.i2;
2175 }
2176
2177 ANIM_animdata_freelist(&anim_data);
2178
2179 return ked;
2180}
2181
2182/* Snap current-frame indicator to 'average time' of selected keyframe. */
2184{
2185 bAnimContext ac;
2186
2187 /* Get editor data. */
2188 if (ANIM_animdata_get_context(C, &ac) == 0) {
2189 return OPERATOR_CANCELLED;
2190 }
2191
2192 const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
2193 const float sum_time = keyframe_sum.f1;
2194 const float sum_value = keyframe_sum.f2;
2195 const int num_keyframes = keyframe_sum.i1;
2196
2197 if (num_keyframes == 0) {
2198 return OPERATOR_FINISHED;
2199 }
2200
2201 /* Set the new current frame and cursor values, based on the average time and value. */
2202 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac.sl);
2203 Scene *scene = ac.scene;
2204
2205 /* Take the average values, rounding to the nearest int as necessary for int results. */
2206 if (sipo->mode == SIPO_MODE_DRIVERS) {
2207 /* Drivers Mode - Affects cursor (float) */
2208 sipo->cursorTime = sum_time / float(num_keyframes);
2209 }
2210 else {
2211 /* Animation Mode - Affects current frame (int) */
2212 scene->r.cfra = round_fl_to_int(sum_time / num_keyframes);
2213 scene->r.subframe = 0.0f;
2214 }
2215 sipo->cursorVal = sum_value / float(num_keyframes);
2216
2217 /* Set notifier that things have changed. */
2219
2220 return OPERATOR_FINISHED;
2221}
2222
2224{
2225 /* Identifiers */
2226 ot->name = "Jump to Keyframes";
2227 ot->idname = "GRAPH_OT_frame_jump";
2228 ot->description = "Place the cursor on the midpoint of selected keyframes";
2229
2230 /* API callbacks */
2233
2234 /* Flags */
2236}
2237
2239
2240/* -------------------------------------------------------------------- */
2243
2245{
2246 BKE_report(op->reports, RPT_WARNING, "Deprecated operator, use screen.keyframe_jump instead");
2247 /* The op->ptr can be passed to the operator because it has an identically named property. */
2248 return WM_operator_name_call(
2249 C, "SCREEN_OT_keyframe_jump", wm::OpCallContext::InvokeDefault, op->ptr, nullptr);
2250}
2251
2253{
2254 ot->name = "Jump to Keyframe";
2255 ot->description = "Jump to previous/next keyframe";
2256 ot->idname = "GRAPH_OT_keyframe_jump";
2257
2259
2262 ot->undo_group = "Frame Change";
2263
2264 /* properties */
2265 RNA_def_boolean(ot->srna, "next", true, "Next Keyframe", "");
2266}
2267
2269
2270/* -------------------------------------------------------------------- */
2273
2274/* snap 2D cursor value to the average value of selected keyframe */
2276{
2277 bAnimContext ac;
2278
2279 if (ANIM_animdata_get_context(C, &ac) == 0) {
2280 return OPERATOR_CANCELLED;
2281 }
2282
2283 const KeyframeEditData keyframe_sum = sum_selected_keyframes(&ac);
2284 const float sum_value = keyframe_sum.f2;
2285 const int num_keyframes = keyframe_sum.i1;
2286
2287 if (num_keyframes == 0) {
2288 return OPERATOR_FINISHED;
2289 }
2290
2291 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac.sl);
2292 sipo->cursorVal = sum_value / float(num_keyframes);
2293 // WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
2295
2296 return OPERATOR_FINISHED;
2297}
2298
2300{
2301 /* Identifiers. */
2302 ot->name = "Snap Cursor Value to Selected";
2303 ot->idname = "GRAPH_OT_snap_cursor_value";
2304 ot->description = "Place the cursor value on the average value of selected keyframes";
2305
2306 /* API callbacks. */
2309
2310 /* Flags */
2312}
2313
2315
2316/* -------------------------------------------------------------------- */
2319
2320/* Defines for snap keyframes tool. */
2323 "CFRA",
2324 0,
2325 "Selection to Current Frame",
2326 "Snap selected keyframes to the current frame"},
2328 "VALUE",
2329 0,
2330 "Selection to Cursor Value",
2331 "Set values of selected keyframes to the cursor value (Y/Horizontal component)"},
2333 "NEAREST_FRAME",
2334 0,
2335 "Selection to Nearest Frame",
2336 "Snap selected keyframes to the nearest (whole) frame (use to fix accidental subframe "
2337 "offsets)"},
2339 "NEAREST_SECOND",
2340 0,
2341 "Selection to Nearest Second",
2342 "Snap selected keyframes to the nearest second"},
2344 "NEAREST_MARKER",
2345 0,
2346 "Selection to Nearest Marker",
2347 "Snap selected keyframes to the nearest marker"},
2349 "HORIZONTAL",
2350 0,
2351 "Flatten Handles",
2352 "Flatten handles for a smoother transition"},
2353 {0, nullptr, 0, nullptr, nullptr},
2354};
2355
2356/* This function is responsible for snapping keyframes to frame-times. */
2357static void snap_graph_keys(bAnimContext *ac, short mode)
2358{
2359 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2360 int filter;
2361
2362 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac->sl);
2363 KeyframeEditData ked;
2364 KeyframeEditFunc edit_cb;
2365 float cursor_value = 0.0f;
2366
2367 /* Filter data. */
2371 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2372
2373 /* Init custom data for iterating over keyframes. */
2374 memset(&ked, 0, sizeof(KeyframeEditData));
2375 ked.scene = ac->scene;
2376 if (mode == GRAPHKEYS_SNAP_NEAREST_MARKER) {
2377 ked.time_marker_list.first_ = (ac->markers) ? ac->markers->first_ : nullptr;
2378 ked.time_marker_list.last_ = (ac->markers) ? ac->markers->last() : nullptr;
2379 }
2380 else if (mode == GRAPHKEYS_SNAP_VALUE) {
2381 cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
2382 }
2383 else if (mode == GRAPHKEYS_SNAP_CFRA) {
2384 /* In drivers mode, use the cursor value instead
2385 * (We need to use a different callback for that though)
2386 */
2387 if (sipo->mode == SIPO_MODE_DRIVERS) {
2388 ked.f1 = sipo->cursorTime;
2389 mode = SNAP_KEYS_TIME;
2390 }
2391 }
2392
2393 /* Get beztriple editing callbacks. */
2394 edit_cb = ANIM_editkeyframes_snap(mode);
2395
2396 /* Snap keyframes. */
2397 const bool use_handle = (sipo->flag & SIPO_NOHANDLES) == 0;
2398 for (bAnimListElem &ale : anim_data) {
2399 /* Normalize cursor value (for normalized F-Curves display). */
2400 if (mode == GRAPHKEYS_SNAP_VALUE) {
2401 short mapping_flag = ANIM_get_normalization_flags(ac->sl);
2402 float offset;
2403 float unit_scale = ANIM_unit_mapping_get_factor(
2404 ac->scene, ale.id, static_cast<FCurve *>(ale.key_data), mapping_flag, &offset);
2405
2406 ked.f1 = (cursor_value / unit_scale) - offset;
2407 }
2408
2409 /* Perform snapping. */
2411 &ale, static_cast<FCurve *>(ale.key_data), false, false);
2413 &ked, static_cast<FCurve *>(ale.key_data), nullptr, edit_cb, BKE_fcurve_handles_recalc);
2415 static_cast<FCurve *>(ale.key_data), BEZT_FLAG_TEMP_TAG, use_handle);
2417 &ale, static_cast<FCurve *>(ale.key_data), true, false);
2418
2419 ale.update |= ANIM_UPDATE_DEFAULT;
2420 }
2421
2422 ANIM_animdata_update(ac, &anim_data);
2423 ANIM_animdata_freelist(&anim_data);
2424}
2425
2426/* ------------------- */
2427
2429{
2430 bAnimContext ac;
2431 short mode;
2432
2433 /* Get editor data. */
2434 if (ANIM_animdata_get_context(C, &ac) == 0) {
2435 return OPERATOR_CANCELLED;
2436 }
2437
2438 /* Get snapping mode. */
2439 mode = RNA_enum_get(op->ptr, "type");
2440
2441 /* Snap keyframes. */
2442 snap_graph_keys(&ac, mode);
2443
2444 /* Set notifier that keyframes have changed. */
2446
2447 return OPERATOR_FINISHED;
2448}
2449
2451{
2452 bAnimContext ac;
2453 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2454
2455 /* Get editor data. */
2456 if (ANIM_animdata_get_context(C, &ac) == 0) {
2457 return false;
2458 }
2459
2460 /* Filter data. */
2464 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2465
2466 /* Check if any of the visible and editable f-curves have at least one selected control point. */
2467 bool has_selected_control_points = false;
2468 for (bAnimListElem &ale : anim_data) {
2469 const FCurve *fcu = static_cast<const FCurve *>(ale.key_data);
2470 if (fcu && BKE_fcurve_has_selected_control_points(*fcu)) {
2471 has_selected_control_points = true;
2472 break;
2473 }
2474 }
2475
2476 ANIM_animdata_freelist(&anim_data);
2477
2478 return has_selected_control_points;
2479}
2480
2482 wmOperator *op,
2483 const wmEvent *event)
2484{
2486 BKE_report(op->reports, RPT_ERROR, "No control points are selected");
2487 return OPERATOR_CANCELLED;
2488 }
2489
2490 return WM_menu_invoke(C, op, event);
2491}
2492
2494{
2495 /* Identifiers */
2496 ot->name = "Snap Keys";
2497 ot->idname = "GRAPH_OT_snap";
2498 ot->description = "Snap selected keyframes to the chosen times/values";
2499
2500 /* API callbacks */
2504
2505 /* Flags */
2507
2508 /* Id-props */
2509 ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_snap_types, 0, "Type", "");
2510}
2511
2513
2514/* -------------------------------------------------------------------- */
2517
2518/* Defines for equalize handles tool. */
2520 {GRAPHKEYS_EQUALIZE_LEFT, "LEFT", 0, "Left", "Equalize selected keyframes' left handles"},
2521 {GRAPHKEYS_EQUALIZE_RIGHT, "RIGHT", 0, "Right", "Equalize selected keyframes' right handles"},
2522 {GRAPHKEYS_EQUALIZE_BOTH, "BOTH", 0, "Both", "Equalize both of a keyframe's handles"},
2523 {0, nullptr, 0, nullptr, nullptr},
2524};
2525
2526/* ------------------- */
2527
2528/* Equalize selected keyframes' bezier handles. */
2529static void equalize_graph_keys(bAnimContext *ac, int mode, float handle_length, bool flatten)
2530{
2531 /* Filter data. */
2534 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2536 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2537
2538 /* Equalize keyframes. */
2539 for (bAnimListElem &ale : anim_data) {
2540 ANIM_fcurve_equalize_keyframes_loop(static_cast<FCurve *>(ale.key_data),
2542 handle_length,
2543 flatten);
2544 ale.update |= ANIM_UPDATE_DEFAULT;
2545 }
2546
2547 ANIM_animdata_update(ac, &anim_data);
2548 ANIM_animdata_freelist(&anim_data);
2549}
2550
2552{
2553 bAnimContext ac;
2554
2555 /* Get editor data. */
2556 if (ANIM_animdata_get_context(C, &ac) == 0) {
2557 return OPERATOR_CANCELLED;
2558 }
2559
2560 /* Get equalize mode. */
2561 int mode = RNA_enum_get(op->ptr, "side");
2562 float handle_length = RNA_float_get(op->ptr, "handle_length");
2563 bool flatten = RNA_boolean_get(op->ptr, "flatten");
2564
2565 /* Equalize graph keyframes. */
2566 equalize_graph_keys(&ac, mode, handle_length, flatten);
2567
2569
2570 return OPERATOR_FINISHED;
2571}
2572
2574{
2575 /* Identifiers */
2576 ot->name = "Equalize Handles";
2577 ot->idname = "GRAPH_OT_equalize_handles";
2578 ot->description =
2579 "Ensure selected keyframes' handles have equal length, optionally making them horizontal. "
2580 "Automatic, Automatic Clamped, or Vector handle types will be converted to Aligned";
2581 /* API callbacks */
2585
2586 /* Flags */
2588
2589 /* Properties */
2590 ot->prop = RNA_def_enum(ot->srna,
2591 "side",
2593 0,
2594 "Side",
2595 "Side of the keyframes' Bézier handles to affect");
2596 RNA_def_float(ot->srna,
2597 "handle_length",
2598 5.0f,
2599 0.1f,
2600 FLT_MAX,
2601 "Handle Length",
2602 "Length to make selected keyframes' Bézier handles",
2603 1.0f,
2604 50.0f);
2606 ot->srna,
2607 "flatten",
2608 false,
2609 "Flatten",
2610 "Make the values of the selected keyframes' handles the same as their respective keyframes");
2611}
2612
2614
2615/* -------------------------------------------------------------------- */
2618
2619/* Defines for mirror keyframes tool. */
2622 "CFRA",
2623 0,
2624 "By Times Over Current Frame",
2625 "Flip times of selected keyframes using the current frame as the mirror line"},
2627 "MARKER",
2628 0,
2629 "By Times Over First Selected Marker",
2630 "Flip times of selected keyframes using the first selected marker as the reference point"},
2632 "YAXIS",
2633 0,
2634 "By Times Over Zero Time",
2635 "Flip times of selected keyframes, effectively reversing the order they appear in"},
2638 "VALUE",
2639 0,
2640 "By Values Over Cursor Value",
2641 "Flip values of selected keyframes using the cursor value (Y/Horizontal component) as the "
2642 "mirror line"},
2644 "XAXIS",
2645 0,
2646 "By Values Over Zero Value",
2647 "Flip values of selected keyframes (i.e. negative values become positive, and vice versa)"},
2648 {0, nullptr, 0, nullptr, nullptr},
2649};
2650
2651/* This function is responsible for mirroring keyframes. */
2652static void mirror_graph_keys(bAnimContext *ac, short mode)
2653{
2654 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2655 int filter;
2656
2657 SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(ac->sl);
2658 KeyframeEditData ked;
2659 KeyframeEditFunc edit_cb;
2660 float cursor_value = 0.0f;
2661
2662 /* Init custom data for looping over keyframes. */
2663 memset(&ked, 0, sizeof(KeyframeEditData));
2664 ked.scene = ac->scene;
2665
2666 /* Store mode-specific custom data... */
2667 if (mode == GRAPHKEYS_MIRROR_MARKER) {
2668 TimeMarker *marker = nullptr;
2669
2670 /* Find first selected marker. */
2672
2673 /* Store marker's time (if available). */
2674 if (marker) {
2675 ked.f1 = float(marker->frame);
2676 }
2677 else {
2678 return;
2679 }
2680 }
2681 else if (mode == GRAPHKEYS_MIRROR_VALUE) {
2682 cursor_value = (sipo) ? sipo->cursorVal : 0.0f;
2683 }
2684 else if (mode == GRAPHKEYS_MIRROR_CFRA) {
2685 /* In drivers mode, use the cursor value instead
2686 * (We need to use a different callback for that though)
2687 */
2688 if (sipo->mode == SIPO_MODE_DRIVERS) {
2689 ked.f1 = sipo->cursorTime;
2690 mode = MIRROR_KEYS_TIME;
2691 }
2692 }
2693
2694 /* Get beztriple editing callbacks. */
2695 edit_cb = ANIM_editkeyframes_mirror(mode);
2696
2697 /* Filter data. */
2701 ac, &anim_data, eAnimFilter_Flags(filter), ac->data, eAnimCont_Types(ac->datatype));
2702
2703 /* Mirror keyframes. */
2704 for (bAnimListElem &ale : anim_data) {
2705 /* Apply unit corrections. */
2706 if (mode == GRAPHKEYS_MIRROR_VALUE) {
2707 short mapping_flag = ANIM_get_normalization_flags(ac->sl);
2708 float offset;
2709 float unit_scale = ANIM_unit_mapping_get_factor(ac->scene,
2710 ale.id,
2711 static_cast<FCurve *>(ale.key_data),
2712 mapping_flag | ANIM_UNITCONV_ONLYKEYS,
2713 &offset);
2714
2715 ked.f1 = (cursor_value - offset) / unit_scale;
2716 }
2717
2718 /* Perform actual mirroring. */
2720 &ale, static_cast<FCurve *>(ale.key_data), false, false);
2722 &ked, static_cast<FCurve *>(ale.key_data), nullptr, edit_cb, BKE_fcurve_handles_recalc);
2724 &ale, static_cast<FCurve *>(ale.key_data), true, false);
2725
2726 ale.update |= ANIM_UPDATE_DEFAULT;
2727 }
2728
2729 ANIM_animdata_update(ac, &anim_data);
2730 ANIM_animdata_freelist(&anim_data);
2731}
2732
2733/* ------------------- */
2734
2736{
2737 bAnimContext ac;
2738 short mode;
2739
2740 /* Get editor data. */
2741 if (ANIM_animdata_get_context(C, &ac) == 0) {
2742 return OPERATOR_CANCELLED;
2743 }
2744
2745 /* Get mirroring mode. */
2746 mode = RNA_enum_get(op->ptr, "type");
2747
2748 /* Mirror keyframes. */
2749 mirror_graph_keys(&ac, mode);
2750
2751 /* Set notifier that keyframes have changed. */
2753
2754 return OPERATOR_FINISHED;
2755}
2756
2758{
2759 /* Identifiers */
2760 ot->name = "Mirror Keys";
2761 ot->idname = "GRAPH_OT_mirror";
2762 ot->description = "Flip selected keyframes over the selected mirror line";
2763
2764 /* API callbacks */
2765 ot->invoke = WM_menu_invoke;
2768
2769 /* Flags */
2771
2772 /* Id-props */
2773 ot->prop = RNA_def_enum(ot->srna, "type", prop_graphkeys_mirror_types, 0, "Type", "");
2774}
2775
2777
2778/* -------------------------------------------------------------------- */
2781
2783{
2784 bAnimContext ac;
2785 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2786 int filter;
2787
2788 /* Get editor data. */
2789 if (ANIM_animdata_get_context(C, &ac) == 0) {
2790 return OPERATOR_CANCELLED;
2791 }
2792
2793 /* Filter data. */
2797 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2798
2799 /* Smooth keyframes. */
2800 for (bAnimListElem &ale : anim_data) {
2801 /* For now, we can only smooth by flattening handles AND smoothing curve values.
2802 * Perhaps the mode argument could be removed, as that functionality is offered through
2803 * Snap->Flatten Handles anyway.
2804 */
2805 smooth_fcurve(static_cast<FCurve *>(ale.key_data));
2806
2807 ale.update |= ANIM_UPDATE_DEFAULT;
2808 }
2809
2810 ANIM_animdata_update(&ac, &anim_data);
2811 ANIM_animdata_freelist(&anim_data);
2812
2813 /* Set notifier that keyframes have changed. */
2815
2816 return OPERATOR_FINISHED;
2817}
2818
2820{
2821 /* Identifiers */
2822 ot->name = "Smooth Keys";
2823 ot->idname = "GRAPH_OT_smooth";
2824 ot->description = "Apply weighted moving means to make selected F-Curves less bumpy";
2825
2826 /* API callbacks */
2829
2830 /* Flags */
2832}
2833
2835
2836/* -------------------------------------------------------------------- */
2839
2841 PointerRNA * /*ptr*/,
2842 PropertyRNA * /*prop*/,
2843 bool *r_free)
2844{
2845 EnumPropertyItem *item = nullptr;
2846 int totitem = 0;
2847 int i = 0;
2848
2849 if (C == nullptr) {
2851 }
2852
2853 /* Start from 1 to skip the 'Invalid' modifier type. */
2854 for (i = 1; i < FMODIFIER_NUM_TYPES; i++) {
2856 int index;
2857
2858 /* Check if modifier is valid for this context. */
2859 if (fmi == nullptr) {
2860 continue;
2861 }
2862
2864 if (index != -1) { /* Not all types are implemented yet... */
2866 }
2867 }
2868
2869 RNA_enum_item_end(&item, &totitem);
2870 *r_free = true;
2871
2872 return item;
2873}
2874
2876{
2877 bAnimContext ac;
2878 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2879 int filter;
2880 short type;
2881
2882 /* Get editor data. */
2883 if (ANIM_animdata_get_context(C, &ac) == 0) {
2884 return OPERATOR_CANCELLED;
2885 }
2886
2887 /* Get type of modifier to add. */
2888 type = RNA_enum_get(op->ptr, "type");
2889
2890 /* Filter data. */
2893 if (RNA_boolean_get(op->ptr, "only_active")) {
2894 /* FIXME: enforce in this case only a single channel to get handled? */
2896 }
2897 else {
2899 }
2901 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
2902
2903 /* Add f-modifier to each curve. */
2904 for (bAnimListElem &ale : anim_data) {
2905 FCurve *fcu = static_cast<FCurve *>(ale.data);
2906 FModifier *fcm;
2907
2908 /* Add F-Modifier of specified type to active F-Curve, and make it the active one. */
2909 fcm = add_fmodifier(&fcu->modifiers, type, fcu);
2910 if (fcm) {
2911 set_active_fmodifier(&fcu->modifiers, fcm);
2912 }
2913 else {
2914 BKE_report(op->reports, RPT_ERROR, "Modifier could not be added (see console for details)");
2915 break;
2916 }
2917
2918 ale.update |= ANIM_UPDATE_DEPS;
2919 }
2920
2921 ANIM_animdata_update(&ac, &anim_data);
2922 ANIM_animdata_freelist(&anim_data);
2923
2924 /* Set notifier that things have changed. */
2926
2927 return OPERATOR_FINISHED;
2928}
2929
2931{
2932 PropertyRNA *prop;
2933
2934 /* Identifiers */
2935 ot->name = "Add F-Curve Modifier";
2936 ot->idname = "GRAPH_OT_fmodifier_add";
2937 ot->description = "Add F-Modifier to the active/selected F-Curves";
2938
2939 /* API callbacks */
2940 ot->invoke = WM_menu_invoke;
2943
2944 /* Flags */
2946
2947 /* Id-props */
2948 prop = RNA_def_enum(ot->srna, "type", rna_enum_fmodifier_type_items, 0, "Type", "");
2951 ot->prop = prop;
2952
2954 ot->srna, "only_active", false, "Only Active", "Only add F-Modifier to active F-Curve");
2955}
2956
2958
2959/* -------------------------------------------------------------------- */
2962
2963enum class RemovalMode { ALL = 0, FIRST = 1, TYPE = 2 };
2964
2966{
2967 bAnimContext ac;
2968 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
2969
2970 const eFModifier_Types type = static_cast<eFModifier_Types>(RNA_enum_get(op->ptr, "type"));
2971
2972 /* Get editor data. */
2973 if (ANIM_animdata_get_context(C, &ac) == 0) {
2974 return OPERATOR_CANCELLED;
2975 }
2976
2977 /* Filter data. */
2980
2981 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
2982
2983 const RemovalMode mode = RemovalMode(RNA_enum_get(op->ptr, "mode"));
2984 int num_fmods_deleted = 0;
2985 int num_fcurves_affected = 0;
2986
2987 /* Collect the F-Mods to delete. */
2988 for (bAnimListElem &ale : anim_data) {
2989 FCurve *fcu = static_cast<FCurve *>(ale.data);
2990
2991 /* Keep track of the modifiers to delete, so that we don't delete
2992 * them while looping over them. */
2993 Vector<FModifier *> fmods_to_delete;
2994
2995 for (FModifier &fcm : fcu->modifiers) {
2996 if (mode == RemovalMode::ALL || (mode == RemovalMode::TYPE && fcm.type == type)) {
2997 fmods_to_delete.append(&fcm);
2998 }
2999 }
3000
3001 if (mode == RemovalMode::FIRST) {
3002 if (FModifier *first = fcu->modifiers.first()) {
3003 fmods_to_delete.append(first);
3004 }
3005 }
3006
3007 /* Delete the modifiers. */
3008 for (FModifier *fmod : fmods_to_delete) {
3010 num_fmods_deleted++;
3011 }
3012
3013 if (!fmods_to_delete.is_empty()) {
3014 num_fcurves_affected++;
3015 }
3016
3017 ale.update |= ANIM_UPDATE_DEPS;
3018 }
3019
3020 ANIM_animdata_update(&ac, &anim_data);
3021 ANIM_animdata_freelist(&anim_data);
3022
3023 /* Set notifier that things have changed. */
3025
3026 if (num_fmods_deleted == 0) {
3027 BKE_report(op->reports, RPT_INFO, "No F-Modifiers found to delete");
3028 }
3029 else {
3030 BKE_reportf(op->reports,
3031 RPT_INFO,
3032 "Removed %d F-Modifier(s) from %d selected F-Curve(s)",
3033 num_fmods_deleted,
3034 num_fcurves_affected);
3035 }
3036
3037 return OPERATOR_FINISHED;
3038}
3039
3040static void fmodifier_delete_ui(bContext * /*C*/, wmOperator *op)
3041{
3042 ui::Layout &layout = *op->layout;
3043 layout.use_property_split_set(true);
3044
3045 layout.prop(op->ptr, "mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
3046 if (RNA_enum_get(op->ptr, "mode") == int(RemovalMode::TYPE)) {
3047 layout.prop(op->ptr, "type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
3048 }
3049}
3050
3052{
3053 PropertyRNA *prop;
3054
3055 /* Identifiers */
3056 ot->name = "Delete F-Curve Modifiers";
3057 ot->idname = "GRAPH_OT_fmodifier_delete";
3058 ot->description = "Remove Modifier(s) from the selected F-Curves";
3059
3060 /* API callbacks */
3062 ot->ui = fmodifier_delete_ui;
3064
3065 /* Flags */
3067
3068 /* Id-props */
3069 static const EnumPropertyItem mode_items[] = {
3070 {int(RemovalMode::ALL),
3071 "ALL",
3072 0,
3073 "Remove All",
3074 "Remove all modifiers from the selected F-Curves"},
3075 {int(RemovalMode::FIRST),
3076 "FIRST",
3077 0,
3078 "Remove First",
3079 "Only remove the first modifier from each F-Curve regardless of type"},
3080 {int(RemovalMode::TYPE),
3081 "TYPE",
3082 0,
3083 "Remove Type",
3084 "Only remove the specified type of F-Curve modifier"},
3085 {0, nullptr, 0, nullptr, nullptr}};
3086
3087 RNA_def_enum(ot->srna,
3088 "mode",
3089 mode_items,
3090 int(RemovalMode::ALL),
3091 "Mode",
3092 "Decide what the operator will remove");
3093
3094 prop = RNA_def_enum(
3098 ot->prop = prop;
3099}
3100
3102
3103/* -------------------------------------------------------------------- */
3106
3108{
3109 bAnimContext ac;
3110 bAnimListElem *ale;
3111 bool ok = false;
3112
3113 /* Get editor data. */
3114 if (ANIM_animdata_get_context(C, &ac) == 0) {
3115 return OPERATOR_CANCELLED;
3116 }
3117
3118 /* Clear buffer first. */
3120
3121 /* Get the active F-Curve. */
3122 ale = get_active_fcurve_channel(&ac);
3123
3124 /* If this exists, call the copy F-Modifiers API function. */
3125 if (ale && ale->data) {
3126 FCurve *fcu = static_cast<FCurve *>(ale->data);
3127
3128 /* TODO: When 'active' vs 'all' boolean is added, change last param! (Joshua Leung 2010) */
3129 ok = ANIM_fmodifiers_copy_to_buf(&fcu->modifiers, false);
3130
3131 /* Free temp data now. */
3132 MEM_delete(ale);
3133 }
3134
3135 /* Successful or not? */
3136 if (ok == 0) {
3137 BKE_report(op->reports, RPT_ERROR, "No F-Modifiers available to be copied");
3138 return OPERATOR_CANCELLED;
3139 }
3140 return OPERATOR_FINISHED;
3141}
3142
3144{
3145 /* Identifiers */
3146 ot->name = "Copy F-Modifiers";
3147 ot->idname = "GRAPH_OT_fmodifier_copy";
3148 ot->description = "Copy the F-Modifier(s) of the active F-Curve";
3149
3150 /* API callbacks */
3153
3154 /* Flags */
3156
3157/* Id-props */
3158#if 0
3159 ot->prop = RNA_def_boolean(ot->srna,
3160 "all",
3161 1,
3162 "All F-Modifiers",
3163 "Copy all the F-Modifiers, instead of just the active one");
3164#endif
3165}
3166
3168
3169/* -------------------------------------------------------------------- */
3172
3174{
3175 bAnimContext ac;
3176
3177 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3178 int filter;
3179
3180 const bool replace = RNA_boolean_get(op->ptr, "replace");
3181 bool ok = false;
3182
3183 /* Get editor data. */
3184 if (ANIM_animdata_get_context(C, &ac) == 0) {
3185 return OPERATOR_CANCELLED;
3186 }
3187
3188 /* Filter data. */
3189 if (RNA_boolean_get(op->ptr, "only_active")) {
3190 /* This should be the default (for buttons) - Just paste to the active FCurve. */
3193 }
3194 else {
3195 /* This is only if the operator gets called from a hotkey or search -
3196 * Paste to all visible curves. */
3199 }
3200
3202 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
3203
3204 /* Paste modifiers. */
3205 for (bAnimListElem &ale : anim_data) {
3206 FCurve *fcu = static_cast<FCurve *>(ale.data);
3207 int tot;
3208
3209 tot = ANIM_fmodifiers_paste_from_buf(&fcu->modifiers, replace, fcu);
3210
3211 if (tot) {
3212 ale.update |= ANIM_UPDATE_DEPS;
3213 ok = true;
3214 }
3215 }
3216
3217 if (ok) {
3218 ANIM_animdata_update(&ac, &anim_data);
3219 }
3220 ANIM_animdata_freelist(&anim_data);
3221
3222 /* Successful or not? */
3223 if (ok) {
3224 /* Set notifier that keyframes have changed. */
3226
3227 return OPERATOR_FINISHED;
3228 }
3229
3230 BKE_report(op->reports, RPT_ERROR, "No F-Modifiers to paste");
3231 return OPERATOR_CANCELLED;
3232}
3233
3235{
3236 /* Identifiers */
3237 ot->name = "Paste F-Modifiers";
3238 ot->idname = "GRAPH_OT_fmodifier_paste";
3239 ot->description = "Add copied F-Modifiers to the selected F-Curves";
3240
3241 /* API callbacks */
3244
3245 /* Flags */
3247
3248 /* Properties */
3250 ot->srna, "only_active", false, "Only Active", "Only paste F-Modifiers on active F-Curve");
3252 ot->srna,
3253 "replace",
3254 false,
3255 "Replace Existing",
3256 "Replace existing F-Modifiers, instead of just appending to the end of the existing list");
3257}
3258
3260
3261/* -------------------------------------------------------------------- */
3264
3266{
3267 bool ok = false;
3268
3269 PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", RNA_FCurve);
3270
3271 /* If this exists, call the copy driver vars API function. */
3272 FCurve *fcu = static_cast<FCurve *>(ptr.data);
3273
3274 if (fcu) {
3275 ok = ANIM_driver_vars_copy(op->reports, fcu);
3276 }
3277
3278 /* Successful or not? */
3279 if (ok) {
3280 return OPERATOR_FINISHED;
3281 }
3282 return OPERATOR_CANCELLED;
3283}
3284
3286{
3287 /* Identifiers */
3288 ot->name = "Copy Driver Variables";
3289 ot->idname = "GRAPH_OT_driver_variables_copy";
3290 ot->description = "Copy the driver variables of the active driver";
3291
3292 /* API callbacks */
3295
3296 /* Flags */
3298}
3299
3301
3302/* -------------------------------------------------------------------- */
3305
3307{
3308 const bool replace = RNA_boolean_get(op->ptr, "replace");
3309 bool ok = false;
3310
3311 PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", RNA_FCurve);
3312
3313 /* If this exists, call the paste driver vars API function. */
3314 FCurve *fcu = static_cast<FCurve *>(ptr.data);
3315
3316 if (fcu) {
3317 ok = ANIM_driver_vars_paste(op->reports, fcu, replace);
3318 }
3319
3320 /* Successful or not? */
3321 if (ok) {
3322 /* Rebuild depsgraph, now that there are extra dependencies here. */
3324
3325 /* Set notifier that keyframes have changed. */
3327
3328 return OPERATOR_FINISHED;
3329 }
3330 return OPERATOR_CANCELLED;
3331}
3332
3334{
3335 /* Identifiers */
3336 ot->name = "Paste Driver Variables";
3337 ot->idname = "GRAPH_OT_driver_variables_paste";
3338 ot->description = "Add copied driver variables to the active driver";
3339
3340 /* API callbacks */
3343
3344 /* Flags */
3346
3347 /* Properties */
3349 "replace",
3350 false,
3351 "Replace Existing",
3352 "Replace existing driver variables, instead of just appending to the end of the "
3353 "existing list");
3354}
3355
3357
3358/* -------------------------------------------------------------------- */
3361
3363{
3364 bAnimContext ac;
3365 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
3366 int filter;
3367 bool ok = false;
3368 uint deleted = 0;
3369
3370 /* Get editor data. */
3371 if (ANIM_animdata_get_context(C, &ac) == 0) {
3372 return OPERATOR_CANCELLED;
3373 }
3374
3375 /* NOTE: We might need a scene update to evaluate the driver flags. */
3376
3377 /* Filter data. */
3381 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
3382
3383 /* Find invalid drivers. */
3384 for (bAnimListElem &ale : anim_data) {
3385 FCurve *fcu = static_cast<FCurve *>(ale.data);
3386 if (ELEM(nullptr, fcu, fcu->driver)) {
3387 continue;
3388 }
3389 if (!(fcu->driver->flag & DRIVER_FLAG_INVALID)) {
3390 continue;
3391 }
3392
3393 ok |= ANIM_remove_driver(ale.id, fcu->rna_path().c_str(), fcu->array_index);
3394 if (!ok) {
3395 break;
3396 }
3397 deleted += 1;
3399 }
3400
3401 /* Cleanup. */
3402 ANIM_animdata_freelist(&anim_data);
3403
3404 if (deleted > 0) {
3405 /* Notify the world of any changes. */
3408 BKE_reportf(op->reports, RPT_INFO, "Deleted %u drivers", deleted);
3409 }
3410 else {
3411 BKE_report(op->reports, RPT_INFO, "No drivers deleted");
3412 }
3413
3414 /* Successful or not? */
3415 if (!ok) {
3416 return OPERATOR_CANCELLED;
3417 }
3418
3419 return OPERATOR_FINISHED;
3420}
3421
3423{
3424 bAnimContext ac;
3425 ScrArea *area = CTX_wm_area(C);
3426
3427 /* Firstly, check if in Graph Editor. */
3428 if ((area == nullptr) || (area->spacetype != SPACE_GRAPH)) {
3429 return false;
3430 }
3431
3432 /* Try to init Anim-Context stuff ourselves and check. */
3433 return ANIM_animdata_get_context(C, &ac) != 0;
3434}
3435
3437{
3438 /* Identifiers */
3439 ot->name = "Delete Invalid Drivers";
3440 ot->idname = "GRAPH_OT_driver_delete_invalid";
3441 ot->description = "Delete all visible drivers considered invalid";
3442
3443 /* API callbacks */
3446
3447 /* Flags */
3449}
3450
3452
3453} // namespace blender
Functions to work with AnimData.
Functions to modify FCurves.
Functions to insert, delete or modify keyframes.
File and directory operations.
#define M_PI
#define FILE_MAX
#define BLT_I18NCONTEXT_ID_ACTION
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
#define ANIM_UPDATE_DEFAULT_NOHANDLES
#define ANIM_UPDATE_DEFAULT
Read Blender memory allocation and freeing.
#define RNA_ENUM_ITEM_SEPR
Definition RNA_types.hh:762
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define NC_ANIMATION
Definition WM_types.hh:401
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define NA_EDITED
Definition WM_types.hh:634
#define ND_KEYFRAME_PROP
Definition WM_types.hh:538
#define ND_FRAME
Definition WM_types.hh:453
#define NA_REMOVED
Definition WM_types.hh:637
#define ND_KEYFRAME
Definition WM_types.hh:537
#define MAKE_CYCLIC_EXPO
#define CLEAR_CYCLIC_EXPO
#define ELEM(...)
#define STREQ(a, b)
Definition scene.h:133
void append(const T &value)
bool is_empty() const
#define FLT_MAX
#define position
constexpr T sign(T) RET
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
ccl_device_inline float2 fmod(const float2 a, const float b)
void animdata_fcurve_delete(AnimData *adt, FCurve *fcu)
Definition animdata.cc:251
KeyframeSettings get_keyframe_settings(bool from_userprefs)
SingleKeyingResult insert_vert_fcurve(FCurve *fcu, const float2 position, const KeyframeSettings &settings, eInsertKeyFlags flag)
Main Key-framing API call.
void bake_fcurve_segments(FCurve *fcu)
eInsertKeyFlags get_keyframing_flags(Scene *scene)
CombinedKeyingResult insert_keyframes(Main *bmain, PointerRNA *struct_pointer, std::optional< StringRefNull > channel_group, const Span< RNAPath > rna_paths, std::optional< float > scene_frame, const AnimationEvalContext &anim_eval_context, eBezTriple_KeyframeType key_type, eInsertKeyFlags insert_key_flags)
Main key-frame insertion API.
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
BMesh Iterators.
void GRAPH_OT_easing_type(wmOperatorType *ot)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
@ KEYFRAME_PASTE_NOTHING_TO_PASTE
@ KEYFRAME_PASTE_NOWHERE_TO_PASTE
void GRAPH_OT_keys_to_samples(wmOperatorType *ot)
static wmOperatorStatus graphkeys_euler_filter_exec(bContext *C, wmOperator *op)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
KeyframeEditFunc ANIM_editkeyframes_ok(short mode)
void GRAPH_OT_click_insert(wmOperatorType *ot)
static bool graph_driver_delete_invalid_poll(bContext *C)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
ScrArea * CTX_wm_area(const bContext *C)
void eul_to_mat3(float mat[3][3], const float eul[3])
static wmOperatorStatus graphkeys_expo_exec(bContext *C, wmOperator *op)
void GRAPH_OT_equalize_handles(wmOperatorType *ot)
void GRAPH_OT_smooth(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
const EnumPropertyItem rna_enum_fmodifier_type_items[]
Definition rna_fcurve.cc:31
@ DRIVER_FLAG_INVALID
void GRAPH_OT_fmodifier_copy(wmOperatorType *ot)
void BKE_fcurve_keyframe_move_value_with_handles(BezTriple *keyframe, float new_value)
@ RPT_WARNING
Definition BKE_report.hh:40
bool BKE_fcurve_delete_keys_selected(FCurve &fcu)
void GRAPH_OT_delete(wmOperatorType *ot)
void GRAPH_OT_copy(wmOperatorType *ot)
KeyframeEditFunc ANIM_editkeyframes_ipo(short mode)
unsigned int uint
Definition BKE_text.h:55
static wmOperatorStatus graphkeys_clean_exec(bContext *C, wmOperator *op)
wmOperatorStatus WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *)
KeyframeEditFunc ANIM_editkeyframes_handles(short mode)
bool graphop_visible_keyframes_poll(bContext *C)
bool BKE_fcurve_is_keyframable(const FCurve &fcu)
void GRAPH_OT_keyframe_jump(wmOperatorType *ot)
MINLINE int round_fl_to_int(float a)
void GRAPH_OT_bake_keys(wmOperatorType *ot)
PointerRNA RNA_id_pointer_create(ID *id)
void smooth_fcurve(FCurve *fcu)
@ ANIM_UNITCONV_RESTORE
@ ANIM_UNITCONV_ONLYKEYS
bool ANIM_driver_vars_paste(ReportList *reports, FCurve *fcu, bool replace)
Definition drivers.cc:706
static wmOperatorStatus graphkeys_easing_exec(bContext *C, wmOperator *op)
static wmOperatorStatus graphkeys_duplicate_exec(bContext *C, wmOperator *)
static wmOperatorStatus graphkeys_equalize_handles_exec(bContext *C, wmOperator *op)
static wmOperatorStatus graph_fmodifier_paste_exec(bContext *C, wmOperator *op)
static wmOperatorStatus graphkeys_snap_exec(bContext *C, wmOperator *op)
bool ANIM_driver_vars_copy(ReportList *reports, FCurve *fcu)
Definition drivers.cc:684
bool graphop_selected_fcurve_poll(bContext *C)
static wmOperatorStatus graphkeys_bake_exec(bContext *C, wmOperator *)
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
void clean_fcurve(bAnimListElem *ale, float thresh, bool cleardefault, const bool only_selected_keys)
static wmOperatorStatus graph_fmodifier_copy_exec(bContext *C, wmOperator *op)
float ANIM_nla_tweakedit_remap(bAnimListElem *ale, const float cframe, const eNlaTime_ConvertModes mode)
Definition anim_draw.cc:329
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus graphkeys_handletype_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem prop_graphkeys_expo_types[]
static bool euler_filter_multi_channel(tEulerFilter *euf, ReportList *reports)
const EnumPropertyItem rna_enum_keyframe_paste_merge_items[]
FModifier * add_fmodifier(ListBaseT< FModifier > *modifiers, int type, FCurve *owner_fcu)
static wmOperatorStatus graphkeys_delete_exec(bContext *C, wmOperator *)
void GRAPH_OT_fmodifier_delete(wmOperatorType *ot)
static wmOperatorStatus graphkeys_delete_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool euler_filter_single_channel(FCurve *fcu)
bool duplicate_fcurve_keys(FCurve *fcu)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
bool graphop_active_fcurve_poll(bContext *C)
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void GRAPH_OT_sound_to_samples(wmOperatorType *ot)
bool list_has_suitable_fmodifier(const ListBaseT< FModifier > *modifiers, int mtype, short acttype)
void GRAPH_OT_clean(wmOperatorType *ot)
@ KEYFRAME_PASTE_OFFSET_CFRA_START
short ANIM_fcurve_keyframes_loop(KeyframeEditData *ked, FCurve *fcu, KeyframeEditFunc key_ok, KeyframeEditFunc key_cb, FcuEditFunc fcu_cb)
static void convert_keys_to_samples(bAnimContext *ac, int start, int end)
static void bake_graph_keys(bAnimContext *ac)
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
bool remove_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
void GRAPH_OT_extrapolation_type(wmOperatorType *ot)
static void equalize_graph_keys(bAnimContext *ac, int mode, float handle_length, bool flatten)
void ANIM_nla_mapping_apply_if_needed_fcurve(bAnimListElem *ale, FCurve *fcu, const bool restore, const bool only_keys)
Definition anim_draw.cc:406
static bool copy_graph_keys(bAnimContext *ac)
void ANIM_animdata_update(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:365
static wmOperatorStatus graphkeys_sound_to_samples_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void GRAPH_OT_frame_jump(wmOperatorType *ot)
void GRAPH_OT_samples_to_keys(wmOperatorType *ot)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
static void mirror_graph_keys(bAnimContext *ac, short mode)
static std::string graphkeys_paste_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
ScenePlaybackRange BKE_scene_get_playback_range(const Scene *scene)
Definition scene.cc:2607
void BKE_fcurve_merge_duplicate_keys(FCurve *fcu, const int sel_flag, const bool use_handle)
Global G
Definition blender.cc:57
@ FMODIFIER_TYPE_CYCLES
@ FMODIFIER_TYPE_GENERATOR
@ FMODIFIER_NUM_TYPES
void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
static bool graph_has_selected_control_points(bContext *C)
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
static wmOperatorStatus graphkeys_copy_exec(bContext *C, wmOperator *op)
bool copy_animedit_keys(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
static const EnumPropertyItem prop_graphkeys_mirror_types[]
static wmOperatorStatus graph_fmodifier_delete_exec(bContext *C, wmOperator *op)
static void clean_graph_keys(bAnimContext *ac, float thresh, bool clean_chan)
static void setexpo_graph_keys(bAnimContext *ac, short mode)
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)
void ANIM_fcurve_equalize_keyframes_loop(FCurve *fcu, const eEditKeyframes_Equalize mode, const float handle_length, const bool flatten)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_FOREDIT
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_CURVE_VISIBLE
@ ANIMFILTER_ACTIVE
@ ANIMFILTER_NODUPLIS
static wmOperatorStatus graphkeys_mirror_exec(bContext *C, wmOperator *op)
void BKE_fcurve_handles_recalc(FCurve &fcu)
static bool duplicate_graph_keys(bAnimContext *ac)
static void fmodifier_delete_ui(bContext *, wmOperator *op)
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
@ WM_FILESEL_SHOW_PROPS
Definition WM_api.hh:1335
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
void GRAPH_OT_keyframe_insert(wmOperatorType *ot)
void ANIM_deselect_keys_in_animation_editors(bContext *C)
Definition anim_deps.cc:487
void GRAPH_OT_snap_cursor_value(wmOperatorType *ot)
static bool delete_graph_keys(bAnimContext *ac)
const EnumPropertyItem rna_enum_beztriple_interpolation_easing_items[]
static std::string graphkeys_clean_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
bool ANIM_remove_driver(ID *id, const char rna_path[], int array_index)
Main Driver Management API calls.
Definition drivers.cc:511
static void snap_graph_keys(bAnimContext *ac, short mode)
TimeMarker * ED_markers_get_first_selected(ListBaseT< TimeMarker > *markers)
static bool graphkeys_framejump_poll(bContext *C)
static bool keyframe_time_differs(BezTriple *keyframes[3])
static wmOperatorStatus graphkeys_ipo_exec(bContext *C, wmOperator *op)
static wmOperatorStatus graphkeys_click_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool ANIM_fmodifiers_paste_from_buf(ListBaseT< FModifier > *modifiers, bool replace, FCurve *curve)
static wmOperatorStatus graphkeys_selected_control_points_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void GRAPH_OT_interpolation_type(wmOperatorType *ot)
static wmOperatorStatus graphkeys_framejump_exec(bContext *C, wmOperator *)
static KeyframeEditData sum_selected_keyframes(bAnimContext *ac)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bAnimListElem * get_active_fcurve_channel(bAnimContext *ac)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
void GRAPH_OT_driver_delete_invalid(wmOperatorType *ot)
void mat3_normalized_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
static wmOperatorStatus graphkeys_smooth_exec(bContext *C, wmOperator *)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
static void sethandles_graph_keys(bAnimContext *ac, short mode)
@ GRAPHKEYS_SNAP_NEAREST_MARKER
@ GRAPHKEYS_SNAP_HORIZONTAL
@ GRAPHKEYS_SNAP_NEAREST_SECOND
@ GRAPHKEYS_SNAP_CFRA
@ GRAPHKEYS_SNAP_NEAREST_FRAME
@ GRAPHKEYS_SNAP_VALUE
static void euler_filter_perform_filter(ListBaseT< tEulerFilter > *eulers, ReportList *reports, int *r_curves_filtered, int *r_curves_seen)
static wmOperatorStatus graphkeys_paste_exec(bContext *C, wmOperator *op)
short(*)(KeyframeEditData *ked, BezTriple *bezt) KeyframeEditFunc
@ GRAPHKEYS_MIRROR_MARKER
@ GRAPHKEYS_MIRROR_VALUE
@ GRAPHKEYS_MIRROR_YAXIS
@ GRAPHKEYS_MIRROR_XAXIS
@ GRAPHKEYS_MIRROR_CFRA
const EnumPropertyItem rna_enum_transform_mode_type_items[]
static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
@ GRAPHKEYS_EQUALIZE_BOTH
@ GRAPHKEYS_EQUALIZE_RIGHT
@ GRAPHKEYS_EQUALIZE_LEFT
@ KEYFRAME_PASTE_VALUE_OFFSET_NONE
static void seteasing_graph_keys(bAnimContext *ac, short mode)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static wmOperatorStatus graph_driver_vars_copy_exec(bContext *C, wmOperator *op)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_OPENFILE
Definition WM_api.hh:1341
float evaluate_fcurve_only_curve(const FCurve *fcu, float evaltime)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
const EnumPropertyItem rna_enum_beztriple_interpolation_mode_items[]
Definition rna_curve.cc:66
Main * CTX_data_main(const bContext *C)
void ANIM_fmodifiers_copybuf_free()
static void convert_samples_to_keys(bAnimContext *ac, int start, int end)
static wmOperatorStatus graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
void deselect_graph_keys(bAnimContext *ac, bool test, eEditKeyframes_Select sel, bool do_channels)
void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
static const EnumPropertyItem prop_graphkeys_insertkey_types[]
Definition graph_edit.cc:84
static wmOperatorStatus graphkeys_keys_to_samples_exec(bContext *C, wmOperator *)
static wmOperatorStatus graph_fmodifier_add_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem * graph_fmodifier_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
KeyframeEditFunc ANIM_editkeyframes_snap(short mode)
float ANIM_unit_mapping_get_factor(Scene *scene, ID *id, FCurve *fcu, short flag, float *r_offset)
Definition anim_draw.cc:636
void GRAPH_OT_duplicate(wmOperatorType *ot)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
const EnumPropertyItem rna_enum_keyframe_paste_offset_items[]
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
void GRAPH_OT_snap(wmOperatorType *ot)
static eKeyPasteError paste_graph_keys(bAnimContext *ac, const eKeyPasteOffset offset_mode, const eKeyPasteValueOffset value_offset_mode, const eKeyMergeMode merge_mode, const bool flip)
static wmOperatorStatus graphkeys_samples_to_keys_exec(bContext *C, wmOperator *)
eKeyPasteError paste_animedit_keys(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const KeyframePasteContext &paste_context)
static wmOperatorStatus graph_driver_vars_paste_exec(bContext *C, wmOperator *op)
static ListBaseT< tEulerFilter > euler_filter_group_channels(const ListBaseT< bAnimListElem > *anim_data, ReportList *reports, int *r_num_groups)
static const EnumPropertyItem prop_graphkeys_snap_types[]
void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
void DEG_relations_tag_update(Main *bmain)
bool ANIM_fmodifiers_copy_to_buf(ListBaseT< FModifier > *modifiers, bool active)
Scene * CTX_data_scene(const bContext *C)
KeyframeEditFunc ANIM_editkeyframes_easing(short mode)
void GRAPH_OT_mirror(wmOperatorType *ot)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_UNDO_GROUPED
Definition WM_types.hh:215
bool BKE_fcurve_is_empty(const FCurve *fcu)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void GRAPH_OT_fmodifier_paste(wmOperatorType *ot)
void GRAPH_OT_handle_type(wmOperatorType *ot)
static wmOperatorStatus graphkeys_insertkey_exec(bContext *C, wmOperator *op)
short bezt_calc_average(KeyframeEditData *ked, BezTriple *bezt)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
void GRAPH_OT_euler_filter(wmOperatorType *ot)
static wmOperatorStatus graphkeys_sound_to_samples_exec(bContext *, wmOperator *op)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool BKE_fcurve_has_selected_control_points(const FCurve &fcu)
static wmOperatorStatus keyframe_jump_exec(bContext *C, wmOperator *op)
MINLINE int min_ii(int a, int b)
bool BLI_is_file(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:469
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)
static void setipo_graph_keys(bAnimContext *ac, short mode)
@ FCURVE_EXTRAPOLATE_CONSTANT
@ FCURVE_EXTRAPOLATE_LINEAR
bool graphop_active_editable_fcurve_ctx_poll(bContext *C)
void set_active_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
ARegion * CTX_wm_region(const bContext *C)
const EnumPropertyItem rna_enum_keyframe_paste_offset_value_items[]
@ ANIM_UPDATE_DEPS
@ ANIM_UPDATE_HANDLES
float RNA_float_get(PointerRNA *ptr, const char *name)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
const FModifierTypeInfo * get_fmodifier_typeinfo(int type)
eGraphKeys_InsertKey_Types
Definition graph_edit.cc:76
@ GRAPHKEYS_INSERTKEY_ACTIVE
Definition graph_edit.cc:80
@ GRAPHKEYS_INSERTKEY_CURSOR
Definition graph_edit.cc:79
@ GRAPHKEYS_INSERTKEY_ALL
Definition graph_edit.cc:77
@ GRAPHKEYS_INSERTKEY_SEL
Definition graph_edit.cc:78
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static wmOperatorStatus graphkeys_click_insert_exec(bContext *C, wmOperator *op)
void fcurve_samples_to_keyframes(FCurve *fcu, int start, int end)
static wmOperatorStatus graphkeys_snap_cursor_value_exec(bContext *C, wmOperator *)
bool graphop_editable_keyframes_poll(bContext *C)
short ANIM_get_normalization_flags(SpaceLink *space_link)
Definition anim_draw.cc:420
static const EnumPropertyItem prop_graphkeys_equalize_handles_sides[]
KeyframeEditFunc ANIM_editkeyframes_mirror(short mode)
const EnumPropertyItem rna_enum_keyframe_handle_type_items[]
Definition rna_curve.cc:38
void GRAPH_OT_paste(wmOperatorType *ot)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bActionGroup * grp
eFCurve_Flags flag
eFCurve_Extend extend
ListBaseT< FModifier > modifiers
ChannelDriver * driver
unsigned int totvert
struct FModifier * next
eFModifier_Types type
char name[258]
Definition DNA_ID.h:433
ListBaseT< TimeMarker > time_marker_list
eKeyPasteValueOffset value_offset_mode
struct RenderData r
struct ToolSettings * toolsettings
eGraphEdit_Flag flag
eGraphEdit_Mode mode
eBezTriple_KeyframeType keyframe_type
ListBaseT< TimeMarker > * markers
eAnimCont_Types datatype
eAnim_Update_Flags update
tEulerFilter * next
tEulerFilter * prev
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
const char * undo_group
Definition WM_types.hh:1117
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
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
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports