ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/rad2mgf.c
(Generate patch)

Comparing ray/src/cv/rad2mgf.c (file contents):
Revision 2.1 by greg, Thu Jul 7 17:30:33 1994 UTC vs.
Revision 2.24 by greg, Wed Dec 28 18:35:42 2005 UTC

# Line 1 | Line 1
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>
8 > #include <ctype.h>
9   #include <string.h>
10 < #include "fvect.h"
10 > #include <stdio.h>
11 >
12 > #include "platform.h"
13 > #include "rtmath.h"
14 > #include "rtio.h"
15 > #include "rtprocess.h"
16   #include "object.h"
17   #include "color.h"
18   #include "lookup.h"
19  
20 < int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder();
19 < int     o_instance(), o_source(), o_illum();
20 < int     o_plastic(), o_metal(), o_glass(), o_mirror(), o_trans(), o_light();
20 > #define C_1SIDEDTHICK   0.005
21  
22 extern void     free();
23 extern char     *malloc();
22  
23   LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */
24  
25   LUTAB   rdispatch = LU_SINIT(NULL,NULL);        /* function dispatch table */
26  
27 < char    curmat[80];             /* current material */
27 > char    curmat[80];                             /* current material */
28 > char    curobj[128] = "Untitled";               /* current object name */
29  
30 < double  unit_mult = 1.;         /* units multiplier */
30 > double  unit_mult = 1.;                         /* units multiplier */
31  
32 + #define hasmult         (unit_mult < .999 || unit_mult > 1.001)
33  
34 < main(argc, argv)
35 < int     argc;
36 < char    **argv;
34 > /*
35 > * Stuff for tracking and reusing vertices:
36 > */
37 >
38 > char    VKFMT[] = "%+16.9e %+16.9e %+16.9e";
39 > #define VKLEN           64
40 >
41 > #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
42 >
43 > #define NVERTS          256
44 >
45 > long    vclock;         /* incremented at each vertex request */
46 >
47 > struct vert {
48 >        long    lused;          /* when last used (0 if unassigned) */
49 >        FVECT   p;              /* track point position only */
50 > } vert[NVERTS];         /* our vertex cache */
51 >
52 > LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
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);
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
83 > main(
84 >        int     argc,
85 >        char    **argv
86 > )
87   {
88          int     i;
89  
# Line 57 | Line 107 | char   **argv;
107                                  goto unkopt;
108                          }
109                          break;
110 +                default:
111 +                        goto unkopt;
112                  }
113          init();
114          if (i >= argc)
# Line 72 | Line 124 | unkopt:
124   }
125  
126  
127 < rad2mgf(inp)            /* convert a Radiance file to MGF */
128 < char    *inp;
127 > void
128 > rad2mgf(                /* convert a Radiance file to MGF */
129 >        char    *inp
130 > )
131   {
132 < #define mod     buf
79 < #define typ     (buf+128)
80 < #define id      (buf+256)
81 < #define alias   (buf+384)
82 <        char    buf[512];
132 >        char  mod[128], typ[32], id[128], alias[128];
133          FUNARGS fa;
134          register FILE   *fp;
135          register int    c;
136  
137          if (inp == NULL) {
138 <                inp = "the standard input";
138 >                inp = "standard input";
139                  fp = stdin;
140          } else if (inp[0] == '!') {
141                  if ((fp = popen(inp+1, "r")) == NULL) {
# Line 118 | Line 168 | char   *inp;
168                          break;
169                  default:                /* Radiance primitive */
170                          ungetc(c, fp);
171 <                        if (fscanf(fp, "%s %s %s", mod, typ, id) != 3) {
171 >                        if (fgetword(mod, sizeof(mod), fp) == NULL ||
172 >                                        fgetword(typ, sizeof(typ), fp) == NULL ||
173 >                                        fgetword(id, sizeof(id), fp) == NULL) {
174                                  fputs(inp, stderr);
175                                  fputs(": unexpected EOF\n", stderr);
176                                  exit(1);
177                          }
178 +                        unspace(mod);
179 +                        unspace(id);
180                          if (!strcmp(typ, "alias")) {
181                                  strcpy(alias, "EOF");
182 <                                fscanf(fp, "%s", alias);
182 >                                fgetword(alias, sizeof(alias), fp);
183 >                                unspace(alias);
184                                  newmat(id, alias);
185                          } else {
186                                  if (!readfargs(&fa, fp)) {
# Line 144 | Line 199 | char   *inp;
199                  pclose(fp);
200          else
201                  fclose(fp);
147 #undef mod
148 #undef typ
149 #undef id
150 #undef alias
202   }
203  
204  
205 < cvtprim(inp, mod, typ, id, fa)  /* process Radiance primitive */
206 < char    *inp, *mod, *typ, *id;
207 < FUNARGS *fa;
205 > void
206 > unspace(        /* replace spaces with underscores in s */
207 >        char *s
208 > )
209   {
210 +        while (*s) {
211 +                if (isspace(*s))
212 +                        *s = '_';
213 +                ++s;
214 +        }
215 + }
216 +
217 +
218 + void
219 + cvtprim(        /* process Radiance primitive */
220 +        char    *inp,
221 +        char    *mod,
222 +        char    *typ,
223 +        char    *id,
224 +        FUNARGS *fa
225 + )
226 + {
227          int     (*df)();
228  
229          df = (int (*)())lu_find(&rdispatch, typ)->data;
230          if (df != NULL) {                               /* convert */
231                  if ((*df)(mod, typ, id, fa) < 0) {
232 <                        fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id);
232 >                        fprintf(stderr, "%s: bad %s \"%s\"\n", "rad2mgf", typ, id);
233                          exit(1);
234                  }
235 <        } else if (lu_find(&rmats, mod)->data != NULL)  /* make alias */
236 <                newmat(id, mod);
235 >        } else {                                        /* unsupported */
236 >                o_unsupported(mod, typ, id, fa);
237 >                if (lu_find(&rmats, mod)->data != NULL) /* make alias */
238 >                        newmat(id, mod);
239 >        }
240   }
241  
242  
243 < newmat(id, alias)               /* add a modifier to the alias list */
244 < char    *id;
245 < char    *alias;
243 > void
244 > newmat(         /* add a modifier to the alias list */
245 >        char    *id,
246 >        char    *alias
247 > )
248   {
249          register LUENT  *lp, *lpa;
250  
# Line 204 | Line 278 | memerr:
278   }
279  
280  
281 < setmat(id)                      /* set material to this one */
282 < char    *id;
281 > void
282 > setmat(                 /* set material to this one */
283 >        char    *id
284 > )
285   {
286          if (!strcmp(id, curmat))        /* already set? */
287                  return;
288 +        if (!strcmp(id, VOIDID))        /* cannot set */
289 +                return;
290          printf("m %s\n", id);
291          strcpy(curmat, id);
292   }
293  
294  
295 < init()                  /* initialize dispatch table and output */
295 > void
296 > setobj(                 /* set object name to this one */
297 >        char    *id
298 > )
299   {
300 +        register char   *cp, *cp2;
301 +        char    *end = NULL;
302 +        int     diff = 0;
303 +                                /* use all but final suffix */
304 +        for (cp = id; *cp; cp++)
305 +                if (*cp == '.')
306 +                        end = cp;
307 +        if (end == NULL)
308 +                end = cp;
309 +                                /* copy to current object */
310 +        cp2 = curobj;
311 +        if (!isalpha(*id)) {    /* start with letter */
312 +                diff = *cp2 != 'O';
313 +                *cp2++ = 'O';
314 +        }
315 +        for (cp = id; cp < end; *cp2++ = *cp++) {
316 +                if ((*cp < '!') | (*cp > '~'))  /* limit to visible chars */
317 +                        *cp = '?';
318 +                diff += *cp != *cp2;
319 +        }
320 +        if (!diff && !*cp2)
321 +                return;
322 +        *cp2 = '\0';
323 +        fputs("o\no ", stdout);
324 +        puts(curobj);
325 + }
326 +
327 +
328 + void
329 + init(void)                      /* initialize dispatch table and output */
330 + {
331 +        lu_init(&vertab, NVERTS);
332          lu_init(&rdispatch, 22);
333          add2dispatch("polygon", o_face);
334          add2dispatch("cone", o_cone);
# Line 226 | Line 339 | init()                 /* initialize dispatch table and output */
339          add2dispatch("tube", o_cylinder);
340          add2dispatch("ring", o_ring);
341          add2dispatch("instance", o_instance);
342 +        add2dispatch("mesh", o_instance);
343          add2dispatch("plastic", o_plastic);
344          add2dispatch("plastic2", o_plastic);
345          add2dispatch("metal", o_metal);
346          add2dispatch("metal2", o_metal);
347          add2dispatch("glass", o_glass);
348 +        add2dispatch("dielectric", o_dielectric);
349          add2dispatch("trans", o_trans);
350          add2dispatch("trans2", o_trans);
351          add2dispatch("mirror", o_mirror);
# Line 238 | Line 353 | init()                 /* initialize dispatch table and output */
353          add2dispatch("spotlight", o_light);
354          add2dispatch("glow", o_light);
355          add2dispatch("illum", o_illum);
356 <        puts("# The following was converted from Radiance scene input");
357 <        if (unit_mult < .999 || unit_mult > 1.001)
356 >        puts("# The following was converted from RADIANCE scene input");
357 >        if (hasmult)
358                  printf("xf -s %.4e\n", unit_mult);
359 +        printf("o %s\n", curobj);
360   }
361  
362  
363 < uninit()                        /* mark end of MGF file */
363 > void
364 > uninit(void)                    /* mark end of MGF file */
365   {
366 <        if (unit_mult < .999 || unit_mult > 1.001)
366 >        puts("o");
367 >        if (hasmult)
368                  puts("xf");
369 <        puts("# End of data converted from Radiance scene input");
369 >        puts("# End of data converted from RADIANCE scene input");
370          lu_done(&rdispatch);
371          lu_done(&rmats);
372 +        lu_done(&vertab);
373   }
374  
375  
376 < add2dispatch(name, func)        /* add function to dispatch table */
377 < char    *name;
259 < int     (*func)();
376 > void
377 > clrverts(void)                  /* clear vertex table */
378   {
379 +        register int    i;
380 +
381 +        lu_done(&vertab);
382 +        for (i = 0; i < NVERTS; i++)
383 +                vert[i].lused = 0;
384 +        lu_init(&vertab, NVERTS);
385 + }
386 +
387 +
388 + void
389 + add2dispatch(   /* add function to dispatch table */
390 +        char    *name,
391 +        int     (*func)()
392 + )
393 + {
394          register LUENT  *lp;
395  
396          lp = lu_find(&rdispatch, name);
# Line 271 | Line 404 | int    (*func)();
404   }
405  
406  
274 char    VKFMT[] = "%+1.9e %+1.9e %+1.9e";
275 #define VKLEN           64
276
277 #define mkvkey(k,v)     sprintf(k, VKFMT, (v)[0], (v)[1], (v)[2])
278
279 #define NVERTS          256
280
281 long    clock;          /* incremented at each vertex request */
282
283 struct vert {
284        long    lused;          /* when last used (0 if unassigned) */
285        FVECT   p;              /* track point position only */
286 } vert[NVERTS];
287
288 LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */
289
290
407   char *
408 < getvertid(vp)                   /* get/set vertex ID for this point */
409 < FVECT   vp;
408 > getvertid(              /* get/set vertex ID for this point */
409 >        char    *vname,
410 >        FVECT   vp
411 > )
412   {
413 <        static char     vname[6];
296 <        char    vkey[VKLEN];
413 >        static char     vkey[VKLEN];
414          register LUENT  *lp;
415          register int    i, vndx;
416  
417 <        if (!vertab.tsiz && !lu_init(&vertab, NVERTS))
301 <                goto memerr;
302 <        clock++;                        /* increment counter */
417 >        vclock++;                       /* increment counter */
418          mkvkey(vkey, vp);
419          if ((lp = lu_find(&vertab, vkey)) == NULL)
420                  goto memerr;
# Line 319 | Line 434 | FVECT  vp;
434                          mkvkey(vkey, vert[vndx].p);
435                          lu_delete(&vertab, vkey);
436                  }
437 <                vert[vndx].lused = clock;                       /* assign it */
438 <                VCOPY(vert[vndx].p, vp);
324 <                printf("v v%d =\np %.15g %.15g %.15g\n",        /* print it */
437 >                VCOPY(vert[vndx].p, vp);                        /* assign it */
438 >                printf("v v%d =\n\tp %.15g %.15g %.15g\n",      /* print it */
439                                  vndx, vp[0], vp[1], vp[2]);
440                  lp->data = (char *)&vert[vndx];                 /* set it */
441          } else
442                  vndx = (struct vert *)lp->data - vert;
443 +        vert[vndx].lused = vclock;              /* record this use */
444          sprintf(vname, "v%d", vndx);
445          return(vname);
446   memerr:
# Line 335 | Line 450 | memerr:
450  
451  
452   int
453 < o_face(mod, typ, id, fa)                /* print out a polygon */
454 < char    *mod, *typ, *id;
455 < FUNARGS *fa;
453 > o_unsupported(          /* mark unsupported primitive */
454 >        char    *mod,
455 >        char    *typ,
456 >        char    *id,
457 >        FUNARGS *fa
458 > )
459   {
342        char    entbuf[512];
343        register char   *cp1, *cp2;
460          register int    i;
461  
462 <        if (fa->nfargs < 9 | fa->nfargs % 3)
462 >        fputs("\n# Unsupported RADIANCE primitive:\n", stdout);
463 >        printf("# %s %s %s", mod, typ, id);
464 >        printf("\n# %d", fa->nsargs);
465 >        for (i = 0; i < fa->nsargs; i++)
466 >                printf(" %s", fa->sarg[i]);
467 > #ifdef IARGS
468 >        printf("\n# %d", fa->niargs);
469 >        for (i = 0; i < fa->niargs; i++)
470 >                printf(" %ld", fa->iarg[i]);
471 > #else
472 >        fputs("\n# 0", stdout);
473 > #endif
474 >        printf("\n# %d", fa->nfargs);
475 >        for (i = 0; i < fa->nfargs; i++)
476 >                printf(" %g", fa->farg[i]);
477 >        fputs("\n\n", stdout);
478 >        return(0);
479 > }
480 >
481 >
482 > int
483 > o_face(         /* print out a polygon */
484 >        char    *mod,
485 >        char    *typ,
486 >        char    *id,
487 >        FUNARGS *fa
488 > )
489 > {
490 >        char    entbuf[2048], *linestart;
491 >        register char   *cp;
492 >        register int    i;
493 >
494 >        if ((fa->nfargs < 9) | (fa->nfargs % 3))
495                  return(-1);
496          setmat(mod);
497 <        printf("o %s\n", id);
498 <        cp1 = entbuf;
499 <        *cp1++ = 'f';
497 >        setobj(id);
498 >        cp = linestart = entbuf;
499 >        *cp++ = 'f';
500          for (i = 0; i < fa->nfargs; i += 3) {
501 <                cp2 = getvertid(fa->farg + i);
502 <                *cp1++ = ' ';
503 <                while ((*cp1 = *cp2++))
504 <                        cp1++;
501 >                *cp++ = ' ';
502 >                if (cp - linestart > 72) {
503 >                        *cp++ = '\\'; *cp++ = '\n';
504 >                        linestart = cp;
505 >                        *cp++ = ' '; *cp++ = ' ';
506 >                }
507 >                getvertid(cp, fa->farg + i);
508 >                while (*cp)
509 >                        cp++;
510          }
511          puts(entbuf);
359        puts("o");
512          return(0);
513   }
514  
515  
516   int
517 < o_cone(mod, typ, id, fa)        /* print out a cone */
518 < char    *mod, *typ, *id;
519 < register FUNARGS        *fa;
517 > o_cone( /* print out a cone */
518 >        char    *mod,
519 >        char    *typ,
520 >        char    *id,
521 >        register FUNARGS        *fa
522 > )
523   {
524 +        char    v1[6], v2[6];
525 +
526          if (fa->nfargs != 8)
527                  return(-1);
528          setmat(mod);
529 <        printf("o %s\n", id);
530 <        printf("v cv1 =\np %.12g %.12g %.12g\n",
531 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
375 <        printf("v cv2 =\np %.12g %.12g %.12g\n",
376 <                        fa->farg[3], fa->farg[4], fa->farg[5]);
529 >        setobj(id);
530 >        getvertid(v1, fa->farg);
531 >        getvertid(v2, fa->farg + 3);
532          if (typ[1] == 'u')                      /* cup -> inverted cone */
533 <                printf("cone cv1 %.12g cv2 %.12g\n",
534 <                                -fa->farg[6], -fa->farg[7]);
533 >                printf("cone %s %.12g %s %.12g\n",
534 >                                v1, -fa->farg[6], v2, -fa->farg[7]);
535          else
536 <                printf("cone cv1 %.12g cv2 %.12g\n",
537 <                                fa->farg[6], fa->farg[7]);
383 <        puts("o");
536 >                printf("cone %s %.12g %s %.12g\n",
537 >                                v1, fa->farg[6], v2, fa->farg[7]);
538          return(0);
539   }
540  
541  
542   int
543 < o_sphere(mod, typ, id, fa)      /* print out a sphere */
544 < char    *mod, *typ, *id;
545 < register FUNARGS        *fa;
543 > o_sphere(       /* print out a sphere */
544 >        char    *mod,
545 >        char    *typ,
546 >        char    *id,
547 >        register FUNARGS        *fa
548 > )
549   {
550 +        char    cent[6];
551 +
552          if (fa->nfargs != 4)
553                  return(-1);
554          setmat(mod);
555 <        printf("o %s\n", id);
556 <        printf("v cent =\np %.12g %.12g %.12g\n",
557 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
399 <        printf("sph cent %.12g\n", typ[0]=='b' ? -fa->farg[3] : fa->farg[3]);
400 <        puts("o");
555 >        setobj(id);
556 >        printf("sph %s %.12g\n", getvertid(cent, fa->farg),
557 >                        typ[0]=='b' ? -fa->farg[3] : fa->farg[3]);
558          return(0);
559   }
560  
561  
562   int
563 < o_cylinder(mod, typ, id, fa)    /* print out a cylinder */
564 < char    *mod, *typ, *id;
565 < register FUNARGS        *fa;
563 > o_cylinder(     /* print out a cylinder */
564 >        char    *mod,
565 >        char    *typ,
566 >        char    *id,
567 >        register FUNARGS        *fa
568 > )
569   {
570 +        char    v1[6], v2[6];
571 +
572          if (fa->nfargs != 7)
573                  return(-1);
574          setmat(mod);
575 <        printf("o %s\n", id);
576 <        printf("v cv1 =\np %.12g %.12g %.12g\n",
577 <                        fa->farg[0], fa->farg[1], fa->farg[2]);
578 <        printf("v cv2 =\np %.12g %.12g %.12g\n",
579 <                        fa->farg[3], fa->farg[4], fa->farg[5]);
418 <        printf("cyl cv1 %.12g cv2\n",
419 <                        typ[0]=='t' ? -fa->farg[6] : fa->farg[6]);
420 <        puts("o");
575 >        setobj(id);
576 >        getvertid(v1, fa->farg);
577 >        getvertid(v2, fa->farg + 3);
578 >        printf("cyl %s %.12g %s\n", v1,
579 >                        typ[0]=='t' ? -fa->farg[6] : fa->farg[6], v2);
580          return(0);
581   }
582  
583  
584   int
585 < o_ring(mod, typ, id, fa)        /* print out a ring */
586 < char    *mod, *typ, *id;
587 < register FUNARGS        *fa;
585 > o_ring( /* print out a ring */
586 >        char    *mod,
587 >        char    *typ,
588 >        char    *id,
589 >        register FUNARGS        *fa
590 > )
591   {
592          if (fa->nfargs != 8)
593                  return(-1);
594          setmat(mod);
595 <        printf("o %s\n", id);
596 <        printf("v cent =\np %.12g %.12g %.12g\n",
595 >        setobj(id);
596 >        printf("v cent =\n\tp %.12g %.12g %.12g\n",
597                          fa->farg[0], fa->farg[1], fa->farg[2]);
598 <        printf("n %.12g %.12g %.12g\n",
598 >        printf("\tn %.12g %.12g %.12g\n",
599                          fa->farg[3], fa->farg[4], fa->farg[5]);
600          if (fa->farg[6] < fa->farg[7])
601                  printf("ring cent %.12g %.12g\n",
# Line 441 | Line 603 | register FUNARGS       *fa;
603          else
604                  printf("ring cent %.12g %.12g\n",
605                                  fa->farg[7], fa->farg[6]);
444        puts("o");
606          return(0);
607   }
608  
609  
610   int
611 < o_instance(mod, typ, id, fa)    /* convert an instance */
612 < char    *mod, *typ, *id;
613 < FUNARGS *fa;
611 > o_instance(     /* convert an instance (or mesh) */
612 >        char    *mod,
613 >        char    *typ,
614 >        char    *id,
615 >        FUNARGS *fa
616 > )
617   {
618 <        return(0);              /* this is too damned difficult! */
618 >        register int    i;
619 >        register char   *cp;
620 >        char    *start = NULL, *end = NULL;
621 >        /*
622 >         * We don't really know how to do this, so we just create
623 >         * a reference to an undefined MGF file and it's the user's
624 >         * responsibility to create this file and put the appropriate
625 >         * stuff into it.
626 >         */
627 >        if (fa->nsargs < 1)
628 >                return(-1);
629 >        setmat(mod);                    /* only works if surfaces are void */
630 >        setobj(id);
631 >        for (cp = fa->sarg[0]; *cp; cp++)       /* construct MGF file name */
632 >                if (*cp == '/')
633 >                        start = cp+1;
634 >                else if (*cp == '.')
635 >                        end = cp;
636 >        if (start == NULL)
637 >                start = fa->sarg[0];
638 >        if (end == NULL || start >= end)
639 >                end = cp;
640 >        fputs("i ", stdout);                    /* print include entity */
641 >        for (cp = start; cp < end; cp++)
642 >                putchar(*cp);
643 >        fputs(".mgf", stdout);                  /* add MGF suffix */
644 >        for (i = 1; i < fa->nsargs; i++) {      /* add transform */
645 >                putchar(' ');
646 >                fputs(fa->sarg[i], stdout);
647 >        }
648 >        putchar('\n');
649 >        clrverts();                     /* vertex id's no longer reliable */
650 >        return(0);
651   }
652  
653  
654   int
655 < o_source(mod, typ, id, fa)      /* convert a source */
656 < char    *mod, *typ, *id;
657 < FUNARGS *fa;
655 > o_illum(        /* convert an illum material */
656 >        char    *mod,
657 >        char    *typ,
658 >        char    *id,
659 >        FUNARGS *fa
660 > )
661   {
463        return(0);              /* there is no MGF equivalent! */
464 }
465
466
467 int
468 o_illum(mod, typ, id, fa)       /* convert an illum material */
469 char    *mod, *typ, *id;
470 FUNARGS *fa;
471 {
662          if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) {
663                  newmat(id, fa->sarg[0]);        /* just create alias */
664                  return(0);
665          }
666                                          /* else create invisible material */
667          newmat(id, NULL);
668 <        puts("ts 1 0");
668 >        puts("\tts 1 0");
669          return(0);
670   }
671  
672  
673   int
674 < o_plastic(mod, typ, id, fa)     /* convert a plastic material */
675 < char    *mod, *typ, *id;
676 < register FUNARGS        *fa;
674 > o_plastic(      /* convert a plastic material */
675 >        char    *mod,
676 >        char    *typ,
677 >        char    *id,
678 >        register FUNARGS        *fa
679 > )
680   {
681          COLOR   cxyz, rrgb;
682          double  d;
# Line 493 | Line 686 | register FUNARGS       *fa;
686          newmat(id, NULL);
687          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
688          rgb_cie(cxyz, rrgb);
689 <        puts("c");                              /* put diffuse component */
689 >        puts("\tc");                            /* put diffuse component */
690          d = cxyz[0] + cxyz[1] + cxyz[2];
691          if (d > FTINY)
692 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
693 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
694 <        puts("c");                              /* put specular component */
695 <        printf("rs %.4f %.4f\n", fa->farg[3],
696 <                        typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
697 <                                        fa->farg[4]);
692 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
693 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
694 >        if (fa->farg[3] > FTINY) {              /* put specular component */
695 >                puts("\tc");
696 >                printf("\trs %.4f %.4f\n", fa->farg[3],
697 >                                typ[7]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
698 >                                                fa->farg[4]);
699 >        }
700          return(0);
701   }
702  
703  
704   int
705 < o_metal(mod, typ, id, fa)       /* convert a metal material */
706 < char    *mod, *typ, *id;
707 < register FUNARGS        *fa;
705 > o_metal(        /* convert a metal material */
706 >        char    *mod,
707 >        char    *typ,
708 >        char    *id,
709 >        register FUNARGS        *fa
710 > )
711   {
712          COLOR   cxyz, rrgb;
713          double  d;
# Line 519 | Line 717 | register FUNARGS       *fa;
717          newmat(id, NULL);
718          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
719          rgb_cie(cxyz, rrgb);
720 <        puts("c");                              /* put diffuse component */
720 >        puts("\tc");                            /* put diffuse component */
721          d = cxyz[0] + cxyz[1] + cxyz[2];
722          if (d > FTINY)
723 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
724 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
723 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
724 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3]));
725                                                  /* put specular component */
726 <        printf("rs %.4f %.4f\n", cxyz[1]*fa->farg[3],
726 >        printf("\trs %.4f %.4f\n", cxyz[1]*fa->farg[3],
727                          typ[5]=='2' ? .5*(fa->farg[4] + fa->farg[5]) :
728                                          fa->farg[4]);
729          return(0);
# Line 533 | Line 731 | register FUNARGS       *fa;
731  
732  
733   int
734 < o_glass(mod, typ, id, fa)       /* convert a glass material */
735 < char    *mod, *typ, *id;
736 < register FUNARGS        *fa;
734 > o_glass(        /* convert a glass material */
735 >        char    *mod,
736 >        char    *typ,
737 >        char    *id,
738 >        register FUNARGS        *fa
739 > )
740   {
741          COLOR   cxyz, rrgb, trgb;
742          double  nrfr = 1.52, F, d;
# Line 546 | Line 747 | register FUNARGS       *fa;
747          newmat(id, NULL);
748          if (fa->nfargs == 4)
749                  nrfr = fa->farg[3];
750 +        printf("\tir %f 0\n", nrfr);
751          F = (1. - nrfr)/(1. + nrfr);            /* use normal incidence */
752          F *= F;
753          for (i = 0; i < 3; i++) {
754 <                rrgb[i] = (1. - F)*(1. - F)/(1. - F*F*fa->farg[i]*fa->farg[i]);
553 <                trgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) /
754 >                trgb[i] = fa->farg[i] * (1. - F)*(1. - F) /
755                                  (1. - F*F*fa->farg[i]*fa->farg[i]);
756 +                rrgb[i] = F * (1. + (1. - 2.*F)*fa->farg[i]) /
757 +                                (1. - F*F*fa->farg[i]*fa->farg[i]);
758          }
759          rgb_cie(cxyz, rrgb);                    /* put reflected component */
760 <        puts("c");
760 >        puts("\tc");
761          d = cxyz[0] + cxyz[1] + cxyz[2];
762          if (d > FTINY)
763 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
764 <        printf("rs %.4f 0\n", cxyz[1]);
763 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
764 >        printf("\trs %.4f 0\n", cxyz[1]);
765          rgb_cie(cxyz, trgb);                    /* put transmitted component */
766 <        puts("c");
766 >        puts("\tc");
767          d = cxyz[0] + cxyz[1] + cxyz[2];
768          if (d > FTINY)
769 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
770 <        printf("ts %.4f 0\n", cxyz[1]);
769 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
770 >        printf("\tts %.4f 0\n", cxyz[1]);
771          return(0);
772   }
773  
774  
775   int
776 < o_mirror(mod, typ, id, fa)      /* convert a mirror material */
777 < char    *mod, *typ, *id;
778 < register FUNARGS        *fa;
776 > o_dielectric(   /* convert a dielectric material */
777 >        char    *mod,
778 >        char    *typ,
779 >        char    *id,
780 >        register FUNARGS        *fa
781 > )
782   {
783 +        COLOR   cxyz, trgb;
784 +        double  F, d;
785 +        register int    i;
786 +
787 +        if (fa->nfargs != 5)
788 +                return(-1);
789 +        newmat(id, NULL);
790 +        F = (1. - fa->farg[3])/(1. + fa->farg[3]);      /* normal incidence */
791 +        F *= F;
792 +        for (i = 0; i < 3; i++)
793 +                trgb[i] = (1. - F)*pow(fa->farg[i], C_1SIDEDTHICK/unit_mult);
794 +        printf("\tir %f 0\n", fa->farg[3]);     /* put index of refraction */
795 +        printf("\tsides 1\n");
796 +        puts("\tc");                            /* put reflected component */
797 +        printf("\trs %.4f 0\n", F);
798 +        rgb_cie(cxyz, trgb);                    /* put transmitted component */
799 +        puts("\tc");
800 +        d = cxyz[0] + cxyz[1] + cxyz[2];
801 +        if (d > FTINY)
802 +                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
803 +        printf("\tts %.4f 0\n", cxyz[1]);
804 +        return(0);
805 + }
806 +
807 +
808 + int
809 + o_mirror(       /* convert a mirror material */
810 +        char    *mod,
811 +        char    *typ,
812 +        char    *id,
813 +        register FUNARGS        *fa
814 + )
815 + {
816          COLOR   cxyz, rrgb;
817          double  d;
818  
# Line 586 | Line 825 | register FUNARGS       *fa;
825          newmat(id, NULL);
826          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
827          rgb_cie(cxyz, rrgb);
828 <        puts("c");                              /* put specular component */
828 >        puts("\tc");                            /* put specular component */
829          d = cxyz[0] + cxyz[1] + cxyz[2];
830          if (d > FTINY)
831 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
832 <        printf("rs %.4f 0\n", cxyz[1]);
831 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
832 >        printf("\trs %.4f 0\n", cxyz[1]);
833          return(0);
834   }
835  
836  
837   int
838 < o_trans(mod, typ, id, fa)       /* convert a trans material */
839 < char    *mod, *typ, *id;
840 < register FUNARGS        *fa;
838 > o_trans(        /* convert a trans material */
839 >        char    *mod,
840 >        char    *typ,
841 >        char    *id,
842 >        register FUNARGS        *fa
843 > )
844   {
845          COLOR   cxyz, rrgb;
846          double  rough, trans, tspec, d;
# Line 619 | Line 861 | register FUNARGS       *fa;
861          newmat(id, NULL);
862          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
863          rgb_cie(cxyz, rrgb);
864 <        puts("c");                              /* put transmitted diffuse */
864 >        puts("\tc");                            /* put transmitted diffuse */
865          d = cxyz[0] + cxyz[1] + cxyz[2];
866          if (d > FTINY)
867 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
868 <        printf("td %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec));
867 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
868 >        printf("\ttd %.4f\n", cxyz[1]*trans*(1. - fa->farg[3])*(1. - tspec));
869                                                  /* put transmitted specular */
870 <        printf("ts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough);
870 >        printf("\tts %.4f %.4f\n", cxyz[1]*trans*tspec*(1. - fa->farg[3]), rough);
871                                                  /* put reflected diffuse */
872 <        printf("rd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans));
873 <        puts("c");                              /* put reflected specular */
874 <        printf("rs %.4f %.4f\n", fa->farg[3], rough);
872 >        printf("\trd %.4f\n", cxyz[1]*(1. - fa->farg[3])*(1. - trans));
873 >        puts("\tc");                            /* put reflected specular */
874 >        printf("\trs %.4f %.4f\n", fa->farg[3], rough);
875          return(0);
876   }
877  
878  
879   int
880 < o_light(mod, typ, id, fa)               /* convert a light type */
881 < char    *mod, *typ, *id;
882 < register FUNARGS        *fa;
880 > o_light(                /* convert a light type */
881 >        char    *mod,
882 >        char    *typ,
883 >        char    *id,
884 >        register FUNARGS        *fa
885 > )
886   {
887          COLOR   cxyz, rrgb;
888          double  d;
# Line 648 | Line 893 | register FUNARGS       *fa;
893          rrgb[0] = fa->farg[0]; rrgb[1] = fa->farg[1]; rrgb[2] = fa->farg[2];
894          rgb_cie(cxyz, rrgb);
895          d = cxyz[0] + cxyz[1] + cxyz[2];
896 <        puts("c");
896 >        puts("\tc");
897          if (d > FTINY)
898 <                printf("cxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
899 <        printf("ed %.4g\n", cxyz[1]);
898 >                printf("\t\tcxy %.4f %.4f\n", cxyz[0]/d, cxyz[1]/d);
899 >        printf("\ted %.4g\n", cxyz[1]*(PI*WHTEFFICACY));
900          return(0);
901   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines