27 |
|
#define OBJECT 0 /* object files */ |
28 |
|
#define SCENE 1 /* scene files */ |
29 |
|
#define MATERIAL 2 /* material files */ |
30 |
< |
#define RENDER 3 /* rendering options */ |
31 |
< |
#define OCONV 4 /* oconv options */ |
32 |
< |
#define PFILT 5 /* pfilt options */ |
33 |
< |
#define VIEW 6 /* view(s) for picture(s) */ |
34 |
< |
#define ZONE 7 /* simulation zone */ |
35 |
< |
#define QUALITY 8 /* desired rendering quality */ |
36 |
< |
#define OCTREE 9 /* octree file name */ |
37 |
< |
#define PICTURE 10 /* picture file name */ |
38 |
< |
#define AMBFILE 11 /* ambient file name */ |
39 |
< |
#define OPTFILE 12 /* rendering options file */ |
40 |
< |
#define EXPOSURE 13 /* picture exposure setting */ |
41 |
< |
#define RESOLUTION 14 /* maximum picture resolution */ |
42 |
< |
#define UP 15 /* view up (X, Y or Z) */ |
43 |
< |
#define INDIRECT 16 /* indirection in lighting */ |
44 |
< |
#define DETAIL 17 /* level of scene detail */ |
45 |
< |
#define PENUMBRAS 18 /* shadow penumbras are desired */ |
46 |
< |
#define VARIABILITY 19 /* level of light variability */ |
47 |
< |
#define REPORT 20 /* report frequency and errfile */ |
30 |
> |
#define ILLUM 3 /* mkillum input files */ |
31 |
> |
#define MKILLUM 4 /* mkillum options */ |
32 |
> |
#define RENDER 5 /* rendering options */ |
33 |
> |
#define OCONV 6 /* oconv options */ |
34 |
> |
#define PFILT 7 /* pfilt options */ |
35 |
> |
#define VIEW 8 /* view(s) for picture(s) */ |
36 |
> |
#define ZONE 9 /* simulation zone */ |
37 |
> |
#define QUALITY 10 /* desired rendering quality */ |
38 |
> |
#define OCTREE 11 /* octree file name */ |
39 |
> |
#define PICTURE 12 /* picture file name */ |
40 |
> |
#define AMBFILE 13 /* ambient file name */ |
41 |
> |
#define OPTFILE 14 /* rendering options file */ |
42 |
> |
#define EXPOSURE 15 /* picture exposure setting */ |
43 |
> |
#define RESOLUTION 16 /* maximum picture resolution */ |
44 |
> |
#define UP 17 /* view up (X, Y or Z) */ |
45 |
> |
#define INDIRECT 18 /* indirection in lighting */ |
46 |
> |
#define DETAIL 19 /* level of scene detail */ |
47 |
> |
#define PENUMBRAS 20 /* shadow penumbras are desired */ |
48 |
> |
#define VARIABILITY 21 /* level of light variability */ |
49 |
> |
#define REPORT 22 /* report frequency and errfile */ |
50 |
|
/* total number of variables */ |
51 |
< |
#define NVARS 21 |
51 |
> |
#define NVARS 23 |
52 |
|
|
53 |
|
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
54 |
|
{"objects", 3, 0, NULL, catvalues}, |
55 |
|
{"scene", 3, 0, NULL, catvalues}, |
56 |
|
{"materials", 3, 0, NULL, catvalues}, |
57 |
+ |
{"illum", 3, 0, NULL, catvalues}, |
58 |
+ |
{"mkillum", 3, 0, NULL, catvalues}, |
59 |
|
{"render", 3, 0, NULL, catvalues}, |
60 |
|
{"oconv", 3, 0, NULL, catvalues}, |
61 |
|
{"pfilt", 2, 0, NULL, catvalues}, |
105 |
|
char overfile[] = "/dev/null"; |
106 |
|
#endif |
107 |
|
|
108 |
< |
extern long fdate(), time(); |
108 |
> |
extern unsigned long fdate(), time(); |
109 |
|
|
110 |
< |
long scenedate; /* date of latest scene or object file */ |
111 |
< |
long octreedate; /* date of octree */ |
112 |
< |
long matdate; /* date of latest material file */ |
110 |
> |
unsigned long scenedate; /* date of latest scene or object file */ |
111 |
> |
unsigned long octreedate; /* date of octree */ |
112 |
> |
unsigned long matdate; /* date of latest material file */ |
113 |
> |
unsigned long illumdate; /* date of last illum file */ |
114 |
|
|
115 |
+ |
char *oct0name; /* name of pre-mkillum octree */ |
116 |
+ |
unsigned long oct0date; /* date of pre-mkillum octree */ |
117 |
+ |
char *oct1name; /* name of post-mkillum octree */ |
118 |
+ |
unsigned long oct1date; /* date of post-mkillum octree (>= matdate) */ |
119 |
+ |
|
120 |
|
int explicate = 0; /* explicate variables */ |
121 |
|
int silent = 0; /* do work silently */ |
122 |
|
int noaction = 0; /* don't do anything */ |
183 |
|
/* print all values if requested */ |
184 |
|
if (explicate) |
185 |
|
printvals(); |
186 |
< |
/* build octree */ |
186 |
> |
/* build octree (and run mkillum) */ |
187 |
|
oconv(); |
188 |
|
/* check date on ambient file */ |
189 |
|
checkambfile(); |
197 |
|
exit(0); |
198 |
|
userr: |
199 |
|
fprintf(stderr, |
200 |
< |
"Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n", |
200 |
> |
"Usage: %s [-s][-n][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
201 |
|
progname); |
202 |
|
exit(1); |
203 |
|
} |
311 |
|
i++; |
312 |
|
*++cp = ass[i]; |
313 |
|
} |
314 |
< |
*++cp = '\0'; |
314 |
> |
if (isspace(*cp)) /* remove trailing space */ |
315 |
> |
*cp = '\0'; |
316 |
|
vp->nass++; |
317 |
|
} |
318 |
|
|
402 |
|
} |
403 |
|
|
404 |
|
|
405 |
< |
long |
405 |
> |
unsigned long |
406 |
|
checklast(fnames) /* check files and find most recent */ |
407 |
|
register char *fnames; |
408 |
|
{ |
409 |
|
char thisfile[MAXPATH]; |
410 |
< |
long thisdate, lastdate = -1; |
410 |
> |
unsigned long thisdate, lastdate = 0; |
411 |
|
register char *cp; |
412 |
|
|
413 |
+ |
if (fnames == NULL) |
414 |
+ |
return(0); |
415 |
|
while (*fnames) { |
416 |
|
while (isspace(*fnames)) fnames++; |
417 |
|
cp = thisfile; |
418 |
|
while (*fnames && !isspace(*fnames)) |
419 |
|
*cp++ = *fnames++; |
420 |
|
*cp = '\0'; |
421 |
< |
if ((thisdate = fdate(thisfile)) < 0) |
421 |
> |
if (!(thisdate = fdate(thisfile))) |
422 |
|
syserr(thisfile); |
423 |
|
if (thisdate > lastdate) |
424 |
|
lastdate = thisdate; |
427 |
|
} |
428 |
|
|
429 |
|
|
430 |
+ |
char * |
431 |
+ |
newfname(orig, pred) /* create modified file name */ |
432 |
+ |
char *orig; |
433 |
+ |
int pred; |
434 |
+ |
{ |
435 |
+ |
extern char *rindex(); |
436 |
+ |
register char *cp; |
437 |
+ |
register int n; |
438 |
+ |
int suffix; |
439 |
+ |
|
440 |
+ |
suffix = n = strlen(orig); /* find start of suffix */ |
441 |
+ |
if ((cp = rindex(orig, '.')) != NULL) |
442 |
+ |
suffix = cp - orig; |
443 |
+ |
if ((cp = bmalloc(n+2)) == NULL) |
444 |
+ |
syserr(progname); |
445 |
+ |
strncpy(cp, orig, suffix); |
446 |
+ |
cp[suffix] = pred; /* root name + pred + suffix */ |
447 |
+ |
strcpy(cp+suffix+1, orig+suffix); |
448 |
+ |
return(cp); |
449 |
+ |
} |
450 |
+ |
|
451 |
+ |
|
452 |
|
checkfiles() /* check for existence and modified times */ |
453 |
|
{ |
454 |
< |
char *cp; |
420 |
< |
long objdate; |
454 |
> |
unsigned long objdate; |
455 |
|
|
456 |
|
if (!vdef(OCTREE)) { |
457 |
< |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) |
457 |
> |
if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL) |
458 |
|
syserr(progname); |
459 |
< |
sprintf(cp, "%s.oct", radname); |
426 |
< |
vval(OCTREE) = cp; |
459 |
> |
sprintf(vval(OCTREE), "%s.oct", radname); |
460 |
|
vdef(OCTREE)++; |
461 |
|
} |
462 |
|
octreedate = fdate(vval(OCTREE)); |
463 |
< |
scenedate = -1; |
464 |
< |
if (vdef(SCENE)) { |
465 |
< |
scenedate = checklast(vval(SCENE)); |
466 |
< |
if (vdef(OBJECT)) { |
467 |
< |
objdate = checklast(vval(OBJECT)); |
468 |
< |
if (objdate > scenedate) |
469 |
< |
scenedate = objdate; |
470 |
< |
} |
471 |
< |
} |
472 |
< |
if (octreedate < 0 & scenedate < 0) { |
473 |
< |
fprintf(stderr, "%s: need '%s' or '%s'\n", progname, |
474 |
< |
vnam(OCTREE), vnam(SCENE)); |
463 |
> |
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
464 |
> |
oct0name = newfname(vval(OCTREE), '0'); |
465 |
> |
oct1name = newfname(vval(OCTREE), '1'); |
466 |
> |
oct0date = fdate(oct0name); |
467 |
> |
oct1date = fdate(oct1name); |
468 |
> |
} else |
469 |
> |
oct0name = oct1name = vval(OCTREE); |
470 |
> |
if ((scenedate = checklast(vval(SCENE))) && |
471 |
> |
(objdate = checklast(vval(OBJECT))) > scenedate) |
472 |
> |
scenedate = objdate; |
473 |
> |
illumdate = checklast(vval(ILLUM)); |
474 |
> |
if (!octreedate & !scenedate & !illumdate) { |
475 |
> |
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
476 |
> |
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
477 |
|
exit(1); |
478 |
|
} |
479 |
< |
matdate = -1; |
445 |
< |
if (vdef(MATERIAL)) |
446 |
< |
matdate = checklast(vval(MATERIAL)); |
479 |
> |
matdate = checklast(vval(MATERIAL)); |
480 |
|
} |
481 |
|
|
482 |
|
|
485 |
|
{ |
486 |
|
extern FILE *popen(); |
487 |
|
static double oorg[3], osiz = 0.; |
488 |
< |
char buf[MAXPATH+16]; |
488 |
> |
double min[3], max[3]; |
489 |
> |
char buf[512]; |
490 |
|
FILE *fp; |
491 |
+ |
register int i; |
492 |
|
|
493 |
< |
if (osiz <= FTINY) { |
494 |
< |
oconv(); /* does nothing if done already */ |
495 |
< |
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
496 |
< |
if ((fp = popen(buf, "r")) == NULL) |
497 |
< |
syserr("getinfo"); |
498 |
< |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
499 |
< |
&oorg[2], &osiz) != 4) { |
500 |
< |
fprintf(stderr, |
493 |
> |
if (osiz <= FTINY) |
494 |
> |
if (noaction && fdate(oct1name) < |
495 |
> |
(scenedate>illumdate?scenedate:illumdate)) { |
496 |
> |
/* run getbbox */ |
497 |
> |
sprintf(buf, "getbbox -w -h %s", |
498 |
> |
vdef(SCENE) ? vval(SCENE) : vval(ILLUM)); |
499 |
> |
if ((fp = popen(buf, "r")) == NULL) |
500 |
> |
syserr("getbbox"); |
501 |
> |
if (fscanf(fp, "%lf %lf %lf %lf %lf %lf", |
502 |
> |
&min[0], &max[0], &min[1], &max[1], |
503 |
> |
&min[2], &max[2]) != 6) { |
504 |
> |
fprintf(stderr, |
505 |
> |
"%s: error reading bounding box from getbbox\n", |
506 |
> |
progname); |
507 |
> |
exit(1); |
508 |
> |
} |
509 |
> |
for (i = 0; i < 3; i++) |
510 |
> |
if (max[i] - min[i] > osiz) |
511 |
> |
osiz = max[i] - min[i]; |
512 |
> |
for (i = 0; i < 3; i++) |
513 |
> |
oorg[i] = (max[i]+min[i]-osiz)*.5; |
514 |
> |
pclose(fp); |
515 |
> |
} else { /* from octree */ |
516 |
> |
oconv(); /* does nothing if done already */ |
517 |
> |
sprintf(buf, "getinfo -d < %s", oct1name); |
518 |
> |
if ((fp = popen(buf, "r")) == NULL) |
519 |
> |
syserr("getinfo"); |
520 |
> |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
521 |
> |
&oorg[2], &osiz) != 4) { |
522 |
> |
fprintf(stderr, |
523 |
|
"%s: error reading bounding cube from getinfo\n", |
524 |
< |
progname); |
525 |
< |
exit(1); |
524 |
> |
progname); |
525 |
> |
exit(1); |
526 |
> |
} |
527 |
> |
pclose(fp); |
528 |
|
} |
470 |
– |
pclose(fp); |
471 |
– |
} |
529 |
|
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
530 |
|
} |
531 |
|
|
588 |
|
} |
589 |
|
|
590 |
|
|
591 |
< |
oconv() /* run oconv if necessary */ |
591 |
> |
oconv() /* run oconv and mkillum if necessary */ |
592 |
|
{ |
593 |
< |
char combuf[512], ocopts[64]; |
593 |
> |
static char illumtmp[] = "ilXXXXXX"; |
594 |
> |
char combuf[512], ocopts[64], mkopts[64]; |
595 |
|
|
596 |
< |
if (octreedate >= scenedate) /* check dates */ |
597 |
< |
return; |
598 |
< |
/* build command */ |
599 |
< |
oconvopts(ocopts); |
600 |
< |
if (vdef(MATERIAL)) |
543 |
< |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
596 |
> |
oconvopts(ocopts); /* get options */ |
597 |
> |
if (octreedate < scenedate) { /* check date on original octree */ |
598 |
> |
/* build command */ |
599 |
> |
if (vdef(MATERIAL)) |
600 |
> |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
601 |
|
vval(MATERIAL), vval(SCENE), vval(OCTREE)); |
602 |
+ |
else |
603 |
+ |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
604 |
+ |
vval(SCENE), vval(OCTREE)); |
605 |
+ |
|
606 |
+ |
if (runcom(combuf)) { /* run it */ |
607 |
+ |
fprintf(stderr, |
608 |
+ |
"%s: error generating octree\n\t%s removed\n", |
609 |
+ |
progname, vval(OCTREE)); |
610 |
+ |
unlink(vval(OCTREE)); |
611 |
+ |
exit(1); |
612 |
+ |
} |
613 |
+ |
octreedate = time(0); |
614 |
+ |
} |
615 |
+ |
if (oct1name == vval(OCTREE)) /* no mkillum? */ |
616 |
+ |
oct1date = octreedate > matdate ? octreedate : matdate; |
617 |
+ |
if (oct1date >= octreedate & oct1date >= matdate |
618 |
+ |
& oct1date >= illumdate) /* all done */ |
619 |
+ |
return; |
620 |
+ |
/* make octree0 */ |
621 |
+ |
if (oct0date < scenedate | oct0date < illumdate) { |
622 |
+ |
/* build command */ |
623 |
+ |
if (octreedate) |
624 |
+ |
sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, |
625 |
+ |
vval(OCTREE), vval(ILLUM), oct0name); |
626 |
+ |
else if (vdef(MATERIAL)) |
627 |
+ |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
628 |
+ |
vval(MATERIAL), vval(ILLUM), oct0name); |
629 |
+ |
else |
630 |
+ |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
631 |
+ |
vval(ILLUM), oct0name); |
632 |
+ |
if (runcom(combuf)) { /* run it */ |
633 |
+ |
fprintf(stderr, |
634 |
+ |
"%s: error generating octree\n\t%s removed\n", |
635 |
+ |
progname, oct0name); |
636 |
+ |
unlink(oct0name); |
637 |
+ |
exit(1); |
638 |
+ |
} |
639 |
+ |
oct0date = time(0); |
640 |
+ |
} |
641 |
+ |
mkillumopts(mkopts); /* build mkillum command */ |
642 |
+ |
mktemp(illumtmp); |
643 |
+ |
sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, |
644 |
+ |
oct0name, vval(ILLUM), illumtmp); |
645 |
+ |
if (runcom(combuf)) { /* run it */ |
646 |
+ |
fprintf(stderr, "%s: error running mkillum\n", progname); |
647 |
+ |
unlink(illumtmp); |
648 |
+ |
exit(1); |
649 |
+ |
} |
650 |
+ |
/* make octree1 (frozen) */ |
651 |
+ |
if (octreedate) |
652 |
+ |
sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, |
653 |
+ |
vval(OCTREE), illumtmp, oct1name); |
654 |
+ |
else if (vdef(MATERIAL)) |
655 |
+ |
sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, |
656 |
+ |
vval(MATERIAL), illumtmp, oct1name); |
657 |
|
else |
658 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
659 |
< |
vval(SCENE), vval(OCTREE)); |
548 |
< |
|
658 |
> |
sprintf(combuf, "oconv%s -f %s > %s", ocopts, |
659 |
> |
illumtmp, oct1name); |
660 |
|
if (runcom(combuf)) { /* run it */ |
661 |
< |
fprintf(stderr, "%s: error generating octree\n\t%s removed\n", |
662 |
< |
progname, vval(OCTREE)); |
663 |
< |
unlink(vval(OCTREE)); |
661 |
> |
fprintf(stderr, |
662 |
> |
"%s: error generating octree\n\t%s removed\n", |
663 |
> |
progname, oct1name); |
664 |
> |
unlink(oct1name); |
665 |
|
exit(1); |
666 |
|
} |
667 |
< |
octreedate = time(0); |
667 |
> |
oct1date = time(0); |
668 |
> |
rmfile(illumtmp); |
669 |
|
} |
670 |
|
|
671 |
|
|
691 |
|
} |
692 |
|
|
693 |
|
|
694 |
+ |
mkillumopts(mo) /* get mkillum options */ |
695 |
+ |
register char *mo; |
696 |
+ |
{ |
697 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
698 |
+ |
|
699 |
+ |
*mo = '\0'; |
700 |
+ |
if (vdef(MKILLUM)) |
701 |
+ |
addarg(mo, vval(MKILLUM)); |
702 |
+ |
} |
703 |
+ |
|
704 |
+ |
|
705 |
|
checkambfile() /* check date on ambient file */ |
706 |
|
{ |
707 |
< |
long afdate; |
707 |
> |
unsigned long afdate; |
708 |
|
|
709 |
|
if (!vdef(AMBFILE)) |
710 |
|
return; |
711 |
< |
if ((afdate = fdate(vval(AMBFILE))) < 0) |
711 |
> |
if (!(afdate = fdate(vval(AMBFILE)))) |
712 |
|
return; |
713 |
< |
if (octreedate > afdate | matdate > afdate) |
713 |
> |
if (oct1date > afdate) |
714 |
|
rmfile(vval(AMBFILE)); |
715 |
|
} |
716 |
|
|
1095 |
|
cp += strlen(cp); |
1096 |
|
} |
1097 |
|
} |
1098 |
< |
strcpy(cp, vs); /* append any additional options */ |
1098 |
> |
if (cp == viewopts) /* append any additional options */ |
1099 |
> |
vs++; /* skip prefixed space if unneeded */ |
1100 |
> |
strcpy(cp, vs); |
1101 |
|
#ifdef MSDOS |
1102 |
|
if (strlen(viewopts) > 40) { |
1103 |
|
setenv("VIEW", viewopts); |
1219 |
|
sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname); |
1220 |
|
if (rvdevice != NULL) |
1221 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1222 |
< |
strcat(combuf, vval(OCTREE)); |
1222 |
> |
strcat(combuf, oct1name); |
1223 |
|
if (runcom(combuf)) { /* run it */ |
1224 |
|
fprintf(stderr, "%s: error running rview\n", progname); |
1225 |
|
exit(1); |
1235 |
|
char pfopts[128]; |
1236 |
|
char vs[32], *vw; |
1237 |
|
int vn, mult; |
1112 |
– |
long lastdate; |
1238 |
|
/* get pfilt options */ |
1239 |
|
pfiltopts(pfopts); |
1240 |
|
/* get resolution, reporting */ |
1265 |
|
else |
1266 |
|
badvalue(REPORT); |
1267 |
|
} |
1143 |
– |
/* get update time */ |
1144 |
– |
lastdate = octreedate > matdate ? octreedate : matdate; |
1268 |
|
/* do each view */ |
1269 |
|
vn = 0; |
1270 |
|
while ((vw = getview(vn++, vs)) != NULL) { |
1274 |
|
sprintf(vs, "%d", vn); |
1275 |
|
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1276 |
|
/* check date on picture */ |
1277 |
< |
if (fdate(picfile) >= lastdate) |
1277 |
> |
if (fdate(picfile) >= oct1date) |
1278 |
|
continue; |
1279 |
|
/* build rpict command */ |
1280 |
|
sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs); |
1281 |
< |
if (fdate(rawfile) >= octreedate) /* recover */ |
1281 |
> |
if (fdate(rawfile) >= oct1date) /* recover */ |
1282 |
|
sprintf(combuf, "rpict%s%s -ro %s %s", |
1283 |
< |
rep, opts, rawfile, vval(OCTREE)); |
1283 |
> |
rep, opts, rawfile, oct1name); |
1284 |
|
else { |
1285 |
|
if (overture) { /* run overture calculation */ |
1286 |
|
sprintf(combuf, |
1287 |
|
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1288 |
|
rep, vw, opts, |
1289 |
< |
vval(OCTREE), overfile); |
1289 |
> |
oct1name, overfile); |
1290 |
|
if (runcom(combuf)) { |
1291 |
|
fprintf(stderr, |
1292 |
|
"%s: error in overture for view %s\n", |
1299 |
|
} |
1300 |
|
sprintf(combuf, "rpict%s %s %s%s %s > %s", |
1301 |
|
rep, vw, res, opts, |
1302 |
< |
vval(OCTREE), rawfile); |
1302 |
> |
oct1name, rawfile); |
1303 |
|
} |
1304 |
|
if (runcom(combuf)) { /* run rpict */ |
1305 |
|
fprintf(stderr, "%s: error rendering view %s\n", |