edits ontop of Alex's patch from r41292.
[blender.git] / source / blender / blenkernel / intern / mesh.c
index 45a60b8..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);
@@ -917,7 +892,7 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int
                                mface->v2= startvert+index[2];
                                mface->v3= startvert+index[1];
                                mface->v4= 0;
-                               mface->mat_nr= (unsigned char)dl->col;
+                               mface->mat_nr= dl->col;
                                test_index_face(mface, NULL, 0, 3);
 
                                if(smooth) mface->flag |= ME_SMOOTH;
@@ -966,7 +941,7 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int
                                        mface->v2= p3;
                                        mface->v3= p4;
                                        mface->v4= p2;
-                                       mface->mat_nr= (unsigned char)dl->col;
+                                       mface->mat_nr= dl->col;
                                        test_index_face(mface, NULL, 0, 4);
 
                                        if(smooth) mface->flag |= ME_SMOOTH;
@@ -1252,12 +1227,12 @@ void mesh_to_curve(Scene *scene, Object *ob)
        }
 }
 
-void mesh_delete_material_index(Mesh *me, int index)
+void mesh_delete_material_index(Mesh *me, short index)
 {
+       MFace *mf;
        int i;
 
-       for (i=0; i<me->totface; i++) {
-               MFace *mf = &((MFace*) me->mface)[i];
+       for (i=0, mf=me->mface; i<me->totface; i++, mf++) {
                if (mf->mat_nr && mf->mat_nr>=index) 
                        mf->mat_nr--;
        }
@@ -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");
+       }
+}