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 <string.h> |
10 |
< |
#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 |
|
|
18 |
< |
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
19 |
< |
int o_instance(), o_source(), o_illum(); |
20 |
< |
int o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light(); |
18 |
> |
#define C_1SIDEDTHICK 0.005 |
19 |
|
|
22 |
– |
extern void free(); |
23 |
– |
extern char *malloc(); |
20 |
|
|
21 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
22 |
|
|
33 |
|
* Stuff for tracking and reusing vertices: |
34 |
|
*/ |
35 |
|
|
36 |
< |
char VKFMT[] = "%+1.9e %+1.9e %+1.9e"; |
36 |
> |
char VKFMT[] = "%+16.9e %+16.9e %+16.9e"; |
37 |
|
#define VKLEN 64 |
38 |
|
|
39 |
|
#define mkvkey(k,v) sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2]) |
40 |
|
|
41 |
|
#define NVERTS 256 |
42 |
|
|
43 |
< |
long clock; /* incremented at each vertex request */ |
43 |
> |
long vclock; /* incremented at each vertex request */ |
44 |
|
|
45 |
|
struct vert { |
46 |
|
long lused; /* when last used (0 if unassigned) */ |
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) |
105 |
< |
#define id (buf+256) |
106 |
< |
#define alias (buf+384) |
107 |
< |
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: bad exit status\n", inp); |
199 |
> |
exit(1); |
200 |
> |
} |
201 |
> |
} else |
202 |
|
fclose(fp); |
203 |
< |
#undef mod |
173 |
< |
#undef typ |
174 |
< |
#undef id |
175 |
< |
#undef alias |
203 |
> |
printf("# End conversion from: %s\n", inp); |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
< |
cvtprim(inp, mod, typ, id, fa) /* process Radiance primitive */ |
208 |
< |
char *inp, *mod, *typ, *id; |
209 |
< |
FUNARGS *fa; |
207 |
> |
void |
208 |
> |
unspace( /* replace spaces with underscores in s */ |
209 |
> |
char *s |
210 |
> |
) |
211 |
|
{ |
212 |
+ |
while (*s) { |
213 |
+ |
if (isspace(*s)) |
214 |
+ |
*s = '_'; |
215 |
+ |
++s; |
216 |
+ |
} |
217 |
+ |
} |
218 |
+ |
|
219 |
+ |
|
220 |
+ |
void |
221 |
+ |
cvtprim( /* process Radiance primitive */ |
222 |
+ |
char *inp, |
223 |
+ |
char *mod, |
224 |
+ |
char *typ, |
225 |
+ |
char *id, |
226 |
+ |
FUNARGS *fa |
227 |
+ |
) |
228 |
+ |
{ |
229 |
|
int (*df)(); |
230 |
|
|
231 |
|
df = (int (*)())lu_find(&rdispatch, typ)->data; |
232 |
|
if (df != NULL) { /* convert */ |
233 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
234 |
< |
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
234 |
> |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id); |
235 |
|
exit(1); |
236 |
|
} |
237 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
238 |
< |
newmat(id, mod); |
237 |
> |
} else { /* unsupported */ |
238 |
> |
o_unsupported(mod, typ, id, fa); |
239 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
240 |
> |
newmat(id, mod); |
241 |
> |
} |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
< |
newmat(id, alias) /* add a modifier to the alias list */ |
246 |
< |
char *id; |
247 |
< |
char *alias; |
245 |
> |
void |
246 |
> |
newmat( /* add a modifier to the alias list */ |
247 |
> |
char *id, |
248 |
> |
char *alias |
249 |
> |
) |
250 |
|
{ |
251 |
|
register LUENT *lp, *lpa; |
252 |
|
|
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
setmat(id) /* set material to this one */ |
284 |
< |
char *id; |
283 |
> |
void |
284 |
> |
setmat( /* set material to this one */ |
285 |
> |
char *id |
286 |
> |
) |
287 |
|
{ |
288 |
|
if (!strcmp(id, curmat)) /* already set? */ |
289 |
|
return; |
294 |
|
} |
295 |
|
|
296 |
|
|
297 |
< |
setobj(id) /* set object name to this one */ |
298 |
< |
char *id; |
297 |
> |
void |
298 |
> |
setobj( /* set object name to this one */ |
299 |
> |
char *id |
300 |
> |
) |
301 |
|
{ |
302 |
|
register char *cp, *cp2; |
303 |
|
char *end = NULL; |
309 |
|
if (end == NULL) |
310 |
|
end = cp; |
311 |
|
/* copy to current object */ |
312 |
< |
for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) |
312 |
> |
cp2 = curobj; |
313 |
> |
if (!isalpha(*id)) { /* start with letter */ |
314 |
> |
diff = *cp2 != 'O'; |
315 |
> |
*cp2++ = 'O'; |
316 |
> |
} |
317 |
> |
for (cp = id; cp < end; *cp2++ = *cp++) { |
318 |
> |
if ((*cp < '!') | (*cp > '~')) /* limit to visible chars */ |
319 |
> |
*cp = '?'; |
320 |
|
diff += *cp != *cp2; |
321 |
+ |
} |
322 |
|
if (!diff && !*cp2) |
323 |
|
return; |
324 |
|
*cp2 = '\0'; |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
< |
init() /* initialize dispatch table and output */ |
330 |
> |
void |
331 |
> |
init(void) /* initialize dispatch table and output */ |
332 |
|
{ |
333 |
|
lu_init(&vertab, NVERTS); |
334 |
|
lu_init(&rdispatch, 22); |
341 |
|
add2dispatch("tube", o_cylinder); |
342 |
|
add2dispatch("ring", o_ring); |
343 |
|
add2dispatch("instance", o_instance); |
344 |
+ |
add2dispatch("mesh", o_instance); |
345 |
|
add2dispatch("plastic", o_plastic); |
346 |
|
add2dispatch("plastic2", o_plastic); |
347 |
|
add2dispatch("metal", o_metal); |
348 |
|
add2dispatch("metal2", o_metal); |
349 |
|
add2dispatch("glass", o_glass); |
350 |
+ |
add2dispatch("dielectric", o_dielectric); |
351 |
|
add2dispatch("trans", o_trans); |
352 |
|
add2dispatch("trans2", o_trans); |
353 |
|
add2dispatch("mirror", o_mirror); |
355 |
|
add2dispatch("spotlight", o_light); |
356 |
|
add2dispatch("glow", o_light); |
357 |
|
add2dispatch("illum", o_illum); |
358 |
< |
puts("# The following was converted from Radiance scene input"); |
358 |
> |
puts("# The following was converted from RADIANCE scene input"); |
359 |
|
if (hasmult) |
360 |
|
printf("xf -s %.4e\n", unit_mult); |
361 |
|
printf("o %s\n", curobj); |
362 |
|
} |
363 |
|
|
364 |
|
|
365 |
< |
uninit() /* mark end of MGF file */ |
365 |
> |
void |
366 |
> |
uninit(void) /* mark end of MGF file */ |
367 |
|
{ |
368 |
|
puts("o"); |
369 |
|
if (hasmult) |
370 |
|
puts("xf"); |
371 |
< |
puts("# End of data converted from Radiance scene input"); |
371 |
> |
puts("# End of data converted from RADIANCE scene input"); |
372 |
|
lu_done(&rdispatch); |
373 |
|
lu_done(&rmats); |
374 |
|
lu_done(&vertab); |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
< |
clrverts() /* clear vertex table */ |
378 |
> |
void |
379 |
> |
clrverts(void) /* clear vertex table */ |
380 |
|
{ |
381 |
|
register int i; |
382 |
|
|
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
< |
add2dispatch(name, func) /* add function to dispatch table */ |
391 |
< |
char *name; |
392 |
< |
int (*func)(); |
390 |
> |
void |
391 |
> |
add2dispatch( /* add function to dispatch table */ |
392 |
> |
char *name, |
393 |
> |
int (*func)() |
394 |
> |
) |
395 |
|
{ |
396 |
|
register LUENT *lp; |
397 |
|
|
407 |
|
|
408 |
|
|
409 |
|
char * |
410 |
< |
getvertid(vname, vp) /* get/set vertex ID for this point */ |
411 |
< |
char *vname; |
412 |
< |
FVECT vp; |
410 |
> |
getvertid( /* get/set vertex ID for this point */ |
411 |
> |
char *vname, |
412 |
> |
FVECT vp |
413 |
> |
) |
414 |
|
{ |
415 |
< |
char vkey[VKLEN]; |
415 |
> |
static char vkey[VKLEN]; |
416 |
|
register LUENT *lp; |
417 |
|
register int i, vndx; |
418 |
|
|
419 |
< |
clock++; /* increment counter */ |
419 |
> |
vclock++; /* increment counter */ |
420 |
|
mkvkey(vkey, vp); |
421 |
|
if ((lp = lu_find(&vertab, vkey)) == NULL) |
422 |
|
goto memerr; |
442 |
|
lp->data = (char *)&vert[vndx]; /* set it */ |
443 |
|
} else |
444 |
|
vndx = (struct vert *)lp->data - vert; |
445 |
< |
vert[vndx].lused = clock; /* record this use */ |
445 |
> |
vert[vndx].lused = vclock; /* record this use */ |
446 |
|
sprintf(vname, "v%d", vndx); |
447 |
|
return(vname); |
448 |
|
memerr: |
452 |
|
|
453 |
|
|
454 |
|
int |
455 |
< |
o_face(mod, typ, id, fa) /* print out a polygon */ |
456 |
< |
char *mod, *typ, *id; |
457 |
< |
FUNARGS *fa; |
455 |
> |
o_unsupported( /* mark unsupported primitive */ |
456 |
> |
char *mod, |
457 |
> |
char *typ, |
458 |
> |
char *id, |
459 |
> |
FUNARGS *fa |
460 |
> |
) |
461 |
|
{ |
462 |
< |
char entbuf[512]; |
462 |
> |
register int i; |
463 |
> |
|
464 |
> |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
465 |
> |
printf("# %s %s %s", mod, typ, id); |
466 |
> |
printf("\n# %d", fa->nsargs); |
467 |
> |
for (i = 0; i < fa->nsargs; i++) |
468 |
> |
printf(" %s", fa->sarg[i]); |
469 |
> |
#ifdef IARGS |
470 |
> |
printf("\n# %d", fa->niargs); |
471 |
> |
for (i = 0; i < fa->niargs; i++) |
472 |
> |
printf(" %ld", fa->iarg[i]); |
473 |
> |
#else |
474 |
> |
fputs("\n# 0", stdout); |
475 |
> |
#endif |
476 |
> |
printf("\n# %d", fa->nfargs); |
477 |
> |
for (i = 0; i < fa->nfargs; i++) |
478 |
> |
printf(" %g", fa->farg[i]); |
479 |
> |
fputs("\n\n", stdout); |
480 |
> |
return(0); |
481 |
> |
} |
482 |
> |
|
483 |
> |
|
484 |
> |
int |
485 |
> |
o_face( /* print out a polygon */ |
486 |
> |
char *mod, |
487 |
> |
char *typ, |
488 |
> |
char *id, |
489 |
> |
FUNARGS *fa |
490 |
> |
) |
491 |
> |
{ |
492 |
> |
char entbuf[2048], *linestart; |
493 |
|
register char *cp; |
494 |
|
register int i; |
495 |
|
|
496 |
< |
if (fa->nfargs < 9 | fa->nfargs % 3) |
496 |
> |
if ((fa->nfargs < 9) | (fa->nfargs % 3)) |
497 |
|
return(-1); |
498 |
|
setmat(mod); |
499 |
|
setobj(id); |
500 |
< |
cp = entbuf; |
500 |
> |
cp = linestart = entbuf; |
501 |
|
*cp++ = 'f'; |
502 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
503 |
|
*cp++ = ' '; |
504 |
+ |
if (cp - linestart > 72) { |
505 |
+ |
*cp++ = '\\'; *cp++ = '\n'; |
506 |
+ |
linestart = cp; |
507 |
+ |
*cp++ = ' '; *cp++ = ' '; |
508 |
+ |
} |
509 |
|
getvertid(cp, fa->farg + i); |
510 |
|
while (*cp) |
511 |
|
cp++; |
516 |
|
|
517 |
|
|
518 |
|
int |
519 |
< |
o_cone(mod, typ, id, fa) /* print out a cone */ |
520 |
< |
char *mod, *typ, *id; |
521 |
< |
register FUNARGS *fa; |
519 |
> |
o_cone( /* print out a cone */ |
520 |
> |
char *mod, |
521 |
> |
char *typ, |
522 |
> |
char *id, |
523 |
> |
register FUNARGS *fa |
524 |
> |
) |
525 |
|
{ |
526 |
|
char v1[6], v2[6]; |
527 |
|
|
542 |
|
|
543 |
|
|
544 |
|
int |
545 |
< |
o_sphere(mod, typ, id, fa) /* print out a sphere */ |
546 |
< |
char *mod, *typ, *id; |
547 |
< |
register FUNARGS *fa; |
545 |
> |
o_sphere( /* print out a sphere */ |
546 |
> |
char *mod, |
547 |
> |
char *typ, |
548 |
> |
char *id, |
549 |
> |
register FUNARGS *fa |
550 |
> |
) |
551 |
|
{ |
552 |
|
char cent[6]; |
553 |
|
|
562 |
|
|
563 |
|
|
564 |
|
int |
565 |
< |
o_cylinder(mod, typ, id, fa) /* print out a cylinder */ |
566 |
< |
char *mod, *typ, *id; |
567 |
< |
register FUNARGS *fa; |
565 |
> |
o_cylinder( /* print out a cylinder */ |
566 |
> |
char *mod, |
567 |
> |
char *typ, |
568 |
> |
char *id, |
569 |
> |
register FUNARGS *fa |
570 |
> |
) |
571 |
|
{ |
572 |
|
char v1[6], v2[6]; |
573 |
|
|
584 |
|
|
585 |
|
|
586 |
|
int |
587 |
< |
o_ring(mod, typ, id, fa) /* print out a ring */ |
588 |
< |
char *mod, *typ, *id; |
589 |
< |
register FUNARGS *fa; |
587 |
> |
o_ring( /* print out a ring */ |
588 |
> |
char *mod, |
589 |
> |
char *typ, |
590 |
> |
char *id, |
591 |
> |
register FUNARGS *fa |
592 |
> |
) |
593 |
|
{ |
594 |
|
if (fa->nfargs != 8) |
595 |
|
return(-1); |
610 |
|
|
611 |
|
|
612 |
|
int |
613 |
< |
o_instance(mod, typ, id, fa) /* convert an instance */ |
614 |
< |
char *mod, *typ, *id; |
615 |
< |
FUNARGS *fa; |
613 |
> |
o_instance( /* convert an instance (or mesh) */ |
614 |
> |
char *mod, |
615 |
> |
char *typ, |
616 |
> |
char *id, |
617 |
> |
FUNARGS *fa |
618 |
> |
) |
619 |
|
{ |
620 |
|
register int i; |
621 |
|
register char *cp; |
654 |
|
|
655 |
|
|
656 |
|
int |
657 |
< |
o_source(mod, typ, id, fa) /* convert a source */ |
658 |
< |
char *mod, *typ, *id; |
659 |
< |
FUNARGS *fa; |
657 |
> |
o_illum( /* convert an illum material */ |
658 |
> |
char *mod, |
659 |
> |
char *typ, |
660 |
> |
char *id, |
661 |
> |
FUNARGS *fa |
662 |
> |
) |
663 |
|
{ |
537 |
– |
return(0); /* there is no MGF equivalent! */ |
538 |
– |
} |
539 |
– |
|
540 |
– |
|
541 |
– |
int |
542 |
– |
o_illum(mod, typ, id, fa) /* convert an illum material */ |
543 |
– |
char *mod, *typ, *id; |
544 |
– |
FUNARGS *fa; |
545 |
– |
{ |
664 |
|
if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) { |
665 |
|
newmat(id, fa->sarg[0]); /* just create alias */ |
666 |
|
return(0); |
673 |
|
|
674 |
|
|
675 |
|
int |
676 |
< |
o_plastic(mod, typ, id, fa) /* convert a plastic material */ |
677 |
< |
char *mod, *typ, *id; |
678 |
< |
register FUNARGS *fa; |
676 |
> |
o_plastic( /* convert a plastic material */ |
677 |
> |
char *mod, |
678 |
> |
char *typ, |
679 |
> |
char *id, |
680 |
> |
register FUNARGS *fa |
681 |
> |
) |
682 |
|
{ |
683 |
|
COLOR cxyz, rrgb; |
684 |
|
double d; |
691 |
|
puts("\tc"); /* put diffuse component */ |
692 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
693 |
|
if (d > FTINY) |
694 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
695 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
694 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
695 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
696 |
|
if (fa->farg[3] > FTINY) { /* put specular component */ |
697 |
|
puts("\tc"); |
698 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], |
698 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], |
699 |
|
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
700 |
|
fa->farg[4]); |
701 |
|
} |
704 |
|
|
705 |
|
|
706 |
|
int |
707 |
< |
o_metal(mod, typ, id, fa) /* convert a metal material */ |
708 |
< |
char *mod, *typ, *id; |
709 |
< |
register FUNARGS *fa; |
707 |
> |
o_metal( /* convert a metal material */ |
708 |
> |
char *mod, |
709 |
> |
char *typ, |
710 |
> |
char *id, |
711 |
> |
register FUNARGS *fa |
712 |
> |
) |
713 |
|
{ |
714 |
|
COLOR cxyz, rrgb; |
715 |
|
double d; |
722 |
|
puts("\tc"); /* put diffuse component */ |
723 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
724 |
|
if (d > FTINY) |
725 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
726 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
725 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
726 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
727 |
|
/* put specular component */ |
728 |
< |
printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
728 |
> |
printf("\trs %.6f %.6f\n", cxyz[1]*fa->farg[3], |
729 |
|
typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
730 |
|
fa->farg[4]); |
731 |
|
return(0); |
733 |
|
|
734 |
|
|
735 |
|
int |
736 |
< |
o_glass(mod, typ, id, fa) /* convert a glass material */ |
737 |
< |
char *mod, *typ, *id; |
738 |
< |
register FUNARGS *fa; |
736 |
> |
o_glass( /* convert a glass material */ |
737 |
> |
char *mod, |
738 |
> |
char *typ, |
739 |
> |
char *id, |
740 |
> |
register FUNARGS *fa |
741 |
> |
) |
742 |
|
{ |
743 |
|
COLOR cxyz, rrgb, trgb; |
744 |
|
double nrfr = 1.52, F, d; |
749 |
|
newmat(id, NULL); |
750 |
|
if (fa->nfargs == 4) |
751 |
|
nrfr = fa->farg[3]; |
752 |
+ |
printf("\tir %f 0\n", nrfr); |
753 |
|
F = (1. - nrfr)/(1. + nrfr); /* use normal incidence */ |
754 |
|
F *= F; |
755 |
|
for (i = 0; i < 3; i++) { |
762 |
|
puts("\tc"); |
763 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
764 |
|
if (d > FTINY) |
765 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
766 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
765 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
766 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
767 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
768 |
|
puts("\tc"); |
769 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
770 |
|
if (d > FTINY) |
771 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
772 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
771 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
772 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
773 |
|
return(0); |
774 |
|
} |
775 |
|
|
776 |
|
|
777 |
|
int |
778 |
< |
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
779 |
< |
char *mod, *typ, *id; |
780 |
< |
register FUNARGS *fa; |
778 |
> |
o_dielectric( /* convert a dielectric material */ |
779 |
> |
char *mod, |
780 |
> |
char *typ, |
781 |
> |
char *id, |
782 |
> |
register FUNARGS *fa |
783 |
> |
) |
784 |
|
{ |
785 |
+ |
COLOR cxyz, trgb; |
786 |
+ |
double F, d; |
787 |
+ |
register int i; |
788 |
+ |
|
789 |
+ |
if (fa->nfargs != 5) |
790 |
+ |
return(-1); |
791 |
+ |
newmat(id, NULL); |
792 |
+ |
F = (1. - fa->farg[3])/(1. + fa->farg[3]); /* normal incidence */ |
793 |
+ |
F *= F; |
794 |
+ |
for (i = 0; i < 3; i++) |
795 |
+ |
trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult); |
796 |
+ |
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
797 |
+ |
printf("\tsides 1\n"); |
798 |
+ |
puts("\tc"); /* put reflected component */ |
799 |
+ |
printf("\trs %.6f 0\n", F); |
800 |
+ |
rgb_cie(cxyz, trgb); /* put transmitted component */ |
801 |
+ |
puts("\tc"); |
802 |
+ |
d = cxyz[0] + cxyz[1] + cxyz[2]; |
803 |
+ |
if (d > FTINY) |
804 |
+ |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
805 |
+ |
printf("\tts %.6f 0\n", cxyz[1]); |
806 |
+ |
return(0); |
807 |
+ |
} |
808 |
+ |
|
809 |
+ |
|
810 |
+ |
int |
811 |
+ |
o_mirror( /* convert a mirror material */ |
812 |
+ |
char *mod, |
813 |
+ |
char *typ, |
814 |
+ |
char *id, |
815 |
+ |
register FUNARGS *fa |
816 |
+ |
) |
817 |
+ |
{ |
818 |
|
COLOR cxyz, rrgb; |
819 |
|
double d; |
820 |
|
|
830 |
|
puts("\tc"); /* put specular component */ |
831 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
832 |
|
if (d > FTINY) |
833 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
834 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
833 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
834 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
835 |
|
return(0); |
836 |
|
} |
837 |
|
|
838 |
|
|
839 |
|
int |
840 |
< |
o_trans(mod, typ, id, fa) /* convert a trans material */ |
841 |
< |
char *mod, *typ, *id; |
842 |
< |
register FUNARGS *fa; |
840 |
> |
o_trans( /* convert a trans material */ |
841 |
> |
char *mod, |
842 |
> |
char *typ, |
843 |
> |
char *id, |
844 |
> |
register FUNARGS *fa |
845 |
> |
) |
846 |
|
{ |
847 |
|
COLOR cxyz, rrgb; |
848 |
|
double rough, trans, tspec, d; |
849 |
|
|
850 |
< |
if (typ[4] == '2') { /* trans2 */ |
850 |
> |
if (typ[5] == '2') { /* trans2 */ |
851 |
|
if (fa->nfargs != 8) |
852 |
|
return(-1); |
853 |
|
rough = .5*(fa->farg[4] + fa->farg[5]); |
866 |
|
puts("\tc"); /* put transmitted diffuse */ |
867 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
868 |
|
if (d > FTINY) |
869 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
870 |
< |
printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
869 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
870 |
> |
printf("\ttd %.6f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
871 |
|
/* put transmitted specular */ |
872 |
< |
printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
872 |
> |
printf("\tts %.6f %.6f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
873 |
|
/* put reflected diffuse */ |
874 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
874 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
875 |
|
puts("\tc"); /* put reflected specular */ |
876 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], rough); |
876 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], rough); |
877 |
|
return(0); |
878 |
|
} |
879 |
|
|
880 |
|
|
881 |
|
int |
882 |
< |
o_light(mod, typ, id, fa) /* convert a light type */ |
883 |
< |
char *mod, *typ, *id; |
884 |
< |
register FUNARGS *fa; |
882 |
> |
o_light( /* convert a light type */ |
883 |
> |
char *mod, |
884 |
> |
char *typ, |
885 |
> |
char *id, |
886 |
> |
register FUNARGS *fa |
887 |
> |
) |
888 |
|
{ |
889 |
|
COLOR cxyz, rrgb; |
890 |
|
double d; |
897 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
898 |
|
puts("\tc"); |
899 |
|
if (d > FTINY) |
900 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
901 |
< |
printf("\ted %.4g\n", cxyz[1]*WHTEFFICACY); |
900 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
901 |
> |
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
902 |
|
return(0); |
903 |
|
} |