disp3D 0.2.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/Gemfile +1 -1
  2. data/README.md +56 -0
  3. data/VERSION +1 -1
  4. data/disp3D.gemspec +24 -20
  5. data/example/stl_viewer/document_ctrl.rb +2 -2
  6. data/example/stl_viewer/qt_widget_controller.rb +3 -7
  7. data/example/tutorial/03_CameraScene.rb +5 -5
  8. data/example/tutorial/04_Qt.rb +4 -4
  9. data/example/tutorial/05_Pick.rb +13 -13
  10. data/example/tutorial/06_FileParser.rb +3 -3
  11. data/example/tutorial/07_SceneGraph.rb +16 -4
  12. data/example/tutorial/08_SceneGraph2.rb +16 -15
  13. data/example/tutorial/09_Texture.rb +28 -0
  14. data/example/tutorial/10_Animation.rb +27 -0
  15. data/example/tutorial/10_AnimationQt.rb +53 -0
  16. data/example/tutorial/11_MultiView.rb +41 -0
  17. data/example/tutorial/12_Light.rb +65 -0
  18. data/example/tutorial/13_RectPick.rb +38 -0
  19. data/example/tutorial/14_LineRubberband.rb +43 -0
  20. data/example/{test → tutorial}/data/test.png +0 -0
  21. data/example/{test → tutorial}/data/test2.jpg +0 -0
  22. data/lib/camera.rb +8 -0
  23. data/lib/compass.rb +21 -14
  24. data/lib/disp3D.rb +3 -0
  25. data/lib/gl_view.rb +70 -40
  26. data/lib/glut_window.rb +24 -18
  27. data/lib/light.rb +35 -21
  28. data/lib/manipulator.rb +0 -7
  29. data/lib/node/node.rb +100 -105
  30. data/lib/node/node_arrows.rb +1 -1
  31. data/lib/node/node_collection.rb +63 -17
  32. data/lib/node/node_cone.rb +49 -0
  33. data/lib/node/node_coord.rb +26 -11
  34. data/lib/node/node_leaf.rb +17 -11
  35. data/lib/node/node_lines.rb +1 -1
  36. data/lib/node/node_points.rb +2 -1
  37. data/lib/node/node_polylines.rb +1 -1
  38. data/lib/node/node_rectangle.rb +9 -4
  39. data/lib/node/node_sphere.rb +28 -0
  40. data/lib/node/node_tea_pod.rb +4 -4
  41. data/lib/node/node_text.rb +2 -2
  42. data/lib/node/node_tris.rb +1 -1
  43. data/lib/node/node_workplane.rb +33 -1
  44. data/lib/picker.rb +157 -3
  45. data/lib/qt_widget_gl.rb +24 -11
  46. data/lib/scene_graph.rb +3 -3
  47. data/test/node/test_node.rb +230 -0
  48. data/test/node/test_node_collection.rb +99 -79
  49. data/test/test_picker.rb +6 -6
  50. metadata +28 -24
  51. data/README.rdoc +0 -63
  52. data/example/test/capture_test.rb +0 -16
  53. data/example/test/dsl_test.rb +0 -46
  54. data/example/test/texture_test.rb +0 -39
  55. data/test/data/binary_test.stl +0 -0
  56. data/test/data/bunny-flatfoot.stl +0 -0
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
  group :development do
3
3
  gem "bundler", "~> 1.0.0"
4
4
  gem "jeweler", "~> 1.6.4"
5
- gem "gmath3D", "~> 0.2.5"
5
+ gem "gmath3D", "~> 1.0.0"
6
6
  gem "ruby-opengl", "0.60.1"
7
7
  gem "rmagick"
