diff options
author | Joshua Leung <aligorith@gmail.com> | 2007-04-27 15:16:35 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2007-04-27 15:16:35 +0400 |
commit | 01335fc7bbc339183a8828b37f905608f7d1a028 (patch) | |
tree | 971ebe3c746ece8ceecc40d67be5e4ad2664c3fd | |
parent | 0a9dc31c8b05ad479eaf22cf99300a9385d7d8c7 (diff) |
Bugfix:
Previous versions of Blender allowed Vertex Groups to be nameless, which
shouldn't be allowed. This caused problems with rigs from previous versions of Blender being loaded in 2.43+ versions, as the new VGroup feature for the
Armature modifier mis-identified these nameless group(s) as being the Vertex Group
to be used. As well as the checks done when renaming VGroups (from another commit), files created prior to and in 2.43 will have all such groups given default
names.
Code notes:
* I've moved the unique_vertexgroup_name function from src to blenkernel like for
constraints
* Formatting in deform.c tidied up a bit
-rw-r--r-- | source/blender/blenkernel/BKE_deform.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 71 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 12 | ||||
-rw-r--r-- | source/blender/include/BIF_editdeform.h | 1 | ||||
-rw-r--r-- | source/blender/src/buttons_editing.c | 1 | ||||
-rw-r--r-- | source/blender/src/editdeform.c | 54 | ||||
-rw-r--r-- | source/blender/src/outliner.c | 1 |
7 files changed, 79 insertions, 66 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 5888975feb6..de0dddabfd3 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -43,9 +43,10 @@ struct ListBase; struct bDeformGroup; void copy_defgroups (struct ListBase *lb1, struct ListBase *lb2); -struct bDeformGroup* copy_defgroup (struct bDeformGroup *ingroup); +struct bDeformGroup *copy_defgroup (struct bDeformGroup *ingroup); struct bDeformGroup *get_named_vertexgroup (Object *ob, char *name); -int get_defgroup_num (struct Object *ob, struct bDeformGroup *dg); +int get_defgroup_num (struct Object *ob, struct bDeformGroup *dg); +void unique_vertexgroup_name (struct bDeformGroup *dg, struct Object *ob); #endif 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; + } + } +} diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 7e6f246be7a..70f8422968c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6369,11 +6369,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } if(main->versionfile <= 243) { + Object *ob= main->object.first; Camera *cam = main->camera.first; for(; cam; cam= cam->id.next) { cam->angle= 360.0f * atan(16.0f/cam->lens) / M_PI; } + + for(; ob; ob= ob->id.next) { + bDeformGroup *curdef; + + for(curdef= ob->defbase.first; curdef; curdef=curdef->next) { + /* replace an empty-string name with unique name */ + if (curdef->name[0] == '\0') { + unique_vertexgroup_name(curdef, ob); + } + } + } } /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ diff --git a/source/blender/include/BIF_editdeform.h b/source/blender/include/BIF_editdeform.h index 4788f1f6837..69f03652887 100644 --- a/source/blender/include/BIF_editdeform.h +++ b/source/blender/include/BIF_editdeform.h @@ -43,7 +43,6 @@ struct MDeformVert; struct MDeformWeight; struct bDeformGroup; -void unique_vertexgroup_name (struct bDeformGroup *dg, struct Object *ob); struct bDeformGroup *add_defgroup_name (struct Object *ob, char *name); void add_defgroup (struct Object *ob); void del_defgroup_in_object_mode ( Object *ob ); diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index ec9a0020685..a64f461b0a0 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -80,6 +80,7 @@ #include "BKE_curve.h" #include "BKE_customdata.h" #include "BKE_colortools.h" +#include "BKE_deform.h" #include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_key.h" diff --git a/source/blender/src/editdeform.c b/source/blender/src/editdeform.c index 29324c28bf0..305d01a8aea 100644 --- a/source/blender/src/editdeform.c +++ b/source/blender/src/editdeform.c @@ -772,60 +772,6 @@ void remove_verts_defgroup (int allverts) } } -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; - } - } -} - void vertexgroup_select_by_name(Object *ob, char *name) { bDeformGroup *curdef; diff --git a/source/blender/src/outliner.c b/source/blender/src/outliner.c index e29275e40d0..97d862383bd 100644 --- a/source/blender/src/outliner.c +++ b/source/blender/src/outliner.c @@ -59,6 +59,7 @@ #include "BLI_blenlib.h" #include "BKE_constraint.h" +#include "BKE_deform.h" #include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_group.h" |