Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/key.cc
- This file was moved from source/blender/blenkernel/intern/key.c.
| Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | static void shapekey_copy_data(Main *UNUSED(bmain), | ||||
| const ID *id_src, | const ID *id_src, | ||||
| const int UNUSED(flag)) | const int UNUSED(flag)) | ||||
| { | { | ||||
| Key *key_dst = (Key *)id_dst; | Key *key_dst = (Key *)id_dst; | ||||
| const Key *key_src = (const Key *)id_src; | const Key *key_src = (const Key *)id_src; | ||||
| BLI_duplicatelist(&key_dst->block, &key_src->block); | BLI_duplicatelist(&key_dst->block, &key_src->block); | ||||
| KeyBlock *kb_dst, *kb_src; | KeyBlock *kb_dst, *kb_src; | ||||
| for (kb_src = key_src->block.first, kb_dst = key_dst->block.first; kb_dst; | for (kb_src = static_cast<KeyBlock *>(key_src->block.first), | ||||
| kb_dst = static_cast<KeyBlock *>(key_dst->block.first); | |||||
| kb_dst; | |||||
| kb_src = kb_src->next, kb_dst = kb_dst->next) { | kb_src = kb_src->next, kb_dst = kb_dst->next) { | ||||
| if (kb_dst->data) { | if (kb_dst->data) { | ||||
| kb_dst->data = MEM_dupallocN(kb_dst->data); | kb_dst->data = MEM_dupallocN(kb_dst->data); | ||||
| } | } | ||||
| if (kb_src == key_src->refkey) { | if (kb_src == key_src->refkey) { | ||||
| key_dst->refkey = kb_dst; | key_dst->refkey = kb_dst; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void shapekey_free_data(ID *id) | static void shapekey_free_data(ID *id) | ||||
| { | { | ||||
| Key *key = (Key *)id; | Key *key = (Key *)id; | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| while ((kb = BLI_pophead(&key->block))) { | while ((kb = static_cast<KeyBlock *>(BLI_pophead(&key->block)))) { | ||||
| if (kb->data) { | if (kb->data) { | ||||
| MEM_freeN(kb->data); | MEM_freeN(kb->data); | ||||
| } | } | ||||
| MEM_freeN(kb); | MEM_freeN(kb); | ||||
| } | } | ||||
| } | } | ||||
| static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data) | static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data) | ||||
| { | { | ||||
| Key *key = (Key *)id; | Key *key = (Key *)id; | ||||
| BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK); | BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK); | ||||
| } | } | ||||
| static ID **shapekey_owner_pointer_get(ID *id) | static ID **shapekey_owner_pointer_get(ID *id) | ||||
| { | { | ||||
| Key *key = (Key *)id; | Key *key = (Key *)id; | ||||
| BLI_assert(key->from != NULL); | BLI_assert(key->from != nullptr); | ||||
| BLI_assert(BKE_key_from_id(key->from) == key); | BLI_assert(BKE_key_from_id(key->from) == key); | ||||
| return &key->from; | return &key->from; | ||||
| } | } | ||||
| static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address) | static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address) | ||||
| { | { | ||||
| Key *key = (Key *)id; | Key *key = (Key *)id; | ||||
| const bool is_undo = BLO_write_is_undo(writer); | const bool is_undo = BLO_write_is_undo(writer); | ||||
| /* write LibData */ | /* write LibData */ | ||||
| BLO_write_id_struct(writer, Key, id_address, &key->id); | BLO_write_id_struct(writer, Key, id_address, &key->id); | ||||
| BKE_id_blend_write(writer, &key->id); | BKE_id_blend_write(writer, &key->id); | ||||
| if (key->adt) { | if (key->adt) { | ||||
| BKE_animdata_blend_write(writer, key->adt); | BKE_animdata_blend_write(writer, key->adt); | ||||
| } | } | ||||
| /* direct data */ | /* direct data */ | ||||
| LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { | LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { | ||||
| KeyBlock tmp_kb = *kb; | KeyBlock tmp_kb = *kb; | ||||
| /* Do not store actual geometry data in case this is a library override ID. */ | /* Do not store actual geometry data in case this is a library override ID. */ | ||||
| if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) { | if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) { | ||||
| tmp_kb.totelem = 0; | tmp_kb.totelem = 0; | ||||
| tmp_kb.data = NULL; | tmp_kb.data = nullptr; | ||||
| } | } | ||||
| BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb); | BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb); | ||||
| if (tmp_kb.data != NULL) { | if (tmp_kb.data != nullptr) { | ||||
| BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data); | BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */ | /* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */ | ||||
| #define IPO_FLOAT 4 | #define IPO_FLOAT 4 | ||||
| #define IPO_BEZTRIPLE 100 | #define IPO_BEZTRIPLE 100 | ||||
| #define IPO_BPOINT 101 | #define IPO_BPOINT 101 | ||||
| static void switch_endian_keyblock(Key *key, KeyBlock *kb) | static void switch_endian_keyblock(Key *key, KeyBlock *kb) | ||||
| { | { | ||||
| int elemsize = key->elemsize; | int elemsize = key->elemsize; | ||||
| char *data = kb->data; | char *data = static_cast<char *>(kb->data); | ||||
| for (int a = 0; a < kb->totelem; a++) { | for (int a = 0; a < kb->totelem; a++) { | ||||
| const char *cp = key->elemstr; | const char *cp = key->elemstr; | ||||
| char *poin = data; | char *poin = data; | ||||
| while (cp[0]) { /* cp[0] == amount */ | while (cp[0]) { /* cp[0] == amount */ | ||||
| switch (cp[1]) { /* cp[1] = type */ | switch (cp[1]) { /* cp[1] = type */ | ||||
| case IPO_FLOAT: | case IPO_FLOAT: | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| static void shapekey_blend_read_expand(BlendExpander *expander, ID *id) | static void shapekey_blend_read_expand(BlendExpander *expander, ID *id) | ||||
| { | { | ||||
| Key *key = (Key *)id; | Key *key = (Key *)id; | ||||
| BLO_expand(expander, key->ipo); /* XXX deprecated - old animation system */ | BLO_expand(expander, key->ipo); /* XXX deprecated - old animation system */ | ||||
| } | } | ||||
| IDTypeInfo IDType_ID_KE = { | IDTypeInfo IDType_ID_KE = { | ||||
| .id_code = ID_KE, | /* id_code */ ID_KE, | ||||
| .id_filter = FILTER_ID_KE, | /* id_filter */ FILTER_ID_KE, | ||||
| .main_listbase_index = INDEX_ID_KE, | /* main_listbase_index */ INDEX_ID_KE, | ||||
| .struct_size = sizeof(Key), | /* struct_size */ sizeof(Key), | ||||
| .name = "Key", | /* name */ "Key", | ||||
| .name_plural = "shape_keys", | /* name_plural */ "shape_keys", | ||||
| .translation_context = BLT_I18NCONTEXT_ID_SHAPEKEY, | /* translation_context */ BLT_I18NCONTEXT_ID_SHAPEKEY, | ||||
| .flags = IDTYPE_FLAGS_NO_LIBLINKING, | /* flags */ IDTYPE_FLAGS_NO_LIBLINKING, | ||||
| .asset_type_info = NULL, | /* asset_type_info */ nullptr, | ||||
| .init_data = NULL, | /* init_data */ nullptr, | ||||
| .copy_data = shapekey_copy_data, | /* copy_data */ shapekey_copy_data, | ||||
| .free_data = shapekey_free_data, | /* free_data */ shapekey_free_data, | ||||
| .make_local = NULL, | /* make_local */ nullptr, | ||||
| .foreach_id = shapekey_foreach_id, | /* foreach_id */ shapekey_foreach_id, | ||||
| .foreach_cache = NULL, | /* foreach_cache */ nullptr, | ||||
| .foreach_path = NULL, | /* foreach_path */ nullptr, | ||||
| /* A bit weird, due to shape-keys not being strictly speaking embedded data... But they also | /* A bit weird, due to shape-keys not being strictly speaking embedded data... But they also | ||||
| * share a lot with those (non linkable, only ever used by one owner ID, etc.). */ | * share a lot with those (non linkable, only ever used by one owner ID, etc.). */ | ||||
| .owner_pointer_get = shapekey_owner_pointer_get, | /* owner_pointer_get */ shapekey_owner_pointer_get, | ||||
| .blend_write = shapekey_blend_write, | /* blend_write */ shapekey_blend_write, | ||||
| .blend_read_data = shapekey_blend_read_data, | /* blend_read_data */ shapekey_blend_read_data, | ||||
| .blend_read_lib = shapekey_blend_read_lib, | /* blend_read_lib */ shapekey_blend_read_lib, | ||||
| .blend_read_expand = shapekey_blend_read_expand, | /* blend_read_expand */ shapekey_blend_read_expand, | ||||
| .blend_read_undo_preserve = NULL, | /* blend_read_undo_preserve */ nullptr, | ||||
| .lib_override_apply_post = NULL, | /* lib_override_apply_post */ nullptr, | ||||
| }; | }; | ||||
| #define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */ | #define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */ | ||||
| #define KEY_MODE_BPOINT 1 | #define KEY_MODE_BPOINT 1 | ||||
| #define KEY_MODE_BEZTRIPLE 2 | #define KEY_MODE_BEZTRIPLE 2 | ||||
| /* Internal use only. */ | /* Internal use only. */ | ||||
| typedef struct WeightsArrayCache { | typedef struct WeightsArrayCache { | ||||
| int num_defgroup_weights; | int num_defgroup_weights; | ||||
| float **defgroup_weights; | float **defgroup_weights; | ||||
| } WeightsArrayCache; | } WeightsArrayCache; | ||||
| void BKE_key_free_data(Key *key) | void BKE_key_free_data(Key *key) | ||||
| { | { | ||||
| shapekey_free_data(&key->id); | shapekey_free_data(&key->id); | ||||
| } | } | ||||
| void BKE_key_free_nolib(Key *key) | void BKE_key_free_nolib(Key *key) | ||||
| { | { | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| while ((kb = BLI_pophead(&key->block))) { | while ((kb = static_cast<KeyBlock *>(BLI_pophead(&key->block)))) { | ||||
| if (kb->data) { | if (kb->data) { | ||||
| MEM_freeN(kb->data); | MEM_freeN(kb->data); | ||||
| } | } | ||||
| MEM_freeN(kb); | MEM_freeN(kb); | ||||
| } | } | ||||
| } | } | ||||
| Key *BKE_key_add(Main *bmain, ID *id) /* common function */ | Key *BKE_key_add(Main *bmain, ID *id) /* common function */ | ||||
| { | { | ||||
| Key *key; | Key *key; | ||||
| char *el; | char *el; | ||||
| key = BKE_id_new(bmain, ID_KE, "Key"); | key = static_cast<Key *>(BKE_id_new(bmain, ID_KE, "Key")); | ||||
| key->type = KEY_NORMAL; | key->type = KEY_NORMAL; | ||||
| key->from = id; | key->from = id; | ||||
| key->uidgen = 1; | key->uidgen = 1; | ||||
| /* XXX the code here uses some defines which will soon be deprecated... */ | /* XXX the code here uses some defines which will soon be deprecated... */ | ||||
| switch (GS(id->name)) { | switch (GS(id->name)) { | ||||
| Show All 36 Lines | |||||
| } | } | ||||
| void BKE_key_sort(Key *key) | void BKE_key_sort(Key *key) | ||||
| { | { | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| KeyBlock *kb2; | KeyBlock *kb2; | ||||
| /* locate the key which is out of position */ | /* locate the key which is out of position */ | ||||
| for (kb = key->block.first; kb; kb = kb->next) { | for (kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next) { | ||||
| if ((kb->next) && (kb->pos > kb->next->pos)) { | if ((kb->next) && (kb->pos > kb->next->pos)) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* if we find a key, move it */ | /* if we find a key, move it */ | ||||
| if (kb) { | if (kb) { | ||||
| kb = kb->next; /* next key is the out-of-order one */ | kb = kb->next; /* next key is the out-of-order one */ | ||||
| BLI_remlink(&key->block, kb); | BLI_remlink(&key->block, kb); | ||||
| /* find the right location and insert before */ | /* find the right location and insert before */ | ||||
| for (kb2 = key->block.first; kb2; kb2 = kb2->next) { | for (kb2 = static_cast<KeyBlock *>(key->block.first); kb2; kb2 = kb2->next) { | ||||
| if (kb2->pos > kb->pos) { | if (kb2->pos > kb->pos) { | ||||
| BLI_insertlinkafter(&key->block, kb2->prev, kb); | BLI_insertlinkafter(&key->block, kb2->prev, kb); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* new rule; first key is refkey, this to match drawing channels... */ | /* new rule; first key is refkey, this to match drawing channels... */ | ||||
| key->refkey = key->block.first; | key->refkey = static_cast<KeyBlock *>(key->block.first); | ||||
| } | } | ||||
| /**************** do the key ****************/ | /**************** do the key ****************/ | ||||
| void key_curve_position_weights(float t, float data[4], int type) | void key_curve_position_weights(float t, float data[4], int type) | ||||
| { | { | ||||
| float t2, t3, fc; | float t2, t3, fc; | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
| static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl) | static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl) | ||||
| { | { | ||||
| /* return 1 means k[2] is the position, return 0 means interpolate */ | /* return 1 means k[2] is the position, return 0 means interpolate */ | ||||
| KeyBlock *k1, *firstkey; | KeyBlock *k1, *firstkey; | ||||
| float d, dpos, ofs = 0, lastpos; | float d, dpos, ofs = 0, lastpos; | ||||
| short bsplinetype; | short bsplinetype; | ||||
| firstkey = lb->first; | firstkey = static_cast<KeyBlock *>(lb->first); | ||||
| k1 = lb->last; | k1 = static_cast<KeyBlock *>(lb->last); | ||||
| lastpos = k1->pos; | lastpos = k1->pos; | ||||
| dpos = lastpos - firstkey->pos; | dpos = lastpos - firstkey->pos; | ||||
| if (fac < firstkey->pos) { | if (fac < firstkey->pos) { | ||||
| fac = firstkey->pos; | fac = firstkey->pos; | ||||
| } | } | ||||
| else if (fac > k1->pos) { | else if (fac > k1->pos) { | ||||
| fac = k1->pos; | fac = k1->pos; | ||||
| } | } | ||||
| k1 = k[0] = k[1] = k[2] = k[3] = firstkey; | k1 = k[0] = k[1] = k[2] = k[3] = firstkey; | ||||
| t[0] = t[1] = t[2] = t[3] = k1->pos; | t[0] = t[1] = t[2] = t[3] = k1->pos; | ||||
| /* if (fac < 0.0 || fac > 1.0) return 1; */ | /* if (fac < 0.0 || fac > 1.0) return 1; */ | ||||
| if (k1->next == NULL) { | if (k1->next == nullptr) { | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| if (cycl) { /* pre-sort */ | if (cycl) { /* pre-sort */ | ||||
| k[2] = k1->next; | k[2] = k1->next; | ||||
| k[3] = k[2]->next; | k[3] = k[2]->next; | ||||
| if (k[3] == NULL) { | if (k[3] == nullptr) { | ||||
| k[3] = k1; | k[3] = k1; | ||||
| } | } | ||||
| while (k1) { | while (k1) { | ||||
| if (k1->next == NULL) { | if (k1->next == nullptr) { | ||||
| k[0] = k1; | k[0] = k1; | ||||
| } | } | ||||
| k1 = k1->next; | k1 = k1->next; | ||||
| } | } | ||||
| /* k1 = k[1]; */ /* UNUSED */ | /* k1 = k[1]; */ /* UNUSED */ | ||||
| t[0] = k[0]->pos; | t[0] = k[0]->pos; | ||||
| t[1] += dpos; | t[1] += dpos; | ||||
| t[2] = k[2]->pos + dpos; | t[2] = k[2]->pos + dpos; | ||||
| t[3] = k[3]->pos + dpos; | t[3] = k[3]->pos + dpos; | ||||
| fac += dpos; | fac += dpos; | ||||
| ofs = dpos; | ofs = dpos; | ||||
| if (k[3] == k[1]) { | if (k[3] == k[1]) { | ||||
| t[3] += dpos; | t[3] += dpos; | ||||
| ofs = 2.0f * dpos; | ofs = 2.0f * dpos; | ||||
| } | } | ||||
| if (fac < t[1]) { | if (fac < t[1]) { | ||||
| fac += dpos; | fac += dpos; | ||||
| } | } | ||||
| k1 = k[3]; | k1 = k[3]; | ||||
| } | } | ||||
| else { /* pre-sort */ | else { /* pre-sort */ | ||||
| k[2] = k1->next; | k[2] = k1->next; | ||||
| t[2] = k[2]->pos; | t[2] = k[2]->pos; | ||||
| k[3] = k[2]->next; | k[3] = k[2]->next; | ||||
| if (k[3] == NULL) { | if (k[3] == nullptr) { | ||||
| k[3] = k[2]; | k[3] = k[2]; | ||||
| } | } | ||||
| t[3] = k[3]->pos; | t[3] = k[3]->pos; | ||||
| k1 = k[3]; | k1 = k[3]; | ||||
| } | } | ||||
| while (t[2] < fac) { /* find correct location */ | while (t[2] < fac) { /* find correct location */ | ||||
| if (k1->next == NULL) { | if (k1->next == nullptr) { | ||||
| if (cycl) { | if (cycl) { | ||||
| k1 = firstkey; | k1 = firstkey; | ||||
| ofs += dpos; | ofs += dpos; | ||||
| } | } | ||||
| else if (t[2] == t[3]) { | else if (t[2] == t[3]) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (GS(key->from->name) == ID_ME) { | ||||
| BMIter iter; | BMIter iter; | ||||
| float(*co)[3]; | float(*co)[3]; | ||||
| int a; | int a; | ||||
| me = (Mesh *)key->from; | me = (Mesh *)key->from; | ||||
| if (me->edit_mesh && me->edit_mesh->bm->totvert == kb->totelem) { | if (me->edit_mesh && me->edit_mesh->bm->totvert == kb->totelem) { | ||||
| a = 0; | a = 0; | ||||
| co = MEM_mallocN(sizeof(float[3]) * me->edit_mesh->bm->totvert, "key_block_get_data"); | co = static_cast<float(*)[3]>( | ||||
| MEM_mallocN(sizeof(float[3]) * me->edit_mesh->bm->totvert, "key_block_get_data")); | |||||
| BM_ITER_MESH (eve, &iter, me->edit_mesh->bm, BM_VERTS_OF_MESH) { | BM_ITER_MESH (eve, &iter, me->edit_mesh->bm, BM_VERTS_OF_MESH) { | ||||
| copy_v3_v3(co[a], eve->co); | copy_v3_v3(co[a], eve->co); | ||||
| a++; | a++; | ||||
| } | } | ||||
| *freedata = (char *)co; | *freedata = (char *)co; | ||||
| return (char *)co; | return (char *)co; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| *freedata = NULL; | *freedata = nullptr; | ||||
| return kb->data; | return static_cast<char *>(kb->data); | ||||
| } | } | ||||
| /* currently only the first value of 'ofs' may be set. */ | /* currently only the first value of 'ofs' may be set. */ | ||||
| static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs, int *step) | static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs, int *step) | ||||
| { | { | ||||
| if (key->from == NULL) { | if (key->from == nullptr) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| *step = 1; | *step = 1; | ||||
| switch (GS(key->from->name)) { | switch (GS(key->from->name)) { | ||||
| case ID_ME: | case ID_ME: | ||||
| *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | ||||
| ▲ Show 20 Lines • Show All 166 Lines • ▼ Show 20 Lines | static void cp_cu_key(Curve *cu, | ||||
| const int start, | const int start, | ||||
| int end, | int end, | ||||
| char *out, | char *out, | ||||
| const int tot) | const int tot) | ||||
| { | { | ||||
| Nurb *nu; | Nurb *nu; | ||||
| int a, step, a1, a2; | int a, step, a1, a2; | ||||
| for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { | for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) { | ||||
| if (nu->bp) { | if (nu->bp) { | ||||
| step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | ||||
| a1 = max_ii(a, start); | a1 = max_ii(a, start); | ||||
| a2 = min_ii(a + step, end); | a2 = min_ii(a + step, end); | ||||
| if (a1 < a2) { | if (a1 < a2) { | ||||
| cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT); | cp_key(a1, a2, tot, out, key, actkb, kb, nullptr, KEY_MODE_BPOINT); | ||||
| } | } | ||||
| } | } | ||||
| else if (nu->bezt) { | else if (nu->bezt) { | ||||
| step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | ||||
| /* exception because keys prefer to work with complete blocks */ | /* exception because keys prefer to work with complete blocks */ | ||||
| a1 = max_ii(a, start); | a1 = max_ii(a, start); | ||||
| a2 = min_ii(a + step, end); | a2 = min_ii(a + step, end); | ||||
| if (a1 < a2) { | if (a1 < a2) { | ||||
| cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE); | cp_key(a1, a2, tot, out, key, actkb, kb, nullptr, KEY_MODE_BEZTRIPLE); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| step = 0; | step = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 26 Lines | static void key_evaluate_relative(const int start, | ||||
| elemstr[0] = 1; /* nr of ipofloats */ | elemstr[0] = 1; /* nr of ipofloats */ | ||||
| elemstr[1] = IPO_BEZTRIPLE; | elemstr[1] = IPO_BEZTRIPLE; | ||||
| elemstr[2] = 0; | elemstr[2] = 0; | ||||
| /* just here, not above! */ | /* just here, not above! */ | ||||
| elemsize = key->elemsize * step; | elemsize = key->elemsize * step; | ||||
| /* step 1 init */ | /* step 1 init */ | ||||
| cp_key(start, end, tot, basispoin, key, actkb, key->refkey, NULL, mode); | cp_key(start, end, tot, basispoin, key, actkb, key->refkey, nullptr, mode); | ||||
| /* step 2: do it */ | /* step 2: do it */ | ||||
| for (kb = key->block.first, keyblock_index = 0; kb; kb = kb->next, keyblock_index++) { | for (kb = static_cast<KeyBlock *>(key->block.first), keyblock_index = 0; kb; | ||||
| kb = kb->next, keyblock_index++) { | |||||
| if (kb != key->refkey) { | if (kb != key->refkey) { | ||||
| float icuval = kb->curval; | float icuval = kb->curval; | ||||
| /* only with value, and no difference allowed */ | /* only with value, and no difference allowed */ | ||||
| if (!(kb->flag & KEYBLOCK_MUTE) && icuval != 0.0f && kb->totelem == tot) { | if (!(kb->flag & KEYBLOCK_MUTE) && icuval != 0.0f && kb->totelem == tot) { | ||||
| KeyBlock *refb; | KeyBlock *refb; | ||||
| float weight, | float weight, | ||||
| *weights = per_keyblock_weights ? per_keyblock_weights[keyblock_index] : NULL; | *weights = per_keyblock_weights ? per_keyblock_weights[keyblock_index] : nullptr; | ||||
| char *freefrom = NULL; | char *freefrom = nullptr; | ||||
| /* reference now can be any block */ | /* reference now can be any block */ | ||||
| refb = BLI_findlink(&key->block, kb->relative); | refb = static_cast<KeyBlock *>(BLI_findlink(&key->block, kb->relative)); | ||||
| if (refb == NULL) { | if (refb == nullptr) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| poin = basispoin; | poin = basispoin; | ||||
| from = key_block_get_data(key, actkb, kb, &freefrom); | from = key_block_get_data(key, actkb, kb, &freefrom); | ||||
| /* For meshes, use the original values instead of the bmesh values to | /* For meshes, use the original values instead of the bmesh values to | ||||
| * maintain a constant offset. */ | * maintain a constant offset. */ | ||||
| reffrom = refb->data; | reffrom = static_cast<char *>(refb->data); | ||||
| poin += start * poinsize; | poin += start * poinsize; | ||||
| reffrom += key->elemsize * start; /* key elemsize yes! */ | reffrom += key->elemsize * start; /* key elemsize yes! */ | ||||
| from += key->elemsize * start; | from += key->elemsize * start; | ||||
| for (b = start; b < end; b += step) { | for (b = start; b < end; b += step) { | ||||
| weight = weights ? (*weights * icuval) : icuval; | weight = weights ? (*weights * icuval) : icuval; | ||||
| ▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | while (cp[0]) { /* (cp[0] == amount) */ | ||||
| (float *)k1, | (float *)k1, | ||||
| (float *)k2, | (float *)k2, | ||||
| (float *)k3, | (float *)k3, | ||||
| (float *)k4, | (float *)k4, | ||||
| t); | t); | ||||
| break; | break; | ||||
| case IPO_BEZTRIPLE: | case IPO_BEZTRIPLE: | ||||
| flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE, | flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE, | ||||
| (void *)poin, | (float *)poin, | ||||
| (void *)k1, | (float *)k1, | ||||
| (void *)k2, | (float *)k2, | ||||
| (void *)k3, | (float *)k3, | ||||
| (void *)k4, | (float *)k4, | ||||
| t); | t); | ||||
| break; | break; | ||||
| default: | default: | ||||
| /* should never happen */ | /* should never happen */ | ||||
| if (freek1) { | if (freek1) { | ||||
| MEM_freeN(freek1); | MEM_freeN(freek1); | ||||
| } | } | ||||
| if (freek2) { | if (freek2) { | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | static void do_key(const int start, | ||||
| } | } | ||||
| if (freek4) { | if (freek4) { | ||||
| MEM_freeN(freek4); | MEM_freeN(freek4); | ||||
| } | } | ||||
| } | } | ||||
| static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache) | static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache) | ||||
| { | { | ||||
| const MDeformVert *dvert = NULL; | const MDeformVert *dvert = nullptr; | ||||
| BMEditMesh *em = NULL; | BMEditMesh *em = nullptr; | ||||
| BMIter iter; | BMIter iter; | ||||
| BMVert *eve; | BMVert *eve; | ||||
| int totvert = 0, defgrp_index = 0; | int totvert = 0, defgrp_index = 0; | ||||
| /* no vgroup string set? */ | /* no vgroup string set? */ | ||||
| if (vgroup[0] == 0) { | if (vgroup[0] == 0) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| /* gather dvert and totvert */ | /* gather dvert and totvert */ | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| dvert = BKE_mesh_deform_verts(me); | dvert = BKE_mesh_deform_verts(me); | ||||
| totvert = me->totvert; | totvert = me->totvert; | ||||
| if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert) { | if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert) { | ||||
| em = me->edit_mesh; | em = me->edit_mesh; | ||||
| } | } | ||||
| } | } | ||||
| else if (ob->type == OB_LATTICE) { | else if (ob->type == OB_LATTICE) { | ||||
| Lattice *lt = ob->data; | Lattice *lt = static_cast<Lattice *>(ob->data); | ||||
| dvert = lt->dvert; | dvert = lt->dvert; | ||||
| totvert = lt->pntsu * lt->pntsv * lt->pntsw; | totvert = lt->pntsu * lt->pntsv * lt->pntsw; | ||||
| } | } | ||||
| if (dvert == NULL) { | if (dvert == nullptr) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| /* find the group (weak loop-in-loop) */ | /* find the group (weak loop-in-loop) */ | ||||
| defgrp_index = BKE_object_defgroup_name_index(ob, vgroup); | defgrp_index = BKE_object_defgroup_name_index(ob, vgroup); | ||||
| if (defgrp_index != -1) { | if (defgrp_index != -1) { | ||||
| float *weights; | float *weights; | ||||
| if (cache) { | if (cache) { | ||||
| if (cache->defgroup_weights == NULL) { | if (cache->defgroup_weights == nullptr) { | ||||
| int num_defgroup = BKE_object_defgroup_count(ob); | int num_defgroup = BKE_object_defgroup_count(ob); | ||||
| cache->defgroup_weights = MEM_callocN(sizeof(*cache->defgroup_weights) * num_defgroup, | cache->defgroup_weights = static_cast<float **>(MEM_callocN( | ||||
| "cached defgroup weights"); | sizeof(*cache->defgroup_weights) * num_defgroup, "cached defgroup weights")); | ||||
| cache->num_defgroup_weights = num_defgroup; | cache->num_defgroup_weights = num_defgroup; | ||||
| } | } | ||||
| if (cache->defgroup_weights[defgrp_index]) { | if (cache->defgroup_weights[defgrp_index]) { | ||||
| return cache->defgroup_weights[defgrp_index]; | return cache->defgroup_weights[defgrp_index]; | ||||
| } | } | ||||
| } | } | ||||
| weights = MEM_mallocN(totvert * sizeof(float), "weights"); | weights = static_cast<float *>(MEM_mallocN(totvert * sizeof(float), "weights")); | ||||
| if (em) { | if (em) { | ||||
| int i; | int i; | ||||
| const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); | const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); | ||||
| BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { | BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) { | ||||
| dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); | dvert = static_cast<const MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset)); | ||||
| weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); | weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (int i = 0; i < totvert; i++, dvert++) { | for (int i = 0; i < totvert; i++, dvert++) { | ||||
| weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); | weights[i] = BKE_defvert_find_weight(dvert, defgrp_index); | ||||
| } | } | ||||
| } | } | ||||
| if (cache) { | if (cache) { | ||||
| cache->defgroup_weights[defgrp_index] = weights; | cache->defgroup_weights[defgrp_index] = weights; | ||||
| } | } | ||||
| return weights; | return weights; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| static float **keyblock_get_per_block_weights(Object *ob, Key *key, WeightsArrayCache *cache) | static float **keyblock_get_per_block_weights(Object *ob, Key *key, WeightsArrayCache *cache) | ||||
| { | { | ||||
| KeyBlock *keyblock; | KeyBlock *keyblock; | ||||
| float **per_keyblock_weights; | float **per_keyblock_weights; | ||||
| int keyblock_index; | int keyblock_index; | ||||
| per_keyblock_weights = MEM_mallocN(sizeof(*per_keyblock_weights) * key->totkey, | per_keyblock_weights = static_cast<float **>( | ||||
| "per keyblock weights"); | MEM_mallocN(sizeof(*per_keyblock_weights) * key->totkey, "per keyblock weights")); | ||||
| for (keyblock = key->block.first, keyblock_index = 0; keyblock; | for (keyblock = static_cast<KeyBlock *>(key->block.first), keyblock_index = 0; keyblock; | ||||
| keyblock = keyblock->next, keyblock_index++) { | keyblock = keyblock->next, keyblock_index++) { | ||||
| per_keyblock_weights[keyblock_index] = get_weights_array(ob, keyblock->vgroup, cache); | per_keyblock_weights[keyblock_index] = get_weights_array(ob, keyblock->vgroup, cache); | ||||
| } | } | ||||
| return per_keyblock_weights; | return per_keyblock_weights; | ||||
| } | } | ||||
| static void keyblock_free_per_block_weights(Key *key, | static void keyblock_free_per_block_weights(Key *key, | ||||
| float **per_keyblock_weights, | float **per_keyblock_weights, | ||||
| WeightsArrayCache *cache) | WeightsArrayCache *cache) | ||||
| { | { | ||||
| int a; | int a; | ||||
| if (cache) { | if (cache) { | ||||
| if (cache->num_defgroup_weights) { | if (cache->num_defgroup_weights) { | ||||
| for (a = 0; a < cache->num_defgroup_weights; a++) { | for (a = 0; a < cache->num_defgroup_weights; a++) { | ||||
| if (cache->defgroup_weights[a]) { | if (cache->defgroup_weights[a]) { | ||||
| MEM_freeN(cache->defgroup_weights[a]); | MEM_freeN(cache->defgroup_weights[a]); | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(cache->defgroup_weights); | MEM_freeN(cache->defgroup_weights); | ||||
| } | } | ||||
| cache->defgroup_weights = NULL; | cache->defgroup_weights = nullptr; | ||||
| } | } | ||||
| else { | else { | ||||
| for (a = 0; a < key->totkey; a++) { | for (a = 0; a < key->totkey; a++) { | ||||
| if (per_keyblock_weights[a]) { | if (per_keyblock_weights[a]) { | ||||
| MEM_freeN(per_keyblock_weights[a]); | MEM_freeN(per_keyblock_weights[a]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(per_keyblock_weights); | MEM_freeN(per_keyblock_weights); | ||||
| } | } | ||||
| static void do_mesh_key(Object *ob, Key *key, char *out, const int tot) | static void do_mesh_key(Object *ob, Key *key, char *out, const int tot) | ||||
| { | { | ||||
| KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | ||||
| float t[4]; | float t[4]; | ||||
| int flag = 0; | int flag = 0; | ||||
| if (key->type == KEY_RELATIVE) { | if (key->type == KEY_RELATIVE) { | ||||
| WeightsArrayCache cache = {0, NULL}; | WeightsArrayCache cache = {0, nullptr}; | ||||
| float **per_keyblock_weights; | float **per_keyblock_weights; | ||||
| per_keyblock_weights = keyblock_get_per_block_weights(ob, key, &cache); | per_keyblock_weights = keyblock_get_per_block_weights(ob, key, &cache); | ||||
| key_evaluate_relative( | key_evaluate_relative( | ||||
| 0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY); | 0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY); | ||||
| keyblock_free_per_block_weights(key, per_keyblock_weights, &cache); | keyblock_free_per_block_weights(key, per_keyblock_weights, &cache); | ||||
| } | } | ||||
| else { | else { | ||||
| const float ctime_scaled = key->ctime / 100.0f; | const float ctime_scaled = key->ctime / 100.0f; | ||||
| flag = setkeys(ctime_scaled, &key->block, k, t, 0); | flag = setkeys(ctime_scaled, &key->block, k, t, 0); | ||||
| if (flag == 0) { | if (flag == 0) { | ||||
| do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY); | do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY); | ||||
| } | } | ||||
| else { | else { | ||||
| cp_key(0, tot, tot, (char *)out, key, actkb, k[2], NULL, KEY_MODE_DUMMY); | cp_key(0, tot, tot, (char *)out, key, actkb, k[2], nullptr, KEY_MODE_DUMMY); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void do_cu_key( | static void do_cu_key( | ||||
| Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, const int tot) | Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, const int tot) | ||||
| { | { | ||||
| Nurb *nu; | Nurb *nu; | ||||
| int a, step; | int a, step; | ||||
| for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { | for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) { | ||||
| if (nu->bp) { | if (nu->bp) { | ||||
| step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | ||||
| do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BPOINT); | do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BPOINT); | ||||
| } | } | ||||
| else if (nu->bezt) { | else if (nu->bezt) { | ||||
| step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | ||||
| do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BEZTRIPLE); | do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BEZTRIPLE); | ||||
| } | } | ||||
| else { | else { | ||||
| step = 0; | step = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const int tot) | static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const int tot) | ||||
| { | { | ||||
| Nurb *nu; | Nurb *nu; | ||||
| int a, step; | int a, step; | ||||
| for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) { | for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) { | ||||
| if (nu->bp) { | if (nu->bp) { | ||||
| step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | ||||
| key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BPOINT); | key_evaluate_relative(a, a + step, tot, out, key, actkb, nullptr, KEY_MODE_BPOINT); | ||||
| } | } | ||||
| else if (nu->bezt) { | else if (nu->bezt) { | ||||
| step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | ||||
| key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BEZTRIPLE); | key_evaluate_relative(a, a + step, tot, out, key, actkb, nullptr, KEY_MODE_BEZTRIPLE); | ||||
| } | } | ||||
| else { | else { | ||||
| step = 0; | step = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void do_curve_key(Object *ob, Key *key, char *out, const int tot) | static void do_curve_key(Object *ob, Key *key, char *out, const int tot) | ||||
| { | { | ||||
| Curve *cu = ob->data; | Curve *cu = static_cast<Curve *>(ob->data); | ||||
| KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | ||||
| float t[4]; | float t[4]; | ||||
| int flag = 0; | int flag = 0; | ||||
| if (key->type == KEY_RELATIVE) { | if (key->type == KEY_RELATIVE) { | ||||
| do_rel_cu_key(cu, cu->key, actkb, out, tot); | do_rel_cu_key(cu, cu->key, actkb, out, tot); | ||||
| } | } | ||||
| else { | else { | ||||
| const float ctime_scaled = key->ctime / 100.0f; | const float ctime_scaled = key->ctime / 100.0f; | ||||
| flag = setkeys(ctime_scaled, &key->block, k, t, 0); | flag = setkeys(ctime_scaled, &key->block, k, t, 0); | ||||
| if (flag == 0) { | if (flag == 0) { | ||||
| do_cu_key(cu, key, actkb, k, t, out, tot); | do_cu_key(cu, key, actkb, k, t, out, tot); | ||||
| } | } | ||||
| else { | else { | ||||
| cp_cu_key(cu, key, actkb, k[2], 0, tot, out, tot); | cp_cu_key(cu, key, actkb, k[2], 0, tot, out, tot); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void do_latt_key(Object *ob, Key *key, char *out, const int tot) | static void do_latt_key(Object *ob, Key *key, char *out, const int tot) | ||||
| { | { | ||||
| Lattice *lt = ob->data; | Lattice *lt = static_cast<Lattice *>(ob->data); | ||||
| KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob); | ||||
| float t[4]; | float t[4]; | ||||
| int flag; | int flag; | ||||
| if (key->type == KEY_RELATIVE) { | if (key->type == KEY_RELATIVE) { | ||||
| float **per_keyblock_weights; | float **per_keyblock_weights; | ||||
| per_keyblock_weights = keyblock_get_per_block_weights(ob, key, NULL); | per_keyblock_weights = keyblock_get_per_block_weights(ob, key, nullptr); | ||||
| key_evaluate_relative( | key_evaluate_relative( | ||||
| 0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY); | 0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY); | ||||
| keyblock_free_per_block_weights(key, per_keyblock_weights, NULL); | keyblock_free_per_block_weights(key, per_keyblock_weights, nullptr); | ||||
| } | } | ||||
| else { | else { | ||||
| const float ctime_scaled = key->ctime / 100.0f; | const float ctime_scaled = key->ctime / 100.0f; | ||||
| flag = setkeys(ctime_scaled, &key->block, k, t, 0); | flag = setkeys(ctime_scaled, &key->block, k, t, 0); | ||||
| if (flag == 0) { | if (flag == 0) { | ||||
| do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY); | do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY); | ||||
| } | } | ||||
| else { | else { | ||||
| cp_key(0, tot, tot, (char *)out, key, actkb, k[2], NULL, KEY_MODE_DUMMY); | cp_key(0, tot, tot, (char *)out, key, actkb, k[2], nullptr, KEY_MODE_DUMMY); | ||||
| } | } | ||||
| } | } | ||||
| if (lt->flag & LT_OUTSIDE) { | if (lt->flag & LT_OUTSIDE) { | ||||
| outside_lattice(lt); | outside_lattice(lt); | ||||
| } | } | ||||
| } | } | ||||
| static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert); | static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert); | ||||
| static void keyblock_data_convert_to_lattice(const float (*fp)[3], | static void keyblock_data_convert_to_lattice(const float (*fp)[3], | ||||
| BPoint *bpoint, | BPoint *bpoint, | ||||
| const int totpoint); | const int totpoint); | ||||
| static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, const int totpoint); | static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, const int totpoint); | ||||
| float *BKE_key_evaluate_object_ex( | float *BKE_key_evaluate_object_ex( | ||||
| Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata) | Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata) | ||||
| { | { | ||||
| Key *key = BKE_key_from_object(ob); | Key *key = BKE_key_from_object(ob); | ||||
| KeyBlock *actkb = BKE_keyblock_from_object(ob); | KeyBlock *actkb = BKE_keyblock_from_object(ob); | ||||
| char *out; | char *out; | ||||
| int tot = 0, size = 0; | int tot = 0, size = 0; | ||||
| if (key == NULL || BLI_listbase_is_empty(&key->block)) { | if (key == nullptr || BLI_listbase_is_empty(&key->block)) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| /* compute size of output array */ | /* compute size of output array */ | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| tot = me->totvert; | tot = me->totvert; | ||||
| size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | ||||
| } | } | ||||
| else if (ob->type == OB_LATTICE) { | else if (ob->type == OB_LATTICE) { | ||||
| Lattice *lt = ob->data; | Lattice *lt = static_cast<Lattice *>(ob->data); | ||||
| tot = lt->pntsu * lt->pntsv * lt->pntsw; | tot = lt->pntsu * lt->pntsv * lt->pntsw; | ||||
| size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]); | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| Curve *cu = ob->data; | Curve *cu = static_cast<Curve *>(ob->data); | ||||
| tot = BKE_keyblock_curve_element_count(&cu->nurb); | tot = BKE_keyblock_curve_element_count(&cu->nurb); | ||||
| size = tot * sizeof(float[KEYELEM_ELEM_SIZE_CURVE]); | size = tot * sizeof(float[KEYELEM_ELEM_SIZE_CURVE]); | ||||
| } | } | ||||
| /* if nothing to interpolate, cancel */ | /* if nothing to interpolate, cancel */ | ||||
| if (tot == 0 || size == 0) { | if (tot == 0 || size == 0) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| /* allocate array */ | /* allocate array */ | ||||
| if (arr == NULL) { | if (arr == nullptr) { | ||||
| out = MEM_callocN(size, "BKE_key_evaluate_object out"); | out = static_cast<char *>(MEM_callocN(size, "BKE_key_evaluate_object out")); | ||||
| } | } | ||||
| else { | else { | ||||
| if (arr_size != size) { | if (arr_size != size) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| out = (char *)arr; | out = (char *)arr; | ||||
| } | } | ||||
| if (ob->shapeflag & OB_SHAPE_LOCK) { | if (ob->shapeflag & OB_SHAPE_LOCK) { | ||||
| /* shape locked, copy the locked shape instead of blending */ | /* shape locked, copy the locked shape instead of blending */ | ||||
| KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1); | KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1)); | ||||
| if (kb && (kb->flag & KEYBLOCK_MUTE)) { | if (kb && (kb->flag & KEYBLOCK_MUTE)) { | ||||
| kb = key->refkey; | kb = key->refkey; | ||||
| } | } | ||||
| if (kb == NULL) { | if (kb == nullptr) { | ||||
| kb = key->block.first; | kb = static_cast<KeyBlock *>(key->block.first); | ||||
| ob->shapenr = 1; | ob->shapenr = 1; | ||||
| } | } | ||||
| if (OB_TYPE_SUPPORT_VGROUP(ob->type)) { | if (OB_TYPE_SUPPORT_VGROUP(ob->type)) { | ||||
| float *weights = get_weights_array(ob, kb->vgroup, NULL); | float *weights = get_weights_array(ob, kb->vgroup, nullptr); | ||||
| cp_key(0, tot, tot, out, key, actkb, kb, weights, 0); | cp_key(0, tot, tot, out, key, actkb, kb, weights, 0); | ||||
| if (weights) { | if (weights) { | ||||
| MEM_freeN(weights); | MEM_freeN(weights); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| cp_cu_key(ob->data, key, actkb, kb, 0, tot, out, tot); | cp_cu_key(static_cast<Curve *>(ob->data), key, actkb, kb, 0, tot, out, tot); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| do_mesh_key(ob, key, out, tot); | do_mesh_key(ob, key, out, tot); | ||||
| } | } | ||||
| else if (ob->type == OB_LATTICE) { | else if (ob->type == OB_LATTICE) { | ||||
| do_latt_key(ob, key, out, tot); | do_latt_key(ob, key, out, tot); | ||||
| } | } | ||||
| else if (ob->type == OB_CURVES_LEGACY) { | else if (ob->type == OB_CURVES_LEGACY) { | ||||
| do_curve_key(ob, key, out, tot); | do_curve_key(ob, key, out, tot); | ||||
| } | } | ||||
| else if (ob->type == OB_SURF) { | else if (ob->type == OB_SURF) { | ||||
| do_curve_key(ob, key, out, tot); | do_curve_key(ob, key, out, tot); | ||||
| } | } | ||||
| } | } | ||||
| if (obdata != NULL) { | if (obdata != nullptr) { | ||||
| switch (GS(obdata->name)) { | switch (GS(obdata->name)) { | ||||
| case ID_ME: { | case ID_ME: { | ||||
| Mesh *mesh = (Mesh *)obdata; | Mesh *mesh = (Mesh *)obdata; | ||||
| MVert *verts = BKE_mesh_verts_for_write(mesh); | MVert *verts = BKE_mesh_verts_for_write(mesh); | ||||
| const int totvert = min_ii(tot, mesh->totvert); | const int totvert = min_ii(tot, mesh->totvert); | ||||
| keyblock_data_convert_to_mesh((const float(*)[3])out, verts, totvert); | keyblock_data_convert_to_mesh((const float(*)[3])out, verts, totvert); | ||||
| break; | break; | ||||
| } | } | ||||
| Show All 17 Lines | float *BKE_key_evaluate_object_ex( | ||||
| if (r_totelem) { | if (r_totelem) { | ||||
| *r_totelem = tot; | *r_totelem = tot; | ||||
| } | } | ||||
| return (float *)out; | return (float *)out; | ||||
| } | } | ||||
| float *BKE_key_evaluate_object(Object *ob, int *r_totelem) | float *BKE_key_evaluate_object(Object *ob, int *r_totelem) | ||||
| { | { | ||||
| return BKE_key_evaluate_object_ex(ob, r_totelem, NULL, 0, NULL); | return BKE_key_evaluate_object_ex(ob, r_totelem, nullptr, 0, nullptr); | ||||
| } | } | ||||
| int BKE_keyblock_element_count_from_shape(const Key *key, const int shape_index) | int BKE_keyblock_element_count_from_shape(const Key *key, const int shape_index) | ||||
| { | { | ||||
| int result = 0; | int result = 0; | ||||
| int index = 0; | int index = 0; | ||||
| for (const KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) { | for (const KeyBlock *kb = static_cast<const KeyBlock *>(key->block.first); kb; | ||||
| kb = kb->next, index++) { | |||||
| if (ELEM(shape_index, -1, index)) { | if (ELEM(shape_index, -1, index)) { | ||||
| result += kb->totelem; | result += kb->totelem; | ||||
| } | } | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| int BKE_keyblock_element_count(const Key *key) | int BKE_keyblock_element_count(const Key *key) | ||||
| Show All 17 Lines | |||||
| * Utilities for getting/setting key data as a single array, | * Utilities for getting/setting key data as a single array, | ||||
| * use #BKE_keyblock_element_calc_size to allocate the size of the data needed. | * use #BKE_keyblock_element_calc_size to allocate the size of the data needed. | ||||
| * \{ */ | * \{ */ | ||||
| void BKE_keyblock_data_get_from_shape(const Key *key, float (*arr)[3], const int shape_index) | void BKE_keyblock_data_get_from_shape(const Key *key, float (*arr)[3], const int shape_index) | ||||
| { | { | ||||
| uint8_t *elements = (uint8_t *)arr; | uint8_t *elements = (uint8_t *)arr; | ||||
| int index = 0; | int index = 0; | ||||
| for (const KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) { | for (const KeyBlock *kb = static_cast<const KeyBlock *>(key->block.first); kb; | ||||
| kb = kb->next, index++) { | |||||
| if (ELEM(shape_index, -1, index)) { | if (ELEM(shape_index, -1, index)) { | ||||
| const int block_elem_len = kb->totelem * key->elemsize; | const int block_elem_len = kb->totelem * key->elemsize; | ||||
| memcpy(elements, kb->data, block_elem_len); | memcpy(elements, kb->data, block_elem_len); | ||||
| elements += block_elem_len; | elements += block_elem_len; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 10 Lines | void BKE_keyblock_data_set_with_mat4(Key *key, | ||||
| if (key->elemsize != sizeof(float[3])) { | if (key->elemsize != sizeof(float[3])) { | ||||
| BLI_assert_msg(0, "Invalid elemsize"); | BLI_assert_msg(0, "Invalid elemsize"); | ||||
| return; | return; | ||||
| } | } | ||||
| const float(*elements)[3] = coords; | const float(*elements)[3] = coords; | ||||
| int index = 0; | int index = 0; | ||||
| for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) { | for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) { | ||||
| if (ELEM(shape_index, -1, index)) { | if (ELEM(shape_index, -1, index)) { | ||||
| const int block_elem_len = kb->totelem; | const int block_elem_len = kb->totelem; | ||||
| float(*block_data)[3] = (float(*)[3])kb->data; | float(*block_data)[3] = (float(*)[3])kb->data; | ||||
| for (int data_offset = 0; data_offset < block_elem_len; ++data_offset) { | for (int data_offset = 0; data_offset < block_elem_len; ++data_offset) { | ||||
| const float *src_data = (const float *)(elements + data_offset); | const float *src_data = (const float *)(elements + data_offset); | ||||
| float *dst_data = (float *)(block_data + data_offset); | float *dst_data = (float *)(block_data + data_offset); | ||||
| mul_v3_m4v3(dst_data, mat, src_data); | mul_v3_m4v3(dst_data, mat, src_data); | ||||
| } | } | ||||
| elements += block_elem_len; | elements += block_elem_len; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_curve_data_set_with_mat4( | void BKE_keyblock_curve_data_set_with_mat4( | ||||
| Key *key, const ListBase *nurb, const int shape_index, const void *data, const float mat[4][4]) | Key *key, const ListBase *nurb, const int shape_index, const void *data, const float mat[4][4]) | ||||
| { | { | ||||
| const uint8_t *elements = data; | const uint8_t *elements = static_cast<const uint8_t *>(data); | ||||
| int index = 0; | int index = 0; | ||||
| for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) { | for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) { | ||||
| if (ELEM(shape_index, -1, index)) { | if (ELEM(shape_index, -1, index)) { | ||||
| const int block_elem_size = kb->totelem * key->elemsize; | const int block_elem_size = kb->totelem * key->elemsize; | ||||
| BKE_keyblock_curve_data_transform(nurb, mat, elements, kb->data); | BKE_keyblock_curve_data_transform(nurb, mat, elements, kb->data); | ||||
| elements += block_elem_size; | elements += block_elem_size; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_data_set(Key *key, const int shape_index, const void *data) | void BKE_keyblock_data_set(Key *key, const int shape_index, const void *data) | ||||
| { | { | ||||
| const uint8_t *elements = data; | const uint8_t *elements = static_cast<const uint8_t *>(data); | ||||
| int index = 0; | int index = 0; | ||||
| for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) { | for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) { | ||||
| if (ELEM(shape_index, -1, index)) { | if (ELEM(shape_index, -1, index)) { | ||||
| const int block_elem_size = kb->totelem * key->elemsize; | const int block_elem_size = kb->totelem * key->elemsize; | ||||
| memcpy(kb->data, elements, block_elem_size); | memcpy(kb->data, elements, block_elem_size); | ||||
| elements += block_elem_size; | elements += block_elem_size; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 15 Lines | |||||
| { | { | ||||
| switch (GS(id->name)) { | switch (GS(id->name)) { | ||||
| case ID_ME: { | case ID_ME: { | ||||
| Mesh *me = (Mesh *)id; | Mesh *me = (Mesh *)id; | ||||
| return &me->key; | return &me->key; | ||||
| } | } | ||||
| case ID_CU_LEGACY: { | case ID_CU_LEGACY: { | ||||
| Curve *cu = (Curve *)id; | Curve *cu = (Curve *)id; | ||||
| if (cu->vfont == NULL) { | if (cu->vfont == nullptr) { | ||||
| return &cu->key; | return &cu->key; | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case ID_LT: { | case ID_LT: { | ||||
| Lattice *lt = (Lattice *)id; | Lattice *lt = (Lattice *)id; | ||||
| return <->key; | return <->key; | ||||
| } | } | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| Key *BKE_key_from_id(ID *id) | Key *BKE_key_from_id(ID *id) | ||||
| { | { | ||||
| Key **key_p; | Key **key_p; | ||||
| key_p = BKE_key_from_id_p(id); | key_p = BKE_key_from_id_p(id); | ||||
| if (key_p) { | if (key_p) { | ||||
| return *key_p; | return *key_p; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| Key **BKE_key_from_object_p(Object *ob) | Key **BKE_key_from_object_p(Object *ob) | ||||
| { | { | ||||
| if (ob == NULL || ob->data == NULL) { | if (ob == nullptr || ob->data == nullptr) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| return BKE_key_from_id_p(ob->data); | return BKE_key_from_id_p(static_cast<ID *>(ob->data)); | ||||
| } | } | ||||
| Key *BKE_key_from_object(Object *ob) | Key *BKE_key_from_object(Object *ob) | ||||
| { | { | ||||
| Key **key_p; | Key **key_p; | ||||
| key_p = BKE_key_from_object_p(ob); | key_p = BKE_key_from_object_p(ob); | ||||
| if (key_p) { | if (key_p) { | ||||
| return *key_p; | return *key_p; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_add(Key *key, const char *name) | KeyBlock *BKE_keyblock_add(Key *key, const char *name) | ||||
| { | { | ||||
| KeyBlock *kb; | KeyBlock *kb; | ||||
| float curpos = -0.1; | float curpos = -0.1; | ||||
| int tot; | int tot; | ||||
| kb = key->block.last; | kb = static_cast<KeyBlock *>(key->block.last); | ||||
| if (kb) { | if (kb) { | ||||
| curpos = kb->pos; | curpos = kb->pos; | ||||
| } | } | ||||
| kb = MEM_callocN(sizeof(KeyBlock), "Keyblock"); | kb = MEM_cnew<KeyBlock>("Keyblock"); | ||||
| BLI_addtail(&key->block, kb); | BLI_addtail(&key->block, kb); | ||||
| kb->type = KEY_LINEAR; | kb->type = KEY_LINEAR; | ||||
| tot = BLI_listbase_count(&key->block); | tot = BLI_listbase_count(&key->block); | ||||
| if (name) { | if (name) { | ||||
| BLI_strncpy(kb->name, name, sizeof(kb->name)); | BLI_strncpy(kb->name, name, sizeof(kb->name)); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 32 Lines | KeyBlock *BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force) | ||||
| /* In case of absolute keys, there is no point in adding more than one key with the same pos. | /* In case of absolute keys, there is no point in adding more than one key with the same pos. | ||||
| * Hence only set new keybloc pos to current time if none previous one already use it. | * Hence only set new keybloc pos to current time if none previous one already use it. | ||||
| * Now at least people just adding absolute keys without touching to ctime | * Now at least people just adding absolute keys without touching to ctime | ||||
| * won't have to systematically use retiming func (and have ordering issues, too). See T39897. | * won't have to systematically use retiming func (and have ordering issues, too). See T39897. | ||||
| */ | */ | ||||
| if (!do_force && (key->type != KEY_RELATIVE)) { | if (!do_force && (key->type != KEY_RELATIVE)) { | ||||
| KeyBlock *it_kb; | KeyBlock *it_kb; | ||||
| for (it_kb = key->block.first; it_kb; it_kb = it_kb->next) { | for (it_kb = static_cast<KeyBlock *>(key->block.first); it_kb; it_kb = it_kb->next) { | ||||
| /* Use epsilon to avoid floating point precision issues. | /* Use epsilon to avoid floating point precision issues. | ||||
| * 1e-3 because the position is stored as frame * 1e-2. */ | * 1e-3 because the position is stored as frame * 1e-2. */ | ||||
| if (compare_ff(it_kb->pos, cpos, 1e-3f)) { | if (compare_ff(it_kb->pos, cpos, 1e-3f)) { | ||||
| return kb; | return kb; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (do_force || (key->type != KEY_RELATIVE)) { | if (do_force || (key->type != KEY_RELATIVE)) { | ||||
| kb->pos = cpos; | kb->pos = cpos; | ||||
| BKE_key_sort(key); | BKE_key_sort(key); | ||||
| } | } | ||||
| return kb; | return kb; | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_from_object(Object *ob) | KeyBlock *BKE_keyblock_from_object(Object *ob) | ||||
| { | { | ||||
| Key *key = BKE_key_from_object(ob); | Key *key = BKE_key_from_object(ob); | ||||
| if (key) { | if (key) { | ||||
| KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1); | KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1)); | ||||
| return kb; | return kb; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_from_object_reference(Object *ob) | KeyBlock *BKE_keyblock_from_object_reference(Object *ob) | ||||
| { | { | ||||
| Key *key = BKE_key_from_object(ob); | Key *key = BKE_key_from_object(ob); | ||||
| if (key) { | if (key) { | ||||
| return key->refkey; | return key->refkey; | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_from_key(Key *key, int index) | KeyBlock *BKE_keyblock_from_key(Key *key, int index) | ||||
| { | { | ||||
| if (key) { | if (key) { | ||||
| KeyBlock *kb = key->block.first; | KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); | ||||
| for (int i = 1; i < key->totkey; i++) { | for (int i = 1; i < key->totkey; i++) { | ||||
| kb = kb->next; | kb = kb->next; | ||||
| if (index == i) { | if (index == i) { | ||||
| return kb; | return kb; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_find_name(Key *key, const char name[]) | KeyBlock *BKE_keyblock_find_name(Key *key, const char name[]) | ||||
| { | { | ||||
| return BLI_findstring(&key->block, name, offsetof(KeyBlock, name)); | return static_cast<KeyBlock *>(BLI_findstring(&key->block, name, offsetof(KeyBlock, name))); | ||||
| } | } | ||||
| KeyBlock *BKE_keyblock_find_uid(Key *key, const int uid) | KeyBlock *BKE_keyblock_find_uid(Key *key, const int uid) | ||||
| { | { | ||||
| LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { | LISTBASE_FOREACH (KeyBlock *, kb, &key->block) { | ||||
| if (kb->uid == uid) { | if (kb->uid == uid) { | ||||
| return kb; | return kb; | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src) | void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src) | ||||
| { | { | ||||
| kb_dst->pos = kb_src->pos; | kb_dst->pos = kb_src->pos; | ||||
| kb_dst->curval = kb_src->curval; | kb_dst->curval = kb_src->curval; | ||||
| kb_dst->type = kb_src->type; | kb_dst->type = kb_src->type; | ||||
| kb_dst->relative = kb_src->relative; | kb_dst->relative = kb_src->relative; | ||||
| BLI_strncpy(kb_dst->vgroup, kb_src->vgroup, sizeof(kb_dst->vgroup)); | BLI_strncpy(kb_dst->vgroup, kb_src->vgroup, sizeof(kb_dst->vgroup)); | ||||
| kb_dst->slidermin = kb_src->slidermin; | kb_dst->slidermin = kb_src->slidermin; | ||||
| kb_dst->slidermax = kb_src->slidermax; | kb_dst->slidermax = kb_src->slidermax; | ||||
| } | } | ||||
| char *BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb) | char *BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, key, kb)) { | if (ELEM(nullptr, key, kb)) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| /* create the RNA pointer */ | /* create the RNA pointer */ | ||||
| RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb, &ptr); | RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb, &ptr); | ||||
| /* get pointer to the property too */ | /* get pointer to the property too */ | ||||
| prop = RNA_struct_find_property(&ptr, "value"); | prop = RNA_struct_find_property(&ptr, "value"); | ||||
| /* return the path */ | /* return the path */ | ||||
| Show All 13 Lines | void BKE_keyblock_update_from_lattice(const Lattice *lt, KeyBlock *kb) | ||||
| BLI_assert(kb->totelem == lt->pntsu * lt->pntsv * lt->pntsw); | BLI_assert(kb->totelem == lt->pntsu * lt->pntsv * lt->pntsw); | ||||
| tot = kb->totelem; | tot = kb->totelem; | ||||
| if (tot == 0) { | if (tot == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| bp = lt->def; | bp = lt->def; | ||||
| fp = kb->data; | fp = static_cast<float(*)[3]>(kb->data); | ||||
| for (a = 0; a < kb->totelem; a++, fp++, bp++) { | for (a = 0; a < kb->totelem; a++, fp++, bp++) { | ||||
| copy_v3_v3(*fp, bp->vec); | copy_v3_v3(*fp, bp->vec); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_convert_from_lattice(const Lattice *lt, KeyBlock *kb) | void BKE_keyblock_convert_from_lattice(const Lattice *lt, KeyBlock *kb) | ||||
| { | { | ||||
| int tot; | int tot; | ||||
| Show All 18 Lines | static void keyblock_data_convert_to_lattice(const float (*fp)[3], | ||||
| for (int i = 0; i < totpoint; i++, fp++, bpoint++) { | for (int i = 0; i < totpoint; i++, fp++, bpoint++) { | ||||
| copy_v3_v3(bpoint->vec, *fp); | copy_v3_v3(bpoint->vec, *fp); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt) | void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt) | ||||
| { | { | ||||
| BPoint *bp = lt->def; | BPoint *bp = lt->def; | ||||
| const float(*fp)[3] = kb->data; | const float(*fp)[3] = static_cast<const float(*)[3]>(kb->data); | ||||
| const int tot = min_ii(kb->totelem, lt->pntsu * lt->pntsv * lt->pntsw); | const int tot = min_ii(kb->totelem, lt->pntsu * lt->pntsv * lt->pntsw); | ||||
| keyblock_data_convert_to_lattice(fp, bp, tot); | keyblock_data_convert_to_lattice(fp, bp, tot); | ||||
| } | } | ||||
| /************************* Curve ************************/ | /************************* Curve ************************/ | ||||
| int BKE_keyblock_curve_element_count(const ListBase *nurb) | int BKE_keyblock_curve_element_count(const ListBase *nurb) | ||||
| { | { | ||||
| const Nurb *nu; | const Nurb *nu; | ||||
| int tot = 0; | int tot = 0; | ||||
| nu = nurb->first; | nu = static_cast<const Nurb *>(nurb->first); | ||||
| while (nu) { | while (nu) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu; | ||||
| } | } | ||||
| else if (nu->bp) { | else if (nu->bp) { | ||||
| tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv; | ||||
| } | } | ||||
| Show All 13 Lines | void BKE_keyblock_update_from_curve(const Curve *UNUSED(cu), KeyBlock *kb, const ListBase *nurb) | ||||
| /* count */ | /* count */ | ||||
| BLI_assert(BKE_keyblock_curve_element_count(nurb) == kb->totelem); | BLI_assert(BKE_keyblock_curve_element_count(nurb) == kb->totelem); | ||||
| tot = kb->totelem; | tot = kb->totelem; | ||||
| if (tot == 0) { | if (tot == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| fp = kb->data; | fp = static_cast<float *>(kb->data); | ||||
| for (nu = nurb->first; nu; nu = nu->next) { | for (nu = static_cast<Nurb *>(nurb->first); nu; nu = nu->next) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | ||||
| for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
| copy_v3_v3(&fp[i * 3], bezt->vec[i]); | copy_v3_v3(&fp[i * 3], bezt->vec[i]); | ||||
| } | } | ||||
| fp[9] = bezt->tilt; | fp[9] = bezt->tilt; | ||||
| fp[10] = bezt->radius; | fp[10] = bezt->radius; | ||||
| fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | ||||
| Show All 10 Lines | void BKE_keyblock_update_from_curve(const Curve *UNUSED(cu), KeyBlock *kb, const ListBase *nurb) | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_curve_data_transform(const ListBase *nurb, | void BKE_keyblock_curve_data_transform(const ListBase *nurb, | ||||
| const float mat[4][4], | const float mat[4][4], | ||||
| const void *src_data, | const void *src_data, | ||||
| void *dst_data) | void *dst_data) | ||||
| { | { | ||||
| const float *src = src_data; | const float *src = static_cast<const float *>(src_data); | ||||
| float *dst = dst_data; | float *dst = static_cast<float *>(dst_data); | ||||
| for (Nurb *nu = nurb->first; nu; nu = nu->next) { | for (Nurb *nu = static_cast<Nurb *>(nurb->first); nu; nu = nu->next) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| for (int a = nu->pntsu; a; a--) { | for (int a = nu->pntsu; a; a--) { | ||||
| for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
| mul_v3_m4v3(&dst[i * 3], mat, &src[i * 3]); | mul_v3_m4v3(&dst[i * 3], mat, &src[i * 3]); | ||||
| } | } | ||||
| dst[9] = src[9]; | dst[9] = src[9]; | ||||
| dst[10] = src[10]; | dst[10] = src[10]; | ||||
| src += KEYELEM_FLOAT_LEN_BEZTRIPLE; | src += KEYELEM_FLOAT_LEN_BEZTRIPLE; | ||||
| Show All 27 Lines | void BKE_keyblock_convert_from_curve(const Curve *cu, KeyBlock *kb, const ListBase *nurb) | ||||
| kb->data = MEM_mallocN(cu->key->elemsize * tot, __func__); | kb->data = MEM_mallocN(cu->key->elemsize * tot, __func__); | ||||
| kb->totelem = tot; | kb->totelem = tot; | ||||
| BKE_keyblock_update_from_curve(cu, kb, nurb); | BKE_keyblock_update_from_curve(cu, kb, nurb); | ||||
| } | } | ||||
| static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, int totpoint) | static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, int totpoint) | ||||
| { | { | ||||
| for (Nurb *nu = nurb->first; nu && totpoint > 0; nu = nu->next) { | for (Nurb *nu = static_cast<Nurb *>(nurb->first); nu && totpoint > 0; nu = nu->next) { | ||||
| if (nu->bezt != NULL) { | if (nu->bezt != nullptr) { | ||||
| BezTriple *bezt = nu->bezt; | BezTriple *bezt = nu->bezt; | ||||
| for (int i = nu->pntsu; i && (totpoint -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; | for (int i = nu->pntsu; i && (totpoint -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; | ||||
| i--, bezt++, fp += KEYELEM_FLOAT_LEN_BEZTRIPLE) { | i--, bezt++, fp += KEYELEM_FLOAT_LEN_BEZTRIPLE) { | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| copy_v3_v3(bezt->vec[j], &fp[j * 3]); | copy_v3_v3(bezt->vec[j], &fp[j * 3]); | ||||
| } | } | ||||
| bezt->tilt = fp[9]; | bezt->tilt = fp[9]; | ||||
| bezt->radius = fp[10]; | bezt->radius = fp[10]; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BPoint *bp = nu->bp; | BPoint *bp = nu->bp; | ||||
| for (int i = nu->pntsu * nu->pntsv; i && (totpoint -= KEYELEM_ELEM_LEN_BPOINT) >= 0; | for (int i = nu->pntsu * nu->pntsv; i && (totpoint -= KEYELEM_ELEM_LEN_BPOINT) >= 0; | ||||
| i--, bp++, fp += KEYELEM_FLOAT_LEN_BPOINT) { | i--, bp++, fp += KEYELEM_FLOAT_LEN_BPOINT) { | ||||
| copy_v3_v3(bp->vec, fp); | copy_v3_v3(bp->vec, fp); | ||||
| bp->tilt = fp[3]; | bp->tilt = fp[3]; | ||||
| bp->radius = fp[4]; | bp->radius = fp[4]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) | void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb) | ||||
| { | { | ||||
| const float *fp = kb->data; | const float *fp = static_cast<const float *>(kb->data); | ||||
| const int tot = min_ii(kb->totelem, BKE_keyblock_curve_element_count(nurb)); | const int tot = min_ii(kb->totelem, BKE_keyblock_curve_element_count(nurb)); | ||||
| keyblock_data_convert_to_curve(fp, nurb, tot); | keyblock_data_convert_to_curve(fp, nurb, tot); | ||||
| } | } | ||||
| /************************* Mesh ************************/ | /************************* Mesh ************************/ | ||||
| void BKE_keyblock_update_from_mesh(const Mesh *me, KeyBlock *kb) | void BKE_keyblock_update_from_mesh(const Mesh *me, KeyBlock *kb) | ||||
| { | { | ||||
| float(*fp)[3]; | float(*fp)[3]; | ||||
| int a, tot; | int a, tot; | ||||
| BLI_assert(me->totvert == kb->totelem); | BLI_assert(me->totvert == kb->totelem); | ||||
| tot = me->totvert; | tot = me->totvert; | ||||
| if (tot == 0) { | if (tot == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| const MVert *mvert = BKE_mesh_verts(me); | const MVert *mvert = BKE_mesh_verts(me); | ||||
| fp = kb->data; | fp = static_cast<float(*)[3]>(kb->data); | ||||
| for (a = 0; a < tot; a++, fp++, mvert++) { | for (a = 0; a < tot; a++, fp++, mvert++) { | ||||
| copy_v3_v3(*fp, mvert->co); | copy_v3_v3(*fp, mvert->co); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb) | void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb) | ||||
| { | { | ||||
| const int len = me->totvert; | const int len = me->totvert; | ||||
| Show All 14 Lines | |||||
| { | { | ||||
| for (int i = 0; i < totvert; i++, fp++, mvert++) { | for (int i = 0; i < totvert; i++, fp++, mvert++) { | ||||
| copy_v3_v3(mvert->co, *fp); | copy_v3_v3(mvert->co, *fp); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MVert *mvert, const int totvert) | void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MVert *mvert, const int totvert) | ||||
| { | { | ||||
| const float(*fp)[3] = kb->data; | const float(*fp)[3] = static_cast<const float(*)[3]>(kb->data); | ||||
| const int tot = min_ii(kb->totelem, totvert); | const int tot = min_ii(kb->totelem, totvert); | ||||
| keyblock_data_convert_to_mesh(fp, mvert, tot); | keyblock_data_convert_to_mesh(fp, mvert, tot); | ||||
| } | } | ||||
| void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, | void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, | ||||
| const Mesh *mesh, | const Mesh *mesh, | ||||
| float (*r_vertnors)[3], | float (*r_vertnors)[3], | ||||
| float (*r_polynors)[3], | float (*r_polynors)[3], | ||||
| float (*r_loopnors)[3]) | float (*r_loopnors)[3]) | ||||
| { | { | ||||
| if (r_vertnors == NULL && r_polynors == NULL && r_loopnors == NULL) { | if (r_vertnors == nullptr && r_polynors == nullptr && r_loopnors == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| MVert *verts = MEM_dupallocN(BKE_mesh_verts(mesh)); | MVert *verts = static_cast<MVert *>(MEM_dupallocN(BKE_mesh_verts(mesh))); | ||||
| BKE_keyblock_convert_to_mesh(kb, verts, mesh->totvert); | BKE_keyblock_convert_to_mesh(kb, verts, mesh->totvert); | ||||
| const MEdge *edges = BKE_mesh_edges(mesh); | const MEdge *edges = BKE_mesh_edges(mesh); | ||||
| const MPoly *polys = BKE_mesh_polys(mesh); | const MPoly *polys = BKE_mesh_polys(mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(mesh); | const MLoop *loops = BKE_mesh_loops(mesh); | ||||
| const bool loop_normals_needed = r_loopnors != NULL; | const bool loop_normals_needed = r_loopnors != nullptr; | ||||
| const bool vert_normals_needed = r_vertnors != NULL || loop_normals_needed; | const bool vert_normals_needed = r_vertnors != nullptr || loop_normals_needed; | ||||
| const bool poly_normals_needed = r_polynors != NULL || vert_normals_needed || | const bool poly_normals_needed = r_polynors != nullptr || vert_normals_needed || | ||||
| loop_normals_needed; | loop_normals_needed; | ||||
| float(*vert_normals)[3] = r_vertnors; | float(*vert_normals)[3] = r_vertnors; | ||||
| float(*poly_normals)[3] = r_polynors; | float(*poly_normals)[3] = r_polynors; | ||||
| bool free_vert_normals = false; | bool free_vert_normals = false; | ||||
| bool free_poly_normals = false; | bool free_poly_normals = false; | ||||
| if (vert_normals_needed && r_vertnors == NULL) { | if (vert_normals_needed && r_vertnors == nullptr) { | ||||
| vert_normals = MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__); | vert_normals = static_cast<float(*)[3]>( | ||||
| MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__)); | |||||
| free_vert_normals = true; | free_vert_normals = true; | ||||
| } | } | ||||
| if (poly_normals_needed && r_polynors == NULL) { | if (poly_normals_needed && r_polynors == nullptr) { | ||||
| poly_normals = MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__); | poly_normals = static_cast<float(*)[3]>( | ||||
| MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__)); | |||||
| free_poly_normals = true; | free_poly_normals = true; | ||||
| } | } | ||||
| if (poly_normals_needed) { | if (poly_normals_needed) { | ||||
| BKE_mesh_calc_normals_poly( | BKE_mesh_calc_normals_poly( | ||||
| verts, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals); | verts, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals); | ||||
| } | } | ||||
| if (vert_normals_needed) { | if (vert_normals_needed) { | ||||
| BKE_mesh_calc_normals_poly_and_vertex(verts, | BKE_mesh_calc_normals_poly_and_vertex(verts, | ||||
| mesh->totvert, | mesh->totvert, | ||||
| loops, | loops, | ||||
| mesh->totloop, | mesh->totloop, | ||||
| polys, | polys, | ||||
| mesh->totpoly, | mesh->totpoly, | ||||
| poly_normals, | poly_normals, | ||||
| vert_normals); | vert_normals); | ||||
| } | } | ||||
| if (loop_normals_needed) { | if (loop_normals_needed) { | ||||
| short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */ | short(*clnors)[2] = static_cast<short(*)[2]>( | ||||
| CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL)); /* May be nullptr. */ | |||||
| BKE_mesh_normals_loop_split(verts, | BKE_mesh_normals_loop_split(verts, | ||||
| vert_normals, | vert_normals, | ||||
| mesh->totvert, | mesh->totvert, | ||||
| edges, | edges, | ||||
| mesh->totedge, | mesh->totedge, | ||||
| loops, | loops, | ||||
| r_loopnors, | r_loopnors, | ||||
| mesh->totloop, | mesh->totloop, | ||||
| polys, | polys, | ||||
| poly_normals, | poly_normals, | ||||
| mesh->totpoly, | mesh->totpoly, | ||||
| (mesh->flag & ME_AUTOSMOOTH) != 0, | (mesh->flag & ME_AUTOSMOOTH) != 0, | ||||
| mesh->smoothresh, | mesh->smoothresh, | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| clnors); | clnors); | ||||
| } | } | ||||
| if (free_vert_normals) { | if (free_vert_normals) { | ||||
| MEM_freeN(vert_normals); | MEM_freeN(vert_normals); | ||||
| } | } | ||||
| if (free_poly_normals) { | if (free_poly_normals) { | ||||
| MEM_freeN(poly_normals); | MEM_freeN(poly_normals); | ||||
| } | } | ||||
| MEM_freeN(verts); | MEM_freeN(verts); | ||||
| } | } | ||||
| /************************* raw coords ************************/ | /************************* raw coords ************************/ | ||||
| void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | ||||
| { | { | ||||
| const float(*co)[3] = vertCos; | const float(*co)[3] = vertCos; | ||||
| float *fp = kb->data; | float *fp = static_cast<float *>(kb->data); | ||||
| int tot, a; | int tot, a; | ||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| if (ob->type == OB_LATTICE) { | if (ob->type == OB_LATTICE) { | ||||
| Lattice *lt = ob->data; | Lattice *lt = static_cast<Lattice *>(ob->data); | ||||
| BLI_assert((lt->pntsu * lt->pntsv * lt->pntsw) == kb->totelem); | BLI_assert((lt->pntsu * lt->pntsv * lt->pntsw) == kb->totelem); | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| Curve *cu = ob->data; | Curve *cu = static_cast<Curve *>(ob->data); | ||||
| BLI_assert(BKE_keyblock_curve_element_count(&cu->nurb) == kb->totelem); | BLI_assert(BKE_keyblock_curve_element_count(&cu->nurb) == kb->totelem); | ||||
| } | } | ||||
| else if (ob->type == OB_MESH) { | else if (ob->type == OB_MESH) { | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| BLI_assert(me->totvert == kb->totelem); | BLI_assert(me->totvert == kb->totelem); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(0 == kb->totelem); | BLI_assert(0 == kb->totelem); | ||||
| } | } | ||||
| #endif | #endif | ||||
| tot = kb->totelem; | tot = kb->totelem; | ||||
| if (tot == 0) { | if (tot == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Copy coords to key-block. */ | /* Copy coords to key-block. */ | ||||
| if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | ||||
| for (a = 0; a < tot; a++, fp += 3, co++) { | for (a = 0; a < tot; a++, fp += 3, co++) { | ||||
| copy_v3_v3(fp, *co); | copy_v3_v3(fp, *co); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| const Curve *cu = (const Curve *)ob->data; | const Curve *cu = (const Curve *)ob->data; | ||||
| const Nurb *nu; | const Nurb *nu; | ||||
| const BezTriple *bezt; | const BezTriple *bezt; | ||||
| const BPoint *bp; | const BPoint *bp; | ||||
| for (nu = cu->nurb.first; nu; nu = nu->next) { | for (nu = static_cast<const Nurb *>(cu->nurb.first); nu; nu = nu->next) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | ||||
| for (int i = 0; i < 3; i++, co++) { | for (int i = 0; i < 3; i++, co++) { | ||||
| copy_v3_v3(&fp[i * 3], *co); | copy_v3_v3(&fp[i * 3], *co); | ||||
| } | } | ||||
| fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | ||||
| } | } | ||||
| } | } | ||||
| Show All 38 Lines | void BKE_keyblock_convert_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3]) | ||||
| /* Copy coords to key-block. */ | /* Copy coords to key-block. */ | ||||
| BKE_keyblock_update_from_vertcos(ob, kb, vertCos); | BKE_keyblock_update_from_vertcos(ob, kb, vertCos); | ||||
| } | } | ||||
| float (*BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3] | float (*BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3] | ||||
| { | { | ||||
| float(*vertCos)[3], (*co)[3]; | float(*vertCos)[3], (*co)[3]; | ||||
| const float *fp = kb->data; | const float *fp = static_cast<const float *>(kb->data); | ||||
| int tot = 0, a; | int tot = 0, a; | ||||
| /* Count of vertex coords in array */ | /* Count of vertex coords in array */ | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| const Mesh *me = (const Mesh *)ob->data; | const Mesh *me = (const Mesh *)ob->data; | ||||
| tot = me->totvert; | tot = me->totvert; | ||||
| } | } | ||||
| else if (ob->type == OB_LATTICE) { | else if (ob->type == OB_LATTICE) { | ||||
| const Lattice *lt = (const Lattice *)ob->data; | const Lattice *lt = (const Lattice *)ob->data; | ||||
| tot = lt->pntsu * lt->pntsv * lt->pntsw; | tot = lt->pntsu * lt->pntsv * lt->pntsw; | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| const Curve *cu = (const Curve *)ob->data; | const Curve *cu = (const Curve *)ob->data; | ||||
| tot = BKE_nurbList_verts_count(&cu->nurb); | tot = BKE_nurbList_verts_count(&cu->nurb); | ||||
| } | } | ||||
| if (tot == 0) { | if (tot == 0) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| co = vertCos = MEM_mallocN(tot * sizeof(*vertCos), __func__); | co = vertCos = static_cast<float(*)[3]>(MEM_mallocN(tot * sizeof(*vertCos), __func__)); | ||||
| /* Copy coords to array */ | /* Copy coords to array */ | ||||
| if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | ||||
| for (a = 0; a < tot; a++, fp += 3, co++) { | for (a = 0; a < tot; a++, fp += 3, co++) { | ||||
| copy_v3_v3(*co, fp); | copy_v3_v3(*co, fp); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| const Curve *cu = (const Curve *)ob->data; | const Curve *cu = (const Curve *)ob->data; | ||||
| const Nurb *nu; | const Nurb *nu; | ||||
| const BezTriple *bezt; | const BezTriple *bezt; | ||||
| const BPoint *bp; | const BPoint *bp; | ||||
| for (nu = cu->nurb.first; nu; nu = nu->next) { | for (nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | ||||
| for (int i = 0; i < 3; i++, co++) { | for (int i = 0; i < 3; i++, co++) { | ||||
| copy_v3_v3(*co, &fp[i * 3]); | copy_v3_v3(*co, &fp[i * 3]); | ||||
| } | } | ||||
| fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | ||||
| } | } | ||||
| } | } | ||||
| Show All 9 Lines | float (*BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3] | ||||
| return vertCos; | return vertCos; | ||||
| } | } | ||||
| /************************* raw coord offsets ************************/ | /************************* raw coord offsets ************************/ | ||||
| void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float (*ofs)[3]) | void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float (*ofs)[3]) | ||||
| { | { | ||||
| int a; | int a; | ||||
| float *fp = kb->data; | float *fp = static_cast<float *>(kb->data); | ||||
| if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | if (ELEM(ob->type, OB_MESH, OB_LATTICE)) { | ||||
| for (a = 0; a < kb->totelem; a++, fp += 3, ofs++) { | for (a = 0; a < kb->totelem; a++, fp += 3, ofs++) { | ||||
| add_v3_v3(fp, *ofs); | add_v3_v3(fp, *ofs); | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) { | ||||
| const Curve *cu = (const Curve *)ob->data; | const Curve *cu = (const Curve *)ob->data; | ||||
| const Nurb *nu; | const Nurb *nu; | ||||
| const BezTriple *bezt; | const BezTriple *bezt; | ||||
| const BPoint *bp; | const BPoint *bp; | ||||
| for (nu = cu->nurb.first; nu; nu = nu->next) { | for (nu = static_cast<const Nurb *>(cu->nurb.first); nu; nu = nu->next) { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) { | ||||
| for (int i = 0; i < 3; i++, ofs++) { | for (int i = 0; i < 3; i++, ofs++) { | ||||
| add_v3_v3(&fp[i * 3], *ofs); | add_v3_v3(&fp[i * 3], *ofs); | ||||
| } | } | ||||
| fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; | ||||
| } | } | ||||
| } | } | ||||
| Show All 29 Lines | if (new_index == org_index) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| rev = ((new_index - org_index) < 0) ? true : false; | rev = ((new_index - org_index) < 0) ? true : false; | ||||
| /* We swap 'org' element with its previous/next neighbor (depending on direction of the move) | /* We swap 'org' element with its previous/next neighbor (depending on direction of the move) | ||||
| * repeatedly, until we reach final position. | * repeatedly, until we reach final position. | ||||
| * This allows us to only loop on the list once! */ | * This allows us to only loop on the list once! */ | ||||
| for (kb = (rev ? key->block.last : key->block.first), i = (rev ? totkey - 1 : 0); kb; | for (kb = static_cast<KeyBlock *>(rev ? key->block.last : key->block.first), | ||||
| i = (rev ? totkey - 1 : 0); | |||||
| kb; | |||||
| kb = (rev ? kb->prev : kb->next), rev ? i-- : i++) { | kb = (rev ? kb->prev : kb->next), rev ? i-- : i++) { | ||||
| if (i == org_index) { | if (i == org_index) { | ||||
| in_range = true; /* Start list items swapping... */ | in_range = true; /* Start list items swapping... */ | ||||
| } | } | ||||
| else if (i == new_index) { | else if (i == new_index) { | ||||
| in_range = false; /* End list items swapping. */ | in_range = false; /* End list items swapping. */ | ||||
| } | } | ||||
| Show All 31 Lines | bool BKE_keyblock_move(Object *ob, int org_index, int new_index) | ||||
| else if (act_index < org_index && act_index >= new_index) { | else if (act_index < org_index && act_index >= new_index) { | ||||
| ob->shapenr++; | ob->shapenr++; | ||||
| } | } | ||||
| else if (act_index > org_index && act_index <= new_index) { | else if (act_index > org_index && act_index <= new_index) { | ||||
| ob->shapenr--; | ob->shapenr--; | ||||
| } | } | ||||
| /* First key is always refkey, matches interface and BKE_key_sort */ | /* First key is always refkey, matches interface and BKE_key_sort */ | ||||
| key->refkey = key->block.first; | key->refkey = static_cast<KeyBlock *>(key->block.first); | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool BKE_keyblock_is_basis(const Key *key, const int index) | bool BKE_keyblock_is_basis(const Key *key, const int index) | ||||
| { | { | ||||
| const KeyBlock *kb; | const KeyBlock *kb; | ||||
| int i; | int i; | ||||
| if (key->type == KEY_RELATIVE) { | if (key->type == KEY_RELATIVE) { | ||||
| for (i = 0, kb = key->block.first; kb; i++, kb = kb->next) { | for (i = 0, kb = static_cast<const KeyBlock *>(key->block.first); kb; i++, kb = kb->next) { | ||||
| if ((i != index) && (kb->relative == index)) { | if ((i != index) && (kb->relative == index)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||