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, 26 October 2011

Raytracing with Processing-2.0 alpha

Since beginRaw() and endRaw(), which are essential to my povwriter library, are currently broken (in processing-2.0) (update as of 14th May 2012 see this) I've been re-exploring the sunflow renderers, notably joons and p5_sunflow libraries, as far I can tell the joons library still works, except that preview is not available. The less complicated p5_sunflow library also works, and there is very easy way to alter the sketch to get a proper preview, in the new glorious opengl. Of course I think the PovRAY rendered version in my previous post, is more impressive (however I've also seen some pretty impressive results from the joons renderer "a glass cow in a cornell_box" comes to mind). Here is the hemesh TwinIso sketch as an example:-
import hipstersinc.sunflow.shape.*;
import hipstersinc.sunflow.*;
import hipstersinc.sunflow.shader.*;
import hipstersinc.sunflow.util.*;
import hipstersinc.*;
import hipstersinc.sunflow.light.*;
import wblut.math.*;
import wblut.processing.*;
import wblut.hemesh.creators.*;
import wblut.hemesh.core.*;
import processing.opengl.*;
import wblut.hemesh.modifiers.*;
HE_Mesh mesh;
HE_Mesh invMesh;
WB_Render render;
int res;
void setup() {
  size(800, 800, "hipstersinc.P5Sunflow");
  smooth();
  res = 20;
  float[][][] values=new float[res+1][res+1][res+1];
  for (int i = 0; i < res+1; i++) {
    for (int j = 0; j < res+1; j++) {
      for (int k = 0; k < res+1; k++) {
        values[i][j][k]=2.1*noise(0.35*i, 0.35*j, 0.35*k);
      }
    }
    noLoop();
  }

  HEC_IsoSurface creator=new HEC_IsoSurface();
  creator.setResolution(res, res, res);// number of cells in x,y,z direction
  creator.setSize(400.0/res, 400.0/res, 400.0/res);// cell size
  creator.setValues(values);// values corresponding to the grid points
  // values can also be double[][][]
  creator.setIsolevel(1);// isolevel to mesh
  creator.setInvert(false);// invert mesh
  creator.setBoundary(100);// value of isoFunction outside grid
  // use creator.clearBoundary() to rest boundary values to "no value".
  // A boundary value of "no value" results in an open mesh

  mesh=new HE_Mesh(creator);
  mesh.modify(new HEM_Smooth().setIterations(10).setAutoRescale(true));
  creator.setInvert(true);

  invMesh=new HE_Mesh(creator);
  invMesh.modify(new HEM_Smooth().setIterations(10).setAutoRescale(true));
  render=new WB_Render(this);
}

void draw() {
  background(120);  
  lights();
  translate(400, 400, 0);
  rotateY(mouseX*1.0f/width*TWO_PI);
  rotateX(mouseY*1.0f/height*TWO_PI);
  scale(2);
  noStroke();
  fill(255);
  render.drawFaces(mesh);
  fill(255, 0, 0);
  render.drawFaces(invMesh);
  stroke(0);
  render.drawEdges(mesh);
  stroke(255, 0, 0, 80);
  render.drawEdges(invMesh);
}
The noLoop() in setup is required only for p5_sunflow as is the scale(2), obviously to run the OPENGL version replace hipstersinc.sunflow, with either P3D or OPENGL, it matters not with processing-2.0.....
Sunflow RenderedOpenGL

Tuesday, 18 October 2011

Povray Rendered TwinIso (Hemesh Example)

Previous hemesh processing sketches with different colored faces did not work correctly with my povwriter library, this sketch however, from the latest version of the hemesh library worked rather well. Update 8 March 2012, direct export of mesh to PovRAY mesh2 is possible since hemesh version 1.70. This has the advantage of export of normals, hence smooth surface.

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