diff options
Diffstat (limited to 'source/blender/blenkernel/intern/deform.c')
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 2b44a10e913..aa6220e88bc 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -69,7 +69,7 @@ #endif -void copy_defgroups(ListBase *outbase, ListBase *inbase) +void copy_defgroups (ListBase *outbase, ListBase *inbase) { bDeformGroup *defgroup, *defgroupn; @@ -81,7 +81,7 @@ void copy_defgroups(ListBase *outbase, ListBase *inbase) } } -bDeformGroup* copy_defgroup (bDeformGroup *ingroup) +bDeformGroup *copy_defgroup (bDeformGroup *ingroup) { bDeformGroup *outgroup; @@ -98,22 +98,22 @@ bDeformGroup* copy_defgroup (bDeformGroup *ingroup) return outgroup; } -bDeformGroup *get_named_vertexgroup(Object *ob, char *name) +bDeformGroup *get_named_vertexgroup (Object *ob, char *name) { /* return a pointer to the deform group with this name * or return NULL otherwise. */ bDeformGroup *curdef; - for (curdef = ob->defbase.first; curdef; curdef=curdef->next){ - if (!strcmp(curdef->name, name)){ + for (curdef = ob->defbase.first; curdef; curdef=curdef->next) { + if (!strcmp(curdef->name, name)) { return curdef; } } return NULL; } -int get_defgroup_num (Object *ob, bDeformGroup *dg) +int get_defgroup_num (Object *ob, bDeformGroup *dg) { /* Fetch the location of this deform group * within the linked list of deform groups. @@ -123,7 +123,7 @@ int get_defgroup_num (Object *ob, bDeformGroup *dg) * deform blah blah deform */ - bDeformGroup *eg; + bDeformGroup *eg; int def_nr; eg = ob->defbase.first; @@ -131,13 +131,13 @@ int get_defgroup_num (Object *ob, bDeformGroup *dg) /* loop through all deform groups */ - while (eg != NULL){ + while (eg != NULL) { /* if the current deform group is * the one we are after, return * def_nr */ - if (eg == dg){ + if (eg == dg) { break; } ++def_nr; @@ -154,3 +154,56 @@ int get_defgroup_num (Object *ob, bDeformGroup *dg) } +void unique_vertexgroup_name (bDeformGroup *dg, Object *ob) +{ + bDeformGroup *curdef; + int number; + int exists = 0; + char tempname[64]; + char *dot; + + if (!ob) + return; + + /* See if we are given an empty string */ + if (dg->name[0] == '\0') { + /* give it default name first */ + strcpy (dg->name, "Group"); + } + + /* See if we even need to do this */ + for (curdef = ob->defbase.first; curdef; curdef=curdef->next) { + if (dg!=curdef) { + if (!strcmp(curdef->name, dg->name)) { + exists = 1; + break; + } + } + } + + if (!exists) + return; + + /* Strip off the suffix */ + dot=strchr(dg->name, '.'); + if (dot) + *dot=0; + + for (number = 1; number <=999; number++) { + sprintf (tempname, "%s.%03d", dg->name, number); + + exists = 0; + for (curdef=ob->defbase.first; curdef; curdef=curdef->next) { + if (dg!=curdef) { + if (!strcmp (curdef->name, tempname)) { + exists = 1; + break; + } + } + } + if (!exists) { + BLI_strncpy (dg->name, tempname, 32); + return; + } + } +} |