Kango_MathProjects/Math3Dc/PovRay.pde


// PovRay-Export ----------------------------------------------------------------------- 

String GetText( String strPfadKommentar, String strNameKommentar) {

  //    Dim i
  //    Dim j
  //    Dim a(205]
  //    Dim strT

  int i = 0; 

  String [] a = new String[350]; 


  a[i] = "// Persistence of Vision Ray Tracer Scene Description File"; 
  i = i + 1;
  a[i] = "// File: " + strPfadKommentar + " " + strNameKommentar; 
  i = i + 1;
  a[i] = "// Vers: 3.6"; 
  i = i + 1;
  a[i] = "// Desc: Basic Scene Example"; 
  i = i + 1;
  a[i] = "// Date: " + TodaysDate(); 
  i = i + 1;
  a[i] = "// Auth: ?"; 
  i = i + 1;
  a[i] = "//"; 
  i = i + 1;

  a[i] = "// This file was generated by math3D, using code by processing - see www.processing.org."; 
  i = i + 1;  
  a[i] = "// You probably need to adjust the code here in POV-Ray;"; 
  i = i + 1;  
  a[i] = "// e.g. adjust the camera (choose between two); adjust the plane (maybe your work is under it...), adjust the scale of your model, the lights..."; 
  i = i + 1;  

  a[i] = ""; 
  i = i + 1;
  a[i] = "#version 3.6;"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// \"colors\""; 
  i = i + 1;
  a[i] = "#include \"colors.inc\""; 
  i = i + 1;
  a[i] = "// a lot of stone textures"; 
  i = i + 1;
  a[i] = "// T_Stone1 - T_Stone44"; 
  i = i + 1;
  a[i] = "#include \"stones.inc\""; 
  i = i + 1;
  a[i] = "// various [mostly layered] wood textures"; 
  i = i + 1;
  a[i] = "// T_Wood1 - T_Wood35"; 
  i = i + 1;
  a[i] = "#include \"woods.inc\""; 
  i = i + 1;
  a[i] = "// several different gold colors, finishes and textures"; 
  i = i + 1;
  a[i] = "#include \"golds.inc\""; 
  i = i + 1;
  a[i] = "// various metal colors, finishes and textures"; 
  i = i + 1;
  a[i] = "// brass, copper, chrome, silver"; 
  i = i + 1;
  a[i] = "#include \"metals.inc\""; 
  i = i + 1;
  a[i] = "// various metal colors, finishes and textures"; 
  i = i + 1;
  a[i] = "// brass, copper, chrome, silver"; 
  i = i + 1;
  a[i] = "#include \"metals.inc\""; 
  i = i + 1;
  a[i] = "// various glass finishes, colors and interiors"; 
  i = i + 1;
  a[i] = "#include \"glass.inc\""; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "/*"; 
  i = i + 1;
  a[i] = "global_settings {"; 
  i = i + 1;
  a[i] = "  assumed_gamma 1.0"; 
  i = i + 1;
  a[i] = "}   */"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// ----------------------------------------"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "camera {"; 
  i = i + 1;
  a[i] = "  location  <15.0, 30.5, 15  >"; 
  i = i + 1;
  a[i] = "  look_at   <15.0, 0.0,  15.0>"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "camera {"; 
  i = i + 1;
  a[i] = "  location  <90.0, 0.0, -80.0>"; 
  i = i + 1;
  a[i] = "  // direction 1.5*z"; 
  //  i = i + 1;
  a[i] = "  // right     x*image_width/image_height"; 
  // i = i + 1;
  a[i] = "  look_at   < 10.0, 0.0, 0.0>"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = "  "; 
  i = i + 1;
  a[i] = "  "; 
  i = i + 1;
  a[i] = "sky_sphere {"; 
  i = i + 1;
  a[i] = "  pigment {"; 
  i = i + 1;
  a[i] = "    gradient y"; 
  i = i + 1;
  a[i] = "    color_map {"; 
  i = i + 1;
  a[i] = "      [0.0 rgb <0.6,0.7,1.0>]"; 
  i = i + 1;
  a[i] = "      [0.7 rgb <0.0,0.1,0.8>]"; 
  i = i + 1;
  a[i] = "    }"; 
  i = i + 1;
  a[i] = "  }"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "light_source {"; 
  i = i + 1;
  a[i] = "  <0, 0, 0>            // light's position (translated below]"; 
  i = i + 1;
  a[i] = "  color rgb <1, 1, 1>  // light's color"; 
  i = i + 1;
  a[i] = "  translate <-30, 30, -300>"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// ----------------------------------------"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "#macro MySphere (x1,y1,z1)  // ---------------------------------------------------------------------------"; 
  i = i + 1;
  a[i] = "    "; 
  i = i + 1;
  a[i] = "    sphere {"; 
  i = i + 1;
  a[i] = "        <x1,z1,y1>, 1"; 
  i = i + 1;
  a[i] = "        // texture { T_Stone2 }"; 
  i = i + 1;
  a[i] = "        texture { F_Glass5 } // texture { T_Glass1 }"; 
  i = i + 1;
  a[i] = "        "; 
  i = i + 1;
  a[i] = "        /*"; 
  i = i + 1;
  a[i] = "        // material {} is a wrapper for interior and texture"; 
  i = i + 1;
  a[i] = "        // you can declare it like texture and interior too"; 
  i = i + 1;
  a[i] = "        // Note that it has nothing to do with material_map  */ "; 
  i = i + 1;
  a[i] = "        material {"; 
  i = i + 1;
  a[i] = "          texture {"; 
  i = i + 1;
  a[i] = "            pigment { color rgbt <x1, y1, z1, 0.5> }"; 
  i = i + 1;
  a[i] = "            finish { diffuse 0.2 specular 0.6 }"; 
  i = i + 1;
  a[i] = "          }"; 
  i = i + 1;
  a[i] = "          interior {"; 
  i = i + 1;
  a[i] = "          // ior 1.5"; 
  i = i + 1;
  a[i] = "          }"; 
  i = i + 1;
  a[i] = "        }   "; 
  i = i + 1;
  a[i] = "     "; 
  i = i + 1;
  a[i] = "    }"; 
  i = i + 1;
  a[i] = "#end // macro  "; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "#macro MyPoly ( x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4 )  // ----------------------------"; 
  i = i + 1;

  a[i] = "     " ;  
  i = i + 1 ; 
  a[i] = "    // polygons  " ;  
  i = i + 1 ; 
  a[i] = "    polygon { " ;  
  i = i + 1 ; 
  a[i] = "      4, // number of points " ;  
  i = i + 1 ; 
  a[i] = "      <x1,y1,z1>, < x2,y2,z2 >,  " ;  
  i = i + 1 ; 
  a[i] = "      <x3,y3,z3>, <x1,y1,z1>  " ;  
  i = i + 1 ; 
  a[i] = "      texture { T_Chrome_2C } " ;  
  i = i + 1 ; 
  a[i] = "    }" ;  
  i = i + 1 ; 
  a[i] = "       " ;  
  i = i + 1 ; 
  a[i] = "    polygon { " ;  
  i = i + 1 ; 
  a[i] = "      4, // number of points " ;  
  i = i + 1 ; 
  a[i] = "      <x1,y1,z1>, < x2,y2,z2 >,  " ;  
  i = i + 1 ; 
  a[i] = "                  < x4,y4,z4 >, " ;  
  i = i + 1 ; 
  a[i] = "                  <x1,y1,z1>  " ;  
  i = i + 1 ; 
  a[i] = "      texture { T_Chrome_2C } " ;  
  i = i + 1 ; 
  a[i] = "    }       " ;  
  i = i + 1 ; 
  a[i] = "    polygon { " ;  
  i = i + 1 ; 
  a[i] = "      4, // number of points " ;  
  i = i + 1 ; 
  a[i] = "      <x3,y3,z3> , < x2,y2,z2 >,  " ;  
  i = i + 1 ; 
  a[i] = "                  < x4,y4,z4 >," ;  
  i = i + 1 ; 
  a[i] = "                  <x3,y3,z3>  " ;  
  i = i + 1 ; 
  a[i] = "      texture { T_Chrome_2C } " ;  
  i = i + 1 ; 
  a[i] = "    }      " ;  
  i = i + 1 ; 


  a[i] = "    "; 
  i = i + 1;
  a[i] = "#end // macro  "; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// ---------------------------------------------------------------------------"; 
  i = i + 1;
  a[i] = "#declare Radiosity=on;"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "global_settings {"; 
  i = i + 1;
  a[i] = "  assumed_gamma 1.0"; 
  i = i + 1;
  a[i] = "  //max_trace_level 25"; 
  i = i + 1;
  a[i] = "  #if (Radiosity)"; 
  i = i + 1;
  a[i] = "    radiosity {"; 
  i = i + 1;
  a[i] = "      pretrace_start 0.08           // start pretrace at this size"; 
  i = i + 1;
  a[i] = "      pretrace_end   0.04           // end pretrace at this size"; 
  i = i + 1;
  a[i] = "      count 35                      // higher -> higher quality [1..1600] [35]"; 
  i = i + 1;
  a[i] = "      nearest_count 5               // higher -> higher quality [1..10] [5]"; 
  i = i + 1;
  a[i] = "      error_bound 1.8               // higher -> smoother, less accurate [1.8]"; 
  i = i + 1;
  a[i] = "      recursion_limit 3             // how much interreflections are calculated [1..5+] [3]"; 
  i = i + 1;
  a[i] = "      low_error_factor .5           // reduce error_bound during last pretrace step"; 
  i = i + 1;
  a[i] = "      gray_threshold 0.0            // increase for weakening colors [0..1] [0]"; 
  i = i + 1;
  a[i] = "      minimum_reuse 0.015           // reuse of old radiosity samples [0.015]"; 
  i = i + 1;
  a[i] = "      brightness 1                  // brightness of radiosity effects (0..1] [1]"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "      adc_bailout 0.01/2"; 
  i = i + 1;
  a[i] = "      //normal on                   // take surface normals into account [off]"; 
  i = i + 1;
  a[i] = "      //media on                    // take media into account [off]"; 
  i = i + 1;
  a[i] = "      //save_file \"file_name\"       // save radiosity data"; 
  i = i + 1;
  a[i] = "      //load_file \"file_name\"       // load saved radiosity data"; 
  i = i + 1;
  a[i] = "      //always_sample off           // turn sampling in final trace off [on]"; 
  i = i + 1;
  a[i] = "      //max_sample 1.0              // maximum brightness of samples"; 
  i = i + 1;
  a[i] = "    }"; 
  i = i + 1;
  a[i] = "  #end"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "#default {"; 
  i = i + 1;
  a[i] = "  texture {"; 
  i = i + 1;
  a[i] = "    pigment {rgb 1}"; 
  i = i + 1;
  a[i] = "    #if (Radiosity)"; 
  i = i + 1;
  a[i] = "      finish {"; 
  i = i + 1;
  a[i] = "        ambient 0.0"; 
  i = i + 1;
  a[i] = "        diffuse 0.6"; 
  i = i + 1;
  a[i] = "        specular 0.3"; 
  i = i + 1;
  a[i] = "      }"; 
  i = i + 1;
  a[i] = "    #else"; 
  i = i + 1;
  a[i] = "      finish {"; 
  i = i + 1;
  a[i] = "        ambient 0.1"; 
  i = i + 1;
  a[i] = "        diffuse 0.6"; 
  i = i + 1;
  a[i] = "        specular 0.3"; 
  i = i + 1;
  a[i] = "      }"; 
  i = i + 1;
  a[i] = "    #end"; 
  i = i + 1;
  a[i] = "  }"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// ----------------------------------------"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "/*"; 
  i = i + 1;
  a[i] = "light_source {"; 
  i = i + 1;
  a[i] = "  <500,500,-500>       // light's position"; 
  i = i + 1;
  a[i] = "  color rgb <1, 1, 1>  // light's color"; 
  i = i + 1;
  a[i] = "} */"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "sky_sphere {"; 
  i = i + 1;
  a[i] = "  pigment {"; 
  i = i + 1;
  a[i] = "    gradient y"; 
  i = i + 1;
  a[i] = "    color_map {"; 
  i = i + 1;
  a[i] = "      [0.0 rgb <0.6,0.7,1.0>]"; 
  i = i + 1;
  a[i] = "      [0.7 rgb <0.0,0.1,0.8>]"; 
  i = i + 1;
  a[i] = "    }"; 
  i = i + 1;
  a[i] = "  }"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "// ----------------------------------------"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;
  a[i] = "plane {"; 
  i = i + 1;
  a[i] = "  y, -40"; 
  i = i + 1;
  a[i] = "  texture {"; 
  i = i + 1;
  a[i] = "    pigment {"; 
  i = i + 1;
  a[i] = "      checker"; 
  i = i + 1;
  a[i] = "      color rgb <1.0, 0.8, 0.6>"; 
  i = i + 1;
  a[i] = "      color rgb <1.0, 0.0, 0.0>"; 
  i = i + 1;
  a[i] = "      scale 25"; 
  i = i + 1;
  a[i] = "    }"; 
  i = i + 1;
  a[i] = "  }"; 
  i = i + 1;
  a[i] = "}"; 
  i = i + 1;
  a[i] = ""; 
  i = i + 1;

  String strT = "";

  for (int j = 0; j < i; j = j+1) {
    strT = strT + a[j] + "\n";
  }

  return (strT);
} // function 

