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

Comparing ray/src/cv/mgf2rad.c (file contents):
Revision 2.5 by greg, Fri Jul 1 10:20:19 1994 UTC vs.
Revision 2.13 by greg, Tue Mar 7 12:18:15 1995 UTC

# Line 17 | Line 17 | static char SCCSid[] = "$SunId$ LBL";
17  
18   #define putv(v)         printf("%18.12g %18.12g %18.12g\n",(v)[0],(v)[1],(v)[2])
19  
20 + #define invert          (xf_context != NULL && xf_context->rev)
21 +
22   double  glowdist = FHUGE;               /* glow test distance */
23  
24 < double  emult = 1.;                     /* emmitter multiplier */
24 > double  emult = 1.;                     /* emitter multiplier */
25  
26 + FILE    *matfp = stdout;                /* material output file */
27 +
28   int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph();
29   char    *material(), *object(), *addarg();
30  
# Line 37 | Line 41 | char   *argv[];
41          mg_ehand[MG_E_CMIX] = c_hcolor;
42          mg_ehand[MG_E_CSPEC] = c_hcolor;
43          mg_ehand[MG_E_CXY] = c_hcolor;
44 +        mg_ehand[MG_E_CCT] = c_hcolor;
45          mg_ehand[MG_E_CYL] = r_cyl;
46          mg_ehand[MG_E_ED] = c_hmaterial;
47          mg_ehand[MG_E_FACE] = r_face;
# Line 48 | Line 53 | char   *argv[];
53          mg_ehand[MG_E_RD] = c_hmaterial;
54          mg_ehand[MG_E_RING] = r_ring;
55          mg_ehand[MG_E_RS] = c_hmaterial;
56 +        mg_ehand[MG_E_SIDES] = c_hmaterial;
57          mg_ehand[MG_E_SPH] = r_sph;
58          mg_ehand[MG_E_TD] = c_hmaterial;
59          mg_ehand[MG_E_TS] = c_hmaterial;
# Line 60 | Line 66 | char   *argv[];
66                  printf(" %s", argv[i]);
67                  switch (argv[i][1]) {
68                  case 'g':                       /* glow distance (meters) */
69 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
69 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
70                                  goto userr;
71                          glowdist = atof(argv[++i]);
72                          printf(" %s", argv[i]);
73                          break;
74                  case 'e':                       /* emitter multiplier */
75 <                        if (argv[i][2] || badarg(argc-i, argv+i, "f"))
75 >                        if (argv[i][2] || badarg(argc-i-1, argv+i+1, "f"))
76                                  goto userr;
77                          emult = atof(argv[++i]);
78                          printf(" %s", argv[i]);
79                          break;
80 +                case 'm':                       /* materials file */
81 +                        matfp = fopen(argv[++i], "a");
82 +                        if (matfp == NULL) {
83 +                                fprintf(stderr, "%s: cannot append\n", argv[i]);
84 +                                exit(1);
85 +                        }
86 +                        printf(" %s", argv[i]);
87 +                        break;
88                  default:
89                          goto userr;
90                  }
# Line 88 | Line 102 | char   *argv[];
102                  }
103          exit(0);
104   userr:
105 <        fprintf(stderr, "Usage: %s [-g dist][-m mult] [file.mgf] ..\n",
105 >        fprintf(stderr, "Usage: %s [-g dist][-e mult][-m matf] [file.mgf] ..\n",
106                          argv[0]);
107          exit(1);
108   }
# Line 99 | Line 113 | r_comment(ac, av)              /* repeat a comment verbatim */
113   register int    ac;
114   register char   **av;
115   {
116 <        fputs("\n#", stdout);   /* use Radiance comment character */
116 >        putchar('#');           /* use Radiance comment character */
117          while (--ac) {
118                  putchar(' ');
119                  fputs(*++av, stdout);
# Line 292 | Line 306 | char   **av;
306          printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces);
307          printf("0\n0\n%d\n", 3*(ac-1));
308          for (i = 1; i < ac; i++) {
309 <                if ((cv = c_getvert(av[i])) == NULL)
309 >                if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL)
310                          return(MG_EUNDEF);
311                  xf_xfmpoint(v, cv->p);
312                  putv(v);
# Line 366 | Line 380 | char   *mat, *vn1, *vn2, *vn3;
380          FVECT   n1, n2, n3;
381          register int    i;
382                          /* the following is repeat code, so assume it's OK */
369        cv1 = c_getvert(vn1);
383          cv2 = c_getvert(vn2);
384 <        cv3 = c_getvert(vn3);
384 >        if (invert) {
385 >                cv3 = c_getvert(vn1);
386 >                cv1 = c_getvert(vn3);
387 >        } else {
388 >                cv1 = c_getvert(vn1);
389 >                cv3 = c_getvert(vn3);
390 >        }
391          xf_xfmpoint(v1, cv1->p);
392          xf_xfmpoint(v2, cv2->p);
393          xf_xfmpoint(v3, cv3->p);
# Line 409 | Line 428 | material()                     /* get (and print) current material */
428          c_cmaterial->clock = 0;
429          if (c_cmaterial->ed > .1) {     /* emitter */
430                  cvtcolor(radrgb, &c_cmaterial->ed_c,
431 <                                emult*c_cmaterial->ed/WHTEFFICACY);
431 >                                emult*c_cmaterial->ed/(PI*WHTEFFICACY));
432                  if (glowdist < FHUGE) {         /* do a glow */
433 <                        printf("\nvoid glow %s\n0\n0\n", mname);
434 <                        printf("4 %f %f %f %f\n", colval(radrgb,RED),
433 >                        fprintf(matfp, "\nvoid glow %s\n0\n0\n", mname);
434 >                        fprintf(matfp, "4 %f %f %f %f\n", colval(radrgb,RED),
435                                          colval(radrgb,GRN),
436                                          colval(radrgb,BLU), glowdist);
437                  } else {
438 <                        printf("\nvoid light %s\n0\n0\n", mname);
439 <                        printf("3 %f %f %f\n", colval(radrgb,RED),
438 >                        fprintf(matfp, "\nvoid light %s\n0\n0\n", mname);
439 >                        fprintf(matfp, "3 %f %f %f\n", colval(radrgb,RED),
440                                          colval(radrgb,GRN),
441                                          colval(radrgb,BLU));
442                  }
# Line 425 | Line 444 | material()                     /* get (and print) current material */
444          }
445          d = c_cmaterial->rd + c_cmaterial->td +
446                          c_cmaterial->rs + c_cmaterial->ts;
447 <        if (d <= 0. | d >= 1.)
447 >        if (d < 0. | d > 1.)
448                  return(NULL);
449                                          /* check for trans */
450          if (c_cmaterial->td > .01 || c_cmaterial->ts > .01) {
451                  double  ts, a5, a6;
452  
453 <                ts = sqrt(c_cmaterial->ts);     /* because we use 2 sides */
453 >                if (c_cmaterial->sided) {
454 >                        ts = sqrt(c_cmaterial->ts);     /* approximate */
455 >                        a5 = .5;
456 >                } else {
457 >                        ts = c_cmaterial->ts;
458 >                        a5 = 1.;
459 >                }
460                                                  /* average colors */
461                  d = c_cmaterial->rd + c_cmaterial->td + ts;
462                  cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
# Line 441 | Line 466 | material()                     /* get (and print) current material */
466                  addcolor(radrgb, c2);
467                  if (c_cmaterial->rs + ts > .0001)
468                          a5 = (c_cmaterial->rs*c_cmaterial->rs_a +
469 <                                        ts*.5*c_cmaterial->ts_a) /
469 >                                        ts*a5*c_cmaterial->ts_a) /
470                                          (c_cmaterial->rs + ts);
471                  a6 = (c_cmaterial->td + ts) /
472                                  (c_cmaterial->rd + c_cmaterial->td + ts);
473 <                if (a6 < .999) {
473 >                if (a6 < .999)
474                          d = c_cmaterial->rd/(1. - c_cmaterial->rs)/(1. - a6);
475 <                        scalecolor(radrgb, d);
476 <                }
477 <                printf("\nvoid trans %s\n0\n0\n", mname);
478 <                printf("7 %f %f %f\n", colval(radrgb,RED),
475 >                else
476 >                        d = c_cmaterial->td + ts;
477 >                scalecolor(radrgb, d);
478 >                fprintf(matfp, "\nvoid trans %s\n0\n0\n", mname);
479 >                fprintf(matfp, "7 %f %f %f\n", colval(radrgb,RED),
480                                  colval(radrgb,GRN), colval(radrgb,BLU));
481 <                printf("\t%f %f %f %f\n", c_cmaterial->rs, a5, a6,
481 >                fprintf(matfp, "\t%f %f %f %f\n", c_cmaterial->rs, a5, a6,
482                                  ts/(ts + c_cmaterial->td));
483                  return(mname);
484          }
485                                          /* check for plastic */
486 <        if (c_cmaterial->rs < .01 || c_isgrey(&c_cmaterial->rs_c)) {
487 <                if (c_cmaterial->rs > .999)
488 <                        cvtcolor(radrgb, &c_cmaterial->rd_c, 1.);
463 <                else
464 <                        cvtcolor(radrgb, &c_cmaterial->rd_c,
486 >        if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 ||
487 >                                        c_isgrey(&c_cmaterial->rs_c))) {
488 >                cvtcolor(radrgb, &c_cmaterial->rd_c,
489                                          c_cmaterial->rd/(1.-c_cmaterial->rs));
490 <                printf("\nvoid plastic %s\n0\n0\n", mname);
491 <                printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
490 >                fprintf(matfp, "\nvoid plastic %s\n0\n0\n", mname);
491 >                fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED),
492                                  colval(radrgb,GRN), colval(radrgb,BLU),
493                                  c_cmaterial->rs, c_cmaterial->rs_a);
494                  return(mname);
495          }
496                                          /* else it's metal */
497 <        d = c_cmaterial->rd + c_cmaterial->rs;  /* average colors */
498 <        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd/d);
499 <        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs/d);
497 >                                                /* average colors */
498 >        cvtcolor(radrgb, &c_cmaterial->rd_c, c_cmaterial->rd);
499 >        cvtcolor(c2, &c_cmaterial->rs_c, c_cmaterial->rs);
500          addcolor(radrgb, c2);
501 <        if (c_cmaterial->rs < .999) {
502 <                d = c_cmaterial->rd/(1. - c_cmaterial->rs);
479 <                scalecolor(radrgb, d);
480 <        }
481 <        printf("\nvoid metal %s\n0\n0\n", mname);
482 <        printf("5 %f %f %f %f %f\n", colval(radrgb,RED),
501 >        fprintf(matfp, "\nvoid metal %s\n0\n0\n", mname);
502 >        fprintf(matfp, "5 %f %f %f %f %f\n", colval(radrgb,RED),
503                          colval(radrgb,GRN), colval(radrgb,BLU),
504 <                        c_cmaterial->rs, c_cmaterial->rs_a);
504 >                        c_cmaterial->rs/(c_cmaterial->rd + c_cmaterial->rs),
505 >                        c_cmaterial->rs_a);
506          return(mname);
507   }
508  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines