Blender V5.3
editors/animation/keyframing.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdio>
10
11#include <fmt/format.h>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_math_base_c.hh"
16#include "BLI_string.hh"
17
18#include "BLT_translation.hh"
19
20#include "DNA_ID.h"
21#include "DNA_anim_types.h"
22#include "DNA_armature_types.h"
23#include "DNA_scene_types.h"
24#include "DNA_sequence_types.h"
25
26#include "BKE_action.hh"
27#include "BKE_anim_data.hh"
28#include "BKE_animsys.hh"
29#include "BKE_armature.hh"
30#include "BKE_context.hh"
31#include "BKE_fcurve.hh"
32#include "BKE_global.hh"
33#include "BKE_idtype.hh"
34#include "BKE_lib_id.hh"
35#include "BKE_nla.hh"
36#include "BKE_report.hh"
37#include "BKE_scene.hh"
38#include "BKE_scene_context.hh"
39
40#include "DEG_depsgraph.hh"
42
43#include "ED_anim_api.hh"
44#include "ED_keyframing.hh"
45#include "ED_object.hh"
46#include "ED_screen.hh"
47#include "ED_sequencer.hh"
48
49#include "ANIM_action.hh"
51#include "ANIM_animdata.hh"
52#include "ANIM_armature.hh"
54#include "ANIM_driver.hh"
55#include "ANIM_fcurve.hh"
56#include "ANIM_keyframing.hh"
57#include "ANIM_keyingsets.hh"
58#include "ANIM_rna.hh"
59
60#include "SEQ_relations.hh"
61
62#include "UI_interface.hh"
64#include "UI_resources.hh"
65
66#include "WM_api.hh"
67#include "WM_types.hh"
68
69#include "RNA_access.hh"
70#include "RNA_define.hh"
71#include "RNA_enum_types.hh"
72#include "RNA_path.hh"
73#include "RNA_prototypes.hh"
74
75#include "anim_intern.hh"
76
77namespace blender {
78
80 PropertyRNA *prop,
81 Scene *scene);
82
84
85/* -------------------------------------------------------------------- */
88
90{
91 PointerRNA tmp_ptr;
92 PropertyRNA *prop;
93 int old_flag = fcu->flag;
94
95 if (!*ptr) {
96 BKE_report(reports, RPT_ERROR, "No RNA pointer available to retrieve values for this F-curve");
97 return;
98 }
99
100 /* try to get property we should be affecting */
101 if (RNA_path_resolve_property(ptr, fcu->rna_path_parsed(), &tmp_ptr, &prop) == false) {
102 /* property not found... */
103 const char *idname = (ptr->owner_id) ? ptr->owner_id->name : RPT_("<No ID pointer>");
104
105 BKE_reportf(reports,
106 RPT_ERROR,
107 "Could not update flags for this F-curve, as RNA path is invalid for the given ID "
108 "(ID = %s, path = %s)",
109 idname,
110 fcu->rna_path().c_str());
111 return;
112 }
113
114 /* update F-Curve flags */
116
117 if (old_flag != fcu->flag) {
118 /* Same as if keyframes had been changed */
120 }
121}
122
123void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
124{
125 BLI_assert_msg(num_keys_to_add >= 0, "cannot remove keyframes with this function");
126
127 if (num_keys_to_add == 0) {
128 return;
129 }
130
131 fcu->bezt = static_cast<BezTriple *>(
132 MEM_realloc_zeroed(fcu->bezt, sizeof(BezTriple) * (fcu->totvert + num_keys_to_add)));
133 BezTriple *bezt = fcu->bezt + fcu->totvert; /* Pointer to the first new one. */
134
135 fcu->totvert += num_keys_to_add;
136
137 /* Iterate over the new keys to update their settings. */
138 while (num_keys_to_add--) {
139 /* Defaults, ignoring user-preference gives predictable results for API. */
140 bezt->f1 = bezt->f2 = bezt->f3 = BEZT_FLAG_SELECT;
141 bezt->ipo = BEZT_IPO_BEZ;
142 bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
143 bezt++;
144 }
145}
146
148
149/* -------------------------------------------------------------------- */
152
153/* mode for commonkey_modifykey */
154enum {
157} /*eCommonModifyKey_Modes*/;
158
165{
166 ScrArea *area = CTX_wm_area(C);
167 Scene *scene = CTX_data_scene(C);
168
169 /* if no area or active scene */
170 if (ELEM(nullptr, area, scene)) {
171 return false;
172 }
173
174 /* should be fine */
175 return true;
176}
177
178/* Fill the list with items depending on the mode of the context. */
179static bool get_selection(bContext *C, Vector<PointerRNA> *r_selection)
180{
181 const eContextObjectMode context_mode = CTX_data_mode_enum(C);
182 ScrArea *area = CTX_wm_area(C);
183
184 if (area && area->spacetype == SPACE_SEQ) {
186 for (Strip *strip : strips) {
187 const bool is_sequencer = CTX_wm_space_seq(C) != nullptr;
188 Scene *scene = is_sequencer ? CTX_data_sequencer_scene(C) : CTX_data_scene(C);
189 PointerRNA ptr;
190 ptr = RNA_pointer_create_discrete(&scene->id, RNA_Strip, strip);
191 r_selection->append(ptr);
192 }
193 return true;
194 }
195
196 switch (context_mode) {
197 case CTX_MODE_OBJECT: {
198 CTX_data_selected_objects(C, r_selection);
199 break;
200 }
201 case CTX_MODE_POSE: {
202 CTX_data_selected_pose_bones(C, r_selection);
203 break;
204 }
205 default:
206 return false;
207 }
208
209 return true;
210}
211
213
214/* -------------------------------------------------------------------- */
217
219{
221 if (!scene) {
222 return OPERATOR_CANCELLED;
223 }
224 Object *obedit = CTX_data_edit_object(C);
225 bool ob_edit_mode = false;
226
227 const float cfra = BKE_scene_frame_get(scene);
228 const bool confirm = op->flag & OP_IS_INVOKE;
229 /* exit the edit mode to make sure that those object data properties that have been
230 * updated since the last switching to the edit mode will be keyframed correctly
231 */
232 if (obedit && animrig::keyingset_find_id(ks, obedit->data)) {
234 ob_edit_mode = true;
235 }
236
237 /* try to insert keyframes for the channels specified by KeyingSet */
238 const int num_channels = animrig::apply_keyingset(
239 C, nullptr, ks, animrig::ModifyKeyMode::INSERT, cfra);
240 if (G.debug & G_DEBUG) {
242 RPT_INFO,
243 "Keying set '%s' - successfully added %d keyframes",
244 ks->name,
245 num_channels);
246 }
247
248 /* restore the edit mode if necessary */
249 if (ob_edit_mode) {
251 }
252
253 /* report failure or do updates? */
254 if (num_channels < 0) {
255 BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
256 return OPERATOR_CANCELLED;
257 }
258
259 if (num_channels > 0) {
260 /* send notifiers that keyframes have been changed */
263 }
264
265 if (confirm) {
266 /* if called by invoke (from the UI), make a note that we've inserted keyframes */
267 if (num_channels > 0) {
269 RPT_INFO,
270 "Successfully added %d keyframes for keying set '%s'",
271 num_channels,
272 ks->name);
273 }
274 else {
275 BKE_report(op->reports, RPT_WARNING, "Keying set failed to insert any keyframes");
276 }
277 }
278
279 return OPERATOR_FINISHED;
280}
281
283{
284 Vector<RNAPath> paths;
285
286 if (ptr->type == RNA_Strip || RNA_struct_is_a(ptr->type, RNA_Strip)) {
287 eKeyInsertChannels insert_channel_flags = eKeyInsertChannels(U.key_insert_channels);
288 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_LOCATION) {
289 paths.append({"transform.offset_x"});
290 paths.append({"transform.offset_y"});
291 }
292 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_ROTATION) {
293 paths.append({"transform.rotation"});
294 }
295 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_SCALE) {
296 paths.append({"transform.scale_x"});
297 paths.append({"transform.scale_y"});
298 }
299 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_CUSTOM_PROPERTIES) {
301 }
302 return paths;
303 }
304
305 std::optional<eRotationModes> rotation_mode = animrig::get_rotation_mode_from_rna_pointer(*ptr);
306 if (!rotation_mode.has_value()) {
307 /* Pointer type not supported. */
308 return paths;
309 }
310
311 eKeyInsertChannels insert_channel_flags = eKeyInsertChannels(U.key_insert_channels);
312 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_LOCATION) {
313 paths.append({"location"});
314 }
315 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_ROTATION) {
316 switch (rotation_mode.value()) {
317 case ROT_MODE_QUAT:
318 paths.append({"rotation_quaternion"});
319 break;
321 paths.append({"rotation_axis_angle"});
322 break;
323 case ROT_MODE_XYZ:
324 case ROT_MODE_XZY:
325 case ROT_MODE_YXZ:
326 case ROT_MODE_YZX:
327 case ROT_MODE_ZXY:
328 case ROT_MODE_ZYX:
329 paths.append({"rotation_euler"});
330 default:
331 break;
332 }
333 }
334 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_SCALE) {
335 paths.append({"scale"});
336 }
337 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_ROTATION_MODE) {
338 paths.append({"rotation_mode"});
339 }
340
341 if (insert_channel_flags & USER_ANIM_KEY_CHANNEL_CUSTOM_PROPERTIES) {
343 }
344 return paths;
345}
346
348{
349 Vector<PointerRNA> selection;
350 const bool found_selection = get_selection(C, &selection);
351 if (!found_selection) {
352 BKE_reportf(op->reports, RPT_ERROR, "Unsupported context mode");
353 return OPERATOR_CANCELLED;
354 }
355
356 if (selection.is_empty()) {
357 BKE_reportf(op->reports, RPT_WARNING, "Nothing selected to key");
358 return OPERATOR_CANCELLED;
359 }
360
361 Main *bmain = CTX_data_main(C);
363 const float scene_frame = BKE_scene_frame_get(scene);
364
365 const eInsertKeyFlags insert_key_flags = animrig::get_keyframing_flags(scene);
368 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
370 depsgraph, BKE_scene_frame_get(scene));
371
372 animrig::CombinedKeyingResult combined_result;
373 Set<ID *> ids;
374 for (PointerRNA &id_ptr : selection) {
375 ID *selected_id = id_ptr.owner_id;
376 ids.add(selected_id);
377 if (!id_can_have_animdata(selected_id)) {
379 RPT_ERROR,
380 "Could not insert keyframe, as this type does not support animation data (ID = "
381 "%s)",
382 selected_id->name);
383 continue;
384 }
385 if (!BKE_id_is_editable(bmain, selected_id)) {
386 BKE_reportf(op->reports, RPT_ERROR, "'%s' is not editable", selected_id->name + 2);
387 continue;
388 }
389 Vector<RNAPath> rna_paths = construct_rna_paths(&id_ptr);
390
391 combined_result.merge(animrig::insert_keyframes(bmain,
392 &id_ptr,
393 std::nullopt,
394 rna_paths.as_span(),
395 scene_frame,
396 anim_eval_context,
397 key_type,
398 insert_key_flags));
399 }
400
401 if (combined_result.get_count(animrig::SingleKeyingResult::SUCCESS) == 0) {
402 combined_result.generate_reports(op->reports);
403 }
404
405 for (ID *id : ids) {
407 }
408
411
412 return OPERATOR_FINISHED;
413}
414
416{
418
420 if (!scene) {
421 return OPERATOR_CANCELLED;
422 }
423 /* Use the active keying set if there is one. */
424 const int type = RNA_enum_get(op->ptr, "type");
426 if (ks) {
427 return insert_key_with_keyingset(C, op, ks);
428 }
429 return insert_key(C, op);
430}
431
433{
434 /* The depsgraph needs to be in an evaluated state to ensure the values we get from the
435 * properties are actually the values of the current frame. However we cannot do that in the exec
436 * function, as that would mean every call to the operator via python has to re-evaluate the
437 * depsgraph, causing performance regressions. */
439 return insert_key_exec(C, op);
440}
441
443{
444 /* identifiers */
445 ot->name = "Insert Keyframe";
446 ot->idname = "ANIM_OT_keyframe_insert";
447 ot->description =
448 "Insert keyframes on the current frame using either the active keying set, or the user "
449 "preferences if no keying set is active";
450
451 /* callbacks */
453 ot->exec = insert_key_exec;
455
456 /* flags */
458
459 /* Allows passing in a keying set when using the Python operator. */
461 ot->srna, "type", rna_enum_dummy_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
464 ot->prop = prop;
465}
466
468{
470
472 if (!scene) {
473 return OPERATOR_CANCELLED;
474 }
476 if (ks == nullptr) {
477 return OPERATOR_CANCELLED;
478 }
479 return insert_key_with_keyingset(C, op, ks);
480}
481
483{
484 PropertyRNA *prop;
485
486 /* identifiers */
487 ot->name = "Insert Keyframe (by name)";
488 ot->idname = "ANIM_OT_keyframe_insert_by_name";
489 ot->description = "Alternate access to 'Insert Keyframe' for keymaps to use";
490
491 /* callbacks */
494
495 /* flags */
497
498 /* keyingset to use (idname) */
499 prop = RNA_def_string(
500 ot->srna, "type", nullptr, MAX_ID_NAME - 2, "Keying Set", "The Keying Set to use");
504 ot->prop = prop;
505}
506
508
509/* -------------------------------------------------------------------- */
515
517 wmOperator *op,
518 const wmEvent * /*event*/)
519{
521 if (!scene) {
522 return OPERATOR_CANCELLED;
523 }
524
525 /* When there is an active keying set and no request to prompt, keyframe immediately. */
526 if ((scene->active_keyingset != 0) && !RNA_boolean_get(op->ptr, "always_prompt")) {
527 /* Just call the exec() on the active keying-set. */
528 RNA_enum_set(op->ptr, "type", 0);
529 return op->type->exec(C, op);
530 }
531
532 /* Show a menu listing all keying-sets, the enum is expanded here to make use of the
533 * operator that accesses the keying-set by name. This is important for the ability
534 * to assign shortcuts to arbitrarily named keying sets. See #89560.
535 * These menu items perform the key-frame insertion (not this operator)
536 * hence the #OPERATOR_INTERFACE return. */
538 C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE);
539 ui::Layout &layout = *popup_menu_layout(pup);
540
541 /* Even though `ANIM_OT_keyframe_insert_menu` can show a menu in one line,
542 * prefer `ANIM_OT_keyframe_insert_by_name` so users can bind keys to specific
543 * keying sets by name in the key-map instead of the index which isn't stable. */
544 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "type");
545 const EnumPropertyItem *item_array = nullptr;
546 int totitem;
547 bool free;
548
549 RNA_property_enum_items_gettexted(C, op->ptr, prop, &item_array, &totitem, &free);
550
551 for (int i = 0; i < totitem; i++) {
552 const EnumPropertyItem *item = &item_array[i];
553 if (item->identifier[0] != '\0') {
554 PointerRNA op_ptr = layout.op("ANIM_OT_keyframe_insert_by_name", item->name, item->icon);
555 RNA_string_set(&op_ptr, "type", item->identifier);
556 }
557 else {
558 /* This enum shouldn't contain headings, assert there are none.
559 * NOTE: If in the future the enum includes them, additional layout code can be
560 * added to show them - although that doesn't seem likely. */
561 BLI_assert(item->name == nullptr);
562 layout.separator();
563 }
564 }
565
566 if (free) {
567 MEM_delete(item_array);
568 }
569
570 popup_menu_end(C, pup);
571
572 return OPERATOR_INTERFACE;
573}
574
576{
577 PropertyRNA *prop;
578
579 /* identifiers */
580 ot->name = "Insert Keyframe Menu";
581 ot->idname = "ANIM_OT_keyframe_insert_menu";
582 ot->description =
583 "Insert Keyframes for specified Keying Set, with menu of available Keying Sets if undefined";
584
585 /* callbacks */
589
590 /* flags */
592
593 /* keyingset to use (dynamic enum) */
594 prop = RNA_def_enum(
595 ot->srna, "type", rna_enum_dummy_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
598 ot->prop = prop;
599
600 /* whether the menu should always be shown
601 * - by default, the menu should only be shown when there is no active Keying Set (2.5 behavior),
602 * although in some cases it might be useful to always shown (pre 2.5 behavior)
603 */
604 prop = RNA_def_boolean(ot->srna, "always_prompt", false, "Always Show Menu", "");
606}
607
609
610/* -------------------------------------------------------------------- */
613
615{
617 if (!scene) {
618 return OPERATOR_CANCELLED;
619 }
621 if (ks == nullptr) {
622 return OPERATOR_CANCELLED;
623 }
624
625 return delete_key_using_keying_set(C, op, ks);
626}
627
629{
631 if (!scene) {
632 return OPERATOR_CANCELLED;
633 }
634 float cfra = BKE_scene_frame_get(scene);
635 int num_channels;
636 const bool confirm = op->flag & OP_IS_INVOKE;
637
638 /* Try to delete keyframes for the channels specified by KeyingSet. */
639 num_channels = animrig::apply_keyingset(
640 C, nullptr, ks, animrig::ModifyKeyMode::DELETE_KEY, cfra);
641 if (G.debug & G_DEBUG) {
642 printf("KeyingSet '%s' - Successfully removed %d Keyframes\n", ks->name, num_channels);
643 }
644
645 /* Report failure or do updates? */
646 if (num_channels < 0) {
647 BKE_report(op->reports, RPT_ERROR, "No suitable context info for active keying set");
648 return OPERATOR_CANCELLED;
649 }
650
651 if (num_channels > 0) {
653
654 /* VSE notifiers. */
657 }
658
659 if (confirm) {
660 /* If called by invoke (from the UI), make a note that we've removed keyframes. */
661 if (num_channels > 0) {
663 RPT_INFO,
664 "Successfully removed %d keyframes for keying set '%s'",
665 num_channels,
666 ks->name);
667 }
668 else {
669 BKE_report(op->reports, RPT_WARNING, "Keying set failed to remove any keyframes");
670 }
671 }
672 return OPERATOR_FINISHED;
673}
674
676{
677 PropertyRNA *prop;
678
679 /* identifiers */
680 ot->name = "Delete Keying-Set Keyframe";
681 ot->idname = "ANIM_OT_keyframe_delete";
682 ot->description =
683 "Delete keyframes on the current frame for all properties in the specified Keying Set";
684
685 /* callbacks */
686 ot->exec = delete_key_exec;
688
689 /* flags */
691
692 /* keyingset to use (dynamic enum) */
693 prop = RNA_def_enum(
694 ot->srna, "type", rna_enum_dummy_DEFAULT_items, 0, "Keying Set", "The Keying Set to use");
697 ot->prop = prop;
698}
699
701{
702 PropertyRNA *prop;
703
704 /* identifiers */
705 ot->name = "Delete Keying-Set Keyframe (by name)";
706 ot->idname = "ANIM_OT_keyframe_delete_by_name";
707 ot->description = "Alternate access to 'Delete Keyframe' for keymaps to use";
708
709 /* callbacks */
710 ot->exec = delete_key_exec;
712
713 /* flags */
715
716 /* keyingset to use (idname) */
717 prop = RNA_def_string(
718 ot->srna, "type", nullptr, MAX_ID_NAME - 2, "Keying Set", "The Keying Set to use");
722 ot->prop = prop;
723}
724
726
727/* -------------------------------------------------------------------- */
730
731/* While in pose mode, the selection of bones has to be considered. */
732static bool can_delete_fcurve(FCurve *fcu, Object *ob)
733{
734 bool can_delete = false;
735 /* in pose mode, only delete the F-Curve if it belongs to a selected bone */
736 if (ob->mode & OB_MODE_POSE) {
737 const StringRefNull rna_path = fcu->rna_path();
738 /* Get bone-name, and check if this bone is selected. */
739 bPoseChannel *pchan = nullptr;
740 char bone_name[sizeof(pchan->name)];
741 if (BLI_str_quoted_substr(rna_path.c_str(), "pose.bones[", bone_name, sizeof(bone_name))) {
742 pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
743 /* Delete if bone is selected. */
744 if ((pchan) && (pchan->bone_get(*ob))) {
745 /* TODO(Sybren): use bone_is_selected() to avoid treating invisible bone as selected. */
746 if (pchan->flag & POSE_SELECTED) {
747 can_delete = true;
748 }
749 }
750 }
751 }
752 else {
753 /* object mode - all of Object's F-Curves are affected */
754 /* TODO: this logic isn't solid. Only delete FCurves of the object, not of bones in this case.
755 */
756 can_delete = true;
757 }
758
759 return can_delete;
760}
761
763{
764 using namespace blender::animrig;
765 bool changed = false;
766
767 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
768 /* just those in active action... */
769 if ((ob->adt) && (ob->adt->action)) {
770 AnimData *adt = ob->adt;
771 bAction *dna_action = adt->action;
772
773 Action &action = dna_action->wrap();
774 Vector<FCurve *> fcurves_to_delete;
776 if (can_delete_fcurve(&fcurve, ob)) {
777 fcurves_to_delete.append(&fcurve);
778 }
779 });
780 for (FCurve *fcurve : fcurves_to_delete) {
781 action_fcurve_remove(action, *fcurve);
783 changed = true;
784 }
785 DEG_id_tag_update(&ob->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
786 }
787 }
789
790 if (!changed) {
791 return OPERATOR_CANCELLED;
792 }
793
794 /* send updates */
796
797 return OPERATOR_FINISHED;
798}
799
801 wmOperator *op,
802 const wmEvent * /*event*/)
803{
804 if (RNA_boolean_get(op->ptr, "confirm")) {
806 op,
807 IFACE_("Remove animation from selected objects?"),
808 nullptr,
811 false);
812 }
813 return clear_anim_v3d_exec(C, op);
814}
815
817{
818 /* identifiers */
819 ot->name = "Remove Animation";
820 ot->description = "Remove all keyframe animation for selected objects";
821 ot->idname = "ANIM_OT_keyframe_clear_v3d";
822
823 /* callbacks */
826
828
829 /* flags */
832}
833
835
836/* -------------------------------------------------------------------- */
839
841{
842 Vector<std::string> selected_strips_rna_paths;
843 for (PointerRNA &id_ptr : selection) {
844 if (RNA_struct_is_a(id_ptr.type, RNA_Strip)) {
845 std::optional<std::string> rna_path = RNA_path_from_ID_to_struct(&id_ptr);
846 selected_strips_rna_paths.append(*rna_path);
847 }
848 }
849 return selected_strips_rna_paths;
850}
851
853{
854 for (PointerRNA &id_ptr : selection) {
855 if (RNA_struct_is_a(id_ptr.type, RNA_Strip)) {
856 blender::Strip *strip = static_cast<blender::Strip *>(id_ptr.data);
858 }
859 }
860}
861
862static bool fcurve_belongs_to_strip(const FCurve &fcurve, const std::string &strip_path)
863{
864 return std::strncmp(fcurve.rna_path().c_str(), strip_path.c_str(), strip_path.length()) == 0;
865}
866
868
869/* -------------------------------------------------------------------- */
872
874{
875 using namespace blender::animrig;
876 bool changed = false;
877
879
880 Vector<PointerRNA> selection;
881 Vector<std::string> selected_strips_rna_paths;
882 get_selection(C, &selection);
883 selected_strips_rna_paths = get_selected_strips_rna_paths(selection);
884
885 if (selected_strips_rna_paths.is_empty()) {
886 BKE_reportf(op->reports, RPT_WARNING, "No strips selected");
887 return OPERATOR_CANCELLED;
888 }
889
890 if (!scene->adt || !scene->adt->action || (scene->adt->slot_handle == Slot::unassigned)) {
891 BKE_reportf(op->reports, RPT_ERROR, "Scene has no animation data or active action");
892 return OPERATOR_CANCELLED;
893 }
894
895 AnimData *adt = scene->adt;
896 bAction *dna_action = adt->action;
897
898 Action &action = dna_action->wrap();
899 Vector<FCurve *> fcurves_to_delete;
901 for (const std::string &strip_path : selected_strips_rna_paths) {
902 if (fcurve_belongs_to_strip(fcurve, strip_path)) {
903 fcurves_to_delete.append(&fcurve);
904 break;
905 }
906 }
907 });
908 for (FCurve *fcurve : fcurves_to_delete) {
909 action_fcurve_remove(action, *fcurve);
910 changed = true;
911 }
912
913 if (!changed) {
914 return OPERATOR_CANCELLED;
915 }
916
917 if (scene->adt->action) {
918 DEG_id_tag_update(&scene->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
919 }
920 invalidate_strip_caches(selection, scene);
923
924 return OPERATOR_FINISHED;
925}
926
928 wmOperator *op,
929 const wmEvent * /*event*/)
930{
931 if (RNA_boolean_get(op->ptr, "confirm")) {
933 op,
934 IFACE_("Remove animation from selected strips?"),
935 nullptr,
938 false);
939 }
940 return clear_anim_vse_exec(C, op);
941}
943{
944 /* identifiers */
945 ot->name = "Remove Animation";
946 ot->description = "Remove all keyframe animation for selected strips";
947 ot->idname = "ANIM_OT_keyframe_clear_vse";
948
949 /* callbacks */
952
954
955 /* flags */
958}
959
961
962/* -------------------------------------------------------------------- */
965
966static bool can_delete_key(FCurve *fcu, Object *ob, ReportList *reports)
967{
968 /* don't touch protected F-Curves */
969 if (!fcu || BKE_fcurve_is_protected(*fcu)) {
970 BKE_reportf(reports,
972 "Not deleting keyframe for locked F-Curve '%s', object '%s'",
973 fcu->rna_path().c_str(),
974 ob->id.name + 2);
975 return false;
976 }
977
978 /* Special exception for bones, as this makes this operator more convenient to use
979 * NOTE: This is only done in pose mode.
980 * In object mode, we're dealing with the entire object.
981 * TODO: While this means bone animation is not deleted of all bones while in pose mode. Running
982 * the code on the armature object WILL delete keys of all bones.
983 */
984 if (ob->mode & OB_MODE_POSE) {
985 bPoseChannel *pchan = nullptr;
986
987 /* Get bone-name, and check if this bone is selected. */
988 char bone_name[sizeof(pchan->name)];
990 fcu->rna_path().c_str(), "pose.bones[", bone_name, sizeof(bone_name)))
991 {
992 return false;
993 }
994 pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
995
996 /* skip if bone is not selected */
997 if ((pchan) && (pchan->bone_get(*ob))) {
998 bArmature *arm = id_cast<bArmature *>(ob->data);
999
1000 /* Only selected bones should be affected. */
1001 if (!animrig::bone_is_selected(arm, {pchan, pchan->bone_get(*ob)})) {
1002 return false;
1003 }
1004 }
1005 }
1006
1007 return true;
1008}
1009
1010static bool can_delete_scene_key(FCurve *fcu, Scene *scene, wmOperator *op)
1011{
1012 /* Don't touch protected F-Curves. */
1013 if (!fcu || BKE_fcurve_is_protected(*fcu)) {
1014 BKE_reportf(op->reports,
1016 "Not deleting keyframe for locked F-Curve '%s', scene '%s'",
1017 fcu->rna_path().c_str(),
1018 scene->id.name + 2);
1019 return false;
1020 }
1021 return true;
1022}
1023
1025
1026/* -------------------------------------------------------------------- */
1029
1031{
1032 using namespace blender::animrig;
1034 const float cfra = BKE_scene_frame_get(scene);
1035
1036 Vector<PointerRNA> selection;
1037 Vector<std::string> selected_strips_rna_paths;
1038 get_selection(C, &selection);
1039 selected_strips_rna_paths = get_selected_strips_rna_paths(selection);
1040
1041 if (selected_strips_rna_paths.is_empty()) {
1042 BKE_reportf(op->reports, RPT_WARNING, "No strips selected");
1043 return OPERATOR_CANCELLED;
1044 }
1045
1046 const bool confirm = op->flag & OP_IS_INVOKE;
1047 if (!scene->adt || !scene->adt->action || (scene->adt->slot_handle == Slot::unassigned)) {
1048 BKE_reportf(op->reports, RPT_ERROR, "Scene has no animation data or active action");
1049 return OPERATOR_CANCELLED;
1050 }
1051
1052 AnimData *adt = scene->adt;
1053 bAction *act = adt->action;
1054 Action &action = act->wrap();
1055
1056 const float cfra_unmap = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
1057
1058 VectorSet<std::string> modified_strips;
1059 Vector<FCurve *> modified_fcurves;
1060
1061 foreach_fcurve_in_action_slot_editable(action, adt->slot_handle, [&](FCurve &fcurve) {
1062 std::string changed_strip;
1063 for (const std::string &strip_path : selected_strips_rna_paths) {
1064 if (fcurve_belongs_to_strip(fcurve, strip_path)) {
1065 changed_strip = strip_path;
1066 break;
1067 }
1068 }
1069 if (!can_delete_scene_key(&fcurve, scene, op) || changed_strip.empty()) {
1070 return;
1071 }
1072 if (animrig::fcurve_delete_keyframe_at_time(&fcurve, cfra_unmap)) {
1073 modified_fcurves.append(&fcurve);
1074 modified_strips.add(changed_strip);
1075 }
1076 });
1077
1078 for (FCurve *fcurve : modified_fcurves) {
1079 if (BKE_fcurve_is_empty(fcurve)) {
1080 action_fcurve_remove(action, *fcurve);
1081 }
1082 }
1083
1084 if (scene->adt->action) {
1085 /* The Action might have been unassigned, if it is legacy and the last
1086 * F-Curve was removed. */
1087 DEG_id_tag_update(&scene->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
1088 }
1089
1090 if (!modified_strips.is_empty()) {
1091 /* Key-frames on strips has been moved, so make sure related editors are informed. */
1094 }
1095
1096 invalidate_strip_caches(selection, scene);
1097
1098 if (confirm) {
1099 /* If called by invoke (from the UI), make a note that we've removed keyframes. */
1100 if (modified_strips.is_empty()) {
1101 const std::string msg = fmt::format(
1102 fmt::runtime(RPT_("No keyframes removed from {} strip(s)")),
1103 selected_strips_rna_paths.size());
1104 BKE_report(op->reports, RPT_WARNING, msg.c_str());
1105 return OPERATOR_CANCELLED;
1106 }
1107
1108 const std::string msg = fmt::format(
1109 fmt::runtime(RPT_("{} strip(s) successfully had {} keyframes removed")),
1110 modified_strips.size(),
1111 modified_fcurves.size());
1112 BKE_report(op->reports, RPT_INFO, msg.c_str());
1113 }
1114
1115 return OPERATOR_FINISHED;
1116}
1117
1119{
1122
1123 if (ks == nullptr) {
1125 }
1126
1127 return delete_key_using_keying_set(C, op, ks);
1128}
1129
1131 wmOperator *op,
1132 const wmEvent * /*event*/)
1133{
1134 if (RNA_boolean_get(op->ptr, "confirm")) {
1136 op,
1137 IFACE_("Delete keyframes from selected strips?"),
1138 nullptr,
1139 IFACE_("Delete"),
1141 false);
1142 }
1143 return delete_key_vse_exec(C, op);
1144}
1145
1147{
1148 /* identifiers */
1149 ot->name = "Delete Keyframe";
1150 ot->description = "Remove keyframes on current frame for selected strips";
1151 ot->idname = "ANIM_OT_keyframe_delete_vse";
1152
1153 /* callbacks */
1156
1158
1159 /* flags */
1162}
1163
1165
1166/* -------------------------------------------------------------------- */
1172
1174{
1175 using namespace blender::animrig;
1176 Scene *scene = CTX_data_scene(C);
1177 const float cfra = BKE_scene_frame_get(scene);
1178
1179 int selected_objects_len = 0;
1180 int selected_objects_success_len = 0;
1181 int success_multi = 0;
1182
1183 const bool confirm = op->flag & OP_IS_INVOKE;
1184
1185 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
1186 int success = 0;
1187
1188 selected_objects_len += 1;
1189
1190 /* just those in active action... */
1191 if ((ob->adt) && (ob->adt->action)) {
1192 AnimData *adt = ob->adt;
1193 bAction *act = adt->action;
1194 const float cfra_unmap = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP);
1195
1196 Action &action = act->wrap();
1197 Vector<FCurve *> modified_fcurves;
1198 foreach_fcurve_in_action_slot_editable(action, adt->slot_handle, [&](FCurve &fcurve) {
1199 if (!can_delete_key(&fcurve, ob, op->reports)) {
1200 return;
1201 }
1202 if (animrig::fcurve_delete_keyframe_at_time(&fcurve, cfra_unmap)) {
1203 modified_fcurves.append(&fcurve);
1204 }
1205 });
1206
1207 success += modified_fcurves.size();
1208 for (FCurve *fcurve : modified_fcurves) {
1209 if (BKE_fcurve_is_empty(fcurve)) {
1210 action_fcurve_remove(action, *fcurve);
1211 }
1212 }
1213
1214 if (ob->adt->action) {
1215 /* The Action might have been unassigned, if it is legacy and the last
1216 * F-Curve was removed. */
1217 DEG_id_tag_update(&ob->adt->action->id, ID_RECALC_ANIMATION_NO_FLUSH);
1218 }
1219 }
1220
1221 /* Only for reporting. */
1222 if (success) {
1223 selected_objects_success_len += 1;
1224 success_multi += success;
1225 }
1226
1228 }
1230
1231 if (selected_objects_success_len) {
1232 /* send updates */
1234 }
1235
1236 if (confirm) {
1237 /* if called by invoke (from the UI), make a note that we've removed keyframes */
1238 if (selected_objects_success_len) {
1239 BKE_reportf(op->reports,
1240 RPT_INFO,
1241 "%d object(s) successfully had %d keyframes removed",
1242 selected_objects_success_len,
1243 success_multi);
1244 }
1245 else {
1247 op->reports, RPT_ERROR, "No keyframes removed from %d object(s)", selected_objects_len);
1248 }
1249 }
1250 return OPERATOR_FINISHED;
1251}
1252
1254{
1255 Scene *scene = CTX_data_scene(C);
1257
1258 if (ks == nullptr) {
1260 }
1261
1262 return delete_key_using_keying_set(C, op, ks);
1263}
1264
1266 wmOperator *op,
1267 const wmEvent * /*event*/)
1268{
1269 if (RNA_boolean_get(op->ptr, "confirm")) {
1271 op,
1272 IFACE_("Delete keyframes from selected objects?"),
1273 nullptr,
1274 IFACE_("Delete"),
1276 false);
1277 }
1278 return delete_key_v3d_exec(C, op);
1279}
1280
1282{
1283 /* identifiers */
1284 ot->name = "Delete Keyframe";
1285 ot->description = "Remove keyframes on current frame for selected objects and bones";
1286 ot->idname = "ANIM_OT_keyframe_delete_v3d";
1287
1288 /* callbacks */
1291
1293
1294 /* flags */
1297}
1298
1300
1301/* -------------------------------------------------------------------- */
1304
1306{
1307 using namespace blender::animrig;
1308 Main *bmain = CTX_data_main(C);
1310 if (!scene) {
1311 return OPERATOR_CANCELLED;
1312 }
1313 ToolSettings *ts = scene->toolsettings;
1314 PointerRNA ptr = {};
1315 PropertyRNA *prop = nullptr;
1316 ui::Button *but;
1319 bool changed = false;
1320 int index;
1321 const bool all = RNA_boolean_get(op->ptr, "all");
1323
1324 flag = get_keyframing_flags(scene);
1325
1326 if (!(but = ui::context_active_but_prop_get(C, &ptr, &prop, &index))) {
1327 /* pass event on if no active button found */
1329 }
1330
1331 if ((ptr && ptr.has_owner_id() && prop) && RNA_property_anim_editable(&ptr, prop)) {
1332 if (ptr.type == RNA_NlaStrip) {
1333 /* Handle special properties for NLA Strips, whose F-Curves are stored on the
1334 * strips themselves. These are stored separately or else the properties will
1335 * not have any effect.
1336 */
1337 NlaStrip *strip = static_cast<NlaStrip *>(ptr.data);
1339
1340 if (fcu) {
1342 ptr,
1343 *prop,
1344 *fcu,
1345 anim_eval_context.eval_time,
1347 eInsertKeyFlags{});
1351 }
1352 }
1353 else {
1354 /* This special case exists because we have to allow drivers and clearing the
1355 * PROP_ANIMATABLE flag from the properties would prevent that. */
1356 BKE_report(op->reports,
1357 RPT_ERROR,
1358 "This property cannot be animated as it will not get updated correctly");
1359 }
1360 }
1361 else if (button_flag_is_set(but, ui::BUT_DRIVEN)) {
1362 /* Driven property - Find driver */
1363 FCurve *fcu;
1364 bool driven, special;
1365
1367 C, &ptr, prop, index, nullptr, nullptr, &driven, &special);
1368
1369 if (fcu && driven) {
1370 const float driver_frame = evaluate_driver_from_rna_pointer(
1371 &anim_eval_context, &ptr, prop, fcu);
1373 ptr,
1374 *prop,
1375 *fcu,
1376 driver_frame,
1382 }
1383 }
1384 }
1385 else {
1386 /* standard properties */
1387 if (const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop)) {
1388 const char *identifier = RNA_property_identifier(prop);
1389 const std::optional<StringRefNull> group = default_channel_group_for_path(&ptr,
1390 identifier);
1391
1393
1394 /* NOTE: `index == -1` is a magic number, meaning either "operate on all
1395 * elements" or "not an array property". */
1396 const std::optional<int> array_index = (all || index < 0) ? std::nullopt :
1397 std::optional(index);
1398 PointerRNA owner_ptr = RNA_id_pointer_create(ptr.owner_id);
1400 &owner_ptr,
1401 group,
1402 {{*path, {}, array_index}},
1403 std::nullopt,
1404 anim_eval_context,
1406 flag);
1407 changed = result.get_count(SingleKeyingResult::SUCCESS) != 0;
1408 }
1409 else {
1410 BKE_report(op->reports,
1412 "Failed to resolve path to property, "
1413 "try manually specifying this using a Keying Set instead");
1414 }
1415 }
1416 }
1417 else {
1418 if (prop && !RNA_property_anim_editable(&ptr, prop)) {
1419 BKE_reportf(op->reports,
1421 "\"%s\" property cannot be animated",
1423 }
1424 else {
1425 BKE_reportf(op->reports,
1427 "Button does not appear to have any property information attached (ptr.data = "
1428 "%p, prop = %p)",
1429 ptr.data,
1430 static_cast<void *>(prop));
1431 }
1432 }
1433
1434 if (changed) {
1435 ID *id = ptr.owner_id;
1436 AnimData *adt = BKE_animdata_from_id(id);
1437 if (adt->action != nullptr) {
1439 }
1441
1442 /* send updates */
1444
1445 /* send notifiers that keyframes have been changed */
1447 }
1448
1449 return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1450}
1451
1453{
1454 /* identifiers */
1455 ot->name = "Insert Keyframe (Buttons)";
1456 ot->idname = "ANIM_OT_keyframe_insert_button";
1457 ot->description = "Insert a keyframe for current UI-active property";
1458
1459 /* callbacks */
1462
1463 /* flags */
1465
1466 /* properties */
1467 RNA_def_boolean(ot->srna, "all", true, "All", "Insert a keyframe for all element of the array");
1468}
1469
1471
1472/* -------------------------------------------------------------------- */
1475
1477{
1479 if (!scene) {
1480 return OPERATOR_CANCELLED;
1481 }
1482 PointerRNA ptr = {};
1483 PropertyRNA *prop = nullptr;
1484 Main *bmain = CTX_data_main(C);
1485 const float cfra = BKE_scene_frame_get(scene);
1486 bool changed = false;
1487 int index;
1488 const bool all = RNA_boolean_get(op->ptr, "all");
1489
1490 if (!ui::context_active_but_prop_get(C, &ptr, &prop, &index)) {
1491 /* pass event on if no active button found */
1493 }
1494
1495 if (ptr && ptr.has_owner_id() && prop) {
1496 if (BKE_nlastrip_has_curves_for_property(&ptr, prop)) {
1497 /* Handle special properties for NLA Strips, whose F-Curves are stored on the
1498 * strips themselves. These are stored separately or else the properties will
1499 * not have any effect.
1500 */
1501 ID *id = ptr.owner_id;
1502 NlaStrip *strip = static_cast<NlaStrip *>(ptr.data);
1503 FCurve *fcu = BKE_fcurve_find(&strip->fcurves, RNA_property_identifier(prop), 0);
1504
1505 if (fcu) {
1506 if (BKE_fcurve_is_protected(*fcu)) {
1508 op->reports,
1510 "Not deleting keyframe for locked F-Curve for NLA Strip influence on %s - %s '%s'",
1511 strip->name,
1512 BKE_idtype_idcode_to_name(id->id_type()),
1513 id->name + 2);
1514 }
1515 else {
1516 /* remove the keyframe directly
1517 * NOTE: cannot use delete_keyframe_fcurve(), as that will free the curve,
1518 * and delete_keyframe() expects the FCurve to be part of an action
1519 */
1520 bool found = false;
1521 int i;
1522
1523 /* try to find index of beztriple to get rid of */
1524 i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
1525 if (found) {
1526 /* delete the key at the index (will sanity check + do recalc afterwards) */
1527 BKE_fcurve_delete_key(fcu, i);
1529 changed = true;
1530 }
1531 }
1532 }
1533 }
1534 else {
1535 /* standard properties */
1536 if (const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop)) {
1537 RNAPath rna_path = {*path, std::nullopt, index};
1538 if (all) {
1539 /* nullopt indicates operating on the entire array (or the property itself otherwise). */
1540 rna_path.index = std::nullopt;
1541 }
1542
1543 changed = animrig::delete_keyframe(bmain, op->reports, ptr.owner_id, rna_path, cfra) != 0;
1544 }
1545 else if (G.debug & G_DEBUG) {
1546 printf("Button Delete-Key: no path to property\n");
1547 }
1548 }
1549 }
1550 else if (G.debug & G_DEBUG) {
1551 printf("ptr.data = %p, prop = %p\n", ptr.data, static_cast<void *>(prop));
1552 }
1553
1554 if (changed) {
1555 /* send updates */
1557
1558 /* send notifiers that keyframes have been changed */
1560 }
1561
1562 return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1563}
1564
1566{
1567 /* identifiers */
1568 ot->name = "Delete Keyframe (Buttons)";
1569 ot->idname = "ANIM_OT_keyframe_delete_button";
1570 ot->description = "Delete current keyframe of current UI-active property";
1571
1572 /* callbacks */
1575
1576 /* flags */
1578
1579 /* properties */
1580 RNA_def_boolean(ot->srna, "all", true, "All", "Delete keyframes from all elements of the array");
1581}
1582
1584
1585/* -------------------------------------------------------------------- */
1588
1590{
1591 PointerRNA ptr = {};
1592 PropertyRNA *prop = nullptr;
1593 Main *bmain = CTX_data_main(C);
1594 bool changed = false;
1595 int index;
1596 const bool all = RNA_boolean_get(op->ptr, "all");
1597
1598 if (!ui::context_active_but_prop_get(C, &ptr, &prop, &index)) {
1599 /* pass event on if no active button found */
1601 }
1602
1603 if (ptr && ptr.has_owner_id() && prop) {
1604 if (const std::optional<std::string> path = RNA_path_from_ID_to_property(&ptr, prop)) {
1605 RNAPath rna_path = {*path, std::nullopt, index};
1606 if (all) {
1607 /* nullopt indicates operating on the entire array (or the property itself otherwise). */
1608 rna_path.index = std::nullopt;
1609 }
1610
1611 changed |= (animrig::clear_keyframe(bmain, op->reports, ptr.owner_id, rna_path) != 0);
1612 }
1613 else if (G.debug & G_DEBUG) {
1614 printf("Button Clear-Key: no path to property\n");
1615 }
1616 }
1617 else if (G.debug & G_DEBUG) {
1618 printf("ptr.data = %p, prop = %p\n", ptr.data, static_cast<void *>(prop));
1619 }
1620
1621 if (changed) {
1622 /* send updates */
1624
1625 /* send notifiers that keyframes have been changed */
1627 }
1628
1629 return (changed) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
1630}
1631
1633{
1634 /* identifiers */
1635 ot->name = "Clear Keyframe (Buttons)";
1636 ot->idname = "ANIM_OT_keyframe_clear_button";
1637 ot->description = "Clear all keyframes on the currently active property";
1638
1639 /* callbacks */
1642
1643 /* flags */
1645
1646 /* properties */
1647 RNA_def_boolean(ot->srna, "all", true, "All", "Clear keyframes from all elements of the array");
1648}
1649
1651
1652/* -------------------------------------------------------------------- */
1655
1657 PropertyRNA *prop,
1658 FCurve *fcu,
1659 const AnimationEvalContext *anim_eval_context)
1660{
1661 PathResolvedRNA anim_rna;
1662 anim_rna.ptr = ptr;
1663 anim_rna.prop = prop;
1664 anim_rna.prop_index = fcu->array_index;
1665
1666 int index = fcu->array_index;
1667 Vector<float> values = animrig::get_rna_values(&ptr, prop);
1668
1669 float fcurve_val = calculate_fcurve(&anim_rna, fcu, anim_eval_context);
1670 float cur_val = (index >= 0 && index < values.size()) ? values[index] : 0.0f;
1671
1672 return !compare_ff_relative(fcurve_val, cur_val, FLT_EPSILON, 64);
1673}
1674
1677{
1678 KeyingSet *ks = nullptr;
1679 const int prop_type = RNA_property_type(prop);
1680 if (prop_type == PROP_ENUM) {
1681 int type = RNA_property_enum_get(op->ptr, prop);
1682 ks = ANIM_keyingset_get_from_enum_type(scene, type);
1683 if (ks == nullptr) {
1684 BKE_report(op->reports, RPT_ERROR, "No active Keying Set");
1685 }
1686 }
1687 else if (prop_type == PROP_STRING) {
1688 char type_id[MAX_ID_NAME - 2];
1689 RNA_property_string_get(op->ptr, prop, type_id);
1690
1691 if (STREQ(type_id, "__ACTIVE__")) {
1693 }
1694 else {
1695 ks = ANIM_keyingset_get_from_idname(scene, type_id);
1696 }
1697
1698 if (ks == nullptr) {
1699 BKE_reportf(op->reports, RPT_ERROR, "Keying set '%s' not found", type_id);
1700 }
1701 }
1702 else {
1703 BLI_assert(0);
1704 }
1705 return ks;
1706}
1707
1709
1710} // namespace blender
Functions and classes to work with Actions.
Functionality to iterate an Action in various ways.
Functions to work with AnimData.
Functions to deal with Armatures.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Functions to work with drivers.
Functions to modify FCurves.
Functions to insert, delete or modify keyframes.
Functionality to interact with keying sets.
Helper functions for animation to interact with the RNA system.
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
#define RPT_(msgid)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
ID and Library types, which are fundamental for SDNA.
#define MAX_ID_NAME
Definition DNA_ID.h:367
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER
Definition WM_types.hh:456
#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 NA_REMOVED
Definition WM_types.hh:637
#define ND_KEYS
Definition WM_types.hh:504
#define ND_KEYFRAME
Definition WM_types.hh:537
#define NC_OBJECT
Definition WM_types.hh:392
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define MEM_realloc_zeroed(vmemh, len)
bool add(const Key &key)
Definition BLI_set.hh:248
bool add(const Key &key)
int64_t size() const
void append(const T &value)
bool is_empty() const
void extend(Span< T > array)
Span< T > as_span() const
void merge(const CombinedKeyingResult &other)
int get_count(const SingleKeyingResult result) const
void generate_reports(ReportList *reports, eReportType report_level=RPT_ERROR)
static constexpr slot_handle_t unassigned
#define FLT_EPSILON
bool all(VecOp< bool, D >) RET
bool action_fcurve_remove(Action &action, FCurve &fcu)
std::optional< StringRefNull > default_channel_group_for_path(const PointerRNA *animated_struct, StringRef prop_rna_path)
void update_autoflags_fcurve_direct(FCurve *fcu, PropertyType prop_type)
KeyingSet * scene_get_active_keyingset(const Scene *scene)
Vector< RNAPath > get_keyable_id_property_paths(const PointerRNA &ptr)
Definition anim_rna.cc:202
Vector< float > get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
Definition anim_rna.cc:26
bool bone_is_selected(const bArmature *armature, const Bone *bone)
int clear_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path)
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path, float cfra)
Main Delete Key-Framing API call.
bool fcurve_delete_keyframe_at_time(FCurve *fcurve, float time)
std::optional< eRotationModes > get_rotation_mode_from_rna_pointer(const PointerRNA &ptr)
Definition anim_rna.cc:152
bool keyingset_find_id(KeyingSet *keyingset, ID *id)
SingleKeyingResult insert_keyframe_direct(PointerRNA &ptr, PropertyRNA &prop, FCurve &fcu, float fcurve_frame, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag)
Secondary Insert Key-framing API call.
int apply_keyingset(bContext *C, Vector< PointerRNA > *sources, KeyingSet *keyingset, ModifyKeyMode mode, float cfra)
void foreach_fcurve_in_action_slot_editable(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
void generate_single_keying_result_report(const SingleKeyingResult result, ReportList *reports)
eInsertKeyFlags get_keyframing_flags(Scene *scene)
float evaluate_driver_from_rna_pointer(const AnimationEvalContext *anim_eval_context, PointerRNA *ptr, PropertyRNA *prop, const FCurve *fcu)
Definition driver.cc:16
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 free(Subdiv *subdiv)
Definition subdiv.cc:192
Scene * scene_or_sequencer_scene_from_context(const bContext &C)
bool mode_set(bContext *C, eObjectMode mode)
VectorSet< Strip * > selected_strips_from_context(bContext *C)
void relations_invalidate_cache(Scene *scene, Strip *strip)
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void context_update_anim_flag(const bContext *C)
Button * context_active_but_prop_get(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
BMesh Iterators.
static wmOperatorStatus insert_key(bContext *C, wmOperator *op)
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
const EnumPropertyItem * ANIM_keying_sets_enum_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void ED_keyframes_add(FCurve *fcu, int num_keys_to_add)
MINLINE int compare_ff_relative(float a, float b, float max_diff, int max_ulps)
static wmOperatorStatus delete_key_v3d_exec(bContext *C, wmOperator *op)
void ANIM_keyingset_visit_for_search_no_poll(const bContext *C, PointerRNA *, PropertyRNA *, const char *, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static Vector< RNAPath > construct_rna_paths(PointerRNA *ptr)
@ RPT_WARNING
Definition BKE_report.hh:40
float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, eNlaTime_ConvertModes mode)
Scene * CTX_data_sequencer_scene(const bContext *C)
static wmOperatorStatus delete_key_vse_exec(bContext *C, wmOperator *op)
void ANIM_OT_keyframe_insert_by_name(wmOperatorType *ot)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static wmOperatorStatus delete_key_using_keying_set(bContext *C, wmOperator *op, KeyingSet *ks)
static wmOperatorStatus clear_anim_v3d_exec(bContext *C, wmOperator *)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
bool bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, size_t result_maxncpy)
static wmOperatorStatus insert_key_with_keyingset(bContext *C, wmOperator *op, KeyingSet *ks)
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
float calculate_fcurve(PathResolvedRNA *anim_rna, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
void ANIM_OT_keyframe_delete_by_name(wmOperatorType *ot)
PointerRNA RNA_id_pointer_create(ID *id)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus clear_key_button_exec(bContext *C, wmOperator *op)
bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, const AnimationEvalContext *anim_eval_context)
Lesser Keyframe Checking API call.
@ NLATIME_CONVERT_UNMAP
Definition BKE_nla.hh:560
bool ED_operator_areaactive(bContext *C)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
Definition rna_path.cc:1078
void BKE_fcurve_delete_key(FCurve *fcu, int index)
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 insert_key_button_exec(bContext *C, wmOperator *op)
void update_autoflags_fcurve(FCurve *fcu, bContext *C, ReportList *reports, PointerRNA *ptr)
Lesser Key-framing API call.
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void ANIM_OT_keyframe_delete_button(wmOperatorType *ot)
@ USER_ANIM_KEY_CHANNEL_CUSTOM_PROPERTIES
@ USER_ANIM_KEY_CHANNEL_ROTATION
@ USER_ANIM_KEY_CHANNEL_ROTATION_MODE
@ USER_ANIM_KEY_CHANNEL_SCALE
@ USER_ANIM_KEY_CHANNEL_LOCATION
KeyingSet * ANIM_keyingset_get_from_enum_type(Scene *scene, int type)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
static bool can_delete_key(FCurve *fcu, Object *ob, ReportList *reports)
static Vector< std::string > get_selected_strips_rna_paths(Vector< PointerRNA > &selection)
bool id_can_have_animdata(const ID *id)
Definition anim_data.cc:78
KeyingSet * ANIM_keyingset_get_from_idname(Scene *scene, const char *idname)
static bool can_delete_scene_key(FCurve *fcu, Scene *scene, wmOperator *op)
static wmOperatorStatus insert_key_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus delete_key_v3d_without_keying_set(bContext *C, wmOperator *op)
static wmOperatorStatus insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
@ CTX_MODE_OBJECT
SpaceSeq * CTX_wm_space_seq(const bContext *C)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
Global G
Definition blender.cc:57
static wmOperatorStatus delete_key_vse_without_keying_set(bContext *C, wmOperator *op)
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
void WM_operator_properties_confirm_or_exec(wmOperatorType *ot)
bool BKE_nlastrip_has_curves_for_property(const PointerRNA *ptr, const PropertyRNA *prop)
bool BKE_fcurve_is_protected(const FCurve &fcu)
static wmOperatorStatus delete_key_button_exec(bContext *C, wmOperator *op)
bool ED_operator_sequencer_scene_editable(bContext *C)
bool RNA_property_anim_editable(const PointerRNA *ptr, PropertyRNA *prop_orig)
@ PROP_STRING_SEARCH_SUGGESTION
Definition RNA_types.hh:883
@ PROP_STRING
Definition RNA_types.hh:213
void BKE_fcurve_handles_recalc(FCurve &fcu)
void DEG_id_tag_update(ID *id, unsigned int flags)
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void RNA_def_property_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
void ANIM_deselect_keys_in_animation_editors(bContext *C)
Definition anim_deps.cc:487
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static wmOperatorStatus insert_key_exec(bContext *C, wmOperator *op)
Object * CTX_data_edit_object(const bContext *C)
void ANIM_OT_keyframe_delete_v3d(wmOperatorType *ot)
static bool modify_key_op_poll(bContext *C)
void ANIM_OT_keyframe_delete_vse(wmOperatorType *ot)
static wmOperatorStatus delete_key_vse_invoke(bContext *C, wmOperator *op, const wmEvent *)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static bool get_selection(bContext *C, Vector< PointerRNA > *r_selection)
const EnumPropertyItem rna_enum_dummy_DEFAULT_items[]
Definition rna_rna.cc:34
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
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)
bool CTX_data_selected_pose_bones(const bContext *C, Vector< PointerRNA > *list)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static bool can_delete_fcurve(FCurve *fcu, Object *ob)
static wmOperatorStatus clear_anim_vse_invoke(bContext *C, wmOperator *op, const wmEvent *)
void ANIM_OT_keyframe_insert_menu(wmOperatorType *ot)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void ANIM_OT_keyframe_clear_v3d(wmOperatorType *ot)
Main * CTX_data_main(const bContext *C)
static void invalidate_strip_caches(Vector< PointerRNA > selection, Scene *scene)
void ANIM_OT_keyframe_clear_vse(wmOperatorType *ot)
@ ID_RECALC_ANIMATION_NO_FLUSH
Definition DNA_ID.h:1178
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ PROP_HIDDEN
Definition RNA_types.hh:408
static wmOperatorStatus clear_anim_vse_exec(bContext *C, wmOperator *op)
void ANIM_OT_keyframe_insert(wmOperatorType *ot)
static wmOperatorStatus keyframe_insert_with_keyingset_exec(bContext *C, wmOperator *op)
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus delete_key_v3d_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool fcurve_belongs_to_strip(const FCurve &fcurve, const std::string &strip_path)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
bool BKE_fcurve_is_empty(const FCurve *fcu)
FCurve * BKE_fcurve_find_by_rna_context_ui(bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **r_animdata, bAction **r_action, bool *r_driven, bool *r_special)
bool CTX_data_selected_objects(const bContext *C, Vector< PointerRNA > *list)
void ANIM_OT_keyframe_insert_button(wmOperatorType *ot)
FCurve * BKE_fcurve_find(ListBaseT< FCurve > *list, const char rna_path[], int array_index)
static KeyingSet * keyingset_get_from_op_with_error(wmOperator *op, PropertyRNA *prop, Scene *scene)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus clear_anim_v3d_invoke(bContext *C, wmOperator *op, const wmEvent *)
void ANIM_OT_keyframe_delete(wmOperatorType *ot)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void ANIM_OT_keyframe_clear_button(wmOperatorType *ot)
static wmOperatorStatus delete_key_exec(bContext *C, wmOperator *op)
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Interpolation ipo
eBezTriple_Handle h1
eFCurve_Flags flag
unsigned int totvert
char name[258]
Definition DNA_ID.h:433
ListBaseT< FCurve > fcurves
struct bPose * pose
StructRNA * type
Definition RNA_types.hh:63
bool has_owner_id() const
Definition RNA_types.hh:186
struct AnimData * adt
struct ToolSettings * toolsettings
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
struct wmOperatorType * type