--- ray/src/cv/rad2mgf.c 1995/04/13 14:43:30 2.10 +++ ray/src/cv/rad2mgf.c 1998/10/14 14:48:04 2.15 @@ -1,4 +1,4 @@ -/* Copyright (c) 1994 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -8,25 +8,21 @@ static char SCCSid[] = "$SunId$ LBL"; * Convert Radiance scene description to MGF */ -#include -#include +#include "standard.h" +#include #include -#include "fvect.h" #include "object.h" #include "color.h" #include "lookup.h" -#define PI 3.14159265358979323846 - #define C_1SIDEDTHICK 0.005 int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); -int o_instance(), o_source(), o_illum(); +int o_instance(), o_illum(); int o_plastic(), o_metal(), o_glass(), o_dielectric(), - o_mirror(), o_trans(), o_light(); + o_mirror(), o_trans(), o_light(); -extern void free(); -extern char *malloc(); +extern int free(); LUTAB rmats = LU_SINIT(free,NULL); /* defined material table */ @@ -194,8 +190,11 @@ FUNARGS *fa; fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); exit(1); } - } else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ - newmat(id, mod); + } else { /* unsupported */ + o_unsupported(mod, typ, id, fa); + if (lu_find(&rmats, mod)->data != NULL) /* make alias */ + newmat(id, mod); + } } @@ -260,8 +259,16 @@ char *id; if (end == NULL) end = cp; /* copy to current object */ - for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) + cp2 = curobj; + if (!isalpha(*id)) { /* start with letter */ + diff = *cp2 != 'O'; + *cp2++ = 'O'; + } + for (cp = id; cp < end; *cp2++ = *cp++) { + if (*cp < '!' | *cp > '~') /* limit to visible chars */ + *cp = '?'; diff += *cp != *cp2; + } if (!diff && !*cp2) return; *cp2 = '\0'; @@ -296,7 +303,7 @@ init() /* initialize dispatch table and output */ add2dispatch("spotlight", o_light); add2dispatch("glow", o_light); add2dispatch("illum", o_illum); - puts("# The following was converted from Radiance scene input"); + puts("# The following was converted from RADIANCE scene input"); if (hasmult) printf("xf -s %.4e\n", unit_mult); printf("o %s\n", curobj); @@ -308,7 +315,7 @@ uninit() /* mark end of MGF file */ puts("o"); if (hasmult) puts("xf"); - puts("# End of data converted from Radiance scene input"); + puts("# End of data converted from RADIANCE scene input"); lu_done(&rdispatch); lu_done(&rmats); lu_done(&vertab); @@ -388,11 +395,38 @@ memerr: int +o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ +char *mod, *typ, *id; +FUNARGS *fa; +{ + register int i; + + fputs("\n# Unsupported RADIANCE primitive:\n", stdout); + printf("# %s %s %s", mod, typ, id); + printf("\n# %d", fa->nsargs); + for (i = 0; i < fa->nsargs; i++) + printf(" %s", fa->sarg[i]); +#ifdef IARGS + printf("\n# %d", fa->niargs); + for (i = 0; i < fa->niargs; i++) + printf(" %ld", fa->iarg[i]); +#else + fputs("\n# 0", stdout); +#endif + printf("\n# %d", fa->nfargs); + for (i = 0; i < fa->nfargs; i++) + printf(" %g", fa->farg[i]); + fputs("\n\n", stdout); + return(0); +} + + +int o_face(mod, typ, id, fa) /* print out a polygon */ char *mod, *typ, *id; FUNARGS *fa; { - char entbuf[512]; + char entbuf[2048], *linestart; register char *cp; register int i; @@ -400,10 +434,15 @@ FUNARGS *fa; return(-1); setmat(mod); setobj(id); - cp = entbuf; + cp = linestart = entbuf; *cp++ = 'f'; for (i = 0; i < fa->nfargs; i += 3) { *cp++ = ' '; + if (cp - linestart > 72) { + *cp++ = '\\'; *cp++ = '\n'; + linestart = cp; + *cp++ = ' '; *cp++ = ' '; + } getvertid(cp, fa->farg + i); while (*cp) cp++; @@ -533,15 +572,6 @@ FUNARGS *fa; putchar('\n'); clrverts(); /* vertex id's no longer reliable */ return(0); -} - - -int -o_source(mod, typ, id, fa) /* convert a source */ -char *mod, *typ, *id; -FUNARGS *fa; -{ - return(0); /* there is no MGF equivalent! */ }