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 "standard.h" |
9 |
> |
#include <ctype.h> |
10 |
|
#include <string.h> |
14 |
– |
#include "fvect.h" |
11 |
|
#include "object.h" |
12 |
|
#include "color.h" |
13 |
|
#include "lookup.h" |
14 |
|
|
19 |
– |
#define PI 3.14159265358979323846 |
20 |
– |
|
15 |
|
#define C_1SIDEDTHICK 0.005 |
16 |
|
|
17 |
|
int o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); |
18 |
< |
int o_instance(), o_source(), o_illum(); |
18 |
> |
int o_instance(), o_illum(); |
19 |
|
int o_plastic(), o_metal(), o_glass(), o_dielectric(), |
20 |
< |
o_mirror(), o_trans(), o_light(); |
20 |
> |
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 */ |
185 |
|
fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); |
186 |
|
exit(1); |
187 |
|
} |
188 |
< |
} else if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
189 |
< |
newmat(id, mod); |
188 |
> |
} else { /* unsupported */ |
189 |
> |
o_unsupported(mod, typ, id, fa); |
190 |
> |
if (lu_find(&rmats, mod)->data != NULL) /* make alias */ |
191 |
> |
newmat(id, mod); |
192 |
> |
} |
193 |
|
} |
194 |
|
|
195 |
|
|
254 |
|
if (end == NULL) |
255 |
|
end = cp; |
256 |
|
/* copy to current object */ |
257 |
< |
for (cp = id, cp2 = curobj; cp < end; *cp2++ = *cp++) |
257 |
> |
cp2 = curobj; |
258 |
> |
if (!isalpha(*id)) { /* start with letter */ |
259 |
> |
diff = *cp2 != 'O'; |
260 |
> |
*cp2++ = 'O'; |
261 |
> |
} |
262 |
> |
for (cp = id; cp < end; *cp2++ = *cp++) { |
263 |
> |
if (*cp < '!' | *cp > '~') /* limit to visible chars */ |
264 |
> |
*cp = '?'; |
265 |
|
diff += *cp != *cp2; |
266 |
+ |
} |
267 |
|
if (!diff && !*cp2) |
268 |
|
return; |
269 |
|
*cp2 = '\0'; |
298 |
|
add2dispatch("spotlight", o_light); |
299 |
|
add2dispatch("glow", o_light); |
300 |
|
add2dispatch("illum", o_illum); |
301 |
< |
puts("# The following was converted from Radiance scene input"); |
301 |
> |
puts("# The following was converted from RADIANCE scene input"); |
302 |
|
if (hasmult) |
303 |
|
printf("xf -s %.4e\n", unit_mult); |
304 |
|
printf("o %s\n", curobj); |
310 |
|
puts("o"); |
311 |
|
if (hasmult) |
312 |
|
puts("xf"); |
313 |
< |
puts("# End of data converted from Radiance scene input"); |
313 |
> |
puts("# End of data converted from RADIANCE scene input"); |
314 |
|
lu_done(&rdispatch); |
315 |
|
lu_done(&rmats); |
316 |
|
lu_done(&vertab); |
390 |
|
|
391 |
|
|
392 |
|
int |
393 |
+ |
o_unsupported(mod, typ, id, fa) /* mark unsupported primitive */ |
394 |
+ |
char *mod, *typ, *id; |
395 |
+ |
FUNARGS *fa; |
396 |
+ |
{ |
397 |
+ |
register int i; |
398 |
+ |
|
399 |
+ |
fputs("\n# Unsupported RADIANCE primitive:\n", stdout); |
400 |
+ |
printf("# %s %s %s", mod, typ, id); |
401 |
+ |
printf("\n# %d", fa->nsargs); |
402 |
+ |
for (i = 0; i < fa->nsargs; i++) |
403 |
+ |
printf(" %s", fa->sarg[i]); |
404 |
+ |
#ifdef IARGS |
405 |
+ |
printf("\n# %d", fa->niargs); |
406 |
+ |
for (i = 0; i < fa->niargs; i++) |
407 |
+ |
printf(" %ld", fa->iarg[i]); |
408 |
+ |
#else |
409 |
+ |
fputs("\n# 0", stdout); |
410 |
+ |
#endif |
411 |
+ |
printf("\n# %d", fa->nfargs); |
412 |
+ |
for (i = 0; i < fa->nfargs; i++) |
413 |
+ |
printf(" %g", fa->farg[i]); |
414 |
+ |
fputs("\n\n", stdout); |
415 |
+ |
return(0); |
416 |
+ |
} |
417 |
+ |
|
418 |
+ |
|
419 |
+ |
int |
420 |
|
o_face(mod, typ, id, fa) /* print out a polygon */ |
421 |
|
char *mod, *typ, *id; |
422 |
|
FUNARGS *fa; |
423 |
|
{ |
424 |
< |
char entbuf[512]; |
424 |
> |
char entbuf[2048], *linestart; |
425 |
|
register char *cp; |
426 |
|
register int i; |
427 |
|
|
429 |
|
return(-1); |
430 |
|
setmat(mod); |
431 |
|
setobj(id); |
432 |
< |
cp = entbuf; |
432 |
> |
cp = linestart = entbuf; |
433 |
|
*cp++ = 'f'; |
434 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
435 |
|
*cp++ = ' '; |
436 |
+ |
if (cp - linestart > 72) { |
437 |
+ |
*cp++ = '\\'; *cp++ = '\n'; |
438 |
+ |
linestart = cp; |
439 |
+ |
*cp++ = ' '; *cp++ = ' '; |
440 |
+ |
} |
441 |
|
getvertid(cp, fa->farg + i); |
442 |
|
while (*cp) |
443 |
|
cp++; |
567 |
|
putchar('\n'); |
568 |
|
clrverts(); /* vertex id's no longer reliable */ |
569 |
|
return(0); |
536 |
– |
} |
537 |
– |
|
538 |
– |
|
539 |
– |
int |
540 |
– |
o_source(mod, typ, id, fa) /* convert a source */ |
541 |
– |
char *mod, *typ, *id; |
542 |
– |
FUNARGS *fa; |
543 |
– |
{ |
544 |
– |
return(0); /* there is no MGF equivalent! */ |
570 |
|
} |
571 |
|
|
572 |
|
|