From 41d6f03ffc0a75cc46c77037e752e4d076207265 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld <chris.lenden@gmail.com> Date: Fri, 12 Apr 2024 14:48:10 +0200 Subject: [PATCH] Fix #119909: Unkeyable custom properties receive keyframes In the case that "Custom Properties" was enabled in the user preferences, the keyframing code would key all custom properties, regardless of that property's type. This can cause issues since it is keying e.g. the custom property that cycles adds. With this PR this is now limited to only Boolean, Int, Float, Double and Array. Custom properties that have been defined via an addon are also not keyed. Pull Request: https://projects.blender.org/blender/blender/pulls/119914 --- .../blender/editors/animation/keyframing.cc | 41 ++++++++++++++++++- source/blender/makesrna/RNA_access.hh | 5 +++ source/blender/makesrna/intern/rna_access.cc | 5 +++ source/blender/makesrna/intern/rna_rna.cc | 2 +- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 0516f152d25..1fb8f268d1c 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -252,6 +252,35 @@ static int insert_key_with_keyingset(bContext *C, wmOperator *op, KeyingSet *ks) return OPERATOR_FINISHED; } +static bool is_idproperty_keyable(IDProperty *prop, const PropertyRNA *property_rna) +{ + if (RNA_property_is_runtime(property_rna)) { + return false; + } + + if (ELEM(prop->type, + eIDPropertyType::IDP_BOOLEAN, + eIDPropertyType::IDP_INT, + eIDPropertyType::IDP_FLOAT, + eIDPropertyType::IDP_DOUBLE)) + { + return true; + } + + if (prop->type == eIDPropertyType::IDP_ARRAY) { + if (ELEM(prop->subtype, + eIDPropertyType::IDP_BOOLEAN, + eIDPropertyType::IDP_INT, + eIDPropertyType::IDP_FLOAT, + eIDPropertyType::IDP_DOUBLE)) + { + return true; + } + } + + return false; +} + static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr) { eRotationModes rotation_mode; @@ -307,7 +336,17 @@ static blender::Vector<std::string> construct_rna_paths(PointerRNA *ptr) LISTBASE_FOREACH (IDProperty *, prop, &properties->data.group) { char name_escaped[MAX_IDPROP_NAME * 2]; BLI_str_escape(name_escaped, prop->name, sizeof(name_escaped)); - paths.append(fmt::format("[\"{}\"]", name_escaped)); + std::string path = fmt::format("[\"{}\"]", name_escaped); + PointerRNA resolved_ptr; + PropertyRNA *resolved_prop; + const bool is_resolved = RNA_path_resolve_property( + ptr, path.c_str(), &resolved_ptr, &resolved_prop); + if (!is_resolved) { + continue; + } + if (is_idproperty_keyable(prop, resolved_prop)) { + paths.append(path); + } } } } diff --git a/source/blender/makesrna/RNA_access.hh b/source/blender/makesrna/RNA_access.hh index 802cffb763d..8cd5ba9aae2 100644 --- a/source/blender/makesrna/RNA_access.hh +++ b/source/blender/makesrna/RNA_access.hh @@ -287,6 +287,11 @@ int RNA_property_enum_bitflag_identifiers( StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop); bool RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value); +/** + * A property is a runtime property if the PROP_INTERN_RUNTIME flag is set on it. + */ +bool RNA_property_is_runtime(const PropertyRNA *prop); + bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop); /** * Version of #RNA_property_editable that tries to return additional info in \a r_info diff --git a/source/blender/makesrna/intern/rna_access.cc b/source/blender/makesrna/intern/rna_access.cc index 74ba9ce3a92..9cdfee3a733 100644 --- a/source/blender/makesrna/intern/rna_access.cc +++ b/source/blender/makesrna/intern/rna_access.cc @@ -2158,6 +2158,11 @@ static bool rna_property_editable_do(const PointerRNA *ptr, return true; } +bool RNA_property_is_runtime(const PropertyRNA *prop) +{ + return prop->flag_internal & PROP_INTERN_RUNTIME; +} + bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop) { return rna_property_editable_do(ptr, prop, -1, nullptr); diff --git a/source/blender/makesrna/intern/rna_rna.cc b/source/blender/makesrna/intern/rna_rna.cc index 8232141058c..2daad6ed87b 100644 --- a/source/blender/makesrna/intern/rna_rna.cc +++ b/source/blender/makesrna/intern/rna_rna.cc @@ -825,7 +825,7 @@ static bool rna_Property_is_registered_optional_get(PointerRNA *ptr) static bool rna_Property_is_runtime_get(PointerRNA *ptr) { PropertyRNA *prop = (PropertyRNA *)ptr->data; - return (prop->flag_internal & PROP_INTERN_RUNTIME) != 0; + return RNA_property_is_runtime(prop); } static bool rna_BoolProperty_default_get(PointerRNA *ptr) -- GitLab