=bmesh= glsl drawing in editmode works again, also fixed some minor customdata bugs
authorJoseph Eagar <joeedh@gmail.com>
Tue, 10 May 2011 17:01:26 +0000 (17:01 +0000)
committerJoseph Eagar <joeedh@gmail.com>
Tue, 10 May 2011 17:01:26 +0000 (17:01 +0000)
source/blender/blenkernel/BKE_customdata.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/editderivedbmesh.c
source/blender/bmesh/bmesh_iterators.h
source/blender/bmesh/operators/edgesplitop.c
source/blender/bmesh/operators/mesh_conv.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/mesh/mesh_data.c

index 319519cf3635ecda353706f6408e2dd6ed830f72..276e8dd3d2f0ef57c4f82234b715464651f8002f 100644 (file)
@@ -229,6 +229,8 @@ void *CustomData_bmesh_get_n(const struct CustomData *data, void *block, int typ
  */
 void *CustomData_bmesh_get_layer_n(const struct CustomData *data, void *block, int n);
 
+int CustomData_set_layer_name(const struct CustomData *data, int type, int n, const char *name);
+
 /* gets a pointer to the active or first layer of type
  * returns NULL if there is no layer of type
  */
index b3ed9e3a7e0ac5338ee766cd4d722ca4c4f5e707..c1cd598026faeda08555d68dd7ec59d62d92c691 100644 (file)
@@ -1069,7 +1069,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
        LinkNode *datamasks, *curr;
        CustomDataMask mask, nextmask;
        float (*deformedVerts)[3] = NULL;
-       DerivedMesh *dm, *orcodm, *clothorcodm, *finaldm;
+       DerivedMesh *dm=NULL, *orcodm, *clothorcodm, *finaldm;
        int numVerts = me->totvert;
        int required_mode;
        int isPrevDeform= FALSE;
@@ -2178,7 +2178,25 @@ void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs,
                                attribs->tface[a].array = tfdata->layers[layer].data;
                                attribs->tface[a].emOffset = tfdata->layers[layer].offset;
                                attribs->tface[a].glIndex = gattribs->layer[b].glindex;
-                       }
+                       } /*else {
+                               int player;
+                               CustomData *pdata = dm->getFaceDataLayout(dm);
+                               
+                               if(gattribs->layer[b].name[0])
+                                       player = CustomData_get_named_layer_index(pdata, CD_MTEXPOLY,
+                                               gattribs->layer[b].name);
+                               else
+                                       player = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY);
+                               
+                               if (player != -1) {
+                                       a = attribs->tottface++;
+       
+                                       attribs->tface[a].array = NULL;
+                                       attribs->tface[a].emOffset = pdata->layers[layer].offset;
+                                       attribs->tface[a].glIndex = gattribs->layer[b].glindex;
+                                       
+                               }
+                       }*/
                }
                else if(gattribs->layer[b].type == CD_MCOL) {
                        /* vertex colors */
index 9b761926719bfbb73501083c53f3a0dbc3dc4141..95b5fd9ec019fde13b073038fbf412496dfabbe2 100644 (file)
@@ -1827,6 +1827,20 @@ void *CustomData_get_layer_named(const struct CustomData *data, int type,
        return data->layers[layer_index].data;
 }
 
+
+int CustomData_set_layer_name(const CustomData *data, int type, int n, const char *name)
+{
+       /* get the layer index of the first layer of type */
+       int layer_index = CustomData_get_layer_index_n(data, type, n);
+
+       if(layer_index < 0) return 0;
+       if (!name) return 0;
+       
+       strcpy(data->layers[layer_index].name, name);
+       
+       return 1;
+}
+
 void *CustomData_set_layer(const CustomData *data, int type, void *ptr)
 {
        /* get the layer index of the first layer of type */
@@ -2165,13 +2179,13 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
        int i;
        for(i=0; i < pdata->totlayer; i++){
                if(pdata->layers[i].type == CD_MTEXPOLY)
-                       CustomData_add_layer(fdata, CD_MTFACE, CD_CALLOC, &(pdata->layers[i].name), total);
+                       CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, pdata->layers[i].name);
        }
        for(i=0; i < ldata->totlayer; i++){
                if(ldata->layers[i].type == CD_MLOOPCOL)
-                       CustomData_add_layer(fdata, CD_MCOL, CD_CALLOC, &(ldata->layers[i].name), total);
+                       CustomData_add_layer_named(fdata, CD_MCOL, CD_CALLOC, NULL, total, ldata->layers[i].name);
                if (ldata->layers[i].type == CD_WEIGHT_MLOOPCOL)
-                       CustomData_add_layer(fdata, CD_WEIGHT_MCOL, CD_CALLOC, &(ldata->layers[i].name), total);
+                       CustomData_add_layer_named(fdata, CD_WEIGHT_MCOL, CD_CALLOC, NULL, total, ldata->layers[i].name);
        }
 }
 
