Bugfix:
authorJoshua Leung <aligorith@gmail.com>
Fri, 27 Apr 2007 11:16:35 +0000 (11:16 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 27 Apr 2007 11:16:35 +0000 (11:16 +0000)
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

source/blender/blenkernel/BKE_deform.h
source/blender/blenkernel/intern/deform.c
source/blender/blenloader/intern/readfile.c
source/blender/include/BIF_editdeform.h
source/blender/src/buttons_editing.c
source/blender/src/editdeform.c
source/blender/src/outliner.c

index 5888975feb6da88de2956b3d60995f9e1dd6e2a9..de0dddabfd3f079c852e97d7756515b628428503 100644 (file)
@@ -43,9 +43,10 @@ struct ListBase;
 struct bDeformGroup;
 
 void copy_defgroups (struct ListBase *lb1, struct ListBase *lb2);
-struct bDeformGroupcopy_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
 
index 2b44a10e913eb266a124005a1c226550d47aa002..aa6220e88bcb0869115a3aec4023880559c6ce86 100644 (file)
@@ -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)
        }
 }
 
-bDeformGroupcopy_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;
+               }
+       }       
+}
index 7e6f246be7ab800926cac40ce7640d529b159f16..70f8422968c1dcf82ef4c1605a5edc752e6cbd71 100644 (file)
@@ -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! */
index 4788f1f683790439cda54438d69711b7064d8a36..69f036528874d839892ab3fa4c03f8bb8695df4b 100644 (file)
@@ -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 );
index ec9a00206851b94a6c67756849fa7b9459b2e85d..a64f461b0a0d9da24ae1fb19aa27b2ed47f83e94 100644 (file)
@@ -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"
index 29324c28bf0f26430194a557690f877974131487..305d01a8aea620a9b7866705db0021fbe5cd58df 100644 (file)
@@ -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;
index e29275e40d01fcfb1383a9c6cd56dfc8b11a5602..97d862383bd30ba700b09c6ffe26830f25a7166c 100644 (file)
@@ -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"