diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_key.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 19 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_shapekey.c | 11 |
3 files changed, 22 insertions, 10 deletions
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index a159cbb13d4..de60d316426 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -59,6 +59,8 @@ void key_curve_position_weights(float t, float data[4], int type); void key_curve_tangent_weights(float t, float data[4], int type); void key_curve_normal_weights(float t, float data[4], int type); +float *BKE_key_evaluate_object_ex(struct Scene *scene, struct Object *ob, int *r_totelem, + float *arr, size_t arr_size); float *BKE_key_evaluate_object(struct Scene *scene, struct Object *ob, int *r_totelem); struct Key *BKE_key_from_object(struct Object *ob); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index e141b9dbabe..a79fa3873f5 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1342,7 +1342,8 @@ static void do_latt_key(Scene *scene, Object *ob, Key *key, char *out, const int } /* returns key coordinates (+ tilt) when key applied, NULL otherwise */ -float *BKE_key_evaluate_object(Scene *scene, Object *ob, int *r_totelem) +float *BKE_key_evaluate_object_ex(Scene *scene, Object *ob, int *r_totelem, + float *arr, size_t arr_size) { Key *key = BKE_key_from_object(ob); KeyBlock *actkb = BKE_keyblock_from_object(ob); @@ -1386,7 +1387,16 @@ float *BKE_key_evaluate_object(Scene *scene, Object *ob, int *r_totelem) return NULL; /* allocate array */ - out = MEM_callocN(size, "BKE_key_evaluate_object out"); + if (arr == NULL) { + out = MEM_callocN(size, "BKE_key_evaluate_object out"); + } + else { + if (arr_size != size) { + return NULL; + } + + out = (char *)arr; + } /* prevent python from screwing this up? anyhoo, the from pointer could be dropped */ key->from = (ID *)ob->data; @@ -1427,6 +1437,11 @@ float *BKE_key_evaluate_object(Scene *scene, Object *ob, int *r_totelem) return (float *)out; } +float *BKE_key_evaluate_object(Scene *scene, Object *ob, int *r_totelem) +{ + return BKE_key_evaluate_object_ex(scene, ob, r_totelem, NULL, 0); +} + Key *BKE_key_from_object(Object *ob) { if (ob == NULL) return NULL; diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c index 697ccdc49a4..fef4c7ccedb 100644 --- a/source/blender/modifiers/intern/MOD_shapekey.c +++ b/source/blender/modifiers/intern/MOD_shapekey.c @@ -55,17 +55,12 @@ static void deformVerts(ModifierData *md, Object *ob, ModifierApplyFlag UNUSED(flag)) { Key *key = BKE_key_from_object(ob); - float (*deformedVerts)[3]; if (key && key->block.first) { int deformedVerts_tot; - deformedVerts = (float(*)[3])BKE_key_evaluate_object(md->scene, ob, &deformedVerts_tot); - if (deformedVerts) { - if (numVerts == deformedVerts_tot) { - memcpy(vertexCos, deformedVerts, sizeof(float) * 3 * numVerts); - } - MEM_freeN(deformedVerts); - } + BKE_key_evaluate_object_ex(md->scene, ob, &deformedVerts_tot, + (float *)vertexCos, sizeof(*vertexCos) * numVerts); + } } |