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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines