9 |
|
*/ |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
+ |
#include <math.h> |
13 |
|
#include <string.h> |
14 |
|
#include "fvect.h" |
15 |
|
#include "object.h" |
16 |
|
#include "color.h" |
17 |
|
#include "lookup.h" |
18 |
|
|
19 |
+ |
#define PI 3.14159265358979323846 |
20 |
+ |
|
21 |
+ |
#define C_1SIDEDTHICK 0.005 |
22 |
+ |
|
23 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
24 |
< |
int o_instance(), o_source(), o_illum(); |
25 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
24 |
> |
int o_instance(), o_illum(); |
25 |
> |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
26 |
> |
o_mirror(), o_trans(), o_light(); |
27 |
|
|
28 |
|
extern void free(); |
29 |
|
extern char *malloc(); |
43 |
|
* Stuff for tracking and reusing vertices: |
44 |
|
*/ |
45 |
|
|
46 |
< |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
46 |
> |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
47 |
|
#define VKLEN 64 |
48 |
|
|
49 |
|
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
50 |
|
|
51 |
|
#define NVERTS 256 |
52 |
|
|
53 |
< |
long clock; /* incremented at each vertex request */ |
53 |
> |
long vclock; /* incremented at each vertex request */ |
54 |
|
|
55 |
|
struct vert { |
56 |
|
long lused; /* when last used (0 if unassigned) */ |
86 |
|
goto unkopt; |
87 |
|
} |
88 |
|
break; |
89 |
+ |
default: |
90 |
+ |
goto unkopt; |
91 |
|
} |
92 |
|
init(); |
93 |
|
if (i >= argc) |
194 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
195 |
|
exit(1); |
196 |
|
} |
197 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
198 |
< |
newmat(id, mod); |
197 |
> |
} else { /* unsupported */ |
198 |
> |
o_unsupported(mod, typ, id, fa); |
199 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
200 |
> |
newmat(id, mod); |
201 |
> |
} |
202 |
|
} |
203 |
|
|
204 |
|
|
291 |
|
add2dispatch("metal", o_metal); |
292 |
|
add2dispatch("metal2", o_metal); |
293 |
|
add2dispatch("glass", o_glass); |
294 |
+ |
add2dispatch("dielectric", o_dielectric); |
295 |
|
add2dispatch("trans", o_trans); |
296 |
|
add2dispatch("trans2", o_trans); |
297 |
|
add2dispatch("mirror", o_mirror); |
299 |
|
add2dispatch("spotlight", o_light); |
300 |
|
add2dispatch("glow", o_light); |
301 |
|
add2dispatch("illum", o_illum); |
302 |
< |
puts("# The following was converted from Radiance scene input"); |
302 |
> |
puts("# The following was converted from RADIANCE scene input"); |
303 |
|
if (hasmult) |
304 |
|
printf("xf -s %.4e\n", unit_mult); |
305 |
|
printf("o %s\n", curobj); |
311 |
|
puts("o"); |
312 |
|
if (hasmult) |
313 |
|
puts("xf"); |
314 |
< |
puts("# End of data converted from Radiance scene input"); |
314 |
> |
puts("# End of data converted from RADIANCE scene input"); |
315 |
|
lu_done(&rdispatch); |
316 |
|
lu_done(&rmats); |
317 |
|
lu_done(&vertab); |
351 |
|
char *vname; |
352 |
|
FVECT vp; |
353 |
|
{ |
354 |
< |
char vkey[VKLEN]; |
354 |
> |
static char vkey[VKLEN]; |
355 |
|
register LUENT *lp; |
356 |
|
register int i, vndx; |
357 |
|
|
358 |
< |
clock++; /* increment counter */ |
358 |
> |
vclock++; /* increment counter */ |
359 |
|
mkvkey(vkey, vp); |
360 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
361 |
|
goto memerr; |
381 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
382 |
|
} else |
383 |
|
vndx = (struct vert *)lp->data - vert; |
384 |
< |
vert[vndx].lused = clock; /* record this use */ |
384 |
> |
vert[vndx].lused = vclock; /* record this use */ |
385 |
|
sprintf(vname, "v%d", vndx); |
386 |
|
return(vname); |
387 |
|
memerr: |
391 |
|
|
392 |
|
|
393 |
|
int |
394 |
+ |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
395 |
+ |
char *mod, *typ, *id; |
396 |
+ |
FUNARGS *fa; |
397 |
+ |
{ |
398 |
+ |
register int i; |
399 |
+ |
|
400 |
+ |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
401 |
+ |
printf("# %s %s %s", mod, typ, id); |
402 |
+ |
printf("\n# %d", fa->nsargs); |
403 |
+ |
for (i = 0; i < fa->nsargs; i++) |
404 |
+ |
printf(" %s", fa->sarg[i]); |
405 |
+ |
#ifdef IARGS |
406 |
+ |
printf("\n# %d", fa->niargs); |
407 |
+ |
for (i = 0; i < fa->niargs; i++) |
408 |
+ |
printf(" %ld", fa->iarg[i]); |
409 |
+ |
#else |
410 |
+ |
fputs("\n# 0", stdout); |
411 |
+ |
#endif |
412 |
+ |
printf("\n# %d", fa->nfargs); |
413 |
+ |
for (i = 0; i < fa->nfargs; i++) |
414 |
+ |
printf(" %g", fa->farg[i]); |
415 |
+ |
fputs("\n\n", stdout); |
416 |
+ |
return(0); |
417 |
+ |
} |
418 |
+ |
|
419 |
+ |
|
420 |
+ |
int |
421 |
|
o_face(mod, typ, id, fa) /* print out a polygon */ |
422 |
|
char *mod, *typ, *id; |
423 |
|
FUNARGS *fa; |
567 |
|
|
568 |
|
|
569 |
|
int |
531 |
– |
o_source(mod, typ, id, fa) /* convert a source */ |
532 |
– |
char *mod, *typ, *id; |
533 |
– |
FUNARGS *fa; |
534 |
– |
{ |
535 |
– |
return(0); /* there is no MGF equivalent! */ |
536 |
– |
} |
537 |
– |
|
538 |
– |
|
539 |
– |
int |
570 |
|
o_illum(mod, typ, id, fa) /* convert an illum material */ |
571 |
|
char *mod, *typ, *id; |
572 |
|
FUNARGS *fa; |
650 |
|
newmat(id, NULL); |
651 |
|
if (fa->nfargs == 4) |
652 |
|
nrfr = fa->farg[3]; |
653 |
+ |
printf("\tir %f 0\n", nrfr); |
654 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
655 |
|
F *= F; |
656 |
|
for (i = 0; i < 3; i++) { |
676 |
|
|
677 |
|
|
678 |
|
int |
679 |
+ |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
680 |
+ |
char *mod, *typ, *id; |
681 |
+ |
register FUNARGS *fa; |
682 |
+ |
{ |
683 |
+ |
COLOR cxyz, trgb; |
684 |
+ |
double F, d; |
685 |
+ |
register int i; |
686 |
+ |
|
687 |
+ |
if (fa->nfargs != 5) |
688 |
+ |
return(-1); |
689 |
+ |
newmat(id, NULL); |
690 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
691 |
+ |
F *= F; |
692 |
+ |
for (i = 0; i < 3; i++) |
693 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
694 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
695 |
+ |
printf("\tsides 1\n"); |
696 |
+ |
puts("\tc"); /* put reflected component */ |
697 |
+ |
printf("\trs %.4f 0\n", F); |
698 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
699 |
+ |
puts("\tc"); |
700 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
701 |
+ |
if (d > FTINY) |
702 |
+ |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
703 |
+ |
printf("\tts %.4f 0\n", cxyz[1]); |
704 |
+ |
return(0); |
705 |
+ |
} |
706 |
+ |
|
707 |
+ |
|
708 |
+ |
int |
709 |
|
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
710 |
|
char *mod, *typ, *id; |
711 |
|
register FUNARGS *fa; |
787 |
|
puts("\tc"); |
788 |
|
if (d > FTINY) |
789 |
|
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
790 |
< |
printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); |
790 |
> |
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
791 |
|
return(0); |
792 |
|
} |