--- ray/src/common/mesh.c 2003/06/30 14:59:11 2.9 +++ ray/src/common/mesh.c 2004/02/12 18:55:50 2.17 @@ -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.17 2004/02/12 18:55:50 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" @@ -70,7 +73,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 +83,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 +130,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 +309,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 +413,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]]; @@ -610,7 +615,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) +