Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/key.c
| Context not available. | |||||
| return BKE_key_evaluate_object_ex(ob, r_totelem, NULL, 0); | return BKE_key_evaluate_object_ex(ob, r_totelem, NULL, 0); | ||||
| } | } | ||||
| int BKE_key_count_keyblocks_elements_shapenr(const Key *key, const int shapenr) | |||||
| { | |||||
| int result = 0; | |||||
| int index = 0; | |||||
| LISTBASE_FOREACH (KeyBlock *, block, &key->block) { | |||||
| if (shapenr < 0 || index == shapenr) { | |||||
| result += block->totelem; | |||||
| } | |||||
| ++index; | |||||
| } | |||||
| return result; | |||||
| } | |||||
| int BKE_key_count_keyblocks_elements(const Key *key) | |||||
| { | |||||
| return BKE_key_count_keyblocks_elements_shapenr(key, -1); | |||||
| } | |||||
| int BKE_key_count_keyblocks_sizes_shapenr(const Key *key, const int shapenr) | |||||
| { | |||||
| return BKE_key_count_keyblocks_elements_shapenr(key, shapenr) * key->elemsize; | |||||
| } | |||||
| int BKE_key_count_keyblocks_sizes(const Key *key) | |||||
| { | |||||
| return BKE_key_count_keyblocks_sizes_shapenr(key, -1); | |||||
| } | |||||
| void BKE_key_get_keyblocks_data_shapenr(const Key *key, float (*arr)[3], const int shapenr) | |||||
| { | |||||
| uint8_t *elements = (uint8_t *)arr; | |||||
| int index = 0; | |||||
| LISTBASE_FOREACH (KeyBlock *, block, &key->block) { | |||||
| if (shapenr < 0 || index == shapenr) { | |||||
| const int block_elem_len = block->totelem * key->elemsize; | |||||
| memcpy(elements, block->data, block_elem_len); | |||||
| elements += block_elem_len; | |||||
| } | |||||
| ++index; | |||||
campbellbarton: Follow naming conventions of similar functions, use `_with_mat4` suffix. | |||||
Done Inline ActionsThis only works for elemsize 3 shape-keys, so it wont work for curves. Remaining TODO's should be noted in comments. campbellbarton: This only works for elemsize 3 shape-keys, so it wont work for curves.
Remaining TODO's should… | |||||
| } | |||||
| } | |||||
Done Inline ActionsUse const for source data. campbellbarton: Use const for source data. | |||||
| void BKE_key_get_keyblocks_data(const Key *key, float (*arr)[3]) | |||||
| { | |||||
| BKE_key_get_keyblocks_data_shapenr(key, arr, -1); | |||||
Done Inline ActionsUse an BLI_assert(0) here if it should be unreachable. campbellbarton: Use an `BLI_assert(0)` here if it should be unreachable. | |||||
| } | |||||
| void BKE_key_set_keyblocks_data_with_mat4(Key *key, | |||||
| const int shapenr, | |||||
| const float (*vertices)[3], | |||||
| const float mat[4][4]) | |||||
| { | |||||
| if (key->elemsize != 3 * sizeof(float)) { | |||||
| BLI_assert(!"Invalid elemsize"); | |||||
| return; | |||||
Done Inline ActionsUse const for source data. campbellbarton: Use const for source data. | |||||
| } | |||||
| int index = 0; | |||||
| const float(*elements)[3] = vertices; | |||||
| LISTBASE_FOREACH (KeyBlock *, block, &key->block) { | |||||
| if (shapenr < 0 || index == shapenr) { | |||||
| const int block_elem_len = block->totelem; | |||||
| float(*block_data)[3] = (float(*)[3])block->data; | |||||
| for (int data_offset = 0; data_offset < block_elem_len; ++data_offset) { | |||||
| float *srcdata = (float *)(elements + data_offset); | |||||
| float *dstdata = (float *)(block_data + data_offset); | |||||
| mul_v3_m4v3(dstdata, mat, srcdata); | |||||
| } | |||||
| elements += block_elem_len; | |||||
| } | |||||
| ++index; | |||||
| } | |||||
| } | |||||
| void BKE_key_set_curve_keyblocks_data_with_mat4(Key *key, | |||||
| const ListBase *nurb, | |||||
| const int shapenr, | |||||
| const void *data, | |||||
| const float mat[4][4]) | |||||
| { | |||||
| int index = 0; | |||||
| const uint8_t *elements = data; | |||||
| LISTBASE_FOREACH (KeyBlock *, block, &key->block) { | |||||
| if (shapenr < 0 || index == shapenr) { | |||||
| const int block_elem_size = block->totelem * key->elemsize; | |||||
| BKE_keyblock_curve_data_transform(nurb, mat, elements, block->data); | |||||
| elements += block_elem_size; | |||||
| } | |||||
| ++index; | |||||
| } | |||||
| } | |||||
| void BKE_key_set_keyblocks_data(Key *key, const int shapenr, const void *data) | |||||
| { | |||||
| int index = 0; | |||||
| const uint8_t *elements = data; | |||||
| LISTBASE_FOREACH (KeyBlock *, block, &key->block) { | |||||
| if (shapenr < 0 || index == shapenr) { | |||||
| const int block_elem_size = block->totelem * key->elemsize; | |||||
| memcpy(block->data, elements, block_elem_size); | |||||
| elements += block_elem_size; | |||||
| } | |||||
| ++index; | |||||
| } | |||||
| } | |||||
| bool BKE_key_idtype_support(const short id_type) | bool BKE_key_idtype_support(const short id_type) | ||||
| { | { | ||||
| switch (id_type) { | switch (id_type) { | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_curve_data_transform(const ListBase *nurb, const float mat[4][4], const void *input, void* output) | |||||
| { | |||||
| const float *in = input; | |||||
| float *out = output; | |||||
| for (Nurb *nu = nurb->first; nu; nu = nu->next) { | |||||
| if (nu->bezt) { | |||||
| for (int a = nu->pntsu; a; a--) { | |||||
| for (int i = 0; i < 3; i++) { | |||||
| mul_v3_m4v3(&out[i * 3], mat, &in[i * 3]); | |||||
| } | |||||
| out[9] = in[9]; | |||||
| out[10] = in[10]; | |||||
| in += KEYELEM_FLOAT_LEN_BEZTRIPLE; | |||||
| out += KEYELEM_FLOAT_LEN_BEZTRIPLE; | |||||
| } | |||||
| } | |||||
| else { | |||||
| for (int a = nu->pntsu * nu->pntsv; a; a--) { | |||||
| mul_v3_m4v3(out, mat, in); | |||||
| out[3] = in[3]; | |||||
| out[4] = in[4]; | |||||
| in += KEYELEM_FLOAT_LEN_BPOINT; | |||||
| out += KEYELEM_FLOAT_LEN_BPOINT; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| void BKE_keyblock_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb) | void BKE_keyblock_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb) | ||||
| { | { | ||||
| int tot; | int tot; | ||||
| Context not available. | |||||
Follow naming conventions of similar functions, use _with_mat4 suffix.