Skip to content

Commit ab0eaa8

Browse files
committed
wblut example
1 parent d00d559 commit ab0eaa8

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
load_library :hemesh
2+
3+
java_import 'wblut.geom.WB_Point'
4+
java_import 'wblut.geom.WB_RandomBox'
5+
java_import 'wblut.geom.WB_RandomPoint'
6+
java_import 'wblut.geom.WB_Triangulate'
7+
java_import 'wblut.geom.WB_Triangulation3D'
8+
java_import 'wblut.processing.WB_Render3D'
9+
10+
attr_reader :source, :render, :numPoints, :tetrahedra, :points
11+
12+
def setup
13+
sketch_title 'Triangulation 3D'
14+
ArcBall.init(self)
15+
@source = WB_RandomBox.new.setSize(500, 500, 500)
16+
@render = WB_Render3D.new(self)
17+
numPoints = 100
18+
@points = (0..numPoints).map { source.nextPoint }
19+
triangulation = WB_Triangulate.triangulate3D(points)
20+
@tetrahedra = triangulation.getTetrahedra() # 1D array of indices of tetrahedra, 4 indices per tetrahedron
21+
puts("First tetrahedron: [ #{tetrahedra[0]}, #{tetrahedra[1]}, #{tetrahedra[2]}, #{tetrahedra[3]} ]")
22+
end
23+
24+
def draw
25+
background(55)
26+
directional_light(255, 255, 255, 1, 1, -1)
27+
directional_light(127, 127, 127, -1, -1, 1)
28+
center = (0...tetrahedra.length).step(4) do |i|
29+
push_matrix
30+
center = WB_Point.new(
31+
points[tetrahedra[i]]).addSelf(points[tetrahedra[i + 1]]).addSelf(points[tetrahedra[i + 2]]).addSelf(points[tetrahedra[i + 3]]).mulSelf(0.25 + 0.25 * sin(0.005 * frame_count)
32+
)
33+
render.translate(center)
34+
render.drawTetrahedron(points[tetrahedra[i]], points[tetrahedra[i + 1]], points[tetrahedra[i + 2]], points[tetrahedra[i + 3]])
35+
pop_matrix
36+
end
37+
end
38+
39+
def settings
40+
size(1000, 1000, P3D)
41+
smooth(8)
42+
end

0 commit comments

Comments
 (0)