diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-23 17:25:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-23 17:25:06 +0400 |
commit | f4b9e837414439ddc7055e112984687d97ef84da (patch) | |
tree | 6e98d56c9cfb1394113f071358d309915a5447ef /source/blender/blenkernel/intern/editderivedmesh.c | |
parent | 25a3d11260b20d340932bc88e0a1a3c66e6c2211 (diff) |
improve editmode triangulation by re-using the loop array when
possiblem, this has to guess when the size is too big so as to re-
well.
If this isnt done, then the number of faces is used to allocate the
initial array to at least avoid many small allocs.
added BLI_array_reserve() to reserve elements and avoid reallocing many
small arrays when the loop starts.
Diffstat (limited to 'source/blender/blenkernel/intern/editderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 5029ff73f03..a52454a76ad 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -121,8 +121,34 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm) BMLoop *l; int i = 0, j; +#if 0 + /* note, we could be clever and re-use this array but would need to ensure + * its realloced at some point, for now just free it */ if (tm->looptris) MEM_freeN(tm->looptris); + /* Use tm->tottri when set, this means no reallocs while transforming, + * (unless scanfill fails), otherwise... */ + /* allocate the length of totfaces, avoid many small reallocs, + * if all faces are tri's it will be correct, quads == 2x allocs */ + BLI_array_reserve(looptris, (tm->tottri && tm->tottri < bm->totface * 3) ? tm->tottri : bm->totface); +#else + + /* this means no reallocs for quad dominant models, for */ + if ( (tm->looptris != NULL) && + (tm->tottri != 0) && + /* (totrti <= bm->totface * 2) would be fine for all quads, + * but incase there are some ngons, still re-use the array */ + (tm->tottri <= bm->totface * 3)) + { + looptris = tm->looptris; + } + else { + if (tm->looptris) MEM_freeN(tm->looptris); + BLI_array_reserve(looptris, bm->totface); + } + +#endif + f = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL); for ( ; f; f=BMIter_Step(&iter)) { /*don't consider two-edged faces*/ @@ -168,6 +194,7 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm) EditVert *v, *lastv=NULL, *firstv=NULL; EditEdge *e; EditFace *efa; + int totfilltri; BLI_begin_edgefill(); /*scanfill time*/ @@ -190,15 +217,14 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm) /*complete the loop*/ BLI_addfilledge(firstv, v); - BLI_edgefill(2); + totfilltri = BLI_edgefill(2); + BLI_array_growitems(looptris, totfilltri); for (efa = fillfacebase.first; efa; efa=efa->next) { BMLoop *l1= efa->v1->tmp.p; BMLoop *l2= efa->v2->tmp.p; BMLoop *l3= efa->v3->tmp.p; - BLI_array_growone(looptris); - if (BM_GetIndex(l1) > BM_GetIndex(l2)) { SWAP(BMLoop*, l1, l2); } if (BM_GetIndex(l2) > BM_GetIndex(l3)) { SWAP(BMLoop*, l2, l3); } if (BM_GetIndex(l1) > BM_GetIndex(l2)) { SWAP(BMLoop*, l1, l2); } |