svn merge -r39765:39781 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / blenkernel / intern / cdderivedmesh.c
index 08cb0ccc23a14fc192174065f7d1a59fe5247063..ad70e00a33ce1f350a47ace908c4b3ada52d3022 100644 (file)
@@ -101,8 +101,6 @@ typedef struct {
        struct IndexNode *fmap_mem;
 } CDDerivedMesh;
 
-DMFaceIter *cdDM_newFaceIter(DerivedMesh *source);
-
 /**************** DerivedMesh interface functions ****************/
 static int cdDM_getNumVerts(DerivedMesh *dm)
 {
@@ -160,6 +158,18 @@ static void cdDM_copyFaceArray(DerivedMesh *dm, MFace *face_r)
        memcpy(face_r, cddm->mface, sizeof(*face_r) * dm->numFaceData);
 }
 
+static void cdDM_copyLoopArray(DerivedMesh *dm, MLoop *loop_r)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
+       memcpy(loop_r, cddm->mloop, sizeof(*loop_r) * dm->numLoopData);
+}
+
+static void cdDM_copyPolyArray(DerivedMesh *dm, MPoly *poly_r)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
+       memcpy(poly_r, cddm->mpoly, sizeof(*poly_r) * dm->numPolyData);
+}
+
 static void cdDM_getMinMax(DerivedMesh *dm, float min_r[3], float max_r[3])
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -305,8 +315,10 @@ static void cdDM_drawVerts(DerivedMesh *dm)
        else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
                GPU_vertex_setup(dm);
                if( !GPU_buffer_legacy(dm) ) {
-                       if(dm->drawObject->nelements)   glDrawArrays(GL_POINTS,0, dm->drawObject->nelements);
-                       else                                                    glDrawArrays(GL_POINTS,0, dm->drawObject->nlooseverts);
+                       if(dm->drawObject->tot_triangle_point)
+                               glDrawArrays(GL_POINTS,0, dm->drawObject->tot_triangle_point);
+                       else
+                               glDrawArrays(GL_POINTS,0, dm->drawObject->tot_loose_point);
                }
                GPU_buffer_unbind();
        }
@@ -568,9 +580,10 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
                GPU_normal_setup( dm );
                if( !GPU_buffer_legacy(dm) ) {
                        glShadeModel(GL_SMOOTH);
-                       for( a = 0; a < dm->drawObject->nmaterials; a++ ) {
+                       for( a = 0; a < dm->drawObject->totmaterial; a++ ) {
                                if( setMaterial(dm->drawObject->materials[a].mat_nr+1, NULL) )
-                                       glDrawArrays(GL_TRIANGLES, dm->drawObject->materials[a].start, dm->drawObject->materials[a].end-dm->drawObject->materials[a].start);
+                                       glDrawArrays(GL_TRIANGLES, dm->drawObject->materials[a].start,
+                                                    dm->drawObject->materials[a].totpoint);
                        }
                }
                GPU_buffer_unbind( );
@@ -650,13 +663,13 @@ static void cdDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha
                GPU_color_setup(dm);
                if( !GPU_buffer_legacy(dm) ) {
                        glShadeModel(GL_SMOOTH);
-                       glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->nelements);
+                       glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->tot_triangle_point);
 
                        if( useTwoSided ) {
                                GPU_color4_upload(dm,cp2);
                                GPU_color_setup(dm);
                                glCullFace(GL_FRONT);
-                               glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->nelements);
+                               glDrawArrays(GL_TRIANGLES, 0, dm->drawObject->tot_triangle_point);
                                glCullFace(GL_BACK);
                        }
                }
@@ -808,8 +821,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                        
                        glShadeModel( GL_SMOOTH );
                        lastFlag = 0;
