--- ray/src/ot/obj2mesh.c 2003/03/12 04:59:04 2.2 +++ ray/src/ot/obj2mesh.c 2004/04/23 00:56:27 2.11 @@ -1,16 +1,18 @@ #ifndef lint -static const char RCSid[] = "$Id: obj2mesh.c,v 2.2 2003/03/12 04:59:04 greg Exp $"; +static const char RCSid[] = "$Id: obj2mesh.c,v 2.11 2004/04/23 00:56:27 greg Exp $"; #endif /* * Main program to compile a Wavefront .OBJ file into a Radiance mesh */ #include "copyright.h" +#include "platform.h" #include "standard.h" +#include "resolu.h" #include "cvmesh.h" #include "otypes.h" -extern int o_face(); +extern int o_face(); /* XXX should go to a header file */ int o_default() { return(O_MISS); } @@ -26,12 +28,22 @@ int resolu = 16384; /* octree resolution limit */ double mincusize; /* minimum cube size from resolu */ +static void addface(CUBE *cu, OBJECT obj); +static void add2full(CUBE *cu, OBJECT obj); -main(argc, argv) /* compile a .OBJ file into a mesh */ -int argc; -char *argv[]; + +int +main( /* compile a .OBJ file into a mesh */ + int argc, + char *argv[] +) { - int i; + int nmatf = 0; + char pathnames[12800]; + char *pns = pathnames; + char *matinp[128]; + char *cp; + int i, j; progname = argv[0]; ofun[OBJ_FACE].funp = o_face; @@ -44,6 +56,21 @@ char *argv[]; case 'r': /* resolution limit */ resolu = atoi(argv[++i]); break; + case 'a': /* material file */ + matinp[nmatf++] = argv[++i]; + break; + case 'l': /* library material */ + cp = getpath(argv[++i], getrlibpath(), R_OK); + if (cp == NULL) { + sprintf(errmsg, + "cannot find library material: '%s'", + argv[i]); + error(USER, errmsg); + } + matinp[nmatf++] = strcpy(pns, cp); + while (*pns++) + ; + break; case 'w': /* supress warnings */ nowarn = 1; break; @@ -52,10 +79,16 @@ char *argv[]; error(USER, errmsg); break; } + + if (i < argc-2) + error(USER, "too many file arguments"); /* initialize mesh */ cvinit(i==argc-2 ? argv[i+1] : ""); - - if (i == argc) /* read .OBJ file into triangles */ + /* load material input */ + for (j = 0; j < nmatf; j++) + readobj(matinp[j]); + /* read .OBJ file into triangles */ + if (i == argc) wfreadobj(NULL); else wfreadobj(argv[i]); @@ -65,9 +98,7 @@ char *argv[]; if (i == argc-2) /* open output file */ if (freopen(argv[i+1], "w", stdout) == NULL) error(SYSTEM, "cannot open output file"); -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); -#endif + SET_FILE_BINARY(stdout); newheader("RADIANCE", stdout); /* new binary file header */ printargs(imcube.cusize / resolu - FTINY; for (i = 0; i < nobjects; i++) /* add triangles to octree */ - addface(&ourmesh->mcube, i); + if (objptr(i)->otype == OBJ_FACE) + addface(&ourmesh->mcube, i); /* optimize octree */ ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree); @@ -88,30 +120,33 @@ char *argv[]; writemesh(ourmesh, stdout); /* write mesh to output */ -printmeshstats(ourmesh, stderr); + /* printmeshstats(ourmesh, stderr); */ quit(0); + return 0; /* pro forma return */ } void -quit(code) /* exit program */ -int code; +quit( /* exit program */ + int code +) { exit(code); } void -cputs() /* interactive error */ +cputs(void) /* interactive error */ { /* referenced, but not used */ } void -wputs(s) /* warning message */ -char *s; +wputs( /* warning message */ + char *s +) { if (!nowarn) eputs(s); @@ -119,8 +154,9 @@ char *s; void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + register char *s +) { static int inln = 0; @@ -134,9 +170,11 @@ register char *s; } -addface(cu, obj) /* add a face to a cube */ -register CUBE *cu; -OBJECT obj; +static void +addface( /* add a face to a cube */ + register CUBE *cu, + OBJECT obj +) { if (o_face(objptr(obj), cu) == O_MISS) @@ -169,9 +207,11 @@ OBJECT obj; } -add2full(cu, obj) /* add object to full node */ -register CUBE *cu; -OBJECT obj; +static void +add2full( /* add object to full node */ + register CUBE *cu, + OBJECT obj +) { OCTREE ot; OBJECT oset[MAXSET+1]; @@ -181,7 +221,8 @@ OBJECT obj; objset(oset, cu->cutree); cukid.cusize = cu->cusize * 0.5; - if (oset[0] < objlim || cukid.cusize < mincusize) { + if (oset[0] < objlim || cukid.cusize < + (oset[0] < MAXSET ? mincusize : mincusize/256.0)) { /* add to set */ if (oset[0] >= MAXSET) { sprintf(errmsg, "set overflow in addobject (%s)",