part 1 of cleaning up my little array macro library to be a formal API. also removed...
[blender.git] / source / blender / blenkernel / intern / editderivedbmesh.c
index a17d16ce754191a3d464fcf9557e285830daa9f7..6aca8d51bc26032e2cc8d2d3ed2b277e9ebe0584 100644 (file)
@@ -60,6 +60,7 @@
 #include "BLI_memarena.h"
 #include "BLI_scanfill.h"
 #include "BLI_ghash.h"
+#include "BLI_array.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_customdata.h"
@@ -124,7 +125,7 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm)
 {
        BMesh *bm = tm->bm;
        BMLoop **looptris = NULL;
-       V_DYNDECLARE(looptris);
+       BLI_array_declare(looptris);
        BMIter iter, liter;
        BMFace *f;
        BMLoop *l;
@@ -132,6 +133,45 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm)
        
        if (tm->looptris) MEM_freeN(tm->looptris);
 
+#if 0 //simple quad/triangle code for performance testing purposes
+       looptris = MEM_callocN(sizeof(void*)*bm->totface*8, "looptris");
+
+       f = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
+       for ( ; f; f=BMIter_Step(&iter)) {
+               EditVert *v, *lastv=NULL, *firstv=NULL;
+               EditEdge *e;
+               EditFace *efa;
+
+               /*don't consider two-edged faces*/
+               if (f->len < 3) continue;
+               
+               //BLI_array_growone(looptris);
+               //BLI_array_growone(looptris);
+               //BLI_array_growone(looptris);
+
+               looptris[i*3] = f->loopbase;
+               looptris[i*3+1] = f->loopbase->head.next;
+               looptris[i*3+2] = f->loopbase->head.next->next;
+               i++;
+
+               if (f->len > 3) {
+                       //BLI_array_growone(looptris);
+                       //BLI_array_growone(looptris);
+                       //BLI_array_growone(looptris);
+
+                       looptris[i*3] = f->loopbase;
+                       looptris[i*3+1] = f->loopbase->head.next->next;
+                       looptris[i*3+2] = f->loopbase->head.next->next->next;
+                       i++;
+               }
+
+       }
+
+       tm->tottri = i;
+       tm->looptris = looptris;
+       return;
+#endif
+
        f = BMIter_New(&iter, bm, BM_FACES_OF_MESH, NULL);
        for ( ; f; f=BMIter_Step(&iter)) {
                EditVert *v, *lastv=NULL, *firstv=NULL;
@@ -166,9 +206,9 @@ static void BMEdit_RecalcTesselation_intern(BMEditMesh *tm)
                for (efa = fillfacebase.first; efa; efa=efa->next) {
                        BMLoop *l1, *l2, *l3;
 
-                       V_GROW(looptris);
-                       V_GROW(looptris);
-                       V_GROW(looptris);
+                       BLI_array_growone(looptris);
+                       BLI_array_growone(looptris);
+                       BLI_array_growone(looptris);
                        
                        looptris[i*3] = l1 = efa->v1->tmp.p;
                        looptris[i*3+1] = l2 = efa->v2->tmp.p;
@@ -213,6 +253,26 @@ void BMEdit_RecalcTesselation(BMEditMesh *tm)
        }
 }
 
+void BMEdit_UpdateLinkedCustomData(BMEditMesh *em)
+{
+       BMesh *bm = em->bm;
+       int act;
+
+       if (CustomData_has_layer(&bm->pdata, CD_MTEXPOLY)) {
+               act = CustomData_get_active_layer(&bm->pdata, CD_MTEXPOLY);
+               CustomData_set_layer_active(&bm->ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_render_layer(&bm->pdata, CD_MTEXPOLY);
+               CustomData_set_layer_render(&bm->ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_clone_layer(&bm->pdata, CD_MTEXPOLY);
+               CustomData_set_layer_clone(&bm->ldata, CD_MLOOPUV, act);
+
+               act = CustomData_get_mask_layer(&bm->pdata, CD_MTEXPOLY);
+               CustomData_set_layer_mask(&bm->ldata, CD_MLOOPUV, act);
+       }
+}
+
 /*does not free the BMEditMesh struct itself*/
 void BMEdit_Free(BMEditMesh *em)
 {
@@ -340,7 +400,7 @@ static void bmDM_recalcTesselation(DerivedMesh *dm)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
 
-       bmdm_recalc_lookups(bmdm);
+       //bmdm_recalc_lookups(bmdm);
 }
 
 static void bmDM_foreachMappedVert(DerivedMesh *dm, void (*func)(void *userData, int index, float *co, float *no_f, short *no_s), void *userData)
@@ -1443,9 +1503,9 @@ static void bmDM_release(void *dm)
                        MEM_freeN(bmdm->faceNos);
                }
                
-               BLI_ghash_free(bmdm->fhash, NULL, NULL);
-               BLI_ghash_free(bmdm->ehash, NULL, NULL);
-               BLI_ghash_free(bmdm->vhash, NULL, NULL);
+               if (bmdm->fhash) BLI_ghash_free(bmdm->fhash, NULL, NULL);
+               if (bmdm->ehash) BLI_ghash_free(bmdm->ehash, NULL, NULL);
+               if (bmdm->vhash) BLI_ghash_free(bmdm->vhash, NULL, NULL);
 
                if (bmdm->vtable) MEM_freeN(bmdm->vtable);
                if (bmdm->etable) MEM_freeN(bmdm->etable);
@@ -1610,7 +1670,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, Object *ob,
                }
        }
 
-       bmdm_recalc_lookups(bmdm);
+       //bmdm_recalc_lookups(bmdm);
 
        return (DerivedMesh*) bmdm;
 }