8
8
  end
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ disp3D
2
+ =======
3
+
4
+ disp3D is a library for 3D application without call opengl function. Writing OpenGL function is time-cosuming and boring. You can display 3D objects very easily as you want with this library.
5
+
6
+ INSTALLING
7
+ ============
8
+
9
+ This library depends on these Gems.
10
+
11
+ - gmath3D
12
+ - ruby-opengl
13
+ - rmagick
14
+ - qtbindings(optional)
15
+
16
+ To install it, just type...
17
+
18
+ $ gem install disp3D
19
+
20
+ RUNNING
21
+ ============
22
+
23
+ Require 'disp3d', then you can use most of the classes in the lib (except for qt-components).
24
+
25
+ This is the first code you type.
26
+
27
+ require 'disp3D'
28
+
29
+ # create view with GLUTWindow, then set width, height and window title
30
+ main_view = Disp3D::GLUTWindow.new(400,400, "01_HelloWorld")
31
+
32
+ # open world scene graph view has
33
+ main_view.world_scene_graph.open do
34
+ # put TeaPod which color is Red and size is 10
35
+ add_new :type => :TeaPod,
36
+ :material_color => [1,0,0,1],
37
+ :size => 10.0
38
+ end
39
+
40
+ # set parameter for camera
41
+ main_view.camera.projection = Disp3D::Camera::ORTHOGONAL
42
+
43
+ # finally show window!
44
+ main_view.start
45
+
46
+ You can see a teapod is shown in the window. you can rotate it with mouse L button and drag.
47
+ ![image](https://github.com/toshi0328/wiki/blob/master/images/disp3D/HelloWorld01.png?raw=true)
48
+
49
+ see example/tutorial/*.rb for more details.
50
+
51
+ Copyright
52
+ ============
53
+
54
+ Copyright (c) 2011 Toshiyasu Shimizu. See LICENSE.txt for
55
+ further details.
56
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 1.0.1
data/disp3D.gemspec CHANGED
@@ -4,23 +4,23 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{disp3D}
8
- s.version = "0.2.1"
7
+ s.name = "disp3D"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Toshiyasu Shimizu"]
12
- s.date = %q{2011-12-01}
13
- s.description = %q{disp3D provide 3D GUI framework}
14
- s.email = %q{toshi0328@gmail.com}
12
+ s.date = "2011-12-12"
13
+ s.description = "disp3D provide 3D GUI framework"
14
+ s.email = "toshi0328@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  "Gemfile",
22
22
  "LICENSE.txt",
23
- "README.rdoc",
23
+ "README.md",
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "disp3D.gemspec",
@@ -29,11 +29,6 @@ Gem::Specification.new do |s|
29
29
  "example/stl_viewer/main.rb",
30
30
  "example/stl_viewer/qt_widget_controller.rb",
31
31
  "example/stl_viewer/stl_viewer.rb",
32
- "example/test/capture_test.rb",
33
- "example/test/data/test.png",
34
- "example/test/data/test2.jpg",
35
- "example/test/dsl_test.rb",
36
- "example/test/texture_test.rb",
37
32
  "example/tutorial/01_helloworld.rb",
38
33
  "example/tutorial/02_elements.rb",
39
34
  "example/tutorial/03_CameraScene.rb",
@@ -42,7 +37,16 @@ Gem::Specification.new do |s|
42
37
  "example/tutorial/06_FileParser.rb",
43
38
  "example/tutorial/07_SceneGraph.rb",
44
39
  "example/tutorial/08_SceneGraph2.rb",
40
+ "example/tutorial/09_Texture.rb",
41
+ "example/tutorial/10_Animation.rb",
42
+ "example/tutorial/10_AnimationQt.rb",
43
+ "example/tutorial/11_MultiView.rb",
44
+ "example/tutorial/12_Light.rb",
45
+ "example/tutorial/13_RectPick.rb",
46
+ "example/tutorial/14_LineRubberband.rb",
45
47
  "example/tutorial/data/bunny.stl",
48
+ "example/tutorial/data/test.png",
49
+ "example/tutorial/data/test2.jpg",
46
50
  "lib/camera.rb",
47
51
  "lib/compass.rb",
48
52
  "lib/disp3D.rb",
@@ -55,12 +59,14 @@ Gem::Specification.new do |s|
55
59
  "lib/node/node.rb",
56
60
  "lib/node/node_arrows.rb",
57
61
  "lib/node/node_collection.rb",
62
+ "lib/node/node_cone.rb",
58
63
  "lib/node/node_coord.rb",
59
64
  "lib/node/node_leaf.rb",
60
65
  "lib/node/node_lines.rb",
61
66
  "lib/node/node_points.rb",
62
67
  "lib/node/node_polylines.rb",
63
68
  "lib/node/node_rectangle.rb",
69
+ "lib/node/node_sphere.rb",
64
70
  "lib/node/node_tea_pod.rb",
65
71
  "lib/node/node_text.rb",
66
72
  "lib/node/node_tris.rb",
@@ -71,8 +77,6 @@ Gem::Specification.new do |s|
71
77
  "lib/qt_widget_gl.rb",
72
78
  "lib/scene_graph.rb",
73
79
  "lib/stl.rb",
74
- "test/data/binary_test.stl",
75
- "test/data/bunny-flatfoot.stl",
76
80
  "test/data/cube-ascii.stl",
77
81
  "test/data/cube-binary.stl",
78
82
  "test/helper.rb",
@@ -96,11 +100,11 @@ Gem::Specification.new do |s|
96
100
  "test/test_scene_graph.rb",
97
101
  "test/test_stl.rb"
98
102
  ]
99
- s.homepage = %q{http://github.com/toshi0328/disp3D}
103
+ s.homepage = "http://github.com/toshi0328/disp3D"
100
104
  s.licenses = ["MIT"]
101
105
  s.require_paths = ["lib"]
102
- s.rubygems_version = %q{1.7.2}
103
- s.summary = %q{disp3D provide 3D GUI framework.}
106
+ s.rubygems_version = "1.8.12"
107
+ s.summary = "disp3D provide 3D GUI framework."
104
108
 
105
109
  if s.respond_to? :specification_version then
106
110
  s.specification_version = 3
@@ -108,20 +112,20 @@ Gem::Specification.new do |s|
108
112
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
109
113
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
110
114
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
111
- s.add_development_dependency(%q<gmath3D>, ["~> 0.2.5"])
115
+ s.add_development_dependency(%q<gmath3D>, ["~> 1.0.0"])
112
116
  s.add_development_dependency(%q<ruby-opengl>, ["= 0.60.1"])
113
117
  s.add_development_dependency(%q<rmagick>, [">= 0"])
114
118
  else
115
119
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
116
120
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
117
- s.add_dependency(%q<gmath3D>, ["~> 0.2.5"])
121
+ s.add_dependency(%q<gmath3D>, ["~> 1.0.0"])
118
122
  s.add_dependency(%q<ruby-opengl>, ["= 0.60.1"])
119
123
  s.add_dependency(%q<rmagick>, [">= 0"])
120
124
  end
121
125
  else
122
126
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
123
127
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
124
- s.add_dependency(%q<gmath3D>, ["~> 0.2.5"])
128
+ s.add_dependency(%q<gmath3D>, ["~> 1.0.0"])
125
129
  s.add_dependency(%q<ruby-opengl>, ["= 0.60.1"])
126
130
  s.add_dependency(%q<rmagick>, [">= 0"])
127
131
  end
@@ -27,8 +27,8 @@ class DocumentCtrl
27
27
 
28
28
  # 更新といっても、ノードの入れ替え、色の変更、フィットさせるだけなど、様々と思うが・・・
29
29
  def update
30
- @main_window.gl_widget.gl_view.world_scene_graph.add(@document.tri_node)
31
- @main_window.gl_widget.gl_view.fit
30
+ @main_window.gl_widget.world_scene_graph.add(@document.tri_node)
31
+ @main_window.gl_widget.fit
32
32
  @main_window.gl_widget.updateGL
33
33
 
34
34
  @main_window.ctrl_widget.vert_cnt = @document.tri_mesh.vertices.size
@@ -73,21 +73,17 @@ class QTWidgetController < Qt::Widget
73
73
  end
74
74
 
75
75
  def fit
76
- @gl_widget.gl_view.fit
76
+ @gl_widget.fit
77
77
  @gl_widget.updateGL
78
78
  end
79
79
 
80
80
  def centering
81
- @gl_widget.gl_view.centering
81
+ @gl_widgetcentering
82
82
  @gl_widget.updateGL
83
83
  end
84
84
 
85
85
  def change_projection
86
- if(@gl_widget.gl_view.camera.is_orth)
87
- @gl_widget.gl_view.camera.is_orth = false
88
- else
89
- @gl_widget.gl_view.camera.is_orth = true
90
- end
86
+ @gl_widget.camera.switch_projection
91
87
  @gl_widget.updateGL
92
88
  end
93
89
 
@@ -2,10 +2,9 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))
2
2
 
3
3
  require 'disp3D'
4
4
 
5
- main_view = Disp3D::GLUTWindow.new(600,400,"03_CameraScene")
5
+ main_view = Disp3D::GLUTWindow.new(350,300,"03_CameraScene")
6
6
 
7
7
  box1 = TriMesh.from_box(Box.new(Vector3.new(-1,-1,-1),Vector3.new(1,1,1)))
8
- box2 = TriMesh.from_box(Box.new(Vector3.new(-200,-100,0),Vector3.new(-150,-50,0.5)))
9
8
 
10
9
  main_view.world_scene_graph.open do
11
10
  add_new :type => :Tris,
@@ -15,9 +14,10 @@ main_view.world_scene_graph.open do
15
14
  end
16
15
 
17
16
  main_view.camera_scene_graph.open do
18
- add_new :type => :Tris,
19
- :geom => box2,
20
- :colors => [0,1,0,1]
17
+ add_new :type => :Text,
18
+ :geom => Vector3.new(-125,100),
19
+ :colors => [0,1,0,1],
20
+ :text => "This text is in the camera scene"
21
21
  end
22
22
 
23
23
  main_view.start
@@ -6,7 +6,7 @@ require 'qt_widget_gl'
6
6
  class TestQTGLWindow < Qt::Widget
7
7
  def initialize(parent = nil)
8
8
  super
9
- @gl_widget = QtWidgetGL.new(self, 600, 400)
9
+ @gl_widget = QtWidgetGL.new(self, 300, 300)
10
10
  self.layout = Qt::HBoxLayout.new do |m|
11
11
  m.addWidget(@gl_widget)
12
12
  end
@@ -16,13 +16,13 @@ class TestQTGLWindow < Qt::Widget
16
16
 
17
17
  def showEvent(eventArg)
18
18
  if( @is_first_show )
19
- @gl_widget.gl_view.world_scene_graph.open do
19
+ @gl_widget.world_scene_graph.open do
20
20
  add_new :type => :TeaPod,
21
21
  :material_color => [1,1,0,1],
22
22
  :size => 10.0
23
23
  end
24
- @gl_widget.gl_view.camera.projection = Disp3D::Camera::ORTHOGONAL
25
- @gl_widget.gl_view.fit
24
+ @gl_widget.camera.projection = Disp3D::Camera::ORTHOGONAL
25
+ @gl_widget.fit
26
26
  @is_first_show = false
27
27
  end
28
28
  end
@@ -5,16 +5,14 @@ require 'disp3D'
5
5
  main_view = Disp3D::GLUTWindow.new(600,400)
6
6
 
7
7
  rect_geom = Rectangle.new(Vector3.new(-1,-1,2), Vector3.new(2,0,0), Vector3.new(0,2,0))
8
- rect_tri_mesh_geom = TriMesh.from_rectangle(rect_geom)
9
-
10
8
  box_geom = Box.new(Vector3.new(),Vector3.new(1,1,1))
11
9
  box_tri_mesh_geom = TriMesh.from_box(box_geom)
12
10
 
13
11
  main_view.world_scene_graph.open do
14
12
  # plane
15
- add_new :type => :Tris,
16
- :geom => rect_tri_mesh_geom,
17
- :name => :plane0
13
+ add_new :type => :Rectangle,
14
+ :geom => rect_geom,
15
+ :name => :rectangle0
18
16
 
19
17
  # text
20
18
  rect_geom.vertices.each do | vertex |
@@ -30,34 +28,31 @@ main_view.world_scene_graph.open do
30
28
  :normal_mode => Disp3D::NodeTris::NORMAL_EACH_FACE,
31
29
  :material_color => [1,0,0,1],
32
30
  :post_translate => Vector3.new(-2,-2,0),
33
- :name => :cube1
31
+ :name => :cube0
34
32
 
35
33
  add_new :type => :Tris,
36
34
  :geom => box_tri_mesh_geom,
37
35
  :normal_mode => Disp3D::NodeTris::NORMAL_EACH_FACE,
38
36
  :material_color => [0,1,0,1],
39
37
  :post_translate => Vector3.new(1,-2,0),
40
- :name => :cube2
38
+ :name => :cube1
41
39
 
42
40
  add_new :type => :Tris,
43
41
  :geom => box_tri_mesh_geom,
44
42
  :normal_mode => Disp3D::NodeTris::NORMAL_EACH_FACE,
45
43
  :material_color => [0,0,1,1],
46
44
  :post_translate => Vector3.new(1,1,0),
47
- :name => :cube3
45
+ :name => :cube2
48
46
 
49
47
  add_new :type => :Tris,
50
48
  :geom => box_tri_mesh_geom,
51
49
  :normal_mode => Disp3D::NodeTris::NORMAL_EACH_FACE,
52
50
  :material_color => [0,0,0,1],
53
51
  :post_translate => Vector3.new(-2,1,0),
54
- :name => :cube4
52
+ :name => :cube3
55
53
  end
56
54
 
57
- main_view.mouse_press do |view, button, x, y|
58
- next if( button != GLUT::LEFT_BUTTON )
59
- # result is Array of PickedResult
60
- results = view.picker.pick(x,y)
55
+ main_view.picker.post_picked do |results|
61
56
  if(results != nil)
62
57
  puts "hit #{results.size} elements"
63
58
  results.each_with_index do | result, idx |
@@ -72,4 +67,9 @@ main_view.mouse_press do |view, button, x, y|
72
67
  end
73
68
  end
74
69
 
70
+ main_view.mouse_press do |view, button, x, y|
71
+ next if( button != GLUT::LEFT_BUTTON )
72
+ view.picker.start_point_pick
73
+ end
74
+
75
75
  main_view.start
@@ -2,13 +2,13 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))
2
2
 
3
3
  require 'disp3D'
4
4
 
5
- file_path = File.dirname(__FILE__) + "./data/bunny.stl";
5
+ file_path = File.dirname(__FILE__) + "/data/bunny.stl";
6
6
  if( !File.exists?(file_path) )
7
7
  puts file_path + " is not exist!"
8
8
  exit
9
9
  end
10
10
 
11
- main_view = Disp3D::GLUTWindow.new(600,400)
11
+ main_view = Disp3D::GLUTWindow.new(600,400,"06_FileParser")
12
12
 
13
13
  stl = Disp3D::STL.new()
14
14
  stl.parse(file_path, Disp3D::STL::ASCII)
@@ -17,5 +17,5 @@ main_view.world_scene_graph.open do
17
17
  add_new :type => :Tris,
18
18
  :geom => stl
19
19
  end
20
-
20
+ main_view.camera.projection = Disp3D::Camera::ORTHOGONAL
21
21
  main_view.start
@@ -32,11 +32,9 @@ main_view.world_scene_graph.open do
32
32
  end
33
33
  end
34
34
 
35
- main_view.mouse_press do |view, button, x, y|
36
- next if( button != GLUT::LEFT_BUTTON )
37
- # result is Array of PickedResult
38
- results = view.picker.pick(x,y)
35
+ main_view.picker.post_picked do |results|
39
36
  if(results != nil)
37
+ picked_node_name = nil
40
38
  puts "hit #{results.size} elements"
41
39
  results.each_with_index do | result, idx |
42
40
  puts "====element #{idx}===="
@@ -44,8 +42,22 @@ main_view.mouse_press do |view, button, x, y|
44
42
  puts "instance id : #{result.node_path_info[0].node.instance_id}"
45
43
  puts "path id : #{result.node_path_info[0].path_id}"
46
44
  puts "=================="
45
+ picked_node_name = result.node_path_info[0].node.name
46
+ end
47
+ if(!picked_node_name.nil?)
48
+ main_view.world_scene_graph.open do
49
+ update :name => picked_node_name,
50
+ :material_color => [0,1,0,1]
51
+ end
52
+ main_view.update
47
53
  end
48
54
  end
49
55
  end
50
56
 
57
+
58
+ main_view.mouse_press do |view, button, x, y|
59
+ next if( button != GLUT::LEFT_BUTTON )
60
+ view.picker.start_point_pick
61
+ end
62
+
51
63
  main_view.start
@@ -33,26 +33,27 @@ main_view.world_scene_graph.open do
33
33
  end
34
34
 
35
35
  main_view.mouse_press do |view, button, x, y|
36
- results = view.picker.pick(x,y)
37
- if(results != nil)
38
- # remove node path when left button pressed
39
- if( button == GLUT::LEFT_BUTTON )
40
- path_id_ary = results.collect {| result | result.node_path_info[0].path_id }
41
- main_view.world_scene_graph.open do
42
- path_id_ary.each do |path_id|
43
- remove path_id
36
+ # remove node path when left button pressed
37
+ if( button == GLUT::LEFT_BUTTON )
38
+ view.picker.start_point_pick do |results|
39
+ if(results != nil)
40
+ path_id_ary = results.collect {| result | result.node_path_info[0].path_id }
41
+ main_view.world_scene_graph.open do
42
+ path_id_ary.each do |path_id|
43
+ remove path_id
44
+ end
44
45
  end
46
+ main_view.update
45
47
  end
46
- main_view.update
47
48
  end
49
+ end
48
50
 
49
- # delete node when right button pressed
50
- if( button == GLUT::RIGHT_BUTTON )
51
- main_view.world_scene_graph.open do
52
- delete :cube0
53
- end
54
- main_view.update
51
+ # delete node when right button pressed
52
+ if( button == GLUT::RIGHT_BUTTON )
53
+ main_view.world_scene_graph.open do
54
+ delete :cube0
55
55
  end
56
+ main_view.update
56
57
  end
57
58
  end
58
59