Blender V5.3
rna_action.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "DNA_action_types.h"
12#include "DNA_anim_types.h"
13#include "DNA_scene_types.h"
14
15#include "BLT_translation.hh"
16
17#include "BKE_action.hh"
18#include "BKE_blender.hh"
19#include "BKE_fcurve.hh"
20#include "BKE_report.hh"
21
22#include "RNA_access.hh"
23#include "RNA_define.hh"
24#include "RNA_enum_types.hh"
25
26#include "rna_internal.hh"
27
28#include "ANIM_action.hh"
29
30#include "WM_types.hh"
31
32namespace blender {
33
34/* Disabled for now, see comment in `rna_def_action_layer()` for more info. */
35#if 0
36const EnumPropertyItem rna_enum_layer_mix_mode_items[] = {
38 "REPLACE",
39 0,
40 "Replace",
41 "Channels in this layer override the same channels from underlying layers"},
43 "OFFSET",
44 0,
45 "Offset",
46 "Channels in this layer are added to underlying layers as sequential operations"},
48 "ADD",
49 0,
50 "Add",
51 "Channels in this layer are added to underlying layers on a per-channel basis"},
53 "SUBTRACT",
54 0,
55 "Subtract",
56 "Channels in this layer are subtracted to underlying layers on a per-channel basis"},
58 "MULTIPLY",
59 0,
60 "Multiply",
61 "Channels in this layer are multiplied with underlying layers on a per-channel basis"},
62 {0, nullptr, 0, nullptr, nullptr},
63};
64#endif
65
68 "KEYFRAME",
69 0,
70 "Keyframe",
71 "Strip containing keyframes on F-Curves"},
72 {0, nullptr, 0, nullptr, nullptr},
73};
74
75/* Cannot use rna_enum_dummy_DEFAULT_items because the UNSPECIFIED entry needs
76 * to exist as it is the default. */
78 {0,
79 "UNSPECIFIED",
80 ICON_NONE,
81 "Unspecified",
82 "Not yet specified. When this slot is first assigned to a data-block, this will be set to "
83 "the type of that data-block"},
84 {0, nullptr, 0, nullptr, nullptr},
85};
86
87} // namespace blender
88
89#ifdef RNA_RUNTIME
90
91# include <algorithm>
92
93# include "BLI_listbase.hh"
94# include "BLI_math_base_c.hh"
95# include "BLI_string.hh"
96# include "BLI_string_utf8.hh"
97
98# include "BKE_animsys.hh"
99# include "BKE_fcurve.hh"
100# include "BKE_main.hh"
101# include "BKE_report.hh"
102
103# include "DEG_depsgraph.hh"
104
105# include "ANIM_action.hh"
106# include "ANIM_animdata.hh"
107# include "ED_anim_api.hh"
108
109# include "WM_api.hh"
110
111# include "UI_interface_icons.hh"
112
113# include "ANIM_action_legacy.hh"
114# include "ANIM_fcurve.hh"
115# include "ANIM_keyframing.hh"
116
117# include <fmt/format.h>
118
119namespace blender {
120
121static animrig::Action &rna_action(const PointerRNA *ptr)
122{
123 return reinterpret_cast<bAction *>(ptr->owner_id)->wrap();
124}
125
126static animrig::Slot &rna_data_slot(const PointerRNA *ptr)
127{
128 BLI_assert(ptr->type == RNA_ActionSlot);
129 return reinterpret_cast<ActionSlot *>(ptr->data)->wrap();
130}
131
132static animrig::Layer &rna_data_layer(const PointerRNA *ptr)
133{
134 return reinterpret_cast<ActionLayer *>(ptr->data)->wrap();
135}
136
137static animrig::Strip &rna_data_strip(const PointerRNA *ptr)
138{
139 return reinterpret_cast<ActionStrip *>(ptr->data)->wrap();
140}
141
142/* Disabled for now, see comment in `rna_def_action_layer()` for more info. */
143# if 0
144static void rna_Action_tag_animupdate(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr)
145{
146 animrig::Action &action = rna_action(ptr);
148}
149# endif
150
151static animrig::Channelbag &rna_data_channelbag(const PointerRNA *ptr)
152{
153 return reinterpret_cast<ActionChannelbag *>(ptr->data)->wrap();
154}
155
156template<typename T>
158 PointerRNA *ptr,
159 Span<T *> items)
160{
161 rna_iterator_array_begin(iter, ptr, (void *)items.data(), sizeof(T *), items.size(), 0, nullptr);
162}
163
164template<typename T>
166 PointerRNA *ptr,
167 MutableSpan<T *> items)
168{
169 rna_iterator_array_begin(iter, ptr, (void *)items.data(), sizeof(T *), items.size(), 0, nullptr);
170}
171
172static PointerRNA rna_ActionSlots_active_get(PointerRNA *ptr)
173{
174 animrig::Action &action = rna_action(ptr);
175 animrig::Slot *active_slot = action.slot_active_get();
176
177 if (!active_slot) {
178 return {};
179 }
180 return RNA_pointer_create_discrete(&action.id, RNA_ActionSlot, active_slot);
181}
182
183static void rna_ActionSlots_active_set(PointerRNA *ptr,
184 PointerRNA value,
185 struct ReportList * /*reports*/)
186{
187 animrig::Action &action = rna_action(ptr);
188
189 if (value) {
190 animrig::Slot &slot = rna_data_slot(&value);
191 action.slot_active_set(slot.handle);
192 }
193 else {
194 action.slot_active_set(animrig::Slot::unassigned);
195 }
196}
197
198static ActionSlot *rna_Action_slots_new(
199 bAction *dna_action, Main *bmain, bContext *C, ReportList *reports, int type, const char *name)
200{
201 animrig::Action &action = dna_action->wrap();
202
203 if (name[0] == 0) {
204 BKE_reportf(reports, RPT_ERROR, "Invalid slot name '%s': name must not be empty.", name);
205 return nullptr;
206 }
207
208 animrig::Slot *slot = &action.slot_add_for_id_type(ID_Type(type));
209 action.slot_display_name_set(*bmain, *slot, name);
210
212 return slot;
213}
214
215void rna_Action_slots_remove(bAction *dna_action,
216 bContext *C,
217 ReportList *reports,
218 PointerRNA *slot_ptr)
219{
220 animrig::Action &action = dna_action->wrap();
221 animrig::Slot &slot = rna_data_slot(slot_ptr);
222 if (!action.slot_remove(slot)) {
223 BKE_report(reports, RPT_ERROR, "This slot does not belong to this Action");
224 return;
225 }
226
227 slot_ptr->invalidate();
230}
231
232static void rna_iterator_action_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
233{
234 animrig::Action &action = rna_action(ptr);
235 rna_iterator_array_begin(iter, ptr, action.layers());
236}
237
238static int rna_iterator_action_layers_length(PointerRNA *ptr)
239{
240 animrig::Action &action = rna_action(ptr);
241 return action.layers().size();
242}
243
244static ActionLayer *rna_Action_layers_new(bAction *dna_action,
245 bContext *C,
246 ReportList *reports,
247 const char *name)
248{
249 animrig::Action &action = dna_action->wrap();
250
251 if (action.layers().size() >= 1) {
252 /* Not allowed to have more than one layer, for now. This limitation is in
253 * place until working with multiple animated IDs is fleshed out better. */
254 BKE_report(reports, RPT_ERROR, "An Action may not have more than one layer");
255 return nullptr;
256 }
257
258 animrig::Layer &layer = action.layer_add(name);
259
261 return &layer;
262}
263
264void rna_Action_layers_remove(bAction *dna_action,
265 bContext *C,
266 ReportList *reports,
267 PointerRNA *layer_ptr)
268{
269 animrig::Action &action = dna_action->wrap();
270 animrig::Layer &layer = rna_data_layer(layer_ptr);
271 if (!action.layer_remove(layer)) {
272 BKE_report(reports, RPT_ERROR, "This layer does not belong to this Action");
273 return;
274 }
275
276 layer_ptr->invalidate();
279}
280
281static void rna_iterator_animation_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
282{
283 animrig::Action &action = rna_action(ptr);
284 rna_iterator_array_begin(iter, ptr, action.slots());
285}
286
287static int rna_iterator_animation_slots_length(PointerRNA *ptr)
288{
289 animrig::Action &action = rna_action(ptr);
290 return action.slots().size();
291}
292
293static std::optional<std::string> rna_ActionSlot_path(const PointerRNA *ptr)
294{
295 animrig::Slot &slot = rna_data_slot(ptr);
296
297 char identifier_esc[sizeof(slot.identifier) * 2];
298 BLI_str_escape(identifier_esc, slot.identifier, sizeof(identifier_esc));
299 return fmt::format("slots[\"{}\"]", identifier_esc);
300}
301
302int rna_ActionSlot_target_id_type_icon_get(PointerRNA *ptr)
303{
304 animrig::Slot &slot = rna_data_slot(ptr);
305 return ui::icon_from_idcode(slot.idtype);
306}
307
308/* Name functions that ignore the first two ID characters */
309void rna_ActionSlot_name_display_get(PointerRNA *ptr, char *value)
310{
311 animrig::Slot &slot = rna_data_slot(ptr);
312 slot.identifier_without_prefix().copy_unsafe(value);
313}
314
315int rna_ActionSlot_name_display_length(PointerRNA *ptr)
316{
317 animrig::Slot &slot = rna_data_slot(ptr);
318 return slot.identifier_without_prefix().size();
319}
320
321static void rna_ActionSlot_name_display_set(PointerRNA *ptr, const char *name)
322{
323 animrig::Action &action = rna_action(ptr);
324 animrig::Slot &slot = rna_data_slot(ptr);
325 const StringRef name_ref(name);
326
327 if (name_ref.is_empty()) {
328 WM_global_report(RPT_ERROR, "Action slot display names cannot be empty");
329 return;
330 }
331
332 action.slot_display_name_define(slot, name);
333}
334
335static void rna_ActionSlot_identifier_set(PointerRNA *ptr, const char *identifier)
336{
337 animrig::Action &action = rna_action(ptr);
338 animrig::Slot &slot = rna_data_slot(ptr);
339 const StringRef identifier_ref(identifier);
340
341 if (identifier_ref.size() < animrig::Slot::identifier_length_min) {
342 WM_global_report(RPT_ERROR, "Action slot identifiers should be at least three characters");
343 return;
344 }
345
346 /* Sanity check. These should never be out of sync in higher-level code. */
347 BLI_assert(slot.idtype_string() == slot.identifier_prefix());
348
349 const std::string identifier_with_correct_prefix = slot.idtype_string() +
350 identifier_ref.substr(2);
351
352 if (identifier_with_correct_prefix != identifier_ref) {
355 "Attempted to set slot identifier to \"%s\", but the type prefix does not match the "
356 "slot's 'target_id_type' \"%s\". Setting to \"%s\" instead.\n",
357 identifier,
358 slot.idtype_string().c_str(),
359 identifier_with_correct_prefix.c_str());
360 }
361
362 action.slot_identifier_define(slot, identifier_with_correct_prefix);
363}
364
365static void rna_ActionSlot_identifier_update(Main *bmain, Scene *, PointerRNA *ptr)
366{
367 animrig::Action &action = rna_action(ptr);
368 animrig::Slot &slot = rna_data_slot(ptr);
369 action.slot_identifier_propagate(*bmain, slot);
370}
371
372static CollectionVector rna_ActionSlot_users(struct ActionSlot *self, Main *bmain)
373{
374 animrig::Slot &slot = self->wrap();
375 const Span<ID *> slot_users = slot.users(*bmain);
376
377 CollectionVector vector{};
378 vector.items.resize(slot_users.size());
379 for (const int i : slot_users.index_range()) {
380 vector.items[i] = RNA_id_pointer_create(slot_users[i]);
381 }
382
383 return vector;
384}
385
386static ActionSlot *rna_ActionSlot_duplicate(ID *action_id, const ActionSlot *self)
387{
388 animrig::Action &action = reinterpret_cast<bAction *>(action_id)->wrap();
389 const animrig::Slot &source_slot = self->wrap();
390
391 animrig::Slot &dupli_slot = animrig::duplicate_slot(action, source_slot);
392 return &dupli_slot;
393}
394
395static std::optional<std::string> rna_ActionLayer_path(const PointerRNA *ptr)
396{
397 animrig::Layer &layer = rna_data_layer(ptr);
398
399 char name_esc[sizeof(layer.name) * 2];
400 BLI_str_escape(name_esc, layer.name, sizeof(name_esc));
401 return fmt::format("layers[\"{}\"]", name_esc);
402}
403
404static void rna_iterator_ActionLayer_strips_begin(CollectionPropertyIterator *iter,
405 PointerRNA *ptr)
406{
407 animrig::Layer &layer = rna_data_layer(ptr);
408 rna_iterator_array_begin(iter, ptr, layer.strips());
409}
410
411static int rna_iterator_ActionLayer_strips_length(PointerRNA *ptr)
412{
413 animrig::Layer &layer = rna_data_layer(ptr);
414 return layer.strips().size();
415}
416
417static StructRNA *rna_ActionStrip_refine(PointerRNA *ptr)
418{
419 animrig::Strip &strip = static_cast<ActionStrip *>(ptr->data)->wrap();
420
421 switch (strip.type()) {
423 return RNA_ActionKeyframeStrip;
424 }
425 return RNA_UnknownType;
426}
427
428ActionStrip *rna_ActionStrips_new(
429 ID *dna_action_id, ActionLayer *dna_layer, bContext *C, ReportList *reports, const int type)
430{
431 const animrig::Strip::Type strip_type = animrig::Strip::Type(type);
432
433 animrig::Layer &layer = dna_layer->wrap();
434
435 if (layer.strips().size() >= 1) {
436 /* Not allowed to have more than one strip, for now. This limitation is in
437 * place until working with layers is fleshed out better. */
438 BKE_report(reports, RPT_ERROR, "A layer may not have more than one strip");
439 return nullptr;
440 }
441
442 animrig::Action &action = reinterpret_cast<bAction *>(dna_action_id)->wrap();
443 animrig::Strip &strip = layer.strip_add(action, strip_type);
444
446 return &strip;
447}
448
449void rna_ActionStrips_remove(
450 ID *action_id, ActionLayer *dna_layer, bContext *C, ReportList *reports, PointerRNA *strip_ptr)
451{
452 animrig::Action &action = reinterpret_cast<bAction *>(action_id)->wrap();
453 animrig::Layer &layer = dna_layer->wrap();
454 animrig::Strip &strip = rna_data_strip(strip_ptr);
455 if (!layer.strip_remove(action, strip)) {
456 BKE_report(reports, RPT_ERROR, "This strip does not belong to this layer");
457 return;
458 }
459
460 strip_ptr->invalidate();
463}
464
465static std::optional<std::string> rna_ActionStrip_path(const PointerRNA *ptr)
466{
467 animrig::Action &action = rna_action(ptr);
468 animrig::Strip &strip_to_find = rna_data_strip(ptr);
469
470 PointerRNA layer_ptr = {};
471 int strip_index = -1;
472
473 if (std::optional<AncestorPointerRNA> layer_ancestor_ptr =
474 RNA_struct_search_closest_ancestor_by_type(ptr, RNA_ActionLayer))
475 {
476 /* Get the layer from the RNA ancestors. */
477 layer_ptr = {&action.id, layer_ancestor_ptr->type, layer_ancestor_ptr->data};
478 BLI_assert_msg(layer_ptr.has_data(), "PointerRNA ancestors should not be nullptr");
479 const animrig::Layer *layer = layer_ptr.data_as<animrig::Layer>();
480 strip_index = layer->strips().first_index_try(&strip_to_find);
481 }
482
483 if (strip_index < 0) {
484 /* Find the layer that contains the strip. */
485 for (animrig::Layer *layer : action.layers()) {
486 Span<animrig::Strip *> strips = layer->strips();
487 const int index = strips.first_index_try(&strip_to_find);
488 if (index < 0) {
489 continue;
490 }
491
492 layer_ptr = RNA_pointer_create_id_subdata(action.id, RNA_ActionLayer, layer);
493 strip_index = index;
494 break;
495 }
496 }
497 if (strip_index < 0) {
498 return std::nullopt;
499 }
500
501 /* Use the path to the layer to construct the path to the strip. */
502 const std::optional<std::string> layer_path = rna_ActionLayer_path(&layer_ptr);
503 BLI_assert_msg(layer_path, "Every animation layer should have a valid RNA path.");
504 const std::string strip_path = fmt::format("{}.strips[{}]", *layer_path, strip_index);
505 return strip_path;
506}
507
508static void rna_iterator_keyframestrip_channelbags_begin(CollectionPropertyIterator *iter,
509 PointerRNA *ptr)
510{
511 animrig::Action &action = reinterpret_cast<bAction *>(ptr->owner_id)->wrap();
512 animrig::Strip &strip = rna_data_strip(ptr);
514 iter, ptr, strip.data<animrig::StripKeyframeData>(action).channelbags());
515}
516
517static int rna_iterator_keyframestrip_channelbags_length(PointerRNA *ptr)
518{
519 animrig::Action &action = reinterpret_cast<bAction *>(ptr->owner_id)->wrap();
520 animrig::Strip &strip = rna_data_strip(ptr);
521 return strip.data<animrig::StripKeyframeData>(action).channelbags().size();
522}
523
524static ActionChannelbag *rna_Channelbags_new(ID *dna_action_id,
525 ActionStrip *dna_strip,
526 bContext *C,
527 ReportList *reports,
528 ActionSlot *dna_slot)
529{
530 animrig::Action &action = reinterpret_cast<bAction *>(dna_action_id)->wrap();
531 animrig::Strip &strip = dna_strip->wrap();
532 animrig::StripKeyframeData &strip_data = strip.data<animrig::StripKeyframeData>(action);
533 animrig::Slot &slot = dna_slot->wrap();
534
535 if (strip_data.channelbag_for_slot(slot) != nullptr) {
536 BKE_report(reports, RPT_ERROR, "A channelbag for this slot already exists");
537 return nullptr;
538 }
539
540 animrig::Channelbag &channelbag = strip_data.channelbag_for_slot_add(slot);
541
543 /* No need to tag the depsgraph, as there is no new animation yet. */
544
545 return &channelbag;
546}
547
548static void rna_Channelbags_remove(ID *dna_action_id,
549 ActionStrip *dna_strip,
550 bContext *C,
551 ReportList *reports,
552 PointerRNA *channelbag_ptr)
553{
554 animrig::Action &action = reinterpret_cast<bAction *>(dna_action_id)->wrap();
555 animrig::StripKeyframeData &strip_data = dna_strip->wrap().data<animrig::StripKeyframeData>(
556 action);
557 animrig::Channelbag &channelbag = rna_data_channelbag(channelbag_ptr);
558
559 if (!strip_data.channelbag_remove(channelbag)) {
560 BKE_report(reports, RPT_ERROR, "This channelbag does not belong to this strip");
561 return;
562 }
563
564 channelbag_ptr->invalidate();
567}
568
569static bool rna_ActionStrip_key_insert(ID *dna_action_id,
570 ActionStrip *dna_strip,
571 Main *bmain,
572 ReportList *reports,
573 ActionSlot *dna_slot,
574 const char *rna_path,
575 const int array_index,
576 const float value,
577 const float time)
578{
579 if (dna_slot == nullptr) {
580 BKE_report(reports, RPT_ERROR, "Slot cannot be None");
581 return false;
582 }
583
584 animrig::Action &action = reinterpret_cast<bAction *>(dna_action_id)->wrap();
585 animrig::StripKeyframeData &strip_data = dna_strip->wrap().data<animrig::StripKeyframeData>(
586 action);
587 const animrig::Slot &slot = dna_slot->wrap();
589
590 const animrig::SingleKeyingResult result = strip_data.keyframe_insert(
591 bmain, slot, {rna_path, array_index}, {time, value}, settings, INSERTKEY_NOFLAGS);
592
594 if (ok) {
595 DEG_id_tag_update_ex(bmain, dna_action_id, ID_RECALC_ANIMATION);
596 }
597
598 return ok;
599}
600
601std::optional<std::string> rna_Channelbag_path(const PointerRNA *ptr)
602{
603 animrig::Action &action = rna_action(ptr);
604 animrig::Channelbag &cbag_to_find = rna_data_channelbag(ptr);
605
606 /* Grab the ancestors from the PointerRNA. */
607 if (std::optional<AncestorPointerRNA> strip_ancestor_ptr =
608 RNA_struct_search_closest_ancestor_by_type(ptr, RNA_ActionStrip))
609 {
610 /* Pass the ChannelBag ancestors to the strip pointer as well, to give the
611 * rna_ActionStrip_path() direct access to the containing ActionLayer. */
612 const PointerRNA strip_ptr = {
613 &action.id, strip_ancestor_ptr->type, strip_ancestor_ptr->data, ptr->ancestors};
614 BLI_assert_msg(strip_ptr.has_data(), "PointerRNA ancestors should not be nullptr");
615
616 const animrig::Strip *strip = strip_ptr.data_as<animrig::Strip>();
617 std::optional<std::string> strip_path = rna_ActionStrip_path(&strip_ptr);
618 BLI_assert_msg(strip_path, "ActionStrip instances should have an RNA path");
619
620 /* Find the channelbag index. */
621 const animrig::StripKeyframeData &strip_data = strip->data<animrig::StripKeyframeData>(action);
622 const int64_t index = strip_data.find_channelbag_index(cbag_to_find);
623 if (index >= 0) {
624 return fmt::format("{}.channelbags[{}]", *strip_path, index);
625 }
626 }
627
628 /* Loop over all layers and all strips to find the ancestor. */
629 for (animrig::Layer *layer : action.layers()) {
630 for (int64_t strip_index : layer->strips().index_range()) {
631 const animrig::Strip *strip = layer->strip(strip_index);
632 if (strip->type() != animrig::Strip::Type::Keyframe) {
633 continue;
634 }
635
636 const animrig::StripKeyframeData &strip_data = strip->data<animrig::StripKeyframeData>(
637 action);
638 const int64_t index = strip_data.find_channelbag_index(cbag_to_find);
639 if (index < 0) {
640 continue;
641 }
642
643 PointerRNA layer_ptr = RNA_pointer_create_discrete(&action.id, RNA_ActionLayer, layer);
644 const std::optional<std::string> layer_path = rna_ActionLayer_path(&layer_ptr);
645 BLI_assert_msg(layer_path, "Every animation layer should have a valid RNA path.");
646 return fmt::format("{}.strips[{}].channelbags[{}]", *layer_path, strip_index, index);
647 }
648 }
649
650 return std::nullopt;
651}
652
653static PointerRNA rna_Channelbag_slot_get(PointerRNA *ptr)
654{
655 animrig::Action &action = rna_action(ptr);
656 animrig::Channelbag &channelbag = rna_data_channelbag(ptr);
657 animrig::Slot *slot = action.slot_for_handle(channelbag.slot_handle);
658 BLI_assert(slot);
659
660 return RNA_pointer_create_with_parent(*ptr, RNA_ActionSlot, slot);
661}
662
663static void rna_iterator_Channelbag_fcurves_begin(CollectionPropertyIterator *iter,
664 PointerRNA *ptr)
665{
666 animrig::Channelbag &bag = rna_data_channelbag(ptr);
667 rna_iterator_array_begin(iter, ptr, bag.fcurves());
668}
669
670static int rna_iterator_Channelbag_fcurves_length(PointerRNA *ptr)
671{
672 animrig::Channelbag &bag = rna_data_channelbag(ptr);
673 return bag.fcurves().size();
674}
675
676static FCurve *rna_Channelbag_fcurve_new(ActionChannelbag *dna_channelbag,
677 Main *bmain,
678 ReportList *reports,
679 const char *data_path,
680 const int index,
681 const char *group_name)
682{
683 BLI_assert(data_path != nullptr);
684 if (data_path[0] == '\0') {
685 BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
686 return nullptr;
687 }
688
689 animrig::FCurveDescriptor descr = {data_path, index};
690 if (group_name && group_name[0]) {
691 descr.channel_group = {group_name};
692 }
693
694 animrig::Channelbag &self = dna_channelbag->wrap();
695 FCurve *fcurve = self.fcurve_create_unique(bmain, descr);
696 if (!fcurve) {
697 BKE_reportf(reports,
698 RPT_ERROR,
699 "F-Curve '%s[%d]' already exists in this channelbag",
700 data_path,
701 index);
702 return nullptr;
703 }
704 return fcurve;
705}
706
707static FCurve *rna_Channelbag_fcurve_new_from_fcurve(ID *dna_action_id,
708 ActionChannelbag *dna_channelbag,
709 ReportList *reports,
710 FCurve *source,
711 const char *data_path)
712{
713 animrig::Channelbag &self = dna_channelbag->wrap();
714
715 if (!data_path) {
716 data_path = source->rna_path().c_str();
717 }
718
719 if (self.fcurve_find({data_path, source->array_index})) {
720 BKE_reportf(reports,
721 RPT_ERROR,
722 "F-Curve '%s[%d]' already exists in this channelbag",
723 data_path,
724 source->array_index);
725 return nullptr;
726 }
727 FCurve *copy = BKE_fcurve_copy(source);
728 copy->rna_path_set(data_path);
729 self.fcurve_append(*copy);
730
732
733 return copy;
734}
735
736static FCurve *rna_Channelbag_fcurve_ensure(ActionChannelbag *dna_channelbag,
737 Main *bmain,
738 ReportList *reports,
739 const char *data_path,
740 const int index,
741 const char *group_name)
742{
743 BLI_assert(data_path != nullptr);
744 if (data_path[0] == '\0') {
745 BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
746 return nullptr;
747 }
748
749 animrig::FCurveDescriptor descr = {data_path, index};
750 if (group_name && group_name[0]) {
751 descr.channel_group = {group_name};
752 }
753
754 animrig::Channelbag &self = dna_channelbag->wrap();
755 FCurve &fcurve = self.fcurve_ensure(bmain, descr);
756 return &fcurve;
757}
758
759static FCurve *rna_Channelbag_fcurve_find(ActionChannelbag *dna_channelbag,
760 ReportList *reports,
761 const char *data_path,
762 const int index)
763{
764 if (data_path[0] == '\0') {
765 BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
766 return nullptr;
767 }
768
769 animrig::Channelbag &self = dna_channelbag->wrap();
770 return self.fcurve_find({data_path, index});
771}
772
773static void rna_Channelbag_fcurve_remove(ID *dna_action_id,
774 ActionChannelbag *dna_channelbag,
775 bContext *C,
776 ReportList *reports,
777 PointerRNA *fcurve_ptr)
778{
779 animrig::Channelbag &self = dna_channelbag->wrap();
780 FCurve *fcurve = static_cast<FCurve *>(fcurve_ptr->data);
781
782 if (!self.fcurve_remove(*fcurve)) {
783 BKE_reportf(reports, RPT_ERROR, "F-Curve not found");
784 return;
785 }
786
789}
790
791static void rna_Channelbag_fcurve_clear(ID *dna_action_id,
792 ActionChannelbag *dna_channelbag,
793 bContext *C)
794{
795 dna_channelbag->wrap().fcurves_clear();
798}
799
800static void rna_iterator_Channelbag_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
801{
802 animrig::Channelbag &bag = rna_data_channelbag(ptr);
803 rna_iterator_array_begin(iter, ptr, bag.channel_groups());
804}
805
806static int rna_iterator_Channelbag_groups_length(PointerRNA *ptr)
807{
808 animrig::Channelbag &bag = rna_data_channelbag(ptr);
809 return bag.channel_groups().size();
810}
811
812static bActionGroup *rna_Channelbag_group_new(ActionChannelbag *dna_channelbag, const char *name)
813{
814 BLI_assert(name != nullptr);
815
816 animrig::Channelbag &self = dna_channelbag->wrap();
817 return &self.channel_group_create(name);
818}
819
820static void rna_Channelbag_group_remove(ActionChannelbag *dna_channelbag,
821 ReportList *reports,
822 PointerRNA *agrp_ptr)
823{
824 animrig::Channelbag &self = dna_channelbag->wrap();
825
826 bActionGroup *agrp = static_cast<bActionGroup *>(agrp_ptr->data);
827
828 if (!self.channel_group_remove(*agrp)) {
829 BKE_report(reports,
830 RPT_ERROR,
831 "Could not remove the F-Curve Group from the collection because it does not exist "
832 "in the collection");
833 return;
834 }
835
836 agrp_ptr->invalidate();
838}
839
840static ActionChannelbag *rna_ActionStrip_channelbag(ID *dna_action_id,
841 ActionStrip *self,
842 ReportList *reports,
843 const ActionSlot *dna_slot,
844 const bool ensure)
845{
846 if (!dna_slot) {
847 BKE_report(reports, RPT_ERROR, "Cannot return channelbag when slot is None");
848 return nullptr;
849 }
850
851 animrig::Action &action = reinterpret_cast<bAction *>(dna_action_id)->wrap();
852 animrig::StripKeyframeData &strip_data = self->wrap().data<animrig::StripKeyframeData>(action);
853 const animrig::Slot &slot = dna_slot->wrap();
854
855 if (ensure) {
856 return &strip_data.channelbag_for_slot_ensure(slot);
857 }
858 return strip_data.channelbag_for_slot(slot);
859}
860
861static std::optional<std::string> rna_ActionGroup_path(const PointerRNA *ptr)
862{
863 bActionGroup *group = ptr->data_as<bActionGroup>();
864
865 /* The ActionGroup should be owned by an Action. Once upon a time they were also used as bone
866 * groups in armatures. */
867 if (GS(ptr->owner_id->name) != ID_AC) {
868 return {};
869 }
870
871 PointerRNA channelbag_ptr;
872
873 if (std::optional<AncestorPointerRNA> channelbag_ancestor_ptr =
874 RNA_struct_search_closest_ancestor_by_type(ptr, RNA_ActionChannelbag))
875 {
876 /* Pass the ActionGroup ancestors to the Channelbag pointer as well, to give the
877 * rna_Channelbag_path() direct access to the containing ActionLayer etc. */
878 channelbag_ptr = {ptr->owner_id,
879 channelbag_ancestor_ptr->type,
880 channelbag_ancestor_ptr->data,
881 ptr->ancestors};
882 BLI_assert_msg(channelbag_ptr.has_data(), "PointerRNA ancestors should not be nullptr");
883 }
884 else {
885 /* Go over all layers, strips, and channelbags to find the group. */
886 animrig::Action &action = reinterpret_cast<bAction *>(ptr->owner_id)->wrap();
887 for (animrig::Layer *layer : action.layers()) {
888 for (animrig::Strip *strip : layer->strips()) {
889 if (strip->type() != animrig::Strip::Type::Keyframe) {
890 continue;
891 }
892
893 animrig::StripKeyframeData &strip_data = strip->data<animrig::StripKeyframeData>(action);
894 for (animrig::Channelbag *channelbag : strip_data.channelbags()) {
895 const int group_index = channelbag->channel_groups().first_index_try(group);
896 if (group_index != -1) {
898 action.id, RNA_ActionLayer, layer);
900 layer_ptr, RNA_ActionStrip, strip);
901 channelbag_ptr = RNA_pointer_create_with_parent(
902 layer_ptr, RNA_ActionChannelbag, channelbag);
903 }
904 }
905 }
906 }
907 }
908
909 std::optional<std::string> channelbag_path = rna_Channelbag_path(&channelbag_ptr);
910 BLI_assert_msg(channelbag_path, "ActionChannelbag instances should have an RNA path");
911
912 char name_esc[sizeof(group->name) * 2];
913 BLI_str_escape(name_esc, group->name, sizeof(name_esc));
914
915 return fmt::format("{}.groups[\"{}\"]", *channelbag_path, name_esc);
916}
917
928struct ActionGroupChannelsIterator {
929 /* Which kind of iterator it is. */
930 enum {
931 ARRAY,
932 LISTBASE,
933 } tag;
934
935 union {
936 ArrayIterator array;
937 ListBaseIterator listbase;
938 };
939};
940
941static void rna_ActionGroup_channels_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
942{
943 bActionGroup *group = static_cast<bActionGroup *>(ptr->data);
944
945 ActionGroupChannelsIterator *custom_iter = MEM_new_zeroed<ActionGroupChannelsIterator>(__func__);
946
947 iter->internal.custom = custom_iter;
948
949 /* Group from a layered action. */
950 animrig::Channelbag &cbag = group->channelbag->wrap();
951
952 custom_iter->tag = ActionGroupChannelsIterator::ARRAY;
953 custom_iter->array.ptr = reinterpret_cast<char *>(cbag.fcurve_array + group->fcurve_range_start);
954 custom_iter->array.endptr = reinterpret_cast<char *>(
955 cbag.fcurve_array + group->fcurve_range_start + group->fcurve_range_length);
956 custom_iter->array.itemsize = sizeof(FCurve *);
957 custom_iter->array.length = group->fcurve_range_length;
958
959 iter->valid = group->fcurve_range_length > 0;
960}
961
962static void rna_ActionGroup_channels_end(CollectionPropertyIterator *iter)
963{
964 MEM_delete(static_cast<ActionGroupChannelsIterator *>(iter->internal.custom));
965}
966
967static void rna_ActionGroup_channels_next(CollectionPropertyIterator *iter)
968{
969 BLI_assert(iter->internal.custom != nullptr);
970 BLI_assert(iter->valid);
971
972 ActionGroupChannelsIterator *custom_iter = static_cast<ActionGroupChannelsIterator *>(
973 iter->internal.custom);
974
975 /* The code for both cases here is written based on the code in
976 * `rna_iterator_array_next()` and `rna_iterator_listbase_next()`,
977 * respectively. */
978 switch (custom_iter->tag) {
979 case ActionGroupChannelsIterator::ARRAY: {
980 custom_iter->array.ptr += custom_iter->array.itemsize;
981 iter->valid = (custom_iter->array.ptr != custom_iter->array.endptr);
982 break;
983 }
984 case ActionGroupChannelsIterator::LISTBASE: {
985 FCurve *fcurve = reinterpret_cast<FCurve *>(custom_iter->listbase.link);
986 bActionGroup *grp = fcurve->grp;
987 /* Only continue if the next F-Curve (if existent) belongs in the same
988 * group. */
989 if ((fcurve->next) && (fcurve->next->grp == grp)) {
990 custom_iter->listbase.link = custom_iter->listbase.link->next;
991 iter->valid = (custom_iter->listbase.link != nullptr);
992 }
993 else {
994 custom_iter->listbase.link = nullptr;
995 iter->valid = false;
996 }
997 break;
998 }
999 }
1000}
1001
1002static PointerRNA rna_ActionGroup_channels_get(CollectionPropertyIterator *iter)
1003{
1004 BLI_assert(iter->internal.custom != nullptr);
1005 BLI_assert(iter->valid);
1006 ActionGroupChannelsIterator *custom_iter = static_cast<ActionGroupChannelsIterator *>(
1007 iter->internal.custom);
1008
1009 FCurve *fcurve;
1010 switch (custom_iter->tag) {
1011 case ActionGroupChannelsIterator::ARRAY:
1012 fcurve = *reinterpret_cast<FCurve **>(custom_iter->array.ptr);
1013 break;
1014 case ActionGroupChannelsIterator::LISTBASE:
1015 fcurve = reinterpret_cast<FCurve *>(custom_iter->listbase.link);
1016 break;
1017 }
1018
1019 return RNA_pointer_create_with_parent(iter->parent, RNA_FCurve, fcurve);
1020}
1021
1022static TimeMarker *rna_Action_pose_markers_new(bAction *act, const char name[])
1023{
1024 TimeMarker *marker = MEM_new<TimeMarker>("TimeMarker");
1025 marker->flag = SELECT;
1026 marker->frame = 1;
1027 STRNCPY_UTF8(marker->name, name);
1028 BLI_addtail(&act->markers, marker);
1029 return marker;
1030}
1031
1032static void rna_Action_pose_markers_remove(bAction *act,
1033 ReportList *reports,
1034 PointerRNA *marker_ptr)
1035{
1036 TimeMarker *marker = static_cast<TimeMarker *>(marker_ptr->data);
1037 if (!BLI_remlink_safe(&act->markers, marker)) {
1038 BKE_reportf(reports,
1039 RPT_ERROR,
1040 "Timeline marker '%s' not found in action '%s'",
1041 marker->name,
1042 act->id.name + 2);
1043 return;
1044 }
1045
1046 BKE_free_time_marker(*marker, true);
1047 marker_ptr->invalidate();
1048}
1049
1050static PointerRNA rna_Action_active_pose_marker_get(PointerRNA *ptr)
1051{
1052 bAction *act = static_cast<bAction *>(ptr->data);
1054 *ptr, RNA_TimelineMarker, BLI_findlink(&act->markers, act->active_marker - 1));
1055}
1056
1057static void rna_Action_active_pose_marker_set(PointerRNA *ptr,
1058 PointerRNA value,
1059 ReportList * /*reports*/)
1060{
1061 bAction *act = static_cast<bAction *>(ptr->data);
1062 act->active_marker = BLI_findindex(&act->markers, value.data) + 1;
1063}
1064
1065static int rna_Action_active_pose_marker_index_get(PointerRNA *ptr)
1066{
1067 bAction *act = static_cast<bAction *>(ptr->data);
1068 return std::max(act->active_marker - 1, 0);
1069}
1070
1071static void rna_Action_active_pose_marker_index_set(PointerRNA *ptr, int value)
1072{
1073 bAction *act = static_cast<bAction *>(ptr->data);
1074 act->active_marker = value + 1;
1075}
1076
1077static void rna_Action_active_pose_marker_index_range(
1078 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
1079{
1080 bAction *act = static_cast<bAction *>(ptr->data);
1081
1082 *min = 0;
1083 *max = max_ii(0, act->markers.count() - 1);
1084}
1085
1086static bool rna_Action_is_empty_get(PointerRNA *ptr)
1087{
1088 animrig::Action &action = rna_action(ptr);
1089 return action.is_empty();
1090}
1091static bool rna_Action_is_action_legacy_get(PointerRNA *ptr)
1092{
1093 /* All actions are versioned so legacy actions no longer exist. This RNA function should be
1094 * removed at the next opportunity. */
1095 return rna_action(ptr).is_empty();
1096}
1097static bool rna_Action_is_action_layered_get(PointerRNA * /* ptr */)
1098{
1099 /* All actions are layered through versioning. */
1100 return true;
1101}
1102
1103static void rna_Action_frame_range_get(PointerRNA *ptr, float *r_values)
1104{
1105 const float2 frame_range = rna_action(ptr).get_frame_range();
1106 r_values[0] = frame_range[0];
1107 r_values[1] = frame_range[1];
1108}
1109
1110static void rna_Action_frame_range_set(PointerRNA *ptr, const float *values)
1111{
1112 bAction *data = id_cast<bAction *>(ptr->owner_id);
1113
1114 data->flag |= ACT_FRAME_RANGE;
1115 data->frame_start = values[0];
1116 data->frame_end = values[1];
1117 CLAMP_MIN(data->frame_end, data->frame_start);
1118}
1119
1120static void rna_Action_curve_frame_range_get(PointerRNA *ptr, float *values)
1121{ /* don't include modifiers because they too easily can have very large
1122 * ranges: MINAFRAMEF to MAXFRAMEF. */
1123 const float2 frame_range = rna_action(ptr).get_frame_range_of_keys(false);
1124 values[0] = frame_range[0];
1125 values[1] = frame_range[1];
1126}
1127
1128static void rna_Action_use_frame_range_set(PointerRNA *ptr, bool value)
1129{
1130 animrig::Action &action = rna_action(ptr);
1131
1132 if (value) {
1133 /* If the frame range is blank, initialize it by scanning F-Curves. */
1134 if ((action.frame_start == action.frame_end) && (action.frame_start == 0)) {
1135 const float2 frame_range = action.get_frame_range_of_keys(false);
1136 action.frame_start = frame_range[0];
1137 action.frame_end = frame_range[1];
1138 }
1139
1140 action.flag |= ACT_FRAME_RANGE;
1141 }
1142 else {
1143 action.flag &= ~ACT_FRAME_RANGE;
1144 }
1145}
1146
1147static void rna_Action_start_frame_set(PointerRNA *ptr, float value)
1148{
1149 bAction *data = id_cast<bAction *>(ptr->owner_id);
1150
1151 data->frame_start = value;
1152 CLAMP_MIN(data->frame_end, data->frame_start);
1153}
1154
1155static void rna_Action_end_frame_set(PointerRNA *ptr, float value)
1156{
1157 bAction *data = id_cast<bAction *>(ptr->owner_id);
1158
1159 data->frame_end = value;
1160 CLAMP_MAX(data->frame_start, data->frame_end);
1161}
1162
1163static void rna_Action_deselect_keys(bAction *act)
1164{
1165 animrig::action_deselect_keys(act->wrap());
1167}
1168
1169static FCurve *rna_Action_fcurve_ensure_for_datablock(bAction *_self,
1170 Main *bmain,
1171 ReportList *reports,
1172 ID *datablock,
1173 const char *data_path,
1174 const int array_index,
1175 const char *group_name)
1176{
1177 /* Precondition checks. */
1178 {
1179 if (animrig::get_action(*datablock) != _self) {
1180 BKE_reportf(reports,
1182 "Assign action \"%s\" to \"%s\" before calling this function",
1183 _self->id.name + 2,
1184 datablock->name + 2);
1185 return nullptr;
1186 }
1187
1188 BLI_assert(data_path != nullptr);
1189 if (data_path[0] == '\0') {
1190 BKE_report(reports, RPT_ERROR_INVALID_INPUT, "F-Curve data path empty, invalid argument");
1191 return nullptr;
1192 }
1193 }
1194
1195 animrig::FCurveDescriptor descriptor = {data_path, array_index};
1196 if (group_name && group_name[0]) {
1197 descriptor.channel_group = group_name;
1198 }
1199
1200 FCurve &fcurve = animrig::action_fcurve_ensure(bmain, *_self, *datablock, descriptor);
1201
1203 return &fcurve;
1204}
1205
1210bool rna_Action_id_poll(PointerRNA * /* ptr */, PointerRNA value)
1211{
1212 bAction *dna_action = id_cast<bAction *>(value.owner_id);
1213
1214 if (!dna_action) {
1215 return false;
1216 }
1217
1218 /* Layered Actions can always be assigned. */
1219 BLI_assert(dna_action->idroot == 0);
1220 return true;
1221}
1222
1227static void reevaluate_fcurve_errors(bAnimContext *ac)
1228{
1229 /* Need to take off the flag before filtering, else the filter code would skip the FCurves, which
1230 * have not yet been validated. */
1231 const bool filtering_enabled = ac->filters.flag & ADS_FILTER_ONLY_ERRORS;
1232 if (filtering_enabled) {
1233 ac->filters.flag &= ~ADS_FILTER_ONLY_ERRORS;
1234 }
1235 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
1237 ANIM_animdata_filter(ac, &anim_data, filter, ac->data, eAnimCont_Types(ac->datatype));
1238
1239 for (bAnimListElem &ale : anim_data) {
1240 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
1241 PointerRNA ptr;
1242 PropertyRNA *prop;
1243 PointerRNA id_ptr = RNA_id_pointer_create(ale.id);
1244 if (RNA_path_resolve_property(&id_ptr, fcu->rna_path_parsed(), &ptr, &prop)) {
1245 fcu->flag &= ~FCURVE_DISABLED;
1246 }
1247 else {
1248 fcu->flag |= FCURVE_DISABLED;
1249 }
1250 }
1251
1252 ANIM_animdata_freelist(&anim_data);
1253 if (filtering_enabled) {
1254 ac->filters.flag |= ADS_FILTER_ONLY_ERRORS;
1255 }
1256}
1257
1258/* All FCurves need to be validated when the "show_only_errors" button is enabled. */
1259static void rna_Action_show_errors_update(bContext *C, PointerRNA * /*ptr*/)
1260{
1261 bAnimContext ac;
1262
1263 /* Get editor data. */
1264 if (ANIM_animdata_get_context(C, &ac) == 0) {
1265 return;
1266 }
1267
1268 if (!(ac.ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
1269 return;
1270 }
1271
1272 reevaluate_fcurve_errors(&ac);
1273}
1274
1275static std::optional<std::string> rna_DopeSheet_path(const PointerRNA *ptr)
1276{
1277 if (GS(ptr->owner_id->name) == ID_SCR) {
1278 const bScreen *screen = reinterpret_cast<bScreen *>(ptr->owner_id);
1279 const bDopeSheet *ads = static_cast<bDopeSheet *>(ptr->data);
1280
1281 for (const auto [area_index, area] : screen->areabase.enumerate()) {
1282 for (const auto [space_index, sl] : area.spacedata.enumerate()) {
1283 if (sl.spacetype == SPACE_GRAPH) {
1284 const SpaceGraph *sipo = reinterpret_cast<const SpaceGraph *>(&sl);
1285 if (sipo->ads == ads) {
1286 return fmt::format("areas[{}].spaces[{}].dopesheet", area_index, space_index);
1287 }
1288 }
1289 else if (sl.spacetype == SPACE_NLA) {
1290 const SpaceNla *snla = reinterpret_cast<const SpaceNla *>(&sl);
1291 if (snla->ads == ads) {
1292 return fmt::format("areas[{}].spaces[{}].dopesheet", area_index, space_index);
1293 }
1294 }
1295 else if (sl.spacetype == SPACE_ACTION) {
1296 const SpaceAction *saction = reinterpret_cast<const SpaceAction *>(&sl);
1297 if (&saction->ads == ads) {
1298 return fmt::format("areas[{}].spaces[{}].dopesheet", area_index, space_index);
1299 }
1300 }
1301 }
1302 }
1303 }
1304 return "dopesheet";
1305}
1306
1314static const EnumPropertyItem *rna_ActionSlot_target_id_type_itemf(bContext * /* C */,
1315 PointerRNA * /* ptr */,
1316 PropertyRNA * /* prop */,
1317 bool *r_free)
1318{
1319 /* These items don't change, as the ID types are hard-coded. So better to
1320 * cache the list of enum items. */
1321 static EnumPropertyItem *_rna_ActionSlot_target_id_type_items = nullptr;
1322
1323 if (_rna_ActionSlot_target_id_type_items) {
1324 return _rna_ActionSlot_target_id_type_items;
1325 }
1326
1327 int totitem = 0;
1328 EnumPropertyItem *items = nullptr;
1329
1330 int i = 0;
1331 while (rna_enum_id_type_items[i].identifier != nullptr) {
1332 EnumPropertyItem item = {0};
1334 item.name = rna_enum_id_type_items[i].name;
1335 item.identifier = rna_enum_id_type_items[i].identifier;
1336 item.icon = rna_enum_id_type_items[i].icon;
1337 item.description = rna_enum_id_type_items[i].description;
1338 RNA_enum_item_add(&items, &totitem, &item);
1339 i++;
1340 }
1341
1343
1344 RNA_enum_item_end(&items, &totitem);
1345
1346 /* Don't free, but keep a reference to the created list. This is necessary
1347 * because of the PROP_ENUM_NO_CONTEXT flag. Without it, this will make
1348 * Blender use memory after it is freed:
1349 *
1350 * >>> slot = C.object.animation_data.action_slot
1351 * >>> enum_item = s.bl_rna.properties['target_id_type'].enum_items[slot.target_id_type]
1352 * >>> print(enum_item.name)
1353 */
1354 *r_free = false;
1355 _rna_ActionSlot_target_id_type_items = items;
1356
1357 auto rna_free_enum_items = [](void *items) {
1358 MEM_delete(static_cast<EnumPropertyItem *>(items));
1359 };
1360 BKE_blender_atexit_register(rna_free_enum_items, items);
1361
1362 return items;
1363}
1364
1365static void rna_ActionSlot_target_id_type_set(PointerRNA *ptr, int value)
1366{
1367 animrig::Action &action = reinterpret_cast<bAction *>(ptr->owner_id)->wrap();
1368 animrig::Slot &slot = reinterpret_cast<ActionSlot *>(ptr->data)->wrap();
1369
1370 if (slot.idtype != 0) {
1371 /* Ignore the assignment. */
1372 printf(
1373 "WARNING: ignoring assignment to target_id_type of Slot '%s' in Action '%s'. A Slot's "
1374 "target_id_type can only be changed when currently 'UNSPECIFIED'.\n",
1375 slot.identifier,
1376 action.id.name);
1377 return;
1378 }
1379
1380 action.slot_idtype_define(slot, ID_Type(value));
1381}
1382
1383} // namespace blender
1384
1385#else
1386
1387namespace blender {
1388
1390{
1391 StructRNA *srna;
1392 PropertyRNA *prop;
1393
1394 srna = RNA_def_struct(brna, "DopeSheet", nullptr);
1395 RNA_def_struct_sdna(srna, "bDopeSheet");
1396 RNA_def_struct_path_func(srna, "rna_DopeSheet_path");
1398 srna, "Dope Sheet", "Settings for filtering the channels shown in animation editors");
1399
1400 /* Source of DopeSheet data */
1401 /* XXX: make this obsolete? */
1402 prop = RNA_def_property(srna, "source", PROP_POINTER, PROP_NONE);
1403 RNA_def_property_struct_type(prop, "ID");
1405 prop, "Source", "ID-Block representing source data, usually ID_SCE (i.e. Scene)");
1406
1407 /* Show data-block filters */
1408 prop = RNA_def_property(srna, "show_datablock_filters", PROP_BOOLEAN, PROP_NONE);
1411 prop,
1412 "Show Data-Block Filters",
1413 "Show options for whether channels related to certain types of data are included");
1414 RNA_def_property_ui_icon(prop, ICON_RIGHTARROW, 1);
1416
1417 /* General Filtering Settings */
1418 prop = RNA_def_property(srna, "show_only_selected", PROP_BOOLEAN, PROP_NONE);
1419 RNA_def_property_boolean_sdna(prop, nullptr, "filterflag", ADS_FILTER_ONLYSEL);
1421 prop, "Only Show Selected", "Only include channels relating to selected objects and data");
1422 RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, 0);
1424
1425 prop = RNA_def_property(srna, "show_only_slot_of_active_object", PROP_BOOLEAN, PROP_NONE);
1428 prop,
1429 "Only Show Slot of Active Object",
1430 "Only show the slot of the active Object. Otherwise show all the Action's Slots");
1431 RNA_def_property_ui_icon(prop, ICON_ACTION_SLOT, 0);
1433
1434 prop = RNA_def_property(srna, "show_hidden", PROP_BOOLEAN, PROP_NONE);
1435 RNA_def_property_boolean_sdna(prop, nullptr, "filterflag", ADS_FILTER_INCL_HIDDEN);
1437 prop, "Show Hidden", "Include channels from objects/bone that are not visible");
1438 RNA_def_property_ui_icon(prop, ICON_OBJECT_HIDDEN, 0);
1440
1441 prop = RNA_def_property(srna, "use_datablock_sort", PROP_BOOLEAN, PROP_NONE);
1444 "Sort Data-Blocks",
1445 "Alphabetically sorts data-blocks - mainly objects in the scene "
1446 "(disable to increase viewport speed)");
1447 RNA_def_property_ui_icon(prop, ICON_SORTALPHA, 0);
1449
1450 prop = RNA_def_property(srna, "use_filter_invert", PROP_BOOLEAN, PROP_NONE);
1452 RNA_def_property_ui_text(prop, "Invert", "Invert filter search");
1453 RNA_def_property_ui_icon(prop, ICON_ZOOM_IN, 0);
1455
1456 /* Debug Filtering Settings */
1457 prop = RNA_def_property(srna, "show_only_errors", PROP_BOOLEAN, PROP_NONE);
1458 RNA_def_property_boolean_sdna(prop, nullptr, "filterflag", ADS_FILTER_ONLY_ERRORS);
1460 "Only Show Errors",
1461 "Only include F-Curves and drivers that are disabled or have errors");
1462 RNA_def_property_ui_icon(prop, ICON_STATUS_ERROR, 0);
1465 prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, "rna_Action_show_errors_update");
1466
1467 /* Object Collection Filtering Settings */
1468 prop = RNA_def_property(srna, "filter_collection", PROP_POINTER, PROP_NONE);
1469 RNA_def_property_pointer_sdna(prop, nullptr, "filter_grp");
1472 prop, "Filtering Collection", "Collection that included object should be a member of");
1474
1475 /* FCurve Display Name Search Settings */
1476 prop = RNA_def_property(srna, "filter_fcurve_name", PROP_STRING, PROP_NONE);
1477 RNA_def_property_string_sdna(prop, nullptr, "searchstr");
1478 RNA_def_property_ui_text(prop, "F-Curve Name Filter", "F-Curve live filtering string");
1479 RNA_def_property_ui_icon(prop, ICON_VIEWZOOM, 0);
1482
1483 /* NLA Name Search Settings (Shared with FCurve setting, but with different labels) */
1484 prop = RNA_def_property(srna, "filter_text", PROP_STRING, PROP_NONE);
1485 RNA_def_property_string_sdna(prop, nullptr, "searchstr");
1486 RNA_def_property_ui_text(prop, "Name Filter", "Live filtering string");
1488 RNA_def_property_ui_icon(prop, ICON_VIEWZOOM, 0);
1490
1491 /* Multi-word fuzzy search option for name/text filters */
1492 prop = RNA_def_property(srna, "use_multi_word_filter", PROP_BOOLEAN, PROP_NONE);
1495 "Multi-Word Fuzzy Filter",
1496 "Perform fuzzy/multi-word matching.\n"
1497 "Warning: May be slow");
1498 RNA_def_property_ui_icon(prop, ICON_SORTALPHA, 0);
1500
1501 /* NLA Specific Settings */
1502 prop = RNA_def_property(srna, "show_missing_nla", PROP_BOOLEAN, PROP_NONE);
1505 "Include Missing NLA",
1506 "Include animation data-blocks with no NLA data (NLA editor only)");
1507 RNA_def_property_ui_icon(prop, ICON_ACTION, 0);
1509
1510 /* Summary Settings (DopeSheet editors only) */
1511 prop = RNA_def_property(srna, "show_summary", PROP_BOOLEAN, PROP_NONE);
1512 RNA_def_property_boolean_sdna(prop, nullptr, "filterflag", ADS_FILTER_SUMMARY);
1514 prop, "Display Summary", "Display an additional 'summary' line (Dope Sheet editors only)");
1515 RNA_def_property_ui_icon(prop, ICON_BORDERMOVE, 0);
1517
1518 prop = RNA_def_property(srna, "show_expanded_summary", PROP_BOOLEAN, PROP_NONE);
1521 prop,
1522 "Collapse Summary",
1523 "Collapse summary when shown, so all other channels get hidden (Dope Sheet editors only)");
1525
1526 /* General DataType Filtering Settings */
1527 prop = RNA_def_property(srna, "show_transforms", PROP_BOOLEAN, PROP_NONE);
1528 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOOBJ);
1530 prop,
1531 "Display Transforms",
1532 "Include visualization of object-level animation data (mostly transforms)");
1533 RNA_def_property_ui_icon(prop, ICON_ORIENTATION_GLOBAL, 0); /* XXX? */
1535
1536 prop = RNA_def_property(srna, "show_shapekeys", PROP_BOOLEAN, PROP_NONE);
1539 prop, "Display Shape Keys", "Include visualization of shape key related animation data");
1540 RNA_def_property_ui_icon(prop, ICON_SHAPEKEY_DATA, 0);
1542
1543 prop = RNA_def_property(srna, "show_modifiers", PROP_BOOLEAN, PROP_NONE);
1546 prop,
1547 "Display Modifier Data",
1548 "Include visualization of animation data related to data-blocks linked to modifiers");
1549 RNA_def_property_ui_icon(prop, ICON_MODIFIER_DATA, 0);
1551
1552 prop = RNA_def_property(srna, "show_meshes", PROP_BOOLEAN, PROP_NONE);
1553 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOMESH);
1555 prop, "Display Meshes", "Include visualization of mesh related animation data");
1556 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_MESH, 0);
1558
1559 prop = RNA_def_property(srna, "show_lattices", PROP_BOOLEAN, PROP_NONE);
1560 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOLAT);
1562 prop, "Display Lattices", "Include visualization of lattice related animation data");
1563 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_LATTICE, 0);
1565
1566 prop = RNA_def_property(srna, "show_cameras", PROP_BOOLEAN, PROP_NONE);
1567 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOCAM);
1569 prop, "Display Camera", "Include visualization of camera related animation data");
1570 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_CAMERA, 0);
1572
1573 prop = RNA_def_property(srna, "show_materials", PROP_BOOLEAN, PROP_NONE);
1574 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOMAT);
1576 prop, "Display Material", "Include visualization of material related animation data");
1577 RNA_def_property_ui_icon(prop, ICON_MATERIAL_DATA, 0);
1579
1580 prop = RNA_def_property(srna, "show_lights", PROP_BOOLEAN, PROP_NONE);
1581 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOLAM);
1583 prop, "Display Light", "Include visualization of light related animation data");
1584 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_LIGHT, 0);
1586
1587 prop = RNA_def_property(srna, "show_linestyles", PROP_BOOLEAN, PROP_NONE);
1590 prop, "Display Line Style", "Include visualization of Line Style related Animation data");
1591 RNA_def_property_ui_icon(prop, ICON_LINE_DATA, 0);
1593
1594 prop = RNA_def_property(srna, "show_textures", PROP_BOOLEAN, PROP_NONE);
1595 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOTEX);
1597 prop, "Display Texture", "Include visualization of texture related animation data");
1598 RNA_def_property_ui_icon(prop, ICON_TEXTURE_DATA, 0);
1600
1601 prop = RNA_def_property(srna, "show_curves", PROP_BOOLEAN, PROP_NONE);
1602 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOCUR);
1604 prop, "Display Curve", "Include visualization of curve related animation data");
1605 RNA_def_property_ui_icon(prop, ICON_CURVE_DATA, 0);
1607
1608 prop = RNA_def_property(srna, "show_worlds", PROP_BOOLEAN, PROP_NONE);
1609 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOWOR);
1611 prop, "Display World", "Include visualization of world related animation data");
1612 RNA_def_property_ui_icon(prop, ICON_WORLD_DATA, 0);
1614
1615 prop = RNA_def_property(srna, "show_scenes", PROP_BOOLEAN, PROP_NONE);
1616 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOSCE);
1618 prop, "Display Scene", "Include visualization of scene related animation data");
1619 RNA_def_property_ui_icon(prop, ICON_SCENE_DATA, 0);
1621
1622 prop = RNA_def_property(srna, "show_particles", PROP_BOOLEAN, PROP_NONE);
1623 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOPART);
1625 prop, "Display Particle", "Include visualization of particle related animation data");
1626 RNA_def_property_ui_icon(prop, ICON_PARTICLE_DATA, 0);
1628
1629 prop = RNA_def_property(srna, "show_metaballs", PROP_BOOLEAN, PROP_NONE);
1630 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOMBA);
1632 prop, "Display Metaball", "Include visualization of metaball related animation data");
1633 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_META, 0);
1635
1636 prop = RNA_def_property(srna, "show_armatures", PROP_BOOLEAN, PROP_NONE);
1637 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOARM);
1639 prop, "Display Armature", "Include visualization of armature related animation data");
1640 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_ARMATURE, 0);
1642
1643 prop = RNA_def_property(srna, "show_nodes", PROP_BOOLEAN, PROP_NONE);
1644 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NONTREE);
1646 prop, "Display Node", "Include visualization of node related animation data");
1647 RNA_def_property_ui_icon(prop, ICON_NODETREE, 0);
1649
1650 prop = RNA_def_property(srna, "show_speakers", PROP_BOOLEAN, PROP_NONE);
1651 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag", ADS_FILTER_NOSPK);
1653 prop, "Display Speaker", "Include visualization of speaker related animation data");
1654 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_SPEAKER, 0);
1656
1657 prop = RNA_def_property(srna, "show_cache_files", PROP_BOOLEAN, PROP_NONE);
1660 prop, "Display Cache Files", "Include visualization of cache file related animation data");
1661 RNA_def_property_ui_icon(prop, ICON_FILE, 0);
1663
1664 prop = RNA_def_property(srna, "show_hair_curves", PROP_BOOLEAN, PROP_NONE);
1665 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag2", ADS_FILTER_NOHAIR);
1667 prop, "Display Hair", "Include visualization of hair related animation data");
1668 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_CURVES, 0);
1670
1671 prop = RNA_def_property(srna, "show_pointclouds", PROP_BOOLEAN, PROP_NONE);
1674 prop, "Display Point Cloud", "Include visualization of point cloud related animation data");
1675 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_POINTCLOUD, 0);
1677
1678 prop = RNA_def_property(srna, "show_volumes", PROP_BOOLEAN, PROP_NONE);
1679 RNA_def_property_boolean_negative_sdna(prop, nullptr, "filterflag2", ADS_FILTER_NOVOLUME);
1681 prop, "Display Volume", "Include visualization of volume related animation data");
1682 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_VOLUME, 0);
1684
1685 prop = RNA_def_property(srna, "show_lightprobes", PROP_BOOLEAN, PROP_NONE);
1688 prop, "Display Light Probe", "Include visualization of light probe related animation data");
1689 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_LIGHTPROBE, 0);
1691
1692 prop = RNA_def_property(srna, "show_gpencil", PROP_BOOLEAN, PROP_NONE);
1695 prop,
1696 "Display Grease Pencil",
1697 "Include visualization of Grease Pencil related animation data and frames");
1698 RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_GREASEPENCIL, 0);
1700
1701 prop = RNA_def_property(srna, "show_movieclips", PROP_BOOLEAN, PROP_NONE);
1704 prop, "Display Movie Clips", "Include visualization of movie clip related animation data");
1705 RNA_def_property_ui_icon(prop, ICON_TRACKER, 0);
1707
1708 prop = RNA_def_property(srna, "show_driver_fallback_as_error", PROP_BOOLEAN, PROP_NONE);
1711 prop,
1712 "Variable Fallback As Error",
1713 "Include drivers that relied on any fallback values for their evaluation "
1714 "in the Only Show Errors filter, even if the driver evaluation succeeded");
1715 RNA_def_property_ui_icon(prop, ICON_RNA, 0);
1717}
1718
1719/* =========================== Layered Action interface =========================== */
1720
1722{
1723 StructRNA *srna;
1724 PropertyRNA *prop;
1725
1726 FunctionRNA *func;
1727 PropertyRNA *parm;
1728
1729 RNA_def_property_srna(cprop, "ActionSlots");
1730 srna = RNA_def_struct(brna, "ActionSlots", nullptr);
1731 RNA_def_struct_sdna(srna, "bAction");
1732 RNA_def_struct_ui_text(srna, "Action Slots", "Collection of action slots");
1733
1734 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1735 RNA_def_property_struct_type(prop, "ActionSlot");
1738 prop, "rna_ActionSlots_active_get", "rna_ActionSlots_active_set", nullptr, nullptr);
1740
1741 RNA_def_property_ui_text(prop, "Active Slot", "Active slot for this action");
1742
1743 /* Animation.slots.new(...) */
1744 func = RNA_def_function(srna, "new", "rna_Action_slots_new");
1745 RNA_def_function_ui_description(func, "Add a slot to the Action");
1747 parm = RNA_def_enum(
1748 func,
1749 "id_type",
1751 ID_OB,
1752 "Data-block Type",
1753 "The data-block type that the slot is intended for. This is combined with the slot name to "
1754 "create the slot's unique identifier, and is also used to limit (on a best-effort basis) "
1755 "which data-blocks the slot can be assigned to.");
1757 parm = RNA_def_string(
1758 func,
1759 "name",
1760 nullptr,
1761 /* Minus 2 for the ID-type prefix. */
1762 sizeof(ActionSlot::identifier) - 2,
1763 "Name",
1764 "Name of the slot. This will be made unique within the Action among slots of the same type");
1766
1767 parm = RNA_def_pointer(func, "slot", "ActionSlot", "", "Newly created action slot");
1769 RNA_def_function_return(func, parm);
1770
1771 /* Animation.slots.remove(layer) */
1772 func = RNA_def_function(srna, "remove", "rna_Action_slots_remove");
1775 "Remove the slot from the Action, including all animation that "
1776 "is associated with that slot");
1777 parm = RNA_def_pointer(func, "action_slot", "ActionSlot", "Action Slot", "The slot to remove");
1779}
1780
1782{
1783 StructRNA *srna;
1784
1785 FunctionRNA *func;
1786 PropertyRNA *parm;
1787
1788 RNA_def_property_srna(cprop, "ActionLayers");
1789 srna = RNA_def_struct(brna, "ActionLayers", nullptr);
1790 RNA_def_struct_sdna(srna, "bAction");
1791 RNA_def_struct_ui_text(srna, "Action Layers", "Collection of animation layers");
1792
1793 /* Animation.layers.new(...) */
1794 func = RNA_def_function(srna, "new", "rna_Action_layers_new");
1797 func,
1798 "Add a layer to the Animation. Currently an Animation can only have at most one layer.");
1799 parm = RNA_def_string(func,
1800 "name",
1801 nullptr,
1802 sizeof(ActionLayer::name) - 1,
1803 "Name",
1804 "Name of the layer, will be made unique within the Action");
1806 parm = RNA_def_pointer(func, "layer", "ActionLayer", "", "Newly created animation layer");
1808 RNA_def_function_return(func, parm);
1809
1810 /* Animation.layers.remove(layer) */
1811 func = RNA_def_function(srna, "remove", "rna_Action_layers_remove");
1813 RNA_def_function_ui_description(func, "Remove the layer from the animation");
1814 parm = RNA_def_pointer(
1815 func, "anim_layer", "ActionLayer", "Animation Layer", "The layer to remove");
1817}
1818
1820{
1821 StructRNA *srna;
1822 PropertyRNA *prop;
1823 PropertyRNA *parm;
1824 FunctionRNA *func;
1825
1826 srna = RNA_def_struct(brna, "ActionSlot", nullptr);
1827 RNA_def_struct_path_func(srna, "rna_ActionSlot_path");
1828 RNA_def_struct_ui_icon(srna, ICON_ACTION_SLOT);
1830 srna,
1831 "Action slot",
1832 "Identifier for a set of channels in this Action, that can be used by a data-block "
1833 "to specify what it gets animated by");
1834
1836
1837 prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
1838 RNA_def_struct_name_property(srna, prop);
1839 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_ActionSlot_identifier_set");
1841 RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN, "rna_ActionSlot_identifier_update");
1843 prop,
1844 "Slot Identifier",
1845 "Used when connecting an Action to a data-block, to find the correct slot handle. This is "
1846 "the display name, prefixed by two characters determined by the slot's ID type");
1847
1848 prop = RNA_def_property(srna, "target_id_type", PROP_ENUM, PROP_NONE);
1849 RNA_def_property_enum_sdna(prop, nullptr, "idtype");
1852 prop, nullptr, "rna_ActionSlot_target_id_type_set", "rna_ActionSlot_target_id_type_itemf");
1853 RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN, "rna_ActionSlot_identifier_update");
1856 "Target ID Type",
1857 "Type of data-block that this slot is intended to animate; can be set "
1858 "when 'UNSPECIFIED' but is otherwise read-only");
1860
1861 prop = RNA_def_property(srna, "target_id_type_icon", PROP_INT, PROP_NONE);
1862 RNA_def_property_int_funcs(prop, "rna_ActionSlot_target_id_type_icon_get", nullptr, nullptr);
1864
1865 prop = RNA_def_property(srna, "name_display", PROP_STRING, PROP_NONE);
1867 "rna_ActionSlot_name_display_get",
1868 "rna_ActionSlot_name_display_length",
1869 "rna_ActionSlot_name_display_set");
1872 prop, NC_ANIMATION | ND_ANIMCHAN | NA_RENAME, "rna_ActionSlot_identifier_update");
1874 prop,
1875 "Slot Display Name",
1876 "Name of the slot, for display in the user interface. This name combined with the slot's "
1877 "data-block type is unique within its Action");
1878
1879 prop = RNA_def_property(srna, "handle", PROP_INT, PROP_NONE);
1882 "Slot Handle",
1883 "Number specific to this Slot, unique within the Action.\n"
1884 "This is used, for example, on a ActionKeyframeStrip to look up the "
1885 "ActionChannelbag for this Slot");
1886
1887 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
1888 RNA_def_property_boolean_sdna(prop, nullptr, "slot_flags", int(animrig::Slot::Flags::Active));
1890 prop,
1891 "Active",
1892 "Whether this is the active slot, can be set by assigning to action.slots.active");
1896
1897 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
1898 RNA_def_property_boolean_sdna(prop, nullptr, "slot_flags", int(animrig::Slot::Flags::Selected));
1899 RNA_def_property_ui_text(prop, "Select", "Selection state of the slot");
1903
1904 prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
1905 RNA_def_property_boolean_sdna(prop, nullptr, "slot_flags", int(animrig::Slot::Flags::Expanded));
1906 RNA_def_property_ui_text(prop, "Show Expanded", "Expanded state of the slot");
1910
1911 func = RNA_def_function(srna, "users", "rna_ActionSlot_users");
1914 func, "Return the data-blocks that are animated by this slot of this action");
1915 /* Return value. */
1916 parm = RNA_def_property(func, "users", PROP_COLLECTION, PROP_NONE);
1917 RNA_def_property_struct_type(parm, "ID");
1918 RNA_def_function_return(func, parm);
1919
1920 func = RNA_def_function(srna, "duplicate", "rna_ActionSlot_duplicate");
1922 func, "Duplicate this slot, including all the animation data associated with it");
1923 /* Return value. */
1924 parm = RNA_def_property(func, "slot", PROP_POINTER, PROP_NONE);
1926 RNA_def_property_struct_type(parm, "ActionSlot");
1927 RNA_def_property_ui_text(parm, "Duplicated Slot", "The slot created by duplicating this one");
1929 RNA_def_function_return(func, parm);
1930}
1931
1933{
1934 StructRNA *srna;
1935
1936 FunctionRNA *func;
1937 PropertyRNA *parm;
1938
1939 RNA_def_property_srna(cprop, "ActionStrips");
1940 srna = RNA_def_struct(brna, "ActionStrips", nullptr);
1941 RNA_def_struct_sdna(srna, "ActionLayer");
1942 RNA_def_struct_ui_text(srna, "Action Strips", "Collection of animation strips");
1943
1944 /* Layer.strips.new(type='...') */
1945 func = RNA_def_function(srna, "new", "rna_ActionStrips_new");
1947 "Add a new strip to the layer. Currently a layer can only have "
1948 "one strip, with infinite boundaries.");
1950 parm = RNA_def_enum(func,
1951 "type",
1954 "Type",
1955 "The type of strip to create");
1956 /* Return value. */
1957 parm = RNA_def_pointer(func, "strip", "ActionStrip", "", "Newly created animation strip");
1959 RNA_def_function_return(func, parm);
1960
1961 /* Layer.strips.remove(strip) */
1962 func = RNA_def_function(srna, "remove", "rna_ActionStrips_remove");
1964 RNA_def_function_ui_description(func, "Remove the strip from the animation layer");
1965 parm = RNA_def_pointer(
1966 func, "anim_strip", "ActionStrip", "Animation Strip", "The strip to remove");
1968}
1969
1971{
1972 StructRNA *srna;
1973 PropertyRNA *prop;
1974
1975 srna = RNA_def_struct(brna, "ActionLayer", nullptr);
1976 RNA_def_struct_ui_text(srna, "Action Layer", "");
1977 RNA_def_struct_path_func(srna, "rna_ActionLayer_path");
1978
1979 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1980 RNA_def_struct_name_property(srna, prop);
1981
1982 /* Disabled in RNA until layered animation is actually implemented.
1983 *
1984 * The animation evaluation already takes these into account, but there is no guarantee that the
1985 * mixing that is currently implemented is going to be mathematically identical to the eventual
1986 * implementation. */
1987# if 0
1988 prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_FACTOR);
1989 RNA_def_property_range(prop, 0.0f, 1.0f);
1991 prop, "Influence", "How much of this layer is used when blending into the lower layers");
1992 RNA_def_property_ui_range(prop, 0.0, 1.0, 3, 2);
1994 RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN, "rna_Action_tag_animupdate");
1995
1996 prop = RNA_def_property(srna, "mix_mode", PROP_ENUM, PROP_NONE);
1997 RNA_def_property_enum_sdna(prop, nullptr, "layer_mix_mode");
1999 prop, "Mix Mode", "How animation of this layer is blended into the lower layers");
2001 RNA_def_property_enum_items(prop, rna_enum_layer_mix_mode_items);
2002 RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN, "rna_Action_tag_animupdate");
2003# endif
2004
2005 /* Collection properties. */
2006 prop = RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
2007 RNA_def_property_struct_type(prop, "ActionStrip");
2009 "rna_iterator_ActionLayer_strips_begin",
2010 "rna_iterator_array_next",
2011 "rna_iterator_array_end",
2012 "rna_iterator_array_dereference_get",
2013 "rna_iterator_ActionLayer_strips_length",
2014 nullptr,
2015 nullptr,
2016 nullptr);
2017 RNA_def_property_ui_text(prop, "Strips", "The list of strips that are on this animation layer");
2018
2019 rna_def_ActionLayer_strips(brna, prop);
2020}
2021
2023{
2024 StructRNA *srna;
2025
2026 FunctionRNA *func;
2027 PropertyRNA *parm;
2028
2029 RNA_def_property_srna(cprop, "ActionChannelbags");
2030 srna = RNA_def_struct(brna, "ActionChannelbags", nullptr);
2031 RNA_def_struct_sdna(srna, "ActionStrip");
2033 srna,
2034 "Animation Channels for Slots",
2035 "For each action slot, a list of animation channels that are meant for that slot");
2036
2037 /* Strip.channelbags.new(slot=...) */
2038 func = RNA_def_function(srna, "new", "rna_Channelbags_new");
2040 func,
2041 "Add a new channelbag to the strip, to contain animation channels for a specific slot");
2043 parm = RNA_def_pointer(func,
2044 "slot",
2045 "ActionSlot",
2046 "Action Slot",
2047 "The slot that should be animated by this channelbag");
2049
2050 /* Return value. */
2051 parm = RNA_def_pointer(func, "channelbag", "ActionChannelbag", "", "Newly created channelbag");
2053 RNA_def_function_return(func, parm);
2054
2055 /* Strip.channelbags.remove(strip) */
2056 func = RNA_def_function(srna, "remove", "rna_Channelbags_remove");
2058 RNA_def_function_ui_description(func, "Remove the channelbag from the strip");
2059 parm = RNA_def_pointer(func, "channelbag", "ActionChannelbag", "", "The channelbag to remove");
2061}
2062
2067{
2068 StructRNA *srna;
2069 PropertyRNA *prop;
2070
2071 srna = RNA_def_struct(brna, "ActionKeyframeStrip", "ActionStrip");
2073 srna, "Keyframe Animation Strip", "Strip with a set of F-Curves for each action slot");
2074 RNA_def_struct_sdna_from(srna, "ActionStrip", nullptr);
2075
2076 prop = RNA_def_property(srna, "channelbags", PROP_COLLECTION, PROP_NONE);
2077 RNA_def_property_struct_type(prop, "ActionChannelbag");
2079 "rna_iterator_keyframestrip_channelbags_begin",
2080 "rna_iterator_array_next",
2081 "rna_iterator_array_end",
2082 "rna_iterator_array_dereference_get",
2083 "rna_iterator_keyframestrip_channelbags_length",
2084 nullptr,
2085 nullptr,
2086 nullptr);
2088
2089 {
2090 FunctionRNA *func;
2091 PropertyRNA *parm;
2092
2093 /* Strip.channelbag(...). */
2094 func = RNA_def_function(srna, "channelbag", "rna_ActionStrip_channelbag");
2096 RNA_def_function_ui_description(func, "Find the ActionChannelbag for a specific Slot");
2097 parm = RNA_def_pointer(
2098 func, "slot", "ActionSlot", "Slot", "The slot for which to find the channelbag");
2100 RNA_def_boolean(func,
2101 "ensure",
2102 false,
2103 "Create if necessary",
2104 "Ensure the channelbag exists for this slot, creating it if necessary");
2105 parm = RNA_def_pointer(func, "channels", "ActionChannelbag", "Channels", "");
2106 RNA_def_function_return(func, parm);
2107
2108 /* Strip.key_insert(...). */
2109
2110 func = RNA_def_function(srna, "key_insert", "rna_ActionStrip_key_insert");
2112 parm = RNA_def_pointer(func,
2113 "slot",
2114 "ActionSlot",
2115 "Slot",
2116 "The slot that identifies which 'thing' should be keyed");
2118
2119 parm = RNA_def_string(func, "data_path", nullptr, 0, "Data Path", "F-Curve data path");
2121
2122 parm = RNA_def_int(
2123 func,
2124 "array_index",
2125 -1,
2126 INT_MIN,
2127 INT_MAX,
2128 "Array Index",
2129 "Index of the animated array element, or -1 if the property is not an array",
2130 -1,
2131 4);
2133
2134 parm = RNA_def_float(func,
2135 "value",
2136 0.0,
2137 -FLT_MAX,
2138 FLT_MAX,
2139 "Value to key",
2140 "Value of the animated property",
2141 -FLT_MAX,
2142 FLT_MAX);
2144
2145 parm = RNA_def_float(func,
2146 "time",
2147 0.0,
2148 -FLT_MAX,
2149 FLT_MAX,
2150 "Time of the key",
2151 "Time, in frames, of the key",
2152 -FLT_MAX,
2153 FLT_MAX);
2155
2156 parm = RNA_def_boolean(
2157 func, "success", true, "Success", "Whether the key was successfully inserted");
2158
2159 RNA_def_function_return(func, parm);
2160 }
2161}
2162
2164{
2165 StructRNA *srna;
2166 PropertyRNA *prop;
2167
2168 srna = RNA_def_struct(brna, "ActionStrip", nullptr);
2169 RNA_def_struct_ui_text(srna, "Action Strip", "");
2170 RNA_def_struct_path_func(srna, "rna_ActionStrip_path");
2171 RNA_def_struct_refine_func(srna, "rna_ActionStrip_refine");
2172
2173 static const EnumPropertyItem prop_type_items[] = {
2175 "KEYFRAME",
2176 0,
2177 "Keyframe",
2178 "Strip with a set of F-Curves for each action slot"},
2179 {0, nullptr, 0, nullptr, nullptr},
2180 };
2181
2182 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
2183 RNA_def_property_enum_sdna(prop, nullptr, "strip_type");
2184 RNA_def_property_enum_items(prop, prop_type_items);
2186
2187 /* Define Strip subtypes. */
2189}
2190
2192{
2193 StructRNA *srna;
2194
2195 FunctionRNA *func;
2196 PropertyRNA *parm;
2197
2198 RNA_def_property_srna(cprop, "ActionChannelbagFCurves");
2199 srna = RNA_def_struct(brna, "ActionChannelbagFCurves", nullptr);
2200 RNA_def_struct_sdna(srna, "ActionChannelbag");
2202 srna, "F-Curves", "Collection of F-Curves for a specific action slot, on a specific strip");
2203
2204 /* Channelbag.fcurves.new(...) */
2205 func = RNA_def_function(srna, "new", "rna_Channelbag_fcurve_new");
2206 RNA_def_function_ui_description(func, "Add an F-Curve to the channelbag");
2208 parm = RNA_def_string(func, "data_path", nullptr, 0, "Data Path", "F-Curve data path to use");
2210 RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
2211 parm = RNA_def_string(
2212 func,
2213 "group_name",
2214 nullptr,
2215 sizeof(bActionGroup::name),
2216 "Group Name",
2217 "Name of the Group for this F-Curve, will be created if it does not exist yet");
2218 parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve");
2220 RNA_def_function_return(func, parm);
2221
2222 func = RNA_def_function(srna, "new_from_fcurve", "rna_Channelbag_fcurve_new_from_fcurve");
2224 func, "Copy an F-Curve into the channelbag. The original F-Curve is unchanged");
2226 parm = RNA_def_pointer(func, "source", "FCurve", "Source F-Curve", "The F-Curve to copy");
2228 parm = RNA_def_string(func,
2229 "data_path",
2230 nullptr,
2231 0,
2232 "Data Path",
2233 "F-Curve data path to use. If not provided, this will use the same data "
2234 "path as the given F-Curve");
2235 parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Newly created F-Curve");
2237 RNA_def_function_return(func, parm);
2238
2239 /* Channelbag.fcurves.ensure(...) */
2240 func = RNA_def_function(srna, "ensure", "rna_Channelbag_fcurve_ensure");
2242 func, "Returns the F-Curve if it already exists, and creates it if necessary");
2244 parm = RNA_def_string(func, "data_path", nullptr, 0, "Data Path", "F-Curve data path to use");
2246 RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
2247 parm = RNA_def_string(func,
2248 "group_name",
2249 nullptr,
2250 sizeof(bActionGroup::name),
2251 "Group Name",
2252 "Name of the Group for this F-Curve, will be created if it does not exist "
2253 "yet. This parameter is ignored if the F-Curve already exists");
2254 parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "Found or newly created F-Curve");
2256 RNA_def_function_return(func, parm);
2257
2258 /* Channelbag.fcurves.find(...) */
2259 func = RNA_def_function(srna, "find", "rna_Channelbag_fcurve_find");
2261 func,
2262 "Find an F-Curve. Note that this function performs a linear scan "
2263 "of all F-Curves in the channelbag.");
2265 parm = RNA_def_string(func, "data_path", nullptr, 0, "Data Path", "F-Curve data path");
2267 RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
2268 parm = RNA_def_pointer(
2269 func, "fcurve", "FCurve", "", "The found F-Curve, or None if it does not exist");
2270 RNA_def_function_return(func, parm);
2271
2272 /* Channelbag.fcurves.remove(...) */
2273 func = RNA_def_function(srna, "remove", "rna_Channelbag_fcurve_remove");
2274 RNA_def_function_ui_description(func, "Remove F-Curve");
2276 parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "F-Curve to remove");
2279
2280 /* Channelbag.fcurves.clear() */
2281 func = RNA_def_function(srna, "clear", "rna_Channelbag_fcurve_clear");
2283 RNA_def_function_ui_description(func, "Remove all F-Curves from this channelbag");
2284}
2285
2287{
2288 StructRNA *srna;
2289
2290 FunctionRNA *func;
2291 PropertyRNA *parm;
2292
2293 RNA_def_property_srna(cprop, "ActionChannelbagGroups");
2294 srna = RNA_def_struct(brna, "ActionChannelbagGroups", nullptr);
2295 RNA_def_struct_sdna(srna, "ActionChannelbag");
2296 RNA_def_struct_ui_text(srna, "F-Curve Groups", "Collection of f-curve groups");
2297
2298 func = RNA_def_function(srna, "new", "rna_Channelbag_group_new");
2300 RNA_def_function_ui_description(func, "Create a new action group and add it to the action");
2301 parm = RNA_def_string(func, "name", "Group", 0, "", "New name for the action group");
2303 parm = RNA_def_pointer(func, "action_group", "ActionGroup", "", "Newly created action group");
2305 RNA_def_function_return(func, parm);
2306
2307 func = RNA_def_function(srna, "remove", "rna_Channelbag_group_remove");
2308 RNA_def_function_ui_description(func, "Remove action group");
2310 parm = RNA_def_pointer(func, "action_group", "ActionGroup", "", "Action group to remove");
2313}
2314
2316{
2317 StructRNA *srna;
2318 PropertyRNA *prop;
2319
2320 srna = RNA_def_struct(brna, "ActionChannelbag", nullptr);
2322 srna,
2323 "Animation Channel Bag",
2324 "Collection of animation channels, typically associated with an action slot");
2325 RNA_def_struct_path_func(srna, "rna_Channelbag_path");
2326
2327 prop = RNA_def_property(srna, "slot_handle", PROP_INT, PROP_NONE);
2329
2330 prop = RNA_def_property(srna, "slot", PROP_POINTER, PROP_NONE);
2331 RNA_def_property_struct_type(prop, "ActionSlot");
2332 RNA_def_property_ui_text(prop, "Slot", "The Slot that the Channelbag's animation data is for");
2334 RNA_def_property_pointer_funcs(prop, "rna_Channelbag_slot_get", nullptr, nullptr, nullptr);
2335
2336 /* Channelbag.fcurves */
2337 prop = RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE);
2339 "rna_iterator_Channelbag_fcurves_begin",
2340 "rna_iterator_array_next",
2341 "rna_iterator_array_end",
2342 "rna_iterator_array_dereference_get",
2343 "rna_iterator_Channelbag_fcurves_length",
2344 nullptr,
2345 nullptr,
2346 nullptr);
2347 RNA_def_property_struct_type(prop, "FCurve");
2348 RNA_def_property_ui_text(prop, "F-Curves", "The individual F-Curves that animate the slot");
2349 rna_def_channelbag_fcurves(brna, prop);
2350
2351 /* Channelbag.groups */
2352 prop = RNA_def_property(srna, "groups", PROP_COLLECTION, PROP_NONE);
2354 "rna_iterator_Channelbag_groups_begin",
2355 "rna_iterator_array_next",
2356 "rna_iterator_array_end",
2357 "rna_iterator_array_dereference_get",
2358 "rna_iterator_Channelbag_groups_length",
2359 nullptr,
2360 nullptr,
2361 nullptr);
2362 RNA_def_property_struct_type(prop, "ActionGroup");
2364 prop,
2365 "F-Curve Groups",
2366 "Groupings of F-Curves for display purposes, in e.g. the dopesheet and graph editor");
2367 rna_def_channelbag_groups(brna, prop);
2368}
2369
2371{
2372 StructRNA *srna;
2373 PropertyRNA *prop;
2374
2375 srna = RNA_def_struct(brna, "ActionGroup", nullptr);
2376 RNA_def_struct_sdna(srna, "bActionGroup");
2377 RNA_def_struct_ui_text(srna, "Action Group", "Groups of F-Curves");
2378
2379 RNA_def_struct_path_func(srna, "rna_ActionGroup_path");
2380
2381 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2382 RNA_def_property_ui_text(prop, "Name", "");
2383 RNA_def_struct_name_property(srna, prop);
2385
2386 /* WARNING: be very careful when working with this list, since the endpoint is not
2387 * defined like a standard ListBase. Adding/removing channels from this list needs
2388 * extreme care, otherwise the F-Curve list running through adjacent groups does
2389 * not match up with the one stored in the Action, resulting in curves which do not
2390 * show up in animation editors. In extreme cases, animation may also selectively
2391 * fail to play back correctly.
2392 *
2393 * If such changes are required, these MUST go through the API functions for manipulating
2394 * these F-Curve groupings. Also, note that groups only apply in actions ONLY.
2395 */
2396 prop = RNA_def_property(srna, "channels", PROP_COLLECTION, PROP_NONE);
2397 RNA_def_property_collection_sdna(prop, nullptr, "channels", nullptr);
2398 RNA_def_property_struct_type(prop, "FCurve");
2400 "rna_ActionGroup_channels_begin",
2401 "rna_ActionGroup_channels_next",
2402 "rna_ActionGroup_channels_end",
2403 "rna_ActionGroup_channels_get",
2404 nullptr,
2405 nullptr,
2406 nullptr,
2407 nullptr);
2408 RNA_def_property_ui_text(prop, "Channels", "F-Curves in this group");
2409
2410 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
2411 RNA_def_property_boolean_sdna(prop, nullptr, "flag", AGRP_SELECTED);
2412 RNA_def_property_ui_text(prop, "Select", "Action group is selected");
2414
2415 prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
2416 RNA_def_property_boolean_sdna(prop, nullptr, "flag", AGRP_PROTECTED);
2417 RNA_def_property_ui_text(prop, "Lock", "Action group is locked");
2419
2420 prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
2421 RNA_def_property_boolean_sdna(prop, nullptr, "flag", AGRP_MUTED);
2422 RNA_def_property_ui_text(prop, "Mute", "Action group is muted");
2424
2425 prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
2427 RNA_def_property_boolean_sdna(prop, nullptr, "flag", AGRP_EXPANDED);
2428 RNA_def_property_ui_text(prop, "Expanded", "Action group is expanded except in graph editor");
2430
2431 prop = RNA_def_property(srna, "show_expanded_graph", PROP_BOOLEAN, PROP_NONE);
2433 RNA_def_property_boolean_sdna(prop, nullptr, "flag", AGRP_EXPANDED_G);
2435 prop, "Expanded in Graph Editor", "Action group is expanded in graph editor");
2437
2438 prop = RNA_def_property(srna, "use_pin", PROP_BOOLEAN, PROP_NONE);
2441 RNA_def_property_ui_text(prop, "Pin in Graph Editor", "");
2443
2444 /* color set */
2446}
2447
2448/* =========================== Legacy Action interface =========================== */
2449
2451{
2452 StructRNA *srna;
2453 PropertyRNA *prop;
2454
2455 FunctionRNA *func;
2456 PropertyRNA *parm;
2457
2458 RNA_def_property_srna(cprop, "ActionPoseMarkers");
2459 srna = RNA_def_struct(brna, "ActionPoseMarkers", nullptr);
2460 RNA_def_struct_sdna(srna, "bAction");
2461 RNA_def_struct_ui_text(srna, "Action Pose Markers", "Collection of timeline markers");
2462
2463 func = RNA_def_function(srna, "new", "rna_Action_pose_markers_new");
2464 RNA_def_function_ui_description(func, "Add a pose marker to the action");
2465 parm = RNA_def_string(
2466 func, "name", "Marker", 0, nullptr, "New name for the marker (not unique)");
2468 parm = RNA_def_pointer(func, "marker", "TimelineMarker", "", "Newly created marker");
2470 RNA_def_function_return(func, parm);
2471
2472 func = RNA_def_function(srna, "remove", "rna_Action_pose_markers_remove");
2473 RNA_def_function_ui_description(func, "Remove a timeline marker");
2475 parm = RNA_def_pointer(func, "marker", "TimelineMarker", "", "Timeline marker to remove");
2478
2479 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2480 RNA_def_property_struct_type(prop, "TimelineMarker");
2483 "rna_Action_active_pose_marker_get",
2484 "rna_Action_active_pose_marker_set",
2485 nullptr,
2486 nullptr);
2487 RNA_def_property_ui_text(prop, "Active Pose Marker", "Active pose marker for this action");
2488
2489 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
2490 RNA_def_property_int_sdna(prop, nullptr, "active_marker");
2493 "rna_Action_active_pose_marker_index_get",
2494 "rna_Action_active_pose_marker_index_set",
2495 "rna_Action_active_pose_marker_index_range");
2496 RNA_def_property_ui_text(prop, "Active Pose Marker Index", "Index of active pose marker");
2497}
2498
2499static void rna_def_action(BlenderRNA *brna)
2500{
2501 StructRNA *srna;
2502 PropertyRNA *prop;
2503
2504 FunctionRNA *func;
2505 PropertyRNA *parm;
2506
2507 srna = RNA_def_struct(brna, "Action", "ID");
2508 RNA_def_struct_sdna(srna, "bAction");
2509 RNA_def_struct_ui_text(srna, "Action", "A collection of F-Curves for animation");
2510 RNA_def_struct_ui_icon(srna, ICON_ACTION);
2511
2512 /* Properties. */
2513 prop = RNA_def_property(srna, "is_empty", PROP_BOOLEAN, PROP_NONE);
2516 prop, "Is Empty", "False when there is any Layer, Slot, or legacy F-Curve");
2517 RNA_def_property_boolean_funcs(prop, "rna_Action_is_empty_get", nullptr);
2518
2519 prop = RNA_def_property(srna, "is_action_legacy", PROP_BOOLEAN, PROP_NONE);
2522 "Is Legacy Action",
2523 "Return whether this is a legacy Action. Legacy Actions have no layers "
2524 "or slots. Since Blender 4.4 actions are automatically updated to "
2525 "layered actions. This will only return true on empty actions");
2526 RNA_def_property_boolean_funcs(prop, "rna_Action_is_action_legacy_get", nullptr);
2527
2528 prop = RNA_def_property(srna, "is_action_layered", PROP_BOOLEAN, PROP_NONE);
2531 prop,
2532 "Is Layered Action",
2533 "Return whether this is a layered Action. At this point all actions "
2534 "are layered through versioning and this function will always return true");
2535 RNA_def_property_boolean_funcs(prop, "rna_Action_is_action_layered_get", nullptr);
2536
2537 /* Collection properties. */
2538 prop = RNA_def_property(srna, "slots", PROP_COLLECTION, PROP_NONE);
2539 RNA_def_property_struct_type(prop, "ActionSlot");
2541 "rna_iterator_animation_slots_begin",
2542 "rna_iterator_array_next",
2543 "rna_iterator_array_end",
2544 "rna_iterator_array_dereference_get",
2545 "rna_iterator_animation_slots_length",
2546 nullptr,
2547 nullptr,
2548 nullptr);
2549 RNA_def_property_ui_text(prop, "Slots", "The list of slots in this Action");
2550 rna_def_action_slots(brna, prop);
2551
2552 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
2553 RNA_def_property_struct_type(prop, "ActionLayer");
2555 "rna_iterator_action_layers_begin",
2556 "rna_iterator_array_next",
2557 "rna_iterator_array_end",
2558 "rna_iterator_array_dereference_get",
2559 "rna_iterator_action_layers_length",
2560 nullptr,
2561 nullptr,
2562 nullptr);
2563 RNA_def_property_ui_text(prop, "Layers", "The list of layers that make up this Action");
2564 rna_def_action_layers(brna, prop);
2565
2566 prop = RNA_def_property(srna, "pose_markers", PROP_COLLECTION, PROP_NONE);
2567 RNA_def_property_collection_sdna(prop, nullptr, "markers", nullptr);
2568 RNA_def_property_struct_type(prop, "TimelineMarker");
2569 /* Use lib exception so the list isn't grayed out;
2570 * adding/removing is still banned though, see #45689. */
2573 prop, "Pose Markers", "Markers specific to this action, for labeling poses");
2574 rna_def_action_pose_markers(brna, prop);
2575
2576 /* properties */
2577 prop = RNA_def_property(srna, "use_frame_range", PROP_BOOLEAN, PROP_NONE);
2579 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ACT_FRAME_RANGE);
2580 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Action_use_frame_range_set");
2582 prop,
2583 "Manual Frame Range",
2584 "Manually specify the intended playback frame range for the action "
2585 "(this range is used by some tools, but does not affect animation evaluation)");
2587
2588 prop = RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
2590 RNA_def_property_boolean_sdna(prop, nullptr, "flag", ACT_CYCLIC);
2592 prop,
2593 "Cyclic Animation",
2594 "The action is intended to be used as a cycle looping over its manually set "
2595 "playback frame range (enabling this does not automatically make it loop)");
2597
2598 prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME);
2600 RNA_def_property_float_sdna(prop, nullptr, "frame_start");
2601 RNA_def_property_float_funcs(prop, nullptr, "rna_Action_start_frame_set", nullptr);
2604 prop, "Start Frame", "The start frame of the manually set intended playback range");
2606
2607 prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_TIME);
2609 RNA_def_property_float_sdna(prop, nullptr, "frame_end");
2610 RNA_def_property_float_funcs(prop, nullptr, "rna_Action_end_frame_set", nullptr);
2613 prop, "End Frame", "The end frame of the manually set intended playback range");
2615
2616 prop = RNA_def_float_vector(
2617 srna,
2618 "frame_range",
2619 2,
2620 nullptr,
2621 0,
2622 0,
2623 "Frame Range",
2624 "The intended playback frame range of this action, using the manually set range "
2625 "if available, or the combined frame range of all F-Curves within this action "
2626 "if not (assigning sets the manual frame range)",
2627 0,
2628 0);
2630 prop, "rna_Action_frame_range_get", "rna_Action_frame_range_set", nullptr);
2632
2633 prop = RNA_def_float_vector(srna,
2634 "curve_frame_range",
2635 2,
2636 nullptr,
2637 0,
2638 0,
2639 "Curve Frame Range",
2640 "The combined frame range of all F-Curves within this action",
2641 0,
2642 0);
2643 RNA_def_property_float_funcs(prop, "rna_Action_curve_frame_range_get", nullptr, nullptr);
2645
2646 func = RNA_def_function(srna, "deselect_keys", "rna_Action_deselect_keys");
2648 func, "Deselects all keys of the Action. The selection status of F-Curves is unchanged.");
2649
2650 /* action.fcurve_ensure_for_datablock() */
2651 func = RNA_def_function(
2652 srna, "fcurve_ensure_for_datablock", "rna_Action_fcurve_ensure_for_datablock");
2654 func,
2655 "Ensure that an F-Curve exists, with the given data path and array index, for the given "
2656 "data-block. This action must already be assigned to the data-block. This function will "
2657 "also create the layer, keyframe strip, and action slot if necessary, and take care of "
2658 "assigning the action slot too");
2660
2661 parm = RNA_def_pointer(func,
2662 "datablock",
2663 "ID",
2664 "",
2665 "The data-block animated by this action, for which to ensure the F-Curve "
2666 "exists. This action must already be assigned to the data-block");
2668 parm = RNA_def_string(func, "data_path", nullptr, 0, "Data Path", "F-Curve data path");
2670 RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
2671 RNA_def_string(func,
2672 "group_name",
2673 nullptr,
2674 0,
2675 "Group Name",
2676 "Name of the group for this F-Curve, if any. If the F-Curve already exists, this "
2677 "parameter is ignored");
2678 parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "The found or created F-Curve");
2680 RNA_def_function_return(func, parm);
2681
2682 /* API calls */
2683 RNA_api_action(srna);
2684}
2685
2686/* --------- */
2687
2689{
2690 rna_def_action(brna);
2692 rna_def_dopesheet(brna);
2693
2694 rna_def_action_slot(brna);
2698}
2699
2700} // namespace blender
2701
2702#endif
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
Functions to work with AnimData.
Functions to modify FCurves.
Functions to insert, delete or modify keyframes.
Blender kernel action and pose functionality.
Blender util stuff.
#define SELECT
Definition BKE_mask.hh:19
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_ID_ID
#define MAXFRAMEF
#define MINAFRAMEF
#define C
Definition RandGen.cpp:29
#define NC_ANIMATION
Definition WM_types.hh:401
#define NA_EDITED
Definition WM_types.hh:634
#define NA_RENAME
Definition WM_types.hh:638
#define ND_KEYFRAME
Definition WM_types.hh:537
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define NA_SELECTED
Definition WM_types.hh:639
#define CLAMP_MAX(a, c)
#define BLI_assert_msg(a, msg)
#define CLAMP_MIN(a, b)
btScalar max
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t first_index_try(const T &search_value) const
Definition BLI_span.hh:391
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
bActionGroup & channel_group_create(StringRefNull name)
const FCurve * fcurve_find(const FCurveDescriptor &fcurve_descriptor) const
Span< const Strip * > strips() const
static constexpr int identifier_length_min
static constexpr slot_handle_t unassigned
Span< const Channelbag * > channelbags() const
#define FLT_MAX
#define INT_MAX
#define layer
#define T
KeyframeSettings get_keyframe_settings(bool from_userprefs)
void action_deselect_keys(Action &action)
Slot & duplicate_slot(Action &action, const Slot &slot)
Action * get_action(ID &animated_id)
FCurve & action_fcurve_ensure(Main *bmain, bAction &action, ID &animated_id, const FCurveDescriptor &fcurve_descriptor)
struct bMotionPath * copy(const struct bMotionPath *mpath_src)
std::string time(const std::tm &date_time, TimeFormat format=TimeFormat::H24)
BLI_INLINE Texture * wrap(MTLTexture *texture)
int icon_from_idcode(int idcode)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void WM_global_reportf(eReportType type, const char *format,...)
@ AGRP_CURVES_ALWAYS_VISIBLE
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
__int64 int64_t
Definition BKE_text.h:90
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
bool rna_Action_id_poll(PointerRNA *ptr, PointerRNA value)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
@ RPT_ERROR_INVALID_INPUT
Definition BKE_report.hh:42
@ RPT_WARNING
Definition BKE_report.hh:40
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
static void rna_def_dopesheet(BlenderRNA *brna)
@ ADS_FLAG_SHOW_DBFILTERS
@ ADS_FLAG_SUMMARY_COLLAPSED
static void rna_def_channelbag_groups(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
PointerRNA RNA_id_pointer_create(ID *id)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
static void rna_def_keyframestrip_channelbags(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
std::optional< AncestorPointerRNA > RNA_struct_search_closest_ancestor_by_type(const PointerRNA *ptr, const StructRNA *srna)
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_USE_MAIN
@ FUNC_USE_CONTEXT
void RNA_define_lib_overridable(const bool make_overridable)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
static void rna_def_action_strip(BlenderRNA *brna)
static void rna_def_action_channelbag(BlenderRNA *brna)
@ ADS_FILTER_ONLY_SLOTS_OF_ACTIVE
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
MINLINE int max_ii(int a, int b)
static void rna_def_ActionLayer_strips(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
static void rna_def_action_pose_markers(BlenderRNA *brna, PropertyRNA *cprop)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
const EnumPropertyItem rna_enum_strip_type_items[]
Definition rna_action.cc:66
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
static void rna_def_action_slots(BlenderRNA *brna, PropertyRNA *cprop)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
static void rna_def_action_layer(BlenderRNA *brna)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
VecBase< float, 2 > float2
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)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_DATA_VISIBLE
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
static void rna_def_action_keyframe_strip(BlenderRNA *brna)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
const EnumPropertyItem default_ActionSlot_target_id_type_items[]
Definition rna_action.cc:77
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
FCurve * BKE_fcurve_copy(const FCurve *fcu)
static void rna_def_channelbag_fcurves(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_def_action(BlenderRNA *brna)
void WM_global_report(eReportType type, const char *message)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
void BKE_free_time_marker(TimeMarker &marker, bool do_id_user)
Definition anim_sys.cc:3974
void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
@ ADS_FILTER_NOCACHEFILES
@ ADS_FILTER_NOLIGHTPROBE
@ ADS_FILTER_NOMOVIECLIPS
@ ADS_FILTER_NOPOINTCLOUD
@ ADS_FILTER_DRIVER_FALLBACK_AS_ERROR
static void rna_def_action_layers(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_api_action(StructRNA *srna)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void rna_def_actionbone_group_common(StructRNA *srna, int update_flag, const char *update_cb)
Definition rna_pose.cc:735
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_ANIMATION_NO_FLUSH
Definition DNA_ID.h:1178
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_TEXTEDIT_UPDATE
Definition RNA_types.hh:396
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:477
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_NO_CONTEXT
Definition RNA_types.hh:500
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:509
@ PROP_LIB_EXCEPTION
Definition RNA_types.hh:382
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_update_notifier(PropertyRNA *prop, const int noteflag)
std::optional< std::string > rna_Channelbag_path(const PointerRNA *ptr)
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:161
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
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)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
static void rna_def_action_group(BlenderRNA *brna)
static void rna_def_action(BlenderRNA *brna)
void BKE_blender_atexit_register(void(*func)(void *user_data), void *user_data)
Definition blender.cc:484
static void rna_def_action_slot(BlenderRNA *brna)
#define min(a, b)
Definition sort.cc:38
Vector< PointerRNA > items
Definition RNA_types.hh:705