| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include "copyright.h" |
| 9 |
+ |
#include "platform.h" |
| 10 |
|
#include "standard.h" |
| 11 |
+ |
#include "resolu.h" |
| 12 |
|
#include "cvmesh.h" |
| 13 |
|
#include "otypes.h" |
| 14 |
|
|
| 15 |
< |
extern int o_face(); |
| 15 |
> |
extern int o_face(); /* XXX should go to a header file */ |
| 16 |
|
|
| 17 |
|
int o_default() { return(O_MISS); } |
| 18 |
|
|
| 28 |
|
|
| 29 |
|
double mincusize; /* minimum cube size from resolu */ |
| 30 |
|
|
| 31 |
+ |
static void addface(CUBE *cu, OBJECT obj); |
| 32 |
+ |
static void add2full(CUBE *cu, OBJECT obj); |
| 33 |
|
|
| 34 |
< |
main(argc, argv) /* compile a .OBJ file into a mesh */ |
| 35 |
< |
int argc; |
| 36 |
< |
char *argv[]; |
| 34 |
> |
|
| 35 |
> |
int |
| 36 |
> |
main( /* compile a .OBJ file into a mesh */ |
| 37 |
> |
int argc, |
| 38 |
> |
char *argv[] |
| 39 |
> |
) |
| 40 |
|
{ |
| 41 |
< |
int i; |
| 41 |
> |
int nmatf = 0; |
| 42 |
> |
char *matinp[32]; |
| 43 |
> |
int i, j; |
| 44 |
|
|
| 45 |
|
progname = argv[0]; |
| 46 |
|
ofun[OBJ_FACE].funp = o_face; |
| 53 |
|
case 'r': /* resolution limit */ |
| 54 |
|
resolu = atoi(argv[++i]); |
| 55 |
|
break; |
| 56 |
+ |
case 'a': /* material file */ |
| 57 |
+ |
matinp[nmatf++] = argv[++i]; |
| 58 |
+ |
break; |
| 59 |
|
case 'w': /* supress warnings */ |
| 60 |
|
nowarn = 1; |
| 61 |
|
break; |
| 64 |
|
error(USER, errmsg); |
| 65 |
|
break; |
| 66 |
|
} |
| 67 |
+ |
|
| 68 |
+ |
if (i < argc-2) |
| 69 |
+ |
error(USER, "too many file arguments"); |
| 70 |
|
/* initialize mesh */ |
| 71 |
|
cvinit(i==argc-2 ? argv[i+1] : "<stdout>"); |
| 72 |
< |
|
| 73 |
< |
if (i == argc) /* read .OBJ file into triangles */ |
| 72 |
> |
/* load material input */ |
| 73 |
> |
for (j = 0; j < nmatf; j++) |
| 74 |
> |
readobj(matinp[j]); |
| 75 |
> |
/* read .OBJ file into triangles */ |
| 76 |
> |
if (i == argc) |
| 77 |
|
wfreadobj(NULL); |
| 78 |
|
else |
| 79 |
|
wfreadobj(argv[i]); |
| 83 |
|
if (i == argc-2) /* open output file */ |
| 84 |
|
if (freopen(argv[i+1], "w", stdout) == NULL) |
| 85 |
|
error(SYSTEM, "cannot open output file"); |
| 86 |
< |
#ifdef MSDOS |
| 69 |
< |
setmode(fileno(stdout), O_BINARY); |
| 70 |
< |
#endif |
| 86 |
> |
SET_FILE_BINARY(stdout); |
| 87 |
|
newheader("RADIANCE", stdout); /* new binary file header */ |
| 88 |
|
printargs(i<argc ? i+1 : argc, argv, stdout); |
| 89 |
|
fputformat(MESHFMT, stdout); |
| 92 |
|
mincusize = ourmesh->mcube.cusize / resolu - FTINY; |
| 93 |
|
|
| 94 |
|
for (i = 0; i < nobjects; i++) /* add triangles to octree */ |
| 95 |
< |
addface(&ourmesh->mcube, i); |
| 95 |
> |
if (objptr(i)->otype == OBJ_FACE) |
| 96 |
> |
addface(&ourmesh->mcube, i); |
| 97 |
|
|
| 98 |
|
/* optimize octree */ |
| 99 |
|
ourmesh->mcube.cutree = combine(ourmesh->mcube.cutree); |
| 105 |
|
|
| 106 |
|
writemesh(ourmesh, stdout); /* write mesh to output */ |
| 107 |
|
|
| 108 |
< |
printmeshstats(ourmesh, stderr); |
| 108 |
> |
/* printmeshstats(ourmesh, stderr); */ |
| 109 |
|
|
| 110 |
|
quit(0); |
| 111 |
+ |
return 0; /* pro forma return */ |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
void |
| 116 |
< |
quit(code) /* exit program */ |
| 117 |
< |
int code; |
| 116 |
> |
quit( /* exit program */ |
| 117 |
> |
int code |
| 118 |
> |
) |
| 119 |
|
{ |
| 120 |
|
exit(code); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
void |
| 125 |
< |
cputs() /* interactive error */ |
| 125 |
> |
cputs(void) /* interactive error */ |
| 126 |
|
{ |
| 127 |
|
/* referenced, but not used */ |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
void |
| 132 |
< |
wputs(s) /* warning message */ |
| 133 |
< |
char *s; |
| 132 |
> |
wputs( /* warning message */ |
| 133 |
> |
char *s |
| 134 |
> |
) |
| 135 |
|
{ |
| 136 |
|
if (!nowarn) |
| 137 |
|
eputs(s); |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
void |
| 142 |
< |
eputs(s) /* put string to stderr */ |
| 143 |
< |
register char *s; |
| 142 |
> |
eputs( /* put string to stderr */ |
| 143 |
> |
register char *s |
| 144 |
> |
) |
| 145 |
|
{ |
| 146 |
|
static int inln = 0; |
| 147 |
|
|
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
< |
addface(cu, obj) /* add a face to a cube */ |
| 159 |
< |
register CUBE *cu; |
| 160 |
< |
OBJECT obj; |
| 158 |
> |
static void |
| 159 |
> |
addface( /* add a face to a cube */ |
| 160 |
> |
register CUBE *cu, |
| 161 |
> |
OBJECT obj |
| 162 |
> |
) |
| 163 |
|
{ |
| 164 |
|
|
| 165 |
|
if (o_face(objptr(obj), cu) == O_MISS) |
| 192 |
|
} |
| 193 |
|
|
| 194 |
|
|
| 195 |
< |
add2full(cu, obj) /* add object to full node */ |
| 196 |
< |
register CUBE *cu; |
| 197 |
< |
OBJECT obj; |
| 195 |
> |
static void |
| 196 |
> |
add2full( /* add object to full node */ |
| 197 |
> |
register CUBE *cu, |
| 198 |
> |
OBJECT obj |
| 199 |
> |
) |
| 200 |
|
{ |
| 201 |
|
OCTREE ot; |
| 202 |
|
OBJECT oset[MAXSET+1]; |