merge with trunk/2.5 at r24463
[blender.git] / source / blender / editors / mesh / mesh_data.c
index 94a7dbebb9caafd52509243739bb2db975fac4dd..a1ec4f3d5d7e22db498e42e5189f52cade70203b 100644 (file)
@@ -38,6 +38,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_context.h"
@@ -48,6 +49,7 @@
 #include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_report.h"
+#include "BKE_tessmesh.h"
 
 #include "BLI_arithb.h"
 #include "BLI_editVert.h"
 #include "ED_object.h"
 #include "ED_view3d.h"
 
+#include "RE_render_ext.h"
+
 #include "mesh_intern.h"
 
 static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
 {
        Mesh *me = ob->data;
-       CustomData *data= (me->edit_mesh)? &me->edit_mesh->fdata: &me->fdata;
+       CustomData *data= (me->edit_btmesh)? &me->edit_btmesh->bm->pdata: &me->pdata;
        void *actlayerdata, *rndlayerdata, *clonelayerdata, *masklayerdata, *layerdata=layer->data;
        int type= layer->type;
        int index= CustomData_get_layer_index(data, type);
-       int i, actindex, rndindex, cloneindex, maskindex;
+       int i, actindex, rndindex, cloneindex, maskindex, tot = me->totpoly;
        
+       if (layer->type == CD_MLOOPCOL) {
+               data = (me->edit_btmesh)? &me->edit_btmesh->bm->ldata: &me->ldata;
+               tot = me->totloop;
+       }
+
        /* ok, deleting a non-active layer needs to preserve the active layer indices.
          to do this, we store a pointer to the .data member of both layer and the active layer,
          (to detect if we're deleting the active layer or not), then use the active
@@ -87,15 +96,15 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
        masklayerdata = data->layers[CustomData_get_mask_layer_index(data, type)].data;
        CustomData_set_layer_active(data, type, layer - &data->layers[index]);
 
-       if(me->edit_mesh) {
-               EM_free_data_layer(me->edit_mesh, data, type);
+       if(me->edit_btmesh) {
+               BM_free_data_layer(me->edit_btmesh->bm, data, type);
        }
        else {
-               CustomData_free_layer_active(data, type, me->totface);
+               CustomData_free_layer_active(data, type, tot);
                mesh_update_customdata_pointers(me);
        }
 
-       if(!CustomData_has_layer(data, type) && (type == CD_MCOL && (ob->mode & OB_MODE_VERTEX_PAINT)))
+       if(!CustomData_has_layer(data, type) && (type == CD_MLOOPCOL && (ob->mode & OB_MODE_VERTEX_PAINT)))
                ED_object_toggle_modes(C, OB_MODE_VERTEX_PAINT);
 
        /* reconstruct active layer */
@@ -158,30 +167,30 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
 
 int ED_mesh_uv_texture_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
 {
-       EditMesh *em;
+       BMEditMesh *em;
        int layernum;
 
-       if(me->edit_mesh) {
-               em= me->edit_mesh;
+       if(me->edit_btmesh) {
+               em= me->edit_btmesh;
 
-               layernum= CustomData_number_of_layers(&em->fdata, CD_MTFACE);
+               layernum= CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
                if(layernum >= MAX_MTFACE)
                        return OPERATOR_CANCELLED;
 
-               EM_add_data_layer(em, &em->fdata, CD_MTFACE);
-               CustomData_set_layer_active(&em->fdata, CD_MTFACE, layernum);
+               BM_add_data_layer(em->bm, &em->bm->pdata, MAX_MTFACE);
+               CustomData_set_layer_active(&em->bm->pdata, MAX_MTFACE, layernum);
        }
        else {
-               layernum= CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+               layernum= CustomData_number_of_layers(&me->pdata, MAX_MTFACE);
                if(layernum >= MAX_MTFACE)
                        return OPERATOR_CANCELLED;
 
                if(me->mtface)
-                       CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface);
+                       CustomData_add_layer(&me->pdata, MAX_MTFACE, CD_DUPLICATE, me->mtpoly, me->totpoly);
                else
-                       CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface);
+                       CustomData_add_layer(&me->pdata, MAX_MTFACE, CD_DEFAULT, NULL, me->totpoly);
 
-               CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum);
+               CustomData_set_layer_active(&me->pdata, MAX_MTFACE, layernum);
                mesh_update_customdata_pointers(me);
        }
 
