| 1 | – | /* Copyright (c) 1995 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 MGF (Materials and Geometry Format) to Radiance | 
| 6 |  | */ | 
| 7 |  |  | 
| 8 |  | #include <stdio.h> | 
| 9 | + | #include <stdlib.h> | 
| 10 |  | #include <math.h> | 
| 11 |  | #include <string.h> | 
| 12 |  | #include "mgflib/parser.h" | 
| 21 |  |  | 
| 22 |  | double  emult = 1.;                     /* emitter multiplier */ | 
| 23 |  |  | 
| 24 | < | FILE    *matfp = stdout;                /* material output file */ | 
| 24 | > | FILE    *matfp;                         /* material output file */ | 
| 25 |  |  | 
| 26 |  | int     r_comment(), r_cone(), r_cyl(), r_face(), r_ies(), r_ring(), r_sph(); | 
| 27 |  | char    *material(), *object(), *addarg(); | 
| 32 |  | char    *argv[]; | 
| 33 |  | { | 
| 34 |  | int     i; | 
| 35 | + |  | 
| 36 | + | matfp = stdout; | 
| 37 |  | /* print out parser version */ | 
| 38 |  | printf("## Translated from MGF Version %d.%d\n", MG_VMAJOR, MG_VMINOR); | 
| 39 |  | /* initialize dispatch table */ | 
| 296 |  | char    **av; | 
| 297 |  | { | 
| 298 |  | static int      nfaces; | 
| 299 | + | int             myi = invert; | 
| 300 |  | char    *mat; | 
| 301 |  | register int    i; | 
| 302 |  | register C_VERTEX       *cv; | 
| 308 |  | if ((mat = material()) == NULL) /* get material */ | 
| 309 |  | return(MG_EBADMAT); | 
| 310 |  | if (ac <= 5) {                          /* check for smoothing */ | 
| 311 | + | C_VERTEX        *cva[5]; | 
| 312 |  | for (i = 1; i < ac; i++) { | 
| 313 | < | if ((cv = c_getvert(av[i])) == NULL) | 
| 313 | > | if ((cva[i-1] = c_getvert(av[i])) == NULL) | 
| 314 |  | return(MG_EUNDEF); | 
| 315 | < | if (is0vect(cv->n)) | 
| 315 | > | if (is0vect(cva[i-1]->n)) | 
| 316 |  | break; | 
| 317 |  | } | 
| 318 | < | if (i == ac) {                  /* break into triangles */ | 
| 319 | < | do_tri(mat, av[1], av[2], av[3]); | 
| 318 | > | if (i < ac) | 
| 319 | > | i = ISFLAT; | 
| 320 | > | else | 
| 321 | > | i = flat_tri(cva[0]->p, cva[1]->p, cva[2]->p, | 
| 322 | > | cva[0]->n, cva[1]->n, cva[2]->n); | 
| 323 | > | if (i == DEGEN) | 
| 324 | > | return(MG_OK);          /* degenerate (error?) */ | 
| 325 | > | if (i == RVBENT) { | 
| 326 | > | myi = !myi; | 
| 327 | > | i = ISBENT; | 
| 328 | > | } else if (i == RVFLAT) { | 
| 329 | > | myi = !myi; | 
| 330 | > | i = ISFLAT; | 
| 331 | > | } | 
| 332 | > | if (i == ISBENT) {              /* smoothed triangles */ | 
| 333 | > | do_tri(mat, cva[0], cva[1], cva[2], myi); | 
| 334 |  | if (ac == 5) | 
| 335 | < | do_tri(mat, av[3], av[4], av[1]); | 
| 335 | > | do_tri(mat, cva[2], cva[3], cva[0], myi); | 
| 336 |  | return(MG_OK); | 
| 337 |  | } | 
| 338 |  | } | 
| 340 |  | printf("\n%s polygon %sf%d\n", mat, object(), ++nfaces); | 
| 341 |  | printf("0\n0\n%d\n", 3*(ac-1)); | 
| 342 |  | for (i = 1; i < ac; i++) {      /* get, transform, print each vertex */ | 
| 343 | < | if ((cv = c_getvert(av[invert ? ac-i : i])) == NULL) | 
| 343 | > | if ((cv = c_getvert(av[myi ? ac-i : i])) == NULL) | 
| 344 |  | return(MG_EUNDEF); | 
| 345 |  | xf_xfmpoint(v, cv->p); | 
| 346 |  | putv(v); | 
| 364 |  | if (ac < 2) | 
| 365 |  | return(MG_EARGC); | 
| 366 |  | /* construct output file name */ | 
| 367 | < | if ((op = strrchr(av[1], '/')) == NULL) | 
| 367 | > | if ((op = strrchr(av[1], '/')) != NULL) | 
| 368 | > | op++; | 
| 369 | > | else | 
| 370 |  | op = av[1]; | 
| 371 |  | (void)strcpy(fname, op); | 
| 372 |  | if ((op = strrchr(fname, '.')) == NULL) | 
| 414 |  | } | 
| 415 |  |  | 
| 416 |  |  | 
| 417 | < | do_tri(mat, vn1, vn2, vn3)              /* put out smoothed triangle */ | 
| 418 | < | char    *mat, *vn1, *vn2, *vn3; | 
| 417 | > | do_tri(mat, cv1, cv2, cv3, iv)          /* put out smoothed triangle */ | 
| 418 | > | char    *mat; | 
| 419 | > | C_VERTEX        *cv1, *cv2, *cv3; | 
| 420 | > | int     iv; | 
| 421 |  | { | 
| 422 |  | static int      ntris; | 
| 423 |  | BARYCCM bvecs; | 
| 424 |  | FLOAT   bcoor[3][3]; | 
| 425 | < | C_VERTEX        *cv1, *cv2, *cv3; | 
| 425 | > | C_VERTEX        *cvt; | 
| 426 |  | FVECT   v1, v2, v3; | 
| 427 |  | FVECT   n1, n2, n3; | 
| 428 |  | register int    i; | 
| 429 | < | /* the following is repeat code, so assume it's OK */ | 
| 430 | < | cv2 = c_getvert(vn2); | 
| 431 | < | if (invert) { | 
| 432 | < | cv3 = c_getvert(vn1); | 
| 433 | < | cv1 = c_getvert(vn3); | 
| 414 | < | } else { | 
| 415 | < | cv1 = c_getvert(vn1); | 
| 416 | < | cv3 = c_getvert(vn3); | 
| 429 | > |  | 
| 430 | > | if (iv) {                       /* swap vertex order if inverted */ | 
| 431 | > | cvt = cv1; | 
| 432 | > | cv1 = cv3; | 
| 433 | > | cv3 = cvt; | 
| 434 |  | } | 
| 435 |  | xf_xfmpoint(v1, cv1->p); | 
| 436 |  | xf_xfmpoint(v2, cv2->p); | 
| 556 |  | return(mname); | 
| 557 |  | } | 
| 558 |  | /* check for plastic */ | 
| 559 | < | if (c_cmaterial->rs < .1 && (c_cmaterial->rs < .01 || | 
| 543 | < | c_isgrey(&c_cmaterial->rs_c))) { | 
| 559 | > | if (c_cmaterial->rs < .1) { | 
| 560 |  | cvtcolor(radrgb, &c_cmaterial->rd_c, | 
| 561 |  | c_cmaterial->rd/(1.-c_cmaterial->rs)); | 
| 562 |  | fprintf(matfp, "\nvoid plastic %s\n0\n0\n", mname); |