LibOverride: Add util to check if a given Override Property is animated.

Searches in available animdata for fcuve(s) with matching RNA path.
This commit is contained in:
Bastien Montagne 2022-06-10 15:53:46 +02:00
parent f5d0a40122
commit 4d0f7c3dcd
2 changed files with 43 additions and 0 deletions

View File

@ -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).

View File

@ -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<char *>(
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;