-                       for(i = 0; i < dm->drawObject->nelements/3; i++) {
-                               int actualFace = dm->drawObject->faceRemap[i];
+                       for(i = 0; i < dm->drawObject->tot_triangle_point/3; i++) {
+                               int actualFace = dm->drawObject->triangle_to_mface[i];
                                int flag = 1;
 
                                if(drawParams) {
@@ -840,13 +853,13 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                        startFace = i;
                                }
                        }
-                       if( startFace < dm->drawObject->nelements/3 ) {
+                       if( startFace < dm->drawObject->tot_triangle_point/3 ) {
                                if( lastFlag != 0 ) { /* if the flag is 0 it means the face is hidden or invisible */
                                        if (lastFlag==1 && col)
                                                GPU_color_switch(1);
                                        else
                                                GPU_color_switch(0);
-                                       glDrawArrays(GL_TRIANGLES,startFace*3,dm->drawObject->nelements-startFace*3);
+                                       glDrawArrays(GL_TRIANGLES, startFace*3, dm->drawObject->tot_triangle_point - startFace*3);
                                }
                        }
                }
@@ -861,13 +874,14 @@ static void cdDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tfa
        cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL);
 }
 
-static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors, int (*setMaterial)(int, void *attribs))
+static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors, int (*setMaterial)(int, void *attribs),
+                       int (*compareDrawOptions)(void *userData, int cur_index, int next_index))
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *mv = cddm->mvert;
        MFace *mf = cddm->mface;
        MCol *mc;
-       float *nors= dm->getTessFaceDataArray(dm, CD_NORMAL);
+       float *nors= DM_get_tessface_data_layer(dm, CD_NORMAL);
        int i, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
        mc = DM_get_tessface_data_layer(dm, CD_ID_MCOL);
@@ -944,7 +958,9 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
                                }
 
                                glEnd();
-                       }
+                       } /*else {
+                               printf("eek in cddm draw mapped faces!\n");
+                       }*/
                        
                        if (nors) nors += 3;
                }
@@ -956,7 +972,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
                if( useColors && mc )
                        GPU_color_setup(dm);
                if( !GPU_buffer_legacy(dm) ) {
-                       int tottri = dm->drawObject->nelements/3;
+                       int tottri = dm->drawObject->tot_triangle_point/3;
                        glShadeModel(GL_SMOOTH);
                        
                        if(tottri == 0) {
@@ -968,17 +984,18 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
                        }
                        else {
                                /* we need to check if the next material changes */
-                               int next_actualFace= dm->drawObject->faceRemap[0];
+                               int next_actualFace= dm->drawObject->triangle_to_mface[0];
                                
                                for( i = 0; i < tottri; i++ ) {
-                                       //int actualFace = dm->drawObject->faceRemap[i];
+                                       //int actualFace = dm->drawObject->triangle_to_mface[i];
                                        int actualFace = next_actualFace;
                                        MFace *mface= mf + actualFace;
                                        int drawSmooth= (mface->flag & ME_SMOOTH);
                                        int draw = 1;
+                                       int flush = 0;
 
                                        if(i != tottri-1)
-                                               next_actualFace= dm->drawObject->faceRemap[i+1];
+                                               next_actualFace= dm->drawObject->triangle_to_mface[i+1];
 
                                        orig= (index==NULL) ? actualFace : index[actualFace];
 
@@ -990,11 +1007,28 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
                                        /* Goal is to draw as long of a contiguous triangle
                                           array as possible, so draw when we hit either an
                                           invisible triangle or at the end of the array */
-                                       if(!draw || i == tottri - 1 || mf[actualFace].mat_nr != mf[next_actualFace].mat_nr) {
-                                               if(prevstart != i)
-                                                       /* Add one to the length (via `draw')
-                                                          if we're drawing at the end of the array */
-                                                       glDrawArrays(GL_TRIANGLES,prevstart*3, (i-prevstart+draw)*3);
+
+                                       /* flush buffer if current triangle isn't drawable or it's last triangle... */
+                                       flush= !draw || i == tottri - 1;
+
+                                       /* ... or when material setting is dissferent  */
+                                       flush|= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr;
+
+                                       if(!flush && compareDrawOptions) {
+                                               int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace];
+
+                                               /* also compare draw options and flush buffer if they're different
+                                                  need for face selection highlight in edit mode */
+                                               flush|= compareDrawOptions(userData, orig, next_orig) == 0;
+                                       }
+
+                                       if(flush) {
+                                               int first= prevstart*3;
+                                               int count= (i-prevstart+(draw ? 1 : 0))*3; /* Add one to the length if we're drawing at the end of the array */
+
+                                               if(count)
+                                                       glDrawArrays(GL_TRIANGLES, first, count);
+
                                                prevstart = i + 1;
                                        }
                                }
@@ -1011,6 +1045,52 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, int (*setDrawOptions)(void
        cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, userData);
 }
 
+
+static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int a, int index, int vert, int smoothnormal)
+{
+       int b;
+
+       /* orco texture coordinates */
+       if(attribs->totorco) {
+               if(attribs->orco.glTexco)
+                       glTexCoord3fv(attribs->orco.array[index]);
+               else
+                       glVertexAttrib3fvARB(attribs->orco.glIndex, attribs->orco.array[index]);
+       }
+
+       /* uv texture coordinates */
+       for(b = 0; b < attribs->tottface; b++) {
+               MTFace *tf = &attribs->tface[b].array[a];
+
+               if(attribs->tface[b].glTexco)
+                       glTexCoord2fv(tf->uv[vert]);
+               else
+                       glVertexAttrib2fvARB(attribs->tface[b].glIndex, tf->uv[vert]);
+       }
+
+       /* vertex colors */
+       for(b = 0; b < attribs->totmcol; b++) {
+               MCol *cp = &attribs->mcol[b].array[a*4 + vert];
+               GLubyte col[4];
+               col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;
+               glVertexAttrib4ubvARB(attribs->mcol[b].glIndex, col);
+       }
+
+       /* tangent for normal mapping */
+       if(attribs->tottang) {
+               float *tang = attribs->tang.array[a*4 + vert];
+               glVertexAttrib4fvARB(attribs->tang.glIndex, tang);
+       }
+
+       /* vertex normal */
+       if(smoothnormal)
+               glNormal3sv(mvert[index].no);
+
+       /* vertex coordinate */
+       glVertex3fv(mvert[index].co);
+}
+
+
 static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -1101,35 +1181,13 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                                }
                        }
 
