17 |
|
|
18 |
|
#define putv(v) printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2]) |
19 |
|
|
20 |
+ |
#define invert (xf_context != NULL && xf_context->rev) |
21 |
+ |
|
22 |
|
double glowdist = FHUGE; /* glow test distance */ |
23 |
|
|
24 |
< |
double emult = 1.; /* emmitter multiplier */ |
24 |
> |
double emult = 1.; /* emitter multiplier */ |
25 |
|
|
26 |
+ |
FILE *matfp = stdout; /* material output file */ |
27 |
+ |
|
28 |
|
int r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); |
29 |
|
char *material(), *object(), *addarg(); |
30 |
|
|
41 |
|
mg_ehand[MG_E_CMIX] = c_hcolor; |
42 |
|
mg_ehand[MG_E_CSPEC] = c_hcolor; |
43 |
|
mg_ehand[MG_E_CXY] = c_hcolor; |
44 |
+ |
mg_ehand[MG_E_CCT] = c_hcolor; |
45 |
|
mg_ehand[MG_E_CYL] = r_cyl; |
46 |
|
mg_ehand[MG_E_ED] = c_hmaterial; |
47 |
|
mg_ehand[MG_E_FACE] = r_face; |
48 |
|
mg_ehand[MG_E_IES] = r_ies; |
49 |
+ |
mg_ehand[MG_E_IR] = c_hmaterial; |
50 |
|
mg_ehand[MG_E_MATERIAL] = c_hmaterial; |
51 |
|
mg_ehand[MG_E_NORMAL] = c_hvertex; |
52 |
|
mg_ehand[MG_E_OBJECT] = obj_handler; |
54 |
|
mg_ehand[MG_E_RD] = c_hmaterial; |
55 |
|
mg_ehand[MG_E_RING] = r_ring; |
56 |
|
mg_ehand[MG_E_RS] = c_hmaterial; |
57 |
+ |
mg_ehand[MG_E_SIDES] = c_hmaterial; |
58 |
|
mg_ehand[MG_E_SPH] = r_sph; |
59 |
|
mg_ehand[MG_E_TD] = c_hmaterial; |
60 |
|
mg_ehand[MG_E_TS] = c_hmaterial; |
67 |
|
printf(" %s", argv[i]); |
68 |
|
switch (argv[i][1]) { |
69 |
|
case 'g': /* glow distance (meters) */ |
70 |
< |
if (argv[i][2] || badarg(argc-i, argv+i, "f")) |
70 |
> |
if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f")) |
71 |
|
goto userr; |
72 |
|
glowdist = atof(argv[++i]); |
73 |
|
printf(" %s", argv[i]); |
74 |
|
break; |
75 |
|
case 'e': /* emitter multiplier */ |
76 |
< |
if (argv[i][2] || badarg(argc-i, argv+i, "f")) |
76 |
> |
if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f")) |
77 |
|
goto userr; |
78 |
|
emult = atof(argv[++i]); |
79 |
|
printf(" %s", argv[i]); |
80 |
|
break; |
81 |
+ |
case 'm': /* materials file */ |
82 |
+ |
matfp = fopen(argv[++i], "a"); |
83 |
+ |
if (matfp == NULL) { |
84 |
+ |
fprintf(stderr, "%s: cannot append\n", argv[i]); |
85 |
+ |
exit(1); |
86 |
+ |
} |
87 |
+ |
printf(" %s", argv[i]); |
88 |
+ |
break; |
89 |
|
default: |
90 |
|
goto userr; |
91 |
|
} |
103 |
|
} |
104 |
|
exit(0); |
105 |
|
userr: |
106 |
< |
fprintf(stderr, "Usage: %s [-g dist][-m mult] [file.mgf] ..\n", |
106 |
> |
fprintf(stderr, "Usage: %s [-g dist][-e mult][-m matf] [file.mgf] ..\n", |
107 |
|
argv[0]); |
108 |
|
exit(1); |
109 |
|
} |
114 |
|
register int ac; |
115 |
|
register char **av; |
116 |
|
{ |
117 |
< |
fputs("\n#", stdout); /* use Radiance comment character */ |
117 |
> |
putchar('#'); /* use Radiance comment character */ |
118 |
|
while (--ac) { |
119 |
|
putchar(' '); |
120 |
|
fputs(*++av, stdout); |
307 |
|
printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces); |
308 |
|
printf("0\n0\n%d\n", 3*(ac-1)); |
309 |
|
for (i = 1; i < ac; i++) { |
310 |
< |
if ((cv = c_getvert(av[i])) == NULL) |
310 |
> |
if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL) |
311 |
|
return(MG_EUNDEF); |
312 |
|
xf_xfmpoint(v, cv->p); |
313 |
|
putv(v); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
+ |
int |
320 |
|
r_ies(ac, av) /* convert an IES luminaire file */ |
321 |
|
int ac; |
322 |
|
char **av; |
323 |
|
{ |
324 |
|
int xa0 = 2; |
325 |
< |
char combuf[72]; |
325 |
> |
char combuf[128]; |
326 |
|
char fname[48]; |
327 |
|
char *oname; |
328 |
|
register char *op; |
331 |
|
if (ac < 2) |
332 |
|
return(MG_EARGC); |
333 |
|
(void)strcpy(combuf, "ies2rad"); |
334 |
< |
op = combuf + 7; |
334 |
> |
op = combuf + 7; /* get -m option (must be first) */ |
335 |
|
if (ac-xa0 >= 2 && !strcmp(av[xa0], "-m")) { |
336 |
|
if (!isflt(av[xa0+1])) |
337 |
|
return(MG_ETYPE); |
338 |
|
op = addarg(addarg(op, "-m"), av[xa0+1]); |
339 |
|
xa0 += 2; |
340 |
|
} |
341 |
< |
if (access(av[1], 0) == -1) |
341 |
> |
*op++ = ' '; /* build IES filename */ |
342 |
> |
i = 0; |
343 |
> |
if (mg_file != NULL && |
344 |
> |
(oname = strrchr(mg_file->fname, '/')) != NULL) { |
345 |
> |
i = oname - mg_file->fname + 1; |
346 |
> |
(void)strcpy(op, mg_file->fname); |
347 |
> |
} |
348 |
> |
(void)strcpy(op+i, av[1]); |
349 |
> |
if (access(op, 0) == -1) |
350 |
|
return(MG_ENOFILE); |
327 |
– |
*op++ = ' '; /* IES filename goes last */ |
328 |
– |
(void)strcpy(op, av[1]); |
351 |
|
system(combuf); /* run ies2rad */ |
352 |
|
/* now let's find the output file */ |
353 |
|
if ((op = strrchr(av[1], '/')) == NULL) |
388 |
|
FVECT n1, n2, n3; |
389 |
|
register int i; |
390 |
|
/* the following is repeat code, so assume it's OK */ |
369 |
– |
cv1 = c_getvert(vn1); |
391 |
|
cv2 = c_getvert(vn2); |
392 |
< |
cv3 = c_getvert(vn3); |
392 |
> |
if (invert) { |
393 |
> |
cv3 = c_getvert(vn1); |
394 |
> |
cv1 = c_getvert(vn3); |
395 |
> |
} else { |
396 |
> |
cv1 = c_getvert(vn1); |
397 |
> |
cv3 = c_getvert(vn3); |
398 |
> |
} |
399 |
|
xf_xfmpoint(v1, cv1->p); |
400 |
|
xf_xfmpoint(v2, cv2->p); |
401 |
|
xf_xfmpoint(v3, cv3->p); |
436 |
|
c_cmaterial->clock = 0; |
437 |
|
if (c_cmaterial->ed > .1) { /* emitter */ |
438 |
|
cvtcolor(radrgb, &c_cmaterial->ed_c, |
439 |
< |
emult*c_cmaterial->ed/WHTEFFICACY); |
439 |
> |
emult*c_cmaterial->ed/(PI*WHTEFFICACY)); |
440 |
|
if (glowdist < FHUGE) { /* do a glow */ |
441 |
< |
printf("\nvoid glow %s\n0\n0\n", mname); |
442 |
< |
printf("4 %f %f %f %f\n", colval(radrgb,RED), |
441 |
> |
fprintf(matfp, "\nvoid glow %s\n0\n0\n", mname); |
442 |
> |
fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED), |
443 |
|
colval(radrgb,GRN), |
444 |
|
colval(radrgb,BLU), glowdist); |
445 |
|
} else { |
446 |
< |
printf("\nvoid light %s\n0\n0\n", mname); |
447 |
< |
printf("3 %f %f %f\n", colval(radrgb,RED), |
446 |
> |
fprintf(matfp, "\nvoid light %s\n0\n0\n", mname); |
447 |
> |
fprintf(matfp, "3 %f %f %f\n", colval(radrgb,RED), |
448 |
|
colval(radrgb,GRN), |
449 |
|
colval(radrgb,BLU)); |
450 |
|
} |
452 |
|
} |
453 |
|
d = c_cmaterial->rd + c_cmaterial->td + |
454 |
|
c_cmaterial->rs + c_cmaterial->ts; |
455 |
< |
if (d <= 0. | d >= 1.) |
455 |
> |
if (d < 0. | d > 1.) |
456 |
|
return(NULL); |
457 |
+ |
/* check for glass/dielectric */ |
458 |
+ |
if (c_cmaterial->nr > 1.1 && |
459 |
+ |
c_cmaterial->ts > .25 && c_cmaterial->rs <= .125 && |
460 |
+ |
c_cmaterial->td <= .01 && c_cmaterial->rd <= .01 && |
461 |
+ |
c_cmaterial->rs_a <= .01 && c_cmaterial->ts_a <= .01) { |
462 |
+ |
cvtcolor(radrgb, &c_cmaterial->ts_c, |
463 |
+ |
c_cmaterial->ts + c_cmaterial->rs); |
464 |
+ |
if (c_cmaterial->sided) { /* dielectric */ |
465 |
+ |
colval(radrgb,RED) = pow(colval(radrgb,RED), |
466 |
+ |
1./C_1SIDEDTHICK); |
467 |
+ |
colval(radrgb,GRN) = pow(colval(radrgb,GRN), |
468 |
+ |
1./C_1SIDEDTHICK); |
469 |
+ |
colval(radrgb,BLU) = pow(colval(radrgb,BLU), |
470 |
+ |
1./C_1SIDEDTHICK); |
471 |
+ |
fprintf(matfp, "\nvoid dielectric %s\n0\n0\n", mname); |
472 |
+ |
fprintf(matfp, "5 %g %g %g %f 0\n", colval(radrgb,RED), |
473 |
+ |
colval(radrgb,GRN), colval(radrgb,BLU), |
474 |
+ |
c_cmaterial->nr); |
475 |
+ |
return(mname); |
476 |
+ |
} |
477 |
+ |
/* glass */ |
478 |
+ |
fprintf(matfp, "\nvoid glass %s\n0\n0\n", mname); |
479 |
+ |
fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED), |
480 |
+ |
colval(radrgb,GRN), colval(radrgb,BLU), |
481 |
+ |
c_cmaterial->nr); |
482 |
+ |
return(mname); |
483 |
+ |
} |
484 |
|
/* check for trans */ |
485 |
|
if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) { |
486 |
|
double ts, a5, a6; |
487 |
|
|
488 |
< |
ts = sqrt(c_cmaterial->ts); /* because we use 2 sides */ |
488 |
> |
if (c_cmaterial->sided) { |
489 |
> |
ts = sqrt(c_cmaterial->ts); /* approximate */ |
490 |
> |
a5 = .5; |
491 |
> |
} else { |
492 |
> |
ts = c_cmaterial->ts; |
493 |
> |
a5 = 1.; |
494 |
> |
} |
495 |
|
/* average colors */ |
496 |
|
d = c_cmaterial->rd + c_cmaterial->td + ts; |
497 |
|
cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); |
501 |
|
addcolor(radrgb, c2); |
502 |
|
if (c_cmaterial->rs + ts > .0001) |
503 |
|
a5 = (c_cmaterial->rs*c_cmaterial->rs_a + |
504 |
< |
ts*.5*c_cmaterial->ts_a) / |
504 |
> |
ts*a5*c_cmaterial->ts_a) / |
505 |
|
(c_cmaterial->rs + ts); |
506 |
|
a6 = (c_cmaterial->td + ts) / |
507 |
|
(c_cmaterial->rd + c_cmaterial->td + ts); |
508 |
< |
if (a6 < .999) { |
508 |
> |
if (a6 < .999) |
509 |
|
d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6); |
510 |
< |
scalecolor(radrgb, d); |
511 |
< |
} |
512 |
< |
printf("\nvoid trans %s\n0\n0\n", mname); |
513 |
< |
printf("7 %f %f %f\n", colval(radrgb,RED), |
510 |
> |
else |
511 |
> |
d = c_cmaterial->td + ts; |
512 |
> |
scalecolor(radrgb, d); |
513 |
> |
fprintf(matfp, "\nvoid trans %s\n0\n0\n", mname); |
514 |
> |
fprintf(matfp, "7 %f %f %f\n", colval(radrgb,RED), |
515 |
|
colval(radrgb,GRN), colval(radrgb,BLU)); |
516 |
< |
printf("\t%f %f %f %f\n", c_cmaterial->rs, a5, a6, |
516 |
> |
fprintf(matfp, "\t%f %f %f %f\n", c_cmaterial->rs, a5, a6, |
517 |
|
ts/(ts + c_cmaterial->td)); |
518 |
|
return(mname); |
519 |
|
} |
520 |
|
/* check for plastic */ |
521 |
< |
if (c_cmaterial->rs < .01 || c_isgrey(&c_cmaterial->rs_c)) { |
522 |
< |
if (c_cmaterial->rs > .999) |
523 |
< |
cvtcolor(radrgb, &c_cmaterial->rd_c, 1.); |
463 |
< |
else |
464 |
< |
cvtcolor(radrgb, &c_cmaterial->rd_c, |
521 |
> |
if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 || |
522 |
> |
c_isgrey(&c_cmaterial->rs_c))) { |
523 |
> |
cvtcolor(radrgb, &c_cmaterial->rd_c, |
524 |
|
c_cmaterial->rd/(1.-c_cmaterial->rs)); |
525 |
< |
printf("\nvoid plastic %s\n0\n0\n", mname); |
526 |
< |
printf("5 %f %f %f %f %f\n", colval(radrgb,RED), |
525 |
> |
fprintf(matfp, "\nvoid plastic %s\n0\n0\n", mname); |
526 |
> |
fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED), |
527 |
|
colval(radrgb,GRN), colval(radrgb,BLU), |
528 |
|
c_cmaterial->rs, c_cmaterial->rs_a); |
529 |
|
return(mname); |
530 |
|
} |
531 |
|
/* else it's metal */ |
532 |
< |
d = c_cmaterial->rd + c_cmaterial->rs; /* average colors */ |
533 |
< |
cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); |
534 |
< |
cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d); |
532 |
> |
/* average colors */ |
533 |
> |
cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd); |
534 |
> |
cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs); |
535 |
|
addcolor(radrgb, c2); |
536 |
< |
if (c_cmaterial->rs < .999) { |
537 |
< |
d = c_cmaterial->rd/(1. - c_cmaterial->rs); |
479 |
< |
scalecolor(radrgb, d); |
480 |
< |
} |
481 |
< |
printf("\nvoid metal %s\n0\n0\n", mname); |
482 |
< |
printf("5 %f %f %f %f %f\n", colval(radrgb,RED), |
536 |
> |
fprintf(matfp, "\nvoid metal %s\n0\n0\n", mname); |
537 |
> |
fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED), |
538 |
|
colval(radrgb,GRN), colval(radrgb,BLU), |
539 |
< |
c_cmaterial->rs, c_cmaterial->rs_a); |
539 |
> |
c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs), |
540 |
> |
c_cmaterial->rs_a); |
541 |
|
return(mname); |
542 |
|
} |
543 |
|
|