2.5
[blender.git] / source / blender / blenkernel / intern / BME_structure.c
index d283e1df5ca9cddca74e9fca194aa84bbb91c94d..22ee48e4f7e996926f37b3fae097aa5776c6747e 100644 (file)
@@ -3,7 +3,7 @@
  *
  *     Low level routines for manipulating the BMesh structure.
  *
- * $Id: BME_structure.c,v 1.00 2007/01/17 17:42:01 Briggs Exp $
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -41,8 +41,6 @@
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
 #include "BLI_ghash.h"
-
-#include "BKE_customdata.h"
 /**
  *     MISC utility functions.
  *
@@ -86,78 +84,98 @@ int BME_edge_swapverts(BME_Edge *e, BME_Vert *orig, BME_Vert *new){
 
 BME_Vert *BME_addvertlist(BME_Mesh *bm, BME_Vert *example){
        BME_Vert *v=NULL;
-       v = MEM_callocN(sizeof(BME_Vert), "BME Vertex");
-       BLI_addtail(&(bm->verts), v);
+       v = BLI_mempool_alloc(bm->vpool);
+       v->next = v->prev = NULL;
        v->EID = bm->nextv;
+       v->co[0] = v->co[1] = v->co[2] = 0.0f;
+       v->no[0] = v->no[1] = v->no[2] = 0.0f;
+       v->edge = NULL;
+       v->data = NULL;
+       v->eflag1 = v->eflag2 = v->tflag1 = v->tflag2 = 0;
+       v->flag = v->h = 0;
+       v->bweight = 0.0f;
+       BLI_addtail(&(bm->verts), v);
        bm->nextv++;
        bm->totvert++;
 
-       if(example)
+       if(example){
                VECCOPY(v->co,example->co);
-       //if(example)
-       //      CustomData_em_copy_data(&bm->vdata, &bm->vdata, example->data, &v->data);
-       //else
-       //      CustomData_em_set_default(&bm->vdata, &v->data);
+               CustomData_bmesh_copy_data(&bm->vdata, &bm->vdata, example->data, &v->data);
+       }
+       else
+               CustomData_bmesh_set_default(&bm->vdata, &v->data);
 
        return v;
 }
 BME_Edge *BME_addedgelist(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge *example){
        BME_Edge *e=NULL;
-       e = MEM_callocN(sizeof(BME_Edge), "BME_Edge");
+       e = BLI_mempool_alloc(bm->epool);
+       e->next = e->prev = NULL;
+       e->EID = bm->nexte;
        e->v1 = v1;
        e->v2 = v2;
+       e->d1.next = e->d1.prev = e->d2.next = e->d2.prev = NULL;
        e->d1.data = e;
        e->d2.data = e;
-       e->EID = bm->nexte;
+       e->loop = NULL;
+       e->data = NULL;
+       e->eflag1 = e->eflag2 = e->tflag1 = e->tflag2 = 0;
+       e->flag = e->h = 0;
+       e->crease = e->bweight = 0.0f;
        bm->nexte++;
        bm->totedge++;
        BLI_addtail(&(bm->edges), e);
        
-       //if(example)
-       //      CustomData_em_copy_data(&bm->edata, &bm->edata, example->data, &e->data);
-       //else
-       //      CustomData_em_set_default(&bm->edata, &e->data);
+       if(example)
+               CustomData_bmesh_copy_data(&bm->edata, &bm->edata, example->data, &e->data);
+       else
+               CustomData_bmesh_set_default(&bm->edata, &e->data);
 
 
        return e;
 }
 BME_Loop *BME_create_loop(BME_Mesh *bm, BME_Vert *v, BME_Edge *e, BME_Poly *f, BME_Loop *example){
-       /*allocate a BME_Loop and add it to the loophash*/
        BME_Loop *l=NULL;
-       BME_CycleNode *loopnode = MEM_callocN(sizeof(BME_CycleNode),"BME Loop Reference");
-       l = MEM_callocN(sizeof(BME_Loop), "BME_Loop");
+       l = BLI_mempool_alloc(bm->lpool);
+       l->next = l->prev = NULL;
+       l->EID = bm->nextl;
+       l->radial.next = l->radial.prev = NULL;
        l->radial.data = l;
        l->v = v;
        l->e = e;
        l->f = f;
