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
This commit is contained in:
2007-04-27 11:16:35 +00:00
parent 0a9dc31c8b
commit 01335fc7bb
7 changed files with 79 additions and 66 deletions

View File

@@ -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

View 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)
}
}
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;
}
}
}

View 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! */

View 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 );

View 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"

View 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;

View 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"