-> Beginning of Custom Data support for BMesh
authorGeoffrey Bantle <hairbat@yahoo.com>
Sun, 1 Jun 2008 18:02:29 +0000 (18:02 +0000)
committerGeoffrey Bantle <hairbat@yahoo.com>
Sun, 1 Jun 2008 18:02:29 +0000 (18:02 +0000)
Now that new allocator is in place, Custom Data
can be effeciently added to BMesh. The plan is to
make all data not directly related to topology
Custom Data and allow callers to decide precisely
what information a mesh should have in order to
make the best tradeoff between memory usage/speed.

Right now not much to look at, just some structure
definitions and commented out code. More to come
soon...

source/blender/blenkernel/BKE_bmesh.h
source/blender/blenkernel/intern/BME_mesh.c
source/blender/blenkernel/intern/bmesh_private.h

index 87202ce047a7bcb7bc8a978afb2001446cab8665..ab2fd34cd427a34650fa78d8be8632f249d68c3e 100644 (file)
 #include "BLI_ghash.h"
 #include "BLI_memarena.h"
 #include "DNA_customdata_types.h"
+#include "DNA_image_types.h"
 #include "BLI_editVert.h"
 #include "BKE_DerivedMesh.h"
 #include "transform.h"
 
+/*forward declerations*/
 struct BME_Vert;
 struct BME_Edge;
 struct BME_Poly;
 struct BME_Loop;
 
+
 struct BME_mempool;
 typedef struct BME_mempool BME_mempool;
 
+/*Custom Data Types and defines
+       Eventual plan is to move almost everything to custom data and let caller
+       decide when making the mesh what layers they want to store in the mesh
+
+       This stuff should probably go in a seperate file....
+*/
+typedef struct BME_CustomDataLayer {
+       int type;                                       /* type of data in layer */
+       int offset;                                     /* offset of layer in block */
+       int active;                                     /* offset of active layer*/
+       char name[32];                                  /* layer name */
+} BME_CustomDataLayer;
+
+typedef struct BME_CustomData {
+       BME_CustomDataLayer *layers;    /*Custom Data Layers*/
+       BME_mempool *pool;                              /*pool for alloc of blocks*/
+       int totlayer, totsize;          /*total layers and total size in bytes of each block*/
+} BME_CustomData;
+
+#define BME_CD_FACETEX         1               /*Image texture/texface*/
+#define BME_CD_LOOPTEX         2               /*UV coordinates*/
+#define BME_CD_LOOPCOL         3               /*Vcolors*/
+#define BME_CD_DEFORMVERT      4               /*Vertex Group/Weights*/
+#define BME_CD_NUMTYPES                5
+
+typedef struct BME_DeformWeight {
+       int                             def_nr;
+       float                   weight;
+} BME_DeformWeight;
+
+typedef struct BME_DeformVert {
+       struct BME_DeformWeight *dw;
+       int totweight;
+} BME_DeformVert;
+
+typedef struct BME_facetex{
+       struct Image *tpage;
+       char flag, transp;
+       short mode, tile, unwrap;
+}BME_facetex;
+
+typedef struct BME_looptex{
+       float u, v;
+}BME_looptex;
+
+typedef struct BME_loopcol{
+       char r, g, b, a;
+}BME_loopcol;
+
+/*Notes on further structure Cleanup:
+       -Remove the tflags, they belong in custom data layers
+       -Remove the eflags completely, they are mostly not used
+       -Remove the selection/vis/bevel weight flag/values ect and move them to custom data
+       -Remove EID member and move to custom data
+       -Add a radial cycle length, disk cycle length and loop cycle lenght attributes to custom data and have eulers maintain/use them if present.
+       -Move data such as vertex coordinates/normals to custom data and leave pointers in structures to active layer data.
+       -Remove BME_CycleNode structure?
+*/
 typedef struct BME_CycleNode{
        struct BME_CycleNode *next, *prev;
        void *data;
@@ -72,9 +133,9 @@ typedef struct BME_Mesh
        struct BME_Loop **lpar;
        struct BME_Poly **plar;
        int vtarlen, edarlen, lparlen, plarlen;
-       int totvert, totedge, totpoly, totloop;                 /*record keeping*/
-       int nextv, nexte, nextp, nextl;                                 /*Next element ID for verts/edges/faces/loops. Never reused*/
-       //struct CustomData vdata, edata, pdata, ldata; /*Custom Data Layer information*/
+       int totvert, totedge, totpoly, totloop;                         /*record keeping*/
+       int nextv, nexte, nextp, nextl;                                         /*Next element ID for verts/edges/faces/loops. Never reused*/
+       struct BME_CustomData vdata, edata, pdata, ldata;       /*Custom Data Layer information*/
 } BME_Mesh;
 
 typedef struct BME_Vert