-       l->EID = bm->nextl;
-       l->gref = loopnode;
-       loopnode->data = l;
-       BLI_addtail(&(bm->loops),loopnode);
+       l->data = NULL;
+       l->eflag1 = l->eflag2 = l->tflag1 = l->tflag2 = 0;
+       l->flag = l->h = 0; //stupid waste!
        bm->nextl++;
        bm->totloop++;
        
-
-/*     if(example)
-               BME_CustomData_copy_data(&bm->ldata, &bm->ldata, example->data, &l->data);
+       if(example)
+               CustomData_bmesh_copy_data(&bm->ldata, &bm->ldata, example->data, &l->data);
        else
-               BME_CustomData_set_default(&bm->ldata, &l->data);
-*/
+               CustomData_bmesh_set_default(&bm->ldata, &l->data);
+
        return l;
 }
 
 BME_Poly *BME_addpolylist(BME_Mesh *bm, BME_Poly *example){
        BME_Poly *f = NULL;
-       f= MEM_callocN(sizeof(BME_Poly),"BME_Poly");
-       BLI_addtail(&(bm->polys),f);
+       f = BLI_mempool_alloc(bm->ppool);
+       f->next = f->prev = NULL;
        f->EID = bm->nextp;
+       f->loopbase = NULL;
+       f->len = 0;
+       f->data = NULL;
+       f->eflag1 = f->eflag2 = f->tflag1 = f->tflag2 = 0;
+       f->flag = f->h = f->mat_nr;
+       BLI_addtail(&(bm->polys),f);
        bm->nextp++;
        bm->totpoly++;
 
-       //if(example)
-       //      CustomData_em_copy_data(&bm->pdata, &bm->pdata, example->data, &f->data);
-       //else
-       //      CustomData_em_set_default(&bm->pdata, &f->data);
+       if(example)
+               CustomData_bmesh_copy_data(&bm->pdata, &bm->pdata, example->data, &f->data);
+       else
+               CustomData_bmesh_set_default(&bm->pdata, &f->data);
 
 
        return f;
@@ -168,31 +186,24 @@ BME_Poly *BME_addpolylist(BME_Mesh *bm, BME_Poly *example){
 */
 void BME_free_vert(BME_Mesh *bm, BME_Vert *v){
        bm->totvert--;
-       //CustomData_em_free_block(&bm->vdata, &v->data);
-       MEM_freeN(v);
+       CustomData_bmesh_free_block(&bm->vdata, &v->data);
+       BLI_mempool_free(bm->vpool, v);
 }
 void BME_free_edge(BME_Mesh *bm, BME_Edge *e){
        bm->totedge--;
-       //CustomData_em_free_block(&bm->edata, &e->data);
-       MEM_freeN(e);
+       CustomData_bmesh_free_block(&bm->edata, &e->data);
+       BLI_mempool_free(bm->epool, e);
 }
 void BME_free_poly(BME_Mesh *bm, BME_Poly *f){
        bm->totpoly--;
-       //CustomData_em_free_block(&bm->pdata, &f->data);
-       MEM_freeN(f);
-}
-void BME_delete_loop(BME_Mesh *bm, BME_Loop *l){
-       bm->totloop--;
-       //CustomData_em_free_block(&bm->ldata, &l->data);
-       MEM_freeN(l);
+       CustomData_bmesh_free_block(&bm->pdata, &f->data);
+       BLI_mempool_free(bm->ppool, f);
 }
 void BME_free_loop(BME_Mesh *bm, BME_Loop *l){
-       BME_CycleNode *loopref = l->gref;
-       BLI_freelinkN(&(bm->loops),loopref);
-       BME_delete_loop(bm,l);
+       bm->totloop--;
+       CustomData_bmesh_free_block(&bm->ldata, &l->data);
+       BLI_mempool_free(bm->lpool, l);
 }
-
-
 /**
  *     BMESH CYCLES
  *