1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert Radiance scene description to MGF |
6 |
|
*/ |
7 |
|
|
11 |
– |
#include <stdio.h> |
12 |
– |
#include <math.h> |
8 |
|
#include <ctype.h> |
9 |
|
#include <string.h> |
10 |
< |
#include "fvect.h" |
10 |
> |
#include <stdio.h> |
11 |
> |
|
12 |
> |
#include "platform.h" |
13 |
> |
#include "rtmath.h" |
14 |
> |
#include "rtio.h" |
15 |
> |
#include "rtprocess.h" |
16 |
|
#include "object.h" |
17 |
|
#include "color.h" |
18 |
|
#include "lookup.h" |
19 |
|
|
20 |
– |
#define PI 3.14159265358979323846 |
21 |
– |
|
20 |
|
#define C_1SIDEDTHICK 0.005 |
21 |
|
|
24 |
– |
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
25 |
– |
int o_instance(), o_illum(); |
26 |
– |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
27 |
– |
o_mirror(), o_trans(), o_light(); |
22 |
|
|
29 |
– |
extern void free(); |
30 |
– |
extern char *malloc(); |
31 |
– |
|
23 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
24 |
|
|
25 |
|
LUTAB rdispatch = LU_SINIT(NULL,NULL); /* function dispatch table */ |
51 |
|
|
52 |
|
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
53 |
|
|
54 |
+ |
void rad2mgf(char *inp); |
55 |
+ |
void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa); |
56 |
+ |
void newmat(char *id, char *alias); |
57 |
+ |
void setmat(char *id); |
58 |
+ |
void setobj(char *id); |
59 |
+ |
void init(void); |
60 |
+ |
void uninit(void); |
61 |
+ |
void clrverts(void); |
62 |
+ |
void unspace(char *s); |
63 |
+ |
void add2dispatch(char *name, int (*func)()); |
64 |
+ |
char *getvertid(char *vname, FVECT vp); |
65 |
+ |
int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa); |
66 |
+ |
int o_face(char *mod, char *typ, char *id, FUNARGS *fa); |
67 |
+ |
int o_cone(char *mod, char *typ, char *id, FUNARGS *fa); |
68 |
+ |
int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa); |
69 |
+ |
int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa); |
70 |
+ |
int o_ring(char *mod, char *typ, char *id, FUNARGS *fa); |
71 |
+ |
int o_instance(char *mod, char *typ, char *id, FUNARGS *fa); |
72 |
+ |
int o_illum(char *mod, char *typ, char *id, FUNARGS *fa); |
73 |
+ |
int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa); |
74 |
+ |
int o_metal(char *mod, char *typ, char *id, FUNARGS *fa); |
75 |
+ |
int o_glass(char *mod, char *typ, char *id, FUNARGS *fa); |
76 |
+ |
int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa); |
77 |
+ |
int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa); |
78 |
+ |
int o_trans(char *mod, char *typ, char *id, FUNARGS *fa); |
79 |
+ |
int o_light(char *mod, char *typ, char *id, FUNARGS *fa); |
80 |
|
|
81 |
< |
main(argc, argv) |
82 |
< |
int argc; |
83 |
< |
char **argv; |
81 |
> |
|
82 |
> |
int |
83 |
> |
main( |
84 |
> |
int argc, |
85 |
> |
char **argv |
86 |
> |
) |
87 |
|
{ |
88 |
|
int i; |
89 |
|
|
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
< |
rad2mgf(inp) /* convert a Radiance file to MGF */ |
128 |
< |
char *inp; |
127 |
> |
void |
128 |
> |
rad2mgf( /* convert a Radiance file to MGF */ |
129 |
> |
char *inp |
130 |
> |
) |
131 |
|
{ |
132 |
< |
#define mod buf |
133 |
< |
#define typ (buf+128) |
112 |
< |
#define id (buf+256) |
113 |
< |
#define alias (buf+384) |
114 |
< |
char buf[512]; |
132 |
> |
char buf[512]; |
133 |
> |
char mod[128], typ[32], id[128], alias[128]; |
134 |
|
FUNARGS fa; |
135 |
|
register FILE *fp; |
136 |
|
register int c; |
169 |
|
break; |
170 |
|
default: /* Radiance primitive */ |
171 |
|
ungetc(c, fp); |
172 |
< |
if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) { |
172 |
> |
if (fgetword(mod, sizeof(mod), fp) == NULL || |
173 |
> |
fgetword(typ, sizeof(typ), fp) == NULL || |
174 |
> |
fgetword(id, sizeof(id), fp) == NULL) { |
175 |
|
fputs(inp, stderr); |
176 |
|
fputs(": unexpected EOF\n", stderr); |
177 |
|
exit(1); |
178 |
|
} |
179 |
+ |
unspace(mod); |
180 |
+ |
unspace(id); |
181 |
|
if (!strcmp(typ, "alias")) { |
182 |
|
strcpy(alias, "EOF"); |
183 |
< |
fscanf(fp, "%s", alias); |
183 |
> |
fgetword(alias, sizeof(alias), fp); |
184 |
> |
unspace(alias); |
185 |
|
newmat(id, alias); |
186 |
|
} else { |
187 |
|
if (!readfargs(&fa, fp)) { |
200 |
|
pclose(fp); |
201 |
|
else |
202 |
|
fclose(fp); |
179 |
– |
#undef mod |
180 |
– |
#undef typ |
181 |
– |
#undef id |
182 |
– |
#undef alias |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
< |
cvtprim(inp, mod, typ, id, fa) /* process Radiance primitive */ |
207 |
< |
char *inp, *mod, *typ, *id; |
208 |
< |
FUNARGS *fa; |
206 |
> |
void |
207 |
> |
unspace( /* replace spaces with underscores in s */ |
208 |
> |
char *s |
209 |
> |
) |
210 |
|
{ |
211 |
+ |
while (*s) { |
212 |
+ |
if (isspace(*s)) |
213 |
+ |
*s = '_'; |
214 |
+ |
++s; |
215 |
+ |
} |
216 |
+ |
} |
217 |
+ |
|
218 |
+ |
|
219 |
+ |
void |
220 |
+ |
cvtprim( /* process Radiance primitive */ |
221 |
+ |
char *inp, |
222 |
+ |
char *mod, |
223 |
+ |
char *typ, |
224 |
+ |
char *id, |
225 |
+ |
FUNARGS *fa |
226 |
+ |
) |
227 |
+ |
{ |
228 |
|
int (*df)(); |
229 |
|
|
230 |
|
df = (int (*)())lu_find(&rdispatch, typ)->data; |
231 |
|
if (df != NULL) { /* convert */ |
232 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
233 |
< |
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
233 |
> |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id); |
234 |
|
exit(1); |
235 |
|
} |
236 |
|
} else { /* unsupported */ |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
newmat(id, alias) /* add a modifier to the alias list */ |
245 |
< |
char *id; |
246 |
< |
char *alias; |
244 |
> |
void |
245 |
> |
newmat( /* add a modifier to the alias list */ |
246 |
> |
char *id, |
247 |
> |
char *alias |
248 |
> |
) |
249 |
|
{ |
250 |
|
register LUENT *lp, *lpa; |
251 |
|
|
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
< |
setmat(id) /* set material to this one */ |
283 |
< |
char *id; |
282 |
> |
void |
283 |
> |
setmat( /* set material to this one */ |
284 |
> |
char *id |
285 |
> |
) |
286 |
|
{ |
287 |
|
if (!strcmp(id, curmat)) /* already set? */ |
288 |
|
return; |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
< |
setobj(id) /* set object name to this one */ |
297 |
< |
char *id; |
296 |
> |
void |
297 |
> |
setobj( /* set object name to this one */ |
298 |
> |
char *id |
299 |
> |
) |
300 |
|
{ |
301 |
|
register char *cp, *cp2; |
302 |
|
char *end = NULL; |
314 |
|
*cp2++ = 'O'; |
315 |
|
} |
316 |
|
for (cp = id; cp < end; *cp2++ = *cp++) { |
317 |
< |
if (*cp < '!' | *cp > '~') /* limit to visible chars */ |
317 |
> |
if ((*cp < '!') | (*cp > '~')) /* limit to visible chars */ |
318 |
|
*cp = '?'; |
319 |
|
diff += *cp != *cp2; |
320 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
< |
init() /* initialize dispatch table and output */ |
329 |
> |
void |
330 |
> |
init(void) /* initialize dispatch table and output */ |
331 |
|
{ |
332 |
|
lu_init(&vertab, NVERTS); |
333 |
|
lu_init(&rdispatch, 22); |
340 |
|
add2dispatch("tube", o_cylinder); |
341 |
|
add2dispatch("ring", o_ring); |
342 |
|
add2dispatch("instance", o_instance); |
343 |
+ |
add2dispatch("mesh", o_instance); |
344 |
|
add2dispatch("plastic", o_plastic); |
345 |
|
add2dispatch("plastic2", o_plastic); |
346 |
|
add2dispatch("metal", o_metal); |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
< |
uninit() /* mark end of MGF file */ |
364 |
> |
void |
365 |
> |
uninit(void) /* mark end of MGF file */ |
366 |
|
{ |
367 |
|
puts("o"); |
368 |
|
if (hasmult) |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
clrverts() /* clear vertex table */ |
377 |
> |
void |
378 |
> |
clrverts(void) /* clear vertex table */ |
379 |
|
{ |
380 |
|
register int i; |
381 |
|
|
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
< |
add2dispatch(name, func) /* add function to dispatch table */ |
390 |
< |
char *name; |
391 |
< |
int (*func)(); |
389 |
> |
void |
390 |
> |
add2dispatch( /* add function to dispatch table */ |
391 |
> |
char *name, |
392 |
> |
int (*func)() |
393 |
> |
) |
394 |
|
{ |
395 |
|
register LUENT *lp; |
396 |
|
|
406 |
|
|
407 |
|
|
408 |
|
char * |
409 |
< |
getvertid(vname, vp) /* get/set vertex ID for this point */ |
410 |
< |
char *vname; |
411 |
< |
FVECT vp; |
409 |
> |
getvertid( /* get/set vertex ID for this point */ |
410 |
> |
char *vname, |
411 |
> |
FVECT vp |
412 |
> |
) |
413 |
|
{ |
414 |
|
static char vkey[VKLEN]; |
415 |
|
register LUENT *lp; |
451 |
|
|
452 |
|
|
453 |
|
int |
454 |
< |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
455 |
< |
char *mod, *typ, *id; |
456 |
< |
FUNARGS *fa; |
454 |
> |
o_unsupported( /* mark unsupported primitive */ |
455 |
> |
char *mod, |
456 |
> |
char *typ, |
457 |
> |
char *id, |
458 |
> |
FUNARGS *fa |
459 |
> |
) |
460 |
|
{ |
461 |
|
register int i; |
462 |
|
|
481 |
|
|
482 |
|
|
483 |
|
int |
484 |
< |
o_face(mod, typ, id, fa) /* print out a polygon */ |
485 |
< |
char *mod, *typ, *id; |
486 |
< |
FUNARGS *fa; |
484 |
> |
o_face( /* print out a polygon */ |
485 |
> |
char *mod, |
486 |
> |
char *typ, |
487 |
> |
char *id, |
488 |
> |
FUNARGS *fa |
489 |
> |
) |
490 |
|
{ |
491 |
< |
char entbuf[2048]; |
491 |
> |
char entbuf[2048], *linestart; |
492 |
|
register char *cp; |
493 |
|
register int i; |
494 |
|
|
495 |
< |
if (fa->nfargs < 9 | fa->nfargs % 3) |
495 |
> |
if ((fa->nfargs < 9) | (fa->nfargs % 3)) |
496 |
|
return(-1); |
497 |
|
setmat(mod); |
498 |
|
setobj(id); |
499 |
< |
cp = entbuf; |
499 |
> |
cp = linestart = entbuf; |
500 |
|
*cp++ = 'f'; |
501 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
502 |
|
*cp++ = ' '; |
503 |
+ |
if (cp - linestart > 72) { |
504 |
+ |
*cp++ = '\\'; *cp++ = '\n'; |
505 |
+ |
linestart = cp; |
506 |
+ |
*cp++ = ' '; *cp++ = ' '; |
507 |
+ |
} |
508 |
|
getvertid(cp, fa->farg + i); |
509 |
|
while (*cp) |
510 |
|
cp++; |
515 |
|
|
516 |
|
|
517 |
|
int |
518 |
< |
o_cone(mod, typ, id, fa) /* print out a cone */ |
519 |
< |
char *mod, *typ, *id; |
520 |
< |
register FUNARGS *fa; |
518 |
> |
o_cone( /* print out a cone */ |
519 |
> |
char *mod, |
520 |
> |
char *typ, |
521 |
> |
char *id, |
522 |
> |
register FUNARGS *fa |
523 |
> |
) |
524 |
|
{ |
525 |
|
char v1[6], v2[6]; |
526 |
|
|
541 |
|
|
542 |
|
|
543 |
|
int |
544 |
< |
o_sphere(mod, typ, id, fa) /* print out a sphere */ |
545 |
< |
char *mod, *typ, *id; |
546 |
< |
register FUNARGS *fa; |
544 |
> |
o_sphere( /* print out a sphere */ |
545 |
> |
char *mod, |
546 |
> |
char *typ, |
547 |
> |
char *id, |
548 |
> |
register FUNARGS *fa |
549 |
> |
) |
550 |
|
{ |
551 |
|
char cent[6]; |
552 |
|
|
561 |
|
|
562 |
|
|
563 |
|
int |
564 |
< |
o_cylinder(mod, typ, id, fa) /* print out a cylinder */ |
565 |
< |
char *mod, *typ, *id; |
566 |
< |
register FUNARGS *fa; |
564 |
> |
o_cylinder( /* print out a cylinder */ |
565 |
> |
char *mod, |
566 |
> |
char *typ, |
567 |
> |
char *id, |
568 |
> |
register FUNARGS *fa |
569 |
> |
) |
570 |
|
{ |
571 |
|
char v1[6], v2[6]; |
572 |
|
|
583 |
|
|
584 |
|
|
585 |
|
int |
586 |
< |
o_ring(mod, typ, id, fa) /* print out a ring */ |
587 |
< |
char *mod, *typ, *id; |
588 |
< |
register FUNARGS *fa; |
586 |
> |
o_ring( /* print out a ring */ |
587 |
> |
char *mod, |
588 |
> |
char *typ, |
589 |
> |
char *id, |
590 |
> |
register FUNARGS *fa |
591 |
> |
) |
592 |
|
{ |
593 |
|
if (fa->nfargs != 8) |
594 |
|
return(-1); |
609 |
|
|
610 |
|
|
611 |
|
int |
612 |
< |
o_instance(mod, typ, id, fa) /* convert an instance */ |
613 |
< |
char *mod, *typ, *id; |
614 |
< |
FUNARGS *fa; |
612 |
> |
o_instance( /* convert an instance (or mesh) */ |
613 |
> |
char *mod, |
614 |
> |
char *typ, |
615 |
> |
char *id, |
616 |
> |
FUNARGS *fa |
617 |
> |
) |
618 |
|
{ |
619 |
|
register int i; |
620 |
|
register char *cp; |
653 |
|
|
654 |
|
|
655 |
|
int |
656 |
< |
o_illum(mod, typ, id, fa) /* convert an illum material */ |
657 |
< |
char *mod, *typ, *id; |
658 |
< |
FUNARGS *fa; |
656 |
> |
o_illum( /* convert an illum material */ |
657 |
> |
char *mod, |
658 |
> |
char *typ, |
659 |
> |
char *id, |
660 |
> |
FUNARGS *fa |
661 |
> |
) |
662 |
|
{ |
663 |
|
if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) { |
664 |
|
newmat(id, fa->sarg[0]); /* just create alias */ |
672 |
|
|
673 |
|
|
674 |
|
int |
675 |
< |
o_plastic(mod, typ, id, fa) /* convert a plastic material */ |
676 |
< |
char *mod, *typ, *id; |
677 |
< |
register FUNARGS *fa; |
675 |
> |
o_plastic( /* convert a plastic material */ |
676 |
> |
char *mod, |
677 |
> |
char *typ, |
678 |
> |
char *id, |
679 |
> |
register FUNARGS *fa |
680 |
> |
) |
681 |
|
{ |
682 |
|
COLOR cxyz, rrgb; |
683 |
|
double d; |
690 |
|
puts("\tc"); /* put diffuse component */ |
691 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
692 |
|
if (d > FTINY) |
693 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
694 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
693 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
694 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
695 |
|
if (fa->farg[3] > FTINY) { /* put specular component */ |
696 |
|
puts("\tc"); |
697 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], |
697 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], |
698 |
|
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
699 |
|
fa->farg[4]); |
700 |
|
} |
703 |
|
|
704 |
|
|
705 |
|
int |
706 |
< |
o_metal(mod, typ, id, fa) /* convert a metal material */ |
707 |
< |
char *mod, *typ, *id; |
708 |
< |
register FUNARGS *fa; |
706 |
> |
o_metal( /* convert a metal material */ |
707 |
> |
char *mod, |
708 |
> |
char *typ, |
709 |
> |
char *id, |
710 |
> |
register FUNARGS *fa |
711 |
> |
) |
712 |
|
{ |
713 |
|
COLOR cxyz, rrgb; |
714 |
|
double d; |
721 |
|
puts("\tc"); /* put diffuse component */ |
722 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
723 |
|
if (d > FTINY) |
724 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
725 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
724 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
725 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
726 |
|
/* put specular component */ |
727 |
< |
printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
727 |
> |
printf("\trs %.6f %.6f\n", cxyz[1]*fa->farg[3], |
728 |
|
typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
729 |
|
fa->farg[4]); |
730 |
|
return(0); |
732 |
|
|
733 |
|
|
734 |
|
int |
735 |
< |
o_glass(mod, typ, id, fa) /* convert a glass material */ |
736 |
< |
char *mod, *typ, *id; |
737 |
< |
register FUNARGS *fa; |
735 |
> |
o_glass( /* convert a glass material */ |
736 |
> |
char *mod, |
737 |
> |
char *typ, |
738 |
> |
char *id, |
739 |
> |
register FUNARGS *fa |
740 |
> |
) |
741 |
|
{ |
742 |
|
COLOR cxyz, rrgb, trgb; |
743 |
|
double nrfr = 1.52, F, d; |
761 |
|
puts("\tc"); |
762 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
763 |
|
if (d > FTINY) |
764 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
765 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
764 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
765 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
766 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
767 |
|
puts("\tc"); |
768 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
769 |
|
if (d > FTINY) |
770 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
771 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
770 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
771 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
772 |
|
return(0); |
773 |
|
} |
774 |
|
|
775 |
|
|
776 |
|
int |
777 |
< |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
778 |
< |
char *mod, *typ, *id; |
779 |
< |
register FUNARGS *fa; |
777 |
> |
o_dielectric( /* convert a dielectric material */ |
778 |
> |
char *mod, |
779 |
> |
char *typ, |
780 |
> |
char *id, |
781 |
> |
register FUNARGS *fa |
782 |
> |
) |
783 |
|
{ |
784 |
|
COLOR cxyz, trgb; |
785 |
|
double F, d; |
795 |
|
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
796 |
|
printf("\tsides 1\n"); |
797 |
|
puts("\tc"); /* put reflected component */ |
798 |
< |
printf("\trs %.4f 0\n", F); |
798 |
> |
printf("\trs %.6f 0\n", F); |
799 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
800 |
|
puts("\tc"); |
801 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
802 |
|
if (d > FTINY) |
803 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
804 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
803 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
804 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
805 |
|
return(0); |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
int |
810 |
< |
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
811 |
< |
char *mod, *typ, *id; |
812 |
< |
register FUNARGS *fa; |
810 |
> |
o_mirror( /* convert a mirror material */ |
811 |
> |
char *mod, |
812 |
> |
char *typ, |
813 |
> |
char *id, |
814 |
> |
register FUNARGS *fa |
815 |
> |
) |
816 |
|
{ |
817 |
|
COLOR cxyz, rrgb; |
818 |
|
double d; |
829 |
|
puts("\tc"); /* put specular component */ |
830 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
831 |
|
if (d > FTINY) |
832 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
833 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
832 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
833 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
834 |
|
return(0); |
835 |
|
} |
836 |
|
|
837 |
|
|
838 |
|
int |
839 |
< |
o_trans(mod, typ, id, fa) /* convert a trans material */ |
840 |
< |
char *mod, *typ, *id; |
841 |
< |
register FUNARGS *fa; |
839 |
> |
o_trans( /* convert a trans material */ |
840 |
> |
char *mod, |
841 |
> |
char *typ, |
842 |
> |
char *id, |
843 |
> |
register FUNARGS *fa |
844 |
> |
) |
845 |
|
{ |
846 |
|
COLOR cxyz, rrgb; |
847 |
|
double rough, trans, tspec, d; |
848 |
|
|
849 |
< |
if (typ[4] == '2') { /* trans2 */ |
849 |
> |
if (typ[5] == '2') { /* trans2 */ |
850 |
|
if (fa->nfargs != 8) |
851 |
|
return(-1); |
852 |
|
rough = .5*(fa->farg[4] + fa->farg[5]); |
865 |
|
puts("\tc"); /* put transmitted diffuse */ |
866 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
867 |
|
if (d > FTINY) |
868 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
869 |
< |
printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
868 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
869 |
> |
printf("\ttd %.6f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
870 |
|
/* put transmitted specular */ |
871 |
< |
printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
871 |
> |
printf("\tts %.6f %.6f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
872 |
|
/* put reflected diffuse */ |
873 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
873 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
874 |
|
puts("\tc"); /* put reflected specular */ |
875 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], rough); |
875 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], rough); |
876 |
|
return(0); |
877 |
|
} |
878 |
|
|
879 |
|
|
880 |
|
int |
881 |
< |
o_light(mod, typ, id, fa) /* convert a light type */ |
882 |
< |
char *mod, *typ, *id; |
883 |
< |
register FUNARGS *fa; |
881 |
> |
o_light( /* convert a light type */ |
882 |
> |
char *mod, |
883 |
> |
char *typ, |
884 |
> |
char *id, |
885 |
> |
register FUNARGS *fa |
886 |
> |
) |
887 |
|
{ |
888 |
|
COLOR cxyz, rrgb; |
889 |
|
double d; |
896 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
897 |
|
puts("\tc"); |
898 |
|
if (d > FTINY) |
899 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
899 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
900 |
|
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
901 |
|
return(0); |
902 |
|
} |