| 10 |
|
|
| 11 |
|
#include "mkillum.h" |
| 12 |
|
|
| 13 |
+ |
#include <signal.h> |
| 14 |
+ |
|
| 15 |
|
#include <ctype.h> |
| 16 |
|
|
| 17 |
|
/* default parameters */ |
| 39 |
|
DFLMAT, |
| 40 |
|
0, |
| 41 |
|
VOIDID, |
| 42 |
+ |
SAMPDENS, |
| 43 |
|
NSAMPS, |
| 44 |
|
}; |
| 45 |
|
|
| 43 |
– |
int sampdens = SAMPDENS; /* sample point density */ |
| 46 |
|
char matcheck[MAXSTR]; /* current material to include or exclude */ |
| 47 |
|
int matselect = S_ALL; /* selection criterion */ |
| 48 |
|
|
| 68 |
|
{ |
| 69 |
|
extern char *getenv(), *getpath(); |
| 70 |
|
char *rtpath; |
| 71 |
+ |
FILE *fp; |
| 72 |
|
register int i; |
| 73 |
|
/* set global arguments */ |
| 74 |
< |
gargc = argc; gargv = argv; |
| 74 |
> |
gargv = argv; |
| 75 |
|
/* set up rtrace command */ |
| 76 |
< |
if (argc < 2) |
| 77 |
< |
error(USER, "too few arguments"); |
| 78 |
< |
for (i = 1; i < argc-1; i++) { |
| 76 |
> |
for (i = 1; i < argc; i++) { |
| 77 |
> |
if (argv[i][0] == '<' && !argv[i][1]) |
| 78 |
> |
break; |
| 79 |
|
rtargv[rtargc++] = argv[i]; |
| 80 |
|
if (argv[i][0] == '-' && argv[i][1] == 'w') |
| 81 |
|
warnings = !warnings; |
| 82 |
|
} |
| 83 |
+ |
if ((gargc = i) < 2) |
| 84 |
+ |
error(USER, "too few arguments"); |
| 85 |
+ |
rtargc--; |
| 86 |
|
for (i = 0; myrtopts[i] != NULL; i++) |
| 87 |
|
rtargv[rtargc++] = myrtopts[i]; |
| 88 |
< |
rtargv[rtargc++] = argv[argc-1]; |
| 88 |
> |
rtargv[rtargc++] = argv[gargc-1]; |
| 89 |
|
rtargv[rtargc] = NULL; |
| 90 |
|
/* just asking for defaults? */ |
| 91 |
< |
if (!strcmp(argv[argc-1], "-defaults")) { |
| 91 |
> |
if (!strcmp(argv[gargc-1], "-defaults")) { |
| 92 |
|
rtpath = getpath(rtargv[0], getenv("PATH"), X_OK); |
| 93 |
|
if (rtpath == NULL) { |
| 94 |
|
eputs(rtargv[0]); |
| 101 |
|
} |
| 102 |
|
/* else initialize and run our calculation */ |
| 103 |
|
init(); |
| 104 |
< |
filter(stdin, "standard input"); |
| 104 |
> |
if (gargc+1 < argc) |
| 105 |
> |
for (i = gargc+1; i < argc; i++) { |
| 106 |
> |
if ((fp = fopen(argv[i], "r")) == NULL { |
| 107 |
> |
sprintf(errmsg, |
| 108 |
> |
"cannot open scene file \"%s\"", argv[i]); |
| 109 |
> |
error(SYSTEM, errmsg); |
| 110 |
> |
} |
| 111 |
> |
filter(fp, argv[i]); |
| 112 |
> |
fclose(fp); |
| 113 |
> |
} |
| 114 |
> |
else |
| 115 |
> |
filter(stdin, "standard input"); |
| 116 |
|
quit(0); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
|
| 120 |
+ |
quit(status) /* exit with status */ |
| 121 |
+ |
int status; |
| 122 |
+ |
{ |
| 123 |
+ |
int rtstat; |
| 124 |
+ |
|
| 125 |
+ |
rtstat = close_process(rt.pd); |
| 126 |
+ |
if (status == 0) |
| 127 |
+ |
if (rtstat < 0) |
| 128 |
+ |
error(WARNING, |
| 129 |
+ |
"unknown return status from rtrace process"); |
| 130 |
+ |
else |
| 131 |
+ |
status = rtstat; |
| 132 |
+ |
exit(status); |
| 133 |
+ |
} |
| 134 |
+ |
|
| 135 |
+ |
|
| 136 |
|
init() /* start rtrace and set up buffers */ |
| 137 |
|
{ |
| 138 |
+ |
extern int o_face(), o_ring(); |
| 139 |
|
int maxbytes; |
| 140 |
< |
|
| 140 |
> |
/* set up object functions */ |
| 141 |
> |
ofun[OBJ_FACE].funp = o_face; |
| 142 |
> |
ofun[OBJ_RING].funp = o_ring; |
| 143 |
> |
/* set up signal handling */ |
| 144 |
> |
signal(SIGPIPE, quit); |
| 145 |
> |
/* start rtrace process */ |
| 146 |
|
maxbytes = open_process(rt.pd, rtargv); |
| 147 |
|
if (maxbytes == 0) { |
| 148 |
|
eputs(rtargv[0]); |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
|
| 124 |
– |
quit(status) /* exit with status */ |
| 125 |
– |
int status; |
| 126 |
– |
{ |
| 127 |
– |
int rtstat; |
| 128 |
– |
|
| 129 |
– |
rtstat = close_process(rt.pd); |
| 130 |
– |
if (status == 0) |
| 131 |
– |
if (rtstat < 0) |
| 132 |
– |
error(WARNING, |
| 133 |
– |
"unknown return status from rtrace process"); |
| 134 |
– |
else |
| 135 |
– |
status = rtstat; |
| 136 |
– |
exit(status); |
| 137 |
– |
} |
| 138 |
– |
|
| 139 |
– |
|
| 163 |
|
eputs(s) /* put string to stderr */ |
| 164 |
|
register char *s; |
| 165 |
|
{ |
| 301 |
|
break; |
| 302 |
|
if (!isintd(++cp, " \t\n")) |
| 303 |
|
break; |
| 304 |
< |
sampdens = atoi(cp); |
| 304 |
> |
thisillum.sampdens = atoi(cp); |
| 305 |
|
cp = sskip(cp); |
| 306 |
|
continue; |
| 307 |
|
case 's': /* point super-samples */ |
| 312 |
|
thisillum.nsamps = atoi(cp); |
| 313 |
|
cp = sskip(cp); |
| 314 |
|
continue; |
| 315 |
+ |
case 'l': /* light sources */ |
| 316 |
+ |
if (*++cp != '+' && *cp != '-') |
| 317 |
+ |
break; |
| 318 |
+ |
if (*cp++ == '+') |
| 319 |
+ |
thisillum.flags |= IL_LIGHT; |
| 320 |
+ |
else |
| 321 |
+ |
thisillum.flags &= ~IL_LIGHT; |
| 322 |
+ |
continue; |
| 323 |
|
case 'o': /* output file */ |
| 324 |
|
if (*++cp != '=') |
| 325 |
|
break; |
| 416 |
|
doit = strcmp(thisillum.altmat, matcheck); |
| 417 |
|
break; |
| 418 |
|
} |
| 419 |
< |
if (doit) /* make sure we can do it */ |
| 420 |
< |
switch (thisobj.otype) { |
| 421 |
< |
case OBJ_SPHERE: |
| 422 |
< |
case OBJ_FACE: |
| 423 |
< |
case OBJ_RING: |
| 424 |
< |
break; |
| 394 |
< |
default: |
| 395 |
< |
sprintf(errmsg, |
| 396 |
< |
"(%s): cannot make illum for %s \"%s\"", |
| 397 |
< |
nm, ofun[thisobj.otype].funame, |
| 398 |
< |
thisobj.oname); |
| 399 |
< |
error(WARNING, errmsg); |
| 400 |
< |
doit = 0; |
| 401 |
< |
break; |
| 402 |
< |
} |
| 419 |
> |
if (doit && ofun[thisobj.otype].funp == o_default) { |
| 420 |
> |
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
| 421 |
> |
nm, ofun[thisobj.otype].funame, thisobj.oname); |
| 422 |
> |
error(WARNING, errmsg); |
| 423 |
> |
doit = 0; |
| 424 |
> |
} |
| 425 |
|
/* print header? */ |
| 426 |
|
checkhead(); |
| 427 |
|
/* process object */ |
| 428 |
|
if (doit) |
| 429 |
< |
mkillum(&thisobj, &thisillum, &rt); |
| 429 |
> |
(*ofun[thisobj.otype].funp)(&thisobj, &thisillum, &rt); |
| 430 |
|
else |
| 431 |
|
printobj(thisillum.altmat, &thisobj); |
| 432 |
|
/* free arguments */ |