toxiclibs 0.5.0-java → 0.5.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +1 -1
- data/examples/povmesh/ftest.rb +36 -23
- data/examples/povmesh/mesh_align.rb +47 -0
- data/examples/spherical_harmonics_mesh.rb +50 -0
- data/lib/toxiclibs/version.rb +1 -1
- data/pom.xml +2 -2
- data/src/toxi/processing/MeshToVBO.java +43 -38
- data/toxiclibs.gemspec +2 -2
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d867709518cd92da4ee751ce618404e36aa58d23
|
4
|
+
data.tar.gz: bc13b0124cbcea23088e24f79246f5b955d4b16c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 006718bd1fd184723895bd17b5e2dbb088875c123b32e1365b763569b489224b69b97cf0644d7e62aa51cf2eb99f6c96c3eccad82dfc3d0fa7bd9bc3ad22f9ba
|
7
|
+
data.tar.gz: 23a90d6fa991b7295b971d5a8b07dec6e78bc6fcc3702b3f630a07b1b2dcafc2afe7c87f017efb7ddf4d95304265199d30b91e6323194e8bf93d05830d3e25de
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
**v0.5.0** New version toxiclibs update to use jdk8 syntax, require jdk8 and probably therefore JRubyArt only new MeshToVBO class.
|
2
1
|
|
2
|
+
**v0.5.1** Mainly corrections.
|
3
|
+
|
4
|
+
**v0.5.0** New version toxiclibs update to use jdk8 syntax, require jdk8 and probably therefore JRubyArt only new MeshToVBO class.
|
3
5
|
|
4
6
|
**v0.4.0** Last version compatible with both ruby-processing and JRubyArt.
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ gem install toxiclibs
|
|
7
7
|
|
8
8
|
### NB: Use version 0.4 for ruby-processing
|
9
9
|
|
10
|
-
Here I have created create a gem to use Karsten Schmidts (aka toxi, @postspectacular) toxiclibs jars in JRubyArt. To compile the gem follow the instructions for [JRubyArt][]. Most parts of toxiclibs API is exposed in the latest version, (but only a few examples are included) in principle it should be possible to make all available!!! For this demonstration I have used up to date source code for version 21, since [toxis final release][] may never materialise (he's probably got more interesting things to do). There are reported to be number of outstanding bugs with toxiclibs, if they affect you report it [here][] (or better fix them yourself and submit a pull request).
|
10
|
+
Here I have created create a gem to use Karsten Schmidts (aka toxi, @postspectacular) toxiclibs jars in JRubyArt. To compile the gem follow the instructions for [JRubyArt][]. Most parts of toxiclibs API is exposed in the latest version, (but only a few examples are included) in principle it should be possible to make all available!!! For this demonstration I have used up to date source code for version 21, since [toxis final release][] may never materialise (he's probably got more interesting things to do). There are reported to be number of outstanding bugs with toxiclibs, if they affect you report it [here][] (or better fix them yourself and submit a pull request). Version 0.5.0 features java code updated to use java lambda (jdk8) and was compiled against processing-3.0.1 core.jar. Added features are export Mesh to PShape and export Mesh to [povray mesh2](http://www.povray.org/documentation/3.7.0/r3_4.html#r3_4_5_2_4).
|
11
11
|
|
12
12
|

|
13
13
|
|
data/examples/povmesh/ftest.rb
CHANGED
@@ -1,46 +1,59 @@
|
|
1
1
|
require 'toxiclibs'
|
2
2
|
|
3
|
-
attr_reader :gfx, :mesh0, :mesh1, :mesh2
|
3
|
+
attr_reader :gfx, :mesh0, :mesh1, :mesh2, :fshape
|
4
4
|
|
5
5
|
def settings
|
6
6
|
size(200, 200, P3D)
|
7
|
-
smooth
|
7
|
+
smooth 8
|
8
8
|
end
|
9
9
|
|
10
10
|
def setup
|
11
11
|
sketch_title('FTest')
|
12
|
-
|
12
|
+
ArcBall.init(self)
|
13
|
+
@gfx = Gfx::MeshToVBO.new(self)
|
13
14
|
# define a rounded cube using the SuperEllipsoid surface function
|
14
15
|
vert = AABB.fromMinMax(TVec3D.new(-1.0, -3.5, -1.0), TVec3D.new(1.0, 3.5, 1.0))
|
15
16
|
box = AABB.fromMinMax(TVec3D.new(1.0, -1.5, -1.0), TVec3D.new(3.0, -3.5, 1.0))
|
16
17
|
box2 = AABB.fromMinMax(TVec3D.new(1.0, 2.0, -1.0), TVec3D.new(3.0, 0.0, 1.0))
|
17
18
|
@mesh0 = box.to_mesh
|
18
19
|
@mesh1 = vert.to_mesh
|
19
|
-
@mesh2 = box2.to_mesh
|
20
|
+
@mesh2 = box2.to_mesh # build a composite mesh
|
20
21
|
mesh0.add_mesh(mesh1)
|
21
22
|
mesh0.add_mesh(mesh2)
|
22
23
|
mesh0.compute_face_normals
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
24
|
+
fill(color('#c0c0c0')) # silver
|
25
|
+
specular(20, 20, 20)
|
26
|
+
ambient(100)
|
27
|
+
no_stroke
|
28
|
+
@fshape = gfx.mesh_to_shape(mesh0, false)
|
36
29
|
end
|
37
30
|
|
38
31
|
def draw
|
39
|
-
background
|
40
|
-
|
41
|
-
translate(width / 2, height / 2)
|
32
|
+
background 80, 80, 160
|
33
|
+
setup_lights
|
42
34
|
scale(10)
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
shape(fshape)
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup_lights
|
39
|
+
lights
|
40
|
+
ambient_light(150, 150, 150)
|
41
|
+
directional_light(100, 100, 100, -1, 0, 0)
|
42
|
+
directional_light(100, 100, 100, 1, 0, -1)
|
46
43
|
end
|
44
|
+
|
45
|
+
|
46
|
+
def key_pressed
|
47
|
+
case key
|
48
|
+
when 'p', 'P'
|
49
|
+
fileID = 'FTest'
|
50
|
+
pm = Gfx::POVMesh.new(self)
|
51
|
+
file = java.io.File.new(sketchPath(fileID + '.inc'))
|
52
|
+
pm.begin_save(file)
|
53
|
+
pm.set_texture(Gfx::Textures::CHROME)
|
54
|
+
pm.saveAsPOV(mesh0.faceOutwards, false)
|
55
|
+
pm.end_save
|
56
|
+
when 's', 'S'
|
57
|
+
save_frame('FTest.png')
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'toxiclibs'
|
2
|
+
|
3
|
+
attr_reader :gfx, :vbo, :meshes
|
4
|
+
SCALE = 200
|
5
|
+
BOX_SIZE = TVec3D.new(5, 5, 50)
|
6
|
+
|
7
|
+
def settings
|
8
|
+
size(600, 600, P3D)
|
9
|
+
end
|
10
|
+
|
11
|
+
def setup
|
12
|
+
sketch_title('Mesh Align')
|
13
|
+
ArcBall.init(self)
|
14
|
+
@vbo = Gfx::MeshToVBO.new(self)
|
15
|
+
no_stroke
|
16
|
+
@meshes = create_shape(GROUP)
|
17
|
+
600.times do |i|
|
18
|
+
# create a new direction vector for each box
|
19
|
+
dir = TVec3D.new(cos(i * TWO_PI / 75), sin(i * TWO_PI / 50), sin(i * TWO_PI / 25)).normalize
|
20
|
+
# create a position on a sphere, using the direction vector
|
21
|
+
pos = dir.scale(SCALE)
|
22
|
+
# create a box mesh at the origin
|
23
|
+
b = AABB.new(TVec3D.new, BOX_SIZE).to_mesh
|
24
|
+
# align the Z axis of the box with the direction vector
|
25
|
+
b.point_towards(dir)
|
26
|
+
# move the box to the correct position
|
27
|
+
b.transform(Toxi::Matrix4x4.new.translate_self(pos.x, pos.y, pos.z))
|
28
|
+
b.compute_face_normals
|
29
|
+
temp = vbo.mesh_to_shape(b, false)
|
30
|
+
temp.disable_style
|
31
|
+
temp.set_fill(color(rand(255), rand(255), rand(255)))
|
32
|
+
meshes.add_child(temp)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def draw
|
37
|
+
background 50, 50, 200
|
38
|
+
define_lights
|
39
|
+
shape(meshes)
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_lights
|
43
|
+
lights
|
44
|
+
shininess(16)
|
45
|
+
directionalLight(255, 255, 255, 0, -1, 1)
|
46
|
+
specular(255)
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'toxiclibs'
|
2
|
+
|
3
|
+
#######
|
4
|
+
# After Paul Bourke see http://paulbourke.net/geometry/sphericalh/
|
5
|
+
# radius =
|
6
|
+
# sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
|
7
|
+
# where phi = (0..PI) and theta = (0..TWO_PI)
|
8
|
+
# As implemented by Karsten Schmidt aka toxi/postspectacular
|
9
|
+
#######
|
10
|
+
|
11
|
+
attr_reader :gfx, :mesh, :spherical, :param
|
12
|
+
|
13
|
+
def setup
|
14
|
+
sketch_title 'Spherical Harmonics Mesh Builder'
|
15
|
+
ArcBall.init(self)
|
16
|
+
@param = [8, 4, 1, 5, 1, 4, 0, 0] # default function parameters (m0..m7)
|
17
|
+
@mesh = spherical_mesh(param)
|
18
|
+
@gfx = Gfx::MeshToVBO.new(self) # Mesh to vertex buffer object converter
|
19
|
+
no_stroke
|
20
|
+
@spherical = gfx.mesh_to_shape(mesh, true) # white
|
21
|
+
end
|
22
|
+
|
23
|
+
def draw
|
24
|
+
background(0)
|
25
|
+
lights
|
26
|
+
shininess(16)
|
27
|
+
directional_light(255, 255, 255, 0, -1, 1)
|
28
|
+
specular(255)
|
29
|
+
shape(spherical)
|
30
|
+
end
|
31
|
+
|
32
|
+
def key_pressed
|
33
|
+
return unless (key == 'r')
|
34
|
+
@mesh = spherical_mesh(random_parameters)
|
35
|
+
no_stroke
|
36
|
+
@spherical = gfx.mesh_to_colored_shape(mesh, true) # harmonic colors
|
37
|
+
end
|
38
|
+
|
39
|
+
def random_parameters
|
40
|
+
(0..8).map { rand(0..8) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def spherical_mesh(param)
|
44
|
+
b = SurfaceMeshBuilder.new(SphericalHarmonics.new(param.to_java(:float)))
|
45
|
+
b.create_mesh(nil, 80, 60)
|
46
|
+
end
|
47
|
+
|
48
|
+
def settings
|
49
|
+
size(1024, 576, P3D)
|
50
|
+
end
|
data/lib/toxiclibs/version.rb
CHANGED
data/pom.xml
CHANGED
@@ -1,31 +1,14 @@
|
|
1
|
-
/*
|
2
|
-
* This library adds translate from toxiclibs Mesh to processing PShape (vbo)
|
3
|
-
* Copyright (c) 2015 Martin Prout
|
4
|
-
*
|
5
|
-
* This library is free software; you can redistribute it and/or modify it under
|
6
|
-
* the terms of the GNU Lesser General Public License as published by the Free
|
7
|
-
* Software Foundation; either version 2.1 of the License, or (at your option)
|
8
|
-
* any later version.
|
9
|
-
*
|
10
|
-
* http://creativecommons.org/licenses/LGPL/2.1/
|
11
|
-
*
|
12
|
-
* This library is distributed in the hope that it will be useful, but WITHOUT
|
13
|
-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
14
|
-
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
15
|
-
* details.
|
16
|
-
*
|
17
|
-
* You should have received a copy of the GNU Lesser General Public License
|
18
|
-
* along with this library; if not, write to the Free Software Foundation, Inc.,
|
19
|
-
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
20
|
-
*/
|
21
1
|
package toxi.processing;
|
22
2
|
|
23
3
|
import java.util.Collection;
|
24
4
|
import processing.core.PApplet;
|
25
5
|
import processing.core.PConstants;
|
26
6
|
import processing.core.PShape;
|
7
|
+
import toxi.geom.Matrix4x4;
|
8
|
+
import toxi.geom.Vec3D;
|
27
9
|
import toxi.geom.mesh.Mesh3D;
|
28
10
|
import toxi.geom.mesh.Face;
|
11
|
+
import toxi.geom.mesh.TriangleMesh;
|
29
12
|
|
30
13
|
/**
|
31
14
|
*
|
@@ -34,6 +17,8 @@ import toxi.geom.mesh.Face;
|
|
34
17
|
public class MeshToVBO {
|
35
18
|
|
36
19
|
private final PApplet app;
|
20
|
+
private final Matrix4x4 normalMap =
|
21
|
+
new Matrix4x4().translateSelf(128, 128, 128).scaleSelf(127);
|
37
22
|
|
38
23
|
/**
|
39
24
|
*
|
@@ -49,39 +34,24 @@ public class MeshToVBO {
|
|
49
34
|
* @param smooth boolean
|
50
35
|
* @return
|
51
36
|
*/
|
52
|
-
public PShape meshToShape(
|
37
|
+
public PShape meshToShape(TriangleMesh mesh, boolean smooth) {
|
53
38
|
PShape retained = app.createShape();
|
54
39
|
retained.beginShape(PConstants.TRIANGLE);
|
55
40
|
if (smooth) {
|
56
|
-
mesh.
|
57
|
-
Collection<Face> faces = mesh.getFaces();
|
58
|
-
faces.stream().map((f) -> {
|
41
|
+
mesh.faces.stream().map((f) -> {
|
59
42
|
retained.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
|
60
|
-
return f;
|
61
|
-
}).map((f) -> {
|
62
43
|
retained.vertex(f.a.x, f.a.y, f.a.z);
|
63
|
-
return f;
|
64
|
-
}).map((f) -> {
|
65
44
|
retained.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
|
66
|
-
return f;
|
67
|
-
}).map((f) -> {
|
68
45
|
retained.vertex(f.b.x, f.b.y, f.b.z);
|
69
|
-
return f;
|
70
|
-
}).map((f) -> {
|
71
46
|
retained.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
|
72
47
|
return f;
|
73
48
|
}).forEach((f) -> {
|
74
49
|
retained.vertex(f.c.x, f.c.y, f.c.z);
|
75
50
|
});
|
76
51
|
} else {
|
77
|
-
|
78
|
-
faces.stream().map((f) -> {
|
52
|
+
mesh.faces.stream().map((f) -> {
|
79
53
|
retained.normal(f.normal.x, f.normal.y, f.normal.z);
|
80
|
-
return f;
|
81
|
-
}).map((f) -> {
|
82
54
|
retained.vertex(f.a.x, f.a.y, f.a.z);
|
83
|
-
return f;
|
84
|
-
}).map((f) -> {
|
85
55
|
retained.vertex(f.b.x, f.b.y, f.b.z);
|
86
56
|
return f;
|
87
57
|
}).forEach((f) -> {
|
@@ -91,4 +61,39 @@ public class MeshToVBO {
|
|
91
61
|
retained.endShape();
|
92
62
|
return retained;
|
93
63
|
}
|
64
|
+
|
65
|
+
public PShape meshToColoredShape(TriangleMesh mesh,
|
66
|
+
boolean vertexNormals) {
|
67
|
+
PShape gfx = app.createShape();
|
68
|
+
gfx.beginShape(PConstants.TRIANGLES);
|
69
|
+
if (vertexNormals) {
|
70
|
+
mesh.faces.stream().map((f) -> {
|
71
|
+
Vec3D n = normalMap.applyTo(f.a.normal);
|
72
|
+
gfx.fill(n.x, n.y, n.z);
|
73
|
+
gfx.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
|
74
|
+
gfx.vertex(f.a.x, f.a.y, f.a.z);
|
75
|
+
n = normalMap.applyTo(f.b.normal);
|
76
|
+
gfx.fill(n.x, n.y, n.z);
|
77
|
+
gfx.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
|
78
|
+
gfx.vertex(f.b.x, f.b.y, f.b.z);
|
79
|
+
n = normalMap.applyTo(f.c.normal);
|
80
|
+
gfx.fill(n.x, n.y, n.z);
|
81
|
+
gfx.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
|
82
|
+
return f;
|
83
|
+
}).forEach((f) -> {
|
84
|
+
gfx.vertex(f.c.x, f.c.y, f.c.z);
|
85
|
+
});
|
86
|
+
} else {
|
87
|
+
mesh.faces.stream().map((f) -> {
|
88
|
+
gfx.normal(f.normal.x, f.normal.y, f.normal.z);
|
89
|
+
gfx.vertex(f.a.x, f.a.y, f.a.z);
|
90
|
+
gfx.vertex(f.b.x, f.b.y, f.b.z);
|
91
|
+
return f;
|
92
|
+
}).forEach((f) -> {
|
93
|
+
gfx.vertex(f.c.x, f.c.y, f.c.z);
|
94
|
+
});
|
95
|
+
}
|
96
|
+
gfx.endShape();
|
97
|
+
return gfx;
|
98
|
+
}
|
94
99
|
}
|
data/toxiclibs.gemspec
CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
expressions (available since jdk8). Also new since version 0.5.0 are 3D Mesh
|
15
15
|
to PShape and 3D mesh to Povray mesh2 utilities.
|
16
16
|
EOS
|
17
|
-
spec.
|
18
|
-
spec.authors = %w{Karsten
|
17
|
+
spec.licenses = %w{MIT LGPL-3.0}
|
18
|
+
spec.authors = %w{Karsten\ Schmidt Martin\ Prout}
|
19
19
|
spec.email = 'martin_p@lineone.net'
|
20
20
|
spec.homepage = 'https://github.com/ruby-processing/toxiclibs'
|
21
21
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toxiclibs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
|
-
- Karsten
|
8
|
-
-
|
9
|
-
- Martin/
|
10
|
-
- Prout
|
7
|
+
- Karsten Schmidt
|
8
|
+
- Martin Prout
|
11
9
|
autorequire:
|
12
10
|
bindir: bin
|
13
11
|
cert_chain: []
|
14
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-16 00:00:00.000000000 Z
|
15
13
|
dependencies:
|
16
14
|
- !ruby/object:Gem::Dependency
|
17
15
|
name: jruby_art
|
@@ -84,6 +82,7 @@ files:
|
|
84
82
|
- examples/inflate_mesh.rb
|
85
83
|
- examples/model_align.rb
|
86
84
|
- examples/povmesh/ftest.rb
|
85
|
+
- examples/povmesh/mesh_align.rb
|
87
86
|
- examples/povmesh/tentacle.rb
|
88
87
|
- examples/simple_cluster/cluster.rb
|
89
88
|
- examples/simple_cluster/node.rb
|
@@ -92,6 +91,7 @@ files:
|
|
92
91
|
- examples/soft_body/connection.rb
|
93
92
|
- examples/soft_body/particle.rb
|
94
93
|
- examples/soft_body/soft_body_square_adapted.rb
|
94
|
+
- examples/spherical_harmonics_mesh.rb
|
95
95
|
- lib/args4j-2.0.31.jar
|
96
96
|
- lib/toxiclibs.jar
|
97
97
|
- lib/toxiclibs.rb
|
@@ -450,7 +450,8 @@ files:
|
|
450
450
|
- toxiclibs.gemspec
|
451
451
|
homepage: https://github.com/ruby-processing/toxiclibs
|
452
452
|
licenses:
|
453
|
-
-
|
453
|
+
- MIT
|
454
|
+
- LGPL-3.0
|
454
455
|
metadata: {}
|
455
456
|
post_install_message:
|
456
457
|
rdoc_options: []
|