4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
28 * (uit traces) maart 95
30 /** \file blender/blenlib/intern/scanfill.c
39 #include "MEM_guardedalloc.h"
41 #include "BLI_callbacks.h"
42 #include "BLI_editVert.h"
43 #include "BLI_listbase.h"
45 #include "BLI_scanfill.h"
46 #include "BLI_utildefines.h"
47 #include "BLI_threads.h"
49 /* callbacks for errors and interrupts and some goo */
50 static void (*BLI_localErrorCallBack)(const char*) = NULL;
51 static int (*BLI_localInterruptCallBack)(void) = NULL;
53 void BLI_setErrorCallBack(void (*f)(const char *))
55 BLI_localErrorCallBack = f;
58 void BLI_setInterruptCallBack(int (*f)(void))
60 BLI_localInterruptCallBack = f;
63 /* just flush the error to /dev/null if the error handler is missing */
64 void callLocalErrorCallBack(const char* msg)
66 if (BLI_localErrorCallBack) {
67 BLI_localErrorCallBack(msg);
72 /* ignore if the interrupt wasn't set */
73 static int callLocalInterruptCallBack(void)
75 if (BLI_localInterruptCallBack) {
76 return BLI_localInterruptCallBack();
84 typedef struct PolyFill {
90 typedef struct ScFillVert {
92 EditEdge *first,*last;
99 #define COMPLIMIT 0.00003
101 static ScFillVert *scdata;
103 ListBase fillvertbase = {0,0};
104 ListBase filledgebase = {0,0};
105 ListBase fillfacebase = {0,0};
107 static short cox, coy;
109 /* **** FUBCTIONS FOR QSORT *************************** */
112 static int vergscdata(const void *a1, const void *a2)
114 const ScFillVert *x1=a1,*x2=a2;
116 if( x1->v1->co[coy] < x2->v1->co[coy] ) return 1;
117 else if( x1->v1->co[coy] > x2->v1->co[coy]) return -1;
118 else if( x1->v1->co[cox] > x2->v1->co[cox] ) return 1;
119 else if( x1->v1->co[cox] < x2->v1->co[cox]) return -1;
124 static int vergpoly(const void *a1, const void *a2)
126 const PolyFill *x1=a1, *x2=a2;
128 if( x1->min[cox] > x2->min[cox] ) return 1;
129 else if( x1->min[cox] < x2->min[cox] ) return -1;
130 else if( x1->min[coy] > x2->min[coy] ) return 1;
131 else if( x1->min[coy] < x2->min[coy] ) return -1;
136 /* ************* MEMORY MANAGEMENT ************* */
138 struct mem_elements {
139 struct mem_elements *next, *prev;
144 /* simple optimization for allocating thousands of small memory blocks
145 only to be used within loops, and not by one function at a time
146 free in the end, with argument '-1'
149 static void *new_mem_element(int size)
151 int blocksize= 16384;
152 static int offs= 0; /* the current free address */
153 static struct mem_elements *cur= 0, *first;
154 static ListBase lb= {0, 0};
157 if(size>10000 || size==0) {
158 printf("incorrect use of new_mem_element\n");
161 /*BMESH_TODO: keep the first block, gives memory leak on exit with 'newmem' */
163 BLI_remlink(&lb, first);
167 MEM_freeN(cur->data);
172 /*reset the block we're keeping*/
173 BLI_addtail(&lb, first);
174 memset(first->data, 0, blocksize);
181 size= 4*( (size+3)/4 );
184 if(size+offs < blocksize) {
185 adr= (void *) (cur->data+offs);
191 cur= MEM_callocN( sizeof(struct mem_elements), "newmem");
192 cur->data= MEM_callocN(blocksize, "newmem");
193 BLI_addtail(&lb, cur);
199 void BLI_end_edgefill(void)
203 fillvertbase.first= fillvertbase.last= 0;
204 filledgebase.first= filledgebase.last= 0;
205 fillfacebase.first= fillfacebase.last= 0;
207 BLI_unlock_thread(LOCK_SCANFILL);
210 /* **** FILL ROUTINES *************************** */
212 EditVert *BLI_addfillvert(float *vec)
216 eve= new_mem_element(sizeof(EditVert));
217 BLI_addtail(&fillvertbase, eve);
226 EditEdge *BLI_addfilledge(EditVert *v1, EditVert *v2)
230 newed= new_mem_element(sizeof(EditEdge));
231 BLI_addtail(&filledgebase, newed);
239 static void addfillface(EditVert *v1, EditVert *v2, EditVert *v3, int mat_nr)
241 /* does not make edges */
244 evl= new_mem_element(sizeof(EditFace));
245 BLI_addtail(&fillfacebase, evl);
254 static int boundisect(PolyFill *pf2, PolyFill *pf1)
256 /* has pf2 been touched (intersected) by pf1 ? with bounding box */
257 /* test first if polys exist */
259 if(pf1->edges==0 || pf2->edges==0) return 0;
261 if(pf2->max[cox] < pf1->min[cox] ) return 0;
262 if(pf2->max[coy] < pf1->min[coy] ) return 0;
264 if(pf2->min[cox] > pf1->max[cox] ) return 0;
265 if(pf2->min[coy] > pf1->max[coy] ) return 0;
268 if(pf2->max[cox]<pf1->max[cox]) pf2->max[cox]= pf1->max[cox];
269 if(pf2->max[coy]<pf1->max[coy]) pf2->max[coy]= pf1->max[coy];
271 if(pf2->min[cox]>pf1->min[cox]) pf2->min[cox]= pf1->min[cox];
272 if(pf2->min[coy]>pf1->min[coy]) pf2->min[coy]= pf1->min[coy];
278 static void mergepolysSimp(PolyFill *pf1, PolyFill *pf2) /* add pf2 to pf1 */
283 /* replace old poly numbers */
284 eve= fillvertbase.first;
286 if(eve->xs== pf2->nr) eve->xs= pf1->nr;
289 eed= filledgebase.first;
291 if(eed->f1== pf2->nr) eed->f1= pf1->nr;
295 pf1->verts+= pf2->verts;
296 pf1->edges+= pf2->edges;
297 pf2->verts= pf2->edges= 0;
298 pf1->f= (pf1->f | pf2->f);
301 static short testedgeside(float *v1, float *v2, float *v3)
302 /* is v3 to the right of v1-v2 ? With exception: v3==v1 || v3==v2 */
306 inp= (v2[cox]-v1[cox])*(v1[coy]-v3[coy])
307 +(v1[coy]-v2[coy])*(v1[cox]-v3[cox]);
309 if(inp<0.0) return 0;
311 if(v1[cox]==v3[cox] && v1[coy]==v3[coy]) return 0;
312 if(v2[cox]==v3[cox] && v2[coy]==v3[coy]) return 0;
317 static short addedgetoscanvert(ScFillVert *sc, EditEdge *eed)
319 /* find first edge to the right of eed, and insert eed before that */
324 sc->first= sc->last= eed;
325 eed->prev= eed->next=0;
332 fac1= eed->v2->co[coy]-y;
334 fac1= 1.0e10*(eed->v2->co[cox]-x);
337 else fac1= (x-eed->v2->co[cox])/fac1;
342 if(ed->v2==eed->v2) return 0;
344 fac= ed->v2->co[coy]-y;
346 fac= 1.0e10*(ed->v2->co[cox]-x);
349 else fac= (x-ed->v2->co[cox])/fac;
354 if(ed) BLI_insertlinkbefore((ListBase *)&(sc->first), ed, eed);
355 else BLI_addtail((ListBase *)&(sc->first),eed);
361 static ScFillVert *addedgetoscanlist(EditEdge *eed, int len)
363 /* inserts edge at correct location in ScFillVert list */
364 /* returns sc when edge already exists */
365 ScFillVert *sc,scsearch;
368 /* which vert is left-top? */
369 if(eed->v1->co[coy] == eed->v2->co[coy]) {
370 if(eed->v1->co[cox] > eed->v2->co[cox]) {
376 else if(eed->v1->co[coy] < eed->v2->co[coy]) {
381 /* find location in list */
382 scsearch.v1= eed->v1;
383 sc= (ScFillVert *)bsearch(&scsearch,scdata,len,
384 sizeof(ScFillVert), vergscdata);
386 if(sc==0) printf("Error in search edge: %p\n", (void *)eed);
387 else if(addedgetoscanvert(sc,eed)==0) return sc;
392 static short boundinsideEV(EditEdge *eed, EditVert *eve)
393 /* is eve inside boundbox eed */
395 float minx,maxx,miny,maxy;
397 if(eed->v1->co[cox]<eed->v2->co[cox]) {
398 minx= eed->v1->co[cox];
399 maxx= eed->v2->co[cox];
401 minx= eed->v2->co[cox];
402 maxx= eed->v1->co[cox];
404 if(eve->co[cox]>=minx && eve->co[cox]<=maxx) {
405 if(eed->v1->co[coy]<eed->v2->co[coy]) {
406 miny= eed->v1->co[coy];
407 maxy= eed->v2->co[coy];
409 miny= eed->v2->co[coy];
410 maxy= eed->v1->co[coy];
412 if(eve->co[coy]>=miny && eve->co[coy]<=maxy) return 1;
418 static void testvertexnearedge(void)
420 /* only vertices with ->h==1 are being tested for
421 being close to an edge, if true insert */
425 float dist,vec1[2],vec2[2],vec3[2];
427 eve= fillvertbase.first;
430 vec3[0]= eve->co[cox];
431 vec3[1]= eve->co[coy];
432 /* find the edge which has vertex eve */
433 ed1= filledgebase.first;
435 if(ed1->v1==eve || ed1->v2==eve) break;
442 eed= filledgebase.first;
444 if(eve!=eed->v1 && eve!=eed->v2 && eve->xs==eed->f1) {
445 if(compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) {
451 else if(compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) {
458 vec1[0]= eed->v1->co[cox];
459 vec1[1]= eed->v1->co[coy];
460 vec2[0]= eed->v2->co[cox];
461 vec2[1]= eed->v2->co[coy];
462 if(boundinsideEV(eed,eve)) {
463 dist= dist_to_line_v2(vec1,vec2,vec3);
466 ed1= BLI_addfilledge(eed->v1, eve);
468 /* printf("fill: vertex near edge %x\n",eve); */
485 static void splitlist(ListBase *tempve, ListBase *temped, short nr)
487 /* everything is in templist, write only poly nr to fillist */
488 EditVert *eve,*nextve;
489 EditEdge *eed,*nexted;
491 BLI_movelisttolist(tempve,&fillvertbase);
492 BLI_movelisttolist(temped,&filledgebase);
498 BLI_remlink(tempve,eve);
499 BLI_addtail(&fillvertbase,eve);
507 BLI_remlink(temped,eed);
508 BLI_addtail(&filledgebase,eed);
515 static void scanfill(PolyFill *pf, int mat_nr)
517 ScFillVert *sc = NULL, *sc1;
518 EditVert *eve,*v1,*v2,*v3;
519 EditEdge *eed,*nexted,*ed1,*ed2,*ed3;
521 int a,b,verts, maxface, totface;
522 short nr, test, twoconnected=0;
528 eve= fillvertbase.first;
530 printf("vert: %x co: %f %f\n",eve,eve->co[cox],eve->co[coy]);
533 eed= filledgebase.first;
535 printf("edge: %x verts: %x %x\n",eed,eed->v1,eed->v2);
539 /* STEP 0: remove zero sized edges */
540 eed= filledgebase.first;
542 if(eed->v1->co[cox]==eed->v2->co[cox]) {
543 if(eed->v1->co[coy]==eed->v2->co[coy]) {
544 if(eed->v1->f==255 && eed->v2->f!=255) {
546 eed->v2->tmp.v= eed->v1->tmp.v;
548 else if(eed->v2->f==255 && eed->v1->f!=255) {
550 eed->v1->tmp.v= eed->v2->tmp.v;
552 else if(eed->v2->f==255 && eed->v1->f==255) {
553 eed->v1->tmp.v= eed->v2->tmp.v;
557 eed->v2->tmp.v = eed->v1->tmp.v;
564 /* STEP 1: make using FillVert and FillEdge lists a sorted
567 sc= scdata= (ScFillVert *)MEM_callocN(pf->verts*sizeof(ScFillVert),"Scanfill1");
568 eve= fillvertbase.first;
574 eve->f= 0; /* flag for connectedges later on */
582 qsort(scdata, verts, sizeof(ScFillVert), vergscdata);
584 eed= filledgebase.first;
588 BLI_remlink(&filledgebase,eed);
589 /* commented all of this out, this I have no idea for what it is for, probably from ancient past */
590 /* it does crash blender, since it uses mixed original and new vertices (ton) */
591 // if(eed->v1->f==255) {
593 // while((eed->v1->f == 255) && (eed->v1->tmp.v != v1))
594 // eed->v1 = eed->v1->tmp.v;
596 // if(eed->v2->f==255) {
598 // while((eed->v2->f == 255) && (eed->v2->tmp.v != v2))
599 // eed->v2 = eed->v2->tmp.v;
601 if(eed->v1!=eed->v2) addedgetoscanlist(eed,verts);
607 for(a=0;a<verts;a++) {
608 printf("\nscvert: %x\n",sc->v1);
611 printf(" ed %x %x %x\n",eed,eed->v1,eed->v2);
618 /* STEP 2: FILL LOOP */
620 if(pf->f==0) twoconnected= 1;
622 /* (temporal) security: never much more faces than vertices */
624 maxface= 2*verts; /* 2*verts: based at a filled circle within a triangle */
627 for(a=0;a<verts;a++) {
628 /* printf("VERTEX %d %x\n",a,sc->v1); */
630 while(ed1) { /* set connectflags */
632 if(ed1->v1->h==1 || ed1->v2->h==1) {
633 BLI_remlink((ListBase *)&(sc->first),ed1);
634 BLI_addtail(&filledgebase,ed1);
635 if(ed1->v1->h>1) ed1->v1->h--;
636 if(ed1->v2->h>1) ed1->v2->h--;
642 while(sc->first) { /* for as long there are edges */
646 /* commented out... the ESC here delivers corrupted memory (and doesnt work during grab) */
647 /* if(callLocalInterruptCallBack()) break; */
648 if(totface>maxface) {
649 /* printf("Fill error: endless loop. Escaped at vert %d, tot: %d.\n", a, verts); */
654 sc->first=sc->last= 0;
655 /* printf("just 1 edge to vert\n"); */
656 BLI_addtail(&filledgebase,ed1);
661 /* test rest of vertices */
665 /* this happens with a serial of overlapping edges */
666 if(v1==v2 || v2==v3) break;
667 /* printf("test verts %x %x %x\n",v1,v2,v3); */
668 miny = ( (v1->co[coy])<(v3->co[coy]) ? (v1->co[coy]) : (v3->co[coy]) );
669 /* miny= MIN2(v1->co[coy],v3->co[coy]); */
673 for(b=a+1;b<verts;b++) {
675 if(sc1->v1->co[coy] <= miny) break;
677 if(testedgeside(v1->co,v2->co,sc1->v1->co))
678 if(testedgeside(v2->co,v3->co,sc1->v1->co))
679 if(testedgeside(v3->co,v1->co,sc1->v1->co)) {
680 /* point in triangle */
689 /* make new edge, and start over */
690 /* printf("add new edge %x %x and start again\n",v2,sc1->v1); */
692 ed3= BLI_addfilledge(v2, sc1->v1);
693 BLI_remlink(&filledgebase, ed3);
694 BLI_insertlinkbefore((ListBase *)&(sc->first), ed2, ed3);
702 /* printf("add face %x %x %x\n",v1,v2,v3); */
703 addfillface(v1, v2, v3, mat_nr);
705 BLI_remlink((ListBase *)&(sc->first),ed1);
706 BLI_addtail(&filledgebase,ed1);
710 /* ed2 can be removed when it's an old one */
711 if(ed2->f==0 && twoconnected) {
712 BLI_remlink((ListBase *)&(sc->first),ed2);
713 BLI_addtail(&filledgebase,ed2);
720 ed3= BLI_addfilledge(v1, v3);
721 BLI_remlink(&filledgebase, ed3);
726 /* printf("add new edge %x %x\n",v1,v3); */
727 sc1= addedgetoscanlist(ed3, verts);
729 if(sc1) { /* ed3 already exists: remove */
730 /* printf("Edge exists\n"); */
734 if(twoconnected) ed3= sc1->first;
737 if( (ed3->v1==v1 && ed3->v2==v3) || (ed3->v1==v3 && ed3->v2==v1) ) {
738 BLI_remlink((ListBase *)&(sc1->first),ed3);
739 BLI_addtail(&filledgebase,ed3);
750 /* test for loose edges */
754 if(ed1->v1->h<2 || ed1->v2->h<2) {
755 BLI_remlink((ListBase *)&(sc->first),ed1);
756 BLI_addtail(&filledgebase,ed1);
757 if(ed1->v1->h>1) ed1->v1->h--;
758 if(ed1->v2->h>1) ed1->v2->h--;
771 int BLI_begin_edgefill(void)
773 BLI_lock_thread(LOCK_SCANFILL);
778 int BLI_edgefill(int mat_nr)
781 - fill works with its own lists, so create that first (no faces!)
782 - for vertices, put in ->tmp.v the old pointer
783 - struct elements xs en ys are not used here: don't hide stuff in it
784 - edge flag ->f becomes 2 when it's a new edge
785 - mode: & 1 is check for crossings, then create edges (TO DO )
786 - mode: & 2 is enable shortest diagonal test for quads
788 ListBase tempve, temped;
790 EditEdge *eed,*nexted;
791 PolyFill *pflist,*pf;
792 float limit, *minp, *maxp, *v1, *v2, norm[3], len;
793 short a,c,poly=0,ok=0,toggle=0;
795 /* reset variables */
796 eve= fillvertbase.first;
806 if (a == 3 && (mat_nr & 2)) {
807 eve = fillvertbase.first;
809 addfillface(eve, eve->next, eve->next->next, 0);
811 } else if (a == 4 && (mat_nr & 2)) {
812 float vec1[3], vec2[3];
814 eve = fillvertbase.first;
816 if (1 && eve->next && eve->next->next && eve->next->next->next) { //BMESH_TODO) {
817 /*use shortest diagonal for quad*/
818 sub_v3_v3v3(vec1, eve->co, eve->next->next->co);
819 sub_v3_v3v3(vec2, eve->next->co, eve->next->next->next->co);
821 if (INPR(vec1, vec1) < INPR(vec2, vec2)) {
822 addfillface(eve, eve->next, eve->next->next, 0);
823 addfillface(eve->next->next, eve->next->next->next, eve, 0);
825 addfillface(eve->next, eve->next->next, eve->next->next->next, 0);
826 addfillface(eve->next->next->next, eve, eve->next, 0);
829 addfillface(eve, eve->next, eve->next->next, 0);
830 addfillface(eve->next->next, eve->next->next->next, eve, 0);
835 /* first test vertices if they are in edges */
836 /* including resetting of flags */
837 eed= filledgebase.first;
839 eed->f= eed->f1= eed->h= 0;
846 eve= fillvertbase.first;
857 /* NEW NEW! define projection: with 'best' normal */
858 /* just use the first three different vertices */
860 /* THIS PART STILL IS PRETTY WEAK! (ton) */
862 eve= fillvertbase.last;
866 eve= fillvertbase.first;
867 limit = a < 5 ? FLT_EPSILON*200 : M_PI/24.0;
870 if( compare_v3v3(v2, eve->co, COMPLIMIT)==0) {
871 float inner = angle_v3v3v3(v1, v2, eve->co);
873 if (fabs(inner-M_PI) < limit || fabs(inner) < limit) {
878 len= normal_tri_v3( norm,v1, v2, eve->co);
879 if(len != 0.0) break;
882 else if(compare_v3v3(v1, eve->co, COMPLIMIT)==0) {
888 if(len==0.0) return 0; /* no fill possible */
890 norm[0]= fabs(norm[0]);
891 norm[1]= fabs(norm[1]);
892 norm[2]= fabs(norm[2]);
894 if(norm[2]>=norm[0] && norm[2]>=norm[1]) {
897 else if(norm[1]>=norm[0] && norm[1]>=norm[2]) {
904 /* STEP 1: COUNT POLYS */
905 eve= fillvertbase.first;
907 /* get first vertex with no poly number */
910 /* now a sortof select connected */
918 if(toggle & 1) eed= filledgebase.first;
919 else eed= filledgebase.last;
922 if(eed->v1->xs==0 && eed->v2->xs==poly) {
927 else if(eed->v2->xs==0 && eed->v1->xs==poly) {
932 else if(eed->f1==0) {
933 if(eed->v1->xs==poly && eed->v2->xs==poly) {
938 if(toggle & 1) eed= eed->next;
945 /* printf("amount of poly's: %d\n",poly); */
947 /* STEP 2: remove loose edges and strings of edges */
948 eed= filledgebase.first;
950 if(eed->v1->h++ >250) break;
951 if(eed->v2->h++ >250) break;
955 /* otherwise it's impossible to be sure you can clear vertices */
956 callLocalErrorCallBack("No vertices with 250 edges allowed!");
960 /* does it only for vertices with ->h==1 */
961 testvertexnearedge();
967 if(toggle & 1) eed= filledgebase.first;
968 else eed= filledgebase.last;
970 if(toggle & 1) nexted= eed->next;
971 else nexted= eed->prev;
974 BLI_remlink(&fillvertbase,eed->v1);
975 BLI_remlink(&filledgebase,eed);
978 else if(eed->v2->h==1) {
980 BLI_remlink(&fillvertbase,eed->v2);
981 BLI_remlink(&filledgebase,eed);
987 if(filledgebase.first==0) {
988 /* printf("All edges removed\n"); */
994 - eve->f :1= availalble in edges
995 - eve->xs :polynumber
996 - eve->h :amount of edges connected to vertex
997 - eve->tmp.v :store! original vertex number
1000 - eed->f1 :poly number
1004 /* STEP 3: MAKE POLYFILL STRUCT */
1005 pflist= (PolyFill *)MEM_callocN(poly*sizeof(PolyFill),"edgefill");
1007 for(a=1;a<=poly;a++) {
1009 pf->min[0]=pf->min[1]=pf->min[2]= 1.0e20;
1010 pf->max[0]=pf->max[1]=pf->max[2]= -1.0e20;
1013 eed= filledgebase.first;
1015 pflist[eed->f1-1].edges++;
1019 eve= fillvertbase.first;
1021 pflist[eve->xs-1].verts++;
1022 minp= pflist[eve->xs-1].min;
1023 maxp= pflist[eve->xs-1].max;
1025 minp[cox]= (minp[cox])<(eve->co[cox]) ? (minp[cox]) : (eve->co[cox]);
1026 minp[coy]= (minp[coy])<(eve->co[coy]) ? (minp[coy]) : (eve->co[coy]);
1027 maxp[cox]= (maxp[cox])>(eve->co[cox]) ? (maxp[cox]) : (eve->co[cox]);
1028 maxp[coy]= (maxp[coy])>(eve->co[coy]) ? (maxp[coy]) : (eve->co[coy]);
1029 if(eve->h>2) pflist[eve->xs-1].f= 1;
1034 /* STEP 4: FIND HOLES OR BOUNDS, JOIN THEM
1035 * ( bounds just to divide it in pieces for optimization,
1036 * the edgefill itself has good auto-hole detection)
1037 * WATCH IT: ONLY WORKS WITH SORTED POLYS!!! */
1040 short *polycache, *pc;
1042 /* so, sort first */
1043 qsort(pflist, poly, sizeof(PolyFill), vergpoly);
1046 for(a=1;a<=poly;a++) {
1047 printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f);
1048 PRINT2(f, f, pf->min[0], pf->min[1]);
1052 polycache= pc= MEM_callocN(sizeof(short)*poly, "polycache");
1054 for(a=0; a<poly; a++, pf++) {
1055 for(c=a+1;c<poly;c++) {
1057 /* if 'a' inside 'c': join (bbox too)
1058 * Careful: 'a' can also be inside another poly.
1060 if(boundisect(pf, pflist+c)) {
1064 /* only for optimize! */
1065 /* else if(pf->max[cox] < (pflist+c)->min[cox]) break; */
1068 while(pc!=polycache) {
1070 mergepolysSimp(pf, pflist+ *pc);
1073 MEM_freeN(polycache);
1076 /* printf("after merge\n");
1078 for(a=1;a<=poly;a++) {
1079 printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f);
1083 /* STEP 5: MAKE TRIANGLES */
1085 tempve.first= fillvertbase.first;
1086 tempve.last= fillvertbase.last;
1087 temped.first= filledgebase.first;
1088 temped.last= filledgebase.last;
1089 fillvertbase.first=fillvertbase.last= 0;
1090 filledgebase.first=filledgebase.last= 0;
1093 for(a=0;a<poly;a++) {
1095 splitlist(&tempve,&temped,pf->nr);
1096 scanfill(pf, mat_nr);
1100 BLI_movelisttolist(&fillvertbase,&tempve);
1101 BLI_movelisttolist(&filledgebase,&temped);