diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-04-26 11:17:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-04-26 11:17:21 +0400 |
commit | e4cc1c3f2c3e5a85fbf4f7f2757b09544dd556ee (patch) | |
tree | 1d134f4085ba2d90e854c47848c6fc82704667bb /source/blender/blenkernel/intern/mesh.c | |
parent | 461a7c5c8185d0504c63ddc8de0b2c765e72be4b (diff) |
fix [#27178] Material links lost when making mesh data local
- making local object data - Curve/Mesh/MBall lost references to linked materials.
- joining a linked mesh object into a local one lost the link.
As well as these reported bugs, checked all local functions for consistency/correctness and found other cases which would also fail.
- making local metaball didn't ensure unique ID name.
- make_local_armature() was missing check for object users - main body of code would never run.
- local particles didn't set the dupli-group or textures to extern.
checked all local functions for consistency/correctness.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 532e96f3031..45a60b842a7 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -247,7 +247,7 @@ Mesh *copy_mesh(Mesh *me) return men; } -void make_local_tface(Mesh *me) +static void make_local_tface(Main *bmain, Mesh *me) { MTFace *tface; Image *ima; @@ -264,7 +264,7 @@ void make_local_tface(Mesh *me) if(ima->id.lib) { ima->id.lib= NULL; ima->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)ima, NULL); + new_id(&bmain->image, (ID *)ima, NULL); } } } @@ -272,58 +272,65 @@ void make_local_tface(Mesh *me) } } +static void expand_local_mesh(Main *bmain, Mesh *me) +{ + id_lib_extern((ID *)me->texcomesh); + + if(me->mtface) { + /* why is this an exception? - should not really make local when extern'ing - campbell */ + make_local_tface(bmain, me); + } + + if(me->mat) { + extern_local_matarar(me->mat, me->totcol); + } +} + void make_local_mesh(Mesh *me) { Main *bmain= G.main; Object *ob; - Mesh *men; int local=0, lib=0; /* - only lib users: do nothing - * - only local users: set flag - * - mixed: make copy - */ - + * - only local users: set flag + * - mixed: make copy + */ + if(me->id.lib==NULL) return; if(me->id.us==1) { me->id.lib= NULL; me->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)me, NULL); - - if(me->mtface) make_local_tface(me); - + + new_id(&bmain->mesh, (ID *)me, NULL); + expand_local_mesh(bmain, me); return; } - - ob= bmain->object.first; - while(ob) { - if( me==get_mesh(ob) ) { + + for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + if(me == ob->data) { if(ob->id.lib) lib= 1; else local= 1; } - ob= ob->id.next; } - + if(local && lib==0) { me->id.lib= NULL; me->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)me, NULL); - - if(me->mtface) make_local_tface(me); - + + new_id(&bmain->mesh, (ID *)me, NULL); + expand_local_mesh(bmain, me); } else if(local && lib) { - men= copy_mesh(me); + Mesh *men= copy_mesh(me); men->id.us= 0; - - ob= bmain->object.first; - while(ob) { - if( me==get_mesh(ob) ) { + + for(ob= bmain->object.first; ob; ob= ob->id.next) { + if(me == ob->data) { if(ob->id.lib==NULL) { set_mesh(ob, men); } } - ob= ob->id.next; } } } |