@@ -196,8 +205,8 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
        CustomDataLayer *cdl;
        int index;
 
-       index= CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
-       cdl= (index == -1)? NULL: &me->fdata.layers[index];
+       index= CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
+       cdl= (index == -1)? NULL: &me->pdata.layers[index];
 
        if(!cdl)
                return 0;
@@ -211,37 +220,39 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
 
 int ED_mesh_color_add(bContext *C, Scene *scene, Object *ob, Mesh *me)
 {
-       EditMesh *em;
-       MCol *mcol;
+       BMEditMesh *em;
+       MLoopCol *mcol;
        int layernum;
 
-       if(me->edit_mesh) {
-               em= me->edit_mesh;
+       if(me->edit_btmesh) {
+               em= me->edit_btmesh;
 
-               layernum= CustomData_number_of_layers(&em->fdata, CD_MCOL);
+               layernum= CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPCOL);
                if(layernum >= MAX_MCOL)
                        return 0;
 
-               EM_add_data_layer(em, &em->fdata, CD_MCOL);
-               CustomData_set_layer_active(&em->fdata, CD_MCOL, layernum);
+               BM_add_data_layer(em->bm, &em->bm->pdata, CD_MLOOPCOL);
+               CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPCOL, layernum);
        }
        else {
-               layernum= CustomData_number_of_layers(&me->fdata, CD_MCOL);
-               if(layernum >= MAX_MCOL)
+               layernum= CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
+               if(layernum >= CD_MLOOPCOL)
                        return 0;
 
-               mcol= me->mcol;
+               mcol= me->mloopcol;
 
-               if(me->mcol)
-                       CustomData_add_layer(&me->fdata, CD_MCOL, CD_DUPLICATE, me->mcol, me->totface);
+               if(me->mloopcol)
+                       CustomData_add_layer(&me->ldata, CD_MLOOPCOL, CD_DUPLICATE, me->mloopcol, me->totloop);
                else
-                       CustomData_add_layer(&me->fdata, CD_MCOL, CD_DEFAULT, NULL, me->totface);
+                       CustomData_add_layer(&me->ldata, CD_MLOOPCOL, CD_DEFAULT, NULL, me->totloop);
 
-               CustomData_set_layer_active(&me->fdata, CD_MCOL, layernum);
+               CustomData_set_layer_active(&me->ldata, CD_MLOOPCOL, layernum);
                mesh_update_customdata_pointers(me);
 
+               /*BMESH_TODO
                if(!mcol)
                        shadeMeshMCol(scene, ob, me);
+               */
        }
 
        DAG_id_flush_update(&me->id, OB_RECALC_DATA);
@@ -255,8 +266,8 @@ int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me)
        CustomDataLayer *cdl;
        int index;
 
-       index= CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
-       cdl= (index == -1)? NULL: &me->fdata.layers[index];
+       index= CustomData_get_active_layer_index(&me->pdata, CD_MLOOPCOL);
+       cdl= (index == -1)? NULL: &me->pdata.layers[index];
 
        if(!cdl)
                return 0;
@@ -389,13 +400,15 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot)
 
 static int sticky_add_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d= CTX_wm_view3d(C);
        Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
        Mesh *me= ob->data;
 
-       if(me->msticky)
-               return OPERATOR_CANCELLED;
+       /*if(me->msticky)
+               return OPERATOR_CANCELLED;*/
 
-       // XXX RE_make_sticky();
+       RE_make_sticky(scene, v3d);
 
        DAG_id_flush_update(&me->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
@@ -503,9 +516,9 @@ static void mesh_calc_edges(Mesh *mesh, int update)
                if(update && (med_orig=BLI_edgehashIterator_getValue(ehi))) {
                        *med= *med_orig; /* copy from the original */
                } else {
-                       BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
-                       med->flag = ME_EDGEDRAW|ME_EDGERENDER;
-               }
+               BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
+               med->flag = ME_EDGEDRAW|ME_EDGERENDER;
+       }
        }
        BLI_edgehashIterator_free(ehi);
 
@@ -633,7 +646,7 @@ static void mesh_add_faces(Mesh *mesh, int len)
 
 void ED_mesh_geometry_add(Mesh *mesh, ReportList *reports, int verts, int edges, int faces)
 {
-       if(mesh->edit_mesh) {
+       if(mesh->edit_btmesh) {
                BKE_report(reports, RPT_ERROR, "Can't add geometry in edit mode.");
                return;
        }