6 |
|
*/ |
7 |
|
|
8 |
|
#include <ctype.h> |
9 |
– |
#include <string.h> |
10 |
– |
#include <stdio.h> |
9 |
|
|
10 |
|
#include "platform.h" |
11 |
|
#include "rtmath.h" |
49 |
|
|
50 |
|
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
51 |
|
|
52 |
+ |
typedef int dispatchf(char *mod, char *typ, char *id, FUNARGS *fa); |
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); |
60 |
|
void uninit(void); |
61 |
|
void clrverts(void); |
62 |
|
void unspace(char *s); |
63 |
< |
void add2dispatch(char *name, int (*func)()); |
63 |
> |
void add2dispatch(char *name, dispatchf *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); |
65 |
|
|
66 |
+ |
dispatchf o_unsupported, o_face, o_cone, o_sphere, |
67 |
+ |
o_cylinder, o_ring, o_instance, o_illum, |
68 |
+ |
o_plastic, o_metal, o_glass, o_dielectric, |
69 |
+ |
o_mirror, o_trans, o_light; |
70 |
|
|
71 |
+ |
|
72 |
|
int |
73 |
|
main( |
74 |
|
int argc, |
119 |
|
char *inp |
120 |
|
) |
121 |
|
{ |
122 |
+ |
char buf[512]; |
123 |
|
char mod[128], typ[32], id[128], alias[128]; |
124 |
|
FUNARGS fa; |
125 |
< |
register FILE *fp; |
126 |
< |
register int c; |
125 |
> |
FILE *fp; |
126 |
> |
int c; |
127 |
|
|
128 |
|
if (inp == NULL) { |
129 |
|
inp = "standard input"; |
185 |
|
} |
186 |
|
break; |
187 |
|
} |
188 |
< |
printf("# End conversion from: %s\n", inp); |
189 |
< |
if (inp[0] == '!') |
190 |
< |
pclose(fp); |
191 |
< |
else |
188 |
> |
if (inp[0] == '!') { |
189 |
> |
if (pclose(fp) != 0) |
190 |
> |
fprintf(stderr, "%s: warning - bad exit status\n", inp); |
191 |
> |
} else |
192 |
|
fclose(fp); |
193 |
+ |
printf("# End conversion from: %s\n", inp); |
194 |
|
} |
195 |
|
|
196 |
|
|
216 |
|
FUNARGS *fa |
217 |
|
) |
218 |
|
{ |
219 |
< |
int (*df)(); |
219 |
> |
dispatchf *df; |
220 |
|
|
221 |
< |
df = (int (*)())lu_find(&rdispatch, typ)->data; |
221 |
> |
df = (dispatchf *)lu_find(&rdispatch, typ)->data; |
222 |
|
if (df != NULL) { /* convert */ |
223 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
224 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id); |
238 |
|
char *alias |
239 |
|
) |
240 |
|
{ |
241 |
< |
register LUENT *lp, *lpa; |
241 |
> |
LUENT *lp, *lpa; |
242 |
|
|
243 |
|
if (alias != NULL) { /* look up alias */ |
244 |
|
if ((lpa = lu_find(&rmats, alias)) == NULL) |
289 |
|
char *id |
290 |
|
) |
291 |
|
{ |
292 |
< |
register char *cp, *cp2; |
292 |
> |
char *cp, *cp2; |
293 |
|
char *end = NULL; |
294 |
|
int diff = 0; |
295 |
|
/* use all but final suffix */ |
368 |
|
void |
369 |
|
clrverts(void) /* clear vertex table */ |
370 |
|
{ |
371 |
< |
register int i; |
371 |
> |
int i; |
372 |
|
|
373 |
|
lu_done(&vertab); |
374 |
|
for (i = 0; i < NVERTS; i++) |
383 |
|
int (*func)() |
384 |
|
) |
385 |
|
{ |
386 |
< |
register LUENT *lp; |
386 |
> |
LUENT *lp; |
387 |
|
|
388 |
|
lp = lu_find(&rdispatch, name); |
389 |
|
if (lp->key != NULL) { |
403 |
|
) |
404 |
|
{ |
405 |
|
static char vkey[VKLEN]; |
406 |
< |
register LUENT *lp; |
407 |
< |
register int i, vndx; |
406 |
> |
LUENT *lp; |
407 |
> |
int i, vndx; |
408 |
|
|
409 |
|
vclock++; /* increment counter */ |
410 |
|
mkvkey(vkey, vp); |
449 |
|
FUNARGS *fa |
450 |
|
) |
451 |
|
{ |
452 |
< |
register int i; |
452 |
> |
int i; |
453 |
|
|
454 |
|
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
455 |
|
printf("# %s %s %s", mod, typ, id); |
480 |
|
) |
481 |
|
{ |
482 |
|
char entbuf[2048], *linestart; |
483 |
< |
register char *cp; |
484 |
< |
register int i; |
483 |
> |
char *cp; |
484 |
> |
int i; |
485 |
|
|
486 |
|
if ((fa->nfargs < 9) | (fa->nfargs % 3)) |
487 |
|
return(-1); |
510 |
|
char *mod, |
511 |
|
char *typ, |
512 |
|
char *id, |
513 |
< |
register FUNARGS *fa |
513 |
> |
FUNARGS *fa |
514 |
|
) |
515 |
|
{ |
516 |
|
char v1[6], v2[6]; |
536 |
|
char *mod, |
537 |
|
char *typ, |
538 |
|
char *id, |
539 |
< |
register FUNARGS *fa |
539 |
> |
FUNARGS *fa |
540 |
|
) |
541 |
|
{ |
542 |
|
char cent[6]; |
556 |
|
char *mod, |
557 |
|
char *typ, |
558 |
|
char *id, |
559 |
< |
register FUNARGS *fa |
559 |
> |
FUNARGS *fa |
560 |
|
) |
561 |
|
{ |
562 |
|
char v1[6], v2[6]; |
578 |
|
char *mod, |
579 |
|
char *typ, |
580 |
|
char *id, |
581 |
< |
register FUNARGS *fa |
581 |
> |
FUNARGS *fa |
582 |
|
) |
583 |
|
{ |
584 |
|
if (fa->nfargs != 8) |
607 |
|
FUNARGS *fa |
608 |
|
) |
609 |
|
{ |
610 |
< |
register int i; |
611 |
< |
register char *cp; |
610 |
> |
int i; |
611 |
> |
char *cp; |
612 |
|
char *start = NULL, *end = NULL; |
613 |
|
/* |
614 |
|
* We don't really know how to do this, so we just create |
667 |
|
char *mod, |
668 |
|
char *typ, |
669 |
|
char *id, |
670 |
< |
register FUNARGS *fa |
670 |
> |
FUNARGS *fa |
671 |
|
) |
672 |
|
{ |
673 |
|
COLOR cxyz, rrgb; |
681 |
|
puts("\tc"); /* put diffuse component */ |
682 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
683 |
|
if (d > FTINY) |
684 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
685 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
684 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
685 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
686 |
|
if (fa->farg[3] > FTINY) { /* put specular component */ |
687 |
|
puts("\tc"); |
688 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], |
688 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], |
689 |
|
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
690 |
|
fa->farg[4]); |
691 |
|
} |
698 |
|
char *mod, |
699 |
|
char *typ, |
700 |
|
char *id, |
701 |
< |
register FUNARGS *fa |
701 |
> |
FUNARGS *fa |
702 |
|
) |
703 |
|
{ |
704 |
|
COLOR cxyz, rrgb; |
712 |
|
puts("\tc"); /* put diffuse component */ |
713 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
714 |
|
if (d > FTINY) |
715 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
716 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
715 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
716 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
717 |
|
/* put specular component */ |
718 |
< |
printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
718 |
> |
printf("\trs %.6f %.6f\n", cxyz[1]*fa->farg[3], |
719 |
|
typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
720 |
|
fa->farg[4]); |
721 |
|
return(0); |
727 |
|
char *mod, |
728 |
|
char *typ, |
729 |
|
char *id, |
730 |
< |
register FUNARGS *fa |
730 |
> |
FUNARGS *fa |
731 |
|
) |
732 |
|
{ |
733 |
|
COLOR cxyz, rrgb, trgb; |
734 |
|
double nrfr = 1.52, F, d; |
735 |
< |
register int i; |
735 |
> |
int i; |
736 |
|
|
737 |
|
if (fa->nfargs != 3 && fa->nfargs != 4) |
738 |
|
return(-1); |
752 |
|
puts("\tc"); |
753 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
754 |
|
if (d > FTINY) |
755 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
756 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
755 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
756 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
757 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
758 |
|
puts("\tc"); |
759 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
760 |
|
if (d > FTINY) |
761 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
762 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
761 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
762 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
763 |
|
return(0); |
764 |
|
} |
765 |
|
|
769 |
|
char *mod, |
770 |
|
char *typ, |
771 |
|
char *id, |
772 |
< |
register FUNARGS *fa |
772 |
> |
FUNARGS *fa |
773 |
|
) |
774 |
|
{ |
775 |
|
COLOR cxyz, trgb; |
776 |
|
double F, d; |
777 |
< |
register int i; |
777 |
> |
int i; |
778 |
|
|
779 |
|
if (fa->nfargs != 5) |
780 |
|
return(-1); |
786 |
|
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
787 |
|
printf("\tsides 1\n"); |
788 |
|
puts("\tc"); /* put reflected component */ |
789 |
< |
printf("\trs %.4f 0\n", F); |
789 |
> |
printf("\trs %.6f 0\n", F); |
790 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
791 |
|
puts("\tc"); |
792 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
793 |
|
if (d > FTINY) |
794 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
795 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
794 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
795 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
796 |
|
return(0); |
797 |
|
} |
798 |
|
|
802 |
|
char *mod, |
803 |
|
char *typ, |
804 |
|
char *id, |
805 |
< |
register FUNARGS *fa |
805 |
> |
FUNARGS *fa |
806 |
|
) |
807 |
|
{ |
808 |
|
COLOR cxyz, rrgb; |
820 |
|
puts("\tc"); /* put specular component */ |
821 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
822 |
|
if (d > FTINY) |
823 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
824 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
823 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
824 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
825 |
|
return(0); |
826 |
|
} |
827 |
|
|
831 |
|
char *mod, |
832 |
|
char *typ, |
833 |
|
char *id, |
834 |
< |
register FUNARGS *fa |
834 |
> |
FUNARGS *fa |
835 |
|
) |
836 |
|
{ |
837 |
|
COLOR cxyz, rrgb; |
838 |
|
double rough, trans, tspec, d; |
839 |
|
|
840 |
< |
if (typ[4] == '2') { /* trans2 */ |
840 |
> |
if (typ[5] == '2') { /* trans2 */ |
841 |
|
if (fa->nfargs != 8) |
842 |
|
return(-1); |
843 |
|
rough = .5*(fa->farg[4] + fa->farg[5]); |
856 |
|
puts("\tc"); /* put transmitted diffuse */ |
857 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
858 |
|
if (d > FTINY) |
859 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
860 |
< |
printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
859 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
860 |
> |
printf("\ttd %.6f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
861 |
|
/* put transmitted specular */ |
862 |
< |
printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
862 |
> |
printf("\tts %.6f %.6f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
863 |
|
/* put reflected diffuse */ |
864 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
864 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
865 |
|
puts("\tc"); /* put reflected specular */ |
866 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], rough); |
866 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], rough); |
867 |
|
return(0); |
868 |
|
} |
869 |
|
|
873 |
|
char *mod, |
874 |
|
char *typ, |
875 |
|
char *id, |
876 |
< |
register FUNARGS *fa |
876 |
> |
FUNARGS *fa |
877 |
|
) |
878 |
|
{ |
879 |
|
COLOR cxyz, rrgb; |
887 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
888 |
|
puts("\tc"); |
889 |
|
if (d > FTINY) |
890 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
890 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
891 |
|
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
892 |
|
return(0); |
893 |
|
} |