edits ontop of Alex's patch from r41292.
[blender.git] / source / blender / blenkernel / intern / mesh.c
index 810e7c2..5c7d927 100644 (file)
@@ -1,10 +1,4 @@
-
-/*  mesh.c
- *
- *  
- * 
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -247,39 +241,26 @@ Mesh *copy_mesh(Mesh *me)
        return men;
 }
 
-static void make_local_tface(Main *bmain, Mesh *me)
+static void expand_local_mesh(Mesh *me)
 {
-       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);
+       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);
                                        }
                                }
                        }
                }
        }
-}
-
-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);
@@ -299,11 +280,8 @@ void make_local_mesh(Mesh *me)
 
        if(me->id.lib==NULL) return;
        if(me->id.us==1) {
-               me->id.lib= NULL;
-               me->id.flag= LIB_LOCAL;
-
-               new_id(&bmain->mesh, (ID *)me, NULL);
-               expand_local_mesh(bmain, me);
+               id_clear_lib_data(bmain, (ID *)me);
+               expand_local_mesh(me);
                return;
        }
 
@@ -315,11 +293,8 @@ void make_local_mesh(Mesh *me)
        }
 
        if(local && lib==0) {
-               me->id.lib= NULL;
-               me->id.flag= LIB_LOCAL;
-
-               new_id(&bmain->mesh, (ID *)me, NULL);
-               expand_local_mesh(bmain, me);
+               id_clear_lib_data(bmain, (ID *)me);
+               expand_local_mesh(me);
        }
        else if(local && lib) {
                Mesh *men= copy_mesh(me);
@@ -1606,3 +1581,19 @@ void mesh_translate(Mesh *me, float offset[3], int do_keys)
                }
        }
 }
+
+
+void BKE_mesh_ensure_navmesh(Mesh *me)
+{
+       if (!CustomData_has_layer(&me->fdata, CD_RECAST)) {
+               int i;
+               int numFaces = me->totface;
+               int* recastData;
+               CustomData_add_layer_named(&me->fdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData");
+               recastData = (int*)CustomData_get_layer(&me->fdata, CD_RECAST);
+               for (i=0; i<numFaces; i++) {
+                       recastData[i] = i+1;
+               }
+               CustomData_add_layer_named(&me->fdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData");
+       }
+}