Skip to content

Commit a1e6a10

Browse files
author
monkstone
committed
add povmesh examples
1 parent dd8661f commit a1e6a10

File tree

7 files changed

+142
-9
lines changed

7 files changed

+142
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.inc
12
*~
23
*.jar
34
*.gem

examples/implicit.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def setup
5252
Processing::ArcBall.init(self)
5353
@vbo = Gfx::MeshToVBO.new(self)
5454
@curr_zoom = 1
55-
vol = EvaluatingVolume.new(TVec3D.new(400,400,400), RES, RES, RES, MAX_ISO)
55+
vol = EvaluatingVolume.new(TVec3D.new(400, 400, 400), RES, RES, RES, MAX_ISO)
5656
surface = Volume::HashIsoSurface.new(vol)
5757
@mesh = WETriangleMesh.new
5858
surface.compute_surface_mesh(mesh, ISO)
@@ -84,6 +84,15 @@ def key_pressed
8484
implicit.setSpecular(color(50, 50, 50))
8585
when 's', 'S'
8686
save_frame("implicit.png")
87+
when 'p', 'P'
88+
no_loop
89+
pm = Gfx::POVMesh.new(self)
90+
file = java.io.File.new('implicit.inc')
91+
pm.begin_save(file)
92+
pm.set_texture(Gfx::Textures::WHITE)
93+
pm.saveAsPOV(mesh, true)
94+
pm.end_save
95+
puts 'finisded'
8796
end
8897
end
8998

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

106+
# Custom evaluating Volume Class
97107
class EvaluatingVolume < Volume::VolumetricSpace
98108

99109
attr_reader :upper_bound

examples/povmesh/ftest.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'toxiclibs'
2+
3+
attr_reader :gfx, :mesh0, :mesh1, :mesh2
4+
5+
def settings
6+
size(200, 200, P3D)
7+
smooth 4
8+
end
9+
10+
def setup
11+
sketch_title('FTest')
12+
@gfx = Gfx::ToxiclibsSupport.new(self)
13+
# define a rounded cube using the SuperEllipsoid surface function
14+
vert = AABB.fromMinMax(TVec3D.new(-1.0, -3.5, -1.0), TVec3D.new(1.0, 3.5, 1.0))
15+
box = AABB.fromMinMax(TVec3D.new(1.0, -1.5, -1.0), TVec3D.new(3.0, -3.5, 1.0))
16+
box2 = AABB.fromMinMax(TVec3D.new(1.0, 2.0, -1.0), TVec3D.new(3.0, 0.0, 1.0))
17+
@mesh0 = box.to_mesh
18+
@mesh1 = vert.to_mesh
19+
@mesh2 = box2.to_mesh
20+
mesh0.add_mesh(mesh1)
21+
mesh0.add_mesh(mesh2)
22+
mesh0.compute_face_normals
23+
mesh0.compute_vertex_normals
24+
fileID = 'FTest'
25+
pm = Gfx::POVMesh.new(self)
26+
file = java.io.File.new(sketchPath(fileID + '.inc'))
27+
pm.begin_save(file)
28+
pm.set_texture(Gfx::Textures::CHROME)
29+
pm.saveAsPOV(mesh0.faceOutwards, false)
30+
# pm.set_texture(Textures::RED)
31+
# pm.saveAsPOV(mesh1, false)
32+
# pm.set_texture(Textures::WHITE)
33+
# pm.saveAsPOV(mesh2, false)
34+
pm.end_save
35+
# exit
36+
end
37+
38+
def draw
39+
background 50, 50, 200
40+
lights
41+
translate(width / 2, height / 2)
42+
scale(10)
43+
rotateY(20.radians)
44+
gfx.choose_stroke_fill(false, Toxi::TColor::WHITE, Toxi::TColor::RED)
45+
gfx.mesh(mesh0)
46+
end