-#define PASSVERT(index, vert) {                                                                                                        \
-               if(attribs.totorco)                                                                                                                     \
-                       glVertexAttrib3fvARB(attribs.orco.glIndex, attribs.orco.array[index]);  \
-               for(b = 0; b < attribs.tottface; b++) {                                                                         \
-                       MTFace *tf = &attribs.tface[b].array[a];                                                                \
-                       glVertexAttrib2fvARB(attribs.tface[b].glIndex, tf->uv[vert]);                   \
-               }                                                                                                                                                       \
-               for(b = 0; b < attribs.totmcol; b++) {                                                                          \
-                       MCol *cp = &attribs.mcol[b].array[a*4 + vert];                                                  \
-                       GLubyte col[4];                                                                                                                 \
-                       col[0]= cp->b; col[1]= cp->g; col[2]= cp->r; col[3]= cp->a;                             \
-                       glVertexAttrib4ubvARB(attribs.mcol[b].glIndex, col);                                    \
-               }                                                                                                                                                       \
-               if(attribs.tottang) {                                                                                                           \
-                       float *tang = attribs.tang.array[a*4 + vert];                                                   \
-                       glVertexAttrib4fvARB(attribs.tang.glIndex, tang);                                               \
-               }                                                                                                                                                       \
-               if(smoothnormal)                                                                                                                        \
-                       glNormal3sv(mvert[index].no);                                                                                   \
-               glVertex3fv(mvert[index].co);                                                                                           \
-       }
-
-                       PASSVERT(mface->v1, 0);
-                       PASSVERT(mface->v2, 1);
-                       PASSVERT(mface->v3, 2);
+                       cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v1, 0, smoothnormal);
+                       cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v2, 1, smoothnormal);
+                       cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v3, 2, smoothnormal);
                        if(mface->v4)
-                               PASSVERT(mface->v4, 3)
+                               cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v4, 3, smoothnormal);
                        else
-                               PASSVERT(mface->v3, 2)
+                               cddm_draw_attrib_vertex(&attribs, mvert, a, mface->v3, 2, smoothnormal);
 
                }
                glEnd();
