See vanilla processing
version here for PovRAY files and a ray-traced image.
load_libraries 'toxiclibscore', 'toxiclibs_p5', 'volumeutils', 'control_panel', 'povmesh', 'verletphysics'
include_package 'povmesh.mesh'
include_package 'toxi.geom'
include_package 'toxi.geom.mesh'
include_package 'toxi.physics'
include_package 'toxi.physics.behaviors'
include_package 'toxi.processing'
include_package 'toxi.physics.constraints'
include_package 'toxi.volume'
attr_reader :mesh, :gfx, :physics, :render, :box, :pm, :inflate
def setup
size(680, 382, P3D)
@gfx = ToxiclibsSupport.new(self)
@pm = POVMesh.new(self)
@render = true
init_physics
end
def draw
physics.update
box.vertices.values().each { |v| v.set(physics.particles.get(v.id))}
box.center(nil)
box.vertices.values().each { |v| physics.particles.get(v.id).set(v)}
box.compute_face_normals()
box.face_outwards()
box.compute_vertex_normals()
background(51)
translate(width / 2.0, height / 2.0, 0)
rotate_x((height / 2 - mouse_x) * 0.01)
rotate_y((width / 2 - mouse_y) * 0.01)
no_fill
lights
directional_light(255, 255, 255, -200, 1000, 500)
specular(255)
shininess(16)
gfx.origin(Vec3D.new, 50)
fill(192)
no_stroke
if (render)
gfx.mesh(box, true, 5)
else
no_loop
pm.begin_save(java.io.File.new(sketchPath("box.inc")))
pm.set_texture(Textures::METAL)
pm.saveAsPOV(box)
pm.end_save
exit
end
end
def init_physics
@box = WETriangleMesh.new
box.add_mesh(AABB.new(Vec3D.new, 50).to_mesh())
4.times { box.subdivide }
@physics = VerletPhysics.new
physics.set_world_bounds(AABB.new(Vec3D.new, 180))
box.vertices.values.each { |v| physics.add_particle(VerletParticle.new(v))}
box.edges.values.each do |e|
a = physics.particles.get((e.a).id)
b = physics.particles.get((e.b).id)
physics.add_spring(VerletSpring.new(a, b, a.distance_to(b), 0.005))
end
end
def key_pressed
case key
when 'r'
init_physics
when 's'
@render = false
end
end
def mouse_pressed
@inflate = AttractionBehavior.new(Vec3D.new, 400, -0.3, 0.001)
physics.add_behavior(inflate);
end
def mouse_released
physics.remove_behavior(inflate)
end