--- ray/src/ot/obj2mesh.c 2003/07/14 05:00:45 2.7 +++ ray/src/ot/obj2mesh.c 2023/02/06 22:40:21 2.17 @@ -1,17 +1,19 @@ #ifndef lint -static const char RCSid[] = "$Id: obj2mesh.c,v 2.7 2003/07/14 05:00:45 greg Exp $"; +static const char RCSid[] = "$Id: obj2mesh.c,v 2.17 2023/02/06 22:40:21 greg Exp $"; #endif /* * Main program to compile a Wavefront .OBJ file into a Radiance mesh */ #include "copyright.h" +#include "paths.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); } @@ -21,19 +23,24 @@ char *progname; /* argv[0] */ int nowarn = 0; /* supress warnings? */ -int objlim = 15; /* # of objects before split */ +int objlim = 9; /* # of objects before split */ 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 nmatf = 0; - char *matinp[32]; + int verbose = 0; + char *cp; int i, j; progname = argv[0]; @@ -48,11 +55,24 @@ char *argv[]; resolu = atoi(argv[++i]); break; case 'a': /* material file */ - matinp[nmatf++] = argv[++i]; + readobj(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(SYSTEM, errmsg); + } + readobj(cp); + break; case 'w': /* supress warnings */ nowarn = 1; break; + case 'v': /* print mesh stats */ + verbose = 1; + break; default: sprintf(errmsg, "unknown option: '%s'", argv[i]); error(USER, errmsg); @@ -63,9 +83,6 @@ char *argv[]; error(USER, "too many file arguments"); /* initialize mesh */ cvinit(i==argc-2 ? argv[i+1] : ""); - /* load material input */ - for (j = 0; j < nmatf; j++) - readobj(matinp[j]); /* read .OBJ file into triangles */ if (i == argc) wfreadobj(NULL); @@ -99,30 +116,34 @@ char *argv[]; writemesh(ourmesh, stdout); /* write mesh to output */ - /* printmeshstats(ourmesh, stderr); */ + if (verbose) + 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 */ + const char *s +) { if (!nowarn) eputs(s); @@ -130,8 +151,9 @@ char *s; void -eputs(s) /* put string to stderr */ -register char *s; +eputs( /* put string to stderr */ + const char *s +) { static int inln = 0; @@ -145,9 +167,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 */ + CUBE *cu, + OBJECT obj +) { if (o_face(objptr(obj), cu) == O_MISS) @@ -180,19 +204,22 @@ OBJECT obj; } -add2full(cu, obj) /* add object to full node */ -register CUBE *cu; -OBJECT obj; +static void +add2full( /* add object to full node */ + CUBE *cu, + OBJECT obj +) { OCTREE ot; OBJECT oset[MAXSET+1]; CUBE cukid; - register int i, j; + int i, j; 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)",