Here is a much more complicated example using toxiclibs in ruby-processing (once more relies on my custom toxiclibscore for the PovRAY export). However you can easily remove that part of the sketch if just want to experiment with using toxiclibs in ruby-processing. This example features the implementation of an abstract java class (namely VolumetricSpace) in jruby.
load_libraries 'toxiclibscore', 'toxiclibs_p5', 'volumeutils', 'opengl'
include_package 'processing.opengl'
include_package 'toxi.geom'
include_package 'toxi.geom.mesh'
include_package 'toxi.volume'
include_package 'toxi.processing'
RES = 64
ISO = 0.2
MAX_ISO = 0.66
attr_reader :mesh, :gfx, :curr_zoom, :is_wire_frame
def setup()
size(720,720, (library_loaded?(:opengl) ? OPENGL : P3D))
@gfx = ToxiclibsSupport.new(self)
@curr_zoom = 1
vol = EvaluatingVolume.new(Vec3D.new(400,400,400), RES, RES, RES, MAX_ISO)
surface = HashIsoSurface.new(vol)
@mesh = WETriangleMesh.new()
surface.compute_surface_mesh(mesh, ISO)
@is_wire_frame = false
end
def draw()
background(0)
translate(width / 2.0, height / 2.0, 0)
rotate_x(mouse_y * 0.01)
rotate_y(mouse_x * 0.01)
scale(curr_zoom)
if (is_wire_frame)
no_fill()
stroke(255)
else
fill(255)
no_stroke()
lights()
end
@gfx.mesh(mesh, true)
end
def key_pressed()
case key
when 'w', 'W'
@is_wire_frame = !is_wire_frame
when '-'
@curr_zoom -= 0.1
when'='
@curr_zoom += 0.1
when 'l', 'L'
LaplacianSmooth.new().filter(mesh, 1)
when 'e', 'E'
file_id = "implicit"
pw = create_writer(file_id + ".inc")
mesh.saveAsPOV(pw)
pw.flush()
pw.close()
exit()
when 's', 'S'
save_frame("implicit.png")
end
end
class EvaluatingVolume < VolumetricSpace
include Processing::Proxy
include_package 'toxi.math'
attr_reader :upper_bound, :lut
FREQ = PI * 3.8
def initialize(scal_vec, resX, resY, resZ, upper_limit)
super(scal_vec, resX, resY, resZ)
@upper_bound = upper_limit
@lut=SinCosLUT.new()
end
def clear()
end
def getVoxelAt(i)
getVoxel(i % resX, (i % sliceRes) / resX, i / sliceRes)
end
def getVoxel(x, y, z)
val = 0
if (x > 0 && x < resX1 && y > 0 && y < resY1 && z > 0 && z < resZ1)
xx = x * 1.0 / resX - 0.5
yy = y * 1.0 / resY - 0.5
zz = z * 1.0 / resZ - 0.5
val = lut.sin(xx * FREQ) + lut.cos(yy * FREQ) + lut.sin(zz * FREQ)
if (val > upper_bound)
val = 0
end
end
return val
end
end
|
opengl rendered implicit function |
No comments:
Post a Comment