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

Monday, 15 October 2012

Tentacle as a retained shape (and export to Povray)

Almost 2 years ago Nikolaus Gradwohl (aka local guru) created a solid tentacle model using processing (and toxiclibs). Here I explore the model as a retained shape(vbo), and the export as a povray mesh2 object. This sketch requires toxiclibs, my povmesh library and processing-2.0. May'be I could create an octopus. By the way I should mention mousewheel for zoom, and drag mouse for arc wheel manipulation.
   1 /**
   2 A 3D tentacle by <a href="http://www.local-guru.net/">guru</a>
   3 */
   4 import povmesh.vbo.*;
   5 import povmesh.mesh.*;
   6 import povmesh.util.*;
   7 import toxi.geom.*;
   8 import toxi.geom.mesh.*;
   9 import toxi.volume.*;
  10 import toxi.processing.*;
  11 
  12 TriangleMesh mesh;
  13 MeshToVBO gfx;
  14 PShape tentacle;
  15 ArcBall arcball;
  16 
  17 void setup() {
  18   size(500,500,P3D);  
  19   arcball = new ArcBall(this);
  20   arcball.constrain(Constrain.YAXIS);  
  21   gfx = new MeshToVBO(this);
  22   VolumetricSpace volume = new VolumetricSpaceArray( new Vec3D(100,200,100), 100, 100, 100 );  
  23   IsoSurface surface = new ArrayIsoSurface( volume );
  24   mesh = new TriangleMesh();
  25   
  26   VolumetricBrush brush = new RoundBrush( volume, 10 );
  27   for ( int i=0; i < 20; i ++) {
  28     brush.setSize( i*1.2 + 6 );
  29     float x = cos( i * TWO_PI / 20 ) * 10;
  30     float y = sin( i * TWO_PI / 20 ) * 10;  
  31     brush.drawAtAbsolutePos( new Vec3D(x,-25+i * 7,y), 1 );
  32   }
  33    
  34   for ( int i=4; i < 20; i+=4) {
  35     brush.setSize( i/1.5+4 );
  36     
  37     float x = cos( i * TWO_PI / 20 ) * (i*1.2+16);
  38     float y = sin( i * TWO_PI / 20 ) * (i*1.2+16);  
  39     
  40     brush.drawAtAbsolutePos( new Vec3D(x,-25+i * 7,y), 1 );
  41 
  42    brush.setSize( i/2+2 );    
  43     float x2 = cos( i * TWO_PI / 20  ) * (i*1.2+18);
  44     float y2 = sin( i * TWO_PI / 20  ) * (i*1.2+18);  
  45     brush.drawAtAbsolutePos( new Vec3D(x2,-25+i * 7,y2), -1.4 );
  46   }  
  47   volume.closeSides();
  48   surface.reset();
  49   surface.computeSurfaceMesh( mesh, .5 );
  50   noStroke();
  51   tentacle = gfx.meshToVBO(mesh, true);
  52   tentacle.enableStyle();
  53   tentacle.fill(200, 0, 0);
  54   tentacle.ambient(40);
  55   tentacle.specular(40);
  56 }
  57 
  58 void draw() {
  59     background(100);
  60     lights();
  61     setupLights();
  62     translate( width/2, height/3, 0);
  63     arcball.update(); 
  64     shape( tentacle );
  65 }
  66 
  67 void setupLights() {
  68   lights();
  69   ambientLight(80, 80, 80);
  70   directionalLight(100, 100, 100, -1, -1, 1);
  71   lightSpecular(30, 30, 30);
  72 }
  73 
  74 void keyPressed() {
  75   if (key == 'e') {
  76     String fileID = "Tentacle";
  77     POVMesh pm = new POVMesh(this);
  78     pm.beginSave(new File(sketchPath(fileID + ".inc")));
  79     pm.setTexture(Textures.RED);  // red with Phong texture
  80     pm.saveAsPOV(mesh, true);
  81     pm.endSave();
  82     exit();
  83   }
  84   if (key == 's') {
  85     saveFrame(sketchPath("Tentacle.png"));
  86   }
  87 }
Sketch snapshot


























Here is ini file:-
   1 ; /home/sid/sketchbook/tentacle/Tentacle.ini
   2 ; Created by povwriter2
   3 Input_File_Name=/home/sid/sketchbook/tentacle/Tentacle.pov
   4 Output_File_Name=/home/sid/sketchbook/tentacle/Tentacle.png
   5 ; Set size and aspect ratio
   6 Width=600
   7 Height=600
   8 Declare=ASPECT_RATIO=1.0
   9 ; Quality settings
  10 Quality=11
  11 Antialias=on
