diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-03-21 16:47:20 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-03-21 16:47:20 +0300 |
commit | ab005dadd5878fe77d0654a3d5dd3d6ab49ea604 (patch) | |
tree | 406d03f892c1bc761a97a24f8b8b2094391d1da8 /source/blender/src/meshtools.c | |
parent | fa2627aa2c6040581700d02eed08790042a8bd84 (diff) |
replaced face sort by Z with randomize (Ctrl+F menu)
Diffstat (limited to 'source/blender/src/meshtools.c')
-rw-r--r-- | source/blender/src/meshtools.c | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/source/blender/src/meshtools.c b/source/blender/src/meshtools.c index 2c18cd8ec31..ec42c93355b 100644 --- a/source/blender/src/meshtools.c +++ b/source/blender/src/meshtools.c @@ -94,6 +94,7 @@ void sort_faces(void); #include "BLI_editVert.h" #include "BLI_threads.h" +#include "BLI_rand.h" /* for randome face sorting */ #include "mydevice.h" #include "blendef.h" @@ -444,41 +445,14 @@ static void permutate(void *list, int num, int size, int *index) MEM_freeN(buf); } -static MVert *mvertbase; -static MFace *mfacebase; - -static int verg_mface(const void *v1, const void *v2) -{ - MFace *x1, *x2; - - MVert *ve1, *ve2; - int i1, i2; - - i1 = ((int *) v1)[0]; - i2 = ((int *) v2)[0]; - - x1 = mfacebase + i1; - x2 = mfacebase + i2; - - ve1= mvertbase+x1->v1; - ve2= mvertbase+x2->v1; - - if( ve1->co[2] > ve2->co[2] ) return 1; - else if( ve1->co[2] < ve2->co[2]) return -1; - return 0; -} - /* sort faces on view axis */ static float *face_sort_floats; -static int vert_mface_floats(const void *v1, const void *v2) +static int float_sort(const void *v1, const void *v2) { float x1, x2; - int i1, i2; - - i1 = ((int *) v1)[0]; - i2 = ((int *) v2)[0]; - x1 = face_sort_floats[i1]; - x2 = face_sort_floats[i2]; + + x1 = face_sort_floats[((int *) v1)[0]]; + x2 = face_sort_floats[((int *) v2)[0]]; if( x1 > x2 ) return 1; else if( x1 < x2 ) return -1; @@ -497,7 +471,7 @@ void sort_faces(void) if(G.obedit) return; if(ob->type!=OB_MESH) return; - event = pupmenu("Sort Faces by%t|View Axis (back to front)%x1|View Axis (front to back)%x2|Cursor Distance (near to far)%x3|Cursor Distance (far to near)%x4|Z Axis%x5"); + event = pupmenu("Sort Faces by%t|View Axis (back to front)%x1|View Axis (front to back)%x2|Cursor Distance (near to far)%x3|Cursor Distance (far to near)%x4|Randomize%x5"); if (event==-1) return; me= ob->data; @@ -508,13 +482,17 @@ void sort_faces(void) for (i = 0; i < me->totface; i++) { index[i] = i; } - mvertbase= me->mvert; - mfacebase = me->mface; - + + face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totface, "sort faces float"); + /* sort index list instead of faces itself and apply this permutation to all face layers */ if (event == 5) { - qsort(index, me->totface, sizeof(int), verg_mface); + /* Random */ + for(i=0; i<me->totface; i++) { + face_sort_floats[i] = BLI_frand(); + } + qsort(index, me->totface, sizeof(int), float_sort); } else { /* event is 1 or 2*/ MFace *mf; float vec[3]; @@ -535,8 +513,6 @@ void sort_faces(void) Mat4MulVecfl(mat, cur); } - face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totface, "sort faces float"); - mf= me->mface; for(i=0; i<me->totface; i++, mf++) { /* find the faces center */ @@ -563,10 +539,11 @@ void sort_faces(void) face_sort_floats[i] = -VecLenf(cur, vec); /* front to back*/ } } - qsort(index, me->totface, sizeof(int), vert_mface_floats); - MEM_freeN(face_sort_floats); + qsort(index, me->totface, sizeof(int), float_sort); } + MEM_freeN(face_sort_floats); + for(i = 0; i < me->fdata.totlayer; i++) { layer = &me->fdata.layers[i]; permutate(layer->data, me->totface, CustomData_sizeof(layer->type), index); |