svn merge ^/trunk/blender -r42521:42550
[blender.git] / source / blender / editors / space_view3d / drawmesh.c
index 6dd362b827f6ec57508e048c54b05526368de512..2c0af90a4d6bd3851d23c9c0042bf7455cf43619 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_edgehash.h"
@@ -46,6 +47,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_effect.h"
@@ -53,6 +55,7 @@
 #include "BKE_material.h"
 #include "BKE_paint.h"
 #include "BKE_property.h"
+#include "BKE_tessmesh.h"
 #include "BKE_scene.h"
 
 #include "BIF_gl.h"
@@ -150,7 +153,7 @@ static int draw_mesh_face_select__drawFaceOptsInv(void *userData, int index)
 {
        Mesh *me = (Mesh*)userData;
 
-       MFace *mface = &me->mface[index];
+       MPoly *mface = &me->mpoly[index];
        if(!(mface->flag&ME_HIDE) && !(mface->flag&ME_FACE_SEL))
                return 2; /* Don't set color */
        else
@@ -427,16 +430,16 @@ static int draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr)
 }
 static void add_tface_color_layer(DerivedMesh *dm)
 {
-       MTFace *tface = DM_get_face_data_layer(dm, CD_MTFACE);
-       MFace *mface = DM_get_face_data_layer(dm, CD_MFACE);
+       MTFace *tface = DM_get_poly_data_layer(dm, CD_MTFACE);
+       MFace *mface = dm->getTessFaceArray(dm);
        MCol *finalCol;
        int i,j;
-       MCol *mcol = dm->getFaceDataArray(dm, CD_WEIGHT_MCOL);
+       MCol *mcol = dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL);
        if(!mcol)
-               mcol = dm->getFaceDataArray(dm, CD_MCOL);
+               mcol = dm->getTessFaceDataArray(dm, CD_MCOL);
 
-       finalCol = MEM_mallocN(sizeof(MCol)*4*dm->getNumFaces(dm),"add_tface_color_layer");
-       for(i=0;i<dm->getNumFaces(dm);i++) {
+       finalCol = MEM_mallocN(sizeof(MCol)*4*dm->getNumTessFaces(dm),"add_tface_color_layer");
+       for(i=0;i<dm->getNumTessFaces(dm);i++) {
                Material *ma= give_current_material(Gtexdraw.ob, mface[i].mat_nr+1);
 
                if (ma && (ma->game.flag&GEMAT_INVISIBLE)) {
@@ -498,42 +501,68 @@ static void add_tface_color_layer(DerivedMesh *dm)
                        }
                }
        }
