| 5 | 
  | 
 * Convert Radiance scene description to MGF | 
| 6 | 
  | 
 */ | 
| 7 | 
  | 
 | 
| 8 | 
– | 
#include "platform.h" | 
| 9 | 
– | 
#include "standard.h" | 
| 8 | 
  | 
#include <ctype.h> | 
| 9 | 
  | 
#include <string.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 | 
  | 
#define C_1SIDEDTHICK   0.005 | 
| 21 | 
  | 
 | 
| 20 | 
– | 
int     o_face(), o_cone(), o_sphere(), o_ring(), o_cylinder(); | 
| 21 | 
– | 
int     o_instance(), o_illum(); | 
| 22 | 
– | 
int     o_plastic(), o_metal(), o_glass(), o_dielectric(), | 
| 23 | 
– | 
        o_mirror(), o_trans(), o_light(); | 
| 22 | 
  | 
 | 
| 23 | 
  | 
LUTAB   rmats = LU_SINIT(free,NULL);            /* defined material table */ | 
| 24 | 
  | 
 | 
| 51 | 
  | 
 | 
| 52 | 
  | 
LUTAB   vertab = LU_SINIT(free,NULL);   /* our vertex lookup table */ | 
| 53 | 
  | 
 | 
| 54 | 
+ | 
static void rad2mgf(char *inp); | 
| 55 | 
+ | 
static void cvtprim(char *inp, char *mod, char *typ, char *id, FUNARGS *fa); | 
| 56 | 
+ | 
static void newmat(char *id, char *alias); | 
| 57 | 
+ | 
static void setmat(char *id); | 
| 58 | 
+ | 
static void setobj(char *id); | 
| 59 | 
+ | 
static void init(void); | 
| 60 | 
+ | 
static void uninit(void); | 
| 61 | 
+ | 
static void clrverts(void); | 
| 62 | 
+ | 
static void add2dispatch(char *name, int (*func)()); | 
| 63 | 
+ | 
static char *getvertid(char *vname, FVECT vp); | 
| 64 | 
+ | 
static int o_unsupported(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 65 | 
+ | 
static int o_face(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 66 | 
+ | 
static int o_cone(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 67 | 
+ | 
static int o_sphere(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 68 | 
+ | 
static int o_cylinder(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 69 | 
+ | 
static int o_ring(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 70 | 
+ | 
static int o_instance(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 71 | 
+ | 
static int o_illum(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 72 | 
+ | 
static int o_plastic(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 73 | 
+ | 
static int o_metal(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 74 | 
+ | 
static int o_glass(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 75 | 
+ | 
static int o_dielectric(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 76 | 
+ | 
static int o_mirror(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 77 | 
+ | 
static int o_trans(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 78 | 
+ | 
static int o_light(char *mod, char *typ, char *id, FUNARGS *fa); | 
| 79 | 
  | 
 | 
| 80 | 
< | 
main(argc, argv) | 
| 81 | 
< | 
int     argc; | 
| 82 | 
< | 
char    **argv; | 
| 80 | 
> | 
 | 
| 81 | 
> | 
int | 
| 82 | 
> | 
main( | 
| 83 | 
> | 
        int     argc, | 
| 84 | 
> | 
        char    **argv | 
| 85 | 
> | 
) | 
| 86 | 
  | 
{ | 
| 87 | 
  | 
        int     i; | 
| 88 | 
  | 
 | 
| 123 | 
  | 
} | 
| 124 | 
  | 
 | 
| 125 | 
  | 
 | 
| 126 | 
< | 
rad2mgf(inp)            /* convert a Radiance file to MGF */ | 
| 127 | 
< | 
char    *inp; | 
| 126 | 
> | 
void | 
| 127 | 
> | 
rad2mgf(                /* convert a Radiance file to MGF */ | 
| 128 | 
> | 
        char    *inp | 
| 129 | 
> | 
) | 
| 130 | 
  | 
{ | 
| 131 | 
  | 
#define mod     buf | 
| 132 | 
  | 
#define typ     (buf+128) | 
| 204 | 
  | 
} | 
| 205 | 
  | 
 | 
| 206 | 
  | 
 | 
| 207 | 
< | 
cvtprim(inp, mod, typ, id, fa)  /* process Radiance primitive */ | 
| 208 | 
< | 
char    *inp, *mod, *typ, *id; | 
| 209 | 
< | 
FUNARGS *fa; | 
| 207 | 
> | 
void | 
| 208 | 
> | 
cvtprim(        /* process Radiance primitive */ | 
| 209 | 
> | 
        char    *inp, | 
| 210 | 
> | 
        char    *mod, | 
| 211 | 
> | 
        char    *typ, | 
| 212 | 
> | 
        char    *id, | 
| 213 | 
> | 
        FUNARGS *fa | 
| 214 | 
> | 
) | 
| 215 | 
  | 
{ | 
| 216 | 
  | 
        int     (*df)(); | 
| 217 | 
  | 
 | 
| 218 | 
  | 
        df = (int (*)())lu_find(&rdispatch, typ)->data; | 
| 219 | 
  | 
        if (df != NULL) {                               /* convert */ | 
| 220 | 
  | 
                if ((*df)(mod, typ, id, fa) < 0) { | 
| 221 | 
< | 
                        fprintf(stderr, "%s: bad %s \"%s\"\n", typ, id); | 
| 221 | 
> | 
                        fprintf(stderr, "%s: bad %s \"%s\"\n", "rat2mgf", typ, id); | 
| 222 | 
  | 
                        exit(1); | 
| 223 | 
  | 
                } | 
| 224 | 
  | 
        } else {                                        /* unsupported */ | 
| 229 | 
  | 
} | 
| 230 | 
  | 
 | 
| 231 | 
  | 
 | 
| 232 | 
< | 
newmat(id, alias)               /* add a modifier to the alias list */ | 
| 233 | 
< | 
char    *id; | 
| 234 | 
< | 
char    *alias; | 
| 232 | 
> | 
void | 
| 233 | 
> | 
newmat(         /* add a modifier to the alias list */ | 
| 234 | 
> | 
        char    *id, | 
| 235 | 
> | 
        char    *alias | 
| 236 | 
> | 
) | 
| 237 | 
  | 
{ | 
| 238 | 
  | 
        register LUENT  *lp, *lpa; | 
| 239 | 
  | 
 | 
| 267 | 
  | 
} | 
| 268 | 
  | 
 | 
| 269 | 
  | 
 | 
| 270 | 
< | 
setmat(id)                      /* set material to this one */ | 
| 271 | 
< | 
char    *id; | 
| 270 | 
> | 
void | 
| 271 | 
> | 
setmat(                 /* set material to this one */ | 
| 272 | 
> | 
        char    *id | 
| 273 | 
> | 
) | 
| 274 | 
  | 
{ | 
| 275 | 
  | 
        if (!strcmp(id, curmat))        /* already set? */ | 
| 276 | 
  | 
                return; | 
| 281 | 
  | 
} | 
| 282 | 
  | 
 | 
| 283 | 
  | 
 | 
| 284 | 
< | 
setobj(id)                      /* set object name to this one */ | 
| 285 | 
< | 
char    *id; | 
| 284 | 
> | 
void | 
| 285 | 
> | 
setobj(                 /* set object name to this one */ | 
| 286 | 
> | 
        char    *id | 
| 287 | 
> | 
) | 
| 288 | 
  | 
{ | 
| 289 | 
  | 
        register char   *cp, *cp2; | 
| 290 | 
  | 
        char    *end = NULL; | 
| 314 | 
  | 
} | 
| 315 | 
  | 
 | 
| 316 | 
  | 
 | 
| 317 | 
< | 
init()                  /* initialize dispatch table and output */ | 
| 317 | 
> | 
void | 
| 318 | 
> | 
init(void)                      /* initialize dispatch table and output */ | 
| 319 | 
  | 
{ | 
| 320 | 
  | 
        lu_init(&vertab, NVERTS); | 
| 321 | 
  | 
        lu_init(&rdispatch, 22); | 
| 349 | 
  | 
} | 
| 350 | 
  | 
 | 
| 351 | 
  | 
 | 
| 352 | 
< | 
uninit()                        /* mark end of MGF file */ | 
| 352 | 
> | 
void | 
| 353 | 
> | 
uninit(void)                    /* mark end of MGF file */ | 
| 354 | 
  | 
{ | 
| 355 | 
  | 
        puts("o"); | 
| 356 | 
  | 
        if (hasmult) | 
| 362 | 
  | 
} | 
| 363 | 
  | 
 | 
| 364 | 
  | 
 | 
| 365 | 
< | 
clrverts()                      /* clear vertex table */ | 
| 365 | 
> | 
void | 
| 366 | 
> | 
clrverts(void)                  /* clear vertex table */ | 
| 367 | 
  | 
{ | 
| 368 | 
  | 
        register int    i; | 
| 369 | 
  | 
 | 
| 374 | 
  | 
} | 
| 375 | 
  | 
 | 
| 376 | 
  | 
 | 
| 377 | 
< | 
add2dispatch(name, func)        /* add function to dispatch table */ | 
| 378 | 
< | 
char    *name; | 
| 379 | 
< | 
int     (*func)(); | 
| 377 | 
> | 
void | 
| 378 | 
> | 
add2dispatch(   /* add function to dispatch table */ | 
| 379 | 
> | 
        char    *name, | 
| 380 | 
> | 
        int     (*func)() | 
| 381 | 
> | 
) | 
| 382 | 
  | 
{ | 
| 383 | 
  | 
        register LUENT  *lp; | 
| 384 | 
  | 
 | 
| 394 | 
  | 
 | 
| 395 | 
  | 
 | 
| 396 | 
  | 
char * | 
| 397 | 
< | 
getvertid(vname, vp)            /* get/set vertex ID for this point */ | 
| 398 | 
< | 
char    *vname; | 
| 399 | 
< | 
FVECT   vp; | 
| 397 | 
> | 
getvertid(              /* get/set vertex ID for this point */ | 
| 398 | 
> | 
        char    *vname, | 
| 399 | 
> | 
        FVECT   vp | 
| 400 | 
> | 
) | 
| 401 | 
  | 
{ | 
| 402 | 
  | 
        static char     vkey[VKLEN]; | 
| 403 | 
  | 
        register LUENT  *lp; | 
| 439 | 
  | 
 | 
| 440 | 
  | 
 | 
| 441 | 
  | 
int | 
| 442 | 
< | 
o_unsupported(mod, typ, id, fa)         /* mark unsupported primitive */ | 
| 443 | 
< | 
char    *mod, *typ, *id; | 
| 444 | 
< | 
FUNARGS *fa; | 
| 442 | 
> | 
o_unsupported(          /* mark unsupported primitive */ | 
| 443 | 
> | 
        char    *mod, | 
| 444 | 
> | 
        char    *typ, | 
| 445 | 
> | 
        char    *id, | 
| 446 | 
> | 
        FUNARGS *fa | 
| 447 | 
> | 
) | 
| 448 | 
  | 
{ | 
| 449 | 
  | 
        register int    i; | 
| 450 | 
  | 
 | 
| 469 | 
  | 
 | 
| 470 | 
  | 
 | 
| 471 | 
  | 
int | 
| 472 | 
< | 
o_face(mod, typ, id, fa)                /* print out a polygon */ | 
| 473 | 
< | 
char    *mod, *typ, *id; | 
| 474 | 
< | 
FUNARGS *fa; | 
| 472 | 
> | 
o_face(         /* print out a polygon */ | 
| 473 | 
> | 
        char    *mod, | 
| 474 | 
> | 
        char    *typ, | 
| 475 | 
> | 
        char    *id, | 
| 476 | 
> | 
        FUNARGS *fa | 
| 477 | 
> | 
) | 
| 478 | 
  | 
{ | 
| 479 | 
  | 
        char    entbuf[2048], *linestart; | 
| 480 | 
  | 
        register char   *cp; | 
| 503 | 
  | 
 | 
| 504 | 
  | 
 | 
| 505 | 
  | 
int | 
| 506 | 
< | 
o_cone(mod, typ, id, fa)        /* print out a cone */ | 
| 507 | 
< | 
char    *mod, *typ, *id; | 
| 508 | 
< | 
register FUNARGS        *fa; | 
| 506 | 
> | 
o_cone( /* print out a cone */ | 
| 507 | 
> | 
        char    *mod, | 
| 508 | 
> | 
        char    *typ, | 
| 509 | 
> | 
        char    *id, | 
| 510 | 
> | 
        register FUNARGS        *fa | 
| 511 | 
> | 
) | 
| 512 | 
  | 
{ | 
| 513 | 
  | 
        char    v1[6], v2[6]; | 
| 514 | 
  | 
 | 
| 529 | 
  | 
 | 
| 530 | 
  | 
 | 
| 531 | 
  | 
int | 
| 532 | 
< | 
o_sphere(mod, typ, id, fa)      /* print out a sphere */ | 
| 533 | 
< | 
char    *mod, *typ, *id; | 
| 534 | 
< | 
register FUNARGS        *fa; | 
| 532 | 
> | 
o_sphere(       /* print out a sphere */ | 
| 533 | 
> | 
        char    *mod, | 
| 534 | 
> | 
        char    *typ, | 
| 535 | 
> | 
        char    *id, | 
| 536 | 
> | 
        register FUNARGS        *fa | 
| 537 | 
> | 
) | 
| 538 | 
  | 
{ | 
| 539 | 
  | 
        char    cent[6]; | 
| 540 | 
  | 
 | 
| 549 | 
  | 
 | 
| 550 | 
  | 
 | 
| 551 | 
  | 
int | 
| 552 | 
< | 
o_cylinder(mod, typ, id, fa)    /* print out a cylinder */ | 
| 553 | 
< | 
char    *mod, *typ, *id; | 
| 554 | 
< | 
register FUNARGS        *fa; | 
| 552 | 
> | 
o_cylinder(     /* print out a cylinder */ | 
| 553 | 
> | 
        char    *mod, | 
| 554 | 
> | 
        char    *typ, | 
| 555 | 
> | 
        char    *id, | 
| 556 | 
> | 
        register FUNARGS        *fa | 
| 557 | 
> | 
) | 
| 558 | 
  | 
{ | 
| 559 | 
  | 
        char    v1[6], v2[6]; | 
| 560 | 
  | 
 | 
| 571 | 
  | 
 | 
| 572 | 
  | 
 | 
| 573 | 
  | 
int | 
| 574 | 
< | 
o_ring(mod, typ, id, fa)        /* print out a ring */ | 
| 575 | 
< | 
char    *mod, *typ, *id; | 
| 576 | 
< | 
register FUNARGS        *fa; | 
| 574 | 
> | 
o_ring( /* print out a ring */ | 
| 575 | 
> | 
        char    *mod, | 
| 576 | 
> | 
        char    *typ, | 
| 577 | 
> | 
        char    *id, | 
| 578 | 
> | 
        register FUNARGS        *fa | 
| 579 | 
> | 
) | 
| 580 | 
  | 
{ | 
| 581 | 
  | 
        if (fa->nfargs != 8) | 
| 582 | 
  | 
                return(-1); | 
| 597 | 
  | 
 | 
| 598 | 
  | 
 | 
| 599 | 
  | 
int | 
| 600 | 
< | 
o_instance(mod, typ, id, fa)    /* convert an instance (or mesh) */ | 
| 601 | 
< | 
char    *mod, *typ, *id; | 
| 602 | 
< | 
FUNARGS *fa; | 
| 600 | 
> | 
o_instance(     /* convert an instance (or mesh) */ | 
| 601 | 
> | 
        char    *mod, | 
| 602 | 
> | 
        char    *typ, | 
| 603 | 
> | 
        char    *id, | 
| 604 | 
> | 
        FUNARGS *fa | 
| 605 | 
> | 
) | 
| 606 | 
  | 
{ | 
| 607 | 
  | 
        register int    i; | 
| 608 | 
  | 
        register char   *cp; | 
| 641 | 
  | 
 | 
| 642 | 
  | 
 | 
| 643 | 
  | 
int | 
| 644 | 
< | 
o_illum(mod, typ, id, fa)       /* convert an illum material */ | 
| 645 | 
< | 
char    *mod, *typ, *id; | 
| 646 | 
< | 
FUNARGS *fa; | 
| 644 | 
> | 
o_illum(        /* convert an illum material */ | 
| 645 | 
> | 
        char    *mod, | 
| 646 | 
> | 
        char    *typ, | 
| 647 | 
> | 
        char    *id, | 
| 648 | 
> | 
        FUNARGS *fa | 
| 649 | 
> | 
) | 
| 650 | 
  | 
{ | 
| 651 | 
  | 
        if (fa->nsargs == 1 && strcmp(fa->sarg[0], VOIDID)) { | 
| 652 | 
  | 
                newmat(id, fa->sarg[0]);        /* just create alias */ | 
| 660 | 
  | 
 | 
| 661 | 
  | 
 | 
| 662 | 
  | 
int | 
| 663 | 
< | 
o_plastic(mod, typ, id, fa)     /* convert a plastic material */ | 
| 664 | 
< | 
char    *mod, *typ, *id; | 
| 665 | 
< | 
register FUNARGS        *fa; | 
| 663 | 
> | 
o_plastic(      /* convert a plastic material */ | 
| 664 | 
> | 
        char    *mod, | 
| 665 | 
> | 
        char    *typ, | 
| 666 | 
> | 
        char    *id, | 
| 667 | 
> | 
        register FUNARGS        *fa | 
| 668 | 
> | 
) | 
| 669 | 
  | 
{ | 
| 670 | 
  | 
        COLOR   cxyz, rrgb; | 
| 671 | 
  | 
        double  d; | 
| 691 | 
  | 
 | 
| 692 | 
  | 
 | 
| 693 | 
  | 
int | 
| 694 | 
< | 
o_metal(mod, typ, id, fa)       /* convert a metal material */ | 
| 695 | 
< | 
char    *mod, *typ, *id; | 
| 696 | 
< | 
register FUNARGS        *fa; | 
| 694 | 
> | 
o_metal(        /* convert a metal material */ | 
| 695 | 
> | 
        char    *mod, | 
| 696 | 
> | 
        char    *typ, | 
| 697 | 
> | 
        char    *id, | 
| 698 | 
> | 
        register FUNARGS        *fa | 
| 699 | 
> | 
) | 
| 700 | 
  | 
{ | 
| 701 | 
  | 
        COLOR   cxyz, rrgb; | 
| 702 | 
  | 
        double  d; | 
| 720 | 
  | 
 | 
| 721 | 
  | 
 | 
| 722 | 
  | 
int | 
| 723 | 
< | 
o_glass(mod, typ, id, fa)       /* convert a glass material */ | 
| 724 | 
< | 
char    *mod, *typ, *id; | 
| 725 | 
< | 
register FUNARGS        *fa; | 
| 723 | 
> | 
o_glass(        /* convert a glass material */ | 
| 724 | 
> | 
        char    *mod, | 
| 725 | 
> | 
        char    *typ, | 
| 726 | 
> | 
        char    *id, | 
| 727 | 
> | 
        register FUNARGS        *fa | 
| 728 | 
> | 
) | 
| 729 | 
  | 
{ | 
| 730 | 
  | 
        COLOR   cxyz, rrgb, trgb; | 
| 731 | 
  | 
        double  nrfr = 1.52, F, d; | 
| 762 | 
  | 
 | 
| 763 | 
  | 
 | 
| 764 | 
  | 
int | 
| 765 | 
< | 
o_dielectric(mod, typ, id, fa)  /* convert a dielectric material */ | 
| 766 | 
< | 
char    *mod, *typ, *id; | 
| 767 | 
< | 
register FUNARGS        *fa; | 
| 765 | 
> | 
o_dielectric(   /* convert a dielectric material */ | 
| 766 | 
> | 
        char    *mod, | 
| 767 | 
> | 
        char    *typ, | 
| 768 | 
> | 
        char    *id, | 
| 769 | 
> | 
        register FUNARGS        *fa | 
| 770 | 
> | 
) | 
| 771 | 
  | 
{ | 
| 772 | 
  | 
        COLOR   cxyz, trgb; | 
| 773 | 
  | 
        double  F, d; | 
| 795 | 
  | 
 | 
| 796 | 
  | 
 | 
| 797 | 
  | 
int | 
| 798 | 
< | 
o_mirror(mod, typ, id, fa)      /* convert a mirror material */ | 
| 799 | 
< | 
char    *mod, *typ, *id; | 
| 800 | 
< | 
register FUNARGS        *fa; | 
| 798 | 
> | 
o_mirror(       /* convert a mirror material */ | 
| 799 | 
> | 
        char    *mod, | 
| 800 | 
> | 
        char    *typ, | 
| 801 | 
> | 
        char    *id, | 
| 802 | 
> | 
        register FUNARGS        *fa | 
| 803 | 
> | 
) | 
| 804 | 
  | 
{ | 
| 805 | 
  | 
        COLOR   cxyz, rrgb; | 
| 806 | 
  | 
        double  d; | 
| 824 | 
  | 
 | 
| 825 | 
  | 
 | 
| 826 | 
  | 
int | 
| 827 | 
< | 
o_trans(mod, typ, id, fa)       /* convert a trans material */ | 
| 828 | 
< | 
char    *mod, *typ, *id; | 
| 829 | 
< | 
register FUNARGS        *fa; | 
| 827 | 
> | 
o_trans(        /* convert a trans material */ | 
| 828 | 
> | 
        char    *mod, | 
| 829 | 
> | 
        char    *typ, | 
| 830 | 
> | 
        char    *id, | 
| 831 | 
> | 
        register FUNARGS        *fa | 
| 832 | 
> | 
) | 
| 833 | 
  | 
{ | 
| 834 | 
  | 
        COLOR   cxyz, rrgb; | 
| 835 | 
  | 
        double  rough, trans, tspec, d; | 
| 866 | 
  | 
 | 
| 867 | 
  | 
 | 
| 868 | 
  | 
int | 
| 869 | 
< | 
o_light(mod, typ, id, fa)               /* convert a light type */ | 
| 870 | 
< | 
char    *mod, *typ, *id; | 
| 871 | 
< | 
register FUNARGS        *fa; | 
| 869 | 
> | 
o_light(                /* convert a light type */ | 
| 870 | 
> | 
        char    *mod, | 
| 871 | 
> | 
        char    *typ, | 
| 872 | 
> | 
        char    *id, | 
| 873 | 
> | 
        register FUNARGS        *fa | 
| 874 | 
> | 
) | 
| 875 | 
  | 
{ | 
| 876 | 
  | 
        COLOR   cxyz, rrgb; | 
| 877 | 
  | 
        double  d; |