From ed97b466c498811d96a68c8c3794b75f755001fa Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 15 Sep 2020 15:41:06 +1000 Subject: Fix T80443: Object.active_shape_key None after adding a shape Change BKE_object_shapekey_{insert/remove} to set/clear the active shape index. Only set the active index when there are no existing active shapes. --- source/blender/blenkernel/intern/object.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 69b4f68bc33..bfb296af069 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -60,6 +60,7 @@ #include "BLI_blenlib.h" #include "BLI_kdtree.h" #include "BLI_linklist.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_threads.h" #include "BLI_utildefines.h" @@ -3867,17 +3868,31 @@ KeyBlock *BKE_object_shapekey_insert(Main *bmain, const char *name, const bool from_mix) { + KeyBlock *key = NULL; + switch (ob->type) { case OB_MESH: - return insert_meshkey(bmain, ob, name, from_mix); + key = insert_meshkey(bmain, ob, name, from_mix); + break; case OB_CURVE: case OB_SURF: - return insert_curvekey(bmain, ob, name, from_mix); + key = insert_curvekey(bmain, ob, name, from_mix); + break; case OB_LATTICE: - return insert_lattkey(bmain, ob, name, from_mix); + key = insert_lattkey(bmain, ob, name, from_mix); + break; default: - return NULL; + break; } + + /* Set the first active when none is set when called from RNA. */ + if (key != NULL) { + if (ob->shapenr <= 0) { + ob->shapenr = 1; + } + } + + return key; } bool BKE_object_shapekey_free(Main *bmain, Object *ob) @@ -3948,7 +3963,11 @@ bool BKE_object_shapekey_remove(Main *bmain, Object *ob, KeyBlock *kb) } MEM_freeN(kb); - if (ob->shapenr > 1) { + /* Unset active when all are freed. */ + if (BLI_listbase_is_empty(&key->block)) { + ob->shapenr = 0; + } + else if (ob->shapenr > 1) { ob->shapenr--; } -- cgit v1.2.3