Cleanup/refactor: get rid of fixed name limit in BKE_deform_flip_side_name & co.
Those were forcing to use vgroup name define in bones area, or even mixing with maxbonename... ugly, and totally avoidable.
This commit is contained in:
parent
b997988323
commit
7ce833af5b
|
@ -119,10 +119,9 @@ void BKE_defvert_extract_vgroup_to_polyweights(
|
|||
/* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only
|
||||
* used with defgroups currently */
|
||||
|
||||
void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]);
|
||||
void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char base[MAX_VGROUP_NAME], char ext[MAX_VGROUP_NAME]);
|
||||
void BKE_deform_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len);
|
||||
void BKE_deform_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len);
|
||||
|
||||
void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME],
|
||||
const bool strip_number);
|
||||
void BKE_deform_flip_side_name(char *r_name, const char *from_name, const bool strip_number, const size_t name_len);
|
||||
|
||||
#endif /* __BKE_DEFORM_H__ */
|
||||
|
|
|
@ -495,7 +495,7 @@ bPoseChannel *BKE_pose_channel_get_mirrored(const bPose *pose, const char *name)
|
|||
{
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, name, false);
|
||||
BKE_deform_flip_side_name(name_flip, name, false, sizeof(name_flip));
|
||||
|
||||
if (!STREQ(name_flip, name)) {
|
||||
return BKE_pose_channel_find_name(pose, name_flip);
|
||||
|
|
|
@ -509,7 +509,7 @@ int *defgroup_flip_map(Object *ob, int *flip_map_len, const bool use_default)
|
|||
if (use_default)
|
||||
map[i] = i;
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
||||
|
||||
if (!STREQ(name_flip, dg->name)) {
|
||||
flip_num = defgroup_name_index(ob, name_flip);
|
||||
|
@ -545,7 +545,7 @@ int *defgroup_flip_map_single(Object *ob, int *flip_map_len, const bool use_defa
|
|||
|
||||
dg = BLI_findlink(&ob->defbase, defgroup);
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
||||
if (!STREQ(name_flip, dg->name)) {
|
||||
flip_num = defgroup_name_index(ob, name_flip);
|
||||
|
||||
|
@ -566,7 +566,7 @@ int defgroup_flip_index(Object *ob, int index, const bool use_default)
|
|||
|
||||
if (dg) {
|
||||
char name_flip[sizeof(dg->name)];
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
||||
|
||||
if (!STREQ(name_flip, dg->name)) {
|
||||
flip_index = defgroup_name_index(ob, name_flip);
|
||||
|
@ -615,91 +615,92 @@ static bool is_char_sep(const char c)
|
|||
* based on `BLI_split_dirfile()` / `os.path.splitext()`,
|
||||
* `"a.b.c"` -> (`"a.b"`, `".c"`).
|
||||
*/
|
||||
void BKE_deform_split_suffix(const char string[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME], char suf[MAX_VGROUP_NAME])
|
||||
void BKE_deform_split_suffix(const char *string, char *r_body, char *r_suf, const size_t str_len)
|
||||
{
|
||||
size_t len = BLI_strnlen(string, MAX_VGROUP_NAME);
|
||||
size_t len = BLI_strnlen(string, str_len);
|
||||
size_t i;
|
||||
|
||||
body[0] = suf[0] = '\0';
|
||||
r_body[0] = r_suf[0] = '\0';
|
||||
|
||||
for (i = len; i > 0; i--) {
|
||||
if (is_char_sep(string[i])) {
|
||||
BLI_strncpy(body, string, i + 1);
|
||||
BLI_strncpy(suf, string + i, (len + 1) - i);
|
||||
BLI_strncpy(r_body, string, i + 1);
|
||||
BLI_strncpy(r_suf, string + i, (len + 1) - i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(body, string, len + 1);
|
||||
memcpy(r_body, string, len + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* `"a.b.c"` -> (`"a."`, `"b.c"`)
|
||||
*/
|
||||
void BKE_deform_split_prefix(const char string[MAX_VGROUP_NAME], char pre[MAX_VGROUP_NAME], char body[MAX_VGROUP_NAME])
|
||||
void BKE_deform_split_prefix(const char *string, char *r_pre, char *r_body, const size_t str_len)
|
||||
{
|
||||
size_t len = BLI_strnlen(string, MAX_VGROUP_NAME);
|
||||
size_t len = BLI_strnlen(string, str_len);
|
||||
size_t i;
|
||||
|
||||
body[0] = pre[0] = '\0';
|
||||
r_body[0] = r_pre[0] = '\0';
|
||||
|
||||
for (i = 1; i < len; i++) {
|
||||
if (is_char_sep(string[i])) {
|
||||
i++;
|
||||
BLI_strncpy(pre, string, i + 1);
|
||||
BLI_strncpy(body, string + i, (len + 1) - i);
|
||||
BLI_strncpy(r_pre, string, i + 1);
|
||||
BLI_strncpy(r_body, string + i, (len + 1) - i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
BLI_strncpy(body, string, len);
|
||||
BLI_strncpy(r_body, string, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the best possible flipped name. For renaming; check for unique names afterwards.
|
||||
* Finds the best possible flipped (left/right) name. For renaming; check for unique names afterwards.
|
||||
*
|
||||
* if strip_number: removes number extensions
|
||||
*
|
||||
* \note don't use sizeof() for 'name' or 'from_name'.
|
||||
* \param r_name flipped name, assumed to be a pointer to a string of at least \a name_len size.
|
||||
* \param from_name original name, assumed to be a pointer to a string of at least \a name_len size.
|
||||
* \param strip_number If set, remove number extensions.
|
||||
*/
|
||||
void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP_NAME],
|
||||
const bool strip_number)
|
||||
void BKE_deform_flip_side_name(char *r_name, const char *from_name, const bool strip_number, const size_t name_len)
|
||||
{
|
||||
int len;
|
||||
char prefix[MAX_VGROUP_NAME] = ""; /* The part before the facing */
|
||||
char suffix[MAX_VGROUP_NAME] = ""; /* The part after the facing */
|
||||
char replace[MAX_VGROUP_NAME] = ""; /* The replacement string */
|
||||
char number[MAX_VGROUP_NAME] = ""; /* The number extension string */
|
||||
char *index = NULL;
|
||||
size_t len;
|
||||
char *prefix = alloca(name_len); /* The part before the facing */
|
||||
char *suffix = alloca(name_len); /* The part after the facing */
|
||||
char *replace = alloca(name_len); /* The replacement string */
|
||||
char *number = alloca(name_len); /* The number extension string */
|
||||
char *index = NULL;
|
||||
bool is_set = false;
|
||||
|
||||
/* always copy the name, since this can be called with an uninitialized string */
|
||||
BLI_strncpy(name, from_name, MAX_VGROUP_NAME);
|
||||
*prefix = *suffix = *replace = *number = '\0';
|
||||
|
||||
len = BLI_strnlen(from_name, MAX_VGROUP_NAME);
|
||||
/* always copy the name, since this can be called with an uninitialized string */
|
||||
BLI_strncpy(r_name, from_name, name_len);
|
||||
|
||||
len = BLI_strnlen(from_name, name_len);
|
||||
if (len < 3) {
|
||||
/* we don't do names like .R or .L */
|
||||
return;
|
||||
}
|
||||
|
||||
/* We first check the case with a .### extension, let's find the last period */
|
||||
if (isdigit(name[len - 1])) {
|
||||
index = strrchr(name, '.'); // last occurrence
|
||||
if (isdigit(r_name[len - 1])) {
|
||||
index = strrchr(r_name, '.'); // last occurrence
|
||||
if (index && isdigit(index[1])) { // doesnt handle case bone.1abc2 correct..., whatever!
|
||||
if (strip_number == false) {
|
||||
BLI_strncpy(number, index, sizeof(number));
|
||||
BLI_strncpy(number, index, name_len);
|
||||
}
|
||||
*index = 0;
|
||||
len = BLI_strnlen(name, MAX_VGROUP_NAME);
|
||||
len = BLI_strnlen(r_name, name_len);
|
||||
}
|
||||
}
|
||||
|
||||
BLI_strncpy(prefix, name, sizeof(prefix));
|
||||
BLI_strncpy(prefix, r_name, name_len);
|
||||
|
||||
/* first case; separator . - _ with extensions r R l L */
|
||||
if ((len > 1) && is_char_sep(name[len - 2])) {
|
||||
if ((len > 1) && is_char_sep(r_name[len - 2])) {
|
||||
is_set = true;
|
||||
switch (name[len - 1]) {
|
||||
switch (r_name[len - 1]) {
|
||||
case 'l':
|
||||
prefix[len - 1] = 0;
|
||||
strcpy(replace, "r");
|
||||
|
@ -722,27 +723,27 @@ void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[
|
|||
}
|
||||
|
||||
/* case; beginning with r R l L, with separator after it */
|
||||
if (!is_set && is_char_sep(name[1])) {
|
||||
if (!is_set && is_char_sep(r_name[1])) {
|
||||
is_set = true;
|
||||
switch (name[0]) {
|
||||
switch (r_name[0]) {
|
||||
case 'l':
|
||||
strcpy(replace, "r");
|
||||
BLI_strncpy(suffix, name + 1, sizeof(suffix));
|
||||
BLI_strncpy(suffix, r_name + 1, name_len);
|
||||
prefix[0] = 0;
|
||||
break;
|
||||
case 'r':
|
||||
strcpy(replace, "l");
|
||||
BLI_strncpy(suffix, name + 1, sizeof(suffix));
|
||||
BLI_strncpy(suffix, r_name + 1, name_len);
|
||||
prefix[0] = 0;
|
||||
break;
|
||||
case 'L':
|
||||
strcpy(replace, "R");
|
||||
BLI_strncpy(suffix, name + 1, sizeof(suffix));
|
||||
BLI_strncpy(suffix, r_name + 1, name_len);
|
||||
prefix[0] = 0;
|
||||
break;
|
||||
case 'R':
|
||||
strcpy(replace, "L");
|
||||
BLI_strncpy(suffix, name + 1, sizeof(suffix));
|
||||
BLI_strncpy(suffix, r_name + 1, name_len);
|
||||
prefix[0] = 0;
|
||||
break;
|
||||
default:
|
||||
|
@ -763,7 +764,7 @@ void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[
|
|||
strcpy(replace, (index[1] == 'I') ? "LEFT" : "Left");
|
||||
}
|
||||
*index = 0;
|
||||
BLI_strncpy(suffix, index + 5, sizeof(suffix));
|
||||
BLI_strncpy(suffix, index + 5, name_len);
|
||||
}
|
||||
else if (((index = BLI_strcasestr(prefix, "left")) == prefix) ||
|
||||
(index == prefix + len - 4))
|
||||
|
@ -776,13 +777,11 @@ void BKE_deform_flip_side_name(char name[MAX_VGROUP_NAME], const char from_name[
|
|||
strcpy(replace, (index[1] == 'E') ? "RIGHT" : "Right");
|
||||
}
|
||||
*index = 0;
|
||||
BLI_strncpy(suffix, index + 4, sizeof(suffix));
|
||||
BLI_strncpy(suffix, index + 4, name_len);
|
||||
}
|
||||
}
|
||||
|
||||
(void)is_set; /* quiet warning */
|
||||
|
||||
BLI_snprintf(name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number);
|
||||
BLI_snprintf(r_name, name_len, "%s%s%s%s", prefix, replace, suffix, number);
|
||||
}
|
||||
|
||||
float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
|
||||
|
|
|
@ -623,7 +623,7 @@ void BKE_object_defgroup_mirror_selection(
|
|||
if (dg_selection[i]) {
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, defgroup->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, defgroup->name, false, sizeof(name_flip));
|
||||
i_mirr = STREQ(name_flip, defgroup->name) ? i : defgroup_name_index(ob, name_flip);
|
||||
|
||||
if ((i_mirr >= 0 && i_mirr < defbase_tot) && (dg_flags_sel[i_mirr] == false)) {
|
||||
|
|
|
@ -668,7 +668,7 @@ static void flip_names(tAnimCopybufItem *aci, char **name)
|
|||
|
||||
/* more ninja stuff, temporary substitute with NULL terminator */
|
||||
str_start[length] = 0;
|
||||
BKE_deform_flip_side_name(bname_new, str_start, false);
|
||||
BKE_deform_flip_side_name(bname_new, str_start, false, sizeof(bname_new));
|
||||
str_start[length] = '\"';
|
||||
|
||||
str_iter = *name = MEM_mallocN(sizeof(char) * (prefix_l + postfix_l + length + 1), "flipped_path");
|
||||
|
|
|
@ -619,9 +619,9 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op)
|
|||
if (EBONE_VISIBLE(arm, ebone_iter) &&
|
||||
(ebone_iter->flag & BONE_SELECTED))
|
||||
{
|
||||
char name_flip[MAX_VGROUP_NAME];
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, ebone_iter->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, ebone_iter->name, false, sizeof(name_flip));
|
||||
|
||||
if (STREQ(name_flip, ebone_iter->name)) {
|
||||
/* if the name matches, we don't have the potential to be mirrored, just skip */
|
||||
|
@ -679,9 +679,9 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op)
|
|||
/* will be set if the mirror bone already exists (no need to make a new one) */
|
||||
(ebone_iter->temp.ebone == NULL))
|
||||
{
|
||||
char name_flip[MAX_VGROUP_NAME];
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, ebone_iter->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, ebone_iter->name, false, sizeof(name_flip));
|
||||
|
||||
/* bones must have a side-suffix */
|
||||
if (!STREQ(name_flip, ebone_iter->name)) {
|
||||
|
|
|
@ -328,7 +328,7 @@ void ED_armature_bones_flip_names(bArmature *arm, ListBase *bones_names)
|
|||
|
||||
/* Do not strip numbers, otherwise we'll end up with completely mismatched names in cases like
|
||||
* Bone.R, Bone.R.001, Bone.R.002, etc. */
|
||||
BKE_deform_flip_side_name(name_flip, name, false);
|
||||
BKE_deform_flip_side_name(name_flip, name, false, sizeof(name_flip));
|
||||
|
||||
ED_armature_bone_rename(arm, name, name_flip);
|
||||
|
||||
|
|
|
@ -817,10 +817,10 @@ static void select_similar_prefix(bArmature *arm, EditBone *ebone_act)
|
|||
{
|
||||
EditBone *ebone;
|
||||
|
||||
char body_tmp[MAX_VGROUP_NAME];
|
||||
char prefix_act[MAX_VGROUP_NAME];
|
||||
char body_tmp[MAXBONENAME];
|
||||
char prefix_act[MAXBONENAME];
|
||||
|
||||
BKE_deform_split_prefix(ebone_act->name, prefix_act, body_tmp);
|
||||
BKE_deform_split_prefix(ebone_act->name, prefix_act, body_tmp, sizeof(ebone_act->name));
|
||||
|
||||
if (prefix_act[0] == '\0')
|
||||
return;
|
||||
|
@ -828,8 +828,8 @@ static void select_similar_prefix(bArmature *arm, EditBone *ebone_act)
|
|||
/* Find matches */
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_SELECTABLE(arm, ebone)) {
|
||||
char prefix_other[MAX_VGROUP_NAME];
|
||||
BKE_deform_split_prefix(ebone->name, prefix_other, body_tmp);
|
||||
char prefix_other[MAXBONENAME];
|
||||
BKE_deform_split_prefix(ebone->name, prefix_other, body_tmp, sizeof(ebone->name));
|
||||
if (STREQ(prefix_act, prefix_other)) {
|
||||
ED_armature_ebone_select_set(ebone, true);
|
||||
}
|
||||
|
@ -841,10 +841,10 @@ static void select_similar_suffix(bArmature *arm, EditBone *ebone_act)
|
|||
{
|
||||
EditBone *ebone;
|
||||
|
||||
char body_tmp[MAX_VGROUP_NAME];
|
||||
char suffix_act[MAX_VGROUP_NAME];
|
||||
char body_tmp[MAXBONENAME];
|
||||
char suffix_act[MAXBONENAME];
|
||||
|
||||
BKE_deform_split_suffix(ebone_act->name, body_tmp, suffix_act);
|
||||
BKE_deform_split_suffix(ebone_act->name, body_tmp, suffix_act, sizeof(ebone_act->name));
|
||||
|
||||
if (suffix_act[0] == '\0')
|
||||
return;
|
||||
|
@ -852,8 +852,8 @@ static void select_similar_suffix(bArmature *arm, EditBone *ebone_act)
|
|||
/* Find matches */
|
||||
for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
|
||||
if (EBONE_SELECTABLE(arm, ebone)) {
|
||||
char suffix_other[MAX_VGROUP_NAME];
|
||||
BKE_deform_split_suffix(ebone->name, body_tmp, suffix_other);
|
||||
char suffix_other[MAXBONENAME];
|
||||
BKE_deform_split_suffix(ebone->name, body_tmp, suffix_other, sizeof(ebone->name));
|
||||
if (STREQ(suffix_act, suffix_other)) {
|
||||
ED_armature_ebone_select_set(ebone, true);
|
||||
}
|
||||
|
|
|
@ -360,7 +360,7 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
|
|||
if (dgroup && mirror) {
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, dgroup->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, dgroup->name, false, sizeof(name_flip));
|
||||
dgroupflip[j] = defgroup_find_name(ob, name_flip);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ EditBone *ED_armature_bone_get_mirrored(const ListBase *edbo, EditBone *ebo)
|
|||
if (ebo == NULL)
|
||||
return NULL;
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, ebo->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, ebo->name, false, sizeof(name_flip));
|
||||
|
||||
if (!STREQ(name_flip, ebo->name)) {
|
||||
return ED_armature_bone_find_name(edbo, name_flip);
|
||||
|
|
|
@ -286,7 +286,7 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, bPoseChannel *chan, const bo
|
|||
|
||||
/* get the name - if flipping, we must flip this first */
|
||||
if (flip)
|
||||
BKE_deform_flip_side_name(name, chan->name, false);
|
||||
BKE_deform_flip_side_name(name, chan->name, false, sizeof(name));
|
||||
else
|
||||
BLI_strncpy(name, chan->name, sizeof(name));
|
||||
|
||||
|
|
|
@ -1131,7 +1131,7 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, primbase->object->id.name + 2, true);
|
||||
BKE_deform_flip_side_name(name_flip, primbase->object->id.name + 2, true, sizeof(name_flip));
|
||||
|
||||
if (!STREQ(name_flip, primbase->object->id.name + 2)) {
|
||||
Object *ob = (Object *)BKE_libblock_find_name(ID_OB, name_flip);
|
||||
|
|
|
@ -275,7 +275,7 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
|
|||
int mirrdef;
|
||||
char name_flip[MAXBONENAME];
|
||||
|
||||
BKE_deform_flip_side_name(name_flip, defgroup->name, false);
|
||||
BKE_deform_flip_side_name(name_flip, defgroup->name, false, sizeof(name_flip));
|
||||
mirrdef = defgroup_name_index(ob, name_flip);
|
||||
if (mirrdef == -1) {
|
||||
if (BKE_defgroup_new(ob, name_flip)) {
|
||||
|
|
Loading…
Reference in New Issue