-> Bevel cleanup

Bevel and bmesh code is in need of some cleanup and fixing.

-Fixed potential crasher in BME_JEKV
-Sped up memory usage of BME_MF
-Removed unused structure members


More to come soon....
This commit is contained in:
2008-02-29 20:26:35 +00:00
parent 0b1ed4c0cd
commit 9d05090a86
3 changed files with 47 additions and 46 deletions

View File

@@ -49,8 +49,6 @@ struct BME_Vert;
struct BME_Edge;
struct BME_Poly;
struct BME_Loop;
struct RetopoPaintData;
struct DerivedMesh;
typedef struct BME_CycleNode{
struct BME_CycleNode *next, *prev;
@@ -60,17 +58,15 @@ typedef struct BME_CycleNode{
typedef struct BME_Mesh
{
ListBase verts, edges, polys, loops;
int lock; /*if set, all calls to eulers will fail.*/
struct BME_Mesh *backup; /*full copy of the mesh*/
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*/
struct DerivedMesh *derivedFinal, *derivedCage;
struct RetopoPaintData *retopo_paint_data; /*here for temporary code compatibility only*/
/*some temporary storage used by loop reverse and make face eulers*/
/*some scratch arrays used by eulers*/
struct BME_Vert **vtar;
struct BME_Edge **edar;
int edarlen;
int lastDataMask;
struct BME_Loop **lpar;
struct BME_Poly **plar;
int vtarlen, edarlen, lparlen, plarlen;
} BME_Mesh;
typedef struct BME_Vert
@@ -121,7 +117,6 @@ typedef struct BME_Poly
struct BME_Poly *next, *prev;
int EID;
struct BME_Loop *loopbase; /*First editloop around Polygon.*/
struct ListBase holes; /*list of inner loops in the face*/
unsigned int len; /*total length of the face. Eulers should preserve this data*/
void *data; /*custom face data*/
int eflag1, eflag2; /*reserved for use by eulers*/

View File

@@ -230,9 +230,14 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
tv = v1;
curvert = v2;
if(bm->vtarlen < len){
MEM_freeN(bm->vtar);
bm->vtar = MEM_callocN(sizeof(BME_Vert *)* len, "BMesh Vert pointer array");
bm->vtarlen = len;
}
/*insert tv into vlist since its the first vertex in face*/
i=0;
vlist=MEM_callocN(sizeof(BME_Vert*)*len,"BME_MF vlist array");
vlist=bm->vtar;
vlist[i] = tv;
/* Basic procedure: Starting with curv we find the edge in it's disk cycle which hasn't
@@ -311,8 +316,6 @@ BME_Poly *BME_MF(BME_Mesh *bm, BME_Vert *v1, BME_Vert *v2, BME_Edge **elist, int
if(edok != (l->e->eflag2 + 1)) BME_error();
}
}
MEM_freeN(vlist);
return f;
}
@@ -739,13 +742,24 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
/*second step, remove all the hanging loops attached to ke*/
killoop = ke->loop;
radlen = BME_cycle_length(&(ke->loop->radial));
/*make sure we have enough room in bm->lpar*/
if(bm->lparlen < radlen){
MEM_freeN(bm->lpar);
bm->lpar = MEM_callocN(sizeof(BME_Loop *)* radlen, "BMesh Loop pointer array");
bm->lparlen = bm->lparlen * radlen;
}
/*this should be wrapped into a bme_free_radial function to be used by BME_KF as well...*/
i=0;
while(i<radlen){
nextl = killoop->radial.next->data;
BME_free_loop(bm, killoop);
killoop = nextl;
bm->lpar[i] = killoop;
killoop = killoop->radial.next->data;
i++;
}
}
i=0;
while(i<radlen){
BME_free_loop(bm,bm->lpar[i]);
i++;
}
/*Validate radial cycle of oe*/
edok = BME_cycle_validate(radlen,&(oe->loop->radial));
@@ -794,14 +808,13 @@ int BME_JEKV(BME_Mesh *bm, BME_Edge *ke, BME_Vert *kv)
int BME_loop_reverse(BME_Mesh *bm, BME_Poly *f){
BME_Loop *l = f->loopbase, *curloop, *oldprev, *oldnext;
BME_Edge **elist;
int i, j, edok, len = 0;
len = BME_cycle_length(l);
if(bm->edarlen < len){
MEM_freeN(bm->edar);
bm->edar = MEM_callocN(sizeof(BME_Edge *)* len, "BMesh Edge pointer array");
bm->edarlen = bm->edarlen * len;
bm->edarlen = len;
}
for(i=0, curloop = l; i< len; i++, curloop=curloop->next){
@@ -840,11 +853,8 @@ int BME_loop_reverse(BME_Mesh *bm, BME_Poly *f){
}
}
/*rebuild radial*/
for(i=0, curloop = l; i < len; i++, curloop = curloop->next){
BME_radial_append(curloop->e, curloop);
//radok = BME_cycle_validate(curloop->e->tmp.l, &(curloop->radial));
//if(!radok || curloop->e->loop == NULL) BME_error();
}
for(i=0, curloop = l; i < len; i++, curloop = curloop->next) BME_radial_append(curloop->e, curloop);
/*validate radial*/
for(i=0, curloop = l; i < len; i++, curloop = curloop->next){
edok = BME_cycle_validate(curloop->e->eflag2, &(curloop->radial));
@@ -893,7 +903,6 @@ BME_Poly *BME_JFKE(BME_Mesh *bm, BME_Poly *f1, BME_Poly *f2, BME_Edge *e)
BME_Loop *curloop, *f1loop=NULL, *f2loop=NULL;
int loopok = 0, newlen = 0,i, f1len=0, f2len=0, radlen=0, edok;
if(f1->holes.first || f2->holes.first) return NULL; //dont operate on faces with holes. Not best solution but tolerable.
if(f1 == f2) return NULL; //can't join a face to itself
/*verify that e is in both f1 and f2*/
f1len = BME_cycle_length(f1->loopbase);

View File

@@ -47,8 +47,6 @@
#include "BKE_bmesh.h"
#include "BKE_global.h"
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
#include "BIF_editmesh.h"
@@ -89,8 +87,6 @@ void BME_free_mesh(BME_Mesh *bm)
while(bf){
nextf = bf->next;
BLI_remlink(&(bm->polys), bf);
if(bf->holes.first)
BLI_freelistN(&(bf->holes));
BME_free_poly(bm, bf);
bf = nextf;
@@ -112,16 +108,6 @@ void BME_free_mesh(BME_Mesh *bm)
bv = nextv;
}
if (bm->derivedFinal) {
bm->derivedFinal->needsFree = 1;
bm->derivedFinal->release(bm->derivedFinal);
}
if (bm->derivedCage && bm->derivedCage != bm->derivedFinal) {
bm->derivedCage->needsFree = 1;
bm->derivedCage->release(bm->derivedCage);
}
for(loopref=bm->loops.first;loopref;loopref=loopref->next) BME_delete_loop(bm,loopref->data);
BLI_freelistN(&(bm->loops));
@@ -155,9 +141,14 @@ void BME_free_mesh(BME_Mesh *bm)
*/
int BME_model_begin(BME_Mesh *bm){
/*scratch edge pointer array*/
/*Initialize some scratch pointer arrays used by eulers*/
bm->vtar = MEM_callocN(sizeof(BME_Vert *) * 1024, "BMesh scratch vert array");
bm->edar = MEM_callocN(sizeof(BME_Edge *) * 1024, "BMesh scratch edge array");
bm->edarlen = 1024;
bm->lpar = MEM_callocN(sizeof(BME_Loop *) * 1024, "BMesh scratch loop array");
bm->plar = MEM_callocN(sizeof(BME_Poly *) * 1024, "BMesh scratch poly array");
bm->vtarlen = bm->edarlen = bm->lparlen = bm->plarlen = 1024;
return 1;
}
@@ -170,11 +161,15 @@ void BME_model_end(BME_Mesh *bm){
totpoly = BLI_countlist(&(bm->polys));
totloop = BLI_countlist(&(bm->loops));
if(bm->edar){
MEM_freeN(bm->edar);
bm->edar = NULL;
bm->edarlen = 0;
}
if(bm->vtar) MEM_freeN(bm->vtar);
if(bm->edar) MEM_freeN(bm->edar);
if(bm->lpar) MEM_freeN(bm->lpar);
if(bm->plar) MEM_freeN(bm->plar);
bm->vtar = bm->edar = bm->lpar = bm->plar = NULL;
bm->vtarlen = bm->edarlen = bm->lparlen = bm->plarlen = 1024;
if(bm->totvert!=totvert || bm->totedge!=totedge || bm->totpoly!=totpoly || bm->totloop!=totloop)
BME_error();
@@ -293,6 +288,8 @@ int BME_validate_mesh(struct BME_Mesh *bm, int halt)
}
}
/*validate that EIDs are within range... if not indicates corrupted mem*/
/*if we get this far, pretty safe to return 1*/
return 1;
}