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

Sunday, 8 May 2011

Dreaming of Processing to Povray Export of Primitives

I would like to support the export of processing primitives to PovRAY, but I have found simple processing tools to be next to useless ( I had hoped modelX, modelY and modelZ would come to my rescue, but I think they are probably broken). Next I looked at using toxiclibs primitives and they do seem somewhat more interesting, dispensing with all the matrix operations needed to use the box and sphere of vanilla processing:-

import povexport.*;
import peasy.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.processing.*;

ToxiclibsSupport gfx;
PeasyCam cam;
PovExporter export;
boolean record = false;

void setup() {
  size(600,600,OPENGL);
  hint(ENABLE_OPENGL_4X_SMOOTH);
  hint(DISABLE_OPENGL_ERROR_REPORT);
  cam = new PeasyCam(this, 0.0, 0.0, 0.0, 300);
  gfx=new ToxiclibsSupport(this);
  export = new PovExporter(this);
}

void draw() {
  background(0);
  lights();
  noStroke();
  if (record) {
    noLights();
    noLoop();
    beginRaw(PovExporter.POV, dataPath("output.pov"));
  }  
  Vec3D p1=new Vec3D(50,50,50);
  Vec3D p2=new Vec3D(-50,-50,-50);
  Vec3D p3=new Vec3D(60,60,60);
  AABB b=AABB.fromMinMax(p1,p2);
  fill(255, 0, 0);
  gfx.box(b);
   fill(0, 0, 255);
  gfx.sphere(new Sphere(p3, 50), 30);
  if (record) {
    endRaw();
    record = false;
    loop();
  }
}

void keyPressed() {
  switch(key) {
  case 'r':    
    record = true;    
    break;
  case 'e': 
    String[] args = {
      "/home/tux/bin/jedit", dataPath("output.pov")
    };
    //String[] args = {export.getPovrayPath(), dataPath("output.pov")}; // use this if path has been set
    try {    // open(args); just should work on processing but didn't for me
      java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
      runtime.exec(args);
    }
    catch(IOException e) {
      e.printStackTrace();
    }
    break;
  }
}


This is the sort of PovRAY output I would like to be able to produce:-

// Persistence Of Vision Ray Tracer Scene Description File
// File:  Simple Scene <template for povwriter>
// Vers: 3.7
// Date: March 2011
// Auth: Martin Prout 

// +w300 +h300

#version 3.7;

global_settings{
  assumed_gamma 1.0
  radiosity{
    pretrace_start 0.04
    pretrace_end 0.01
    count 200
    recursion_limit 3
    nearest_count 10
    error_bound 0.5
  }
}

#include "colors.inc"
#include "skies.inc"

// ---------------declare adjustments to processing scene
#declare ScaleP5 = 0.3;     // scale factor
#declare TransXP5 = -20;    // translate in X axis
#declare TransYP5 = 70;    // translate in Y axis
#declare TransZP5 = -50;    // translate in Z axis
#declare RotYP5 = 15;       // rotate around Y axis
#declare RotXP5 = 0;        // rotate around Y axis
#declare RotZP5 = 0;         // rotate around Y axis
// ---------------end of declare adjustments to scene

//----------------declare default colors
#declare CornellRed = rgb<0.57, 0.025, 0.025>;  // Right wall Cornell Box
#declare CornellGreen = rgb<0.025, 0.236, 0.025>; // Left wall Cornell Box
#declare LineFill = rgb<1.0, 0.9, 0.8>; // polygon outline color
#declare LineCol = rgb<0.3, 0.225, 0.12>; // polygon outline color
#declare TransFill = rgbf<1.0, 0.95, 0.8, 0.7>; // polygon outline color
#declare BuddhaGold = rgb<195, 160, 4>/255; // Custom Gold
//----------------end declare default colors #### paste sketch after this ####

//----------------begin declare finish

#declare Finish0=finish{diffuse 0.75 emission 0}  // Stroke
#declare Finish1=finish{diffuse 0.78 emission 0}  // Cornell Box Light Patch
#declare Finish2=finish{emission 0.1 phong 0.5 phong_size 10.0}   // Processing object finish

//----------------end declare finish

#declare SWIDTH=1.0; // processing equivalent is stroke width

//----------------begin declare pigment

#declare Pigment0 = pigment{rgb<1, 1, 1>}  // Cornell Box Light Patch

//----------------end declare pigment

//----------------begin declare texture

#declare WhiteT=texture{pigment{White} finish{Finish0}} //
#declare RedT=texture{pigment{CornellRed} finish{Finish0}}   // Cornell Box Walls
#declare GreenT=texture{pigment{CornellGreen} finish{Finish0}} //
#declare Texture0=texture{pigment{LineFill} finish{Finish1}} // this is for 'stroke' color

//----------------end declare texture

//----------------declare scene Settings
#declare camera0 = camera {            // define additional cameras to suit viewing preferences
   location <-1.5, 30.0, -150.0>
   direction <0.0, 0.0, 2.0>
   up  <0.0, 1.0, 0.0>
   right <1.33333, 0.0, 0.0>
   look_at <0.0, 25.0, 35.0>
}

#declare light0 = light_source { <100.0, 100.0, -200.0> colour White }

#declare ground0 = plane { <0.0, 1.0, 0.0>, 0.0  // a reflective ground plane
   pigment { NeonBlue }
   finish {reflection 0.15}
}

//------------------end of declare scene settings

// -----------------set the scene

camera { camera0 }              // ------------------------------------------
                                //  The use of declared values makes it possible to easily 
light_source{ light0 }          //  change the way the scene is rendered. Just define an
                                //  additional camera say for your template, and do the
sky_sphere{ S_Cloud3 }          //  substitution here. Retain the original definition and
                                //  you can easily backtrack. Definitions can also be saved
plane{ ground0 }                //  as included file see colors.inc for an example.
                                // ---------------------------------------------  
// -----------------end set the scene

// -----------------hand crafted sketch begins here------------------------

union{
  box{ <50,50,50>,<-50,-50,-50>
    texture{ pigment{rgb<0.7, 0, 0>}
      finish {Finish2}    }
  }
   sphere{ <50,40,40>,60
    texture{ pigment{rgb<0.7, 0.7, 0.7>}
      finish {Finish2}
    }
  }
  translate<TransXP5, TransYP5, TransZP5>
rotate<RotXP5, RotYP5, RotZP5>
scale<ScaleP5, ScaleP5, ScaleP5>

}

Povray Primitives Hand Edited




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