51 |
|
|
52 |
|
LUTAB vertab = LU_SINIT(free,NULL); /* our vertex lookup table */ |
53 |
|
|
54 |
< |
static void rad2mgf(char *inp); |
55 |
< |
static void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa); |
56 |
< |
static void newmat(char *id, char *alias); |
57 |
< |
static void setmat(char *id); |
58 |
< |
static void setobj(char *id); |
59 |
< |
static void init(void); |
60 |
< |
static void uninit(void); |
61 |
< |
static void clrverts(void); |
62 |
< |
static void add2dispatch(char *name, int (*func)()); |
63 |
< |
static char *getvertid(char *vname, FVECT vp); |
64 |
< |
static int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa); |
65 |
< |
static int o_face(char *mod, char *typ, char *id, FUNARGS *fa); |
66 |
< |
static int o_cone(char *mod, char *typ, char *id, FUNARGS *fa); |
67 |
< |
static int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa); |
68 |
< |
static int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa); |
69 |
< |
static int o_ring(char *mod, char *typ, char *id, FUNARGS *fa); |
70 |
< |
static int o_instance(char *mod, char *typ, char *id, FUNARGS *fa); |
71 |
< |
static int o_illum(char *mod, char *typ, char *id, FUNARGS *fa); |
72 |
< |
static int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa); |
73 |
< |
static int o_metal(char *mod, char *typ, char *id, FUNARGS *fa); |
74 |
< |
static int o_glass(char *mod, char *typ, char *id, FUNARGS *fa); |
75 |
< |
static int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa); |
76 |
< |
static int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa); |
77 |
< |
static int o_trans(char *mod, char *typ, char *id, FUNARGS *fa); |
78 |
< |
static int o_light(char *mod, char *typ, char *id, FUNARGS *fa); |
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 |
|
|
82 |
|
int |
129 |
|
char *inp |
130 |
|
) |
131 |
|
{ |
132 |
< |
#define mod buf |
133 |
< |
#define typ (buf+128) |
133 |
< |
#define id (buf+256) |
134 |
< |
#define alias (buf+384) |
135 |
< |
char buf[512]; |
132 |
> |
char buf[512]; |
133 |
> |
char mod[128], typ[32], id[128], alias[128]; |
134 |
|
FUNARGS fa; |
135 |
|
register FILE *fp; |
136 |
|
register int c; |
169 |
|
break; |
170 |
|
default: /* Radiance primitive */ |
171 |
|
ungetc(c, fp); |
172 |
< |
if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) { |
172 |
> |
if (fgetword(mod, sizeof(mod), fp) == NULL || |
173 |
> |
fgetword(typ, sizeof(typ), fp) == NULL || |
174 |
> |
fgetword(id, sizeof(id), fp) == NULL) { |
175 |
|
fputs(inp, stderr); |
176 |
|
fputs(": unexpected EOF\n", stderr); |
177 |
|
exit(1); |
178 |
|
} |
179 |
+ |
unspace(mod); |
180 |
+ |
unspace(id); |
181 |
|
if (!strcmp(typ, "alias")) { |
182 |
|
strcpy(alias, "EOF"); |
183 |
< |
fscanf(fp, "%s", alias); |
183 |
> |
fgetword(alias, sizeof(alias), fp); |
184 |
> |
unspace(alias); |
185 |
|
newmat(id, alias); |
186 |
|
} else { |
187 |
|
if (!readfargs(&fa, fp)) { |
200 |
|
pclose(fp); |
201 |
|
else |
202 |
|
fclose(fp); |
200 |
– |
#undef mod |
201 |
– |
#undef typ |
202 |
– |
#undef id |
203 |
– |
#undef alias |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
void |
207 |
+ |
unspace( /* replace spaces with underscores in s */ |
208 |
+ |
char *s |
209 |
+ |
) |
210 |
+ |
{ |
211 |
+ |
while (*s) { |
212 |
+ |
if (isspace(*s)) |
213 |
+ |
*s = '_'; |
214 |
+ |
++s; |
215 |
+ |
} |
216 |
+ |
} |
217 |
+ |
|
218 |
+ |
|
219 |
+ |
void |
220 |
|
cvtprim( /* process Radiance primitive */ |
221 |
|
char *inp, |
222 |
|
char *mod, |
230 |
|
df = (int (*)())lu_find(&rdispatch, typ)->data; |
231 |
|
if (df != NULL) { /* convert */ |
232 |
|
if ((*df)(mod, typ, id, fa) < 0) { |
233 |
< |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rat2mgf", typ, id); |
233 |
> |
fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id); |
234 |
|
exit(1); |
235 |
|
} |
236 |
|
} else { /* unsupported */ |
690 |
|
puts("\tc"); /* put diffuse component */ |
691 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
692 |
|
if (d > FTINY) |
693 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
694 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
693 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
694 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
695 |
|
if (fa->farg[3] > FTINY) { /* put specular component */ |
696 |
|
puts("\tc"); |
697 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], |
697 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], |
698 |
|
typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
699 |
|
fa->farg[4]); |
700 |
|
} |
721 |
|
puts("\tc"); /* put diffuse component */ |
722 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
723 |
|
if (d > FTINY) |
724 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
725 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])); |
724 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
725 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])); |
726 |
|
/* put specular component */ |
727 |
< |
printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3], |
727 |
> |
printf("\trs %.6f %.6f\n", cxyz[1]*fa->farg[3], |
728 |
|
typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) : |
729 |
|
fa->farg[4]); |
730 |
|
return(0); |
761 |
|
puts("\tc"); |
762 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
763 |
|
if (d > FTINY) |
764 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
765 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
764 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
765 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
766 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
767 |
|
puts("\tc"); |
768 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
769 |
|
if (d > FTINY) |
770 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
771 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
770 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
771 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
772 |
|
return(0); |
773 |
|
} |
774 |
|
|
795 |
|
printf("\tir %f 0\n", fa->farg[3]); /* put index of refraction */ |
796 |
|
printf("\tsides 1\n"); |
797 |
|
puts("\tc"); /* put reflected component */ |
798 |
< |
printf("\trs %.4f 0\n", F); |
798 |
> |
printf("\trs %.6f 0\n", F); |
799 |
|
rgb_cie(cxyz, trgb); /* put transmitted component */ |
800 |
|
puts("\tc"); |
801 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
802 |
|
if (d > FTINY) |
803 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
804 |
< |
printf("\tts %.4f 0\n", cxyz[1]); |
803 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
804 |
> |
printf("\tts %.6f 0\n", cxyz[1]); |
805 |
|
return(0); |
806 |
|
} |
807 |
|
|
829 |
|
puts("\tc"); /* put specular component */ |
830 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
831 |
|
if (d > FTINY) |
832 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
833 |
< |
printf("\trs %.4f 0\n", cxyz[1]); |
832 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
833 |
> |
printf("\trs %.6f 0\n", cxyz[1]); |
834 |
|
return(0); |
835 |
|
} |
836 |
|
|
846 |
|
COLOR cxyz, rrgb; |
847 |
|
double rough, trans, tspec, d; |
848 |
|
|
849 |
< |
if (typ[4] == '2') { /* trans2 */ |
849 |
> |
if (typ[5] == '2') { /* trans2 */ |
850 |
|
if (fa->nfargs != 8) |
851 |
|
return(-1); |
852 |
|
rough = .5*(fa->farg[4] + fa->farg[5]); |
865 |
|
puts("\tc"); /* put transmitted diffuse */ |
866 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
867 |
|
if (d > FTINY) |
868 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
869 |
< |
printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
868 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
869 |
> |
printf("\ttd %.6f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec)); |
870 |
|
/* put transmitted specular */ |
871 |
< |
printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
871 |
> |
printf("\tts %.6f %.6f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough); |
872 |
|
/* put reflected diffuse */ |
873 |
< |
printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
873 |
> |
printf("\trd %.6f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans)); |
874 |
|
puts("\tc"); /* put reflected specular */ |
875 |
< |
printf("\trs %.4f %.4f\n", fa->farg[3], rough); |
875 |
> |
printf("\trs %.6f %.6f\n", fa->farg[3], rough); |
876 |
|
return(0); |
877 |
|
} |
878 |
|
|
896 |
|
d = cxyz[0] + cxyz[1] + cxyz[2]; |
897 |
|
puts("\tc"); |
898 |
|
if (d > FTINY) |
899 |
< |
printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d); |
899 |
> |
printf("\t\tcxy %.6f %.6f\n", cxyz[0]/d, cxyz[1]/d); |
900 |
|
printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY)); |
901 |
|
return(0); |
902 |
|
} |