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, 31 October 2012

Improved Joons-Fork (ArcBall added)

Despite there being very little current interest in the Joons library I have continued to meddle with my fork, I have now implemented the rotate(w, x, y, z) function, which was pre-requisite before adding ArcBall functionality. Here is my FTest sketch that demonstrates the ArcBall usage (the rotate function is 'hidden' in the library so don't expect to see it). In this sketch rotation is constrained about the Z axis, and achieved by
'dragging the mouse'.

   1 import joons.JoonsRenderer;
   2 import joons.util.ArcBall;
   3 import joons.util.Constrain;
   4 
   5 JoonsRenderer jr;
   6 ArcBall arcball;
   7 float eyeX = 0;
   8 float eyeY = 115;
   9 float eyeZ = 40;
  10 float centerX = 0;
  11 float centerY = 0;
  12 float centerZ = 40;
  13 float upX = 0;
  14 float upY = 0;
  15 float upZ = -1;
  16 float fov = PI / 4; 
  17 float aspect = 1.0;  
  18 float zNear = 5;
  19 float zFar = 10000;
  20 
  21 void setup() {
  22   size(600, 600, P3D);
  23   jr = new JoonsRenderer(this);
  24   arcball = new ArcBall(this, 0, 0, width*0.8);
  25   arcball.constrain(Constrain.ZAXIS);  
  26   jr.setRenderSpeed(1);  
  27   //renderSpeed is set 1 by default, if this method is not called.
  28   //speed is inversely proportional to the render quality
  29 
  30   /*SC file format:-
  31    Image Settings
  32    Lights
  33    Shaders
  34    Modifiers
  35    Objects
  36    Instances
  37    */
  38 }
  39 
  40 
  41 void draw() {
  42   background(200);
  43   if (jr.displaySketch()){
  44   beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  45 
  46   perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  47   camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  48   arcball.update();     // need this here for JoonsRenderer to record rotations
  49   render();
  50   endRecord();
  51   }
  52 }
  53 
  54 void render() {  // encapsulate the processing sketch as a function  
  55   translate(0, 0, 8);
  56   fill(255, 0, 0);
  57   box(15);
  58   translate(0, 0, 15);
  59   box(15);
  60   translate(15, 0, 0);
  61   box(15);
  62   translate(-15, 0, 15);
  63   box(15);
  64   translate(0, 0, 15);  
  65   box(15);
  66   translate(15, 0, 0);
  67   box(15);
  68 }
  69 
  70 
  71 void keyPressed() {
  72   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  73     saveFrame("capture.png");
  74     jr.setShader("object0", "Red");
  75     jr.setSC(dataPath("cornell_box.sc"));
  76     
  77     jr.render("ipr");
  78     // render using render("ipr") to render quick and rough,
  79     // and render("bucket") to render slow and smooth
  80     // if successfully rendered, returns true
  81   }
  82 }
  83 
FTest sketch snapshot ('F' rotated via arcball)
Sunflow ray traced sketch

Thursday, 25 October 2012

Running Vanilla Processing from jEdit

Now that command line has been restored for processing, it is now quite possible to run the sketch that your are currently editing from emacs, vim, jedit and textmate. Here is what I did for jEdit:-

I created a console commando file processing.xml see embedded gist:-

I created a bsh macro script processing.bsh
   1 new console.commando.CommandoDialog(view, null);
   2 runCommandInConsole(view,"System","processing");


