--- ray/src/common/mesh.c 2012/11/06 01:04:23 2.24 +++ ray/src/common/mesh.c 2012/11/06 01:56:37 2.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mesh.c,v 2.24 2012/11/06 01:04:23 greg Exp $"; +static const char RCSid[] = "$Id: mesh.c,v 2.25 2012/11/06 01:56:37 greg Exp $"; #endif /* * Mesh support routines @@ -148,43 +148,43 @@ nextmeshtri( /* get next triangle ID */ MESH *mp ) { + int advance = 1; int pn; MESHPATCH *pp; if (*tip == OVOID) { /* check for first index */ *tip = 0; - return(mp->npatches > 0); /* assumes 1 local triangle */ + advance = 0; } pn = *tip >> 10; - if (pn >= mp->npatches) /* past end? */ - return(0); - pp = &mp->patch[pn]; - if (!(*tip & 0x200)) { /* local triangle? */ - if ((*tip & 0x1ff) < pp->ntris-1) { - ++*tip; - return(1); + while (pn < mp->npatches) { + pp = &mp->patch[pn]; + if (!(*tip & 0x200)) { /* local triangle? */ + if ((*tip & 0x1ff) < pp->ntris - advance) { + *tip += advance; + return(1); + } + *tip &= ~0x1ff; /* move on to single-joiners */ + *tip |= 0x200; + advance = 0; } - *tip &= ~0x1ff; /* move on to single-joiners */ - *tip |= 0x200; - if (pp->nj1tris) /* is there at least one? */ - return(1); - } - if (!(*tip & 0x100)) { /* single joiner? */ - if ((*tip & 0xff) < pp->nj1tris-1) { - ++*tip; - return(1); + if (!(*tip & 0x100)) { /* single joiner? */ + if ((*tip & 0xff) < pp->nj1tris - advance) { + *tip += advance; + return(1); + } + *tip &= ~0xff; /* move on to double-joiners */ + *tip |= 0x100; + advance = 0; } - *tip &= ~0xff; /* move on to double-joiners */ - *tip |= 0x100; - if (pp->nj2tris) /* is there one? */ + if ((*tip & 0xff) < pp->nj2tris - advance) { + *tip += advance; return(1); + } + *tip = ++pn << 10; /* first in next patch */ + advance = 0; } - if ((*tip & 0xff) < pp->nj2tris-1) { /* double-joiner? */ - ++*tip; - return(1); - } - *tip = ++pn << 10; /* first in next patch */ - return(pn < mp->npatches); + return(0); /* out of patches */ } int