--- ray/src/cv/mgf2rad.c 1994/06/24 17:16:51 2.3 +++ ray/src/cv/mgf2rad.c 1994/07/21 15:04:23 2.9 @@ -17,9 +17,11 @@ static char SCCSid[] = "$SunId$ LBL"; #define putv(v) printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2]) +#define invert (xf_context != NULL && xf_context->rev) + double glowdist = FHUGE; /* glow test distance */ -double emult = 1.; /* emmitter multiplier */ +double emult = 1.; /* emitter multiplier */ int r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); char *material(), *object(), *addarg(); @@ -34,6 +36,8 @@ char *argv[]; mg_ehand[MG_E_COMMENT] = r_comment; mg_ehand[MG_E_COLOR] = c_hcolor; mg_ehand[MG_E_CONE] = r_cone; + mg_ehand[MG_E_CMIX] = c_hcolor; + mg_ehand[MG_E_CSPEC] = c_hcolor; mg_ehand[MG_E_CXY] = c_hcolor; mg_ehand[MG_E_CYL] = r_cyl; mg_ehand[MG_E_ED] = c_hmaterial; @@ -46,6 +50,7 @@ char *argv[]; mg_ehand[MG_E_RD] = c_hmaterial; mg_ehand[MG_E_RING] = r_ring; mg_ehand[MG_E_RS] = c_hmaterial; + mg_ehand[MG_E_SIDES] = c_hmaterial; mg_ehand[MG_E_SPH] = r_sph; mg_ehand[MG_E_TD] = c_hmaterial; mg_ehand[MG_E_TS] = c_hmaterial; @@ -97,7 +102,7 @@ r_comment(ac, av) /* repeat a comment verbatim */ register int ac; register char **av; { - fputs("\n#", stdout); /* use Radiance comment character */ + putchar('#'); /* use Radiance comment character */ while (--ac) { putchar(' '); fputs(*++av, stdout); @@ -290,7 +295,7 @@ char **av; printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces); printf("0\n0\n%d\n", 3*(ac-1)); for (i = 1; i < ac; i++) { - if ((cv = c_getvert(av[i])) == NULL) + if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL) return(MG_EUNDEF); xf_xfmpoint(v, cv->p); putv(v); @@ -337,8 +342,11 @@ char **av; /* put out xform command */ printf("\n!xform"); oname = object(); - if (*oname) - printf(" -n %s", oname); + if (*oname) { + printf(" -n "); + for (op = oname; op[1]; op++) /* remove trailing separator */ + putchar(*op); + } for (i = xa0; i < ac; i++) printf(" %s", av[i]); if (ac > xa0 && xf_argc > 0) @@ -361,9 +369,14 @@ char *mat, *vn1, *vn2, *vn3; FVECT n1, n2, n3; register int i; /* the following is repeat code, so assume it's OK */ - cv1 = c_getvert(vn1); cv2 = c_getvert(vn2); - cv3 = c_getvert(vn3); + if (invert) { + cv3 = c_getvert(vn1); + cv1 = c_getvert(vn3); + } else { + cv1 = c_getvert(vn1); + cv3 = c_getvert(vn3); + } xf_xfmpoint(v1, cv1->p); xf_xfmpoint(v2, cv2->p); xf_xfmpoint(v3, cv3->p); @@ -396,8 +409,8 @@ material() /* get (and print) current material */ double d; register int i; - if (c_cmaterial->name != NULL) - mname = c_cmaterial->name; + if (c_cmname != NULL) + mname = c_cmname; if (!c_cmaterial->clock) return(mname); /* already current */ /* else update output */ @@ -420,13 +433,19 @@ material() /* get (and print) current material */ } d = c_cmaterial->rd + c_cmaterial->td + c_cmaterial->rs + c_cmaterial->ts; - if (d <= 0. | d >= 1.) + if (d < 0. | d > 1.) return(NULL); /* check for trans */ if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) { double ts, a5, a6; - ts = sqrt(c_cmaterial->ts); /* because we use 2 sides */ + if (c_cmaterial->sided) { + ts = sqrt(c_cmaterial->ts); /* approximate */ + a5 = .5; + } else { + ts = c_cmaterial->ts; + a5 = 1.; + } /* average colors */ d = c_cmaterial->rd + c_cmaterial->td + ts; cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); @@ -436,14 +455,15 @@ material() /* get (and print) current material */ addcolor(radrgb, c2); if (c_cmaterial->rs + ts > .0001) a5 = (c_cmaterial->rs*c_cmaterial->rs_a + - ts*.5*c_cmaterial->ts_a) / + ts*a5*c_cmaterial->ts_a) / (c_cmaterial->rs + ts); a6 = (c_cmaterial->td + ts) / (c_cmaterial->rd + c_cmaterial->td + ts); - if (a6 < .999) { + if (a6 < .999) d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6); - scalecolor(radrgb, d); - } + else + d = c_cmaterial->td + ts; + scalecolor(radrgb, d); printf("\nvoid trans %s\n0\n0\n", mname); printf("7 %f %f %f\n", colval(radrgb,RED), colval(radrgb,GRN), colval(radrgb,BLU)); @@ -452,11 +472,9 @@ material() /* get (and print) current material */ return(mname); } /* check for plastic */ - if (c_cmaterial->rs < .01 || c_isgrey(&c_cmaterial->rs_c)) { - if (c_cmaterial->rs > .999) - cvtcolor(radrgb, &c_cmaterial->rd_c, 1.); - else - cvtcolor(radrgb, &c_cmaterial->rd_c, + if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 || + c_isgrey(&c_cmaterial->rs_c))) { + cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/(1.-c_cmaterial->rs)); printf("\nvoid plastic %s\n0\n0\n", mname); printf("5 %f %f %f %f %f\n", colval(radrgb,RED), @@ -465,18 +483,15 @@ material() /* get (and print) current material */ return(mname); } /* else it's metal */ - d = c_cmaterial->rd + c_cmaterial->rs; /* average colors */ - cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d); - cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d); + /* average colors */ + cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd); + cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs); addcolor(radrgb, c2); - if (c_cmaterial->rs < .999) { - d = c_cmaterial->rd/(1. - c_cmaterial->rs); - scalecolor(radrgb, d); - } printf("\nvoid metal %s\n0\n0\n", mname); printf("5 %f %f %f %f %f\n", colval(radrgb,RED), colval(radrgb,GRN), colval(radrgb,BLU), - c_cmaterial->rs, c_cmaterial->rs_a); + c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs), + c_cmaterial->rs_a); return(mname); } @@ -488,6 +503,7 @@ double intensity; { static COLOR ciexyz; + c_ccvt(ciec, C_CSXY); /* get xy representation */ ciexyz[1] = intensity; ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1]; ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0];