examples/povmesh/tentacle.rb

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require 'toxiclibs'
2+
3+
# A 3D Tentacle by Nikolaus Gradwohl http://www.local-guru.net
4+
# Adapted for JRubyArt and mesh to PShape, and mesh2 export by Martin Prout
5+
6+
attr_reader :mesh, :gfx, :tentacle
7+
8+
def settings
9+
size(500, 500, P3D)
10+
end
11+
12+
def setup
13+
sketch_title 'Tentacle'
14+
ArcBall.init(self)
15+
@gfx = Gfx::MeshToVBO.new(self)
16+
volume = VolumetricSpaceArray.new(TVec3D.new(100, 200, 100), 100, 100, 100)
17+
surface = ArrayIsoSurface.new(volume)
18+
@mesh = TriangleMesh.new
19+
brush = RoundBrush.new(volume, 10)
20+
20.times do |i|
21+
brush.set_size(i * 1.2 + 6)
22+
x = cos(i * TWO_PI / 20) * 10
23+
y = sin(i * TWO_PI / 20) * 10
24+
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
25+
end
26+
(4..20).step(4) do |i|
27+
brush.set_size(i / 1.5 + 4)
28+
x = cos(i * TWO_PI / 20) * (i * 1.2 + 16)
29+
y = sin(i * TWO_PI / 20) * (i * 1.2 + 16)
30+
brush.draw_at_absolute_pos(TVec3D.new(x, -25 + i * 7, y), 1)
31+
brush.set_size(i / 2 + 2)
32+
x2 = cos(i * TWO_PI / 20) * (i * 1.2 + 18)
33+
y2 = sin(i * TWO_PI / 20) * (i * 1.2 + 18)
34+
brush.draw_at_absolute_pos(TVec3D.new(x2, -25 + i * 7, y2), -1.4)
35+
end
36+
volume.close_sides
37+
surface.reset
38+
surface.compute_surface_mesh(mesh, 0.5)
39+
no_stroke
40+
@tentacle = gfx.mesh_to_shape(mesh, true)
41+
tentacle.set_fill(color(200, 10, 10))
42+
tentacle.set_ambient(80)
43+
tentacle.set_specular(80)
44+
end
45+
46+
def draw
47+
background(150)
48+
lights
49+
setup_lights
50+
shape(tentacle)
51+
end
52+
53+
def setup_lights
54+
lights
55+
ambient_light(100, 100, 100)
56+
directional_light(100, 100, 100, -1, -1, 1)
57+
light_specular(50, 50, 50)
58+
end
59+
60+
def key_pressed
61+
case key
62+
when 'p', 'P'
63+
fileID = 'Tentacle'
64+
pm = Gfx::POVMesh.new(self)
65+
pm.begin_save(java.io.File.new(fileID + '.inc'))
66+
pm.set_texture(Gfx::Textures::RED) # red with Phong texture
67+
pm.saveAsPOV(mesh, true)
68+
pm.end_save
69+
exit
70+
when 's', 'S'
71+
save_frame('Tentacle.png')
72+
end
73+
end

src/toxi/processing/POVWriter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class POVWriter implements POVInterface {
4242
/**
4343
*
4444
*/
45-
public final String VERSION = "0.58";
45+
public final String VERSION = "0.60";
4646
/**
4747
*
4848
*/
@@ -72,7 +72,8 @@ public class POVWriter implements POVInterface {
7272
// }
7373
public POVWriter(File meshObj) {
7474
this.opt = Textures.RAW;
75-
spath = meshObj.getParent();
75+
String path = meshObj.getAbsolutePath();
76+
spath = path.replaceFirst(meshObj.getName(), "");
7677
try {
7778
this.povWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(meshObj), "UTF8")));
7879
} catch (IOException ex) {
@@ -415,7 +416,7 @@ protected void endForeground() {
415416
povWriter.append("}");
416417
povWriter.append(eol);
417418

418-
String outFile = spath + File.separator + "my_texture.inc";
419+
String outFile = spath + "my_texture.inc";
419420
// if (declaredOpt.size() > 1) { // guard against only RAW
420421
try {
421422
PrintWriter pw;

src/toxi/processing/Tracing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* To change this template, choose Tools | Templates
33
* and open the template in the editor.
44
*/
5-
package povmesh.mesh;
5+
package toxi.processing;
66

77
/**
88
*

toxiclibs.gemspec

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ Gem::Specification.new do |spec|
88
spec.version = Toxiclibs::VERSION
99
spec.has_rdoc = true
1010
spec.extra_rdoc_files = %w{README.md LICENSE.md}
11-
spec.summary = %q{Experimental gem for some toxiclibs}
12-
spec.description = %q{A gem wrapper for some toxiclibs jars}
11+
spec.summary = %q{Updated and extended toxiclibs libraries for JRubyArt}
12+
spec.description =<<-EOS
13+
Toxiclibs java libraries wrapped in a rubygem. Updated to use java lambda
14+
expressions (available since jdk8). Also new since version 0.5.0 are 3D Mesh
15+
to PShape and 3D mesh to Povray mesh2 utilities.
16+
EOS
1317
spec.license = 'GPLv3'
1418
spec.authors = %w{Karsten/ Schmidt Martin/ Prout}
1519
spec.email = 'martin_p@lineone.net'
@@ -28,5 +32,3 @@ Gem::Specification.new do |spec|
2832
spec.requirements << 'maven = 3.3.3'
2933
spec.requirements << 'jruby_art = 1.0+'
3034
end
31-
32-

0 commit comments

Comments
 (0)