I put the console script in my local .jedit commando folder, I put the processing.bsh script in the macro folder. To copy the gist click on the "view raw" link. You obviously require the console plugin to run this script, and I have recently updated the highlight mode for processing at the jEdit community downloads. You may also be interested in similar commando files I created for ruby-processing and processing.py. also available as a community download.  The presence of the bsh script in the macros folder is detected by jedit and displayed a as clickable button in the drop down macro menu. I used the commando file to cope with the possible options. However since jEdit "remembers" your previously  selected options and automatically detect the pde file, you mostly just click straight through, so single keystroke is probably also possible.
Here is what the gui looks like
Update 20 October 2012 jEdit community is now back on line so you can now download this commando file and my updated processing modes file from there, confusingly they are both called processing.xml, so make sure to keep them separate, I suggest you first download and install the mode, and only once you are happy that the syntax-highlighting is working OK, before you install the commando file. You will need at a minimum the console plugin, but I suggest installing code2html, and editor scheme plugins at a minimum. See below for a screenshot of me "running" a regular pde script from jEdit. Click on image to see larger size. I quite like to have a floating console(takes up less desktop real-estate, however if you prefer you can anchor it to the bottom of the editor, jEdit is extremely customizable.
 
A regular processing script run directly from jEdit

Wednesday, 24 October 2012

Nested Matrix test Joons-Fork render

In my previous post I presented an intermediate step to this a full nested matrix test, the code for Vec3D and MyBox is presented there, here is the nested matrix test:-


   1 import joons.JoonsRenderer;
   2 
   3 JoonsRenderer jr;
   4 
   5 float eyeX = 0;
   6 float eyeY = 115;
   7 float eyeZ = 40;
   8 float centerX = 0;
   9 float centerY = 0;
  10 float centerZ = 40;
  11 float upX = 0;
  12 float upY = 0;
  13 float upZ = -1;
  14 float fov = PI / 4; 
  15 float aspect = 1.0;  
  16 float zNear = 5;
  17 float zFar = 10000;
  18 MyBox[] boxes;
  19 Vec3D incTrans = new Vec3D(-10, 0, 10);
  20 Vec3D incRot = new Vec3D(radians(5), 0, radians(10));
  21 Vec3D sz = new Vec3D(20, 20, 20);
  22 float rotX = 0;
  23 float ROT_INC = 0.01;
  24 void setup() {
  25   size(600, 600, P3D);
  26   jr = new JoonsRenderer(this, width, height);
  27   jr.setRenderSpeed(1);  
  28   //renderSpeed is set 1 by default, if this method is not called.
  29   //speed is inversely proportional to the render quality
  30   boxes = new MyBox[4];
  31   /*SC file format:-
  32    Image Settings
  33    Lights
  34    Shaders
  35    Modifiers
  36    Objects
  37    Instances
  38    */
  39 }
  40 
  41 
  42 void draw() {
  43   if (jr.displaySketch()) {
  44     beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  45     perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  46     camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  47     render();
  48     endRecord();
  49   }
  50 }
  51 
  52 void render() {  // encapsulate the processing sketch as a function
  53   background(100);
  54   Vec3D pos = new Vec3D(25, 0, 20);
  55   Vec3D rot = new Vec3D();
  56   rotX += ROT_INC;
  57   translate(7, -20, 30);
  58   fill(255);
  59   sphere(15);
  60   pushMatrix();
  61   rotateX(rotX);
  62   for (MyBox myBox: boxes) {
  63     myBox = new MyBox(sz, pos, rot);
  64     pos = pos.add(incTrans);
  65     rot = rot.add(incRot);
  66   }
  67   popMatrix();
  68 }
  69 
  70 void keyPressed() {
  71   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  72     noLoop();
  73     saveFrame("capture.png");
  74     jr.setShader("object0", "Red");
  75     jr.setShader("sphere0", "Glass");
  76     jr.setSC(dataPath("cornell_box.sc"));
  77     jr.render("bucket");
  78     // render using render("ipr") to render quick and rough,
  79     // and render("bucket") to render slow and smooth
  80     // if successfully rendered, returns true
  81   }
  82 }
  83 
processing sketch
sunflow rendered

Tuesday, 23 October 2012

Another Matrix Test for Joons-Fork

Here is an idea I had for testing both rotation and translation with pushMatrix and popMatrix with my joons fork (still only single depth, but readily adjustable). First I created my own Vec3D and MyBox classes in the processing ide.