-       CustomData_add_layer( &dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numFaceData );
+       CustomData_add_layer( &dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numTessFaceData );
 }
 
 static int draw_tface_mapped__set_draw(void *userData, int index)
 {
        Mesh *me = (Mesh*)userData;
-       MTFace *tface = (me->mtface)? &me->mtface[index]: NULL;
-       MFace *mface = &me->mface[index];
-       const int matnr = mface->mat_nr;
-       if (mface->flag & ME_HIDE) return 0;
-       return draw_tface__set_draw(tface, (me->mcol != NULL), matnr);
+       MTexPoly *tpoly = (me->mtpoly)? &me->mtpoly[index]: NULL;
+       MPoly *mpoly = (me->mpoly)? &me->mpoly[index]: NULL;
+       MTFace mtf;
+       int matnr = me->mpoly[index].mat_nr;
+
+       BLI_assert(index >= 0 && index < me->totpoly);
+
+       if (mpoly && mpoly->flag&ME_HIDE) return 0;
+
+       memset(&mtf, 0, sizeof(mtf));
+       if (tpoly) {
+               mtf.flag = tpoly->flag;
+               mtf.tpage = tpoly->tpage;
+               mtf.transp = tpoly->transp;
+               mtf.mode = tpoly->mode;
+               mtf.tile = tpoly->tile;
+               mtf.unwrap = tpoly->unwrap;
+       }
+
+       return draw_tface__set_draw(&mtf, (me->mcol != NULL), matnr);
 }
 
 static int draw_em_tf_mapped__set_draw(void *userData, int index)
 {
-       struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data = userData;
-       EditMesh *em = data->em;
-       EditFace *efa= EM_get_face_for_index(index);
-       MTFace *tface;
-       int matnr;
+       struct {BMEditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data = userData;
+       BMEditMesh *em = data->em;
+       BMFace *efa= EDBM_get_face_for_index(em, index);
 
-       if (efa->h)
+       if (efa==NULL || BM_TestHFlag(efa, BM_HIDDEN)) {
                return 0;
+       }
+       else {
+               MTFace mtf= {{{0}}};
+               int matnr = efa->mat_nr;
+
+               if (data->has_mtface) {
+                       MTexPoly *tpoly = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
+                       mtf.flag = tpoly->flag;
+                       mtf.tpage = tpoly->tpage;
+                       mtf.transp = tpoly->transp;
+                       mtf.mode = tpoly->mode;
+                       mtf.tile = tpoly->tile;
+                       mtf.unwrap = tpoly->unwrap;
 
-       tface = data->has_mtface ? CustomData_em_get(&em->fdata, efa->data, CD_MTFACE) : NULL;
-       matnr = efa->mat_nr;
+               }
 
-       return draw_tface__set_draw_legacy(tface, data->has_mcol, matnr);
+               return draw_tface__set_draw_legacy(&mtf, data->has_mcol, matnr);
+       }
 }
 
 static int wpaint__setSolidDrawOptions(void *userData, int index, int *drawSmooth_r)
 {
        Mesh *me = (Mesh*)userData;
 
-       if (me->mat && me->mface) {
-               Material *ma= me->mat[me->mface[index].mat_nr];
+       if (me->mat && me->mpoly) {
+               Material *ma= me->mat[me->mpoly[index].mat_nr];
                if (ma && (ma->game.flag & GEMAT_INVISIBLE)) {
                        return 0;
                }
@@ -644,7 +673,7 @@ static int compareDrawOptions(void *userData, int cur_index, int next_index)
 
 static int compareDrawOptionsEm(void *userData, int cur_index, int next_index)
 {
-       struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data= userData;
+       struct {BMEditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data= userData;
 
        if(data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr)
                return 0;
@@ -669,13 +698,13 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
        glColor4f(1.0f,1.0f,1.0f,1.0f);
 
        if(ob->mode & OB_MODE_EDIT) {
-               struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} data;
+               struct {BMEditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} data;
 
-               data.em= me->edit_mesh;
-               data.has_mcol= CustomData_has_layer(&me->edit_mesh->fdata, CD_MCOL);
-               data.has_mtface= CustomData_has_layer(&me->edit_mesh->fdata, CD_MTFACE);
-               data.mf= DM_get_face_data_layer(dm, CD_MFACE);
-               data.tf= DM_get_face_data_layer(dm, CD_MTFACE);
+               data.em= me->edit_btmesh;
+               data.has_mcol= CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL);
+               data.has_mtface= CustomData_has_layer(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY);
+               data.mf= DM_get_tessface_data_layer(dm, CD_MFACE);
+               data.tf= DM_get_tessface_data_layer(dm, CD_MTFACE);
 
                dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, compareDrawOptionsEm, &data);
        }
@@ -683,7 +712,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                if(ob->mode & OB_MODE_WEIGHT_PAINT)
                        dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, GPU_enable_material, NULL, me, 1);
                else
-                       dm->drawMappedFacesTex(dm, me->mface ? draw_tface_mapped__set_draw : NULL, NULL, me);
+                       dm->drawMappedFacesTex(dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, NULL, me);
        }
        else {
                if(GPU_buffer_legacy(dm)) {
@@ -698,8 +727,8 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                        if(!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL))
                                add_tface_color_layer(dm);
 
-                       userData.mf = DM_get_face_data_layer(dm, CD_MFACE);
-                       userData.tf = DM_get_face_data_layer(dm, CD_MTFACE);
+                       userData.mf = DM_get_tessface_data_layer(dm, CD_MFACE);
+                       userData.tf = DM_get_tessface_data_layer(dm, CD_MTFACE);
 
                        dm->drawFacesTex(dm, draw_tface__set_draw, compareDrawOptions, &userData);
                }
@@ -808,17 +837,19 @@ static int tex_mat_set_face_mesh_cb(void *userData, int index)
        /* faceselect mode face hiding */
        TexMatCallback *data= (TexMatCallback*)userData;
        Mesh *me = (Mesh*)data->me;
-       MFace *mface = &me->mface[index];
+       MPoly *mface = &me->mpoly[index];
 
        return !(mface->flag & ME_HIDE);
 }
 
-static int tex_mat_set_face_editmesh_cb(void *UNUSED(userData), int index)
+static int tex_mat_set_face_editmesh_cb(void *userData, int index)
 {
        /* editmode face hiding */
-       EditFace *efa= EM_get_face_for_index(index);
+       TexMatCallback *data= (TexMatCallback*)userData;
+       Mesh *me = (Mesh*)data->me;
+       BMFace *efa= EDBM_get_face_for_index(me->edit_btmesh, index);
 
-       return !(efa->h);
+       return !BM_TestHFlag(efa, BM_HIDDEN);
 }
 
 void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int draw_flags)