From e4cc1c3f2c3e5a85fbf4f7f2757b09544dd556ee Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 26 Apr 2011 07:17:21 +0000 Subject: 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. --- source/blender/blenkernel/intern/material.c | 34 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'source/blender/blenkernel/intern/material.c') diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 130bc798ff1..fd58dc2dfc0 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -267,6 +267,14 @@ Material *localize_material(Material *ma) return man; } +static void extern_local_material(Material *ma) +{ + int i; + for(i=0; i < MAX_MTEX; i++) { + if(ma->mtex[i]) id_lib_extern((ID *)ma->mtex[i]->tex); + } +} + void make_local_material(Material *ma) { Main *bmain= G.main; @@ -286,11 +294,9 @@ void make_local_material(Material *ma) if(ma->id.us==1) { ma->id.lib= NULL; ma->id.flag= LIB_LOCAL; - new_id(NULL, (ID *)ma, NULL); - for(a=0; amtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex); - } - + + new_id(&bmain->mat, (ID *)ma, NULL); + extern_local_material(ma); return; } @@ -350,12 +356,9 @@ void make_local_material(Material *ma) if(local && lib==0) { ma->id.lib= NULL; ma->id.flag= LIB_LOCAL; - - for(a=0; amtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex); - } - - new_id(NULL, (ID *)ma, NULL); + + new_id(&bmain->mat, (ID *)ma, NULL); + extern_local_material(ma); } else if(local && lib) { @@ -429,6 +432,15 @@ void make_local_material(Material *ma) } } +/* for curve, mball, mesh types */ +void extern_local_matarar(struct Material **matar, short totcol) +{ + short i; + for(i= 0; i < totcol; i++) { + id_lib_extern((ID *)matar[i]); + } +} + Material ***give_matarar(Object *ob) { Mesh *me; -- cgit v1.2.3