here is pov file:-
   1 // Persistence Of Vision Ray Tracer Scene Description File
   2 // File:  Simple Scene <template for povwriter>
   3 // Vers: 3.7
   4 // Date: January 2012
   5 // Auth: Martin Prout 
   6 
   7 #version 3.7;
   8 
   9 global_settings{
  10   assumed_gamma 1.0
  11   radiosity{
  12     pretrace_start 0.04
  13     pretrace_end 0.01
  14     count 200
  15     recursion_limit 3
  16     nearest_count 10
  17     error_bound 0.5
  18   }
  19 }
  20 
  21 #include "colors.inc"
  22 #include "skies.inc"
  23 // ---------------declare adjustments to processing scene
  24 #declare ScaleP5 = 0.1;     // scale factor
  25 #declare TransXP5 = -100;    // translate in X axis
  26 #declare TransYP5 = 200;    // translate in Y axis
  27 #declare TransZP5 = -150;    // translate in Z axis
  28 #declare RotYP5 = 15;       // rotate around Y axis
  29 #declare RotXP5 = 0;        // rotate around Y axis
  30 #declare RotZP5 = 0;         // rotate around Y axis
  31 // ---------------end of declare adjustments to scene
  32 
  33 //----------------declare default colors
  34 #declare CornellRed = rgb<0.57, 0.025, 0.025>;  // Right wall Cornell Box
  35 #declare CornellGreen = rgb<0.025, 0.236, 0.025>; // Left wall Cornell Box
  36 #declare LineFill = rgb<1.0, 0.9, 0.8>; // polygon outline color
  37 #declare LineCol = rgb<0.3, 0.225, 0.12>; // polygon outline color
  38 #declare TransFill = rgbf<1.0, 0.95, 0.8, 0.7>; // polygon outline color
  39 #declare BuddhaGold = rgb<195, 160, 4>/255; // Custom Gold
  40 //----------------end declare default colors #### paste sketch after this ####
  41 
  42 //----------------begin declare finish
  43 
  44 #declare Finish0=finish{diffuse 0.75 emission 0}  // Stroke
  45 #declare Finish1=finish{diffuse 0.78 emission 0}  // Cornell Box Light Patch
  46 #declare Finish2=finish{emission 0.1 phong 0.5 phong_size 10.0}   // Processing object finish
  47 
  48 //----------------end declare finish
  49 
  50 #declare SWIDTH=1.0; // processing equivalent is stroke width
  51 
  52 //----------------begin declare pigment
  53 
  54 #declare Pigment0 = pigment{rgb<1, 1, 1>}  // Cornell Box Light Patch
  55 
  56 //----------------end declare pigment
  57 
  58 //----------------begin declare texture
  59 
  60 #declare WhiteT=texture{pigment{White} finish{Finish0}} //
  61 #declare RedT=texture{pigment{CornellRed} finish{Finish0}}   // Cornell Box Walls
  62 #declare GreenT=texture{pigment{CornellGreen} finish{Finish0}} //
  63 #declare Texture0=texture{pigment{LineFill} finish{Finish1}} // this is for 'stroke' color
  64 
  65 //----------------end declare texture
  66 
  67 //----------------declare scene Settings
  68 #declare camera0 = camera {            // define additional cameras to suit viewing preferences
  69    location <-1.5, 30.0, -150.0>
  70    direction <0.0, 0.0, 2.0>
  71    up  <0.0, 1.0, 0.0>
  72    right <1.0, 0.0, 0.0>
  73    look_at <0.0, 25.0, 35.0>
  74 }
  75 
  76 #declare light0 = light_source { <100.0, 100.0, -200.0> colour White }
  77 
  78 #declare ground0 = plane { <0.0, 1.0, 0.0>, 0.0  // a reflective ground plane
  79    pigment { NeonBlue }
  80    finish {reflection 0.15}
  81 }
  82 
  83 //------------------end of declare scene settings
  84 
  85 // -----------------set the scene
  86 
  87 camera { camera0 }              // ------------------------------------------
  88                                 //  The use of declared values makes it possible to easily 
  89 light_source{ light0 }          //  change the way the scene is rendered. Just define an
  90                                 //  additional camera say for your template, and do the
  91 sky_sphere{ S_Cloud3 }          //  substitution here. Retain the original definition and
  92                                 //  you can easily backtrack. Definitions can also be saved
  93 plane{ ground0 }                //  as included file see colors.inc for an example.
  94                                 // ---------------------------------------------  
  95 // -----------------end set the scene
  96 #include "/home/sid/sketchbook/tentacle/my_texture.inc"
  97 #include "/home/sid/sketchbook/tentacle/Tentacle.inc"
  98 
  99 object{
 100 mesh2{ mesh_objects }
 101 translate<0, 45, 0>                  
 102 }
And here is an extract of the Tentacle.inc file
   1 // generated by POVExport v0.58
   2 #declare mesh_objects = union {
   3 mesh2{
   4 /** untitled */
   5     vertex_vectors {
   6     12096,
   7     <0.50504684, -85.85858, 32.953594>, 
   8     <0.34051752, -85.85858, 32.828285>, 
   9     
  10     ..............................
  11     
  12         <12095, 12043, 12038>, 
  13     <12043, 12095, 12039>, 
  14     }
  15 pigment{ color rgb<1, 0, 0> }
  16 finish{ Phong1 }
  17 }
  18 rotate<0.0, 15.0, 0.0>
  19 scale<0.5, 0.5, 0.5>
  20 translate<0.0, 0.0, 0.0>
  21 }

PovRAY traced tentacle

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