52#include "RNA_prototypes.hh"
72 if (typeinfo !=
nullptr) {
118 if (iat->
adt ==
nullptr) {
122 adt = iat->
adt = MEM_new<AnimData>(
"AnimData");
145 if (adt ==
nullptr) {
152 BKE_report(reports,
RPT_ERROR,
"Cannot change action, as it is still being edited in NLA");
169 return !is_tweaking_strip;
194 "Expecting action un-assignment to always work when not in NLA tweak mode");
202 BLI_assert_msg(unassign_ok,
"Expecting tmpaction un-assignment to always work");
231 if (adt ==
nullptr) {
264 std::optional<Library *> owner_library,
274 if (adt ==
nullptr) {
277 dadt = MEM_dupalloc(adt);
299 reinterpret_cast<ID *
>(dadt->
action),
306 reinterpret_cast<ID *
>(dadt->
tmpact),
311 else if (do_id_user) {
355 if ((id_to && id_from) && (id_to->id_type() != id_from->id_type())) {
372 const bool set_newid,
373 const bool do_linked_id)
382 cloned_action->
id.
us = 0;
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");
402 cloned_action->
id.
us = 0;
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");
436 const uint duplicate_flags)
450 if (
ELEM(
nullptr, dst, src)) {
458 "Merging AnimData blocks while editing NLA is dangerous as it may cause data corruption");
483 ListBaseT<NlaTrack> tracks = {
nullptr,
nullptr};
491 ListBaseT<FCurve> drivers = {
nullptr,
nullptr};
499 for (
FCurve &fcu : drivers) {
503 if (dtar->id == src_id) {
535 if (old_basepath == new_basepath) {
539 std::string new_rna_path = new_basepath +
541 fcu->rna_path_set(new_rna_path);
552 if (&src_action == &dst_action && src_slot_handle == dst_slot_handle &&
553 src_basepath == dst_basepath)
567 fcurves_to_copy.
append(&fcurve);
571 for (
const FCurve *fcurve : fcurves_to_copy) {
572 std::optional<StringRefNull> group_name;
574 group_name = fcurve->
grp->
name;
609 if (src_adt ==
nullptr) {
611 return {
nullptr,
nullptr};
616 if (dst_adt ==
nullptr) {
620 return {
nullptr,
nullptr};
637 return {src_adt, dst_adt};
655 if (src_adt->action) {
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))
674 if (src_adt->drivers.first()) {
677 *src_adt, *dst_adt, basepath_change.src_basepath, basepath_change.dst_basepath))
713 const bool verify_paths)
715 const int64_t prefix_offset = old_path.
find(prefix);
720 const int64_t old_infix_offset = old_path.
find(old_infix);
727 if (prefix_offset + prefix.
size() != old_infix_offset) {
736 std::string modified_path;
737 const int64_t postfix_offset = old_infix_offset + old_infix.
size();
740 if (prefix_offset > 0) {
741 modified_path.append(old_path.
substr(0, prefix_offset));
744 modified_path.append(prefix);
745 modified_path.append(new_infix);
746 modified_path.append(old_path.
substr(postfix_offset));
753 return modified_path;
763 std::string unescaped;
764 unescaped.resize(infix.
size() - 4);
766 unescaped.resize(string_size);
776 const bool verify_paths)
778 bool is_changed =
false;
781 if (fcu->rna_path().is_empty()) {
786 owner_id, prefix, old_infix, new_infix, fcu->rna_path(), verify_paths);
787 if (!new_path.has_value()) {
790 fcu->rna_path_set(*new_path);
799 if (!
RNA_path_resolve(&ptr, fcu->rna_path().c_str(), &resolved_ptr, &resolved_prop)) {
809 if (agrp && resolved_ptr.
type == RNA_PoseBone) {
828 const bool verify_paths)
831 bool is_changed_action;
837 owner_id, prefix, old_infix, new_infix, fcurves, verify_paths);
842 owner_id, prefix, old_infix, new_infix, fcurves, verify_paths);
844 if (is_changed_action) {
847 return is_changed_action;
855 ListBaseT<NlaStrip> &strips,
856 const bool verify_paths)
858 bool is_changed =
false;
862 if (strip.act !=
nullptr) {
864 strip.action_slot_handle,
870 is_changed |= is_changed_action;
875 owner_id, prefix, old_infix, new_infix, strip.strips, verify_paths);
883 const char *old_path,
889 if (
ELEM(
nullptr, owner_id, old_path)) {
900 printf(
"%s | %s | oldpath = %p ", old_key.c_str(), new_key.c_str(), old_path);
903 *owner_id, prefix, old_key, new_key, old_path,
false);
904 if (!new_path.has_value()) {
916 const bool verify_paths)
919 if (
ELEM(
nullptr, owner_id, act)) {
948 bool is_changed =
false;
951 "Driver Map for this ID contains targets for another ID.");
952 if (target->rna_path) {
956 owner_id, prefix, old_infix, new_infix, target->rna_path,
false);
957 if (fixed_path.has_value()) {
958 MEM_delete(target->rna_path);
959 target->rna_path =
BLI_strdup(fixed_path->c_str());
964 if (owner_id.id_type() ==
ID_OB && target->pchan_name[0] && prefix.
find(
"bones")) {
969 if (old_bone_name ==
StringRef(target->pchan_name)) {
971 STRNCPY(target->pchan_name, new_bone_name.data());
1005 const bool verify_paths,
1008 bool is_changed =
false;
1028 id, prefix, old_infix, new_infix, nlt.
strips, verify_paths);
1032 id, prefix, old_infix, new_infix, fcurve.rna_path(), verify_paths);
1033 if (!fixed_path.has_value()) {
1036 fcurve.rna_path_set(*fixed_path);
1061 bool any_removed =
false;
1067 for (fcu =
curves->first(); fcu; fcu = fcn) {
1082 bool any_removed =
false;
1089 *strip.act, strip.action_slot_handle, prefix);
1106 bool any_removed =
false;
1143 if (!base_path.has_value()) {
1163 for (
FCurve *fcu : fcurves) {
1164 if (!func(
id, fcu)) {
1171 ListBaseT<FCurve> *fcurves,
1174 for (
FCurve &fcu : *fcurves) {
1175 if (!func(
id, &fcu)) {
1184 ListBaseT<NlaStrip> *strips,
1189 BLI_assert_msg(strip.act->curves.is_empty(),
"Legacy Actions are not supported here");
1191 strip.action_slot_handle);
1252 if (adt !=
nullptr) {
1254 const auto wrapper = [&func](
ID *
id,
FCurve *fcurve) {
1265 const auto wrapper = [&func](
ID *
id,
FCurve *fcurve) {
1307 if (!iat || !iat->
adt) {
1312 if (adt ==
nullptr) {
1371 nullptr,
const_cast<AnimData *
>(adt), [&](
const ID *,
const FCurve *fcurve) {
1376 return !looped_until_end;
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,...)
#define CLOG_WARN(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_LINKED(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
#define ID_NEW_SET(_id, _idn)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
Value & lookup_or_add_default(const Key &key)
constexpr MutableSpan()=default
constexpr bool is_empty() const
static constexpr int64_t not_found
constexpr StringRefNull()
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)
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)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool BKE_animdata_action_editable(const AnimData *adt)
static bool nlastrips_path_remove_fix(const char *prefix, ListBaseT< NlaStrip > *strips)
const IDTypeInfo * BKE_idtype_get_info_from_idcode(short id_code)
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)
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
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)
static std::string infix_to_name(const StringRef infix)
PointerRNA RNA_id_pointer_create(ID *id)
static bool check_rna_path_is_valid(ID &owner_id, const StringRefNull path)
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)
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)
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
AnimData * BKE_animdata_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, AnimData *adt, int flag)
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)
static bool animdata_copy_drivers_by_basepath(AnimData &src_adt, AnimData &dst_adt, const StringRef src_basepath, const StringRef dst_basepath)
bool id_type_can_have_animdata(short id_type)
bool BKE_animdata_id_is_animated(const ID *id)
bool id_can_have_animdata(const ID *id)
void BKE_animdata_duplicate_id_action(Main *bmain, ID *id, uint duplicate_flags)
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
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)
static bool animpath_matches_basepath(const StringRef path, const StringRef basepath)
AnimData * BKE_animdata_ensure_id(ID *id)
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)
void BKE_animdata_blend_read_data(BlendDataReader *reader, ID *id)
bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
PropertyType RNA_property_type(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
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)
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)
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)
BMesh const char void * data
void BKE_animdata_free(ID *id, bool do_id_user)
static void animpath_update_basepath(FCurve *fcu, const StringRef old_basepath, const StringRef new_basepath)
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)
void BKE_animdata_foreach_id(AnimData *adt, LibraryForeachIDData *data)
bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, int flag)
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)
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)
void BKE_nla_tweakmode_exit_nofollowptr(AnimData *adt)
void BKE_fcurve_free(FCurve *fcu)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
FunctionRef< bool(ID *, FCurve *)> IDFCurveCallback
AnimData * BKE_animdata_copy(Main *bmain, AnimData *adt, int flag)
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)
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)
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
ID * BKE_id_copy(Main *bmain, const ID *id)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
char * BKE_animsys_fix_rna_path_rename(ID *owner_id, const char *old_path, StringRef prefix, StringRefNull old_name, StringRefNull newName)
void BKE_animdata_copy_id_action(Main *bmain, ID *id)
void BKE_animdata_merge_copy(Main *bmain, ID *dst_id, ID *src_id, eAnimData_MergeCopy_Modes action_mode, bool fix_drivers)
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)
ID_Readfile_Data::Tags BLO_readfile_id_runtime_tags(const ID &id)
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)
void BKE_nla_tracks_copy_from_adt(Main *bmain, AnimData *adt_dest, const AnimData *adt_source, int flag)
@ IDTYPE_FLAGS_NO_ANIMDATA
char tmp_last_slot_identifier[258]
char last_slot_identifier[258]
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
ListBaseT< NlaStrip > strips
ListBaseT< FCurve > curves