@@ -1149,9 +1207,9 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                GPU_normal_setup(dm);
 
                if( !GPU_buffer_legacy(dm) ) {
-                       for( i = 0; i < dm->drawObject->nelements/3; i++ ) {
+                       for( i = 0; i < dm->drawObject->tot_triangle_point/3; i++ ) {
 
-                               a = dm->drawObject->faceRemap[i];
+                               a = dm->drawObject->triangle_to_mface[i];
 
                                mface = mf + a;
                                new_matnr = mface->mat_nr + 1;
@@ -1173,7 +1231,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
 
                                                        if( numdata != 0 ) {
 
-                                                               GPU_buffer_free(buffer, NULL);
+                                                               GPU_buffer_free(buffer);
 
                                                                buffer = NULL;
                                                        }
@@ -1213,7 +1271,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                                                }
                                                if( numdata != 0 ) {
                                                        elementsize = GPU_attrib_element_size( datatypes, numdata );
-                                                       buffer = GPU_buffer_alloc( elementsize*dm->drawObject->nelements, NULL );
+                                                       buffer = GPU_buffer_alloc( elementsize*dm->drawObject->tot_triangle_point);
                                                        if( buffer == NULL ) {
                                                                GPU_buffer_unbind();
                                                                dm->drawObject->legacy = 1;
@@ -1222,7 +1280,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                                                        varray = GPU_buffer_lock_stream(buffer);
                                                        if( varray == NULL ) {
                                                                GPU_buffer_unbind();
-                                                               GPU_buffer_free(buffer, NULL);
+                                                               GPU_buffer_free(buffer);
                                                                dm->drawObject->legacy = 1;
                                                                return;
                                                        }
@@ -1304,6 +1362,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                                                QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang);
                                                offset += sizeof(float)*4;
                                        }
+                                       (void)offset;
                                }
                                curface++;
                                if(mface->v4) {
@@ -1344,6 +1403,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                                                        QUATCOPY((float *)&varray[elementsize*curface*3+offset+elementsize*2], tang);
                                                        offset += sizeof(float)*4;
                                                }
+                                               (void)offset;
                                        }
                                        curface++;
                                        i++;
@@ -1361,7 +1421,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
                        }
                        GPU_buffer_unbind();
                }
-               GPU_buffer_free( buffer, NULL );
+               GPU_buffer_free(buffer);
        }
 
        glShadeModel(GL_FLAT);
@@ -1551,14 +1611,14 @@ static CDDerivedMesh *cdDM_create(const char *desc)
        dm->getNumTessFaces = cdDM_getNumTessFaces;
        dm->getNumFaces = cdDM_getNumFaces;
 
-       dm->newFaceIter = cdDM_newFaceIter;
-
        dm->getVert = cdDM_getVert;
        dm->getEdge = cdDM_getEdge;
        dm->getTessFace = cdDM_getFace;
        dm->copyVertArray = cdDM_copyVertArray;
        dm->copyEdgeArray = cdDM_copyEdgeArray;
        dm->copyTessFaceArray = cdDM_copyFaceArray;
+       dm->copyLoopArray = cdDM_copyLoopArray;
+       dm->copyPolyArray = cdDM_copyPolyArray;
        dm->getVertData = DM_get_vert_data;
        dm->getEdgeData = DM_get_edge_data;
        dm->getTessFaceData = DM_get_face_data;
@@ -2016,139 +2076,6 @@ DerivedMesh *CDDM_from_BMEditMesh(BMEditMesh *em, Mesh *UNUSED(me), int use_mdis
        return dm;
 }
 
