diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-15 08:41:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-15 08:41:06 +0300 |
commit | ed97b466c498811d96a68c8c3794b75f755001fa (patch) | |
tree | 769d054c58c60148b73b7833c5a0b5a5ce61d035 /source/blender/blenkernel/intern/object.c | |
parent | 9afadb3a9d0d64be70cb9bf3d878f5d121264edc (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern/object.c')
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 29 |
1 files 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--; } |