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