svn merge -r39286:39385 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / space_view3d / drawmesh.c
index 351be1ca4c922f5ff5ce6c21ed81f3b170133255..9a6e14fcbad7ce4575505728e01e7e2f33428c2a 100644 (file)
@@ -29,7 +29,6 @@
  *  \ingroup spview3d
  */
 
-
 #include <string.h>
 #include <math.h>
 
 
 #include "view3d_intern.h"     // own include
 
-/***/
+/**************************** Face Select Mode *******************************/
 
-       /* Flags for marked edges */
+/* Flags for marked edges */
 enum {
        eEdge_Visible = (1<<0),
        eEdge_Select = (1<<1),
 };
 
-       /* Creates a hash of edges to flags indicating
-        * adjacent tface select/active/etc flags.
-        */
+/* Creates a hash of edges to flags indicating selected/visible */
 static void get_marked_edge_info__orFlags(EdgeHash *eh, int v0, int v1, int flags)
 {
        int *flags_p;
 
-       if (!BLI_edgehash_haskey(eh, v0, v1)) {
+       if(!BLI_edgehash_haskey(eh, v0, v1))
                BLI_edgehash_insert(eh, v0, v1, NULL);
-       }
 
        flags_p = (int*) BLI_edgehash_lookup_p(eh, v0, v1);
        *flags_p |= flags;
@@ -99,26 +95,25 @@ static void get_marked_edge_info__orFlags(EdgeHash *eh, int v0, int v1, int flag
 static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me)
 {
        EdgeHash *eh = BLI_edgehash_new();
-       int i;
        MFace *mf;
+       int i;
        
-       for (i=0; i<me->totface; i++) {
+       for(i=0; i<me->totface; i++) {
                mf = &me->mface[i];
 
-               if (mf->v3) {
-                       if (!(mf->flag&ME_HIDE)) {
-                               unsigned int flags = eEdge_Visible;
-                               if (mf->flag&ME_FACE_SEL) flags |= eEdge_Select;
-
-                               get_marked_edge_info__orFlags(eh, mf->v1, mf->v2, flags);
-                               get_marked_edge_info__orFlags(eh, mf->v2, mf->v3, flags);
-                               if (mf->v4) {
-                                       get_marked_edge_info__orFlags(eh, mf->v3, mf->v4, flags);
-                                       get_marked_edge_info__orFlags(eh, mf->v4, mf->v1, flags);
-                               } else {
-                                       get_marked_edge_info__orFlags(eh, mf->v3, mf->v1, flags);
-                               }
+               if(!(mf->flag & ME_HIDE)) {
+                       unsigned int flags = eEdge_Visible;
+                       if(mf->flag & ME_FACE_SEL) flags |= eEdge_Select;
+
+                       get_marked_edge_info__orFlags(eh, mf->v1, mf->v2, flags);
+                       get_marked_edge_info__orFlags(eh, mf->v2, mf->v3, flags);
+
+                       if(mf->v4) {
+                               get_marked_edge_info__orFlags(eh, mf->v3, mf->v4, flags);
+                               get_marked_edge_info__orFlags(eh, mf->v4, mf->v1, flags);
                        }
+                       else
+                               get_marked_edge_info__orFlags(eh, mf->v3, mf->v1, flags);
                }
        }
 
@@ -126,45 +121,24 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me)
 }
 
 
-static int draw_tfaces3D__setHiddenOpts(void *userData, int index)
+static int draw_mesh_face_select__setHiddenOpts(void *userData, int index)
 {
        struct { Mesh *me; EdgeHash *eh; } *data = userData;
        Mesh *me= data->me;
        MEdge *med = &me->medge[index];
        uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2);
 
-       if((me->drawflag & ME_DRAWSEAMS) && (med->flag&ME_SEAM)) {
-               return 0;
-       } else if(me->drawflag & ME_DRAWEDGES){ 
-               if (me->drawflag & ME_HIDDENEDGES) {
+       if(me->drawflag & ME_DRAWEDGES) { 
+               if(me->drawflag & ME_HIDDENEDGES)
                        return 1;
-               } else {
-                       return (flags & eEdge_Visible);
-               }
-       } else {
-               return (flags & eEdge_Select);
-       }
-}
-
-static int draw_tfaces3D__setSeamOpts(void *userData, int index)
-{
-       struct { Mesh *me; EdgeHash *eh; } *data = userData;
-       Mesh *me= data->me;
-       MEdge *med = &data->me->medge[index];
-       uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2);
-
-       if (med->flag & ME_SEAM) {
-               if (me->drawflag & ME_HIDDENEDGES) {
-                       return 1;
-               } else {
+               else
                        return (flags & eEdge_Visible);
-               }
-       } else {
-               return 0;
        }
+       else
+               return (flags & eEdge_Select);
 }
 
-static int draw_tfaces3D__setSelectOpts(void *userData, int index)
+static int draw_mesh_face_select__setSelectOpts(void *userData, int index)
 {
        struct { Mesh *me; EdgeHash *eh; } *data = userData;
        MEdge *med = &data->me->medge[index];
@@ -173,45 +147,19 @@ static int draw_tfaces3D__setSelectOpts(void *userData, int index)
        return flags & eEdge_Select;
 }
 
-#if 0
-static int draw_tfaces3D__setActiveOpts(void *userData, int index)
-{
-       struct { Mesh *me; EdgeHash *eh; } *data = userData;
-       MEdge *med = &data->me->medge[index];
-       uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2);
-
-       if (flags & eEdge_Select) {
-               return 1;
-       } else {
-               return 0;
-       }
-}
-
-static int draw_tfaces3D__drawFaceOpts(void *userData, int index)
-{
-       Mesh *me = (Mesh*)userData;
-
-       MFace *mface = &me->mface[index];
-       if (!(mface->flag&ME_HIDE) && (mface->flag&ME_FACE_SEL))
-               return 2; /* Don't set color */
-       else
-               return 0;
-}
-#endif
-
 /* draws unselected */
-static int draw_tfaces3D__drawFaceOptsInv(void *userData, int index)
+static int draw_mesh_face_select__drawFaceOptsInv(void *userData, int index)
 {
        Mesh *me = (Mesh*)userData;
 
        MFace *mface = &me->mface[index];
-       if (!(mface->flag&ME_HIDE) && !(mface->flag&ME_FACE_SEL))
+       if(!(mface->flag&ME_HIDE) && !(mface->flag&ME_FACE_SEL))
                return 2; /* Don't set color */
        else
                return 0;
 }
 
-static void draw_tfaces3D(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, short draw_seams)
+static void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm)
 {
        struct { Mesh *me; EdgeHash *eh; } data;
 
@@ -225,30 +173,16 @@ static void draw_tfaces3D(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, short d
        /* Draw (Hidden) Edges */
        setlinestyle(1);
        UI_ThemeColor(TH_EDGE_FACESEL);
-       dm->drawMappedEdges(dm, draw_tfaces3D__setHiddenOpts, &data);
+       dm->drawMappedEdges(dm, draw_mesh_face_select__setHiddenOpts, &data);
        setlinestyle(0);
 
-       /* Draw Seams */
-       if(draw_seams && me->drawflag & ME_DRAWSEAMS) {
-               UI_ThemeColor(TH_EDGE_SEAM);
-               glLineWidth(2);
-               dm->drawMappedEdges(dm, draw_tfaces3D__setSeamOpts, &data);
-               glLineWidth(1);
-       }
-
        /* Draw Selected Faces */
        if(me->drawflag & ME_DRAWFACES) {
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-#if 0
-               UI_ThemeColor4(TH_FACE_SELECT);
-
-               dm->drawMappedFacesTex(dm, draw_tfaces3D__drawFaceOpts, (void*)me);
-#else
                /* dull unselected faces so as not to get in the way of seeing color */
                glColor4ub(96, 96, 96, 64);
-               dm->drawMappedFacesTex(dm, draw_tfaces3D__drawFaceOptsInv, (void*)me);
-#endif
+               dm->drawMappedFacesTex(dm, draw_mesh_face_select__drawFaceOptsInv, (void*)me);
                
                glDisable(GL_BLEND);
        }
@@ -258,7 +192,7 @@ static void draw_tfaces3D(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, short d
                /* Draw Stippled Outline for selected faces */
        glColor3ub(255, 255, 255);
        setlinestyle(1);
-       dm->drawMappedEdges(dm, draw_tfaces3D__setSelectOpts, &data);
+       dm->drawMappedEdges(dm, draw_mesh_face_select__setSelectOpts, &data);
        setlinestyle(0);
 
        bglPolygonOffset(rv3d->dist, 0.0);      // resets correctly now, even after calling accumulated offsets
@@ -266,6 +200,8 @@ static void draw_tfaces3D(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, short d
        BLI_edgehash_free(data.eh, NULL);
 }
 
+/***************************** Texture Drawing ******************************/
+
 static Material *give_current_material_or_def(Object *ob, int matnr)
 {
        extern Material defmaterial;    // render module abuse...
@@ -695,18 +631,21 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o
 
        if(ob->mode & OB_MODE_EDIT) {
                dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, me->edit_btmesh);
-       } else if(faceselect) {
+       }
+       else if(faceselect) {
                if(ob->mode & OB_MODE_WEIGHT_PAINT)
                        dm->drawMappedFaces(dm, wpaint__setSolidDrawOptions, me, 1, GPU_enable_material);
                else
                        dm->drawMappedFacesTex(dm, me->mface ? draw_tface_mapped__set_draw : NULL, me);
        }
        else {
-               if( GPU_buffer_legacy(dm) )
+               if(GPU_buffer_legacy(dm)) {
                        dm->drawFacesTex(dm, draw_tface__set_draw_legacy);
+               }
                else {
-                       if( !CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL) )
+                       if(!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL))
                                add_tface_color_layer(dm);
+
                        dm->drawFacesTex(dm, draw_tface__set_draw);
                }
        }
@@ -719,7 +658,7 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o
        
        /* draw edges and selected faces over textured mesh */
        if(!(ob == scene->obedit) && faceselect)
-               draw_tfaces3D(rv3d, me, dm, ob->mode & OB_MODE_WEIGHT_PAINT);
+               draw_mesh_face_select(rv3d, me, dm);
 
        /* reset from negative scale correction */
        glFrontFace(GL_CCW);