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

Saturday, 30 June 2012

Displaying Hemesh meshes as RetainedShapes (VBO)

Very much taken with my success in rendering toxiclibs (Karsten Schmidt) mesh sketches in the processing-2.0 ide using VBO (for efficiency) I thought I would give the Hemesh (Frederick Vanhoutte) the same treatment, for this sketch I was used the latest version of the library hemesh_b1_7agx3, and processing version 2.0a6 (or greater). I have published the conversion library at github, but it is at a very early stage as yet.  I have also posted this sketch at open processing but currently opengl sketches (is supposed to be fixed for processing-2.0?) won't run on that site.

   1 import mshape.*;
   2 import wblut.hemesh.core.*;
   3 import wblut.hemesh.creators.*;
   4 import wblut.hemesh.modifiers.*;
   5 
   6 PShape retainedMesh;
   7 PShape retainedInverse;
   8 ArcBall arcball;   
   9 HE_Mesh mesh;
  10 HE_Mesh invMesh;
  11 int RES = 32;  // original was 20
  12 MeshToVBO mshape;
  13 
  14 void setup() {
  15   size(800, 800, P3D);
  16   arcball = new ArcBall(this);
  17   mshape = new MeshToVBO(this);  
  18   smooth(16);  
  19   float[][][] values = new float[RES + 1][RES + 1][RES + 1];
  20   for (int i = 0; i < RES + 1; i++) {
  21     for (int j = 0; j < RES + 1; j++) {
  22       for (int k = 0; k < RES + 1; k++) {
  23         values[i][j][k] = 2.1 * noise(0.35 * i, 0.35 * j, 0.35 * k);
  24       }
  25     }
  26   }
  27 
  28   HEC_IsoSurface creator = new HEC_IsoSurface();
  29   creator.setResolution(RES, RES, RES);// number of cells in x,y,z direction
  30   creator.setSize(400.0f / RES, 400.0 / RES, 400.0 / RES);// cell size
  31   creator.setValues(values);// values corresponding to the grid points
  32   // values can also be double[][][]
  33   creator.setIsolevel(1);// isolevel to mesh
  34   creator.setInvert(false);// invert mesh
  35   creator.setBoundary(100);// value of isoFunction outside grid
  36   // use creator.clearBoundary() to rest boundary values to "no value".
  37   // A boundary value of "no value" results in an open mesh
  38 
  39   mesh = new HE_Mesh(creator);
  40   mesh.modify(new HEM_Smooth().setIterations(10).setAutoRescale(true));
  41   creator.setInvert(true);
  42   invMesh = new HE_Mesh(creator);
  43   invMesh.modify(new HEM_Smooth().setIterations(10).setAutoRescale(true));
  44   noStroke();
  45   // silver
  46   retainedMesh = mshape.meshToRetained(mesh, 192, 192, 192);
  47   //white marble
  48   retainedInverse = mshape.meshToRetained(invMesh, 249, 246, 224);
  49 }
  50 
  51 
  52 void draw() {
  53   background(0);
  54   lights();
  55   lightSpecular(80, 80, 80);
  56   directionalLight(80, 80, 80, 0, 0, -1);
  57   ambientLight(50, 50, 50);
  58   translate(400, 400, 0);
  59   arcball.update();
  60   shape(retainedMesh);
  61   shape(retainedInverse);
  62 }

TwinIso sketch rendered in processing-2.0 ide as two vbo objects

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