--- ray/src/common/readmesh.c 2003/03/14 21:27:46 2.2 +++ ray/src/common/readmesh.c 2003/10/22 02:06:34 2.10 @@ -1,14 +1,18 @@ #ifndef lint -static const char RCSid[] = "$Id: readmesh.c,v 2.2 2003/03/14 21:27:46 greg Exp $"; +static const char RCSid[] = "$Id: readmesh.c,v 2.10 2003/10/22 02:06:34 greg Exp $"; #endif /* * Routines for reading a compiled mesh from a file */ +#include + +#include "platform.h" #include "standard.h" #include "octree.h" #include "object.h" #include "mesh.h" +#include "resolu.h" static char *meshfn; /* input file name */ static FILE *meshfp; /* mesh file pointer */ @@ -73,21 +77,22 @@ gettree() /* get a pre-ordered octree */ register int i; switch (getc(meshfp)) { - case OT_EMPTY: - return(EMPTY); - case OT_FULL: - return(getfullnode()); - case OT_TREE: - if ((ot = octalloc()) == EMPTY) - mesherror(SYSTEM, "out of tree space in readmesh"); - for (i = 0; i < 8; i++) - octkid(ot, i) = gettree(); - return(ot); - case EOF: - mesherror(USER, "truncated mesh octree"); - default: - mesherror(USER, "damaged mesh octree"); + case OT_EMPTY: + return(EMPTY); + case OT_FULL: + return(getfullnode()); + case OT_TREE: + if ((ot = octalloc()) == EMPTY) + mesherror(SYSTEM, "out of tree space in readmesh"); + for (i = 0; i < 8; i++) + octkid(ot, i) = gettree(); + return(ot); + case EOF: + mesherror(USER, "truncated mesh octree"); + default: + mesherror(USER, "damaged mesh octree"); } + return (OCTREE)NULL; /* pro forma return */ } @@ -130,17 +135,17 @@ register MESHPATCH *pp; pp->nverts = mgetint(2); if (pp->nverts <= 0 || pp->nverts > 256) mesherror(USER, "bad number of patch vertices"); - pp->xyz = (uint4 (*)[3])malloc(pp->nverts*3*sizeof(uint4)); + pp->xyz = (uint32 (*)[3])malloc(pp->nverts*3*sizeof(uint32)); if (pp->xyz == NULL) goto nomem; if (flags & MT_N) { - pp->norm = (int4 *)calloc(pp->nverts, sizeof(int4)); + pp->norm = (int32 *)calloc(pp->nverts, sizeof(int32)); if (pp->norm == NULL) goto nomem; } else pp->norm = NULL; if (flags & MT_UV) { - pp->uv = (uint4 (*)[2])calloc(pp->nverts, 2*sizeof(uint4)); + pp->uv = (uint16 (*)[2])calloc(pp->nverts, 2*sizeof(uint16)); if (pp->uv == NULL) goto nomem; } else @@ -157,7 +162,7 @@ register MESHPATCH *pp; if (flags & MT_UV) for (i = 0; i < pp->nverts; i++) for (j = 0; j < 2; j++) - pp->uv[i][j] = mgetint(4); + pp->uv[i][j] = mgetint(2); /* local triangles */ pp->ntris = mgetint(2); if (pp->ntris < 0 || pp->ntris > 512) @@ -176,7 +181,7 @@ register MESHPATCH *pp; pp->tri = NULL; /* local triangle material(s) */ if (mgetint(2) > 1) { - pp->trimat = (int2 *)malloc(pp->ntris*sizeof(int2)); + pp->trimat = (int16 *)malloc(pp->ntris*sizeof(int16)); if (pp->trimat == NULL) goto nomem; for (i = 0; i < pp->ntris; i++) @@ -244,9 +249,7 @@ int flags; sprintf(errmsg, "cannot open mesh file \"%s\"", path); error(SYSTEM, errmsg); } -#ifdef MSDOS - setmode(fileno(meshfp), O_BINARY); -#endif + SET_FILE_BINARY(meshfp); /* read header */ checkheader(meshfp, MESHFMT, flags&IO_INFO ? stdout : (FILE *)NULL); /* read format number */