From 4d0f7c3dcde22224b17e5c481fea11f99fe5b160 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 10 Jun 2022 15:53:46 +0200 Subject: LibOverride: Add util to check if a given Override Property is animated. Searches in available animdata for fcuve(s) with matching RNA path. --- source/blender/blenkernel/BKE_lib_override.h | 13 ++++++++++ source/blender/blenkernel/intern/lib_override.cc | 30 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_lib_override.h b/source/blender/blenkernel/BKE_lib_override.h index 533bfa6b0bc..d19c2907be2 100644 --- a/source/blender/blenkernel/BKE_lib_override.h +++ b/source/blender/blenkernel/BKE_lib_override.h @@ -69,6 +69,19 @@ bool BKE_lib_override_library_is_user_edited(const struct ID *id); */ bool BKE_lib_override_library_is_system_defined(const struct Main *bmain, const struct ID *id); +/** + * Check if given Override Property for given ID is animated (through a F-Curve in an Action, or + * from a driver). + * + * \param override_rna_prop if not NULL, the RNA property matching the given path in the + * `override_prop`. + * \param rnaprop_index Array in the RNA property, 0 if unknown or irrelevant. + */ +bool BKE_lib_override_library_property_is_animated(const ID *id, + const IDOverrideLibraryProperty *override_prop, + const struct PropertyRNA *override_rna_prop, + const int rnaprop_index); + /** * Check if given ID is a leaf in its liboverride hierarchy (i.e. if it does not use any other * override ID). diff --git a/source/blender/blenkernel/intern/lib_override.cc b/source/blender/blenkernel/intern/lib_override.cc index 56d0308a033..22012662180 100644 --- a/source/blender/blenkernel/intern/lib_override.cc +++ b/source/blender/blenkernel/intern/lib_override.cc @@ -21,8 +21,10 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" +#include "BKE_anim_data.h" #include "BKE_armature.h" #include "BKE_collection.h" +#include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_idtype.h" #include "BKE_key.h" @@ -321,6 +323,34 @@ bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id) return false; } +bool BKE_lib_override_library_property_is_animated(const ID *id, + const IDOverrideLibraryProperty *override_prop, + const PropertyRNA *override_rna_prop, + const int rnaprop_index) +{ + AnimData *anim_data = BKE_animdata_from_id(id); + if (anim_data != nullptr) { + struct FCurve *fcurve; + char *index_token_start = const_cast( + RNA_path_array_index_token_find(override_prop->rna_path, override_rna_prop)); + if (index_token_start != nullptr) { + const char index_token_start_backup = *index_token_start; + *index_token_start = '\0'; + fcurve = BKE_animadata_fcurve_find_by_rna_path( + anim_data, override_prop->rna_path, rnaprop_index, nullptr, nullptr); + *index_token_start = index_token_start_backup; + } + else { + fcurve = BKE_animadata_fcurve_find_by_rna_path( + anim_data, override_prop->rna_path, 0, nullptr, nullptr); + } + if (fcurve != nullptr) { + return true; + } + } + return false; +} + static int foreachid_is_hierarchy_leaf_fn(LibraryIDLinkCallbackData *cb_data) { ID *id_owner = cb_data->id_owner; -- cgit v1.2.3