Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Thursday 2 February 2012

Export toxiclibs mesh from ruby-processing to PovRAY

Here is my test ruby processing sketch (using my customised toxiclibscore.jar), that exports the toxiclibs mesh as a PovRAY mesh2 object, written to a PovRAY inc file.
#######################################################################
# FtestPOV demonstrates how to save a model as PovRAY mesh2
# format to a Java PrintWriter, called with the processing convenience 
# method create_writer.
#
# Copyright (c) 2012 Martin Prout
#
# This library example is free software you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation either version 2.1 of the License, or (at
# your option) any later version.
#
# http:#creativecommons.org/licenses/LGPL/2.1/
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##########################################################################


load_libraries 'toxiclibscore', 'toxiclibs_p5'
include_package 'toxi.geom'
include_package 'toxi.geom.mesh'
include_package 'toxi.processing'

attr_reader :mesh, :gfx

def setup()
  size(200, 200, P3D)
  @gfx = ToxiclibsSupport.new(self)
  # define a "F" badly
  vert = AABB.fromMinMax(Vec3D.new(-1.0, -4.5, -1.0), Vec3D.new(1.0, 3.5, 1.0))
  box = AABB.fromMinMax(Vec3D.new(1.0, 1.5, -1.0), Vec3D.new(3.0, 3.5, 1.0))
  box2 = AABB.fromMinMax(Vec3D.new(1.0, -2.5, -1.0), Vec3D.new(3.0, -0.5, 1.0))
  @mesh = box.toMesh()
  mesh.addMesh(vert.toMesh())
  mesh.addMesh(box2.toMesh())
end

def draw()
  translate(width/2, height/2)
  scale(15)
  rotate_y(radians(-10))
  gfx.mesh(mesh)
end

def keyPressed()
  if (key == 'e')
    file_id = "FTest"
    pw = create_writer(file_id + ".inc")
    mesh.save_as_pov(pw, false)
    pw.flush()
    pw.close()
    exit()
  end
  if (key == 's')
    save_frame("Frb.png")
  end
end
Here is the pov file, that uses the geometry from the exported ruby-processing sketch, to create a PovRAY scene description file.
// Persistence Of Vision Ray Tracer Scene Description File
// File:  Simple Scene <template for povwriter>
// Vers: 3.7
// Date: January 2012
// Auth: Martin Prout 

#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"
#include "FTest.inc"
#include "golds.inc"


//----------------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.0, 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
object{
mesh2{aabb}                  // name aabb created by modified toxiclibs library
texture {T_Gold_1A}
scale<5, 5, 5>
rotate<0, 25, 0>
translate<0, 20, 40>
}

Processing sketch

PovRAY rendered

No comments:

Post a Comment

Followers

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2