5 |
|
* Convert Radiance scene description to MGF |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include "standard.h" |
8 |
|
#include <ctype.h> |
9 |
|
#include <string.h> |
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
|
#include "platform.h" |
13 |
+ |
#include "rtmath.h" |
14 |
+ |
#include "rtio.h" |
15 |
+ |
#include "rtprocess.h" |
16 |
|
#include "object.h" |
17 |
|
#include "color.h" |
18 |
|
#include "lookup.h" |
19 |
|
|
20 |
|
#define C_1SIDEDTHICK 0.005 |
21 |
|
|
20 |
– |
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
21 |
– |
int o_instance(), o_illum(); |
22 |
– |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
23 |
– |
o_mirror(), o_trans(), o_light(); |
22 |
|
|
23 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
24 |
|
|
51 |
|
|
52 |
|
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
53 |
|
|
54 |
+ |
void rad2mgf(char *inp); |
55 |
+ |
void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa); |
56 |
+ |
void newmat(char *id, char *alias); |
57 |
+ |
void setmat(char *id); |
58 |
+ |
void setobj(char *id); |
59 |
+ |
void init(void); |
60 |
+ |
void uninit(void); |
61 |
+ |
void clrverts(void); |
62 |
+ |
void unspace(char *s); |
63 |
+ |
void add2dispatch(char *name, int (*func)()); |
64 |
+ |
char *getvertid(char *vname, FVECT vp); |
65 |
+ |
int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa); |
66 |
+ |
int o_face(char *mod, char *typ, char *id, FUNARGS *fa); |
67 |
+ |
int o_cone(char *mod, char *typ, char *id, FUNARGS *fa); |
68 |
+ |
int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa); |
69 |
+ |
int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa); |
70 |
+ |
int o_ring(char *mod, char *typ, char *id, FUNARGS *fa); |
71 |
+ |
int o_instance(char *mod, char *typ, char *id, FUNARGS *fa); |
72 |
+ |
int o_illum(char *mod, char *typ, char *id, FUNARGS *fa); |
73 |
+ |
int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa); |
74 |
+ |
int o_metal(char *mod, char *typ, char *id, FUNARGS *fa); |
75 |
+ |
int o_glass(char *mod, char *typ, char *id, FUNARGS *fa); |
76 |
+ |
int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa); |
77 |
+ |
int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa); |
78 |
+ |
int o_trans(char *mod, char *typ, char *id, FUNARGS *fa); |
79 |
+ |
int o_light(char *mod, char *typ, char *id, FUNARGS *fa); |
80 |
|
|
81 |
< |
main(argc, argv) |
82 |
< |
int argc; |
83 |
< |
char **argv; |
81 |
> |
|
82 |
> |
int |
83 |
> |
main( |
84 |
> |
int argc, |
85 |
> |
char **argv |
86 |
> |
) |
87 |
|
{ |
88 |
|
int i; |
89 |
|
|
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
< |
rad2mgf(inp) /* convert a Radiance file to MGF */ |
128 |
< |
char *inp; |
127 |
> |
void |
128 |
> |
rad2mgf( /* convert a Radiance file to MGF */ |
129 |
> |
char *inp |
130 |
> |
) |
131 |
|
{ |
132 |
< |
#define mod buf |
104 |
< |
#define typ (buf+128) |
105 |
< |
#define id (buf+256) |
106 |
< |
#define alias (buf+384) |
107 |
< |
char buf[512]; |
132 |
> |
char mod[128], typ[32], id[128], alias[128]; |
133 |
|
FUNARGS fa; |
134 |
|
register FILE *fp; |
135 |
|
register int c; |
168 |
|
break; |
169 |
|
default: /* Radiance primitive */ |
170 |
|
ungetc(c, fp); |
171 |
< |
if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) { |
171 |
> |
if (fgetword(mod, sizeof(mod), fp) == NULL || |
172 |
> |
fgetword(typ, sizeof(typ), fp) == NULL || |
173 |
> |
fgetword(id, sizeof(id), fp) == NULL) { |
174 |
|
fputs(inp, stderr); |
175 |
|
fputs(": unexpected EOF\n", stderr); |
176 |
|
exit(1); |
177 |
|
} |
178 |
+ |
unspace(mod); |
179 |
+ |
unspace(id); |
180 |
|
if (!strcmp(typ, "alias")) { |
181 |
|
strcpy(alias, "EOF"); |
182 |
< |
fscanf(fp, "%s", alias); |
182 |
> |
fgetword(alias, sizeof(alias), fp); |
183 |
> |
unspace(alias); |
184 |
|
newmat(id, alias); |
185 |
|
} else { |
186 |
|
if (!readfargs(&fa, fp)) { |
199 |
|
pclose(fp); |
200 |
|
else |
201 |
|
fclose(fp); |
172 |
– |
#undef mod |
173 |
– |
#undef typ |
174 |
– |
#undef id |
175 |
– |
#undef alias |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
cvtprim(inp, mod, typ, id, fa) /* process Radiance primitive */ |
206 |
< |
char *inp, *mod, *typ, *id; |
207 |
< |
FUNARGS *fa; |
205 |
> |
void |
206 |
> |
unspace( /* replace spaces with underscores in s */ |
207 |
> |
char *s |
208 |
> |
) |
209 |
|
{ |
210 |
+ |
while (*s) { |
211 |
+ |
if (isspace(*s)) |
212 |
+ |
*s = '_'; |
213 |
+ |
++s; |
214 |
+ |
} |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
|
218 |
+ |
void |
219 |
+ |
cvtprim( /* process Radiance primitive */ |
220 |
+ |
char *inp, |
221 |
+ |
char *mod, |
222 |
+ |
char *typ, |
223 |
+ |
char *id, |
224 |
+ |
FUNARGS *fa |
225 |
+ |
) |
226 |
+ |
{ |
227 |
|
int (*df)(); |
228 |
|
|
229 |
|
df = (int (*)())lu_find(&rdispatch, typ)->data; |
230 |
|
if (df != NULL) { /* convert */ |
231 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
232 |
< |
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
232 |
> |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id); |
233 |
|
exit(1); |
234 |
|
} |
235 |
|
} else { /* unsupported */ |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
< |
newmat(id, alias) /* add a modifier to the alias list */ |
244 |
< |
char *id; |
245 |
< |
char *alias; |
243 |
> |
void |
244 |
> |
newmat( /* add a modifier to the alias list */ |
245 |
> |
char *id, |
246 |
> |
char *alias |
247 |
> |
) |
248 |
|
{ |
249 |
|
register LUENT *lp, *lpa; |
250 |
|
|
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
< |
setmat(id) /* set material to this one */ |
282 |
< |
char *id; |
281 |
> |
void |
282 |
> |
setmat( /* set material to this one */ |
283 |
> |
char *id |
284 |
> |
) |
285 |
|
{ |
286 |
|
if (!strcmp(id, curmat)) /* already set? */ |
287 |
|
return; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
< |
setobj(id) /* set object name to this one */ |
296 |
< |
char *id; |
295 |
> |
void |
296 |
> |
setobj( /* set object name to this one */ |
297 |
> |
char *id |
298 |
> |
) |
299 |
|
{ |
300 |
|
register char *cp, *cp2; |
301 |
|
char *end = NULL; |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
< |
init() /* initialize dispatch table and output */ |
328 |
> |
void |
329 |
> |
init(void) /* initialize dispatch table and output */ |
330 |
|
{ |
331 |
|
lu_init(&vertab, NVERTS); |
332 |
|
lu_init(&rdispatch, 22); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
< |
uninit() /* mark end of MGF file */ |
363 |
> |
void |
364 |
> |
uninit(void) /* mark end of MGF file */ |
365 |
|
{ |
366 |
|
puts("o"); |
367 |
|
if (hasmult) |
373 |
|
} |
374 |
|
|
375 |
|
|
376 |
< |
clrverts() /* clear vertex table */ |
376 |
> |
void |
377 |
> |
clrverts(void) /* clear vertex table */ |
378 |
|
{ |
379 |
|
register int i; |
380 |
|
|
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
< |
add2dispatch(name, func) /* add function to dispatch table */ |
389 |
< |
char *name; |
390 |
< |
int (*func)(); |
388 |
> |
void |
389 |
> |
add2dispatch( /* add function to dispatch table */ |
390 |
> |
char *name, |
391 |
> |
int (*func)() |
392 |
> |
) |
393 |
|
{ |
394 |
|
register LUENT *lp; |
395 |
|
|
405 |
|
|
406 |
|
|
407 |
|
char * |
408 |
< |
getvertid(vname, vp) /* get/set vertex ID for this point */ |
409 |
< |
char *vname; |
410 |
< |
FVECT vp; |
408 |
> |
getvertid( /* get/set vertex ID for this point */ |
409 |
> |
char *vname, |
410 |
> |
FVECT vp |
411 |
> |
) |
412 |
|
{ |
413 |
|
static char vkey[VKLEN]; |
414 |
|
register LUENT *lp; |
450 |
|
|
451 |
|
|
452 |
|
int |
453 |
< |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
454 |
< |
char *mod, *typ, *id; |
455 |
< |
FUNARGS *fa; |
453 |
> |
o_unsupported( /* mark unsupported primitive */ |
454 |
> |
char *mod, |
455 |
> |
char *typ, |
456 |
> |
char *id, |
457 |
> |
FUNARGS *fa |
458 |
> |
) |
459 |
|
{ |
460 |
|
register int i; |
461 |
|
|
480 |
|
|
481 |
|
|
482 |
|
int |
483 |
< |
o_face(mod, typ, id, fa) /* print out a polygon */ |
484 |
< |
char *mod, *typ, *id; |
485 |
< |
FUNARGS *fa; |
483 |
> |
o_face( /* print out a polygon */ |
484 |
> |
char *mod, |
485 |
> |
char *typ, |
486 |
> |
char *id, |
487 |
> |
FUNARGS *fa |
488 |
> |
) |
489 |
|
{ |
490 |
|
char entbuf[2048], *linestart; |
491 |
|
register char *cp; |
514 |
|
|
515 |
|
|
516 |
|
int |
517 |
< |
o_cone(mod, typ, id, fa) /* print out a cone */ |
518 |
< |
char *mod, *typ, *id; |
519 |
< |
register FUNARGS *fa; |
517 |
> |
o_cone( /* print out a cone */ |
518 |
> |
char *mod, |
519 |
> |
char *typ, |
520 |
> |
char *id, |
521 |
> |
register FUNARGS *fa |
522 |
> |
) |
523 |
|
{ |
524 |
|
char v1[6], v2[6]; |
525 |
|
|
540 |
|
|
541 |
|
|
542 |
|
int |
543 |
< |
o_sphere(mod, typ, id, fa) /* print out a sphere */ |
544 |
< |
char *mod, *typ, *id; |
545 |
< |
register FUNARGS *fa; |
543 |
> |
o_sphere( /* print out a sphere */ |
544 |
> |
char *mod, |
545 |
> |
char *typ, |
546 |
> |
char *id, |
547 |
> |
register FUNARGS *fa |
548 |
> |
) |
549 |
|
{ |
550 |
|
char cent[6]; |
551 |
|
|
560 |
|
|
561 |
|
|
562 |
|
int |
563 |
< |
o_cylinder(mod, typ, id, fa) /* print out a cylinder */ |
564 |
< |
char *mod, *typ, *id; |
565 |
< |
register FUNARGS *fa; |
563 |
> |
o_cylinder( /* print out a cylinder */ |
564 |
> |
char *mod, |
565 |
> |
char *typ, |
566 |
> |
char *id, |
567 |
> |
register FUNARGS *fa |
568 |
> |
) |
569 |
|
{ |
570 |
|
char v1[6], v2[6]; |
571 |
|
|
582 |
|
|
583 |
|
|
584 |
|
int |
585 |
< |
o_ring(mod, typ, id, fa) /* print out a ring */ |
586 |
< |
char *mod, *typ, *id; |
587 |
< |
register FUNARGS *fa; |
585 |
> |
o_ring( /* print out a ring */ |
586 |
> |
char *mod, |
587 |
> |
char *typ, |
588 |
> |
char *id, |
589 |
> |
register FUNARGS *fa |
590 |
> |
) |
591 |
|
{ |
592 |
|
if (fa->nfargs != 8) |
593 |
|
return(-1); |
608 |
|
|
609 |
|
|
610 |
|
int |
611 |
< |
o_instance(mod, typ, id, fa) /* convert an instance (or mesh) */ |
612 |
< |
char *mod, *typ, *id; |
613 |
< |
FUNARGS *fa; |
611 |
> |
o_instance( /* convert an instance (or mesh) */ |
612 |
> |
char *mod, |
613 |
> |
char *typ, |
614 |
> |
char *id, |
615 |
> |
FUNARGS *fa |
616 |
> |
) |
617 |
|
{ |
618 |
|
register int i; |
619 |
|
register char *cp; |
652 |
|
|
653 |
|
|
654 |
|
int |
655 |
< |
o_illum(mod, typ, id, fa) /* convert an illum material */ |
656 |
< |
char *mod, *typ, *id; |
657 |
< |
FUNARGS *fa; |
655 |
> |
o_illum( /* convert an illum material */ |
656 |
> |
char *mod, |
657 |
> |
char *typ, |
658 |
> |
char *id, |
659 |
> |
FUNARGS *fa |
660 |
> |
) |
661 |
|
{ |
662 |
|
if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) { |
663 |
|
newmat(id, fa->sarg[0]); /* just create alias */ |
671 |
|
|
672 |
|
|
673 |
|
int |
674 |
< |
o_plastic(mod, typ, id, fa) /* convert a plastic material */ |
675 |
< |
char *mod, *typ, *id; |
676 |
< |
register FUNARGS *fa; |
674 |
> |
o_plastic( /* convert a plastic material */ |
675 |
> |
char *mod, |
676 |
> |
char *typ, |
677 |
> |
char *id, |
678 |
> |
register FUNARGS *fa |
679 |
> |
) |
680 |
|
{ |
681 |
|
COLOR cxyz, rrgb; |
682 |
|
double d; |
702 |
|
|
703 |
|
|
704 |
|
int |
705 |
< |
o_metal(mod, typ, id, fa) /* convert a metal material */ |
706 |
< |
char *mod, *typ, *id; |
707 |
< |
register FUNARGS *fa; |
705 |
> |
o_metal( /* convert a metal material */ |
706 |
> |
char *mod, |
707 |
> |
char *typ, |
708 |
> |
char *id, |
709 |
> |
register FUNARGS *fa |
710 |
> |
) |
711 |
|
{ |
712 |
|
COLOR cxyz, rrgb; |
713 |
|
double d; |
731 |
|
|
732 |
|
|
733 |
|
int |
734 |
< |
o_glass(mod, typ, id, fa) /* convert a glass material */ |
735 |
< |
char *mod, *typ, *id; |
736 |
< |
register FUNARGS *fa; |
734 |
> |
o_glass( /* convert a glass material */ |
735 |
> |
char *mod, |
736 |
> |
char *typ, |
737 |
> |
char *id, |
738 |
> |
register FUNARGS *fa |
739 |
> |
) |
740 |
|
{ |
741 |
|
COLOR cxyz, rrgb, trgb; |
742 |
|
double nrfr = 1.52, F, d; |
773 |
|
|
774 |
|
|
775 |
|
int |
776 |
< |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
777 |
< |
char *mod, *typ, *id; |
778 |
< |
register FUNARGS *fa; |
776 |
> |
o_dielectric( /* convert a dielectric material */ |
777 |
> |
char *mod, |
778 |
> |
char *typ, |
779 |
> |
char *id, |
780 |
> |
register FUNARGS *fa |
781 |
> |
) |
782 |
|
{ |
783 |
|
COLOR cxyz, trgb; |
784 |
|
double F, d; |
806 |
|
|
807 |
|
|
808 |
|
int |
809 |
< |
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
810 |
< |
char *mod, *typ, *id; |
811 |
< |
register FUNARGS *fa; |
809 |
> |
o_mirror( /* convert a mirror material */ |
810 |
> |
char *mod, |
811 |
> |
char *typ, |
812 |
> |
char *id, |
813 |
> |
register FUNARGS *fa |
814 |
> |
) |
815 |
|
{ |
816 |
|
COLOR cxyz, rrgb; |
817 |
|
double d; |
835 |
|
|
836 |
|
|
837 |
|
int |
838 |
< |
o_trans(mod, typ, id, fa) /* convert a trans material */ |
839 |
< |
char *mod, *typ, *id; |
840 |
< |
register FUNARGS *fa; |
838 |
> |
o_trans( /* convert a trans material */ |
839 |
> |
char *mod, |
840 |
> |
char *typ, |
841 |
> |
char *id, |
842 |
> |
register FUNARGS *fa |
843 |
> |
) |
844 |
|
{ |
845 |
|
COLOR cxyz, rrgb; |
846 |
|
double rough, trans, tspec, d; |
877 |
|
|
878 |
|
|
879 |
|
int |
880 |
< |
o_light(mod, typ, id, fa) /* convert a light type */ |
881 |
< |
char *mod, *typ, *id; |
882 |
< |
register FUNARGS *fa; |
880 |
> |
o_light( /* convert a light type */ |
881 |
> |
char *mod, |
882 |
> |
char *typ, |
883 |
> |
char *id, |
884 |
> |
register FUNARGS *fa |
885 |
> |
) |
886 |
|
{ |
887 |
|
COLOR cxyz, rrgb; |
888 |
|
double d; |