index 307047463cf05b69a17ce2c8c2e8d09bdffa8056..e12ba2f8c650ca5be85a23d7e1b6d5e312df56b4 100644 (file)
@@ -62,8 +62,7 @@
  *  Allocates a new BME_Mesh structure
 */
 
-
-
+//BME_Mesh *BME_make_mesh(int valloc, int ealloc, int lalloc, int palloc, int vdata[BME_CD_NUMTYPES], int edata[BME_CD_NUMTYPES], int ldata[BME_CD_NUMTYPES], int pdata[BME_CD_NUMTYPES])
 BME_Mesh *BME_make_mesh(int valloc, int ealloc, int lalloc, int palloc){
        /*allocate the structure*/
        BME_Mesh *bm = MEM_callocN(sizeof(BME_Mesh),"BMesh");
@@ -72,11 +71,17 @@ BME_Mesh *BME_make_mesh(int valloc, int ealloc, int lalloc, int palloc){
        bm->epool = BME_mempool_create(sizeof(BME_Edge), ealloc, ealloc);
        bm->ppool = BME_mempool_create(sizeof(BME_Poly), palloc, palloc);
        bm->lpool = BME_mempool_create(sizeof(BME_Loop), lalloc, lalloc);
-       /*allocate the customdata pools*/
-       return bm;
-}
 
+       /*Setup Custom data structs and layers*/
+       /*      
+               BME_CD_Create(bm, &bm->vdata, vdata);
+               BME_CD_Create(bm, &bm->edata, edata);
+               BME_CD_Create(bm, &bm->ldata, ldata);
+               BME_CD_Create(bm, &bm->pdata, pdata);
 
+       */
+       return bm;
+}
 /*     
  *     BME FREE MESH
  *
@@ -90,8 +95,12 @@ void BME_free_mesh(BME_Mesh *bm)
        BME_mempool_destroy(bm->epool);
        BME_mempool_destroy(bm->ppool);
        BME_mempool_destroy(bm->lpool);
-       /*destroy custom data pools*/
-
+       /*
+               BME_CD_Free(bm, &bm->vdata);
+               BME_CD_Free(bm, &bm->edata);
+               BME_CD_Free(bm, &bm->ldata);
+               BME_CD_Free(bm, &bm->pdata);
+       */
        MEM_freeN(bm);  
 }
 
@@ -156,6 +165,13 @@ void BME_model_end(BME_Mesh *bm){
        }
 }
 
+/*note, this needs to be turned on for debugging only.
+       We need two levels of debugging,
+       1: Mesh level
+       2: Euler level
+       Both need to be turned off in production builds (they really slow things down)
+*/
+
 /*     
  *     BME VALIDATE MESH
  *
index ed58421ffb7e9c7dd58ac6c67f2a325f3f0f93e5..4aa2a85b8b1e4dc477bab4258d8bf810b97db9d5 100644 (file)
 
 #include "BKE_bmesh.h"
 
-/*MEMORY MANAGMENT*/
-struct BME_mempool;
-typedef struct BME_mempool BME_mempool;
-
 struct BME_mempool *BME_mempool_create(int esize, int tote, int pchunk);
 void BME_mempool_destroy(struct BME_mempool *pool);
 void *BME_mempool_alloc(struct BME_mempool *pool);