index ec66410da63ffd10fc362a6ead43ccc485c312ef..e1598b8fad3fc630e5031c8dd1fea662d896565a 100644 (file)
@@ -336,9 +336,6 @@ typedef struct EditDerivedBMesh {
        /*private variables, for number of verts/edges/faces
          within the above hash/table members*/
        int tv, te, tf;
-
-       /*customdata layout of the tesselated faces*/
-       CustomData tessface_layout;
 } EditDerivedBMesh;
 
 static void bmdm_recalc_lookups(EditDerivedBMesh *bmdm)
@@ -962,7 +959,7 @@ static void bmDM_drawMappedFacesGLSL(DerivedMesh *dm,
                int (*setMaterial)(int, void *attribs),
                int (*setDrawOptions)(void *userData, int index), void *userData)
 {
-#if 1
+#if 0
        (void)dm;
        (void)setMaterial;
        (void)setDrawOptions;
@@ -971,13 +968,16 @@ static void bmDM_drawMappedFacesGLSL(DerivedMesh *dm,
 
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
        BMesh *bm= bmdm->tc->bm;
+       BMEditMesh *em = bmdm->tc;
        float (*vertexCos)[3]= bmdm->vertexCos;
        float (*vertexNos)[3]= bmdm->vertexNos;
        BMVert *eve;
        BMFace *efa;
+       BMIter iter;
+       BMLoop **ltri;
        DMVertexAttribs attribs;
        GPUVertexAttribs gattribs;
-       MTFace *tf;
+       MTexPoly *tp;
        int transp, new_transp, orig_transp, tfoffset;
        int i, b, matnr, new_matnr, dodraw, layer;
 
@@ -986,42 +986,47 @@ static void bmDM_drawMappedFacesGLSL(DerivedMesh *dm,
 
        transp = GPU_get_material_blend_mode();
        orig_transp = transp;
-       layer = CustomData_get_layer_index(&bm->pdata, CD_MTFACE);
-       tfoffset = (layer == -1)? -1: bm->pdata.layers[layer].offset;
 
        memset(&attribs, 0, sizeof(attribs));
 
        /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
        glShadeModel(GL_SMOOTH);
+       BM_ITER_INDEX(eve, &iter, bm, BM_VERTS_OF_MESH, NULL, i) {
+                BMINDEX_SET(eve, i);
+       }
 
-       for (i=0,eve=bm->verts.first; eve; eve= eve->next)
-               BMINDEX_SET(eve, i++);
-
-#define PASSATTRIB(efa, eve, vert) {                                                                                   \
+#define PASSATTRIB(loop, eve, vert) {                                                                                  \
        if(attribs.totorco) {                                                                                                           \
-               float *orco = attribs.orco.array[BMINDEX_GET(eve)];                                                     \
+               float *orco = attribs.orco.array[BMINDEX_GET(eve)];                                             \
                glVertexAttrib3fvARB(attribs.orco.glIndex, orco);                                               \
        }                                                                                                                                                       \
        for(b = 0; b < attribs.tottface; b++) {                                                                         \
-               MTFace *_tf = (MTFace*)((char*)efa->data + attribs.tface[b].bmOffset);  \
-               glVertexAttrib2fvARB(attribs.tface[b].glIndex, _tf->uv[vert]);                  \
+               MLoopUV *_luv = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, b);\
+               glVertexAttrib2fvARB(attribs.tface[b].glIndex, _luv->uv);                               \
        }                                                                                                                                                       \
        for(b = 0; b < attribs.totmcol; b++) {                                                                          \
-               MCol *cp = (MCol*)((char*)efa->data + attribs.mcol[b].bmOffset);                \
-               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);                                    \
+               MLoopCol *_cp = CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPCOL, b);\
+               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[i*4 + vert];                                                   \
                glVertexAttrib3fvARB(attribs.tang.glIndex, tang);                                               \
        }                                                                                                                                                       \
