--- ray/src/common/mesh.c 2003/06/30 14:59:11 2.9 +++ ray/src/common/mesh.c 2010/05/01 21:49:42 2.21 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: mesh.c,v 2.9 2003/06/30 14:59:11 schorsch Exp $"; +static const char RCSid[] = "$Id: mesh.c,v 2.21 2010/05/01 21:49:42 greg Exp $"; #endif /* * Mesh support routines @@ -7,7 +7,10 @@ static const char RCSid[] = "$Id: mesh.c,v 2.9 2003/06 #include -#include "standard.h" +#include "rtio.h" +#include "rtmath.h" +#include "rterror.h" +#include "paths.h" #include "octree.h" #include "object.h" #include "otypes.h" @@ -27,11 +30,16 @@ typedef struct { static MESH *mlist = NULL; /* list of loaded meshes */ +static lut_keycmpf_t cvcmp; +static lut_hashf_t cvhash; + static unsigned long -cvhash(cvp) /* hash an encoded vertex */ -MCVERT *cvp; +cvhash(p) /* hash an encoded vertex */ +/* MCVERT *cvp; */ +const void *p; { + const MCVERT *cvp = (const MCVERT *)p; unsigned long hval; if (!(cvp->fl & MT_V)) @@ -46,9 +54,11 @@ MCVERT *cvp; static int -cvcmp(v1, v2) /* compare encoded vertices */ -register MCVERT *v1, *v2; +cvcmp(vv1, vv2) /* compare encoded vertices */ +/* register MCVERT *v1, *v2; */ +const void *vv1, *vv2; { + const MCVERT *v1 = vv1, *v2 = vv2; if (v1->fl != v2->fl) return(1); if (v1->xyz[0] != v2->xyz[0]) @@ -70,7 +80,7 @@ register MCVERT *v1, *v2; MESH * -getmesh(mname, flags) /* get mesh data */ +getmesh(mname, flags) /* get new mesh data reference */ char *mname; int flags; { @@ -80,13 +90,10 @@ int flags; flags &= IO_LEGAL; for (ms = mlist; ms != NULL; ms = ms->next) if (!strcmp(mname, ms->name)) { - if ((ms->ldflags & flags) == flags) { - ms->nref++; - return(ms); /* loaded */ - } - break; /* load the rest */ + ms->nref++; /* increase reference count */ + break; } - if (ms == NULL) { + if (ms == NULL) { /* load first time */ ms = (MESH *)calloc(1, sizeof(MESH)); if (ms == NULL) error(SYSTEM, "out of memory in getmesh"); @@ -130,8 +137,12 @@ int flags; ins->msh = NULL; o->os = (char *)ins; } - if (ins->msh == NULL || (ins->msh->ldflags & flags) != flags) + if (ins->msh == NULL) ins->msh = getmesh(o->oargs.sarg[0], flags); + else if ((flags &= ~ins->msh->ldflags)) + readmesh(ins->msh, + getpath(o->oargs.sarg[0], getrlibpath(), R_OK), + flags); return(ins); } @@ -305,7 +316,7 @@ MESHVERT *vp; (vp->v[i] - mp->mcube.cuorg[i]) / mp->mcube.cusize); } - if (vp->fl & MT_N) + if (vp->fl & MT_N) /* assumes normalized! */ cv.norm = encodedir(vp->n); if (vp->fl & MT_UV) for (i = 0; i < 2; i++) { @@ -409,11 +420,12 @@ OBJECT mo; pn[i] = vid[i] >> 8; } /* normalize material index */ - if (mo != OVOID) + if (mo != OVOID) { if ((mo -= mp->mat0) >= mp->nmats) mp->nmats = mo+1; else if (mo < 0) error(INTERNAL, "modifier range error in addmeshtri"); + } /* assign triangle */ if (pn[0] == pn[1] && pn[1] == pn[2]) { /* local case */ pp = &mp->patch[pn[0]]; @@ -541,8 +553,6 @@ register MESH *mp; if (nouvbounds && pp->uv != NULL) return("unreferenced uv coordinates"); } - if (pp->ntris + pp->nj1tris + pp->nj2tris <= 0) - error(WARNING, "no triangles in patch"); if (pp->ntris > 0 && pp->tri == NULL) return("missing patch triangle list"); if (pp->nj1tris > 0 && pp->j1tri == NULL) @@ -610,7 +620,7 @@ FILE *fp; t2cnt += pp->nj2tris; } fprintf(fp, "Mesh statistics:\n"); - fprintf(fp, "\t%d materials\n", ms->nmats); + fprintf(fp, "\t%ld materials\n", ms->nmats); fprintf(fp, "\t%d patches (%.2f MBytes)\n", ms->npatches, (ms->npatches*sizeof(MESHPATCH) + vcnt*3*sizeof(uint32) +