Updated 8 March hemesh library since 1.70 beta includes export code
Here I present how to export from ruby-processing to PovRAY mesh2 format. The beauty of this approach is it does not rely on the processing rendering method, further the mesh2 object is better matched to PovRAY internals then raw triangles so rendering is quicker. However the major advantage is by using the normals calculated by the hemesh library (
I'm using svn version 108 here) we get "smooth" surfaces (there is an option to exclude normals and view facets if desired). Here is the ruby processing sketch:-
load_libraries 'hemesh', 'opengl'
include_package 'wblut.hemesh'
include_package 'wblut.hemesh.core'
include_package 'wblut.hemesh.creators'
include_package 'wblut.hemesh.modifiers'
include_package 'wblut.hemesh.subdividors'
include_package 'wblut.hemesh.tools'
include_package 'wblut.core.processing'
attr_accessor :render, :mesh, :inv_mesh, :display, :creator
def setup()
size(800, 800, OPENGL)
@display = true
res = 20
count = res + 1
values=init_array(count, count, count)
count.times do |i|
count.times do |j|
count.times do |k|
values[i][j][k]=2.1*noise(0.35*i, 0.35*j, 0.35*k)
end
end
end
@creator=HEC_IsoSurface.new()
creator.set_resolution(res, res, res)
creator.set_size(400.0/res, 400.0/res, 400.0/res)
creator.set_values(values.to_java(Java::float[][]))
creator.set_isolevel(1)
creator.set_invert(false)
creator.set_boundary(100)
@mesh=HE_Mesh.new(creator)
mesh.modify(HEM_Smooth.new().set_iterations(20).set_auto_rescale(true))
creator.set_invert(true)
@inv_mesh=HE_Mesh.new(creator)
inv_mesh.modify(HEM_Smooth.new().set_iterations(3).set_auto_rescale(true))
@render=WB_Render.new(self)
end
def draw()
if (display)
screen_render()
else
povray_render()
end
end
def screen_render()
background(120)
lights()
translate(400, 400, 0)
rotate_y(mouse_x*1.0/width*TWO_PI)
rotate_x(mouse_y*1.0/height*TWO_PI)
no_stroke()
fill(255)
render.draw_faces(mesh)
fill(255, 0, 0)
render.draw_faces(inv_mesh)
stroke(0)
render.draw_edges(mesh)
stroke(255, 0, 0, 80)
render.draw_edges(inv_mesh)
end
def povray_render()
file_id = "mesh0"
pw = create_writer(file_id + ".inc")
HET_Export.saveToPOV(mesh, pw)
HET_Export.saveToPOV(inv_mesh, pw)
pw.flush
pw.close
exit
end
def init_array(width, height, depth)
Array.new(width).map!{ Array.new(height).map!{ Array.new(depth)}}
end
def key_pressed()
case key
when 'e', 'E'
@display = false
when 's', 'S'
save_frame("twin_iso.png")
end
end
Here is the associated "pov" file:-
#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 "mesh0.inc"
#include "metals.inc"
#declare camera0 = camera {
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
pigment { NeonBlue }
finish {reflection 0.15}
}
camera { camera0 }
light_source{ light0 }
sky_sphere{ S_Cloud3 }
plane{ ground0 }
object{
mesh2{ obj0 }
texture {T_Silver_5E}
scale<0.3, 0.3, 0.3>
rotate<0, 15, 0>
translate<0, 50, 400>
}
object{
mesh2{ obj2 }
texture {T_Copper_1A}
scale<0.3, 0.3, 0.3>
rotate<0, 15, 0>
translate<0, 50, 400>
}
|
PovRAY rendered |
|
Opengl Rendered |