1 |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Convert MGF (Materials and Geometry Format) to Radiance |
9 |
*/ |
10 |
|
11 |
#include <stdio.h> |
12 |
#include <math.h> |
13 |
#include <string.h> |
14 |
#include "mgflib/parser.h" |
15 |
#include "color.h" |
16 |
#include "tmesh.h" |
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.; /* 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 |
|
31 |
|
32 |
main(argc, argv) /* convert files to stdout */ |
33 |
int argc; |
34 |
char *argv[]; |
35 |
{ |
36 |
int i, rv; |
37 |
/* initialize dispatch table */ |
38 |
mg_ehand[MG_E_COMMENT] = r_comment; |
39 |
mg_ehand[MG_E_COLOR] = c_hcolor; |
40 |
mg_ehand[MG_E_CONE] = r_cone; |
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; |
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; |
63 |
mg_init(); /* initialize the parser */ |
64 |
/* get options & print header */ |
65 |
printf("## %s", argv[0]); |
66 |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
67 |
printf(" %s", argv[i]); |
68 |
switch (argv[i][1]) { |
69 |
case 'g': /* glow distance (meters) */ |
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-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 |
} |
92 |
} |
93 |
putchar('\n'); |
94 |
if (i == argc) { /* convert stdin */ |
95 |
if ((rv = mg_load(NULL)) != MG_OK) |
96 |
exit(1); |
97 |
} else /* convert each file */ |
98 |
for ( ; i < argc; i++) { |
99 |
printf("## %s %s ##############################\n", |
100 |
argv[0], argv[i]); |
101 |
if ((rv = mg_load(argv[i])) != MG_OK) |
102 |
exit(1); |
103 |
} |
104 |
exit(0); |
105 |
userr: |
106 |
fprintf(stderr, "Usage: %s [-g dist][-e mult][-m matf] [file.mgf] ..\n", |
107 |
argv[0]); |
108 |
exit(1); |
109 |
} |
110 |
|
111 |
|
112 |
int |
113 |
r_comment(ac, av) /* repeat a comment verbatim */ |
114 |
register int ac; |
115 |
register char **av; |
116 |
{ |
117 |
putchar('#'); /* use Radiance comment character */ |
118 |
while (--ac) { |
119 |
putchar(' '); |
120 |
fputs(*++av, stdout); |
121 |
} |
122 |
putchar('\n'); |
123 |
return(MG_OK); |
124 |
} |
125 |
|
126 |
|
127 |
int |
128 |
r_cone(ac, av) /* put out a cone */ |
129 |
int ac; |
130 |
char **av; |
131 |
{ |
132 |
static int ncones; |
133 |
char *mat; |
134 |
double r1, r2; |
135 |
C_VERTEX *cv1, *cv2; |
136 |
FVECT p1, p2; |
137 |
int inv; |
138 |
|
139 |
if (ac != 5) |
140 |
return(MG_EARGC); |
141 |
if (!isflt(av[2]) || !isflt(av[4])) |
142 |
return(MG_ETYPE); |
143 |
if ((cv1 = c_getvert(av[1])) == NULL || |
144 |
(cv2 = c_getvert(av[3])) == NULL) |
145 |
return(MG_EUNDEF); |
146 |
xf_xfmpoint(p1, cv1->p); |
147 |
xf_xfmpoint(p2, cv2->p); |
148 |
r1 = xf_scale(atof(av[2])); |
149 |
r2 = xf_scale(atof(av[4])); |
150 |
inv = r1 < 0.; |
151 |
if (r1 == 0.) { |
152 |
if (r2 == 0.) |
153 |
return(MG_EILL); |
154 |
inv = r2 < 0.; |
155 |
} else if (r2 != 0. && inv ^ r2 < 0.) |
156 |
return(MG_EILL); |
157 |
if (inv) { |
158 |
r1 = -r1; |
159 |
r2 = -r2; |
160 |
} |
161 |
if ((mat = material()) == NULL) |
162 |
return(MG_EBADMAT); |
163 |
printf("\n%s %s %sc%d\n", mat, inv ? "cup" : "cone", |
164 |
object(), ++ncones); |
165 |
printf("0\n0\n8\n"); |
166 |
putv(p1); |
167 |
putv(p2); |
168 |
printf("%18.12g %18.12g\n", r1, r2); |
169 |
return(MG_OK); |
170 |
} |
171 |
|
172 |
|
173 |
int |
174 |
r_cyl(ac, av) /* put out a cylinder */ |
175 |
int ac; |
176 |
char **av; |
177 |
{ |
178 |
static int ncyls; |
179 |
char *mat; |
180 |
double rad; |
181 |
C_VERTEX *cv1, *cv2; |
182 |
FVECT p1, p2; |
183 |
int inv; |
184 |
|
185 |
if (ac != 4) |
186 |
return(MG_EARGC); |
187 |
if (!isflt(av[2])) |
188 |
return(MG_ETYPE); |
189 |
if ((cv1 = c_getvert(av[1])) == NULL || |
190 |
(cv2 = c_getvert(av[3])) == NULL) |
191 |
return(MG_EUNDEF); |
192 |
xf_xfmpoint(p1, cv1->p); |
193 |
xf_xfmpoint(p2, cv2->p); |
194 |
rad = xf_scale(atof(av[2])); |
195 |
if ((inv = rad < 0.)) |
196 |
rad = -rad; |
197 |
if ((mat = material()) == NULL) |
198 |
return(MG_EBADMAT); |
199 |
printf("\n%s %s %scy%d\n", mat, inv ? "tube" : "cylinder", |
200 |
object(), ++ncyls); |
201 |
printf("0\n0\n7\n"); |
202 |
putv(p1); |
203 |
putv(p2); |
204 |
printf("%18.12g\n", rad); |
205 |
return(MG_OK); |
206 |
} |
207 |
|
208 |
|
209 |
int |
210 |
r_sph(ac, av) /* put out a sphere */ |
211 |
int ac; |
212 |
char **av; |
213 |
{ |
214 |
static int nsphs; |
215 |
char *mat; |
216 |
double rad; |
217 |
C_VERTEX *cv; |
218 |
FVECT cent; |
219 |
int inv; |
220 |
|
221 |
if (ac != 3) |
222 |
return(MG_EARGC); |
223 |
if (!isflt(av[2])) |
224 |
return(MG_ETYPE); |
225 |
if ((cv = c_getvert(av[1])) == NULL) |
226 |
return(MG_EUNDEF); |
227 |
xf_xfmpoint(cent, cv->p); |
228 |
rad = xf_scale(atof(av[2])); |
229 |
if ((inv = rad < 0.)) |
230 |
rad = -rad; |
231 |
if ((mat = material()) == NULL) |
232 |
return(MG_EBADMAT); |
233 |
printf("\n%s %s %ss%d\n", mat, inv ? "bubble" : "sphere", |
234 |
object(), ++nsphs); |
235 |
printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n", |
236 |
cent[0], cent[1], cent[2], rad); |
237 |
return(MG_OK); |
238 |
} |
239 |
|
240 |
|
241 |
int |
242 |
r_ring(ac, av) /* put out a ring */ |
243 |
int ac; |
244 |
char **av; |
245 |
{ |
246 |
static int nrings; |
247 |
char *mat; |
248 |
double r1, r2; |
249 |
C_VERTEX *cv; |
250 |
FVECT cent, norm; |
251 |
|
252 |
if (ac != 4) |
253 |
return(MG_EARGC); |
254 |
if (!isflt(av[2]) || !isflt(av[3])) |
255 |
return(MG_ETYPE); |
256 |
if ((cv = c_getvert(av[1])) == NULL) |
257 |
return(MG_EUNDEF); |
258 |
if (is0vect(cv->n)) |
259 |
return(MG_EILL); |
260 |
xf_xfmpoint(cent, cv->p); |
261 |
xf_rotvect(norm, cv->n); |
262 |
r1 = xf_scale(atof(av[2])); |
263 |
r2 = xf_scale(atof(av[3])); |
264 |
if (r1 < 0. | r2 <= r1) |
265 |
return(MG_EILL); |
266 |
if ((mat = material()) == NULL) |
267 |
return(MG_EBADMAT); |
268 |
printf("\n%s ring %sr%d\n", mat, object(), ++nrings); |
269 |
printf("0\n0\n8\n"); |
270 |
putv(cent); |
271 |
putv(norm); |
272 |
printf("%18.12g %18.12g\n", r1, r2); |
273 |
return(MG_OK); |
274 |
} |
275 |
|
276 |
|
277 |
int |
278 |
r_face(ac, av) /* convert a face */ |
279 |
int ac; |
280 |
char **av; |
281 |
{ |
282 |
static int nfaces; |
283 |
char *mat; |
284 |
register int i; |
285 |
register C_VERTEX *cv; |
286 |
FVECT v; |
287 |
int rv; |
288 |
|
289 |
if (ac < 4) |
290 |
return(MG_EARGC); |
291 |
if ((mat = material()) == NULL) |
292 |
return(MG_EBADMAT); |
293 |
if (ac <= 5) { /* check for surface normals */ |
294 |
for (i = 1; i < ac; i++) { |
295 |
if ((cv = c_getvert(av[i])) == NULL) |
296 |
return(MG_EUNDEF); |
297 |
if (is0vect(cv->n)) |
298 |
break; |
299 |
} |
300 |
if (i == ac) { /* break into triangles */ |
301 |
do_tri(mat, av[1], av[2], av[3]); |
302 |
if (ac == 5) |
303 |
do_tri(mat, av[3], av[4], av[1]); |
304 |
return(MG_OK); |
305 |
} |
306 |
} |
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[invert ? ac-i : i])) == NULL) |
311 |
return(MG_EUNDEF); |
312 |
xf_xfmpoint(v, cv->p); |
313 |
putv(v); |
314 |
} |
315 |
return(MG_OK); |
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[128]; |
326 |
char fname[48]; |
327 |
char *oname; |
328 |
register char *op; |
329 |
register int i; |
330 |
|
331 |
if (ac < 2) |
332 |
return(MG_EARGC); |
333 |
(void)strcpy(combuf, "ies2rad"); |
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 |
*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); |
351 |
system(combuf); /* run ies2rad */ |
352 |
/* now let's find the output file */ |
353 |
if ((op = strrchr(av[1], '/')) == NULL) |
354 |
op = av[1]; |
355 |
(void)strcpy(fname, op); |
356 |
if ((op = strrchr(fname, '.')) == NULL) |
357 |
op = fname + strlen(fname); |
358 |
(void)strcpy(op, ".rad"); |
359 |
if (access(fname, 0) == -1) |
360 |
return(MG_EINCL); |
361 |
/* put out xform command */ |
362 |
printf("\n!xform"); |
363 |
oname = object(); |
364 |
if (*oname) { |
365 |
printf(" -n "); |
366 |
for (op = oname; op[1]; op++) /* remove trailing separator */ |
367 |
putchar(*op); |
368 |
} |
369 |
for (i = xa0; i < ac; i++) |
370 |
printf(" %s", av[i]); |
371 |
if (ac > xa0 && xf_argc > 0) |
372 |
printf(" -i 1"); |
373 |
for (i = 0; i < xf_argc; i++) |
374 |
printf(" %s", xf_argv[i]); |
375 |
printf(" %s\n", fname); |
376 |
return(MG_OK); |
377 |
} |
378 |
|
379 |
|
380 |
do_tri(mat, vn1, vn2, vn3) /* put out smoothed triangle */ |
381 |
char *mat, *vn1, *vn2, *vn3; |
382 |
{ |
383 |
static int ntris; |
384 |
BARYCCM bvecs; |
385 |
FLOAT bcoor[3][3]; |
386 |
C_VERTEX *cv1, *cv2, *cv3; |
387 |
FVECT v1, v2, v3; |
388 |
FVECT n1, n2, n3; |
389 |
register int i; |
390 |
/* the following is repeat code, so assume it's OK */ |
391 |
cv2 = c_getvert(vn2); |
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); |
402 |
if (comp_baryc(&bvecs, v1, v2, v3) < 0) |
403 |
return; /* degenerate triangle! */ |
404 |
printf("\n%s texfunc T-nor\n", mat); |
405 |
printf("4 dx dy dz %s\n0\n", TCALNAME); |
406 |
xf_rotvect(n1, cv1->n); |
407 |
xf_rotvect(n2, cv2->n); |
408 |
xf_rotvect(n3, cv3->n); |
409 |
for (i = 0; i < 3; i++) { |
410 |
bcoor[i][0] = n1[i]; |
411 |
bcoor[i][1] = n2[i]; |
412 |
bcoor[i][2] = n3[i]; |
413 |
} |
414 |
put_baryc(&bvecs, bcoor, 3); |
415 |
printf("\nT-nor polygon %st%d\n", object(), ++ntris); |
416 |
printf("0\n0\n9\n"); |
417 |
putv(v1); |
418 |
putv(v2); |
419 |
putv(v3); |
420 |
} |
421 |
|
422 |
|
423 |
char * |
424 |
material() /* get (and print) current material */ |
425 |
{ |
426 |
char *mname = "mat"; |
427 |
COLOR radrgb, c2; |
428 |
double d; |
429 |
register int i; |
430 |
|
431 |
if (c_cmname != NULL) |
432 |
mname = c_cmname; |
433 |
if (!c_cmaterial->clock) |
434 |
return(mname); /* already current */ |
435 |
/* else update output */ |
436 |
c_cmaterial->clock = 0; |
437 |
if (c_cmaterial->ed > .1) { /* emitter */ |
438 |
cvtcolor(radrgb, &c_cmaterial->ed_c, |
439 |
emult*c_cmaterial->ed/(PI*WHTEFFICACY)); |
440 |
if (glowdist < FHUGE) { /* do a glow */ |
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 |
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 |
} |
451 |
return(mname); |
452 |
} |
453 |
d = c_cmaterial->rd + c_cmaterial->td + |
454 |
c_cmaterial->rs + c_cmaterial->ts; |
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 |
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); |
498 |
cvtcolor(c2, &c_cmaterial->td_c, c_cmaterial->td/d); |
499 |
addcolor(radrgb, c2); |
500 |
cvtcolor(c2, &c_cmaterial->ts_c, ts/d); |
501 |
addcolor(radrgb, c2); |
502 |
if (c_cmaterial->rs + ts > .0001) |
503 |
a5 = (c_cmaterial->rs*c_cmaterial->rs_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) |
509 |
d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6); |
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 |
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 < .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 |
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 |
/* 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 |
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->rd + c_cmaterial->rs), |
540 |
c_cmaterial->rs_a); |
541 |
return(mname); |
542 |
} |
543 |
|
544 |
|
545 |
cvtcolor(radrgb, ciec, intensity) /* convert a CIE color to Radiance */ |
546 |
COLOR radrgb; |
547 |
register C_COLOR *ciec; |
548 |
double intensity; |
549 |
{ |
550 |
static COLOR ciexyz; |
551 |
|
552 |
c_ccvt(ciec, C_CSXY); /* get xy representation */ |
553 |
ciexyz[1] = intensity; |
554 |
ciexyz[0] = ciec->cx/ciec->cy*ciexyz[1]; |
555 |
ciexyz[2] = ciexyz[1]*(1./ciec->cy - 1.) - ciexyz[0]; |
556 |
cie_rgb(radrgb, ciexyz); |
557 |
} |
558 |
|
559 |
|
560 |
char * |
561 |
object() /* return current object name */ |
562 |
{ |
563 |
static char objbuf[64]; |
564 |
register int i; |
565 |
register char *cp; |
566 |
int len; |
567 |
|
568 |
i = obj_nnames - sizeof(objbuf)/16; |
569 |
if (i < 0) |
570 |
i = 0; |
571 |
for (cp = objbuf; i < obj_nnames && |
572 |
cp + (len=strlen(obj_name[i])) < objbuf+sizeof(objbuf)-1; |
573 |
i++, *cp++ = '.') { |
574 |
strcpy(cp, obj_name[i]); |
575 |
cp += len; |
576 |
} |
577 |
*cp = '\0'; |
578 |
return(objbuf); |
579 |
} |
580 |
|
581 |
|
582 |
char * |
583 |
addarg(op, arg) /* add argument and advance pointer */ |
584 |
register char *op, *arg; |
585 |
{ |
586 |
*op = ' '; |
587 |
while (*++op = *arg++) |
588 |
; |
589 |
return(op); |
590 |
} |