Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Wednesday, 7 March 2012

Exploring Hemesh (svn 108)/ PovRAY (3.7beta) export

Michael Smith posted a nice sketch at openprocessing which I have modified to use an updated version of the hemesh (svn 108) library. Which includes the export to PovRAY mesh2 object tool.
   1 import wblut.core.processing.WB_Render;
   2 import wblut.hemesh.core.HE_Mesh;
   3 import wblut.hemesh.creators.HEC_Dodecahedron;
   4 import wblut.hemesh.modifiers.HEM_Extrude;
   5 import wblut.hemesh.modifiers.HEM_Noise;
   6 import wblut.hemesh.subdividors.HES_PlanarMidEdge;
   7 import wblut.hemesh.tools.HET_Export;
   8 
   9 HE_Mesh mesh;
  10 WB_Render render;
  11 HEM_Extrude modifier;
  12 
  13 void setup() {
  14   size(800, 800, P3D);
  15   fill(120);
  16   createMesh();
  17   HES_PlanarMidEdge subdividor = new HES_PlanarMidEdge();
  18   mesh.subdivide(subdividor, 2);
  19   modifier = new HEM_Extrude();
  20   modifier.setDistance(30);
  21   modifier.setRelative(false);
  22   modifier.setChamfer(4);
  23   modifier.setHardEdgeChamfer(100);
  24   modifier.setThresholdAngle(1.5f * HALF_PI);
  25   modifier.setFuse(true);
  26   modifier.setFuseAngle(0.05f * HALF_PI);
  27   modifier.setPeak(true);
  28   mesh.modify(modifier);
  29   HEM_Noise modifierT = new HEM_Noise();
  30   modifierT.setDistance(10);
  31   mesh.modify(modifierT);
  32   render = new WB_Render(this);
  33 }
  34 
  35 
  36 void draw() {
  37         background(255);
  38         directionalLight(255, 255, 255, 1, 1, -1);
  39         directionalLight(127, 127, 127, -1, -1, 1);
  40         translate(400, 400, 100);
  41         rotateY(mouseX * 1.0f / width * TWO_PI);
  42         rotateX(mouseY * 1.0f / height * TWO_PI);
  43         stroke(0);
  44         render.drawEdges(mesh);
  45         noStroke();
  46         render.drawFaces(mesh);
  47 }
  48 
  49 void createMesh() {
  50   HEC_Dodecahedron creator = new HEC_Dodecahedron();
  51   creator.setEdge(150);
  52   mesh = new HE_Mesh(creator);
  53 }
  54 
  55 
  56 void keyPressed() {
  57   if (key == 's') {
  58     PrintWriter pw = null;
  59     try {
  60       String fileID = "mesh0";
  61       pw = createWriter(fileID + ".inc");
  62       //HET_Export.saveAsPOV(mesh, pw);
  63       HET_Export.saveToPOV(mesh, pw, false);
  64     } catch (Exception e) {
  65     } finally {
  66       pw.flush();
  67       pw.close();
  68     }
  69     exit();
  70   }
  71 }
  72 
  73 
The default option is to include calculated normals (smooth), if you provide the third argument (line 63) it only makes sense if it is false (ie no normals).

Here is the PovRAY file that "includes" the processing generated mesh0.inc file.
   1 // Persistence Of Vision Ray Tracer Scene Description File
   2 // File: radiosity3.pov
   3 // Desc: radiosity tutorial scene
   4 // Date: 2000-2001
   5 // Auth: Christoph Hormann
   6 
   7 // -w240 -h180 +a0.3
   8 
   9 // Updated: 29Dec2010 (cli) modified scene to use 3.7 syntax and more realistic diffuse finish
  10 
  11 //#version 3.6;
  12 #version 3.7;
  13 
  14 #declare use_light=true;
  15 
  16 global_settings {
  17         assumed_gamma 1.0
  18         
  19         radiosity {
  20                 pretrace_start 0.08
  21                 pretrace_end   0.04
  22                 count 35
  23                 
  24                 nearest_count 5
  25                 error_bound 0.2
  26                 recursion_limit 1
  27                 
  28                 low_error_factor .5
  29                 gray_threshold 0.0
  30                 minimum_reuse 0.015
  31                 brightness 1
  32                 
  33                 adc_bailout 0.01/2
  34                 
  35         }
  36 }
  37 
  38 #if (use_light)
  39 light_source {
  40         <.5, 1, -0.5>*20000
  41         color rgb <1.0, 1.0, 1.0>
  42 }
  43 #end
  44 
  45 camera {
  46         location <3.8, 7.2, -10>
  47         look_at <0.0, 1.2, 0.0>
  48         right<240/180, 0, 0>
  49 }
  50 
  51 
  52 #declare FinX= finish { diffuse 0.65 #if (version < 3.7) ambient 0 #end }
  53 #include "/home/sid/hemesh/mesh0.inc"
  54 union {
  55         mesh2{obj0
  56                 
  57         }
  58         texture {
  59                 pigment {
  60                         gradient y
  61                         color_map {
  62                                 [0.0 color rgb < 0.900, 0.910, 1.000 >]
  63                                 [0.0 color rgb < 0.700, 0.705, 1.000 >]
  64                         }
  65                 }
  66                 finish{FinX}
  67                 
  68         }
  69         scale<0.02, 0.02, 0.02>
  70 }
Exported with calculated normals
Exported without normals

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2