Revision: 40876
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40876
Author:   ender79
Date:     2011-10-09 16:59:48 +0000 (Sun, 09 Oct 2011)
Log Message:
-----------
Fix 28493: Meshes added with many addons revert to only verts on entry to edit 
mode

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/blenkernel/intern/mesh_validate.c
    branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
    branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c

Modified: 
branches/bmesh/blender/source/blender/blenkernel/intern/mesh_validate.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh_validate.c     
2011-10-09 12:41:42 UTC (rev 40875)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh_validate.c     
2011-10-09 16:59:48 UTC (rev 40876)
@@ -326,6 +326,7 @@
        MEdge *med, *med_orig;
        EdgeHash *eh = BLI_edgehash_new();
        int i, totedge, totface = mesh->totface;
+       int med_index;
 
        if(mesh->totedge==0)
                update= 0;
@@ -345,7 +346,9 @@
                        MLoop *l= &mesh->mloop[mp->loopstart];
                        int j, l_prev= (l + (mp->totloop-1))->v;
                        for (j=0; j < mp->totloop; j++, l++) {
-                               BLI_edgehash_insert(eh, l_prev, l->v, NULL);
+                               if (!BLI_edgehash_haskey(eh, l_prev, l->v)) {
+                                       BLI_edgehash_insert(eh, l_prev, l->v, 
NULL);
+                               }
                                l_prev= l->v;
                        }
                }
@@ -387,9 +390,29 @@
                        BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, 
(int*)&med->v2);
                        med->flag = ME_EDGEDRAW|ME_EDGERENDER|SELECT; /* select 
for newly created meshes which are selected [#25595] */
                }
+
+               /* store the new edge index in the hash value */
+               BLI_edgehashIterator_setValue(ehi, SET_INT_IN_POINTER(i));
        }
        BLI_edgehashIterator_free(ehi);
 
+       if (mesh->totpoly) {
+               /* second pass, iterate through all loops again and assign
+                  the newly created edges to them. */
+               MPoly *mp= mesh->mpoly;
+               for(i=0; i < mesh->totpoly; i++, mp++) {
+                       MLoop *l= &mesh->mloop[mp->loopstart];
+                       MLoop *l_prev= (l + (mp->totloop-1));
+                       int j;
+                       for (j=0; j < mp->totloop; j++, l++) {
+                               /* lookup hashed edge index */
+                               med_index = BLI_edgehash_lookup(eh, l_prev->v, 
l->v);
+                               l_prev->e = med_index;
+                               l_prev= l;
+                       }
+               }
+       }
+
        /* free old CustomData and assign new one */
        CustomData_free(&mesh->edata, mesh->totedge);
        mesh->edata = edata;

Modified: branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c   
2011-10-09 12:41:42 UTC (rev 40875)
+++ branches/bmesh/blender/source/blender/bmesh/operators/mesh_conv.c   
2011-10-09 16:59:48 UTC (rev 40876)
@@ -131,11 +131,12 @@
                vt[i] = v;
                BM_SetIndex(v, i);
 
+               /*transfer flags*/
+               v->head.flag = MEFlags_To_BMFlags(mvert->flag, BM_VERT);
+
                /*this is necassary for selection counts to work properly*/
                if(v->head.flag & BM_SELECT) BM_Select_Vert(bm, v, 1);
 
-               /*transfer flags*/
-               v->head.flag = MEFlags_To_BMFlags(mvert->flag, BM_VERT);
                BM_SetCDf(&bm->vdata, v, CD_BWEIGHT, (float)mvert->bweight / 
255.0f);
 
                /*Copy Custom Data*/
@@ -176,11 +177,11 @@
                BM_SetCDf(&bm->edata, e, CD_CREASE, (float)medge->crease / 
255.0f);
                BM_SetCDf(&bm->edata, e, CD_BWEIGHT, (float)medge->bweight / 
255.0f);
 
+               /*transfer flags*/
+               e->head.flag = MEFlags_To_BMFlags(medge->flag, BM_EDGE);
+
                /*this is necassary for selection counts to work properly*/
                if (e->head.flag & BM_SELECT) BM_Select(bm, e, 1);
-
-               /*transfer flags*/
-               e->head.flag = MEFlags_To_BMFlags(medge->flag, BM_EDGE);
        }
        
        if (!me->totpoly) {
@@ -227,12 +228,12 @@
                        continue;
                }
 
+               /*transfer flags*/
+               f->head.flag = MEFlags_To_BMFlags(mpoly->flag, BM_FACE);
+
                /*this is necassary for selection counts to work properly*/
                if (f->head.flag & BM_SELECT) BM_Select(bm, f, 1);
 
-               /*transfer flags*/
-               f->head.flag = MEFlags_To_BMFlags(mpoly->flag, BM_FACE);
-
                f->mat_nr = mpoly->mat_nr;
                if (i == me->act_face) bm->act_face = f;
 

Modified: branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c      
2011-10-09 12:41:42 UTC (rev 40875)
+++ branches/bmesh/blender/source/blender/editors/mesh/mesh_data.c      
2011-10-09 16:59:48 UTC (rev 40876)
@@ -629,14 +629,25 @@
 
 void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges)
 {
-       if(calc_edges || (mesh->totface && mesh->totedge == 0))
-               BKE_mesh_calc_edges(mesh, calc_edges);
-
        if(mesh->totface > 0 && mesh->totpoly == 0)
                convert_mfaces_to_mpolys(mesh);
 
+       if(calc_edges || (mesh->totpoly && mesh->totedge == 0))
+               BKE_mesh_calc_edges(mesh, calc_edges);
+
        mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, 
mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
 
+       mesh->totface = mesh_recalcTesselation(
+               &mesh->fdata,
+               &mesh->ldata,
+               &mesh->pdata,
+               mesh->mvert,
+               mesh->totface,
+               mesh->totloop,
+               mesh->totpoly,
+               0,
+               0);
+
        DAG_id_tag_update(&mesh->id, 0);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, mesh);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to