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