home *** CD-ROM | disk | FTP | other *** search
/ Current Shareware 1994 January / SHAR194.ISO / graphuti / rawpov18.zip / SOURCE.ZIP / RAW2POV.C next >
C/C++ Source or Header  |  1993-10-02  |  18KB  |  769 lines

  1. /*-------------------------------------------------------------------------
  2.  
  3.             RAW to POV-Ray Converter
  4.              Copyright (c) 1993 Steve Anger
  5.  
  6.    Reads a list of triangle coordinates in raw ASCII text format and
  7.  outputs a POV-Ray compatable file. Automatically adds bounding shapes
  8.  and produces smooth triangles. This file may be freely modified and
  9.  distributed.
  10.  
  11.                       CompuServe: 70714,3113
  12.                     Internet: 70714.3113@compuserve.com
  13.                        YCCMR BBS: (708)358-5611
  14.  
  15. --------------------------------------------------------------------------*/
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <values.h>
  21. #include <ctype.h>
  22. #include "vect.h"
  23. #include "rayopt.h"
  24.  
  25. #if defined(applec) || defined(THINK_C)
  26. #include "RAW2POV.mac.h"
  27. #else
  28. #define COOPERATE
  29. #endif
  30.  
  31. #ifdef __TURBOC__
  32. extern unsigned _stklen = 16384;
  33. #endif
  34.  
  35. #ifndef FALSE
  36. #define FALSE 0
  37. #define TRUE  1
  38. #endif
  39.  
  40. #define OFF  0
  41. #define ON   1
  42. #define AUTO 2
  43.  
  44. #define VERSION "v1.8"
  45. #define MAX_TEXTURE 500
  46.  
  47. #define DEFAULT  0
  48. #define FRACTINT 1
  49. #define TEXTURE  2
  50.  
  51. #define POV10   0
  52. #define POV20   1
  53. #define VIVID   2
  54. #define POLYRAY 3
  55.  
  56. /* Function prototypes */
  57. static void process_args (int argc, char *argv[]);
  58. static void parse_option (char *option);
  59. static char *next_token (FILE *f);
  60. static int  parse_input (FILE *f);
  61. static void make_camera (void);
  62. static void update_txtlist (char *new_texture);
  63. static void fswap (float *a, float *b);
  64. static char upcase (char c);
  65. static void write_light (FILE *f, Vector pos);
  66. static void write_camera (FILE *f, Vector pos, Vector target);
  67. static void write_texture (FILE *f, char *mat);
  68. static void write_intro (FILE *f);
  69.  
  70.  
  71. static    char  infile[64];       /* Name of input file */
  72. static    char  outfile[64];      /* Name of output file */
  73. static    float smooth;           /* Smooth triangles with angles < this value */
  74. static    int   bound;            /* Type of bounding shape to use */
  75. static    int   verbose;          /* Verbose status messages */
  76. static    int   one_object;       /* Optimize file as a single object */
  77. static    int   swap_yz;          /* Swap Y and Z coordinates */
  78. static  int   internal_bounding;/* Use internal bounding for POV-Ray */
  79. static    int   camera;           /* Place a camera and light source in scene file */
  80. static    int   iformat;          /* Input file format type */
  81. static  int   oformat;          /* Output format */
  82. static    long  line_cnt;         /* Line number */
  83.  
  84. static    float ax, ay, az;
  85. static    float bx, by, bz;
  86. static    float cx, cy, cz;
  87. static    float red, green, blue;
  88. static    char  new_obj_name[80];
  89. static    char  new_texture[80];
  90.  
  91. static    char  **txtlist;
  92. static    int   txtcnt = 0;
  93.  
  94.  
  95. int main (int argc, char *argv[])
  96. {
  97.     FILE  *f, *g;
  98.     int   obj_cnt, tri_cnt;
  99.     int   done, i;
  100.     char  obj_name[80] = "";
  101.  
  102.     txtlist = malloc((MAX_TEXTURE+1) * sizeof(char *));
  103.     if (txtlist == NULL)
  104.     abortmsg ("Out of memory", 1);
  105.  
  106.     process_args (argc, argv);
  107.  
  108.     f = fopen (infile, "r");
  109.  
  110.     if (f == NULL) {
  111.     printf ("Error opening input file %s\n", infile);
  112.     exit(1);
  113.     }
  114.  
  115.     opt_set_format (oformat);
  116.     opt_set_dec (4);
  117.     opt_set_bound (bound);
  118.     opt_set_smooth (smooth);
  119.     opt_set_quiet (!verbose);
  120.     opt_set_fname (outfile, "");
  121.  
  122.     /* Use the name of the file as default object name */
  123.     strcpy (obj_name, infile);
  124.     add_ext (obj_name, "", 1);
  125.  
  126.     line_cnt = 0;
  127.     obj_cnt = 0;
  128.     tri_cnt = 0;
  129.     done = 0;
  130.  
  131.     printf ("Reading file...\n");
  132.  
  133.     g = fopen (outfile, "a");
  134.     write_intro (g);
  135.     fclose(g);
  136.  
  137.     while (!done) {
  138.     COOPERATE    /* support multitasking */
  139.  
  140.     switch (parse_input (f)) {
  141.         /* End of file */
  142.         case  0: done = 1;
  143.              break;
  144.  
  145.         /* New triangle with RGB color */
  146.         case  1: opt_set_color (red, green, blue);
  147.              opt_add_tri (ax, ay, az, bx, by, bz, cx, cy, cz);
  148.              ++tri_cnt;
  149.              break;
  150.  
  151.         /* New triangle with named texture */
  152.         case  2: update_txtlist (new_texture);
  153.              opt_set_texture (new_texture);
  154.              opt_add_tri (ax, ay, az, bx, by, bz, cx, cy, cz);
  155.              ++tri_cnt;
  156.              break;
  157.  
  158.         /* New object */
  159.         case  3: if (!one_object) {
  160.              if (tri_cnt > 0) {
  161.                  opt_write_file (obj_name);
  162.                  ++obj_cnt;
  163.              }
  164.  
  165.              strcpy (obj_name, new_obj_name);
  166.              printf ("Working on: %s\n", obj_name);
  167.              }
  168.              break;
  169.     }
  170.     }
  171.  
  172.     fclose (f);
  173.  
  174.     opt_write_pov (obj_name);
  175.     ++obj_cnt;
  176.  
  177.     printf ("\n");
  178.  
  179.     g = fopen (outfile, "a");
  180.  
  181.     if (txtcnt > 0)
  182.     fprintf (g, "\n/* Named textures, modify as needed */\n");
  183.  
  184.     for (i = 0; i < txtcnt; i++) {
  185.         write_texture (g, txtlist[i]);
  186.     free (txtlist[i]);
  187.     }
  188.  
  189.     fclose(g);
  190.  
  191.     opt_finish();
  192.  
  193.     if (camera)
  194.     make_camera();
  195.  
  196.     free(txtlist);
  197.  
  198.     return 0;
  199. }
  200.  
  201.  
  202. static void process_args (int argc, char *argv[])
  203. {
  204.     int i;
  205.     char *env_opt, *option;
  206.  
  207.     printf ("\n");
  208.     printf ("RAW to POV-Ray (and others) Converter %s - Copyright (c) 1993 Steve Anger\n", VERSION);
  209. #if defined(__GNUC__) && defined(i386)
  210.     printf ("32 bit version. DOS Extender Copyright (c) 1991 DJ Delorie\n");
  211. #endif
  212.     printf ("This program is freely distributable\n");
  213.     printf ("\n");
  214.  
  215.     if (argc < 2) {
  216.     printf ("Usage: raw2pov inputfile[.raw] [outputfile[.pov]] [options]\n\n");
  217.     printf ("Options: -snnn  - Smooth triangles with angles < nnn\n");
  218.     printf ("         +v, -v - Turn verbose status messages on or off\n");
  219.     printf ("         +i, -i - Turn internal bounding on or off\n");
  220.     printf ("         -1     - Generate one object only\n");
  221.     printf ("         -x     - Exchange the Y and Z coords\n");
  222.     printf ("         -c     - Add camera and light source\n");
  223.     printf ("         -fc    - Input file in fractint color format\n");
  224.     printf ("         -ft    - Input file has textures specified\n");
  225.     printf ("         -op    - Output to POV-Ray 2.0 format (default)\n");
  226.     printf ("         -op1   - Output to POV-Ray 1.0 format\n");
  227.     printf ("         -ov    - Output to Vivid format\n");
  228.     printf ("         -ol    - Output to poLyray format\n");
  229.     printf ("\nex. raw2pov chess.raw chess.pov\n\n");
  230.     exit(1);
  231.     }
  232.  
  233.     infile[0] = '\0';
  234.     outfile[0] = '\0';
  235.     smooth = 70.0;
  236.     bound = 0;
  237.     verbose = 0;
  238.     one_object = 0;
  239.     swap_yz = 0;
  240.     camera = 0;
  241.     internal_bounding = AUTO;
  242.     iformat = DEFAULT;
  243.     oformat = POV20;
  244.  
  245.     /* Parse the enviroment string options */
  246.     env_opt = getenv ("RAW2POV");
  247.  
  248.     if (env_opt != NULL) {
  249.     option = strtok (env_opt, " ");
  250.  
  251.     while (option != NULL) {
  252.         parse_option (option);
  253.         option = strtok (NULL, " ");
  254.     }
  255.     }
  256.  
  257.     /* Parse the command line options */
  258.     for (i = 1; i < argc; i++)
  259.     parse_option (argv[i]);
  260.  
  261.     if (strlen(infile) == 0)
  262.     abortmsg ("No input file specified", 1);
  263.  
  264.     if (strlen(outfile) == 0) {
  265.     strcpy (outfile, infile);
  266.  
  267.     switch (oformat) {
  268.         case POV10:
  269.         case POV20:   add_ext (outfile, "pov", 1); break;
  270.         case VIVID:   add_ext (outfile, "v",   1); break;
  271.         case POLYRAY: add_ext (outfile, "pi",  1); break;
  272.     }
  273.     }
  274.     else {
  275.     switch (oformat) {
  276.         case POV10:
  277.         case POV20:   add_ext (outfile, "pov", 0); break;
  278.         case VIVID:   add_ext (outfile, "v",   0); break;
  279.         case POLYRAY: add_ext (outfile, "pi",  0); break;
  280.     }
  281.     }
  282.  
  283.     switch (internal_bounding) {
  284.     case OFF:  bound = 2; break;
  285.     case ON:   bound = 0; break;
  286.     case AUTO: bound = (oformat == POV10) ? 0 : 2; break;
  287.     }
  288. }
  289.  
  290.  
  291. static void parse_option (char *option)
  292. {
  293.     if (option[0] == '-' || option[0] == '+') {
  294.     switch (upcase(option[1])) {
  295.         case 'C': camera = TRUE;
  296.               break;
  297.  
  298.         case 'F': if (upcase(option[2]) == 'C')
  299.               iformat = FRACTINT;
  300.               else if (upcase(option[2]) == 'T')
  301.               iformat = TEXTURE;
  302.               break;
  303.  
  304.         case 'I': if (option[0] == '-')
  305.               internal_bounding = OFF;
  306.               else
  307.               internal_bounding = ON;
  308.               break;
  309.  
  310.         case 'O': switch (upcase (option[2])) {
  311.               case 'P': if (option[3] == '1')
  312.                     oformat = POV10;
  313.                     else
  314.                     oformat = POV20;
  315.                     break;
  316.  
  317.               case 'V': oformat = VIVID;
  318.                     break;
  319.  
  320.               case 'L': oformat = POLYRAY;
  321.                     break;
  322.               }
  323.               break;
  324.  
  325.         case 'S': if (option[2] == '\0')
  326.               smooth = 70.0;
  327.               else
  328.               sscanf (&option[2], "%f", &smooth);
  329.               break;
  330.  
  331.         case 'U': printf ("Warning: -u parameter no long has any effect\n");
  332.               printf ("         use +i or -i instead.\n");
  333.               break;
  334.  
  335.         case 'V': if (option[0] == '-')
  336.               verbose = FALSE;
  337.               else
  338.               verbose = TRUE;
  339.               break;
  340.  
  341.         case '1': one_object = TRUE;
  342.               break;
  343.  
  344.         case 'X': swap_yz = TRUE;
  345.               break;
  346.  
  347.         default : printf ("\nInvalid option -%c\n", option[1]);
  348.               exit (1);
  349.     }
  350.     }
  351.     else if (strlen(infile) == 0) {
  352.     strcpy (infile, option);
  353.     add_ext (infile, "raw", 0);
  354.     }
  355.     else if (strlen(outfile) == 0)
  356.     strcpy (outfile, option);
  357.     else
  358.     abortmsg ("Too many file names specified.\n", 1);
  359. }
  360.  
  361.  
  362. static char *next_token (FILE *f)
  363. {
  364.     static char token[128];
  365.     int  index, comment;
  366.     char ch;
  367.  
  368.     index = 0;
  369.     comment = 0;
  370.  
  371.     strcpy (token, "");
  372.  
  373.     /* Skip the white space */
  374.     while (1) {
  375.     ch = fgetc (f);
  376.  
  377.     if (feof(f))
  378.         break;
  379.  
  380.     if (ch == '\n')
  381.        ++line_cnt;
  382.     else if (ch == '{')
  383.         comment += 1;
  384.     else if (ch == '}')
  385.         comment = (comment > 0) ? (comment - 1) : 0;
  386.     else if (!isspace(ch) && !comment)
  387.         break;
  388.     }
  389.  
  390.     if (feof(f))
  391.     return token;
  392.  
  393.     ungetc (ch, f);
  394.  
  395.     while (1) {
  396.     ch = fgetc (f);
  397.  
  398.     if (feof(f))
  399.        break;
  400.  
  401.     if (ch == '\n')
  402.         ++line_cnt;
  403.  
  404.     if (isspace(ch))
  405.         break;
  406.  
  407.     if (index < 127)
  408.         token[index++] = ch;
  409.     }
  410.  
  411.     token[index] = '\0';
  412.  
  413.     return token;
  414. }
  415.  
  416.  
  417. static int parse_input (FILE *f)
  418. {
  419.     int   token_cnt, expected, result;
  420.     char  *token;
  421.     char  tokens[12][64];
  422.  
  423.     token_cnt = 0;
  424.     expected = 0;
  425.     result = -1;
  426.  
  427.     /* How many tokens to expect per triangle */
  428.     switch (iformat) {
  429.     case DEFAULT:  expected = 9;   break;
  430.     case FRACTINT: expected = 12;  break;
  431.     case TEXTURE:  expected = 10;  break;
  432.     }
  433.  
  434.     do {
  435.     token = next_token (f);
  436.  
  437.     if (strlen(token) == 0)
  438.         break;
  439.  
  440.     if (!isdigit(token[0]) && token[0] != '+' && token[0] != '-' && token[0] != '.') {
  441.         if (token_cnt == 0) {
  442.         strcpy (new_obj_name, token);
  443.         cleanup_name (new_obj_name);
  444.         return 3; /* New object name */
  445.         }
  446.         else if (token_cnt != 9 || expected != 10) {
  447.         printf ("Error in input file, line %ld. Misplaced object name.\n", line_cnt);
  448.         exit(1);
  449.         }
  450.     }
  451.  
  452.     strcpy (tokens[token_cnt++], token);
  453.     } while (token_cnt < expected);
  454.  
  455.     if (token_cnt == 0)
  456.     return 0; /* End of file */
  457.  
  458.     if (token_cnt != expected) {
  459.     printf ("Error in input file, line %ld. Unexpected end of file.\n", line_cnt);
  460.     exit(1);
  461.     }
  462.  
  463.     switch (iformat) {
  464.     case DEFAULT:  /* Ax Ay Az Bx By Bz Cx Cy Cz */
  465.         red   = 1.0;
  466.         green = 1.0;
  467.         blue  = 1.0;
  468.         ax    = atof(tokens[0]);
  469.         ay    = atof(tokens[1]);
  470.         az    = atof(tokens[2]);
  471.         bx    = atof(tokens[3]);
  472.         by    = atof(tokens[4]);
  473.         bz    = atof(tokens[5]);
  474.         cx    = atof(tokens[6]);
  475.         cy    = atof(tokens[7]);
  476.         cz    = atof(tokens[8]);
  477.         result = 1;
  478.         break;
  479.  
  480.     case FRACTINT:  /* R G B Ax Ay Az Bx By Bz Cx Cy Cz */
  481.         red   = atof(tokens[0]);
  482.         green = atof(tokens[1]);
  483.         blue  = atof(tokens[2]);
  484.         ax    = atof(tokens[3]);
  485.         ay    = atof(tokens[4]);
  486.         az    = atof(tokens[5]);
  487.         bx    = atof(tokens[6]);
  488.         by    = atof(tokens[7]);
  489.         bz    = atof(tokens[8]);
  490.         cx    = atof(tokens[9]);
  491.         cy    = atof(tokens[10]);
  492.         cz    = atof(tokens[11]);
  493.         result = 1;
  494.         break;
  495.  
  496.     case TEXTURE:  /* Ax Ay Az Bx By Bz Cx Cy Cz Texture */
  497.         ax    = atof(tokens[0]);
  498.         ay    = atof(tokens[1]);
  499.         az    = atof(tokens[2]);
  500.         bx    = atof(tokens[3]);
  501.         by    = atof(tokens[4]);
  502.         bz    = atof(tokens[5]);
  503.         cx    = atof(tokens[6]);
  504.         cy    = atof(tokens[7]);
  505.         cz    = atof(tokens[8]);
  506.         strcpy (new_texture, tokens[9]);
  507.         cleanup_name (new_texture);
  508.         result = 2;
  509.         break;
  510.     }
  511.  
  512.     if (swap_yz) {
  513.     fswap (&ay, &az);
  514.     fswap (&by, &bz);
  515.     fswap (&cy, &cz);
  516.     }
  517.  
  518.     return result;
  519. }
  520.  
  521.  
  522. static void make_camera()
  523. {
  524.     Vector gmin, gmax, look;
  525.     Vector size, scale, temp;
  526.     float  maxdim;
  527.     FILE *f;
  528.  
  529.     f = fopen (outfile, "a");
  530.  
  531.     opt_get_glimits (&gmin[X], &gmin[Y], &gmin[Z], &gmax[X], &gmax[Y], &gmax[Z]);
  532.  
  533.     look[X] = (gmin[X] + gmax[X])/2.0;
  534.     look[Y] = (gmin[Y] + gmax[Y])/2.0;
  535.     look[Z] = (gmin[Z] + gmax[Z])/2.0;
  536.  
  537.     size[X] = gmax[X] - gmin[X];
  538.     size[Y] = gmax[Y] - gmin[Y];
  539.     size[Z] = gmax[Z] - gmin[Z];
  540.  
  541.     maxdim = -MAXINT;
  542.  
  543.     if (size[X] > maxdim) maxdim = size[X];
  544.     if (size[Y] > maxdim) maxdim = size[Y];
  545.     if (size[Z] > maxdim) maxdim = size[Z];
  546.  
  547.     if (oformat != POV10 && oformat != POV20)
  548.     fswap (&size[Y], &size[Z]);
  549.  
  550.     if (size[X] > size[Z]) {
  551.     scale[X] =  0.3;
  552.     scale[Y] =  0.4;
  553.     scale[Z] = -1.3;
  554.     }
  555.     else {
  556.     scale[X] = 1.3;
  557.     scale[Y] = 0.4;
  558.     scale[Z] = 0.3;
  559.     }
  560.  
  561.     if (oformat != POV10 && oformat != POV20)
  562.     fswap (&scale[Y], &scale[Z]);
  563.  
  564.     fprintf (f, "\n");
  565.  
  566.     vect_scale (temp, scale, maxdim);
  567.     vect_add (temp, temp, look);
  568.     write_camera (f, temp, look);
  569.  
  570.     vect_scale (temp, scale, 4.0*maxdim);
  571.     vect_add (temp, temp, look);
  572.     write_light (f, temp);
  573.  
  574.     fclose(f);
  575. }
  576.  
  577.  
  578. static void update_txtlist (char *new_texture)
  579. {
  580.     int i;
  581.  
  582.     for (i = 0; i < txtcnt; i++) {
  583.     if (strcmp (new_texture, txtlist[i]) == 0)
  584.         break;
  585.     }
  586.  
  587.     if (i < txtcnt)
  588.     return;
  589.  
  590.     if (i == MAX_TEXTURE)
  591.     abortmsg ("Too many textures", 1);
  592.  
  593.     txtlist[i] = malloc (strlen (new_texture) + 1);
  594.     strcpy (txtlist[i], new_texture);
  595.  
  596.     ++txtcnt;
  597. }
  598.  
  599.  
  600. static void fswap (float *a, float *b)
  601. {
  602.     float temp;
  603.  
  604.     temp = *a;
  605.     *a = *b;
  606.     *b = temp;
  607. }
  608.  
  609.  
  610. /* Convert character 'c' top upper case */
  611. static char upcase (char c)
  612. {
  613.     if (c >= 'a' && c <= 'z')
  614.     c = c - 'a' + 'A';
  615.  
  616.     return c;
  617. }
  618.  
  619.  
  620. static void write_light (FILE *f, Vector pos)
  621. {
  622.     switch (oformat) {
  623.     case POV10:
  624.         fprintf (f, "object {\n");
  625.         fprintf (f, "    light_source { <%.4f %.4f %.4f> color White }\n",
  626.                  pos[X], pos[Y], pos[Z]);
  627.         fprintf (f, "}\n\n");
  628.         break;
  629.  
  630.     case POV20:
  631.         fprintf (f, "light_source {\n");
  632.         fprintf (f, "    <%.4f, %.4f, %.4f> color White\n",
  633.                  pos[X], pos[Y], pos[Z]);
  634.         fprintf (f, "}\n\n");
  635.         break;
  636.  
  637.     case VIVID:
  638.         fprintf (f, "light {\n");
  639.         fprintf (f, "    type point\n");
  640.         fprintf (f, "    position %.4f %.4f %.4f\n",
  641.                  pos[X], pos[Y], pos[Z]);
  642.         fprintf (f, "    color white\n");
  643.         fprintf (f, "}\n\n");
  644.         break;
  645.  
  646.     case POLYRAY:
  647.         fprintf (f, "light white, <%.4f, %.4f, %.4f>\n\n",
  648.              pos[X], pos[Y], pos[Z]);
  649.         break;
  650.     }
  651. }
  652.  
  653.  
  654. static void write_camera (FILE *f, Vector pos, Vector target)
  655. {
  656.     switch (oformat) {
  657.     case POV10:
  658.         fprintf (f, "camera {\n");
  659.         fprintf (f, "   location <%.4f %.4f %.4f>\n",
  660.                 pos[X], pos[Y], pos[Z]);
  661.         fprintf (f, "   look_at <%.4f %.4f %.4f>\n",
  662.                 target[X], target[Y], target[Z]);
  663.         fprintf (f, "}\n\n");
  664.         break;
  665.  
  666.     case POV20:
  667.         fprintf (f, "camera {\n");
  668.         fprintf (f, "   location <%.4f, %.4f, %.4f>\n",
  669.                 pos[X], pos[Y], pos[Z]);
  670.         fprintf (f, "   look_at <%.4f, %.4f, %.4f>\n",
  671.                 target[X], target[Y], target[Z]);
  672.         fprintf (f, "}\n\n");
  673.         break;
  674.  
  675.     case VIVID:
  676.         fprintf (f, "studio {\n");
  677.         fprintf (f, "    from %.4f %.4f %.4f\n",
  678.                  pos[X], pos[Y], pos[Z]);
  679.         fprintf (f, "    at %.4f %.4f %.4f\n",
  680.                  target[X], target[Y], target[Z]);
  681.         fprintf (f, "    up 0 0 1\n");
  682.         fprintf (f, "    angle 60.0\n");
  683.         fprintf (f, "    aspect 4/3\n");
  684.         fprintf (f, "    resolution 320 200\n");
  685.         fprintf (f, "    antialias none\n");
  686.         fprintf (f, "}\n\n");
  687.         break;
  688.  
  689.     case POLYRAY:
  690.         fprintf (f, "viewpoint {\n");
  691.         fprintf (f, "    from <%.4f, %.4f, %.4f>\n",
  692.                  pos[X], pos[Y], pos[Z]);
  693.         fprintf (f, "    at <%.4f, %.4f, %.4f>\n",
  694.                  target[X], target[Y], target[Z]);
  695.         fprintf (f, "    up <0, 0, 1>\n");
  696.         fprintf (f, "    angle 60.0\n");
  697.         fprintf (f, "    aspect -4/3\n");
  698.         fprintf (f, "    resolution 320, 200\n");
  699.         fprintf (f, "}\n\n");
  700.         break;
  701.     }
  702. }
  703.  
  704.  
  705. static void write_texture (FILE *f, char *mat)
  706. {
  707.     switch (oformat) {
  708.     case POV10:
  709.         fprintf (f, "#declare %s = texture {\n", mat);
  710.         fprintf (f, "    Shiny\n");
  711.         fprintf (f, "    color White\n");
  712.         fprintf (f, "}\n\n");
  713.         break;
  714.  
  715.     case POV20:
  716.         fprintf (f, "#declare %s = texture {\n", mat);
  717.         fprintf (f, "    finish { Shiny }\n");
  718.         fprintf (f, "    pigment { White }\n");
  719.         fprintf (f, "}\n\n");
  720.         break;
  721.  
  722.     case VIVID:
  723.         fprintf (f, "#define %s \\ \n", mat);
  724.         fprintf (f, "    surface { \\ \n");
  725.         fprintf (f, "        ambient 0.1*white \\ \n");
  726.         fprintf (f, "        diffuse 0.8*white \\ \n");
  727.         fprintf (f, "        shine 70, white \\ \n");
  728.         fprintf (f, "    }\n\n");
  729.         break;
  730.  
  731.     case POLYRAY:
  732.         fprintf (f, "define %s\n", mat);
  733.         fprintf (f, "texture {\n");
  734.         fprintf (f, "    surface {\n");
  735.         fprintf (f, "        ambient white, 0.1\n");
  736.         fprintf (f, "        diffuse white, 0.8\n");
  737.         fprintf (f, "        microfacet Reitz 20\n");
  738.         fprintf (f, "    }\n");
  739.         fprintf (f, "}\n\n");
  740.         break;
  741.     }
  742. }
  743.  
  744.  
  745.  
  746. static void write_intro (FILE *f)
  747. {
  748.     switch (oformat) {
  749.     case POV10:
  750.     case POV20:
  751.         fprintf (f, "#include \"colors.inc\"\n");
  752.         fprintf (f, "#include \"shapes.inc\"\n");
  753.         fprintf (f, "#include \"textures.inc\"\n");
  754.         fprintf (f, "\n");
  755.         break;
  756.  
  757.     case VIVID:
  758.         fprintf (f, "#include color.vc\n");
  759.         fprintf (f, "\n");
  760.         break;
  761.  
  762.     case POLYRAY:
  763.         fprintf (f, "include \"colors.inc\"\n");
  764.         fprintf (f, "\n");
  765.         break;
  766.     }
  767. }
  768.  
  769.