--- ray/src/common/mesh.c 2003/06/30 14:59:11 2.9 +++ ray/src/common/mesh.c 2003/09/18 16:53:52 2.14 @@ -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.14 2003/09/18 16:53:52 greg Exp $"; #endif /* * Mesh support routines @@ -18,7 +18,7 @@ typedef struct { int fl; uint32 xyz[3]; int32 norm; - uint32 uv[2]; + uint16 uv[2]; } MCVERT; #define MPATCHBLKSIZ 128 /* patch allocation block size */ @@ -70,7 +70,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 +80,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 +127,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); } @@ -234,7 +235,7 @@ int what; for (i = 0; i < 2; i++) vp->uv[i] = mp->uvlim[0][i] + (mp->uvlim[1][i] - mp->uvlim[0][i])* - (pp->uv[vid][i] + .5)*(1./4294967296.); + (pp->uv[vid][i] + .5)*(1./65536.); vp->fl |= MT_UV; } return(vp->fl); @@ -313,7 +314,7 @@ MESHVERT *vp; return(-1); if (vp->uv[i] >= mp->uvlim[1][i]) return(-1); - cv.uv[i] = (uint32)(4294967296. * + cv.uv[i] = (uint32)(65536. * (vp->uv[i] - mp->uvlim[0][i]) / (mp->uvlim[1][i] - mp->uvlim[0][i])); } @@ -371,8 +372,8 @@ MESHVERT *vp; } if (cv.fl & MT_UV) { if (pp->uv == NULL) { - pp->uv = (uint32 (*)[2])calloc(256, - 2*sizeof(uint32)); + pp->uv = (uint16 (*)[2])calloc(256, + 2*sizeof(uint16)); if (pp->uv == NULL) goto nomem; } @@ -409,11 +410,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,12 +612,12 @@ 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) + nscnt*sizeof(int32) + - uvscnt*2*sizeof(uint32) + + uvscnt*2*sizeof(uint16) + tcnt*sizeof(struct PTri) + t1cnt*sizeof(struct PJoin1) + t2cnt*sizeof(struct PJoin2))/(1024.*1024.));