--- ray/src/common/mesh.c 2012/11/06 01:56:37 2.25 +++ ray/src/common/mesh.c 2017/03/01 21:51:38 2.28 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mesh.c,v 2.25 2012/11/06 01:56:37 greg Exp $"; +static const char RCSid[] = "$Id: mesh.c,v 2.28 2017/03/01 21:51:38 greg Exp $"; #endif /* * Mesh support routines @@ -52,6 +52,7 @@ static int cvcmp(const char *vv1, const char *vv2) /* compare encoded vertices */ { const MCVERT *v1 = (const MCVERT *)vv1, *v2 = (const MCVERT *)vv2; + if (v1->fl != v2->fl) return(1); if (v1->xyz[0] != v2->xyz[0]) @@ -99,7 +100,7 @@ getmesh( /* get new mesh data reference */ } if ((pathname = getpath(mname, getrlibpath(), R_OK)) == NULL) { sprintf(errmsg, "cannot find mesh file \"%s\"", mname); - error(USER, errmsg); + error(SYSTEM, errmsg); } flags &= ~ms->ldflags; if (flags) @@ -148,41 +149,27 @@ nextmeshtri( /* get next triangle ID */ MESH *mp ) { - int advance = 1; int pn; MESHPATCH *pp; - if (*tip == OVOID) { /* check for first index */ - *tip = 0; - advance = 0; - } - pn = *tip >> 10; + pn = ++(*tip) >> 10; /* next triangle (OVOID init) */ while (pn < mp->npatches) { pp = &mp->patch[pn]; if (!(*tip & 0x200)) { /* local triangle? */ - if ((*tip & 0x1ff) < pp->ntris - advance) { - *tip += advance; + if ((*tip & 0x1ff) < pp->ntris) return(1); - } *tip &= ~0x1ff; /* move on to single-joiners */ *tip |= 0x200; - advance = 0; } if (!(*tip & 0x100)) { /* single joiner? */ - if ((*tip & 0xff) < pp->nj1tris - advance) { - *tip += advance; + if ((*tip & 0xff) < pp->nj1tris) return(1); - } *tip &= ~0xff; /* move on to double-joiners */ *tip |= 0x100; - advance = 0; } - if ((*tip & 0xff) < pp->nj2tris - advance) { - *tip += advance; + if ((*tip & 0xff) < pp->nj2tris) return(1); - } *tip = ++pn << 10; /* first in next patch */ - advance = 0; } return(0); /* out of patches */ } @@ -341,12 +328,12 @@ getmeshtri( /* get triangle vertices */ int32 addmeshvert( /* find/add a mesh vertex */ - MESH *mp, + MESH *mp, MESHVERT *vp ) { - LUENT *lvp; - MCVERT cv; + LUENT *lvp; + MCVERT cv; int i; if (!(vp->fl & MT_V)) @@ -453,8 +440,8 @@ addmeshtri( /* add a new mesh triangle */ OBJECT mo ) { - int32 vid[3], t; - int pn[3], i; + int32 vid[3], t; + int pn[3], i; MESHPATCH *pp; if (!(tv[0].fl & tv[1].fl & tv[2].fl & MT_V)) @@ -473,7 +460,7 @@ addmeshtri( /* add a new mesh triangle */ error(INTERNAL, "modifier range error in addmeshtri"); } /* assign triangle */ - if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */ + if ((pn[0] == pn[1]) & (pn[1] == pn[2])) { /* local case */ pp = &mp->patch[pn[0]]; if (pp->tri == NULL) { pp->tri = (struct PTri *)malloc( @@ -499,8 +486,7 @@ addmeshtri( /* add a new mesh triangle */ pp->trimat[pp->ntris] = mo; return(pn[0] << 10 | pp->ntris++); } - } - if (pn[0] == pn[1]) { + } else if (pn[0] == pn[1]) { t = vid[2]; vid[2] = vid[1]; vid[1] = vid[0]; vid[0] = t; i = pn[2]; pn[2] = pn[1]; pn[1] = pn[0]; pn[0] = i; } else if (pn[0] == pn[2]) { @@ -549,7 +535,7 @@ checkmesh(MESH *mp) /* validate mesh data */ { static char embuf[128]; int nouvbounds = 1; - int i; + int i; /* basic checks */ if (mp == NULL) return("NULL mesh pointer");