diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-10 15:34:52 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-10 15:34:52 +0300 |
commit | 7daabec53482a5b0700f19a0d03ed7ae60d1e1a2 (patch) | |
tree | 8f5793fa08dad9a82cd31525a83e9a42051a6703 | |
parent | 763e8d0bec3c49ca3f1644ef551f1e0cfdf30adf (diff) |
mesh validation: bugfix for removing doubles, another fix coming...
-rw-r--r-- | source/blender/blenkernel/intern/mesh_validate.c | 31 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_boxpack2d.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/boxpack2d.c | 10 |
3 files changed, 23 insertions, 20 deletions
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index 35a23a17115..5d8a2bdeb72 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -66,12 +66,12 @@ static void edge_store_assign(uint32_t verts[2], const uint32_t v1, const uint3 } } -static void edge_store_from_mface_quad(EdgeUUID es[3], MFace *mf) +static void edge_store_from_mface_quad(EdgeUUID es[4], MFace *mf) { edge_store_assign(es[0].verts, mf->v1, mf->v2); edge_store_assign(es[1].verts, mf->v2, mf->v3); edge_store_assign(es[2].verts, mf->v3, mf->v4); - edge_store_assign(es[2].verts, mf->v4, mf->v1); + edge_store_assign(es[3].verts, mf->v4, mf->v1); } static void edge_store_from_mface_tri(EdgeUUID es[3], MFace *mf) @@ -83,7 +83,8 @@ static void edge_store_from_mface_tri(EdgeUUID es[3], MFace *mf) static int uint_cmp(const void *v1, const void *v2) { - const unsigned int x1= GET_INT_FROM_POINTER(v1), x2= GET_INT_FROM_POINTER(v2); + const unsigned int x1= *(const unsigned int *)v1; + const unsigned int x2= *(const unsigned int *)v2; if( x1 > x2 ) return 1; else if( x1 < x2 ) return -1; @@ -97,16 +98,19 @@ static int search_face_cmp(const void *v1, const void *v2) if (sfa->v[0] > sfb->v[0]) return 1; else if (sfa->v[0] < sfb->v[0]) return -1; - if (sfa->v[1] > sfb->v[1]) return 1; + else if (sfa->v[1] > sfb->v[1]) return 1; else if (sfa->v[1] < sfb->v[1]) return -1; - if (sfa->v[2] > sfb->v[2]) return 1; + else if (sfa->v[2] > sfb->v[2]) return 1; else if (sfa->v[2] < sfb->v[2]) return -1; - if (sfa->v[3] > sfb->v[3]) return 1; + else if (sfa->v[3] > sfb->v[3]) return 1; else if (sfa->v[3] < sfb->v[3]) return -1; - return 0; +// else if (sfb->index > sfa->index) return 1; +// else if (sfb->index < sfa->index) return -1; + else return 0; + } int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge *medges, int totedge, MFace *mfaces, int totface, const short do_verbose, const short do_fixes) @@ -118,6 +122,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge // MVert *mv; MEdge *med; MFace *mf; + MFace *mf_prev; int i; int do_face_free= FALSE; @@ -175,7 +180,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge fidx = mf->v4 ? 3:2; do { - sf->v[fidx]= *(&mf->v1 + fidx); + sf->v[fidx]= *(&(mf->v1) + fidx); if(sf->v[fidx] >= totvert) { PRINT(" face %d: 'v%d' index out of range, %d\n", i, fidx + 1, sf->v[fidx]); remove= do_fixes; @@ -215,7 +220,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge } } - sort_faces[totsortface].index = i; + sf->index = i; if(mf->v4) { qsort(sf->v, 4, sizeof(unsigned int), uint_cmp); @@ -245,12 +250,12 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge /* on a valid mesh, code below will never run */ if(memcmp(sf->v, sf_prev->v, sizeof(sf_prev->v)) == 0) { /* slow, could be smarter here */ - MFace *mf= mfaces + sf->index; - MFace *mf_prev= mfaces + sf_prev->index; - EdgeUUID eu[4]; EdgeUUID eu_prev[4]; + mf= mfaces + sf->index; + mf_prev= mfaces + sf_prev->index; + if(mf->v4) { edge_store_from_mface_quad(eu, mf); edge_store_from_mface_quad(eu_prev, mf_prev); @@ -269,7 +274,7 @@ int BKE_mesh_validate_arrays(Mesh *me, MVert *UNUSED(mverts), int totvert, MEdge } else { edge_store_from_mface_tri(eu, mf); - edge_store_from_mface_tri(eu_prev, mf); + edge_store_from_mface_tri(eu_prev, mf_prev); if( ELEM3(eu[0].edval, eu_prev[0].edval, eu_prev[1].edval, eu_prev[2].edval) && ELEM3(eu[1].edval, eu_prev[0].edval, eu_prev[1].edval, eu_prev[2].edval) && diff --git a/source/blender/blenlib/BLI_boxpack2d.h b/source/blender/blenlib/BLI_boxpack2d.h index a83e4c28882..008af55e1d0 100644 --- a/source/blender/blenlib/BLI_boxpack2d.h +++ b/source/blender/blenlib/BLI_boxpack2d.h @@ -41,5 +41,5 @@ typedef struct boxPack { struct boxVert *v[4]; } boxPack; -void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height); +void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_height); diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index b20a42f5cf8..643dcb6efca 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -100,12 +100,10 @@ typedef struct boxVert { /* qsort function - sort largest to smallest */ static int box_areasort(const void *p1, const void *p2) { - const boxPack *b1=p1, *b2=p2; - float a1, a2; + const boxPack *b1= p1, *b2= p2; + const float a1= BOXAREA(b1); + const float a2= BOXAREA(b2); - a1 = BOXAREA(b1); - a2 = BOXAREA(b2); - if ( a1 < a2 ) return 1; else if ( a1 > a2 ) return -1; return 0; @@ -149,7 +147,7 @@ static int vertex_sort(const void *p1, const void *p2) * len - the number of boxes in the array. * tot_width and tot_height are set so you can normalize the data. * */ -void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height) +void boxPack2D(boxPack *boxarray, const int len, float *tot_width, float *tot_height) { boxVert *vert; /* the current vert */ int box_index, verts_pack_len, i, j, k, isect; |