--- ray/src/cv/obj2rad.c 1994/06/15 12:29:55 2.10 +++ ray/src/cv/obj2rad.c 2010/09/16 03:28:21 2.26 @@ -1,9 +1,6 @@ -/* Copyright (c) 1994 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: obj2rad.c,v 2.26 2010/09/16 03:28:21 greg Exp $"; #endif - /* * Convert a Wavefront .obj file to Radiance format. * @@ -13,40 +10,39 @@ static char SCCSid[] = "$SunId$ LBL"; * I'm not sure they work correctly. (Taken out -- see TEXMAPS defines.) */ -#include "standard.h" +#include +#include +#include +#include "rtmath.h" +#include "rtio.h" +#include "resolu.h" #include "trans.h" +#include "tmesh.h" -#include -#define TCALNAME "tmesh.cal" /* triangle interp. file */ -#define QCALNAME "surf.cal" /* quad interp. file */ #define PATNAME "M-pat" /* mesh pattern name (reused) */ #define TEXNAME "M-nor" /* mesh texture name (reused) */ #define DEFOBJ "unnamed" /* default object name */ #define DEFMAT "white" /* default material name */ -#define ABS(x) ((x)>=0 ? (x) : -(x)) - #define pvect(v) printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2]) FVECT *vlist; /* our vertex list */ int nvs; /* number of vertices in our list */ FVECT *vnlist; /* vertex normal list */ int nvns; -FLOAT (*vtlist)[2]; /* map vertex list */ +RREAL (*vtlist)[2]; /* map vertex list */ int nvts; -typedef struct { - int ax; /* major axis */ - FLOAT tm[2][3]; /* transformation */ -} BARYCCM; +int ndegen = 0; /* count of degenerate faces */ +int n0norm = 0; /* count of zero normals */ typedef int VNDX[3]; /* vertex index (point,map,normal) */ -#define CHUNKSIZ 256 /* vertex allocation chunk size */ +#define CHUNKSIZ 1024 /* vertex allocation chunk size */ -#define MAXARG 64 /* maximum # arguments in a statement */ +#define MAXARG 512 /* maximum # arguments in a statement */ /* qualifiers */ #define Q_MTL 0 @@ -75,8 +71,6 @@ char *defobj = DEFOBJ; /* default (starting) object na int flatten = 0; /* discard surface normal information */ -char *getmtl(), *getonm(); - char mapname[128]; /* current picture file */ char matname[64]; /* current material name */ char group[16][32]; /* current group names */ @@ -85,10 +79,28 @@ char *inpfile; /* input file name */ int lineno; /* current line number */ int faceno; /* current face number */ +static void getnames(FILE *fp); +static void convert(FILE *fp); +static int getstmt(char *av[MAXARG], FILE *fp); +static char * getmtl(void); +static char * getonm(void); +static int matchrule(RULEHD *rp); +static int cvtndx(VNDX vi, char *vs); +static int nonplanar(int ac, char **av); +static int putface(int ac, char **av); +static int puttri(char *v1, char *v2, char *v3); +static void freeverts(void); +static int newv(double x, double y, double z); +static int newvn(double x, double y, double z); +static int newvt(double x, double y); +static void syntax(char *er); -main(argc, argv) /* read in .obj file and convert */ -int argc; -char *argv[]; + +int +main( /* read in .obj file and convert */ + int argc, + char *argv[] +) { int donames = 0; int i; @@ -110,7 +122,7 @@ char *argv[]; default: goto userr; } - if (i > argc | i < argc-1) + if ((i > argc) | (i < argc-1)) goto userr; if (i == argc) inpfile = ""; @@ -131,6 +143,10 @@ char *argv[]; printargs(argc, argv, stdout); convert(stdin); } + if (ndegen) + printf("# %d degenerate faces\n", ndegen); + if (n0norm) + printf("# %d invalid (zero) normals\n", n0norm); exit(0); userr: fprintf(stderr, "Usage: %s [-o obj][-m mapping][-n][-f] [file.obj]\n", @@ -139,15 +155,17 @@ userr: } -getnames(fp) /* get valid qualifier names */ -FILE *fp; +void +getnames( /* get valid qualifier names */ + FILE *fp +) { char *argv[MAXARG]; int argc; ID tmpid; register int i; - while (argc = getstmt(argv, fp)) + while ( (argc = getstmt(argv, fp)) ) switch (argv[0][0]) { case 'f': /* face */ if (!argv[0][1]) @@ -188,8 +206,10 @@ FILE *fp; } -convert(fp) /* convert a T-mesh */ -FILE *fp; +void +convert( /* convert a T-mesh */ + FILE *fp +) { char *argv[MAXARG]; int argc; @@ -198,7 +218,7 @@ FILE *fp; nstats = nunknown = 0; /* scan until EOF */ - while (argc = getstmt(argv, fp)) { + while ( (argc = getstmt(argv, fp)) ) { switch (argv[0][0]) { case 'v': /* vertex */ switch (argv[0][1]) { @@ -240,11 +260,6 @@ FILE *fp; if (!puttri(argv[1], argv[2], argv[3])) syntax("Bad triangle"); break; - case 4: - if (!putquad(argv[1], argv[2], - argv[3], argv[4])) - syntax("Bad quad"); - break; default: if (!putface(argc-1, argv+1)) syntax("Bad face"); @@ -262,7 +277,7 @@ FILE *fp; if (!strcmp(argv[1], "off")) mapname[0] = '\0'; else - sprintf(mapname, "%s.pic", argv[1]); + sprintf(mapname, "%s.hdr", argv[1]); } else goto unknown; break; @@ -297,12 +312,12 @@ FILE *fp; int -getstmt(av, fp) /* read the next statement from fp */ -register char *av[MAXARG]; -FILE *fp; +getstmt( /* read the next statement from fp */ + register char *av[MAXARG], + FILE *fp +) { - extern char *fgetline(); - static char sbuf[MAXARG*10]; + static char sbuf[MAXARG*16]; register char *cp; register int i; @@ -316,8 +331,14 @@ FILE *fp; lineno++; *cp++ = '\0'; } - if (!*cp || i >= MAXARG-1) + if (!*cp) break; + if (i >= MAXARG-1) { + fprintf(stderr, + "warning: line %d: too many arguments (limit %d)\n", + lineno+1, MAXARG-1); + break; + } av[i++] = cp; while (*++cp && !isspace(*cp)) ; @@ -331,7 +352,7 @@ FILE *fp; char * -getmtl() /* figure material for this face */ +getmtl(void) /* figure material for this face */ { register RULEHD *rp = ourmapping; @@ -357,7 +378,7 @@ getmtl() /* figure material for this face */ char * -getonm() /* invent a good name for object */ +getonm(void) /* invent a good name for object */ { static char name[64]; register char *cp1, *cp2; @@ -372,7 +393,7 @@ getonm() /* invent a good name for object */ cp2 = group[i]; if (cp1 > name) *cp1++ = '.'; - while (*cp1 = *cp2++) + while ( (*cp1 = *cp2++) ) if (++cp1 >= name+sizeof(name)-2) { *cp1 = '\0'; return(name); @@ -382,8 +403,10 @@ getonm() /* invent a good name for object */ } -matchrule(rp) /* check for a match on this rule */ -register RULEHD *rp; +int +matchrule( /* check for a match on this rule */ + register RULEHD *rp +) { ID tmpid; int gotmatch; @@ -433,9 +456,11 @@ register RULEHD *rp; } -cvtndx(vi, vs) /* convert vertex string to index */ -register VNDX vi; -register char *vs; +int +cvtndx( /* convert vertex string to index */ + register VNDX vi, + register char *vs +) { /* get point */ vi[0] = atoi(vs); @@ -476,23 +501,28 @@ register char *vs; return(0); } else vi[2] = -1; + /* zero normal is not normal */ + if (vi[2] >= 0 && DOT(vnlist[vi[2]],vnlist[vi[2]]) <= FTINY) + vi[2] = -1; return(1); } -nonplanar(ac, av) /* are vertices non-planar? */ -register int ac; -register char **av; +int +nonplanar( /* are vertices non-planar? */ + register int ac, + register char **av +) { VNDX vi; - FLOAT *p0, *p1; + RREAL *p0, *p1; FVECT v1, v2, nsum, newn; double d; register int i; if (!cvtndx(vi, av[0])) return(0); - if (vi[2] >= 0) + if (!flatten && vi[2] >= 0) return(1); /* has interpolated normals */ if (ac < 4) return(0); /* it's a triangle! */ @@ -531,30 +561,30 @@ register char **av; } -putface(ac, av) /* put out an N-sided polygon */ -int ac; -register char **av; +int +putface( /* put out an N-sided polygon */ + int ac, + register char **av +) { VNDX vi; char *cp; register int i; - if (nonplanar(ac, av)) { /* break into quads and triangles */ - while (ac > 3) { - if (!putquad(av[0], av[1], av[2], av[3])) + if (nonplanar(ac, av)) { /* break into triangles */ + while (ac > 2) { + if (!puttri(av[0], av[1], av[2])) return(0); - ac -= 2; /* remove two vertices & rotate */ + ac--; /* remove vertex & rotate */ cp = av[0]; for (i = 0; i < ac-1; i++) - av[i] = av[i+3]; + av[i] = av[i+2]; av[i] = cp; } - if (ac == 3 && !puttri(av[0], av[1], av[2])) - return(0); return(1); } if ((cp = getmtl()) == NULL) - return(-1); + return(0); printf("\n%s polygon %s.%d\n", cp, getonm(), faceno); printf("0\n0\n%d\n", 3*ac); for (i = 0; i < ac; i++) { @@ -566,21 +596,48 @@ register char **av; } -puttri(v1, v2, v3) /* put out a triangle */ -char *v1, *v2, *v3; +int +puttri( /* put out a triangle */ + char *v1, + char *v2, + char *v3 +) { char *mod; VNDX v1i, v2i, v3i; BARYCCM bvecs; - int texOK, patOK; + RREAL bcoor[3][3]; + int texOK = 0, patOK; + int flatness; + register int i; if ((mod = getmtl()) == NULL) - return(-1); + return(0); if (!cvtndx(v1i, v1) || !cvtndx(v2i, v2) || !cvtndx(v3i, v3)) return(0); /* compute barycentric coordinates */ - texOK = !flatten && (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0); + if (v1i[2]>=0 && v2i[2]>=0 && v3i[2]>=0) + flatness = flat_tri(vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]], + vnlist[v1i[2]], vnlist[v2i[2]], vnlist[v3i[2]]); + else + flatness = ISFLAT; + + switch (flatness) { + case DEGEN: /* zero area */ + ndegen++; + return(-1); + case RVFLAT: /* reversed normals, but flat */ + case ISFLAT: /* smoothing unnecessary */ + texOK = 0; + break; + case RVBENT: /* reversed normals with smoothing */ + case ISBENT: /* proper smoothing */ + texOK = 1; + break; + } + if (flatten) + texOK = 0; #ifdef TEXMAPS patOK = mapname[0] && (v1i[1]>=0 && v2i[1]>=0 && v3i[1]>=0); #else @@ -589,23 +646,19 @@ char *v1, *v2, *v3; if (texOK | patOK) if (comp_baryc(&bvecs, vlist[v1i[0]], vlist[v2i[0]], vlist[v3i[0]]) < 0) - return(-1); + texOK = patOK = 0; /* put out texture (if any) */ if (texOK) { printf("\n%s texfunc %s\n", mod, TEXNAME); mod = TEXNAME; printf("4 dx dy dz %s\n", TCALNAME); - printf("0\n16 "); - put_baryc(&bvecs); - printf("\t%14.12g %14.12g %14.12g\n", - vnlist[v1i[2]][0], vnlist[v2i[2]][0], - vnlist[v3i[2]][0]); - printf("\t%14.12g %14.12g %14.12g\n", - vnlist[v1i[2]][1], vnlist[v2i[2]][1], - vnlist[v3i[2]][1]); - printf("\t%14.12g %14.12g %14.12g\n", - vnlist[v1i[2]][2], vnlist[v2i[2]][2], - vnlist[v3i[2]][2]); + printf("0\n"); + for (i = 0; i < 3; i++) { + bcoor[i][0] = vnlist[v1i[2]][i]; + bcoor[i][1] = vnlist[v2i[2]][i]; + bcoor[i][2] = vnlist[v3i[2]][i]; + } + put_baryc(&bvecs, bcoor, 3); } #ifdef TEXMAPS /* put out pattern (if any) */ @@ -613,273 +666,61 @@ char *v1, *v2, *v3; printf("\n%s colorpict %s\n", mod, PATNAME); mod = PATNAME; printf("7 noneg noneg noneg %s %s u v\n", mapname, TCALNAME); - printf("0\n13 "); - put_baryc(&bvecs); - printf("\t%f %f %f\n", vtlist[v1i[1]][0], - vtlist[v2i[1]][0], vtlist[v3i[1]][0]); - printf("\t%f %f %f\n", vtlist[v1i[1]][1], - vtlist[v2i[1]][1], vtlist[v3i[1]][1]); + printf("0\n"); + for (i = 0; i < 2; i++) { + bcoor[i][0] = vtlist[v1i[1]][i]; + bcoor[i][1] = vtlist[v2i[1]][i]; + bcoor[i][2] = vtlist[v3i[1]][i]; + } + put_baryc(&bvecs, bcoor, 2); } #endif - /* put out triangle */ + /* put out (reversed) triangle */ printf("\n%s polygon %s.%d\n", mod, getonm(), faceno); printf("0\n0\n9\n"); - pvect(vlist[v1i[0]]); - pvect(vlist[v2i[0]]); - pvect(vlist[v3i[0]]); - - return(1); -} - - -int -comp_baryc(bcm, v1, v2, v3) /* compute barycentric vectors */ -register BARYCCM *bcm; -FLOAT *v1, *v2, *v3; -{ - FLOAT *vt; - FVECT va, vab, vcb; - double d; - int ax0, ax1; - register int i, j; - /* compute major axis */ - for (i = 0; i < 3; i++) { - vab[i] = v1[i] - v2[i]; - vcb[i] = v3[i] - v2[i]; + if (flatness == RVFLAT || flatness == RVBENT) { + pvect(vlist[v3i[0]]); + pvect(vlist[v2i[0]]); + pvect(vlist[v1i[0]]); + } else { + pvect(vlist[v1i[0]]); + pvect(vlist[v2i[0]]); + pvect(vlist[v3i[0]]); } - fcross(va, vab, vcb); - bcm->ax = ABS(va[0]) > ABS(va[1]) ? 0 : 1; - bcm->ax = ABS(va[bcm->ax]) > ABS(va[2]) ? bcm->ax : 2; - ax0 = (bcm->ax + 1) % 3; - ax1 = (bcm->ax + 2) % 3; - for (j = 0; j < 2; j++) { - vab[0] = v1[ax0] - v2[ax0]; - vcb[0] = v3[ax0] - v2[ax0]; - vab[1] = v1[ax1] - v2[ax1]; - vcb[1] = v3[ax1] - v2[ax1]; - d = vcb[0]*vcb[0] + vcb[1]*vcb[1]; - if (d <= FTINY) - return(-1); - d = (vcb[0]*vab[0]+vcb[1]*vab[1])/d; - va[0] = vab[0] - vcb[0]*d; - va[1] = vab[1] - vcb[1]*d; - d = va[0]*va[0] + va[1]*va[1]; - if (d <= FTINY) - return(-1); - bcm->tm[j][0] = va[0] /= d; - bcm->tm[j][1] = va[1] /= d; - bcm->tm[j][2] = -(v2[ax0]*va[0]+v2[ax1]*va[1]); - /* rotate vertices */ - vt = v1; - v1 = v2; - v2 = v3; - v3 = vt; - } - return(0); -} - - -put_baryc(bcm) /* put barycentric coord. vectors */ -register BARYCCM *bcm; -{ - printf("\t%d\n", bcm->ax); - printf("%14.8f %14.8f %14.8f\n", - bcm->tm[0][0], bcm->tm[0][1], bcm->tm[0][2]); - printf("%14.8f %14.8f %14.8f\n", - bcm->tm[1][0], bcm->tm[1][1], bcm->tm[1][2]); -} - - -putquad(p0, p1, p3, p2) /* put out a quadrilateral */ -char *p0, *p1, *p3, *p2; /* names correspond to binary pos. */ -{ - VNDX p0i, p1i, p2i, p3i; - FVECT norm[4]; - char *mod, *name; - int axis; - FVECT v1, v2, vc1, vc2; - int ok1, ok2; - -#ifdef TEXMAPS - /* also should output texture index coordinates, - * which will require new .cal file - */ -#endif - if ((mod = getmtl()) == NULL) - return(-1); - name = getonm(); - /* get actual indices */ - if (!cvtndx(p0i,p0) || !cvtndx(p1i,p1) || - !cvtndx(p2i,p2) || !cvtndx(p3i,p3)) - return(0); - /* compute exact normals */ - fvsum(v1, vlist[p1i[0]], vlist[p0i[0]], -1.0); - fvsum(v2, vlist[p2i[0]], vlist[p0i[0]], -1.0); - fcross(vc1, v1, v2); - ok1 = normalize(vc1) != 0.0; - fvsum(v1, vlist[p2i[0]], vlist[p3i[0]], -1.0); - fvsum(v2, vlist[p1i[0]], vlist[p3i[0]], -1.0); - fcross(vc2, v1, v2); - ok2 = normalize(vc2) != 0.0; - if (!(ok1 | ok2)) - return(-1); - /* compute normal interpolation */ - axis = norminterp(norm, p0i, p1i, p2i, p3i); - - /* put out quadrilateral? */ - if (ok1 & ok2 && fabs(fdot(vc1,vc2)) >= 1.0-FTINY) { - printf("\n%s ", mod); - if (axis != -1) { - printf("texfunc %s\n", TEXNAME); - printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); - printf("0\n13\t%d\n", axis); - pvect(norm[0]); - pvect(norm[1]); - pvect(norm[2]); - fvsum(v1, norm[3], vc1, -0.5); - fvsum(v1, v1, vc2, -0.5); - pvect(v1); - printf("\n%s ", TEXNAME); - } - printf("polygon %s.%d\n", name, faceno); - printf("0\n0\n12\n"); - pvect(vlist[p0i[0]]); - pvect(vlist[p1i[0]]); - pvect(vlist[p3i[0]]); - pvect(vlist[p2i[0]]); - return(1); - } - /* put out triangles? */ - if (ok1) { - printf("\n%s ", mod); - if (axis != -1) { - printf("texfunc %s\n", TEXNAME); - printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); - printf("0\n13\t%d\n", axis); - pvect(norm[0]); - pvect(norm[1]); - pvect(norm[2]); - fvsum(v1, norm[3], vc1, -1.0); - pvect(v1); - printf("\n%s ", TEXNAME); - } - printf("polygon %s.%da\n", name, faceno); - printf("0\n0\n9\n"); - pvect(vlist[p0i[0]]); - pvect(vlist[p1i[0]]); - pvect(vlist[p2i[0]]); - } - if (ok2) { - printf("\n%s ", mod); - if (axis != -1) { - printf("texfunc %s\n", TEXNAME); - printf("4 surf_dx surf_dy surf_dz %s\n", QCALNAME); - printf("0\n13\t%d\n", axis); - pvect(norm[0]); - pvect(norm[1]); - pvect(norm[2]); - fvsum(v2, norm[3], vc2, -1.0); - pvect(v2); - printf("\n%s ", TEXNAME); - } - printf("polygon %s.%db\n", name, faceno); - printf("0\n0\n9\n"); - pvect(vlist[p2i[0]]); - pvect(vlist[p1i[0]]); - pvect(vlist[p3i[0]]); - } return(1); } -int -norminterp(resmat, p0i, p1i, p2i, p3i) /* compute normal interpolation */ -register FVECT resmat[4]; -register VNDX p0i, p1i, p2i, p3i; +void +freeverts(void) /* free all vertices */ { -#define u ((ax+1)%3) -#define v ((ax+2)%3) - - register int ax; - MAT4 eqnmat; - FVECT v1; - register int i, j; - -#ifdef TEXMAPS - /* also check for texture indices */ -#endif - if (flatten || !(p0i[2]>=0 && p1i[2]>=0 && p2i[2]>=0 && p3i[2]>=0)) - return(-1); - /* find dominant axis */ - VCOPY(v1, vnlist[p0i[2]]); - fvsum(v1, v1, vnlist[p1i[2]], 1.0); - fvsum(v1, v1, vnlist[p2i[2]], 1.0); - fvsum(v1, v1, vnlist[p3i[2]], 1.0); - ax = ABS(v1[0]) > ABS(v1[1]) ? 0 : 1; - ax = ABS(v1[ax]) > ABS(v1[2]) ? ax : 2; - /* assign equation matrix */ - eqnmat[0][0] = vlist[p0i[0]][u]*vlist[p0i[0]][v]; - eqnmat[0][1] = vlist[p0i[0]][u]; - eqnmat[0][2] = vlist[p0i[0]][v]; - eqnmat[0][3] = 1.0; - eqnmat[1][0] = vlist[p1i[0]][u]*vlist[p1i[0]][v]; - eqnmat[1][1] = vlist[p1i[0]][u]; - eqnmat[1][2] = vlist[p1i[0]][v]; - eqnmat[1][3] = 1.0; - eqnmat[2][0] = vlist[p2i[0]][u]*vlist[p2i[0]][v]; - eqnmat[2][1] = vlist[p2i[0]][u]; - eqnmat[2][2] = vlist[p2i[0]][v]; - eqnmat[2][3] = 1.0; - eqnmat[3][0] = vlist[p3i[0]][u]*vlist[p3i[0]][v]; - eqnmat[3][1] = vlist[p3i[0]][u]; - eqnmat[3][2] = vlist[p3i[0]][v]; - eqnmat[3][3] = 1.0; - /* invert matrix (solve system) */ - if (!invmat4(eqnmat, eqnmat)) - return(-1); /* no solution */ - /* compute result matrix */ - for (j = 0; j < 4; j++) - for (i = 0; i < 3; i++) - resmat[j][i] = eqnmat[j][0]*vnlist[p0i[2]][i] + - eqnmat[j][1]*vnlist[p1i[2]][i] + - eqnmat[j][2]*vnlist[p2i[2]][i] + - eqnmat[j][3]*vnlist[p3i[2]][i]; -#ifdef TEXMAPS - /* compute result matrix for texture indices */ -#endif - return(ax); - -#undef u -#undef v -} - - -freeverts() /* free all vertices */ -{ if (nvs) { - free((char *)vlist); + free((void *)vlist); nvs = 0; } if (nvts) { - free((char *)vtlist); + free((void *)vtlist); nvts = 0; } if (nvns) { - free((char *)vnlist); + free((void *)vnlist); nvns = 0; } } int -newv(x, y, z) /* create a new vertex */ -double x, y, z; +newv( /* create a new vertex */ + double x, + double y, + double z +) { if (!(nvs%CHUNKSIZ)) { /* allocate next block */ if (nvs == 0) vlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT)); else - vlist = (FVECT *)realloc((char *)vlist, + vlist = (FVECT *)realloc((void *)vlist, (nvs+CHUNKSIZ)*sizeof(FVECT)); if (vlist == NULL) { fprintf(stderr, @@ -896,14 +737,17 @@ double x, y, z; int -newvn(x, y, z) /* create a new vertex normal */ -double x, y, z; +newvn( /* create a new vertex normal */ + double x, + double y, + double z +) { if (!(nvns%CHUNKSIZ)) { /* allocate next block */ if (nvns == 0) vnlist = (FVECT *)malloc(CHUNKSIZ*sizeof(FVECT)); else - vnlist = (FVECT *)realloc((char *)vnlist, + vnlist = (FVECT *)realloc((void *)vnlist, (nvns+CHUNKSIZ)*sizeof(FVECT)); if (vnlist == NULL) { fprintf(stderr, @@ -915,22 +759,23 @@ double x, y, z; vnlist[nvns][0] = x; vnlist[nvns][1] = y; vnlist[nvns][2] = z; - if (normalize(vnlist[nvns]) == 0.0) - return(0); + n0norm += (normalize(vnlist[nvns]) == 0.0); return(++nvns); } int -newvt(x, y) /* create a new texture map vertex */ -double x, y; +newvt( /* create a new texture map vertex */ + double x, + double y +) { if (!(nvts%CHUNKSIZ)) { /* allocate next block */ if (nvts == 0) - vtlist = (FLOAT (*)[2])malloc(CHUNKSIZ*2*sizeof(FLOAT)); + vtlist = (RREAL (*)[2])malloc(CHUNKSIZ*2*sizeof(RREAL)); else - vtlist = (FLOAT (*)[2])realloc((char *)vtlist, - (nvts+CHUNKSIZ)*2*sizeof(FLOAT)); + vtlist = (RREAL (*)[2])realloc((void *)vtlist, + (nvts+CHUNKSIZ)*2*sizeof(RREAL)); if (vtlist == NULL) { fprintf(stderr, "Out of memory while allocating texture vertex %d\n", @@ -945,8 +790,10 @@ double x, y; } -syntax(er) /* report syntax error and exit */ -char *er; +void +syntax( /* report syntax error and exit */ + char *er +) { fprintf(stderr, "%s: Wavefront syntax error near line %d: %s\n", inpfile, lineno, er);