String TodaysDate () {
  int d = day();    // Values from 1 - 31
  int m = month();  // Values from 1 - 12
  int y = year();   // 2003, 2004, 2005, etc.
  String s = String.valueOf(d);

  return( s+"." + String.valueOf(m) + "." + String.valueOf(y) + " (dd.mm.yyyy)" );
}

void WriteToFile ( String MyText ) {

  // Write to file

  final String fileName = "output.pov"; 

  // for save 
  PrintWriter output;

  int i = 13; 
  int i2 = 10;  
  char c = char(i);
  char c2 = char(i2);
  String SketchPath1 = sketchPath(""); 

  // Create a new file in the sketch directory
  output = createWriter(fileName);   
  String Buffer = MyText; 
  String ReplaceWith = " " +  c + c2; 
  output.println(Buffer.replaceAll ("\n", ReplaceWith )); // Write to the file
  output.flush(); // Writes the remaining data to the file
  output.close(); // Finishes the file
  File f = new File(PathToPOVRayExe);
  if (f.exists()) { 
    // println("I found the file."); 
    String[] params = { 
      PathToPOVRayExe, "/RENDER", "" + SketchPath1 + fileName + "", "/EDIT", "" + SketchPath1 + fileName + "", "/NR"                                                                                                                                                                                     }  
      ;
    // from http://www.coderanch.com/t/419192/Java-General/java/Runtime-getRuntime-exec-String-command
    Runtime rt = Runtime.getRuntime();  //  
    try {   
      rt.exec(params  ) ; // "mspaint " + strPictureLocation);
    } 
    catch (IOException ioe) {   
      ioe.printStackTrace();
    }
  } else 
  {     
    ShowSpecialMessage("Could not find POV-Ray: " + PathToPOVRayExe + 
      ". Sorry. Please correct the path in source.");
  }
} // function 

boolean DoesPOVRayExist () {
  boolean Buffer = false; 
  File f = new File(PathToPOVRayExe);
  if ( ! f.exists() ) { 
    ShowSpecialMessage("Could not find POV-Ray:\n" + PathToPOVRayExe + 
      ". \nSorry. Please correct the path in source."); 
    Buffer = false;
  } else { 
    Buffer = true;
  }
  return ( Buffer );
} // function
//