-}
-
-       for (i=0,efa= bm->faces.first; efa; i++,efa= efa->next) {
-               int drawSmooth= (efa->flag & ME_SMOOTH);
+       }
+       
+       BM_ITER_INDEX(efa, &iter, bm, BM_FACES_OF_MESH, NULL, i) {
+               BMINDEX_SET(efa, i);
+       }
+       
+       for (i=0, ltri=em->looptris[0]; i<em->tottri; i++, ltri += 3) {
+               int drawSmooth;
 
-               if(setDrawOptions && !setDrawOptions(userData, i))
+               efa = ltri[0]->f;
+               drawSmooth= BM_TestHFlag(efa, BM_SMOOTH);
+               
+               if(setDrawOptions && !setDrawOptions(userData, BMINDEX_GET(efa)))
                        continue;
 
                new_matnr = efa->mat_nr + 1;
@@ -1031,9 +1036,9 @@ static void bmDM_drawMappedFacesGLSL(DerivedMesh *dm,
                                DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
                }
 
-               if(tfoffset != -1) {
-                       tf = (MTFace*)((char*)efa->data)+tfoffset;
-                       new_transp = tf->transp;
+               if(attribs.tottface) {
+                       tp = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
+                       new_transp = tp->transp;
 
                        if(new_transp != transp) {
                                if(new_transp == GPU_BLEND_SOLID && orig_transp != GPU_BLEND_SOLID)
@@ -1045,69 +1050,51 @@ static void bmDM_drawMappedFacesGLSL(DerivedMesh *dm,
                }
 
                if(dodraw) {
-                       glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
+                       glBegin(GL_TRIANGLES);
                        if (!drawSmooth) {
                                if(vertexCos) glNormal3fv(bmdm->faceNos[i]);
-                               else glNormal3fv(efa->n);
-
-                               PASSATTRIB(efa, efa->v1, 0);
-                               if(vertexCos) glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
-                               else glVertex3fv(efa->v1->co);
+                               else glNormal3fv(efa->no);
 
-                               PASSATTRIB(efa, efa->v2, 1);
-                               if(vertexCos) glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
-                               else glVertex3fv(efa->v2->co);
+                               PASSATTRIB(ltri[0], ltri[0]->v, 0);
+                               if(vertexCos) glVertex3fv(vertexCos[BMINDEX_GET(ltri[0]->v)]);
+                               else glVertex3fv(ltri[0]->v->co);
 
-                               PASSATTRIB(efa, efa->v3, 2);
-                               if(vertexCos) glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
-                               else glVertex3fv(efa->v3->co);
+                               PASSATTRIB(ltri[1], ltri[1]->v, 1);
+                               if(vertexCos) glVertex3fv(vertexCos[BMINDEX_GET(ltri[1]->v)]);
+                               else glVertex3fv(ltri[1]->v->co);
 
-                               if(efa->v4) {
-                                       PASSATTRIB(efa, efa->v4, 3);
-                                       if(vertexCos) glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
-                                       else glVertex3fv(efa->v4->co);
-                               }
+                               PASSATTRIB(ltri[2], ltri[2]->v, 2);
+                               if(vertexCos) glVertex3fv(vertexCos[BMINDEX_GET(ltri[2]->v)]);
+                               else glVertex3fv(ltri[2]->v->co);
                        } else {
-                               PASSATTRIB(efa, efa->v1, 0);
+                               PASSATTRIB(ltri[0], ltri[0]->v, 0);
                                if(vertexCos) {
-                                       glNormal3fv(vertexNos[(int) efa->v1->tmp.l]);
-                                       glVertex3fv(vertexCos[(int) efa->v1->tmp.l]);
+                                       glNormal3fv(vertexNos[BMINDEX_GET(ltri[0]->v)]);
+                                       glVertex3fv(vertexCos[BMINDEX_GET(ltri[0]->v)]);
                                }
                                else {
-                                       glNormal3fv(efa->v1->no);
-                                       glVertex3fv(efa->v1->co);
+                                       glNormal3fv(ltri[0]->v->no);
+                                       glVertex3fv(ltri[0]->v->co);
                                }
 
-                               PASSATTRIB(efa, efa->v2, 1);
+                               PASSATTRIB(ltri[1], ltri[1]->v, 1);
                                if(vertexCos) {
-                                       glNormal3fv(vertexNos[(int) efa->v2->tmp.l]);
-                                       glVertex3fv(vertexCos[(int) efa->v2->tmp.l]);
+                                       glNormal3fv(vertexNos[BMINDEX_GET(ltri[1]->v)]);
+                                       glVertex3fv(vertexCos[BMINDEX_GET(ltri[1]->v)]);
                                }
                                else {
-                                       glNormal3fv(efa->v2->no);
-                                       glVertex3fv(efa->v2->co);
+                                       glNormal3fv(ltri[1]->v->no);
+                                       glVertex3fv(ltri[1]->v->co);
                                }
 
-                               PASSATTRIB(efa, efa->v3, 2);
+                               PASSATTRIB(ltri[2], ltri[2]->v, 2);
                                if(vertexCos) {
-                                       glNormal3fv(vertexNos[(int) efa->v3->tmp.l]);
-                                       glVertex3fv(vertexCos[(int) efa->v3->tmp.l]);
+                                       glNormal3fv(vertexNos[BMINDEX_GET(ltri[2]->v)]);
+                                       glVertex3fv(vertexCos[BMINDEX_GET(ltri[2]->v)]);
                                }
                                else {
-                                       glNormal3fv(efa->v3->no);
-                                       glVertex3fv(efa->v3->co);
-                               }
-
-                               if(efa->v4) {
-                                       PASSATTRIB(efa, efa->v4, 3);
-                                       if(vertexCos) {
-                                               glNormal3fv(vertexNos[(int) efa->v4->tmp.l]);
-                                               glVertex3fv(vertexCos[(int) efa->v4->tmp.l]);
-                                       }
-                                       else {
-                                               glNormal3fv(efa->v4->no);
-                                               glVertex3fv(efa->v4->co);
-                                       }
+                                       glNormal3fv(ltri[2]->v->no);
+                                       glVertex3fv(ltri[2]->v->co);
                                }
                        }
                        glEnd();
@@ -1600,7 +1587,7 @@ CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm)
 {
        EditDerivedBMesh *bmdm = (EditDerivedBMesh*)dm;
 
-       return &bmdm->tessface_layout;
+       return &bmdm->dm.faceData;
 }
 
 CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm)
@@ -1630,14 +1617,8 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, Object *UNUSED(ob),
        DM_init((DerivedMesh*)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert, 
                 em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface);
        
-       for (i=0; i<bm->ldata.totlayer; i++) {
-               if (bm->ldata.layers[i].type == CD_MLOOPCOL) {
-                       CustomData_add_layer(&bmdm->tessface_layout, CD_MCOL, CD_ASSIGN, NULL, 0);
-               } else if (bm->ldata.layers[i].type == CD_MLOOPUV) {
-                       CustomData_add_layer(&bmdm->tessface_layout, CD_MTFACE, CD_ASSIGN, NULL, 0);
-               }
-       }
-
+       CustomData_from_bmeshpoly(&bmdm->dm.faceData, &em->bm->pdata, &em->bm->ldata, 0);
+       
        bmdm->dm.numVertData = bm->totvert;
        bmdm->dm.numEdgeData = bm->totedge;
        bmdm->dm.numFaceData = em->tottri;
index a3af1938c8b154236d1637aa9f7fad7ef1e4e6ab..6d80949163121e598da4667084dad60bdccaa1e0 100644 (file)
@@ -51,6 +51,10 @@ a different face hole boundary*/
        ele = BMIter_New(iter, bm, type, data); \
        for ( ; ele; ele=BMIter_Step(iter))
 
+#define BM_ITER_INDEX(ele, iter, bm, type, data, indexvar) \
+       ele = BMIter_New(iter, bm, type, data); \
+       for (indexvar=0; ele; indexvar++, ele=BMIter_Step(iter))
+
 #define BM_ITER_SELECT(ele, iter, bm, type, data)\
 for (ele = BMIter_New(iter, bm, type, data); ele; ele=BMIter_Step(iter)) {\
        if (BM_TestHFlag(ele, BM_HIDDEN) || !BM_TestHFlag(ele, BM_SELECT)) continue;
index 8906ef1f3015da511c3956973dbda8b63b46c1b9..2ca74ac22687704d87174e737b58b60e08aee4b5 100644 (file)
@@ -260,8 +260,6 @@ void bmesh_edgesplitop_exec(BMesh *bm, BMOperator *op)
                                continue;
                        }
 
-                       BMO_SetFlag(bm, l->e, EDGE_DEL);
-
                        nextl = (BMLoop*) l->next;
                        prevl = (BMLoop*) l->prev;
                        
index 16e53883008f9196b7d06d6fc43ceb219cb5383d..ffa04edee488baa8b79a5f51d4e74d32d5471d2c 100644 (file)
@@ -60,7 +60,7 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
        float (*keyco)[3]= NULL;
        int *keyi;
        int set_key = BMO_Get_Int(op, "set_shapekey");
-       int i, j, li, allocsize[4] = {512, 512, 2048, 512};
+       int totuv, i, j, li, allocsize[4] = {512, 512, 2048, 512};
 
        if (!me || !me->totvert) return; /*sanity check*/
        
@@ -71,7 +71,14 @@ void mesh_to_bmesh_exec(BMesh *bm, BMOperator *op) {
        CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
        CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
        CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
-
+       
+       /*make sure uv layer names are consistent*/
+       totuv = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
+       for (i=0; i<totuv; i++) {
+               int li = CustomData_get_layer_index_n(&bm->pdata, CD_MTEXPOLY, i);
+               CustomData_set_layer_name(&bm->ldata, CD_MLOOPUV, i, bm->pdata.layers[li].name);
+       }
+       
        CustomData_add_layer(&bm->vdata, CD_SHAPE_KEYINDEX, CD_ASSIGN, NULL, 0);
 
        if (!CustomData_has_layer(&bm->edata, CD_CREASE))
index 7791ddb38aff7d3679a7802edd9762b6868fc921..115e3bda00fc2c2f7571fd286b9489cefbdb2311 100644 (file)
@@ -2689,28 +2689,6 @@ void MESH_OT_select_vertex_path(wmOperatorType *ot)
 }
 /********************** Rip Operator *************************/
 
-#if 0
-/* helper for below */
-static void mesh_rip_setface(EditMesh *em, EditFace *sefa)
-{
-       /* put new vertices & edges in best face */
-       if(sefa->v1->tmp.v) sefa->v1= sefa->v1->tmp.v;
-       if(sefa->v2->tmp.v) sefa->v2= sefa->v2->tmp.v;
-       if(sefa->v3->tmp.v) sefa->v3= sefa->v3->tmp.v;
-       if(sefa->v4 && sefa->v4->tmp.v) sefa->v4= sefa->v4->tmp.v;
-
-       sefa->e1= addedgelist(em, sefa->v1, sefa->v2, sefa->e1);
-       sefa->e2= addedgelist(em, sefa->v2, sefa->v3, sefa->e2);
-       if(sefa->v4) {
-               sefa->e3= addedgelist(em, sefa->v3, sefa->v4, sefa->e3);
-               sefa->e4= addedgelist(em, sefa->v4, sefa->v1, sefa->e4);
-       }
-       else
-               sefa->e3= addedgelist(em, sefa->v3, sefa->v1, sefa->e3);
-
-}
-#endif
-
 /* helper to find edge for edge_rip */
 static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *co2, short *mval)
 {
@@ -2870,7 +2848,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        }
                }
        }
