Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/deform.c
| Show First 20 Lines • Show All 566 Lines • ▼ Show 20 Lines | |||||
| void BKE_object_defgroup_active_index_set(Object *ob, const int new_index) | void BKE_object_defgroup_active_index_set(Object *ob, const int new_index) | ||||
| { | { | ||||
| /* Cast away const just for the accessor. */ | /* Cast away const just for the accessor. */ | ||||
| int *index = (int *)object_defgroup_active_index_get_p(ob); | int *index = (int *)object_defgroup_active_index_get_p(ob); | ||||
| *index = new_index; | *index = new_index; | ||||
| } | } | ||||
| int *BKE_object_defgroup_flip_map(const Object *ob, int *flip_map_len, const bool use_default) | static int *object_defgroup_unlocked_flip_map_ex(const Object *ob, | ||||
| int *flip_map_len, | |||||
| const bool use_default, | |||||
| const bool use_only_unlocked) | |||||
| { | { | ||||
| const ListBase *defbase = BKE_object_defgroup_list(ob); | const ListBase *defbase = BKE_object_defgroup_list(ob); | ||||
| int defbase_tot = *flip_map_len = BLI_listbase_count(defbase); | *flip_map_len = BLI_listbase_count(defbase); | ||||
| if (defbase_tot == 0) { | if (*flip_map_len == 0) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| bDeformGroup *dg; | bDeformGroup *dg; | ||||
| char name_flip[sizeof(dg->name)]; | char name_flip[sizeof(dg->name)]; | ||||
| int i, flip_num, *map = MEM_mallocN(defbase_tot * sizeof(int), __func__); | int i, flip_num; | ||||
| int *map = MEM_mallocN(*flip_map_len * sizeof(int), __func__); | |||||
| for (i = 0; i < defbase_tot; i++) { | for (int i = 0; i < *flip_map_len; i++) { | ||||
| map[i] = -1; | map[i] = -1; | ||||
| } | } | ||||
| for (dg = defbase->first, i = 0; dg; dg = dg->next, i++) { | for (dg = defbase->first, i = 0; dg; dg = dg->next, i++) { | ||||
| if (map[i] == -1) { /* may be calculated previously */ | if (map[i] == -1) { /* may be calculated previously */ | ||||
| /* in case no valid value is found, use this */ | /* in case no valid value is found, use this */ | ||||
| if (use_default) { | if (use_default) { | ||||
| map[i] = i; | map[i] = i; | ||||
| } | } | ||||
| if (use_only_unlocked && ((dg->flag & DG_LOCK_WEIGHT) != 0)) { | |||||
| continue; | |||||
| } | |||||
| BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip)); | BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip)); | ||||
| if (!STREQ(name_flip, dg->name)) { | if (!STREQ(name_flip, dg->name)) { | ||||
| flip_num = BKE_object_defgroup_name_index(ob, name_flip); | flip_num = BKE_object_defgroup_name_index(ob, name_flip); | ||||
| if (flip_num >= 0) { | if (flip_num != -1) { | ||||
| map[i] = flip_num; | map[i] = flip_num; | ||||
| map[flip_num] = i; /* save an extra lookup */ | map[flip_num] = i; /* save an extra lookup */ | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return map; | return map; | ||||
| } | } | ||||
| int *BKE_object_defgroup_flip_map(const Object *ob, int *flip_map_len, const bool use_default) | |||||
| { | |||||
| return object_defgroup_unlocked_flip_map_ex(ob, flip_map_len, use_default, false); | |||||
| } | |||||
| int *BKE_object_defgroup_flip_map_unlocked(const Object *ob, | |||||
| int *flip_map_len, | |||||
| const bool use_default) | |||||
| { | |||||
| return object_defgroup_unlocked_flip_map_ex(ob, flip_map_len, use_default, true); | |||||
| } | |||||
| int *BKE_object_defgroup_flip_map_single(const Object *ob, | int *BKE_object_defgroup_flip_map_single(const Object *ob, | ||||
| int *flip_map_len, | int *flip_map_len, | ||||
| const bool use_default, | const bool use_default, | ||||
| int defgroup) | int defgroup) | ||||
| { | { | ||||
| const ListBase *defbase = BKE_object_defgroup_list(ob); | const ListBase *defbase = BKE_object_defgroup_list(ob); | ||||
| int defbase_tot = *flip_map_len = BLI_listbase_count(defbase); | int defbase_tot = *flip_map_len = BLI_listbase_count(defbase); | ||||
| ▲ Show 20 Lines • Show All 983 Lines • Show Last 20 Lines | |||||