--- ray/src/cv/obj2rad.c 2004/04/23 16:20:56 2.23 +++ ray/src/cv/obj2rad.c 2010/09/28 21:28:23 2.27 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: obj2rad.c,v 2.23 2004/04/23 16:20:56 greg Exp $"; +static const char RCSid[] = "$Id: obj2rad.c,v 2.27 2010/09/28 21:28:23 greg Exp $"; #endif /* * Convert a Wavefront .obj file to Radiance format. @@ -35,6 +35,9 @@ int nvns; RREAL (*vtlist)[2]; /* map vertex list */ int nvts; +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 1024 /* vertex allocation chunk size */ @@ -140,6 +143,10 @@ main( /* read in .obj file and convert */ 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", @@ -270,7 +277,7 @@ convert( /* convert a T-mesh */ 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; @@ -494,6 +501,9 @@ cvtndx( /* convert vertex string to index */ 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); } @@ -615,6 +625,7 @@ puttri( /* put out a triangle */ switch (flatness) { case DEGEN: /* zero area */ + ndegen++; return(-1); case RVFLAT: /* reversed normals, but flat */ case ISFLAT: /* smoothing unnecessary */ @@ -635,7 +646,7 @@ puttri( /* put out a triangle */ 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); @@ -748,8 +759,7 @@ newvn( /* create a new vertex normal */ 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); }