-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ruby-processing/toxicgem
- Loading branch information
Showing
5 changed files
with
177 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,59 @@ | ||
require 'toxiclibs' | ||
|
||
attr_reader :gfx, :mesh0, :mesh1, :mesh2 | ||
attr_reader :gfx, :mesh0, :mesh1, :mesh2, :fshape | ||
|
||
def settings | ||
size(200, 200, P3D) | ||
smooth 4 | ||
smooth 8 | ||
end | ||
|
||
def setup | ||
sketch_title('FTest') | ||
@gfx = Gfx::ToxiclibsSupport.new(self) | ||
ArcBall.init(self) | ||
@gfx = Gfx::MeshToVBO.new(self) | ||
# define a rounded cube using the SuperEllipsoid surface function | ||
vert = AABB.fromMinMax(TVec3D.new(-1.0, -3.5, -1.0), TVec3D.new(1.0, 3.5, 1.0)) | ||
box = AABB.fromMinMax(TVec3D.new(1.0, -1.5, -1.0), TVec3D.new(3.0, -3.5, 1.0)) | ||
box2 = AABB.fromMinMax(TVec3D.new(1.0, 2.0, -1.0), TVec3D.new(3.0, 0.0, 1.0)) | ||
@mesh0 = box.to_mesh | ||
@mesh1 = vert.to_mesh | ||
@mesh2 = box2.to_mesh | ||
@mesh2 = box2.to_mesh # build a composite mesh | ||
mesh0.add_mesh(mesh1) | ||
mesh0.add_mesh(mesh2) | ||
mesh0.compute_face_normals | ||
mesh0.compute_vertex_normals | ||
fileID = 'FTest' | ||
pm = Gfx::POVMesh.new(self) | ||
file = java.io.File.new(sketchPath(fileID + '.inc')) | ||
pm.begin_save(file) | ||
pm.set_texture(Gfx::Textures::CHROME) | ||
pm.saveAsPOV(mesh0.faceOutwards, false) | ||
# pm.set_texture(Textures::RED) | ||
# pm.saveAsPOV(mesh1, false) | ||
# pm.set_texture(Textures::WHITE) | ||
# pm.saveAsPOV(mesh2, false) | ||
pm.end_save | ||
# exit | ||
fill(color('#c0c0c0')) # silver | ||
specular(20, 20, 20) | ||
ambient(100) | ||
no_stroke | ||
@fshape = gfx.mesh_to_shape(mesh0, false) | ||
end | ||
|
||
def draw | ||
background 50, 50, 200 | ||
lights | ||
translate(width / 2, height / 2) | ||
background 80, 80, 160 | ||
setup_lights | ||
scale(10) | ||
rotateY(20.radians) | ||
gfx.choose_stroke_fill(false, Toxi::TColor::WHITE, Toxi::TColor::RED) | ||
gfx.mesh(mesh0) | ||
shape(fshape) | ||
end | ||
|
||
def setup_lights | ||
lights | ||
ambient_light(150, 150, 150) | ||
directional_light(100, 100, 100, -1, 0, 0) | ||
directional_light(100, 100, 100, 1, 0, -1) | ||
end | ||
|
||
|
||
def key_pressed | ||
case key | ||
when 'p', 'P' | ||
fileID = 'FTest' | ||
pm = Gfx::POVMesh.new(self) | ||
file = java.io.File.new(sketchPath(fileID + '.inc')) | ||
pm.begin_save(file) | ||
pm.set_texture(Gfx::Textures::CHROME) | ||
pm.saveAsPOV(mesh0.faceOutwards, false) | ||
pm.end_save | ||
when 's', 'S' | ||
save_frame('FTest.png') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'toxiclibs' | ||
|
||
attr_reader :gfx, :vbo, :meshes | ||
SCALE = 200 | ||
BOX_SIZE = TVec3D.new(5, 5, 50) | ||
|
||
def settings | ||
size(600, 600, P3D) | ||
end | ||
|
||
def setup | ||
sketch_title('Mesh Align') | ||
ArcBall.init(self) | ||
@vbo = Gfx::MeshToVBO.new(self) | ||
no_stroke | ||
@meshes = create_shape(GROUP) | ||
600.times do |i| | ||
# create a new direction vector for each box | ||
dir = TVec3D.new(cos(i * TWO_PI / 75), sin(i * TWO_PI / 50), sin(i * TWO_PI / 25)).normalize | ||
# create a position on a sphere, using the direction vector | ||
pos = dir.scale(SCALE) | ||
# create a box mesh at the origin | ||
b = AABB.new(TVec3D.new, BOX_SIZE).to_mesh | ||
# align the Z axis of the box with the direction vector | ||
b.point_towards(dir) | ||
# move the box to the correct position | ||
b.transform(Toxi::Matrix4x4.new.translate_self(pos.x, pos.y, pos.z)) | ||
b.compute_face_normals | ||
temp = vbo.mesh_to_shape(b, false) | ||
temp.disable_style | ||
temp.set_fill(color(rand(255), rand(255), rand(255))) | ||
meshes.add_child(temp) | ||
end | ||
end | ||
|
||
def draw | ||
background 50, 50, 200 | ||
define_lights | ||
shape(meshes) | ||
end | ||
|
||
def define_lights | ||
lights | ||
shininess(16) | ||
directionalLight(255, 255, 255, 0, -1, 1) | ||
specular(255) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'toxiclibs' | ||
|
||
####### | ||
# After Paul Bourke see http://paulbourke.net/geometry/sphericalh/ | ||
# radius = | ||
# sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7 | ||
# where phi = (0..PI) and theta = (0..TWO_PI) | ||
# As implemented by Karsten Schmidt aka toxi/postspectacular | ||
####### | ||
|
||
attr_reader :gfx, :mesh, :spherical, :param | ||
|
||
def setup | ||
sketch_title 'Spherical Harmonics Mesh Builder' | ||
ArcBall.init(self) | ||
@param = [8, 4, 1, 5, 1, 4, 0, 0] # default function parameters (m0..m7) | ||
@mesh = spherical_mesh(param) | ||
@gfx = Gfx::MeshToVBO.new(self) # Mesh to vertex buffer object converter | ||
no_stroke | ||
@spherical = gfx.mesh_to_shape(mesh, true) # white | ||
end | ||
|
||
def draw | ||
background(0) | ||
lights | ||
shininess(16) | ||
directional_light(255, 255, 255, 0, -1, 1) | ||
specular(255) | ||
shape(spherical) | ||
end | ||
|
||
def key_pressed | ||
return unless (key == 'r') | ||
@mesh = spherical_mesh(random_parameters) | ||
no_stroke | ||
@spherical = gfx.mesh_to_colored_shape(mesh, true) # harmonic colors | ||
end | ||
|
||
def random_parameters | ||
(0..8).map { rand(0..8) } | ||
end | ||
|
||
def spherical_mesh(param) | ||
b = SurfaceMeshBuilder.new(SphericalHarmonics.new(param.to_java(:float))) | ||
b.create_mesh(nil, 80, 60) | ||
end | ||
|
||
def settings | ||
size(1024, 576, P3D) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Toxiclibs | ||
VERSION = '0.5.1' | ||
VERSION = '0.5.1'.freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters