Hey not only can I run sketches in ruby-processing-3.0 using my
toxiclibs gem but I can also run them in watch mode, my only problem is can't dispose of the frame of the old sketch (has black background, which is frozen so probably not eating resources). Here I am using jEdit as my ruby-processing ide, which has advantages if you you want test different java versions etc...:-
require 'toxiclibs'
load_library :vecmath
RES = 64
ISO = 0.2
MAX_ISO = 0.66
attr_reader :mesh, :gfx, :curr_zoom, :is_wire_frame
def setup
sketch_title 'Isosurface'
ArcBall.init(self)
@gfx = Gfx::ToxiclibsSupport.new(self)
vol = EvaluatingVolume.new(TVec3D.new(400, 400, 400), RES, RES, RES, MAX_ISO)
surface = Volume::HashIsoSurface.new(vol)
@mesh = WETriangleMesh.new
surface.compute_surface_mesh(mesh, ISO)
@is_wire_frame = false
end
def settings
size(720, 720, P3D)
end
def draw
background(200, 0, 200)
if is_wire_frame
no_fill
stroke(255)
else
fill(255)
no_stroke
define_lights
lights
end
@gfx.mesh(mesh, true)
end
def key_pressed
case key
when 'w', 'W'
@is_wire_frame = !is_wire_frame
when 'l', 'L'
LaplacianSmooth.new.filter(mesh, 1)
when 's', 'S'
save_frame('implicit.png')
end
end
def define_lights
ambient_light(50, 50, 50)
point_light(30, 30, 30, 200, -150, 0)
directional_light(0, 30, 50, 1, 0, 0)
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, -0.5, PI / 2, 2)
end
class EvaluatingVolume < Volume::VolumetricSpace
include Processing::Proxy
attr_reader :upper_bound
FREQ = PI * 3.8
def initialize(scal_vec, resX, resY, resZ, upper_limit)
super(scal_vec, resX, resY, resZ)
@upper_bound = upper_limit
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 = cos(xx * FREQ) * sin(yy * FREQ) + cos(yy * FREQ) * sin(zz* FREQ) + cos(zz * FREQ) * sin(xx * FREQ)
val = 0 if val > upper_bound
end
val
end
end
No comments:
Post a Comment