Vec3D:-

   1 class Vec3D {
   2   float x, y, z;
   3 
   4   Vec3D() {
   5     this.x = 0;
   6     this.y = 0;
   7     this.z = 0;
   8   }
   9 
  10   Vec3D(float x, float y, float z) {
  11     this.x = x;
  12     this.y = y;
  13     this.z = z;
  14   }
  15 
  16   Vec3D(Vec3D v) {
  17     this.x = v.x;
  18     this.y = v.y;
  19     this.z = v.z;
  20   }
  21 
  22   Vec3D add(Vec3D v) {
  23     Vec3D vcopy = new Vec3D(this);
  24     vcopy.x += v.x;
  25     vcopy.y += v.y;
  26     vcopy.z += v.z;
  27     return vcopy;
  28   }
  29 }
  30 

MyBox:-

   1 class MyBox {
   2   Vec3D sz;
   3   Vec3D rot;
   4   Vec3D trans;
   5 
   6   MyBox(Vec3D sz, Vec3D trans, Vec3D rot) {
   7     this.sz = sz;
   8     this.trans = trans;
   9     this.rot = rot;
  10     pushMatrix();
  11     fill(200, 0, 0);
  12     stroke(0);
  13     translate(trans.x, trans.y, trans.z);
  14     rotateX(rot.x);
  15     rotateY(rot.y);
  16     rotateZ(rot.z);
  17     box(sz.x, sz.y, sz.z);
  18     popMatrix();
  19   }
  20 }

The Sketch:-

   1 import joons.JoonsRenderer;
   2 
   3 JoonsRenderer jr;
   4 
   5 float eyeX = 0;
   6 float eyeY = 115;
   7 float eyeZ = 40;
   8 float centerX = 0;
   9 float centerY = 0;
  10 float centerZ = 40;
  11 float upX = 0;
  12 float upY = 0;
  13 float upZ = -1;
  14 float fov = PI / 4; 
  15 float aspect = 1.0;  
  16 float zNear = 5;
  17 float zFar = 10000;
  18 MyBox[] boxes;
  19 Vec3D incTrans = new Vec3D(-10, 0, 10);
  20 Vec3D incRot = new Vec3D(radians(5), 0, radians(10));
  21 Vec3D sz = new Vec3D(20, 20, 20);
  22 
  23 void setup() {
  24   size(600, 600, P3D);
  25   jr = new JoonsRenderer(this, width, height);
  26   jr.setRenderSpeed(1);  
  27   //renderSpeed is set 1 by default, if this method is not called.
  28   //speed is inversely proportional to the render quality
  29   boxes = new MyBox[4];
  30   /*SC file format:-
  31    Image Settings
  32    Lights
  33    Shaders
  34    Modifiers
  35    Objects
  36    Instances
  37    */
  38 }
  39 
  40 
  41 void draw() {
  42   if (jr.displaySketch()){
  43   beginRecord("joons.OBJWriter", "");// just call like this. Leave the second parameter as "".
  44   perspective(fov, aspect, zNear, zFar);// use perspective() before camera()!!
  45   camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
  46   render();
  47   endRecord();
  48   }
  49 }
  50 
  51 void render() {  // encapsulate the processing sketch as a function    
  52   Vec3D pos = new Vec3D(20, 0, 30);
  53   Vec3D rot = new Vec3D();
  54   for (MyBox myBox: boxes){
  55     myBox = new MyBox(sz, pos, rot);
  56     pos = pos.add(incTrans);
  57     rot = rot.add(incRot);
  58   }
  59 }
  60 
  61 void keyPressed() {
  62   if (key == 'r' || key == 'R' && jr.displaySketch()) {
  63     saveFrame("capture.png");
  64     jr.setShader("object0", "Red");
  65     jr.setSC(dataPath("cornell_box.sc"));
  66     jr.render("bucket");
  67     // render using render("ipr") to render quick and rough,
  68     // and render("bucket") to render slow and smooth
  69     // if successfully rendered, returns true
  70   }
  71 }
sunflow rendered sketch
processing sketch

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