Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / source / blender / blenkernel / intern / mesh.c
index a5bf39d..2b92cdf 100644 (file)
@@ -193,7 +193,6 @@ Mesh *add_mesh(const char *name)
        me->smoothresh= 30;
        me->texflag= AUTOSPACE;
        me->flag= ME_TWOSIDED;
-       me->bb= unit_boundbox();
        me->drawflag= ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES;
        
        return me;
@@ -241,26 +240,39 @@ Mesh *copy_mesh(Mesh *me)
        return men;
 }
 
-static void expand_local_mesh(Mesh *me)
+static void make_local_tface(Main *bmain, Mesh *me)
 {
-       id_lib_extern((ID *)me->texcomesh);
-
-       if(me->mtface) {
-               MTFace *tface;
-               int a, i;
-
-               for(i=0; i<me->fdata.totlayer; i++) {
-                       if(me->fdata.layers[i].type == CD_MTFACE) {
-                               tface= (MTFace*)me->fdata.layers[i].data;
-
-                               for(a=0; a<me->totface; a++, tface++) {
-                                       if(tface->tpage) {
-                                               id_lib_extern((ID *)tface->tpage);
+       MTFace *tface;
+       Image *ima;
+       int a, i;
+       
+       for(i=0; i<me->fdata.totlayer; i++) {
+               if(me->fdata.layers[i].type == CD_MTFACE) {
+                       tface= (MTFace*)me->fdata.layers[i].data;
+                       
+                       for(a=0; a<me->totface; a++, tface++) {
+                               /* special case: ima always local immediately */
+                               if(tface->tpage) {
+                                       ima= tface->tpage;
+                                       if(ima->id.lib) {
+                                               ima->id.lib= NULL;
+                                               ima->id.flag= LIB_LOCAL;
+                                               new_id(&bmain->image, (ID *)ima, NULL);
                                        }
                                }
                        }
                }
        }
+}
+
+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);
@@ -280,8 +292,11 @@ void make_local_mesh(Mesh *me)
 
        if(me->id.lib==NULL) return;
        if(me->id.us==1) {
-               id_clear_lib_data(&bmain->mesh, (ID *)me);
-               expand_local_mesh(me);
+               me->id.lib= NULL;
+               me->id.flag= LIB_LOCAL;
+
+               new_id(&bmain->mesh, (ID *)me, NULL);
+               expand_local_mesh(bmain, me);
                return;
        }
 
@@ -293,8 +308,11 @@ void make_local_mesh(Mesh *me)
        }
 
        if(local && lib==0) {
-               id_clear_lib_data(&bmain->mesh, (ID *)me);
-               expand_local_mesh(me);
+               me->id.lib= NULL;
+               me->id.flag= LIB_LOCAL;
+
+               new_id(&bmain->mesh, (ID *)me, NULL);
+               expand_local_mesh(bmain, me);
        }
        else if(local && lib) {
                Mesh *men= copy_mesh(me);