1 |
– |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Convert Radiance scene description to MGF |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include <stdio.h> |
9 |
< |
#include <math.h> |
8 |
> |
#include "platform.h" |
9 |
> |
#include "standard.h" |
10 |
> |
#include <ctype.h> |
11 |
|
#include <string.h> |
12 |
< |
#include "fvect.h" |
12 |
> |
#include <stdio.h> |
13 |
> |
|
14 |
> |
#include "rtprocess.h" |
15 |
|
#include "object.h" |
16 |
|
#include "color.h" |
17 |
|
#include "lookup.h" |
18 |
|
|
19 |
– |
#define PI 3.14159265358979323846 |
20 |
– |
|
19 |
|
#define C_1SIDEDTHICK 0.005 |
20 |
|
|
23 |
– |
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
24 |
– |
int o_instance(), o_illum(); |
25 |
– |
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
26 |
– |
o_mirror(), o_trans(), o_light(); |
21 |
|
|
28 |
– |
extern void free(); |
29 |
– |
extern char *malloc(); |
30 |
– |
|
22 |
|
LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ |
23 |
|
|
24 |
|
LUTAB rdispatch = LU_SINIT(NULL,NULL); /* function dispatch table */ |
50 |
|
|
51 |
|
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
52 |
|
|
53 |
+ |
static void rad2mgf(char *inp); |
54 |
+ |
static void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa); |
55 |
+ |
static void newmat(char *id, char *alias); |
56 |
+ |
static void setmat(char *id); |
57 |
+ |
static void setobj(char *id); |
58 |
+ |
static void init(void); |
59 |
+ |
static void uninit(void); |
60 |
+ |
static void clrverts(void); |
61 |
+ |
static void add2dispatch(char *name, int (*func)()); |
62 |
+ |
static char *getvertid(char *vname, FVECT vp); |
63 |
+ |
static int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa); |
64 |
+ |
static int o_face(char *mod, char *typ, char *id, FUNARGS *fa); |
65 |
+ |
static int o_cone(char *mod, char *typ, char *id, FUNARGS *fa); |
66 |
+ |
static int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa); |
67 |
+ |
static int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa); |
68 |
+ |
static int o_ring(char *mod, char *typ, char *id, FUNARGS *fa); |
69 |
+ |
static int o_instance(char *mod, char *typ, char *id, FUNARGS *fa); |
70 |
+ |
static int o_illum(char *mod, char *typ, char *id, FUNARGS *fa); |
71 |
+ |
static int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa); |
72 |
+ |
static int o_metal(char *mod, char *typ, char *id, FUNARGS *fa); |
73 |
+ |
static int o_glass(char *mod, char *typ, char *id, FUNARGS *fa); |
74 |
+ |
static int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa); |
75 |
+ |
static int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa); |
76 |
+ |
static int o_trans(char *mod, char *typ, char *id, FUNARGS *fa); |
77 |
+ |
static int o_light(char *mod, char *typ, char *id, FUNARGS *fa); |
78 |
|
|
79 |
< |
main(argc, argv) |
80 |
< |
int argc; |
81 |
< |
char **argv; |
79 |
> |
|
80 |
> |
int |
81 |
> |
main( |
82 |
> |
int argc, |
83 |
> |
char **argv |
84 |
> |
) |
85 |
|
{ |
86 |
|
int i; |
87 |
|
|
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
< |
rad2mgf(inp) /* convert a Radiance file to MGF */ |
126 |
< |
char *inp; |
125 |
> |
void |
126 |
> |
rad2mgf( /* convert a Radiance file to MGF */ |
127 |
> |
char *inp |
128 |
> |
) |
129 |
|
{ |
130 |
|
#define mod buf |
131 |
|
#define typ (buf+128) |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
< |
cvtprim(inp, mod, typ, id, fa) /* process Radiance primitive */ |
207 |
< |
char *inp, *mod, *typ, *id; |
208 |
< |
FUNARGS *fa; |
206 |
> |
void |
207 |
> |
cvtprim( /* process Radiance primitive */ |
208 |
> |
char *inp, |
209 |
> |
char *mod, |
210 |
> |
char *typ, |
211 |
> |
char *id, |
212 |
> |
FUNARGS *fa |
213 |
> |
) |
214 |
|
{ |
215 |
|
int (*df)(); |
216 |
|
|
217 |
|
df = (int (*)())lu_find(&rdispatch, typ)->data; |
218 |
|
if (df != NULL) { /* convert */ |
219 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
220 |
< |
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
220 |
> |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rat2mgf", typ, id); |
221 |
|
exit(1); |
222 |
|
} |
223 |
|
} else { /* unsupported */ |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
< |
newmat(id, alias) /* add a modifier to the alias list */ |
232 |
< |
char *id; |
233 |
< |
char *alias; |
231 |
> |
void |
232 |
> |
newmat( /* add a modifier to the alias list */ |
233 |
> |
char *id, |
234 |
> |
char *alias |
235 |
> |
) |
236 |
|
{ |
237 |
|
register LUENT *lp, *lpa; |
238 |
|
|
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
< |
setmat(id) /* set material to this one */ |
270 |
< |
char *id; |
269 |
> |
void |
270 |
> |
setmat( /* set material to this one */ |
271 |
> |
char *id |
272 |
> |
) |
273 |
|
{ |
274 |
|
if (!strcmp(id, curmat)) /* already set? */ |
275 |
|
return; |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
setobj(id) /* set object name to this one */ |
284 |
< |
char *id; |
283 |
> |
void |
284 |
> |
setobj( /* set object name to this one */ |
285 |
> |
char *id |
286 |
> |
) |
287 |
|
{ |
288 |
|
register char *cp, *cp2; |
289 |
|
char *end = NULL; |
295 |
|
if (end == NULL) |
296 |
|
end = cp; |
297 |
|
/* copy to current object */ |
298 |
< |
for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) |
298 |
> |
cp2 = curobj; |
299 |
> |
if (!isalpha(*id)) { /* start with letter */ |
300 |
> |
diff = *cp2 != 'O'; |
301 |
> |
*cp2++ = 'O'; |
302 |
> |
} |
303 |
> |
for (cp = id; cp < end; *cp2++ = *cp++) { |
304 |
> |
if ((*cp < '!') | (*cp > '~')) /* limit to visible chars */ |
305 |
> |
*cp = '?'; |
306 |
|
diff += *cp != *cp2; |
307 |
+ |
} |
308 |
|
if (!diff && !*cp2) |
309 |
|
return; |
310 |
|
*cp2 = '\0'; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
< |
init() /* initialize dispatch table and output */ |
316 |
> |
void |
317 |
> |
init(void) /* initialize dispatch table and output */ |
318 |
|
{ |
319 |
|
lu_init(&vertab, NVERTS); |
320 |
|
lu_init(&rdispatch, 22); |
327 |
|
add2dispatch("tube", o_cylinder); |
328 |
|
add2dispatch("ring", o_ring); |
329 |
|
add2dispatch("instance", o_instance); |
330 |
+ |
add2dispatch("mesh", o_instance); |
331 |
|
add2dispatch("plastic", o_plastic); |
332 |
|
add2dispatch("plastic2", o_plastic); |
333 |
|
add2dispatch("metal", o_metal); |
348 |
|
} |
349 |
|
|
350 |
|
|
351 |
< |
uninit() /* mark end of MGF file */ |
351 |
> |
void |
352 |
> |
uninit(void) /* mark end of MGF file */ |
353 |
|
{ |
354 |
|
puts("o"); |
355 |
|
if (hasmult) |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
< |
clrverts() /* clear vertex table */ |
364 |
> |
void |
365 |
> |
clrverts(void) /* clear vertex table */ |
366 |
|
{ |
367 |
|
register int i; |
368 |
|
|
373 |
|
} |
374 |
|
|
375 |
|
|
376 |
< |
add2dispatch(name, func) /* add function to dispatch table */ |
377 |
< |
char *name; |
378 |
< |
int (*func)(); |
376 |
> |
void |
377 |
> |
add2dispatch( /* add function to dispatch table */ |
378 |
> |
char *name, |
379 |
> |
int (*func)() |
380 |
> |
) |
381 |
|
{ |
382 |
|
register LUENT *lp; |
383 |
|
|
393 |
|
|
394 |
|
|
395 |
|
char * |
396 |
< |
getvertid(vname, vp) /* get/set vertex ID for this point */ |
397 |
< |
char *vname; |
398 |
< |
FVECT vp; |
396 |
> |
getvertid( /* get/set vertex ID for this point */ |
397 |
> |
char *vname, |
398 |
> |
FVECT vp |
399 |
> |
) |
400 |
|
{ |
401 |
|
static char vkey[VKLEN]; |
402 |
|
register LUENT *lp; |
438 |
|
|
439 |
|
|
440 |
|
int |
441 |
< |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
442 |
< |
char *mod, *typ, *id; |
443 |
< |
FUNARGS *fa; |
441 |
> |
o_unsupported( /* mark unsupported primitive */ |
442 |
> |
char *mod, |
443 |
> |
char *typ, |
444 |
> |
char *id, |
445 |
> |
FUNARGS *fa |
446 |
> |
) |
447 |
|
{ |
448 |
|
register int i; |
449 |
|
|
468 |
|
|
469 |
|
|
470 |
|
int |
471 |
< |
o_face(mod, typ, id, fa) /* print out a polygon */ |
472 |
< |
char *mod, *typ, *id; |
473 |
< |
FUNARGS *fa; |
471 |
> |
o_face( /* print out a polygon */ |
472 |
> |
char *mod, |
473 |
> |
char *typ, |
474 |
> |
char *id, |
475 |
> |
FUNARGS *fa |
476 |
> |
) |
477 |
|
{ |
478 |
< |
char entbuf[512]; |
478 |
> |
char entbuf[2048], *linestart; |
479 |
|
register char *cp; |
480 |
|
register int i; |
481 |
|
|
482 |
< |
if (fa->nfargs < 9 | fa->nfargs % 3) |
482 |
> |
if ((fa->nfargs < 9) | (fa->nfargs % 3)) |
483 |
|
return(-1); |
484 |
|
setmat(mod); |
485 |
|
setobj(id); |
486 |
< |
cp = entbuf; |
486 |
> |
cp = linestart = entbuf; |
487 |
|
*cp++ = 'f'; |
488 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
489 |
|
*cp++ = ' '; |
490 |
+ |
if (cp - linestart > 72) { |
491 |
+ |
*cp++ = '\\'; *cp++ = '\n'; |
492 |
+ |
linestart = cp; |
493 |
+ |
*cp++ = ' '; *cp++ = ' '; |
494 |
+ |
} |
495 |
|
getvertid(cp, fa->farg + i); |
496 |
|
while (*cp) |
497 |
|
cp++; |
502 |
|
|
503 |
|
|
504 |
|
int |
505 |
< |
o_cone(mod, typ, id, fa) /* print out a cone */ |
506 |
< |
char *mod, *typ, *id; |
507 |
< |
register FUNARGS *fa; |
505 |
> |
o_cone( /* print out a cone */ |
506 |
> |
char *mod, |
507 |
> |
char *typ, |
508 |
> |
char *id, |
509 |
> |
register FUNARGS *fa |
510 |
> |
) |
511 |
|
{ |
512 |
|
char v1[6], v2[6]; |
513 |
|
|
528 |
|
|
529 |
|
|
530 |
|
int |
531 |
< |
o_sphere(mod, typ, id, fa) /* print out a sphere */ |
532 |
< |
char *mod, *typ, *id; |
533 |
< |
register FUNARGS *fa; |
531 |
> |
o_sphere( /* print out a sphere */ |
532 |
> |
char *mod, |
533 |
> |
char *typ, |
534 |
> |
char *id, |
535 |
> |
register FUNARGS *fa |
536 |
> |
) |
537 |
|
{ |
538 |
|
char cent[6]; |
539 |
|
|
548 |
|
|
549 |
|
|
550 |
|
int |
551 |
< |
o_cylinder(mod, typ, id, fa) /* print out a cylinder */ |
552 |
< |
char *mod, *typ, *id; |
553 |
< |
register FUNARGS *fa; |
551 |
> |
o_cylinder( /* print out a cylinder */ |
552 |
> |
char *mod, |
553 |
> |
char *typ, |
554 |
> |
char *id, |
555 |
> |
register FUNARGS *fa |
556 |
> |
) |
557 |
|
{ |
558 |
|
char v1[6], v2[6]; |
559 |
|
|
570 |
|
|
571 |
|
|
572 |
|
int |
573 |
< |
o_ring(mod, typ, id, fa) /* print out a ring */ |
574 |
< |
char *mod, *typ, *id; |
575 |
< |
register FUNARGS *fa; |
573 |
> |
o_ring( /* print out a ring */ |
574 |
> |
char *mod, |
575 |
> |
char *typ, |
576 |
> |
char *id, |
577 |
> |
register FUNARGS *fa |
578 |
> |
) |
579 |
|
{ |
580 |
|
if (fa->nfargs != 8) |
581 |
|
return(-1); |
596 |
|
|
597 |
|
|
598 |
|
int |
599 |
< |
o_instance(mod, typ, id, fa) /* convert an instance */ |
600 |
< |
char *mod, *typ, *id; |
601 |
< |
FUNARGS *fa; |
599 |
> |
o_instance( /* convert an instance (or mesh) */ |
600 |
> |
char *mod, |
601 |
> |
char *typ, |
602 |
> |
char *id, |
603 |
> |
FUNARGS *fa |
604 |
> |
) |
605 |
|
{ |
606 |
|
register int i; |
607 |
|
register char *cp; |
640 |
|
|
641 |
|
|
642 |
|
int |
643 |
< |
o_illum(mod, typ, id, fa) /* convert an illum material */ |
644 |
< |
char *mod, *typ, *id; |
645 |
< |
FUNARGS *fa; |
643 |
> |
o_illum( /* convert an illum material */ |
644 |
> |
char *mod, |
645 |
> |
char *typ, |
646 |
> |
char *id, |
647 |
> |
FUNARGS *fa |
648 |
> |
) |
649 |
|
{ |
650 |
|
if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) { |
651 |
|
newmat(id, fa->sarg[0]); /* just create alias */ |
659 |
|
|
660 |
|
|
661 |
|
int |
662 |
< |
o_plastic(mod, typ, id, fa) /* convert a plastic material */ |
663 |
< |
char *mod, *typ, *id; |
664 |
< |
register FUNARGS *fa; |
662 |
> |
o_plastic( /* convert a plastic material */ |
663 |
> |
char *mod, |
664 |
> |
char *typ, |
665 |
> |
char *id, |
666 |
> |
register FUNARGS *fa |
667 |
> |
) |
668 |
|
{ |
669 |
|
COLOR cxyz, rrgb; |
670 |
|
double d; |
690 |
|
|
691 |
|
|
692 |
|
int |
693 |
< |
o_metal(mod, typ, id, fa) /* convert a metal material */ |
694 |
< |
char *mod, *typ, *id; |
695 |
< |
register FUNARGS *fa; |
693 |
> |
o_metal( /* convert a metal material */ |
694 |
> |
char *mod, |
695 |
> |
char *typ, |
696 |
> |
char *id, |
697 |
> |
register FUNARGS *fa |
698 |
> |
) |
699 |
|
{ |
700 |
|
COLOR cxyz, rrgb; |
701 |
|
double d; |
719 |
|
|
720 |
|
|
721 |
|
int |
722 |
< |
o_glass(mod, typ, id, fa) /* convert a glass material */ |
723 |
< |
char *mod, *typ, *id; |
724 |
< |
register FUNARGS *fa; |
722 |
> |
o_glass( /* convert a glass material */ |
723 |
> |
char *mod, |
724 |
> |
char *typ, |
725 |
> |
char *id, |
726 |
> |
register FUNARGS *fa |
727 |
> |
) |
728 |
|
{ |
729 |
|
COLOR cxyz, rrgb, trgb; |
730 |
|
double nrfr = 1.52, F, d; |
761 |
|
|
762 |
|
|
763 |
|
int |
764 |
< |
o_dielectric(mod, typ, id, fa) /* convert a dielectric material */ |
765 |
< |
char *mod, *typ, *id; |
766 |
< |
register FUNARGS *fa; |
764 |
> |
o_dielectric( /* convert a dielectric material */ |
765 |
> |
char *mod, |
766 |
> |
char *typ, |
767 |
> |
char *id, |
768 |
> |
register FUNARGS *fa |
769 |
> |
) |
770 |
|
{ |
771 |
|
COLOR cxyz, trgb; |
772 |
|
double F, d; |
794 |
|
|
795 |
|
|
796 |
|
int |
797 |
< |
o_mirror(mod, typ, id, fa) /* convert a mirror material */ |
798 |
< |
char *mod, *typ, *id; |
799 |
< |
register FUNARGS *fa; |
797 |
> |
o_mirror( /* convert a mirror material */ |
798 |
> |
char *mod, |
799 |
> |
char *typ, |
800 |
> |
char *id, |
801 |
> |
register FUNARGS *fa |
802 |
> |
) |
803 |
|
{ |
804 |
|
COLOR cxyz, rrgb; |
805 |
|
double d; |
823 |
|
|
824 |
|
|
825 |
|
int |
826 |
< |
o_trans(mod, typ, id, fa) /* convert a trans material */ |
827 |
< |
char *mod, *typ, *id; |
828 |
< |
register FUNARGS *fa; |
826 |
> |
o_trans( /* convert a trans material */ |
827 |
> |
char *mod, |
828 |
> |
char *typ, |
829 |
> |
char *id, |
830 |
> |
register FUNARGS *fa |
831 |
> |
) |
832 |
|
{ |
833 |
|
COLOR cxyz, rrgb; |
834 |
|
double rough, trans, tspec, d; |
865 |
|
|
866 |
|
|
867 |
|
int |
868 |
< |
o_light(mod, typ, id, fa) /* convert a light type */ |
869 |
< |
char *mod, *typ, *id; |
870 |
< |
register FUNARGS *fa; |
868 |
> |
o_light( /* convert a light type */ |
869 |
> |
char *mod, |
870 |
> |
char *typ, |
871 |
> |
char *id, |
872 |
> |
register FUNARGS *fa |
873 |
> |
) |
874 |
|
{ |
875 |
|
COLOR cxyz, rrgb; |
876 |
|
double d; |