1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
33 |
|
int argc; |
34 |
|
char *argv[]; |
35 |
|
{ |
36 |
< |
int i, rv; |
36 |
> |
int i; |
37 |
> |
/* print out parser version */ |
38 |
> |
printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); |
39 |
|
/* initialize dispatch table */ |
40 |
< |
mg_ehand[MG_E_COMMENT] = r_comment; |
41 |
< |
mg_ehand[MG_E_COLOR] = c_hcolor; |
42 |
< |
mg_ehand[MG_E_CONE] = r_cone; |
43 |
< |
mg_ehand[MG_E_CMIX] = c_hcolor; |
44 |
< |
mg_ehand[MG_E_CSPEC] = c_hcolor; |
45 |
< |
mg_ehand[MG_E_CXY] = c_hcolor; |
46 |
< |
mg_ehand[MG_E_CYL] = r_cyl; |
47 |
< |
mg_ehand[MG_E_ED] = c_hmaterial; |
48 |
< |
mg_ehand[MG_E_FACE] = r_face; |
49 |
< |
mg_ehand[MG_E_IES] = r_ies; |
50 |
< |
mg_ehand[MG_E_MATERIAL] = c_hmaterial; |
51 |
< |
mg_ehand[MG_E_NORMAL] = c_hvertex; |
52 |
< |
mg_ehand[MG_E_OBJECT] = obj_handler; |
53 |
< |
mg_ehand[MG_E_POINT] = c_hvertex; |
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; |
61 |
< |
mg_ehand[MG_E_VERTEX] = c_hvertex; |
62 |
< |
mg_ehand[MG_E_XF] = xf_handler; |
40 |
> |
mg_ehand[MG_E_COMMENT] = r_comment; /* we pass comments */ |
41 |
> |
mg_ehand[MG_E_COLOR] = c_hcolor; /* they get color */ |
42 |
> |
mg_ehand[MG_E_CONE] = r_cone; /* we do cones */ |
43 |
> |
mg_ehand[MG_E_CMIX] = c_hcolor; /* they mix colors */ |
44 |
> |
mg_ehand[MG_E_CSPEC] = c_hcolor; /* they get spectra */ |
45 |
> |
mg_ehand[MG_E_CXY] = c_hcolor; /* they get chromaticities */ |
46 |
> |
mg_ehand[MG_E_CCT] = c_hcolor; /* they get color temp's */ |
47 |
> |
mg_ehand[MG_E_CYL] = r_cyl; /* we do cylinders */ |
48 |
> |
mg_ehand[MG_E_ED] = c_hmaterial; /* they get emission */ |
49 |
> |
mg_ehand[MG_E_FACE] = r_face; /* we do faces */ |
50 |
> |
mg_ehand[MG_E_IES] = r_ies; /* we do IES files */ |
51 |
> |
mg_ehand[MG_E_IR] = c_hmaterial; /* they get refractive index */ |
52 |
> |
mg_ehand[MG_E_MATERIAL] = c_hmaterial; /* they get materials */ |
53 |
> |
mg_ehand[MG_E_NORMAL] = c_hvertex; /* they get normals */ |
54 |
> |
mg_ehand[MG_E_OBJECT] = obj_handler; /* they track object names */ |
55 |
> |
mg_ehand[MG_E_POINT] = c_hvertex; /* they get points */ |
56 |
> |
mg_ehand[MG_E_RD] = c_hmaterial; /* they get diffuse refl. */ |
57 |
> |
mg_ehand[MG_E_RING] = r_ring; /* we do rings */ |
58 |
> |
mg_ehand[MG_E_RS] = c_hmaterial; /* they get specular refl. */ |
59 |
> |
mg_ehand[MG_E_SIDES] = c_hmaterial; /* they get # sides */ |
60 |
> |
mg_ehand[MG_E_SPH] = r_sph; /* we do spheres */ |
61 |
> |
mg_ehand[MG_E_TD] = c_hmaterial; /* they get diffuse trans. */ |
62 |
> |
mg_ehand[MG_E_TS] = c_hmaterial; /* they get specular trans. */ |
63 |
> |
mg_ehand[MG_E_VERTEX] = c_hvertex; /* they get vertices */ |
64 |
> |
mg_ehand[MG_E_XF] = xf_handler; /* they track transforms */ |
65 |
|
mg_init(); /* initialize the parser */ |
66 |
< |
/* get options & print header */ |
66 |
> |
/* get our options & print header */ |
67 |
|
printf("## %s", argv[0]); |
68 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
69 |
|
printf(" %s", argv[i]); |
94 |
|
} |
95 |
|
putchar('\n'); |
96 |
|
if (i == argc) { /* convert stdin */ |
97 |
< |
if ((rv = mg_load(NULL)) != MG_OK) |
97 |
> |
if (mg_load(NULL) != MG_OK) |
98 |
|
exit(1); |
99 |
+ |
if (mg_nunknown) |
100 |
+ |
printf("## %s: %u unknown entities\n", |
101 |
+ |
argv[0], mg_nunknown); |
102 |
|
} else /* convert each file */ |
103 |
|
for ( ; i < argc; i++) { |
104 |
|
printf("## %s %s ##############################\n", |
105 |
|
argv[0], argv[i]); |
106 |
< |
if ((rv = mg_load(argv[i])) != MG_OK) |
106 |
> |
if (mg_load(argv[i]) != MG_OK) |
107 |
|
exit(1); |
108 |
+ |
if (mg_nunknown) { |
109 |
+ |
printf("## %s %s: %u unknown entities\n", |
110 |
+ |
argv[0], argv[i], mg_nunknown); |
111 |
+ |
mg_nunknown = 0; |
112 |
+ |
} |
113 |
|
} |
114 |
|
exit(0); |
115 |
|
userr: |
125 |
|
register char **av; |
126 |
|
{ |
127 |
|
putchar('#'); /* use Radiance comment character */ |
128 |
< |
while (--ac) { |
128 |
> |
while (--ac) { /* pass through verbatim */ |
129 |
|
putchar(' '); |
130 |
|
fputs(*++av, stdout); |
131 |
|
} |
145 |
|
C_VERTEX *cv1, *cv2; |
146 |
|
FVECT p1, p2; |
147 |
|
int inv; |
148 |
< |
|
148 |
> |
/* check argument count and type */ |
149 |
|
if (ac != 5) |
150 |
|
return(MG_EARGC); |
151 |
|
if (!isflt(av[2]) || !isflt(av[4])) |
152 |
|
return(MG_ETYPE); |
153 |
+ |
/* get the endpoint vertices */ |
154 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
155 |
|
(cv2 = c_getvert(av[3])) == NULL) |
156 |
|
return(MG_EUNDEF); |
157 |
< |
xf_xfmpoint(p1, cv1->p); |
157 |
> |
xf_xfmpoint(p1, cv1->p); /* transform endpoints */ |
158 |
|
xf_xfmpoint(p2, cv2->p); |
159 |
< |
r1 = xf_scale(atof(av[2])); |
159 |
> |
r1 = xf_scale(atof(av[2])); /* scale radii */ |
160 |
|
r2 = xf_scale(atof(av[4])); |
161 |
< |
inv = r1 < 0.; |
162 |
< |
if (r1 == 0.) { |
161 |
> |
inv = r1 < 0.; /* check for inverted cone */ |
162 |
> |
if (r1 == 0.) { /* check for illegal radii */ |
163 |
|
if (r2 == 0.) |
164 |
|
return(MG_EILL); |
165 |
|
inv = r2 < 0.; |
169 |
|
r1 = -r1; |
170 |
|
r2 = -r2; |
171 |
|
} |
172 |
< |
if ((mat = material()) == NULL) |
172 |
> |
if ((mat = material()) == NULL) /* get material */ |
173 |
|
return(MG_EBADMAT); |
174 |
+ |
/* spit the sucker out */ |
175 |
|
printf("\n%s %s %sc%d\n", mat, inv ? "cup" : "cone", |
176 |
|
object(), ++ncones); |
177 |
|
printf("0\n0\n8\n"); |
193 |
|
C_VERTEX *cv1, *cv2; |
194 |
|
FVECT p1, p2; |
195 |
|
int inv; |
196 |
< |
|
196 |
> |
/* check argument count and type */ |
197 |
|
if (ac != 4) |
198 |
|
return(MG_EARGC); |
199 |
|
if (!isflt(av[2])) |
200 |
|
return(MG_ETYPE); |
201 |
+ |
/* get the endpoint vertices */ |
202 |
|
if ((cv1 = c_getvert(av[1])) == NULL || |
203 |
|
(cv2 = c_getvert(av[3])) == NULL) |
204 |
|
return(MG_EUNDEF); |
205 |
< |
xf_xfmpoint(p1, cv1->p); |
205 |
> |
xf_xfmpoint(p1, cv1->p); /* transform endpoints */ |
206 |
|
xf_xfmpoint(p2, cv2->p); |
207 |
< |
rad = xf_scale(atof(av[2])); |
208 |
< |
if ((inv = rad < 0.)) |
207 |
> |
rad = xf_scale(atof(av[2])); /* scale radius */ |
208 |
> |
if ((inv = rad < 0.)) /* check for inverted cylinder */ |
209 |
|
rad = -rad; |
210 |
< |
if ((mat = material()) == NULL) |
210 |
> |
if ((mat = material()) == NULL) /* get material */ |
211 |
|
return(MG_EBADMAT); |
212 |
+ |
/* spit out the primitive */ |
213 |
|
printf("\n%s %s %scy%d\n", mat, inv ? "tube" : "cylinder", |
214 |
|
object(), ++ncyls); |
215 |
|
printf("0\n0\n7\n"); |
231 |
|
C_VERTEX *cv; |
232 |
|
FVECT cent; |
233 |
|
int inv; |
234 |
< |
|
234 |
> |
/* check argument count and type */ |
235 |
|
if (ac != 3) |
236 |
|
return(MG_EARGC); |
237 |
|
if (!isflt(av[2])) |
238 |
|
return(MG_ETYPE); |
239 |
< |
if ((cv = c_getvert(av[1])) == NULL) |
239 |
> |
if ((cv = c_getvert(av[1])) == NULL) /* get center vertex */ |
240 |
|
return(MG_EUNDEF); |
241 |
< |
xf_xfmpoint(cent, cv->p); |
242 |
< |
rad = xf_scale(atof(av[2])); |
243 |
< |
if ((inv = rad < 0.)) |
241 |
> |
xf_xfmpoint(cent, cv->p); /* transform center */ |
242 |
> |
rad = xf_scale(atof(av[2])); /* scale radius */ |
243 |
> |
if ((inv = rad < 0.)) /* check for inversion */ |
244 |
|
rad = -rad; |
245 |
< |
if ((mat = material()) == NULL) |
245 |
> |
if ((mat = material()) == NULL) /* get material */ |
246 |
|
return(MG_EBADMAT); |
247 |
+ |
/* spit out primitive */ |
248 |
|
printf("\n%s %s %ss%d\n", mat, inv ? "bubble" : "sphere", |
249 |
|
object(), ++nsphs); |
250 |
|
printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n", |
263 |
|
double r1, r2; |
264 |
|
C_VERTEX *cv; |
265 |
|
FVECT cent, norm; |
266 |
< |
|
266 |
> |
/* check argument count and type */ |
267 |
|
if (ac != 4) |
268 |
|
return(MG_EARGC); |
269 |
|
if (!isflt(av[2]) || !isflt(av[3])) |
270 |
|
return(MG_ETYPE); |
271 |
< |
if ((cv = c_getvert(av[1])) == NULL) |
271 |
> |
if ((cv = c_getvert(av[1])) == NULL) /* get center vertex */ |
272 |
|
return(MG_EUNDEF); |
273 |
< |
if (is0vect(cv->n)) |
273 |
> |
if (is0vect(cv->n)) /* make sure we have normal */ |
274 |
|
return(MG_EILL); |
275 |
< |
xf_xfmpoint(cent, cv->p); |
276 |
< |
xf_rotvect(norm, cv->n); |
277 |
< |
r1 = xf_scale(atof(av[2])); |
275 |
> |
xf_xfmpoint(cent, cv->p); /* transform center */ |
276 |
> |
xf_rotvect(norm, cv->n); /* rotate normal */ |
277 |
> |
r1 = xf_scale(atof(av[2])); /* scale radii */ |
278 |
|
r2 = xf_scale(atof(av[3])); |
279 |
|
if (r1 < 0. | r2 <= r1) |
280 |
|
return(MG_EILL); |
281 |
< |
if ((mat = material()) == NULL) |
281 |
> |
if ((mat = material()) == NULL) /* get material */ |
282 |
|
return(MG_EBADMAT); |
283 |
+ |
/* spit out primitive */ |
284 |
|
printf("\n%s ring %sr%d\n", mat, object(), ++nrings); |
285 |
|
printf("0\n0\n8\n"); |
286 |
|
putv(cent); |
301 |
|
register C_VERTEX *cv; |
302 |
|
FVECT v; |
303 |
|
int rv; |
304 |
< |
|
304 |
> |
/* check argument count and type */ |
305 |
|
if (ac < 4) |
306 |
|
return(MG_EARGC); |
307 |
< |
if ((mat = material()) == NULL) |
307 |
> |
if ((mat = material()) == NULL) /* get material */ |
308 |
|
return(MG_EBADMAT); |
309 |
< |
if (ac <= 5) { /* check for surface normals */ |
309 |
> |
if (ac <= 5) { /* check for smoothing */ |
310 |
|
for (i = 1; i < ac; i++) { |
311 |
|
if ((cv = c_getvert(av[i])) == NULL) |
312 |
|
return(MG_EUNDEF); |
320 |
|
return(MG_OK); |
321 |
|
} |
322 |
|
} |
323 |
+ |
/* spit out unsmoothed primitive */ |
324 |
|
printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces); |
325 |
|
printf("0\n0\n%d\n", 3*(ac-1)); |
326 |
< |
for (i = 1; i < ac; i++) { |
326 |
> |
for (i = 1; i < ac; i++) { /* get, transform, print each vertex */ |
327 |
|
if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL) |
328 |
|
return(MG_EUNDEF); |
329 |
|
xf_xfmpoint(v, cv->p); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
+ |
int |
337 |
|
r_ies(ac, av) /* convert an IES luminaire file */ |
338 |
|
int ac; |
339 |
|
char **av; |
340 |
|
{ |
341 |
|
int xa0 = 2; |
342 |
< |
char combuf[72]; |
342 |
> |
char combuf[128]; |
343 |
|
char fname[48]; |
344 |
|
char *oname; |
345 |
|
register char *op; |
346 |
|
register int i; |
347 |
< |
|
347 |
> |
/* check argument count */ |
348 |
|
if (ac < 2) |
349 |
|
return(MG_EARGC); |
350 |
< |
(void)strcpy(combuf, "ies2rad"); |
331 |
< |
op = combuf + 7; |
332 |
< |
if (ac-xa0 >= 2 && !strcmp(av[xa0], "-m")) { |
333 |
< |
if (!isflt(av[xa0+1])) |
334 |
< |
return(MG_ETYPE); |
335 |
< |
op = addarg(addarg(op, "-m"), av[xa0+1]); |
336 |
< |
xa0 += 2; |
337 |
< |
} |
338 |
< |
if (access(av[1], 0) == -1) |
339 |
< |
return(MG_ENOFILE); |
340 |
< |
*op++ = ' '; /* IES filename goes last */ |
341 |
< |
(void)strcpy(op, av[1]); |
342 |
< |
system(combuf); /* run ies2rad */ |
343 |
< |
/* now let's find the output file */ |
350 |
> |
/* construct output file name */ |
351 |
|
if ((op = strrchr(av[1], '/')) == NULL) |
352 |
|
op = av[1]; |
353 |
|
(void)strcpy(fname, op); |
354 |
|
if ((op = strrchr(fname, '.')) == NULL) |
355 |
|
op = fname + strlen(fname); |
356 |
|
(void)strcpy(op, ".rad"); |
357 |
< |
if (access(fname, 0) == -1) |
358 |
< |
return(MG_EINCL); |
359 |
< |
/* put out xform command */ |
360 |
< |
printf("\n!xform"); |
357 |
> |
/* see if we need to run ies2rad */ |
358 |
> |
if (access(fname, 0) == -1) { |
359 |
> |
(void)strcpy(combuf, "ies2rad");/* build ies2rad command */ |
360 |
> |
op = combuf + 7; /* get -m option (first) */ |
361 |
> |
if (ac-xa0 >= 2 && !strcmp(av[xa0], "-m")) { |
362 |
> |
if (!isflt(av[xa0+1])) |
363 |
> |
return(MG_ETYPE); |
364 |
> |
op = addarg(addarg(op, "-m"), av[xa0+1]); |
365 |
> |
xa0 += 2; |
366 |
> |
} |
367 |
> |
*op++ = ' '; /* build IES filename */ |
368 |
> |
i = 0; |
369 |
> |
if (mg_file != NULL && |
370 |
> |
(oname = strrchr(mg_file->fname,'/')) != NULL) { |
371 |
> |
i = oname - mg_file->fname + 1; |
372 |
> |
(void)strcpy(op, mg_file->fname); |
373 |
> |
} |
374 |
> |
(void)strcpy(op+i, av[1]); |
375 |
> |
if (access(op, 0) == -1) /* check for file existence */ |
376 |
> |
return(MG_ENOFILE); |
377 |
> |
system(combuf); /* run ies2rad */ |
378 |
> |
if (access(fname, 0) == -1) /* check success */ |
379 |
> |
return(MG_EINCL); |
380 |
> |
} |
381 |
> |
printf("\n!xform"); /* put out xform command */ |
382 |
|
oname = object(); |
383 |
|
if (*oname) { |
384 |
|
printf(" -n "); |
418 |
|
xf_xfmpoint(v1, cv1->p); |
419 |
|
xf_xfmpoint(v2, cv2->p); |
420 |
|
xf_xfmpoint(v3, cv3->p); |
421 |
+ |
/* compute barycentric coords. */ |
422 |
|
if (comp_baryc(&bvecs, v1, v2, v3) < 0) |
423 |
|
return; /* degenerate triangle! */ |
424 |
< |
printf("\n%s texfunc T-nor\n", mat); |
424 |
> |
printf("\n%s texfunc T-nor\n", mat); /* put out texture */ |
425 |
|
printf("4 dx dy dz %s\n0\n", TCALNAME); |
426 |
|
xf_rotvect(n1, cv1->n); |
427 |
|
xf_rotvect(n2, cv2->n); |
432 |
|
bcoor[i][2] = n3[i]; |
433 |
|
} |
434 |
|
put_baryc(&bvecs, bcoor, 3); |
435 |
+ |
/* put out triangle */ |
436 |
|
printf("\nT-nor polygon %st%d\n", object(), ++ntris); |
437 |
|
printf("0\n0\n9\n"); |
438 |
|
putv(v1); |
457 |
|
c_cmaterial->clock = 0; |
458 |
|
if (c_cmaterial->ed > .1) { /* emitter */ |
459 |
|
cvtcolor(radrgb, &c_cmaterial->ed_c, |
460 |
< |
emult*c_cmaterial->ed/WHTEFFICACY); |
460 |
> |
emult*c_cmaterial->ed/(PI*WHTEFFICACY)); |
461 |
|
if (glowdist < FHUGE) { /* do a glow */ |
462 |
|
fprintf(matfp, "\nvoid glow %s\n0\n0\n", mname); |
463 |
|
fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED), |
475 |
|
c_cmaterial->rs + c_cmaterial->ts; |
476 |
|
if (d < 0. | d > 1.) |
477 |
|
return(NULL); |
478 |
+ |
/* check for glass/dielectric */ |
479 |
+ |
if (c_cmaterial->nr > 1.1 && |
480 |
+ |
c_cmaterial->ts > .25 && c_cmaterial->rs <= .125 && |
481 |
+ |
c_cmaterial->td <= .01 && c_cmaterial->rd <= .01 && |
482 |
+ |
c_cmaterial->rs_a <= .01 && c_cmaterial->ts_a <= .01) { |
483 |
+ |
cvtcolor(radrgb, &c_cmaterial->ts_c, |
484 |
+ |
c_cmaterial->ts + c_cmaterial->rs); |
485 |
+ |
if (c_cmaterial->sided) { /* dielectric */ |
486 |
+ |
colval(radrgb,RED) = pow(colval(radrgb,RED), |
487 |
+ |
1./C_1SIDEDTHICK); |
488 |
+ |
colval(radrgb,GRN) = pow(colval(radrgb,GRN), |
489 |
+ |
1./C_1SIDEDTHICK); |
490 |
+ |
colval(radrgb,BLU) = pow(colval(radrgb,BLU), |
491 |
+ |
1./C_1SIDEDTHICK); |
492 |
+ |
fprintf(matfp, "\nvoid dielectric %s\n0\n0\n", mname); |
493 |
+ |
fprintf(matfp, "5 %g %g %g %f 0\n", colval(radrgb,RED), |
494 |
+ |
colval(radrgb,GRN), colval(radrgb,BLU), |
495 |
+ |
c_cmaterial->nr); |
496 |
+ |
return(mname); |
497 |
+ |
} |
498 |
+ |
/* glass */ |
499 |
+ |
fprintf(matfp, "\nvoid glass %s\n0\n0\n", mname); |
500 |
+ |
fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED), |
501 |
+ |
colval(radrgb,GRN), colval(radrgb,BLU), |
502 |
+ |
c_cmaterial->nr); |
503 |
+ |
return(mname); |
504 |
+ |
} |
505 |
|
/* check for trans */ |
506 |
|
if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) { |
507 |
|
double ts, a5, a6; |
563 |
|
} |
564 |
|
|
565 |
|
|
566 |
< |
cvtcolor(radrgb, ciec, intensity) /* convert a CIE color to Radiance */ |
566 |
> |
cvtcolor(radrgb, ciec, intensity) /* convert a CIE XYZ color to RGB */ |
567 |
|
COLOR radrgb; |
568 |
|
register C_COLOR *ciec; |
569 |
|
double intensity; |
585 |
|
register int i; |
586 |
|
register char *cp; |
587 |
|
int len; |
588 |
< |
|
588 |
> |
/* tracked by obj_handler */ |
589 |
|
i = obj_nnames - sizeof(objbuf)/16; |
590 |
|
if (i < 0) |
591 |
|
i = 0; |