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