-
+       
        EDBM_clear_flag_all(em, BM_SELECT);
        BMO_HeaderFlag_Buffer(em->bm, &bmop, side?"edgeout2":"edgeout1", BM_SELECT, BM_EDGE);
 
@@ -2912,211 +2890,6 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event)
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
 
        return OPERATOR_FINISHED;
-#if 0 //BMESH_TODO
-       ARegion *ar= CTX_wm_region(C);
-       RegionView3D *rv3d= ar->regiondata;
-       Object *obedit= CTX_data_edit_object(C);
-       EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
-       EditVert *eve, *nextve;
-       EditEdge *eed, *seed= NULL;
-       EditFace *efa, *sefa= NULL;
-       float projectMat[4][4], vec[3], dist, mindist;
-       short doit= 1, *mval= event->mval;
-
-       /* select flush... vertices are important */
-       EM_selectmode_set(em);
-
-       view3d_get_object_project_mat(rv3d, obedit, projectMat);
-
-       /* find best face, exclude triangles and break on face select or faces with 2 edges select */
-       mindist= 1000000.0f;
-       for(efa= em->faces.first; efa; efa=efa->next) {
-               if( efa->f & 1)
-                       break;
-               if(efa->v4 && faceselectedOR(efa, SELECT) ) {
-                       int totsel=0;
-
-                       if(efa->e1->f & SELECT) totsel++;
-                       if(efa->e2->f & SELECT) totsel++;
-                       if(efa->e3->f & SELECT) totsel++;
-                       if(efa->e4->f & SELECT) totsel++;
-
-                       if(totsel>1)
-                               break;
-                       view3d_project_float(ar, efa->cent, vec, projectMat);
-                       dist= sqrt( (vec[0]-mval[0])*(vec[0]-mval[0]) + (vec[1]-mval[1])*(vec[1]-mval[1]) );
-                       if(dist<mindist) {
-                               mindist= dist;
-                               sefa= efa;
-                       }
-               }
-       }
-
-       if(efa) {
-               BKE_report(op->reports, RPT_ERROR, "Can't perform ripping with faces selected this way");
-               BKE_mesh_end_editmesh(obedit->data, em);
-               return OPERATOR_CANCELLED;
-       }
-       if(sefa==NULL) {
-               BKE_report(op->reports, RPT_ERROR, "No proper selection or faces included");
-               BKE_mesh_end_editmesh(obedit->data, em);
-               return OPERATOR_CANCELLED;
-       }
-
-
-       /* duplicate vertices, new vertices get selected */
-       for(eve = em->verts.last; eve; eve= eve->prev) {
-               eve->tmp.v = NULL;
-               if(eve->f & SELECT) {
-                       eve->tmp.v = addvertlist(em, eve->co, eve);
-                       eve->f &= ~SELECT;
-                       eve->tmp.v->f |= SELECT;
-               }
-       }
-
-       /* find the best candidate edge */
-       /* or one of sefa edges is selected... */
-       if(sefa->e1->f & SELECT) seed= sefa->e2;
-       if(sefa->e2->f & SELECT) seed= sefa->e1;
-       if(sefa->e3->f & SELECT) seed= sefa->e2;
-       if(sefa->e4 && sefa->e4->f & SELECT) seed= sefa->e3;
-
-       /* or we do the distance trick */
-       if(seed==NULL) {
-               mindist= 1000000.0f;
-               if(sefa->e1->v1->tmp.v || sefa->e1->v2->tmp.v) {
-                       dist = mesh_rip_edgedist(ar, projectMat,
-                                                                        sefa->e1->v1->co,
-                                                                        sefa->e1->v2->co, mval);
-                       if(dist<mindist) {
-                               seed= sefa->e1;
-                               mindist= dist;
-                       }
-               }
-               if(sefa->e2->v1->tmp.v || sefa->e2->v2->tmp.v) {
-                       dist = mesh_rip_edgedist(ar, projectMat,
-                                                                        sefa->e2->v1->co,
-                                                                        sefa->e2->v2->co, mval);
-                       if(dist<mindist) {
-                               seed= sefa->e2;
-                               mindist= dist;
-                       }
-               }
-               if(sefa->e3->v1->tmp.v || sefa->e3->v2->tmp.v) {
-                       dist= mesh_rip_edgedist(ar, projectMat,
-                                                                       sefa->e3->v1->co,
-                                                                       sefa->e3->v2->co, mval);
-                       if(dist<mindist) {
-                               seed= sefa->e3;
-                               mindist= dist;
-                       }
-               }
-               if(sefa->e4 && (sefa->e4->v1->tmp.v || sefa->e4->v2->tmp.v)) {
-                       dist= mesh_rip_edgedist(ar, projectMat,
-                                                                       sefa->e4->v1->co,
-                                                                       sefa->e4->v2->co, mval);
-                       if(dist<mindist) {
-                               seed= sefa->e4;
-                               mindist= dist;
-                       }
-               }
-       }
-
-       if(seed==NULL) {        // never happens?
-               BKE_report(op->reports, RPT_ERROR, "No proper edge found to start");
-               BKE_mesh_end_editmesh(obedit->data, em);
-               return OPERATOR_CANCELLED;
-       }
-
-       faceloop_select(em, seed, 2);   // tmp abuse for finding all edges that need duplicated, returns OK faces with f1
-
-       /* duplicate edges in the loop, with at least 1 vertex selected, needed for selection flip */
-       for(eed = em->edges.last; eed; eed= eed->prev) {
-               eed->tmp.v = NULL;
-               if((eed->v1->tmp.v) || (eed->v2->tmp.v)) {
-                       EditEdge *newed;
-
-                       newed= addedgelist(em, eed->v1->tmp.v?eed->v1->tmp.v:eed->v1,
-                                                          eed->v2->tmp.v?eed->v2->tmp.v:eed->v2, eed);
-                       if(eed->f & SELECT) {
-                               EM_select_edge(eed, 0);
-                               EM_remove_selection(em, eed, EDITEDGE);
-                               EM_select_edge(newed, 1);
-                       }
-                       eed->tmp.v = (EditVert *)newed;
-               }
-       }
-
-       /* first clear edges to help finding neighbours */
-       for(eed = em->edges.last; eed; eed= eed->prev) eed->f1= 0;
-
-       /* put new vertices & edges && flag in best face */
-       mesh_rip_setface(em, sefa);
-
-       /* starting with neighbours of best face, we loop over the seam */
-       sefa->f1= 2;
-       doit= 1;
-       while(doit) {
-               doit= 0;
-
-               for(efa= em->faces.first; efa; efa=efa->next) {
-                       /* new vert in face */
-                       if (efa->v1->tmp.v || efa->v2->tmp.v ||
-                               efa->v3->tmp.v || (efa->v4 && efa->v4->tmp.v)) {
-                               /* face is tagged with loop */
-                               if(efa->f1==1) {
-                                       mesh_rip_setface(em, efa);
-                                       efa->f1= 2;
-                                       doit= 1;
-                               }
-                       }
-               }
-       }
-
-       /* remove loose edges, that were part of a ripped face */
-       for(eve = em->verts.first; eve; eve= eve->next) eve->f1= 0;
-       for(eed = em->edges.last; eed; eed= eed->prev) eed->f1= 0;
-       for(efa= em->faces.first; efa; efa=efa->next) {
-               efa->e1->f1= 1;
-               efa->e2->f1= 1;
-               efa->e3->f1= 1;
-               if(efa->e4) efa->e4->f1= 1;
-       }
-
-       for(eed = em->edges.last; eed; eed= seed) {
-               seed= eed->prev;
-               if(eed->f1==0) {
-                       if(eed->v1->tmp.v || eed->v2->tmp.v ||
-                          (eed->v1->f & SELECT) || (eed->v2->f & SELECT)) {
-                               remedge(em, eed);
-                               free_editedge(em, eed);
-                               eed= NULL;
-                       }
-               }
-               if(eed) {
-                       eed->v1->f1= 1;
-                       eed->v2->f1= 1;
-               }
-       }
-
-       /* and remove loose selected vertices, that got duplicated accidentally */
-       for(eve = em->verts.first; eve; eve= nextve) {
-               nextve= eve->next;
-               if(eve->f1==0 && (eve->tmp.v || (eve->f & SELECT))) {
-                       BLI_remlink(&em->verts,eve);
-                       free_editvert(em, eve);
-               }
-       }
-
-       DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-
-       BKE_mesh_end_editmesh(obedit->data, em);
-
-//     RNA_enum_set(op->ptr, "proportional", 0);
-//     RNA_boolean_set(op->ptr, "mirror", 0);
-//     WM_operator_name_call(C, "TRANSFORM_OT_translate", WM_OP_INVOKE_REGION_WIN, op->ptr);
-#endif
 }
 
 void MESH_OT_rip(wmOperatorType *ot)
index bdfbc488a06b9eb5d6545cf6c82b64a9a22b9746..4bb2060ac1819fdb9df83ae776de93a9d85c37fb 100644 (file)
@@ -202,6 +202,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
 
                BM_add_data_layer(em->bm, &em->bm->pdata, CD_MTEXPOLY);
                CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
+               CustomData_set_layer_name(&em->bm->pdata, CD_MTEXPOLY, layernum, name);
 
                if(layernum) /* copy data from active UV */
                        copy_editface_active_customdata(em, CD_MTFACE, layernum);
@@ -210,6 +211,8 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s
                        CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum);
 
                BM_add_data_layer(em->bm, &em->bm->ldata, CD_MLOOPUV);
+               CustomData_set_layer_name(&em->bm->ldata, CD_MLOOPUV, layernum, name);
+               
                CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);
                if(active_set || layernum==0)
                        CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum);