Skip to content

Commit

Permalink
add povmesh examples
Browse files Browse the repository at this point in the history
  • Loading branch information
monkstone committed Nov 10, 2015
1 parent dd8661f commit a1e6a10
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.inc
*~
*.jar
*.gem
Expand Down
12 changes: 11 additions & 1 deletion examples/implicit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setup
Processing::ArcBall.init(self)
@vbo = Gfx::MeshToVBO.new(self)
@curr_zoom = 1
vol = EvaluatingVolume.new(TVec3D.new(400,400,400), RES, RES, RES, MAX_ISO)
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)
Expand Down Expand Up @@ -84,6 +84,15 @@ def key_pressed
implicit.setSpecular(color(50, 50, 50))
when 's', 'S'
save_frame("implicit.png")
when 'p', 'P'
no_loop
pm = Gfx::POVMesh.new(self)
file = java.io.File.new('implicit.inc')
pm.begin_save(file)
pm.set_texture(Gfx::Textures::WHITE)
pm.saveAsPOV(mesh, true)
pm.end_save
puts 'finisded'
end
end

Expand All @@ -94,6 +103,7 @@ def define_lights
spot_light(30, 30, 30, 0, 40, 200, 0, -0.5, -0.5, PI / 2, 2)
end

# Custom evaluating Volume Class
class EvaluatingVolume < Volume::VolumetricSpace

attr_reader :upper_bound
Expand Down
46 changes: 46 additions & 0 deletions examples/povmesh/ftest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'toxiclibs'

attr_reader :gfx, :mesh0, :mesh1, :mesh2

def settings
size(200, 200, P3D)
smooth 4
end

def setup
sketch_title('FTest')
@gfx = Gfx::ToxiclibsSupport.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
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
end

def draw
background 50, 50, 200
lights
translate(width / 2, height / 2)
scale(10)
rotateY(20.radians)
gfx.choose_stroke_fill(false, Toxi::TColor::WHITE, Toxi::TColor::RED)
gfx.mesh(mesh0)
end
73 changes: 73 additions & 0 deletions examples/povmesh/tentacle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'toxiclibs'

# A 3D Tentacle by Nikolaus Gradwohl http://www.local-guru.net
# Adapted for JRubyArt and mesh to PShape, and mesh2 export by Martin Prout

attr_reader :mesh, :gfx, :tentacle

def settings
size(500, 500, P3D)
end

def setup
sketch_title 'Tentacle'
ArcBall.init(self)
@gfx = Gfx::MeshToVBO.new(self)
volume = VolumetricSpaceArray.new(TVec3D.new(100, 200, 100), 100, 100, 100)
surface = ArrayIsoSurface.new(volume)
@mesh = TriangleMesh.new
brush = RoundBrush.new(volume, 10)
20.times do |i|
brush.set_size(i * 1.2 + 6)
x = cos(i * TWO_PI / 20) * 10
y = sin(i * TWO_PI / 20) * 10
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
end
(4..20).step(4) do |i|
brush.set_size(i / 1.5 + 4)
x = cos(i * TWO_PI / 20) * (i * 1.2 + 16)
y = sin(i * TWO_PI / 20) * (i * 1.2 + 16)
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
brush.set_size(i / 2 + 2)
x2 = cos(i * TWO_PI / 20) * (i * 1.2 + 18)
y2 = sin(i * TWO_PI / 20) * (i * 1.2 + 18)
brush.draw_at_absolute_pos(TVec3D.new(x2, -25 + i * 7, y2), -1.4)
end
volume.close_sides
surface.reset
surface.compute_surface_mesh(mesh, 0.5)
no_stroke
@tentacle = gfx.mesh_to_shape(mesh, true)
tentacle.set_fill(color(200, 10, 10))
tentacle.set_ambient(80)
tentacle.set_specular(80)
end

def draw
background(150)
lights
setup_lights
shape(tentacle)
end

def setup_lights
lights
ambient_light(100, 100, 100)
directional_light(100, 100, 100, -1, -1, 1)
light_specular(50, 50, 50)
end

def key_pressed
case key
when 'p', 'P'
fileID = 'Tentacle'
pm = Gfx::POVMesh.new(self)
pm.begin_save(java.io.File.new(fileID + '.inc'))
pm.set_texture(Gfx::Textures::RED) # red with Phong texture
pm.saveAsPOV(mesh, true)
pm.end_save
exit
when 's', 'S'
save_frame('Tentacle.png')
end
end
7 changes: 4 additions & 3 deletions src/toxi/processing/POVWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class POVWriter implements POVInterface {
/**
*
*/
public final String VERSION = "0.58";
public final String VERSION = "0.60";
/**
*
*/
Expand Down Expand Up @@ -72,7 +72,8 @@ public class POVWriter implements POVInterface {
// }
public POVWriter(File meshObj) {
this.opt = Textures.RAW;
spath = meshObj.getParent();
String path = meshObj.getAbsolutePath();
spath = path.replaceFirst(meshObj.getName(), "");
try {
this.povWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(meshObj), "UTF8")));
} catch (IOException ex) {
Expand Down Expand Up @@ -415,7 +416,7 @@ protected void endForeground() {
povWriter.append("}");
povWriter.append(eol);

String outFile = spath + File.separator + "my_texture.inc";
String outFile = spath + "my_texture.inc";
// if (declaredOpt.size() > 1) { // guard against only RAW
try {
PrintWriter pw;
Expand Down
2 changes: 1 addition & 1 deletion src/toxi/processing/Tracing.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package povmesh.mesh;
package toxi.processing;

/**
*
Expand Down
10 changes: 6 additions & 4 deletions toxiclibs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ Gem::Specification.new do |spec|
spec.version = Toxiclibs::VERSION
spec.has_rdoc = true
spec.extra_rdoc_files = %w{README.md LICENSE.md}
spec.summary = %q{Experimental gem for some toxiclibs}
spec.description = %q{A gem wrapper for some toxiclibs jars}
spec.summary = %q{Updated and extended toxiclibs libraries for JRubyArt}
spec.description =<<-EOS
Toxiclibs java libraries wrapped in a rubygem. Updated to use java lambda
expressions (available since jdk8). Also new since version 0.5.0 are 3D Mesh
to PShape and 3D mesh to Povray mesh2 utilities.
EOS
spec.license = 'GPLv3'
spec.authors = %w{Karsten/ Schmidt Martin/ Prout}
spec.email = 'martin_p@lineone.net'
Expand All @@ -28,5 +32,3 @@ Gem::Specification.new do |spec|
spec.requirements << 'maven = 3.3.3'
spec.requirements << 'jruby_art = 1.0+'
end


0 comments on commit a1e6a10

Please sign in to comment.