Blender V5.3
anim_data.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors, Joshua Leung. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#include "MEM_guardedalloc.h"
9
10#include <cstring>
11#include <optional>
12
13#include "BKE_action.hh"
14#include "BKE_anim_data.hh"
15#include "BKE_animsys.hh"
16#include "BKE_context.hh"
17#include "BKE_fcurve.hh"
18#include "BKE_fcurve_driver.h"
19#include "BKE_global.hh"
20#include "BKE_idtype.hh"
21#include "BKE_lib_id.hh"
22#include "BKE_lib_query.hh"
23#include "BKE_main.hh"
24#include "BKE_nla.hh"
25#include "BKE_node.hh"
26#include "BKE_report.hh"
27
28#include "DNA_ID.h"
29#include "DNA_action_types.h"
30#include "DNA_anim_types.h"
31#include "DNA_light_types.h"
32#include "DNA_material_types.h"
33#include "DNA_node_types.h"
35#include "DNA_world_types.h"
36
37#include "BLI_alloca.hh"
38#include "BLI_dynstr.hh"
39#include "BLI_listbase.hh"
40#include "BLI_string.hh"
41#include "BLI_string_utf8.hh"
42#include "BLI_utildefines.hh"
43
44#include "DEG_depsgraph.hh"
46
47#include "BLO_read_write.hh"
48#include "BLO_readfile.hh"
49
50#include "RNA_access.hh"
51#include "RNA_path.hh"
52#include "RNA_prototypes.hh"
53
55#include "ANIM_action_legacy.hh"
56#include "ANIM_versioning.hh"
57
58#include "CLG_log.h"
59
60namespace blender {
61
62static CLG_LogRef LOG = {"anim.data"};
63
64/* ***************************************** */
65/* AnimData API */
66
67/* Getter/Setter -------------------------------------------- */
68
69bool id_type_can_have_animdata(const short id_type)
70{
71 const IDTypeInfo *typeinfo = BKE_idtype_get_info_from_idcode(id_type);
72 if (typeinfo != nullptr) {
73 return (typeinfo->flags & IDTYPE_FLAGS_NO_ANIMDATA) == 0;
74 }
75 return false;
76}
77
78bool id_can_have_animdata(const ID *id)
79{
80 /* sanity check */
81 if (id == nullptr) {
82 return false;
83 }
84 /* Placeholders IDs used during readfile process are just an ID struct, so they never have
85 * animdata either. */
87 return false;
88 }
89
90 return id_type_can_have_animdata(id->id_type());
91}
92
94{
95 /* In order for this to work, we assume that the #AnimData pointer is stored
96 * immediately after the given ID-block in the struct, as per IdAdtTemplate. */
97
98 /* Only some ID-blocks have this info for now, so we cast the types that do
99 * to be of type IdAdtTemplate, and add the AnimData to it using the template. */
100 if (id_can_have_animdata(id)) {
101 const IdAdtTemplate *iat = reinterpret_cast<const IdAdtTemplate *>(id);
102 return iat->adt;
103 }
104 return nullptr;
105}
106
108{
109 /* In order for this to work, we assume that the #AnimData pointer is stored
110 * immediately after the given ID-block in the struct, as per IdAdtTemplate. */
111
112 /* Only some ID-blocks have this info for now, so we cast the types that do
113 * to be of type IdAdtTemplate, and add the AnimData to it using the template. */
114 if (id_can_have_animdata(id)) {
115 IdAdtTemplate *iat = reinterpret_cast<IdAdtTemplate *>(id);
116
117 /* check if there's already AnimData, in which case, don't add */
118 if (iat->adt == nullptr) {
119 AnimData *adt;
120
121 /* add animdata */
122 adt = iat->adt = MEM_new<AnimData>("AnimData");
123
124 /* set default settings */
125 adt->act_influence = 1.0f;
126 }
127
128 return iat->adt;
129 }
130 return nullptr;
131}
132
133/* Action Setter --------------------------------------- */
134
136{
137 /* If we're unassigning (null action pointer) and there's no animdata, we can
138 * skip the whole song and dance of creating animdata just to "unassign" the
139 * action from it. */
140 if (act == nullptr && BKE_animdata_from_id(id) == nullptr) {
141 return true;
142 }
143
145 if (adt == nullptr) {
146 BKE_report(reports, RPT_WARNING, "Attempt to set action on non-animatable ID");
147 return false;
148 }
149
151 /* Cannot remove, otherwise things turn to custard. */
152 BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA");
153 return false;
154 }
155
156 const bool success = animrig::assign_action(act, {*id, *adt});
157 if (success) {
159 }
160
161 return success;
162}
163
165{
166 /* Active action is only editable when it is not a tweaking strip. */
167 const bool is_tweaking_strip = (adt->flag & ADT_NLA_EDIT_ON) || adt->actstrip != nullptr ||
168 adt->tmpact != nullptr;
169 return !is_tweaking_strip;
170}
171
172/* Freeing -------------------------------------------- */
173
174void BKE_animdata_free(ID *id, const bool do_id_user)
175{
176 if (!id_can_have_animdata(id)) {
177 return;
178 }
179
180 IdAdtTemplate *iat = reinterpret_cast<IdAdtTemplate *>(id);
181 AnimData *adt = iat->adt;
182 if (!adt) {
183 return;
184 }
185
186 if (do_id_user) {
187 /* The ADT is going to be freed, which means that if it's in tweak mode, it'll have to exit
188 * that first. Otherwise we cannot un-assign its Action. */
189 BKE_nla_tweakmode_exit({*id, *adt});
190
191 if (adt->action) {
192 const bool unassign_ok = animrig::unassign_action(*id);
193 BLI_assert_msg(unassign_ok,
194 "Expecting action un-assignment to always work when not in NLA tweak mode");
195 UNUSED_VARS_NDEBUG(unassign_ok);
196 }
197 /* same goes for the temporarily displaced action */
198 if (adt->tmpact) {
199 /* This should never happen, as we _just_ exited tweak mode. */
201 const bool unassign_ok = animrig::assign_tmpaction(nullptr, {*id, *adt});
202 BLI_assert_msg(unassign_ok, "Expecting tmpaction un-assignment to always work");
203 UNUSED_VARS_NDEBUG(unassign_ok);
204 }
205 }
206
207 /* free nla data */
208 BKE_nla_tracks_free(&adt->nla_tracks, do_id_user);
209
210 /* free drivers - stored as a list of F-Curves */
212
213 /* free driver array cache */
214 MEM_SAFE_DELETE(adt->driver_array);
215
216 /* free overrides */
217 /* TODO... */
218
219 /* free animdata now */
220 MEM_delete(adt);
221 iat->adt = nullptr;
222}
223
225{
226 if (id == nullptr) {
227 return false;
228 }
229
230 const AnimData *adt = BKE_animdata_from_id(const_cast<ID *>(id));
231 if (adt == nullptr) {
232 return false;
233 }
234
235 if (adt->action) {
236 const animrig::Action &action = adt->action->wrap();
237 if (action.is_slot_animated(adt->slot_handle)) {
238 return true;
239 }
240 }
241
242 return !adt->drivers.is_empty() || !adt->nla_tracks.is_empty() || !adt->overrides.is_empty();
243}
244
246{
247 for (FCurve &fcu : adt->drivers) {
249 }
250
253
254 for (NlaTrack &nla_track : adt->nla_tracks) {
255 for (NlaStrip &nla_strip : nla_track.strips) {
256 BKE_nla_strip_foreach_id(&nla_strip, data);
257 }
258 }
259}
260
261/* Copying -------------------------------------------- */
262
264 std::optional<Library *> owner_library,
265 AnimData *adt,
266 const int flag)
267{
268 AnimData *dadt;
269
270 const bool do_action = (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0;
271 const bool do_id_user = (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0;
272
273 /* sanity check before duplicating struct */
274 if (adt == nullptr) {
275 return nullptr;
276 }
277 dadt = MEM_dupalloc(adt);
278
279 /* make a copy of action - at worst, user has to delete copies... */
280 if (do_action) {
281 /* Recursive copy of 'real' IDs is a bit hairy. Even if do not want to deal with user-count
282 * when copying ID's data itself, we still need to do so with sub-IDs, since those will not be
283 * handled by later 'update user-counts of used IDs' code as used e.g. at end of
284 * #BKE_id_copy_ex().
285 * So in case we do copy the ID and its sub-IDs in bmain, silence the 'no user-count' flag for
286 * the sub-IDs copying.
287 * NOTE: This is a bit weak, as usually when it comes to recursive ID copy. Should work for
288 * now, but we may have to revisit this at some point and add a proper extra flag to deal with
289 * that situation. Or refactor completely the way we handle such recursion, by flattening it
290 * e.g. */
291 const int id_copy_flag = (flag & LIB_ID_CREATE_NO_MAIN) == 0 ?
293 flag;
294 BLI_assert(bmain != nullptr);
295 BLI_assert(dadt->action == nullptr || dadt->action != dadt->tmpact);
296 dadt->action = reinterpret_cast<bAction *>(
297 BKE_id_copy_in_lib(bmain,
298 owner_library,
299 reinterpret_cast<ID *>(dadt->action),
300 std::nullopt,
301 nullptr,
302 id_copy_flag));
303 dadt->tmpact = reinterpret_cast<bAction *>(
304 BKE_id_copy_in_lib(bmain,
305 owner_library,
306 reinterpret_cast<ID *>(dadt->tmpact),
307 std::nullopt,
308 nullptr,
309 id_copy_flag));
310 }
311 else if (do_id_user) {
312 id_us_plus(id_cast<ID *>(dadt->action));
313 id_us_plus(id_cast<ID *>(dadt->tmpact));
314 }
315
316 /* duplicate NLA data */
317 BKE_nla_tracks_copy_from_adt(bmain, dadt, adt, flag);
318
319 /* duplicate drivers (F-Curves) */
320 BKE_fcurves_copy(&dadt->drivers, &adt->drivers);
321 dadt->driver_array = nullptr;
322
323 /* don't copy overrides */
324 dadt->overrides.clear_no_delete();
325
326 const bool is_main = (flag & LIB_ID_CREATE_NO_MAIN) == 0;
327 if (is_main) {
328 /* Action references were changed, so the Slot-to-user map is incomplete now. Only necessary
329 * when this happens in the main database though, as the user cache only tracks original IDs,
330 * not evaluated copies.
331 *
332 * This function does not have access to the animated ID, so it cannot just add that ID to the
333 * slot's users, hence the invalidation of the users map.
334 *
335 * TODO: refactor to pass the owner ID to this function, and just add it to the Slot's
336 * users. */
337 if (bmain) {
339 }
340 }
341
342 /* return */
343 return dadt;
344}
345
346AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag)
347{
348 return BKE_animdata_copy_in_lib(bmain, std::nullopt, adt, flag);
349}
350
351bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag)
352{
353 AnimData *adt;
354
355 if ((id_to && id_from) && (id_to->id_type() != id_from->id_type())) {
356 return false;
357 }
358
360
361 adt = BKE_animdata_from_id(id_from);
362 if (adt) {
363 IdAdtTemplate *iat = reinterpret_cast<IdAdtTemplate *>(id_to);
364 iat->adt = BKE_animdata_copy(bmain, adt, flag);
365 }
366
367 return true;
368}
369
370static void animdata_copy_id_action(Main *bmain,
371 ID *id,
372 const bool set_newid,
373 const bool do_linked_id)
374{
375 using namespace blender::animrig;
376
378 if (adt) {
379 if (adt->action && (do_linked_id || !ID_IS_LINKED(adt->action))) {
380 bAction *cloned_action = reinterpret_cast<bAction *>(BKE_id_copy(bmain, &adt->action->id));
381
382 cloned_action->id.us = 0;
383 if (set_newid) {
384 ID_NEW_SET(adt->action, cloned_action);
385 }
386
387 /* The Action was cloned, so this should find the same-named slot automatically. */
388 const slot_handle_t orig_slot_handle = adt->slot_handle;
389 const bool assign_ok = assign_action(&cloned_action->wrap(), *id);
390 BLI_assert_msg(assign_ok, "Expected action assignment to work when copying animdata");
391 BLI_assert(orig_slot_handle == adt->slot_handle);
392 UNUSED_VARS_NDEBUG(assign_ok, orig_slot_handle);
393 }
394 else if (!adt->action) {
395 /* When the duplicated ID does not have an Action assigned, it's better to reset its
396 * last-used slot identifier as well. See #143117. */
397 adt->last_slot_identifier[0] = '\0';
398 }
399 if (adt->tmpact && (do_linked_id || !ID_IS_LINKED(adt->tmpact))) {
400 bAction *cloned_action = reinterpret_cast<bAction *>(BKE_id_copy(bmain, &adt->tmpact->id));
401
402 cloned_action->id.us = 0;
403 if (set_newid) {
404 ID_NEW_SET(adt->tmpact, cloned_action);
405 }
406
407 /* The Action was cloned, so this should find the same-named slot automatically. */
408 const slot_handle_t orig_slot_handle = adt->tmp_slot_handle;
409 const bool assign_ok = assign_tmpaction(&cloned_action->wrap(), {*id, *adt});
410 BLI_assert_msg(assign_ok, "Expected tmp-action assignment to work when copying animdata");
411 BLI_assert(orig_slot_handle == adt->tmp_slot_handle);
412 UNUSED_VARS_NDEBUG(assign_ok, orig_slot_handle);
413 }
414 else if (!adt->tmpact) {
415 /* When the duplicated ID does not have an Action assigned, it's better to reset its
416 * last-used slot identifier as well. See #143117. */
417 adt->tmp_last_slot_identifier[0] = '\0';
418 }
419 }
421 if (ntree) {
422 animdata_copy_id_action(bmain, &ntree->id, set_newid, do_linked_id);
423 }
424 /* Note that collections are not animatable currently, so no need to handle scenes' master
425 * collection here. */
426}
427
429{
430 const bool is_id_liboverride = ID_IS_OVERRIDE_LIBRARY(id);
431 animdata_copy_id_action(bmain, id, false, !is_id_liboverride);
432}
433
435 ID *id,
436 const /*eDupli_ID_Flags*/ uint duplicate_flags)
437{
438 if (duplicate_flags & USER_DUP_ACT) {
439 animdata_copy_id_action(bmain, id, true, (duplicate_flags & USER_DUP_LINKED_ID) != 0);
440 }
441}
442
444 Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers)
445{
446 AnimData *src = BKE_animdata_from_id(src_id);
447 AnimData *dst = BKE_animdata_from_id(dst_id);
448
449 /* sanity checks */
450 if (ELEM(nullptr, dst, src)) {
451 return;
452 }
453
454 /* TODO: we must unset all "tweak-mode" flags. */
455 if ((src->flag & ADT_NLA_EDIT_ON) || (dst->flag & ADT_NLA_EDIT_ON)) {
457 &LOG,
458 "Merging AnimData blocks while editing NLA is dangerous as it may cause data corruption");
459 return;
460 }
461
462 /* handle actions... */
463 if (action_mode == ADT_MERGECOPY_SRC_COPY) {
464 /* make a copy of the actions */
465 dst->action = id_cast<bAction *>(BKE_id_copy(bmain, &src->action->id));
466 dst->tmpact = id_cast<bAction *>(BKE_id_copy(bmain, &src->tmpact->id));
467 }
468 else if (action_mode == ADT_MERGECOPY_SRC_REF) {
469 /* make a reference to it */
470 dst->action = src->action;
471 id_us_plus(id_cast<ID *>(dst->action));
472
473 dst->tmpact = src->tmpact;
474 id_us_plus(id_cast<ID *>(dst->tmpact));
475 }
476 dst->slot_handle = src->slot_handle;
480
481 /* duplicate NLA data */
482 if (src->nla_tracks.first()) {
483 ListBaseT<NlaTrack> tracks = {nullptr, nullptr};
484
485 BKE_nla_tracks_copy(bmain, &tracks, &src->nla_tracks, 0);
486 BLI_movelisttolist(&dst->nla_tracks, &tracks);
487 }
488
489 /* duplicate drivers (F-Curves) */
490 if (src->drivers.first()) {
491 ListBaseT<FCurve> drivers = {nullptr, nullptr};
492
493 BKE_fcurves_copy(&drivers, &src->drivers);
494
495 /* Fix up all driver targets using the old target id
496 * - This assumes that the src ID is being merged into the dst ID
497 */
498 if (fix_drivers) {
499 for (FCurve &fcu : drivers) {
500 ChannelDriver *driver = fcu.driver;
501 for (DriverVar &dvar : driver->variables) {
503 if (dtar->id == src_id) {
504 dtar->id = dst_id;
505 }
506 }
508 }
509 }
510 }
511
512 BLI_movelisttolist(&dst->drivers, &drivers);
513 }
514}
515
516/* Sub-ID Regrouping ------------------------------------------- */
517
525static bool animpath_matches_basepath(const StringRef path, const StringRef basepath)
526{
527 return path.startswith(basepath);
528}
529
531 const StringRef old_basepath,
532 const StringRef new_basepath)
533{
534 BLI_assert(animpath_matches_basepath(fcu->rna_path(), old_basepath));
535 if (old_basepath == new_basepath) {
536 return;
537 }
538
539 std::string new_rna_path = new_basepath +
540 StringRefNull(fcu->rna_path().c_str() + old_basepath.size());
541 fcu->rna_path_set(new_rna_path);
542}
543
544/* Copy or move F-Curves in src action to dst action if their base path matches. */
546 const animrig::slot_handle_t src_slot_handle,
547 animrig::Action &dst_action,
548 const animrig::slot_handle_t dst_slot_handle,
549 const StringRef src_basepath,
550 const StringRef dst_basepath)
551{
552 if (&src_action == &dst_action && src_slot_handle == dst_slot_handle &&
553 src_basepath == dst_basepath)
554 {
555 return false;
556 }
557
558 bool result = false;
559 /* Store list of all F-Curves to copy so we don't copy the curves while iterating over them. The
560 * fcurve array of slot grows with each copy, invalidating the iterator. */
561 Vector<const FCurve *> fcurves_to_copy;
562 /* const_cast the src_action here because there is only a non-const fcurve iterator method.
563 * We only use the fcurve as a const ref, there's no risk of modifying the data. */
565 const_cast<animrig::Action &>(src_action), src_slot_handle, [&](const FCurve &fcurve) {
566 if (animpath_matches_basepath(fcurve.rna_path(), src_basepath)) {
567 fcurves_to_copy.append(&fcurve);
568 result = true;
569 }
570 });
571 for (const FCurve *fcurve : fcurves_to_copy) {
572 std::optional<StringRefNull> group_name;
573 if (fcurve->grp) {
574 group_name = fcurve->grp->name;
575 }
576 FCurve *new_fcurve = BKE_fcurve_copy(fcurve);
577 animpath_update_basepath(new_fcurve, src_basepath, dst_basepath);
578 action_fcurve_attach(dst_action, dst_slot_handle, *new_fcurve, group_name);
579 }
580 return result;
581}
582
584 AnimData &dst_adt,
585 const StringRef src_basepath,
586 const StringRef dst_basepath)
587{
588 bool result = false;
589 for (const FCurve &fcurve : src_adt.drivers) {
590 if (animpath_matches_basepath(fcurve.rna_path(), src_basepath)) {
591 FCurve *fcurve_copy = BKE_fcurve_copy(&fcurve);
592 animpath_update_basepath(fcurve_copy, src_basepath, dst_basepath);
593 BLI_addtail(&dst_adt.drivers, fcurve_copy);
594
595 result = true;
596 }
597 }
598 return result;
599}
600
601/* Make sure the destination ID has animdata and a valid action.
602 * Note: Returned source animdata pointer is mutable, but should only be modified if the source ID
603 * is mutable too. */
604static std::pair<AnimData *, AnimData *> ensure_animdata_pair(Main &bmain,
605 const ID &src_id,
606 ID &dst_id)
607{
608 AnimData *src_adt = BKE_animdata_from_id(&src_id);
609 if (src_adt == nullptr) {
610 /* Nothing to do. */
611 return {nullptr, nullptr};
612 }
613
614 /* Create destination animdata if needed. */
615 AnimData *dst_adt = BKE_animdata_ensure_id(&dst_id);
616 if (dst_adt == nullptr) {
617 if (G.debug & G_DEBUG) {
618 CLOG_ERROR(&LOG, "Failed to create AnimData for '%s'", dst_id.name);
619 }
620 return {nullptr, nullptr};
621 }
622 const OwnedAnimData dst_owned_adt = {dst_id, *dst_adt};
623
624 /* Create an empty action for the destination if necessary. */
625 if (src_adt->action && !dst_adt->action) {
626 animrig::Action &new_action = animrig::action_add(bmain, src_adt->action->id.name + 2);
627 new_action.slot_add_for_id(dst_id);
628
629 const bool assign_ok = animrig::assign_action(&new_action, dst_owned_adt);
630 BLI_assert_msg(assign_ok, "Expected Action assignment to work");
631 UNUSED_VARS_NDEBUG(assign_ok);
633
635 }
636
637 return {src_adt, dst_adt};
638}
639
641 const ID &src_id,
642 ID &dst_id,
644{
645 if (basepaths.is_empty()) {
646 return;
647 }
648
649 auto [src_adt, dst_adt] = ensure_animdata_pair(bmain, src_id, dst_id);
650 if (!src_adt) {
651 return;
652 }
653
654 /* Copy data from the source action. */
655 if (src_adt->action) {
656 BLI_assert(dst_adt->action);
657
658 /* Copy F-curves for each base path. */
659 for (const AnimationBasePathChange &basepath_change : basepaths) {
660 if (action_copy_fcurves_by_basepath(src_adt->action->wrap(),
661 src_adt->slot_handle,
662 dst_adt->action->wrap(),
663 dst_adt->slot_handle,
664 basepath_change.src_basepath,
665 basepath_change.dst_basepath))
666 {
668 DEG_id_tag_update(&dst_adt->action->id, ID_RECALC_SYNC_TO_EVAL);
669 }
670 }
671 }
672
673 /* Copy drivers in the animation data. */
674 if (src_adt->drivers.first()) {
675 for (const AnimationBasePathChange &basepath_change : basepaths) {
677 *src_adt, *dst_adt, basepath_change.src_basepath, basepath_change.dst_basepath))
678 {
681 }
682 }
683 }
684}
685
686/* Path Validation -------------------------------------------- */
687
688/* Check if a given RNA Path is valid, by tracing it from the given ID,
689 * and seeing if we can resolve it. */
690static bool check_rna_path_is_valid(ID &owner_id, const StringRefNull path)
691{
692 PointerRNA ptr;
693 PropertyRNA *prop = nullptr;
694
695 /* make initial RNA pointer to start resolving from */
696 PointerRNA id_ptr = RNA_id_pointer_create(&owner_id);
697
698 /* try to resolve */
699 return RNA_path_resolve_property(&id_ptr, path.data(), &ptr, &prop);
700}
701
708static std::optional<std::string> rna_path_rename_fix(ID &owner_id,
709 const StringRef prefix,
710 const StringRef old_infix,
711 const StringRef new_infix,
712 const StringRefNull old_path,
713 const bool verify_paths)
714{
715 const int64_t prefix_offset = old_path.find(prefix);
716 if (prefix_offset == StringRefBase::not_found) {
717 return std::nullopt;
718 }
719
720 const int64_t old_infix_offset = old_path.find(old_infix);
721 if (old_infix_offset == StringRefBase::not_found) {
722 return std::nullopt;
723 }
724
725 /* Only modify paths if the prefix and old_name feature in the path,
726 * and prefix occurs immediately before old_name. */
727 if (prefix_offset + prefix.size() != old_infix_offset) {
728 return std::nullopt;
729 }
730
731 /* Only modify a path that is invalid. */
732 if (verify_paths && check_rna_path_is_valid(owner_id, old_path)) {
733 return std::nullopt;
734 }
735
736 std::string modified_path;
737 const int64_t postfix_offset = old_infix_offset + old_infix.size();
738
739 /* Add the part of the string that goes up to the start of the prefix. */
740 if (prefix_offset > 0) {
741 modified_path.append(old_path.substr(0, prefix_offset));
742 }
743
744 modified_path.append(prefix);
745 modified_path.append(new_infix);
746 modified_path.append(old_path.substr(postfix_offset));
747
748 /* If the new path is not valid, the renaming failed. */
749 if (verify_paths && !check_rna_path_is_valid(owner_id, modified_path)) {
750 return std::nullopt;
751 }
752
753 return modified_path;
754}
755
759static std::string infix_to_name(const StringRef infix)
760{
761 /* An empty name infix would be `[""]` so four characters. */
762 BLI_assert(infix.size() >= 4);
763 std::string unescaped;
764 unescaped.resize(infix.size() - 4);
765 size_t string_size = BLI_str_unescape(unescaped.data(), infix.data() + 2, unescaped.size());
766 unescaped.resize(string_size);
767 return unescaped;
768}
769
770/* Check RNA-Paths for a list of F-Curves */
771static bool fcurves_path_rename_fix(ID &owner_id,
772 const StringRef prefix,
773 const StringRef old_infix,
774 const StringRef new_infix,
776 const bool verify_paths)
777{
778 bool is_changed = false;
779 /* We need to check every curve. */
780 for (FCurve *fcu : curves) {
781 if (fcu->rna_path().is_empty()) {
782 continue;
783 }
784 /* Firstly, handle the F-Curve's own path. */
785 std::optional<std::string> new_path = rna_path_rename_fix(
786 owner_id, prefix, old_infix, new_infix, fcu->rna_path(), verify_paths);
787 if (!new_path.has_value()) {
788 continue;
789 }
790 fcu->rna_path_set(*new_path);
791 is_changed = true;
792
793 /* If the path changed and the FCurve is grouped, check if its group also needs renaming
794 * (i.e. F-Curve is first of a bone's F-Curves;
795 * hence renaming this should also trigger rename) */
796 PointerRNA ptr = RNA_id_pointer_create(&owner_id);
797 PointerRNA resolved_ptr;
798 PropertyRNA *resolved_prop;
799 if (!RNA_path_resolve(&ptr, fcu->rna_path().c_str(), &resolved_ptr, &resolved_prop)) {
800 /* This can happen in versioning code. */
801 continue;
802 }
803 /* If the path changed, make sure to update the fcurve flags to the new property type. See
804 * #157234. We assume that the property type didn't change if the path is the same. */
806 /* If the path changed and the F-Curve is grouped, check if its group also needs renaming
807 * For pose bones, the group is named after it, hence it also needs a name update. */
808 bActionGroup *agrp = fcu->grp;
809 if (agrp && resolved_ptr.type == RNA_PoseBone) {
810 /* Only update the name if the action group name was contained in the old infix. Since groups
811 * can be renamed by the user we shouldn't override that data. */
812 bPoseChannel *pchan = static_cast<bPoseChannel *>(resolved_ptr.data);
813 std::string old_name = infix_to_name(old_infix);
814 if (old_name == StringRefNull(agrp->name)) {
815 STRNCPY_UTF8(agrp->name, pchan->name);
816 }
817 }
818 }
819 return is_changed;
820}
821
822static bool rename_paths_action(bAction *dna_action,
823 const animrig::slot_handle_t slot_handle,
824 ID &owner_id,
825 const StringRef prefix,
826 const StringRef old_infix,
827 const StringRef new_infix,
828 const bool verify_paths)
829{
830 animrig::Action &action = dna_action->wrap();
831 bool is_changed_action;
832 /* Since this code path is used for versioning of actions before they are converted to layered,
833 * we have to keep support for legacy actions here. */
835 const Span<FCurve *> fcurves = animrig::fcurves_for_action_slot(action, slot_handle);
836 is_changed_action = fcurves_path_rename_fix(
837 owner_id, prefix, old_infix, new_infix, fcurves, verify_paths);
838 }
839 else {
841 is_changed_action = fcurves_path_rename_fix(
842 owner_id, prefix, old_infix, new_infix, fcurves, verify_paths);
843 }
844 if (is_changed_action) {
846 }
847 return is_changed_action;
848}
849
850/* Fix all RNA-Paths for Actions linked to NLA Strips */
851static bool nlastrips_path_rename_fix(ID &owner_id,
852 const StringRef prefix,
853 const StringRef old_infix,
854 const StringRef new_infix,
855 ListBaseT<NlaStrip> &strips,
856 const bool verify_paths)
857{
858 bool is_changed = false;
859 /* Recursively check strips, fixing only actions. */
860 for (NlaStrip &strip : strips) {
861 /* fix strip's action */
862 if (strip.act != nullptr) {
863 const bool is_changed_action = rename_paths_action(strip.act,
864 strip.action_slot_handle,
865 owner_id,
866 prefix,
867 old_infix,
868 new_infix,
869 verify_paths);
870 is_changed |= is_changed_action;
871 }
872 /* Ignore own F-Curves, since those are local. */
873 /* Check sub-strips (if meta-strips). */
874 is_changed |= nlastrips_path_rename_fix(
875 owner_id, prefix, old_infix, new_infix, strip.strips, verify_paths);
876 }
877 return is_changed;
878}
879
880/* Rename Sub-ID Entities in RNA Paths ----------------------- */
881
883 const char *old_path,
884 const StringRef prefix,
885 const StringRefNull old_name,
886 const StringRefNull new_name)
887{
888 /* if no action, no need to proceed */
889 if (ELEM(nullptr, owner_id, old_path)) {
890 if (G.debug & G_DEBUG) {
891 CLOG_WARN(&LOG, "early abort");
892 }
893 return nullptr;
894 }
895
896 auto &&[old_key, new_key] = RNA_generate_keys_for_path_rename(old_name, new_name, 0, 0, true);
897
898 /* fix given path */
899 if (G.debug & G_DEBUG) {
900 printf("%s | %s | oldpath = %p ", old_key.c_str(), new_key.c_str(), old_path);
901 }
902 std::optional<std::string> new_path = rna_path_rename_fix(
903 *owner_id, prefix, old_key, new_key, old_path, false);
904 if (!new_path.has_value()) {
905 return nullptr;
906 }
907 return BLI_strdup(new_path->c_str());
908}
909
911 bAction *act,
912 animrig::slot_handle_t slot_handle,
913 const StringRef prefix,
914 const StringRefNull old_name,
915 const StringRefNull new_name,
916 const bool verify_paths)
917{
918 /* if no action, no need to proceed */
919 if (ELEM(nullptr, owner_id, act)) {
920 return;
921 }
922
923 auto &&[old_key, new_key] = RNA_generate_keys_for_path_rename(old_name, new_name, 0, 0, true);
924
925 /* fix paths in action */
926 fcurves_path_rename_fix(*owner_id,
927 prefix,
928 old_key,
929 new_key,
930 animrig::fcurves_for_action_slot(act->wrap(), slot_handle),
931 verify_paths);
932
934}
935
936/* Fix all targets that point to the given ID. */
937static bool driver_target_path_fix(ID &owner_id,
938 const StringRef prefix,
939 const StringRef old_infix,
940 const StringRef new_infix,
941 const DriverMap &driver_map)
942{
943 const Vector<DriverTarget *> *target_uses = driver_map.lookup_ptr(&owner_id);
944 if (!target_uses) {
945 return false;
946 }
947
948 bool is_changed = false;
949 for (DriverTarget *target : *target_uses) {
950 BLI_assert_msg(target->id == &owner_id,
951 "Driver Map for this ID contains targets for another ID.");
952 if (target->rna_path) {
953 /* This cannot verify paths because driver paths are not always valid rna paths. They can end
954 * in e.g. ".location[0]" while "location" + array index integer would be correct. */
955 std::optional<std::string> fixed_path = rna_path_rename_fix(
956 owner_id, prefix, old_infix, new_infix, target->rna_path, /*verify_paths=*/false);
957 if (fixed_path.has_value()) {
958 MEM_delete(target->rna_path);
959 target->rna_path = BLI_strdup(fixed_path->c_str());
960 is_changed = true;
961 }
962 }
963
964 if (owner_id.id_type() == ID_OB && target->pchan_name[0] && prefix.find("bones")) {
965 /* If the target is a bone we can assume that the infix will be surrounded with square
966 * brackets and escaped. */
967 BLI_assert(old_infix.size() >= 4);
968 const std::string old_bone_name = infix_to_name(old_infix);
969 if (old_bone_name == StringRef(target->pchan_name)) {
970 const std::string new_bone_name = infix_to_name(new_infix);
971 STRNCPY(target->pchan_name, new_bone_name.data());
972 is_changed = true;
973 }
974 }
975 }
976
977 return is_changed;
978}
979
981{
982 DriverMap map;
983 BKE_animdata_main_cb(&bmain, [&](ID * /* id */, AnimData *adt) {
984 for (const FCurve &driver : adt->drivers) {
985 if (!driver.driver) {
986 continue;
987 }
988 for (DriverVar &driver_var : driver.driver->variables) {
989 for (DriverTarget &target : MutableSpan(driver_var.targets, driver_var.num_targets)) {
990 if (!target.id) {
991 continue;
992 }
993 map.lookup_or_add_default(target.id).append(&target);
994 }
995 }
996 }
997 });
998 return map;
999}
1000
1002 const StringRef prefix,
1003 const StringRef old_infix,
1004 const StringRef new_infix,
1005 const bool verify_paths,
1006 const DriverMap &driver_map)
1007{
1008 bool is_changed = false;
1009 /* We always need to fix drivers that target this ID. This is independent of this ID having
1010 * animation data. Also fixes this ID's drivers if they target the ID itself. */
1011 is_changed |= driver_target_path_fix(id, prefix, old_infix, new_infix, driver_map);
1012
1013 AnimData *adt = BKE_animdata_from_id(&id);
1014 if (!adt) {
1015 return;
1016 }
1017
1018 if (adt->action && adt->slot_handle != animrig::Slot::unassigned) {
1019 is_changed |= rename_paths_action(
1020 adt->action, adt->slot_handle, id, prefix, old_infix, new_infix, verify_paths);
1021 }
1022 if (adt->tmpact && adt->tmp_slot_handle != animrig::Slot::unassigned) {
1023 is_changed |= rename_paths_action(
1024 adt->tmpact, adt->tmp_slot_handle, id, prefix, old_infix, new_infix, verify_paths);
1025 }
1026 for (NlaTrack &nlt : adt->nla_tracks) {
1027 is_changed |= nlastrips_path_rename_fix(
1028 id, prefix, old_infix, new_infix, nlt.strips, verify_paths);
1029 }
1030 for (FCurve &fcurve : adt->drivers) {
1031 std::optional<std::string> fixed_path = rna_path_rename_fix(
1032 id, prefix, old_infix, new_infix, fcurve.rna_path(), verify_paths);
1033 if (!fixed_path.has_value()) {
1034 continue;
1035 }
1036 fcurve.rna_path_set(*fixed_path);
1037 is_changed = true;
1038 }
1039 if (is_changed) {
1041 }
1042}
1043
1045 StringRef prefix,
1046 StringRef old_infix,
1047 StringRef new_infix,
1048 bool verify_paths,
1049 Main &bmain)
1050{
1051 const DriverMap driver_map = BKE_animdata_build_driver_target_map(bmain);
1052 BKE_animdata_fix_paths(id, prefix, old_infix, new_infix, verify_paths, driver_map);
1053}
1054
1055/* Remove FCurves with Prefix -------------------------------------- */
1056
1058static bool fcurves_path_remove_from_listbase(const char *prefix, ListBaseT<FCurve> *curves)
1059{
1060 FCurve *fcu, *fcn;
1061 bool any_removed = false;
1062 if (!prefix) {
1063 return any_removed;
1064 }
1065
1066 /* we need to check every curve... */
1067 for (fcu = curves->first(); fcu; fcu = fcn) {
1068 fcn = fcu->next;
1069 const StringRefNull rna_path = fcu->rna_path();
1070 if (rna_path.startswith(prefix)) {
1071 BLI_remlink(curves, fcu);
1072 BKE_fcurve_free(fcu);
1073 any_removed = true;
1074 }
1075 }
1076 return any_removed;
1077}
1078
1079/* Check RNA-Paths for a list of F-Curves */
1080static bool nlastrips_path_remove_fix(const char *prefix, ListBaseT<NlaStrip> *strips)
1081{
1082 bool any_removed = false;
1083
1084 /* recursively check strips, fixing only actions... */
1085 for (NlaStrip &strip : *strips) {
1086 /* fix strip's action */
1087 if (strip.act) {
1089 *strip.act, strip.action_slot_handle, prefix);
1090 }
1091
1092 /* Check sub-strips (if meta-strips). */
1093 any_removed |= nlastrips_path_remove_fix(prefix, &strip.strips);
1094 }
1095
1096 return any_removed;
1097}
1098
1099bool BKE_animdata_fix_paths_remove(ID *id, const char *prefix)
1100{
1101 AnimData *adt = BKE_animdata_from_id(id);
1102 if (!adt) {
1103 return false;
1104 }
1105
1106 bool any_removed = false;
1107
1108 /* Actions. */
1109 if (adt->action) {
1110 any_removed |= animrig::legacy::action_fcurves_remove(*adt->action, adt->slot_handle, prefix);
1111 }
1112 if (adt->tmpact) {
1114 *adt->action, adt->tmp_slot_handle, prefix);
1115 }
1116
1117 /* Drivers. */
1118 any_removed |= fcurves_path_remove_from_listbase(prefix, &adt->drivers);
1119
1120 /* NLA strips. */
1121 for (NlaTrack &nlt : adt->nla_tracks) {
1122 any_removed |= nlastrips_path_remove_fix(prefix, &nlt.strips);
1123 }
1124
1125 return any_removed;
1126}
1127
1129{
1130 AnimData *adt = BKE_animdata_from_id(id);
1131 if (!adt) {
1132 return false;
1133 }
1134
1135 const bool any_removed = fcurves_path_remove_from_listbase(prefix.data(), &adt->drivers);
1136 return any_removed;
1137}
1138
1140{
1141 PointerRNA constraint_ptr = RNA_pointer_create_discrete(&owner_id, &type, data);
1142 const std::optional<std::string> base_path = RNA_path_from_ID_to_struct(&constraint_ptr);
1143 if (!base_path.has_value()) {
1144 /* The data should exist, so the path should always resolve. */
1146 }
1147
1148 return BKE_animdata_driver_path_remove(&owner_id, base_path.value());
1149}
1150
1151/* Apply Op to All FCurves in Database --------------------------- */
1152
1159
1160/* Helper for adt_apply_all_fcurves_cb() - Apply wrapped operator to list of F-Curves */
1161static bool fcurves_apply_cb(ID *id, Span<FCurve *> fcurves, const IDFCurveCallback func)
1162{
1163 for (FCurve *fcu : fcurves) {
1164 if (!func(id, fcu)) {
1165 return false;
1166 }
1167 }
1168 return true;
1169}
1171 ListBaseT<FCurve> *fcurves,
1172 const IDFCurveCallback func)
1173{
1174 for (FCurve &fcu : *fcurves) {
1175 if (!func(id, &fcu)) {
1176 return false;
1177 }
1178 }
1179 return true;
1180}
1181
1182/* Helper for adt_apply_all_fcurves_cb() - Recursively go through each NLA strip */
1184 ListBaseT<NlaStrip> *strips,
1185 const IDFCurveCallback func)
1186{
1187 for (NlaStrip &strip : *strips) {
1188 if (strip.act) {
1189 BLI_assert_msg(strip.act->curves.is_empty(), "Legacy Actions are not supported here");
1190 const Vector<FCurve *> fcurves = animrig::fcurves_for_action_slot(strip.act->wrap(),
1191 strip.action_slot_handle);
1192 if (!fcurves_apply_cb(id, fcurves, func)) {
1193 return false;
1194 }
1195 }
1196
1197 /* Check sub-strips (if meta-strips). */
1198 if (!nlastrips_apply_all_curves_cb(id, &strip.strips, func)) {
1199 return false;
1200 }
1201 }
1202 return true;
1203}
1204
1212static bool adt_apply_all_fcurves_cb(ID *id, AnimData *adt, const IDFCurveCallback func)
1213{
1214 if (adt->action) {
1215 BLI_assert_msg(adt->action->curves.is_empty(), "Legacy Actions are not supported here");
1216 if (!fcurves_apply_cb(
1217 id, animrig::fcurves_for_action_slot(adt->action->wrap(), adt->slot_handle), func))
1218 {
1219 return false;
1220 }
1221 }
1222
1223 if (adt->tmpact) {
1224 BLI_assert_msg(adt->tmpact->curves.is_empty(), "Legacy Actions are not supported here");
1225 if (!fcurves_apply_cb(
1226 id, animrig::fcurves_for_action_slot(adt->tmpact->wrap(), adt->tmp_slot_handle), func))
1227 {
1228 return false;
1229 }
1230 }
1231
1232 /* Drivers, stored as a list of F-Curves. */
1233 if (!fcurves_listbase_apply_cb(id, &adt->drivers, func)) {
1234 return false;
1235 }
1236
1237 /* NLA Data - Animation Data for Strips */
1238 for (NlaTrack &nlt : adt->nla_tracks) {
1239 if (!BKE_nlatrack_is_enabled(*adt, nlt)) {
1240 continue;
1241 }
1242 if (!nlastrips_apply_all_curves_cb(id, &nlt.strips, func)) {
1243 return false;
1244 }
1245 }
1246 return true;
1247}
1248
1249void BKE_fcurves_id_cb(ID *id, const FunctionRef<void(ID *, FCurve *)> func)
1250{
1251 AnimData *adt = BKE_animdata_from_id(id);
1252 if (adt != nullptr) {
1253 /* Use a little wrapper function to always return 'true' and thus keep the loop looping. */
1254 const auto wrapper = [&func](ID *id, FCurve *fcurve) {
1255 func(id, fcurve);
1256 return true;
1257 };
1258 adt_apply_all_fcurves_cb(id, adt, wrapper);
1259 }
1260}
1261
1262void BKE_fcurves_main_cb(Main *bmain, const FunctionRef<void(ID *, FCurve *)> func)
1263{
1264 /* Use a little wrapper function to always return 'true' and thus keep the loop looping. */
1265 const auto wrapper = [&func](ID *id, FCurve *fcurve) {
1266 func(id, fcurve);
1267 return true;
1268 };
1269
1270 /* Use the AnimData-based function so that we don't have to reimplement all that stuff */
1272 [&](ID *id, AnimData *adt) { adt_apply_all_fcurves_cb(id, adt, wrapper); });
1273}
1274
1275/* .blend file API -------------------------------------------- */
1276
1278{
1279 AnimData *adt = BKE_animdata_from_id(id);
1280 if (!adt) {
1281 return;
1282 }
1283
1284 /* firstly, just write the AnimData block */
1285 writer->write_struct(adt);
1286
1287 /* write drivers */
1289
1290 /* write overrides */
1291 /* FIXME: are these needed? */
1292 for (AnimOverride &aor : adt->overrides) {
1293 /* overrides consist of base data + rna_path */
1294 writer->write_struct(&aor);
1295 writer->write_string(aor.rna_path);
1296 }
1297
1298 /* TODO: write the remaps (if they are needed). */
1299
1300 /* write NLA data */
1301 BKE_nla_blend_write(writer, &adt->nla_tracks);
1302}
1303
1305{
1306 IdAdtTemplate *iat = id_can_have_animdata(id) ? reinterpret_cast<IdAdtTemplate *>(id) : nullptr;
1307 if (!iat || !iat->adt) {
1308 return;
1309 }
1310
1311 AnimData *adt = static_cast<AnimData *>(BLO_read_struct(reader, AnimData, &iat->adt));
1312 if (adt == nullptr) {
1313 return;
1314 }
1315
1316 /* link drivers */
1317 BLO_read_struct_list(reader, FCurve, &adt->drivers);
1319 adt->driver_array = nullptr;
1320
1321 /* link overrides */
1322 /* TODO... */
1323
1324 /* link NLA-data */
1326 BKE_nla_blend_read_data(reader, id, &adt->nla_tracks);
1327
1328 /* relink active track/strip - even though strictly speaking this should only be used
1329 * if we're in 'tweaking mode', we need to be able to have this loaded back for
1330 * undo, but also since users may not exit tweak-mode before saving (#24535).
1331 */
1332 /* TODO: it's not really nice that anyone should be able to save the file in this
1333 * state, but it's going to be too hard to enforce this single case. */
1334 BLO_read_struct(reader, NlaTrack, &adt->act_track);
1335 BLO_read_struct(reader, NlaStrip, &adt->actstrip);
1336
1337 if (ID_IS_LINKED(id)) {
1338 /* Linked NLAs should never be in tweak mode, as you cannot exit that on linked data. */
1340 }
1341}
1342
1344{
1345 AnimData *adt = BKE_animdata_from_id(id);
1346 if (!adt) {
1347 return;
1348 }
1349
1351}
1352
1353namespace bke::animdata {
1354
1359
1360bool prop_is_animated(const AnimData *adt, const StringRefNull rna_path, const int array_index)
1361{
1362 if (!adt) {
1363 /* If there is no animdata, it's clear the property is not animated. */
1364 return false;
1365 }
1366
1367 /* The const_cast is used because adt_apply_all_fcurves_cb() wants to yield a
1368 * mutable F-Curve and thus gets a mutable AnimData. The function itself is
1369 * not modifying anything, so this case should be safe. */
1370 const bool looped_until_end = adt_apply_all_fcurves_cb(
1371 nullptr, const_cast<AnimData *>(adt), [&](const ID *, const FCurve *fcurve) {
1372 /* Looping should stop (so return false) when the F-Curve was found. */
1373 return !(array_index == fcurve->array_index && rna_path == fcurve->rna_path());
1374 });
1375
1376 return !looped_until_end;
1377}
1378
1379} // namespace bke::animdata
1380} // namespace blender
Functionality to iterate an Action in various ways.
Functions for backward compatibility with the legacy Action API.
Versioning of old animation data. Most animation versioning code lives in the versioning_xxx....
Blender kernel action and pose functionality.
#define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
#define DRIVER_TARGETS_LOOPER_END
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
A dynamically sized string ADT.
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
external readfile function prototypes.
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_NEW_SET(_id, _idn)
Definition DNA_ID.h:757
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
Definition BLI_map.hh:508
Value & lookup_or_add_default(const Key &key)
Definition BLI_map.hh:639
constexpr MutableSpan()=default
constexpr bool is_empty() const
Definition BLI_span.hh:264
static constexpr int64_t not_found
constexpr StringRefNull()
constexpr StringRef()
void append(const T &value)
Slot & slot_add_for_id(const ID &animated_id)
bool is_slot_animated(slot_handle_t slot_handle) const
static void users_invalidate(Main &bmain)
static constexpr slot_handle_t unassigned
constexpr bool startswith(StringRef prefix) const
constexpr int64_t size() const
constexpr int64_t find(char c, int64_t pos=0) const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr const char * data() const
bool action_fcurves_remove(bAction &action, slot_handle_t slot_handle, StringRefNull rna_path_prefix)
bool action_is_layered(const bAction &dna_action)
Definition versioning.cc:38
Vector< FCurve * > fcurves_for_legacy_action(bAction *action)
void action_fcurve_attach(Action &action, slot_handle_t action_slot, FCurve &fcurve_to_attach, std::optional< StringRefNull > group_name)
void foreach_fcurve_in_action_slot(Action &action, slot_handle_t handle, FunctionRef< void(FCurve &fcurve)> callback)
decltype(blender::ActionSlot::handle) slot_handle_t
void update_autoflags_fcurve_direct(FCurve *fcu, PropertyType prop_type)
Action & action_add(Main &bmain, StringRefNull name)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
bool assign_tmpaction(bAction *action, OwnedAnimData owned_adt)
bool unassign_action(ID &animated_id)
bool assign_action(bAction *action, ID &animated_id)
void action_slots_user_cache_invalidate(Main &bmain)
bool prop_is_animated(const AnimData *adt, StringRefNull rna_path, int array_index)
bNodeTree * node_tree_from_id(ID *id)
Definition node.cc:5337
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BKE_animdata_action_editable(const AnimData *adt)
Definition anim_data.cc:164
__int64 int64_t
Definition BKE_text.h:90
static bool nlastrips_path_remove_fix(const char *prefix, ListBaseT< NlaStrip > *strips)
const IDTypeInfo * BKE_idtype_get_info_from_idcode(short id_code)
Definition idtype.cc:227
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_action_fix_paths_rename(ID *owner_id, bAction *act, int32_t slot_handle, StringRef prefix, StringRefNull oldName, StringRefNull newName, bool verify_paths)
@ RPT_WARNING
Definition BKE_report.hh:40
unsigned int uint
Definition BKE_text.h:55
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:529
static bool rename_paths_action(bAction *dna_action, const animrig::slot_handle_t slot_handle, ID &owner_id, const StringRef prefix, const StringRef old_infix, const StringRef new_infix, const bool verify_paths)
Definition anim_data.cc:822
void id_us_plus(ID *id)
Definition lib_id.cc:433
static std::string infix_to_name(const StringRef infix)
Definition anim_data.cc:759
PointerRNA RNA_id_pointer_create(ID *id)
static bool check_rna_path_is_valid(ID &owner_id, const StringRefNull path)
Definition anim_data.cc:690
void BKE_fcurves_free(ListBaseT< FCurve > *list)
void BKE_fcurves_id_cb(struct ID *id, FunctionRef< void(ID *, FCurve *)> func)
void BKE_nla_blend_read_data(BlendDataReader *reader, ID *id_owner, ListBaseT< NlaTrack > *tracks)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
Definition rna_path.cc:1078
void BKE_animdata_main_cb(struct Main *bmain, FunctionRef< void(ID *, AnimData *)> func)
void BKE_fcurve_blend_read_data_listbase(BlendDataReader *reader, ListBaseT< FCurve > *fcurves)
void BKE_fcurve_foreach_id(FCurve *fcu, LibraryForeachIDData *data)
static bool driver_target_path_fix(ID &owner_id, const StringRef prefix, const StringRef old_infix, const StringRef new_infix, const DriverMap &driver_map)
Definition anim_data.cc:937
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:32
AnimData * BKE_animdata_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, AnimData *adt, int flag)
Definition anim_data.cc:263
std::pair< std::string, std::string > RNA_generate_keys_for_path_rename(const StringRefNull old_infix, const StringRefNull new_infix, const int old_subscript, const int new_subscript, const bool infix_is_name)
Definition rna_path.cc:1430
static bool animdata_copy_drivers_by_basepath(AnimData &src_adt, AnimData &dst_adt, const StringRef src_basepath, const StringRef dst_basepath)
Definition anim_data.cc:583
bool id_type_can_have_animdata(short id_type)
Definition anim_data.cc:69
bool BKE_animdata_id_is_animated(const ID *id)
Definition anim_data.cc:224
bool id_can_have_animdata(const ID *id)
Definition anim_data.cc:78
void BKE_animdata_duplicate_id_action(Main *bmain, ID *id, uint duplicate_flags)
Definition anim_data.cc:434
void BKE_fcurve_blend_write_listbase(BlendWriter *writer, ListBaseT< FCurve > *fcurves)
void BKE_animdata_blend_write(BlendWriter *writer, ID *id)
void BKE_nla_liboverride_post_process(ID *id, AnimData *adt)
bool BKE_animdata_fix_paths_remove(ID *id, const char *prefix)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_ACTIONS
@ LIB_ID_CREATE_NO_MAIN
static bool nlastrips_apply_all_curves_cb(ID *id, ListBaseT< NlaStrip > *strips, const IDFCurveCallback func)
static bool fcurves_path_rename_fix(ID &owner_id, const StringRef prefix, const StringRef old_infix, const StringRef new_infix, const Span< FCurve * > curves, const bool verify_paths)
Definition anim_data.cc:771
static bool animpath_matches_basepath(const StringRef path, const StringRef basepath)
Definition anim_data.cc:525
AnimData * BKE_animdata_ensure_id(ID *id)
Definition anim_data.cc:107
void BKE_nla_tweakmode_exit(OwnedAnimData owned_adt)
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
Global G
Definition blender.cc:57
void BKE_animdata_blend_read_data(BlendDataReader *reader, ID *id)
bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
Definition anim_data.cc:135
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
void BKE_nla_strip_foreach_id(NlaStrip *strip, LibraryForeachIDData *data)
static std::pair< AnimData *, AnimData * > ensure_animdata_pair(Main &bmain, const ID &src_id, ID &dst_id)
Definition anim_data.cc:604
void BKE_fcurves_copy(ListBaseT< FCurve > *dst, ListBaseT< FCurve > *src)
bool BKE_nlatrack_is_enabled(const AnimData &adt, const NlaTrack &nlt)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void BKE_nla_tracks_free(ListBaseT< NlaTrack > *tracks, bool do_id_user)
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 BKE_animdata_free(ID *id, bool do_id_user)
Definition anim_data.cc:174
static void animpath_update_basepath(FCurve *fcu, const StringRef old_basepath, const StringRef new_basepath)
Definition anim_data.cc:530
static bool adt_apply_all_fcurves_cb(ID *id, AnimData *adt, const IDFCurveCallback func)
FCurve * BKE_fcurve_copy(const FCurve *fcu)
void BKE_nla_tracks_copy(Main *bmain, ListBaseT< NlaTrack > *dst, const ListBaseT< NlaTrack > *src, int flag)
DriverMap BKE_animdata_build_driver_target_map(Main &bmain)
Definition anim_data.cc:980
void BKE_animdata_foreach_id(AnimData *adt, LibraryForeachIDData *data)
Definition anim_data.cc:245
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, int flag)
Definition anim_data.cc:351
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_nla_blend_write(BlendWriter *writer, ListBaseT< NlaTrack > *tracks)
static void animdata_copy_id_action(Main *bmain, ID *id, const bool set_newid, const bool do_linked_id)
Definition anim_data.cc:370
void BKE_fcurves_main_cb(struct Main *bmain, FunctionRef< void(ID *, FCurve *)> func)
static bool fcurves_listbase_apply_cb(ID *id, ListBaseT< FCurve > *fcurves, const IDFCurveCallback func)
bool BKE_animdata_driver_path_remove(ID *id, StringRefNull prefix)
void BKE_animdata_copy_by_basepath(Main &bmain, const ID &src_id, ID &dst_id, Span< AnimationBasePathChange > basepaths)
Definition anim_data.cc:640
void BKE_nla_tweakmode_exit_nofollowptr(AnimData *adt)
void BKE_fcurve_free(FCurve *fcu)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
FunctionRef< bool(ID *, FCurve *)> IDFCurveCallback
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
AnimData * BKE_animdata_copy(Main *bmain, AnimData *adt, int flag)
Definition anim_data.cc:346
static bool action_copy_fcurves_by_basepath(const animrig::Action &src_action, const animrig::slot_handle_t src_slot_handle, animrig::Action &dst_action, const animrig::slot_handle_t dst_slot_handle, const StringRef src_basepath, const StringRef dst_basepath)
Definition anim_data.cc:545
static CLG_LogRef LOG
Definition logging.cpp:12
size_t size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_len) ATTR_NONNULL(1
void DEG_relations_tag_update(Main *bmain)
static bool fcurves_path_remove_from_listbase(const char *prefix, ListBaseT< FCurve > *curves)
Map< ID *, Vector< DriverTarget * > > DriverMap
static std::optional< std::string > rna_path_rename_fix(ID &owner_id, const StringRef prefix, const StringRef old_infix, const StringRef new_infix, const StringRefNull old_path, const bool verify_paths)
Definition anim_data.cc:708
bool BKE_animdata_drivers_remove_for_rna_struct(ID &owner_id, struct StructRNA &type, void *data)
static bool fcurves_apply_cb(ID *id, Span< FCurve * > fcurves, const IDFCurveCallback func)
eAnimData_MergeCopy_Modes
@ ADT_MERGECOPY_SRC_REF
@ ADT_MERGECOPY_SRC_COPY
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:856
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
char * BKE_animsys_fix_rna_path_rename(ID *owner_id, const char *old_path, StringRef prefix, StringRefNull old_name, StringRefNull newName)
Definition anim_data.cc:882
void BKE_animdata_copy_id_action(Main *bmain, ID *id)
Definition anim_data.cc:428
void BKE_animdata_merge_copy(Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers)
Definition anim_data.cc:443
void BKE_animdata_liboverride_post_process(ID *id)
struct ID * BKE_id_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, const ID *id, std::optional< const ID * > new_owner_id, ID **new_id_p, int flag)
Definition lib_id.cc:749
ID_Readfile_Data::Tags BLO_readfile_id_runtime_tags(const ID &id)
Definition readfile.cc:2297
static bool nlastrips_path_rename_fix(ID &owner_id, const StringRef prefix, const StringRef old_infix, const StringRef new_infix, ListBaseT< NlaStrip > &strips, const bool verify_paths)
Definition anim_data.cc:851
void BKE_nla_tracks_copy_from_adt(Main *bmain, AnimData *adt_dest, const AnimData *adt_source, int flag)
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition BKE_idtype.hh:52
char tmp_last_slot_identifier[258]
char last_slot_identifier[258]
eAnimData_Flag flag
ListBaseT< AnimOverride > overrides
ListBaseT< FCurve > drivers
ListBaseT< NlaTrack > nla_tracks
void write_string(const char *data)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
ListBaseT< DriverVar > variables
DriverTarget targets[8]
bActionGroup * grp
struct FCurve * next
ChannelDriver * driver
char name[258]
Definition DNA_ID.h:433
ListBaseT< NlaStrip > strips
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< FCurve > curves