- added getMappedVertCoEM and drawMappedVertEM to DerivedMesh with
authorDaniel Dunbar <daniel@zuster.org>
Mon, 28 Mar 2005 07:10:32 +0000 (07:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 28 Mar 2005 07:10:32 +0000 (07:10 +0000)
   implementations (slightly redundant, could implement draw in terms
   of first... can be cleaned later)
 - switch to use of new APIs... all uses of EditVert->ssco are now
   clean (read: ready to die as soon as a proper DerivedMesh implementation
   is swapped in with ccgsubsurf)

source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/src/drawobject.c
source/blender/src/editmesh_mods.c

index e66b36d951806e954f9f5d182920029dc7907831..5e210cb35899b2b4c4daa16c9a85057622162cad 100644 (file)
@@ -51,6 +51,8 @@ struct DerivedMesh {
        int (*getNumVerts)(DerivedMesh *dm);
        int (*getNumFaces)(DerivedMesh *dm);
 
+       void (*getMappedVertCoEM)(DerivedMesh *dm, void *vert, float co_r[3]);
+
                        /* Convert to new DispListMesh, should be free'd by caller */
        struct DispListMesh* (*convertToDispListMesh)(DerivedMesh *dm);
 
@@ -82,6 +84,9 @@ struct DerivedMesh {
                         */
        void (*drawFacesColored)(DerivedMesh *dm, int useTwoSided, unsigned char *col1, unsigned char *col2);
 
+                       /* Draw single mapped vert as bgl point (no options) */
+       void (*drawMappedVertEM)(DerivedMesh *dm, void *vert);
+
                        /* Draw mapped vertices as bgl points
                         *  o Only if mapped EditVert->h==0
                         */
index 1245d1bec3b43e031163351590579321909fe477..9b18a46a32ce2f4f3ca0663beba8caec7720fde1 100644 (file)
@@ -392,6 +392,7 @@ static DerivedMesh *getMeshDerivedMesh(Object *ob, float *extverts, float *nors)
        mdm->dm.convertToDispListMesh = meshDM_convertToDispListMesh;
 
        mdm->dm.drawVerts = meshDM_drawVerts;
+       mdm->dm.drawMappedVertEM = NULL;
        mdm->dm.drawMappedVertsEM = NULL;
        mdm->dm.drawMappedVertsEMSelect = NULL;
 
@@ -424,6 +425,22 @@ typedef struct {
        EditMesh *em;
 } EditMeshDerivedMesh;
 
+static void emDM_getMappedVertCoEM(DerivedMesh *dm, void *vert, float co_r[3])
+{
+       EditVert *eve = vert;
+
+       co_r[0] = eve->co[0];
+       co_r[1] = eve->co[1];
+       co_r[2] = eve->co[2];
+}
+static void emDM_drawMappedVertEM(DerivedMesh *dm, void *vert)
+{
+       EditVert *eve = vert;
+
+       bglBegin(GL_POINTS);
+       bglVertex3fv(eve->co);
+       bglEnd();               
+}
 static void emDM_drawMappedVertsEM(DerivedMesh *dm, int sel)
 {
        EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
@@ -591,9 +608,11 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em)
 
        emdm->dm.getNumVerts = emDM_getNumVerts;
        emdm->dm.getNumFaces = emDM_getNumFaces;
+       emdm->dm.getMappedVertCoEM = emDM_getMappedVertCoEM;
        emdm->dm.convertToDispListMesh = emDM_convertToDispListMesh;
 
        emdm->dm.drawVerts = NULL;
+       emdm->dm.drawMappedVertEM = emDM_drawMappedVertEM;
        emdm->dm.drawMappedVertsEM = emDM_drawMappedVertsEM;
        emdm->dm.drawMappedVertsEMSelect = emDM_drawMappedVertsEMSelect;
 
@@ -626,6 +645,22 @@ typedef struct {
        float *nors;
 } SSDerivedMesh;
 
+static void ssDM_getMappedVertCoEM(DerivedMesh *dm, void *vert, float co_r[3])
+{
+       EditVert *eve = vert;
+
+       co_r[0] = eve->ssco[0];
+       co_r[1] = eve->ssco[1];
+       co_r[2] = eve->ssco[2];
+}
+static void ssDM_drawMappedVertEM(DerivedMesh *dm, void *vert)
+{
+       EditVert *eve = vert;
+
+       bglBegin(GL_POINTS);
+       bglVertex3fv(eve->ssco);
+       bglEnd();               
+}
 static void ssDM_drawMappedVertsEM(DerivedMesh *dm, int sel)
 {
        SSDerivedMesh *ssdm = (SSDerivedMesh*) dm;
@@ -985,9 +1020,11 @@ static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, float *nor
 
        ssdm->dm.getNumVerts = ssDM_getNumVerts;
        ssdm->dm.getNumFaces = ssDM_getNumFaces;
+       ssdm->dm.getMappedVertCoEM = ssDM_getMappedVertCoEM;
        ssdm->dm.convertToDispListMesh = ssDM_convertToDispListMesh;
 
        ssdm->dm.drawVerts = ssDM_drawVerts;
+       ssdm->dm.drawMappedVertEM = ssDM_drawMappedVertEM;
        ssdm->dm.drawMappedVertsEM = ssDM_drawMappedVertsEM;
        ssdm->dm.drawMappedVertsEMSelect = ssDM_drawMappedVertsEMSelect;
 
index 846ba6be5bdfaf385a50c660cb63c0016722c062..d12b767290a5a422f841458516a8e6378b0a5660 100644 (file)
@@ -970,16 +970,6 @@ static void drawlattice(Object *ob)
 
 /* ***************** ******************** */
 
-int subsurf_optimal(Object *ob)
-{
-       if(ob->type==OB_MESH) {
-               Mesh *me= ob->data;
-               if( (me->flag & ME_OPT_EDGES) && (me->flag & ME_SUBSURF) && me->subdiv) return 1;
-       }
-       return 0;
-}
-
-
 void calc_mesh_facedots_ext(void)
 {
        EditMesh *em = G.editMesh;
@@ -1012,27 +1002,22 @@ void calc_mesh_facedots_ext(void)
 /* window coord, assuming all matrices are set OK */
 static void calc_meshverts(void)
 {
-       EditMesh *em = G.editMesh;
+       DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
+       float co[3], mat[4][4];
        EditVert *eve;
-       float mat[4][4];
-
-       if(em->verts.first==0) return;
-       eve= em->verts.first;
 
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
        mygetsingmatrix(G.vd->persmat);
 
-       if(subsurf_optimal(G.obedit)) { // separate loop for speed 
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if(eve->h==0 && eve->ssco) project_short(eve->ssco, &(eve->xs));
-               }
-       }
-       else {
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if(eve->h==0) project_short(eve->co, &(eve->xs));
+       for(eve= G.editMesh->verts.first; eve; eve= eve->next) {
+               if(eve->h==0) {
+                       dm->getMappedVertCoEM(dm, eve, co);
+                       project_short(co, &(eve->xs));
                }
        }
+
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
+       dm->release(dm);
 }
 
 /* window coord for current window, sets matrices temporal */
@@ -1051,13 +1036,9 @@ void calc_meshverts_ext(void)
 /* window coord for current window, sets matrices temporal, sets (eve->f & 2) when not visible */
 void calc_meshverts_ext_f2(void)
 {
-       EditMesh *em = G.editMesh;
+       DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
+       float co[3], mat[4][4];
        EditVert *eve;
-       float mat[4][4];
-       int optimal= subsurf_optimal(G.obedit);
-       
-       if(em->verts.first==0) return;
-       eve= em->verts.first;
 
        /* matrices */
        areawinset(curarea->win);
@@ -1067,11 +1048,11 @@ void calc_meshverts_ext_f2(void)
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
        mygetsingmatrix(G.vd->persmat);
 
-       for(eve= em->verts.first; eve; eve= eve->next) {
+       for(eve= G.editMesh->verts.first; eve; eve= eve->next) {
                eve->f &= ~2;
                if(eve->h==0) {
-                       if(optimal && eve->ssco) project_short_noclip(eve->ssco, &(eve->xs));
-                       else project_short_noclip(eve->co, &(eve->xs));
+                       dm->getMappedVertCoEM(dm, eve, co);
+                       project_short_noclip(co, &(eve->xs));
        
                        if( eve->xs >= 0 && eve->ys >= 0 && eve->xs<curarea->winx && eve->ys<curarea->winy);
                        else eve->f |= 2;
@@ -1081,7 +1062,8 @@ void calc_meshverts_ext_f2(void)
        /* restore */
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
        myloadmatrix(G.vd->viewmat);
-       
+
+       dm->release(dm);
 }
 
 
index f883be682932be7f5ad25d2d142a61b8490c1b3c..dd5422ff4497bf73b4e40a6695f7e0abecc3575d 100644 (file)
@@ -628,7 +628,6 @@ static EditFace *findnearestface(short *dist)
 /* for interactivity, frontbuffer draw in current window */
 static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
 {
-       int optimal= subsurf_optimal(G.obedit);
        DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
 
        glDrawBuffer(GL_FRONT);
@@ -669,10 +668,8 @@ static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
                if(G.scene->selectmode & SCE_SELECT_FACE) {
                        if(efa->fgonf==0) {
                                glPointSize(BIF_GetThemeValuef(TH_FACEDOT_SIZE));
-                               
-                               if(efa->f & SELECT) BIF_ThemeColor(TH_FACE_DOT);
-                               else BIF_ThemeColor(TH_WIRE);
-                               
+                               BIF_ThemeColor((efa->f & SELECT)?TH_FACE_DOT:TH_WIRE);
+
                                bglBegin(GL_POINTS);
                                bglVertex3fv(efa->cent);
                                bglEnd();
@@ -689,32 +686,19 @@ static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
                if(G.scene->selectmode & SCE_SELECT_VERTEX) {
                        glPointSize(BIF_GetThemeValuef(TH_VERTEX_SIZE));
                        
-                       if(eed->f & SELECT) BIF_ThemeColor(TH_VERTEX_SELECT);
-                       else BIF_ThemeColor(TH_VERTEX);
+                       BIF_ThemeColor((eed->f & SELECT)?TH_VERTEX_SELECT:TH_VERTEX);
                        
-                       bglBegin(GL_POINTS);
-                       if(optimal) {
-                               bglVertex3fv(eed->v1->ssco);
-                               bglVertex3fv(eed->v2->ssco);
-                       } else {
-                               bglVertex3fv(eed->v1->co);
-                               bglVertex3fv(eed->v2->co);
-                       }
-                       bglEnd();
+                       dm->drawMappedVertEM(dm, eed->v1);
+                       dm->drawMappedVertEM(dm, eed->v2);
                }
        }
        if(eve) {
                if(G.scene->selectmode & SCE_SELECT_VERTEX) {
-
                        glPointSize(BIF_GetThemeValuef(TH_VERTEX_SIZE));
                        
-                       if(eve->f & SELECT) BIF_ThemeColor(TH_VERTEX_SELECT);
-                       else BIF_ThemeColor(TH_VERTEX);
+                       BIF_ThemeColor((eve->f & SELECT)?TH_VERTEX_SELECT:TH_VERTEX);
                        
-                       bglBegin(GL_POINTS);
-                       if(optimal) bglVertex3fv(eve->ssco);
-                       else bglVertex3fv(eve->co);
-                       bglEnd();
+                       dm->drawMappedVertEM(dm, eve);
                }
        }