From 2e06c223cc1ff386e4b108c6733795c1fc931d83 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 19 May 2022 09:05:24 +0200 Subject: Fix T73250: Override Library will always return to Object Mode on file opening. Was an old known annoying issue, since the matching RNA property is read-only we need a manual handling of this in override applying and resyncing code. --- source/blender/blenkernel/intern/lib_override.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index dc112af41db..608c3949858 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -72,6 +72,21 @@ static void lib_override_library_property_clear(IDOverrideLibraryProperty *op); static void lib_override_library_property_operation_clear( IDOverrideLibraryPropertyOperation *opop); +/** Helper to preserve Pose mode on override objects. + * A bit annoying to have this special case, but not much to be done here currently, since the + * matching RNA property is read-only. */ +BLI_INLINE void lib_override_object_posemode_transfer(ID *id_dst, ID *id_src) +{ + if (GS(id_src->name) == ID_OB && GS(id_dst->name) == ID_OB) { + Object *ob_src = (Object *)id_src; + Object *ob_dst = (Object *)id_dst; + if (ob_src->type == OB_ARMATURE && (ob_src->mode & OB_MODE_POSE) != 0) { + ob_dst->restore_mode = ob_dst->mode; + ob_dst->mode |= OB_MODE_POSE; + } + } +} + /** Get override data for a given ID. Needed because of our beloved shape keys snowflake. */ BLI_INLINE IDOverrideLibrary *lib_override_get(Main *bmain, ID *id, ID **r_owner_id) { @@ -1703,6 +1718,8 @@ static bool lib_override_library_resync(Main *bmain, id_override_old->tag |= LIB_TAG_NO_MAIN; id_override_new->tag &= ~LIB_TAG_NO_MAIN; + lib_override_object_posemode_transfer(id_override_new, id_override_old); + if (ID_IS_OVERRIDE_LIBRARY_REAL(id_override_new)) { BLI_assert(ID_IS_OVERRIDE_LIBRARY_REAL(id_override_old)); @@ -3423,6 +3440,8 @@ void BKE_lib_override_library_update(Main *bmain, ID *local) local->override_library, RNA_OVERRIDE_APPLY_FLAG_NOP); + lib_override_object_posemode_transfer(tmp_id, local); + /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. * So when we'll free tmp_id, we'll actually free old, outdated data from local. */ lib_override_id_swap(bmain, local, tmp_id); -- cgit v1.2.3