diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index fbc3a1a8b3e..81bbfd40466 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -88,9 +88,9 @@ struct KeyBlock *BKE_keyblock_add(struct Key *key, const char *name); */ struct KeyBlock *BKE_keyblock_add_ctime(struct Key *key, const char *name, bool do_force); /** - * Get the appropriate #KeyBlock given an index. + * Get the appropriate #KeyBlock given an index (0 refers to the basis key). Key may be null. */ -struct KeyBlock *BKE_keyblock_from_key(struct Key *key, int index); +struct KeyBlock *BKE_keyblock_find_by_index(struct Key *key, int index); /** * Get the appropriate #KeyBlock given a name to search for. */ diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index 6f3994d0954..7b3e15002aa 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -357,9 +357,9 @@ static float (*get_orco_coords(Object *ob, BMEditMesh *em, int layer, int *free) if (!em) { ClothModifierData *clmd = (ClothModifierData *)BKE_modifiers_findby_type( ob, eModifierType_Cloth); - if (clmd) { - KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ob), - clmd->sim_parms->shapekey_rest); + if (clmd && clmd->sim_parms->shapekey_rest) { + KeyBlock *kb = BKE_keyblock_find_by_index(BKE_key_from_object(ob), + clmd->sim_parms->shapekey_rest); if (kb && kb->data) { return (float(*)[3])kb->data; diff --git a/source/blender/blenkernel/intern/ipo.cc b/source/blender/blenkernel/intern/ipo.cc index 024721c5221..2aecc75a82d 100644 --- a/source/blender/blenkernel/intern/ipo.cc +++ b/source/blender/blenkernel/intern/ipo.cc @@ -443,7 +443,7 @@ static char *shapekey_adrcodes_to_paths(ID *id, int adrcode, int * /*r_array_ind else { /* Find the name of the ShapeKey (i.e. KeyBlock) to look for */ Key *key = (Key *)id; - KeyBlock *kb = BKE_keyblock_from_key(key, adrcode); + KeyBlock *kb = BKE_keyblock_find_by_index(key, adrcode); /* setting that we alter is the "value" (i.e. keyblock.curval) */ if (kb) { diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index 9a445409cc0..ca637a99eee 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -1897,12 +1897,7 @@ KeyBlock *BKE_keyblock_from_object(Object *ob) { Key *key = BKE_key_from_object(ob); - if (key) { - KeyBlock *kb = static_cast(BLI_findlink(&key->block, ob->shapenr - 1)); - return kb; - } - - return nullptr; + return BKE_keyblock_find_by_index(key, ob->shapenr - 1); } KeyBlock *BKE_keyblock_from_object_reference(Object *ob) @@ -1916,21 +1911,13 @@ KeyBlock *BKE_keyblock_from_object_reference(Object *ob) return nullptr; } -KeyBlock *BKE_keyblock_from_key(Key *key, int index) +KeyBlock *BKE_keyblock_find_by_index(Key *key, int index) { - if (key) { - KeyBlock *kb = static_cast(key->block.first); - - for (int i = 1; i < key->totkey; i++) { - kb = kb->next; - - if (index == i) { - return kb; - } - } + if (!key) { + return nullptr; } - return nullptr; + return static_cast(BLI_findlink(&key->block, index)); } KeyBlock *BKE_keyblock_find_name(Key *key, const char name[]) diff --git a/source/blender/modifiers/intern/MOD_cloth.cc b/source/blender/modifiers/intern/MOD_cloth.cc index 12d5366d429..f2838638f53 100644 --- a/source/blender/modifiers/intern/MOD_cloth.cc +++ b/source/blender/modifiers/intern/MOD_cloth.cc @@ -100,8 +100,8 @@ static void deform_verts(ModifierData *md, * Also hopefully new cloth system will arrive soon.. */ if (mesh == nullptr && clmd->sim_parms->shapekey_rest) { - KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ctx->object), - clmd->sim_parms->shapekey_rest); + KeyBlock *kb = BKE_keyblock_find_by_index(BKE_key_from_object(ctx->object), + clmd->sim_parms->shapekey_rest); if (kb && kb->data != nullptr) { float(*layerorco)[3]; if (!(layerorco = static_cast(