Port mball_to_mesh to use polys.
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 20 Mar 2012 14:23:22 +0000 (14:23 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 20 Mar 2012 14:23:22 +0000 (14:23 +0000)
source/blender/blenkernel/intern/mesh.c

index e376134b26b9c711501e8b3e6ab868558a04e43f..476fcff9220bdc315573bd9f9b44bb3d65fece67 100644 (file)
@@ -1155,7 +1155,8 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
 {
        DispList *dl;
        MVert *mvert;
-       MFace *mface;
+       MLoop *mloop, *allloop;
+       MPoly *mpoly;
        float *nors, *verts;
        int a, *index;
        
@@ -1163,13 +1164,14 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
        if (dl==NULL) return;
 
        if (dl->type==DL_INDEX4) {
-               me->totvert= dl->nr;
-               me->totface= dl->parts;
-               
                mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr);
-               mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, dl->parts);
+               allloop= mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4);
+               mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts);
                me->mvert= mvert;
-               me->mface= mface;
+               me->mloop= mloop;
+               me->mpoly= mpoly;
+               me->totvert= dl->nr;
+               me->totpoly= dl->parts;
 
                a= dl->nr;
                nors= dl->nors;
@@ -1185,25 +1187,30 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
                a= dl->parts;
                index= dl->index;
                while (a--) {
-                       mface->v1= index[0];
-                       mface->v2= index[1];
-                       mface->v3= index[2];
-                       mface->v4= index[3];
-                       mface->flag= ME_SMOOTH;
+                       int count= index[2] != index[3] ? 4 : 3;
+
+                       mloop[0].v= index[0];
+                       mloop[1].v= index[1];
+                       mloop[2].v= index[2];
+                       if (count == 4)
+                               mloop[3].v= index[3];
 
-                       test_index_face(mface, NULL, 0, (mface->v3==mface->v4)? 3: 4);
+                       mpoly->totloop= count;
+                       mpoly->loopstart= (int)(mloop - allloop);
+                       mpoly->flag= ME_SMOOTH;
 
-                       mface++;
+
+                       mpoly++;
+                       mloop+= count;
+                       me->totloop+= count;
                        index+= 4;
                }
 
-               make_edges(me, 0);      // all edges
-
+               mesh_update_customdata_pointers(me, TRUE);
 
-               /* BMESH_TODO - low priority, should make polygons instead */
-               convert_mfaces_to_mpolys(me);
+               mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
 
-               mesh_update_customdata_pointers(me, TRUE);
+               BKE_mesh_calc_edges(me, TRUE);
        }
 }