-typedef struct CDDM_LoopIter {
-       DMLoopIter head;
-       CDDerivedMesh *cddm;
-       int len, i;
-} CDDM_LoopIter;
-
-typedef struct CDDM_FaceIter {
-       DMFaceIter head;
-       CDDerivedMesh *cddm;
-       CDDM_LoopIter liter;
-} CDDM_FaceIter;
-
-static void cddm_freeiter(void *self)
-{
-       MEM_freeN(self);
-}
-
-static void cddm_stepiter(void *self)
-{
-       CDDM_FaceIter *iter = self;
-       MPoly *mp;
-       
-       mp = iter->cddm->mpoly + iter->head.index;
-       mp->flag = iter->head.flags;
-       mp->mat_nr = iter->head.mat_nr;
-
-       iter->head.index++;
-       if (iter->head.index >= iter->cddm->dm.numPolyData) {
-               iter->head.done = 1;
-               return;
-       }
-
-       mp = iter->cddm->mpoly + iter->head.index;
-
-       iter->head.flags = mp->flag;
-       iter->head.mat_nr = mp->mat_nr;
-       iter->head.len = mp->totloop;
-}
-
-static void *cddm_faceiter_getcddata(void *self, int type, int layer)
-{
-       CDDM_FaceIter *iter = self;
-
-       if (layer == -1) return CustomData_get(&iter->cddm->dm.polyData, 
-                                              iter->head.index, type);
-       else return CustomData_get_n(&iter->cddm->dm.polyData, type, 
-                                   iter->head.index, layer);
-}
-
-static void *cddm_loopiter_getcddata(void *self, int type, int layer)
-{
-       CDDM_LoopIter *iter = self;
-
-       if (layer == -1) return CustomData_get(&iter->cddm->dm.loopData, 
-                                              iter->head.index, type);
-       else return CustomData_get_n(&iter->cddm->dm.loopData, type, 
-                                    iter->head.index, layer);
-}
-
-static void *cddm_loopiter_getvertcddata(void *self, int type, int layer)
-{
-       CDDM_LoopIter *iter = self;
-
-       if (layer == -1) return CustomData_get(&iter->cddm->dm.vertData, 
-                                              iter->cddm->mloop[iter->head.index].v,
-                                              type);
-       else return CustomData_get_n(&iter->cddm->dm.vertData, type, 
-                                    iter->cddm->mloop[iter->head.index].v, layer);
-}
-
-static DMLoopIter *cddmiter_get_loopiter(void *self)
-{
-       CDDM_FaceIter *iter = self;
-       CDDM_LoopIter *liter = &iter->liter;
-       MPoly *mp = iter->cddm->mpoly + iter->head.index;
-
-       liter->i = -1;
-       liter->len = iter->head.len;
-       liter->head.index = mp->loopstart-1;
-       liter->head.done = 0;
-
-       liter->head.step(liter);
-
-       return (DMLoopIter*) liter;
-}
-
-static void cddm_loopiter_step(void *self)
-{
-       CDDM_LoopIter *liter = self;
-       MLoop *ml;
-
-       liter->i++;
-       liter->head.index++;
-
-       if (liter->i == liter->len) {
-               liter->head.done = 1;
-               return;
-       }
-
-       ml = liter->cddm->mloop + liter->head.index;
-
-       liter->head.eindex = ml->e;
-       liter->head.v = liter->cddm->mvert[ml->v];
-       liter->head.vindex = ml->v;
-}
-
-DMFaceIter *cdDM_newFaceIter(DerivedMesh *source)
-{
-       CDDerivedMesh *cddm = (CDDerivedMesh*) source;
-       CDDM_FaceIter *iter = MEM_callocN(sizeof(CDDM_FaceIter), "DMFaceIter from cddm");
-
-       iter->head.free = cddm_freeiter;
-       iter->head.step = cddm_stepiter;
-       iter->head.getCDData = cddm_faceiter_getcddata;
-       iter->head.getLoopsIter = cddmiter_get_loopiter;
-
-       iter->liter.head.step = cddm_loopiter_step;
-       iter->liter.head.getLoopCDData = cddm_loopiter_getcddata;
-       iter->liter.head.getVertCDData = cddm_loopiter_getvertcddata;
-       iter->liter.cddm = cddm;
-
-       iter->cddm = cddm;
-
-       if (source->numFaceData) {
-               iter->head.index = -1;
-               iter->head.step(iter);
-       } else {
-               iter->head.done = 1;
-       }
-
-       return (DMFaceIter*) iter;
-}
-
 DerivedMesh *CDDM_copy(DerivedMesh *source, int faces_from_tessfaces)
 {
        CDDerivedMesh *cddm = cdDM_create("CDDM_copy cddm");
@@ -2189,7 +2116,9 @@ DerivedMesh *CDDM_copy(DerivedMesh *source, int faces_from_tessfaces)
 
        cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
        cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
-
+       
+       cdDM_recalcTesselation((DerivedMesh *)cddm);
+       
        return dm;
 }
 
@@ -2350,15 +2279,8 @@ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, int *vtargetmap)
                if (ml->v == -1)
                        continue;
                
-               if (vtargetmap[ml->v] != -1) {
-                       me = &cddm->medge[ml->e];
-                       if (me->v1 == ml->v)
-                               me->v1 = vtargetmap[ml->v];
-                       else
-                               me->v2 = vtargetmap[ml->v];
-                       
+               if (vtargetmap[ml->v] != -1)
                        ml->v = vtargetmap[ml->v];
-               }
        }
        
        /*now go through and fix edges and faces*/