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

Thursday, 11 October 2012

Joons Sunflow Renderer Fork

I have always been attracted to the way the Joons renderer deals with spheres, ie it makes use of the sphere rendering capabilities of sunflow rather than using any triangle mesh mess.  This is what I'd like to do for my povray libraries. Anyway to understand the joons library I've created a version that works with processing-2.0b3 (and a modified sunflow-0.73). You catch the library at my github account, here is an examples sketch:-


   1 import joons.JoonsRenderer;
   2 
   3 
   4 /**
   5  * This sketch is adapted from the DXF export processing library example, and
   6  * demonstrates the use of the joons library to export processing spheres data to
   7  * sunflow rendering
   8  * @author Martin Prout
   9  */
  10 
  11 JoonsRenderer jr;
  12 boolean rendered = false;
  13 float eyeX = 0;
  14 float eyeY = 115;
  15 float eyeZ = 40;
  16 float centerX = 0;
  17 float centerY = 0;
  18 float centerZ = 40;
  19 float upX = 0;
  20 float upY = 0;
  21 float upZ = -1;
  22 float fov = PI / 4; 
  23 float aspect = 1.0;  
  24 float zNear = 5;
  25 float zFar = 10000;
  26 String[] shades = {"Blue", "Red", "Mirror", "Green"};
  27 int[] DATA = {
  28   -1, 0, 1
  29 };
  30 
  31 /**
  32  * Processing Setup
  33  */
  34 
  35 void setup() {
  36   size(400, 400, P3D);
  37   jr = new JoonsRenderer(this, width, height);
  38   jr.setRenderSpeed(1); 
  39   noStroke();
  40   sphereDetail(18);
  41   jr.addAfterShader("shader {");             // add a shader from processing
  42   jr.addAfterShader("   name Green");
  43   jr.addAfterShader("   type diffuse");
  44   jr.addAfterShader("   diff 0.25 0.8 0.25");
  45   jr.addAfterShader("}");
  46   jr.setShader("object0", "Green"); 
  47 }
  48 
  49 /**
  50  * Processing Draw
  51  */
  52 
  53 void draw() {  
  54   beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  55 
  56   perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  57   camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  58   rotateY(PI/30);
  59   translate(0, 0, 40);
  60   render();
  61   endRecord();
  62   if (rendered) {
  63     jr.display();
  64   }
  65 
  66 }
  67 
  68 
  69 /**
  70  * Render processing sketch
  71  */
  72 void render() {
  73   for (int y : DATA) {
  74     for (int x : DATA) {
  75       for (int z : DATA) {
  76         pushMatrix();
  77         translate(22 * x, 22 * y, 22 * z);
  78         fill(random(255), random(255), random(255)); // a nice test for my colorFactory class
  79         sphere(8);
  80         popMatrix();
  81       }
  82     }
  83   }
  84 }
  85 
  86 void keyPressed() {
  87   if (key == 'r' || key == 'R' && !rendered) {
  88     saveFrame("capture.png");
  89     for (int i = 0; i<27; i++)  // assign a shader to each sphere
  90     {
  91     jr.setShader("sphere" + i, shades[i % 4]);  
  92     }
  93     jr.setSC(dataPath("cornell_box.sc"));
  94     rendered=jr.render("bucket");
  95   }
  96 }
  97 
Sunflow rendered.

One thing that is a bit odd to me, is that to translate the balls in the direction from floor to ceiling, I needed to modify the Z coordinate in translate with a positive value. I had expected, in the knowledge of processings poxy coordinate system to require a negative value in the Y coordinate!!!

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