mittsu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +39 -0
  8. data/Rakefile +7 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/examples/01_-_Default1noCulling.png +0 -0
  12. data/examples/01_scene_example.rb +14 -0
  13. data/examples/02_box_mesh_example.rb +30 -0
  14. data/examples/02_sphere_mesh_example.rb +30 -0
  15. data/examples/03_complex_object_example.rb +52 -0
  16. data/examples/04_ambient_light_example.rb +33 -0
  17. data/examples/04_dir_light_example.rb +36 -0
  18. data/examples/04_hemi_light_example.rb +30 -0
  19. data/examples/04_point_light_example.rb +50 -0
  20. data/examples/04_spot_light_example.rb +44 -0
  21. data/examples/05_earth_example.rb +42 -0
  22. data/examples/05_earth_moon_example.rb +46 -0
  23. data/examples/05_texture_example.rb +32 -0
  24. data/examples/06_cube_texture_example.rb +36 -0
  25. data/examples/06_skybox_example.rb +60 -0
  26. data/examples/07_earth_normal_example.rb +36 -0
  27. data/examples/08_shadow_example.rb +87 -0
  28. data/examples/09_line_example.rb +52 -0
  29. data/examples/10_obj_loader_example.rb +68 -0
  30. data/examples/11_character_input_example.rb +18 -0
  31. data/examples/11_continuous_keyboard_input_example.rb +35 -0
  32. data/examples/11_keyboard_input_example.rb +43 -0
  33. data/examples/12_mouse_click_example.rb +38 -0
  34. data/examples/12_mouse_motion_example.rb +35 -0
  35. data/examples/12_mouse_scroll_example.rb +36 -0
  36. data/examples/12_orbit_zoom_example.rb +68 -0
  37. data/examples/13_joystick_example.rb +80 -0
  38. data/examples/cubemap/tron_bk.png +0 -0
  39. data/examples/cubemap/tron_dn.png +0 -0
  40. data/examples/cubemap/tron_ft.png +0 -0
  41. data/examples/cubemap/tron_lf.png +0 -0
  42. data/examples/cubemap/tron_rt.png +0 -0
  43. data/examples/cubemap/tron_up.png +0 -0
  44. data/examples/earth.png +0 -0
  45. data/examples/earth_normal.png +0 -0
  46. data/examples/example_helper.rb +2 -0
  47. data/examples/male-02-1noCulling.png +0 -0
  48. data/examples/male02.mtl +54 -0
  49. data/examples/male02.obj +13888 -0
  50. data/examples/moon.png +0 -0
  51. data/examples/orig_02_-_Defaul1noCulling.png +0 -0
  52. data/examples/texture.png +0 -0
  53. data/lib/mittsu.rb +15 -0
  54. data/lib/mittsu/cameras.rb +4 -0
  55. data/lib/mittsu/cameras/camera.rb +34 -0
  56. data/lib/mittsu/cameras/cube_camera.rb +74 -0
  57. data/lib/mittsu/cameras/orthographic_camera.rb +53 -0
  58. data/lib/mittsu/cameras/perspective_camera.rb +115 -0
  59. data/lib/mittsu/constants.rb +160 -0
  60. data/lib/mittsu/core.rb +10 -0
  61. data/lib/mittsu/core/buffer_attribute.rb +87 -0
  62. data/lib/mittsu/core/buffer_geometry.rb +694 -0
  63. data/lib/mittsu/core/clock.rb +44 -0
  64. data/lib/mittsu/core/dynamic_buffer_attribute.rb +16 -0
  65. data/lib/mittsu/core/event_dispatcher.rb +39 -0
  66. data/lib/mittsu/core/face3.rb +30 -0
  67. data/lib/mittsu/core/geometry.rb +596 -0
  68. data/lib/mittsu/core/hash_array.rb +36 -0
  69. data/lib/mittsu/core/hash_object.rb +19 -0
  70. data/lib/mittsu/core/object_3d.rb +421 -0
  71. data/lib/mittsu/core/raycaster.rb +78 -0
  72. data/lib/mittsu/extras.rb +3 -0
  73. data/lib/mittsu/extras/geometries.rb +2 -0
  74. data/lib/mittsu/extras/geometries/box_geometry.rb +108 -0
  75. data/lib/mittsu/extras/geometries/sphere_geometry.rb +88 -0
  76. data/lib/mittsu/extras/helpers.rb +1 -0
  77. data/lib/mittsu/extras/helpers/camera_helper.rb +155 -0
  78. data/lib/mittsu/extras/image.rb +3 -0
  79. data/lib/mittsu/extras/image_utils.rb +80 -0
  80. data/lib/mittsu/lights.rb +7 -0
  81. data/lib/mittsu/lights/ambient_light.rb +16 -0
  82. data/lib/mittsu/lights/area_light.rb +24 -0
  83. data/lib/mittsu/lights/directional_light.rb +131 -0
  84. data/lib/mittsu/lights/hemisphere_light.rb +29 -0
  85. data/lib/mittsu/lights/light.rb +21 -0
  86. data/lib/mittsu/lights/point_light.rb +27 -0
  87. data/lib/mittsu/lights/spot_light.rb +104 -0
  88. data/lib/mittsu/loaders.rb +7 -0
  89. data/lib/mittsu/loaders/cache.rb +53 -0
  90. data/lib/mittsu/loaders/file_loader.rb +22 -0
  91. data/lib/mittsu/loaders/image_loader.rb +32 -0
  92. data/lib/mittsu/loaders/loader.rb +212 -0
  93. data/lib/mittsu/loaders/loading_manager.rb +17 -0
  94. data/lib/mittsu/loaders/mtl_loader.rb +242 -0
  95. data/lib/mittsu/loaders/obj_mtl_loader.rb +225 -0
  96. data/lib/mittsu/materials.rb +7 -0
  97. data/lib/mittsu/materials/line_basic_material.rb +39 -0
  98. data/lib/mittsu/materials/material.rb +156 -0
  99. data/lib/mittsu/materials/mesh_basic_material.rb +122 -0
  100. data/lib/mittsu/materials/mesh_face_material.rb +30 -0
  101. data/lib/mittsu/materials/mesh_lambert_material.rb +126 -0
  102. data/lib/mittsu/materials/mesh_phong_material.rb +152 -0
  103. data/lib/mittsu/materials/shader_material.rb +108 -0
  104. data/lib/mittsu/math.rb +105 -0
  105. data/lib/mittsu/math/box2.rb +135 -0
  106. data/lib/mittsu/math/box3.rb +194 -0
  107. data/lib/mittsu/math/color.rb +252 -0
  108. data/lib/mittsu/math/color_keywords.rb +151 -0
  109. data/lib/mittsu/math/euler.rb +182 -0
  110. data/lib/mittsu/math/frustum.rb +106 -0
  111. data/lib/mittsu/math/line3.rb +76 -0
  112. data/lib/mittsu/math/matrix3.rb +163 -0
  113. data/lib/mittsu/math/matrix4.rb +581 -0
  114. data/lib/mittsu/math/plane.rb +128 -0
  115. data/lib/mittsu/math/quaternion.rb +309 -0
  116. data/lib/mittsu/math/ray.rb +292 -0
  117. data/lib/mittsu/math/sphere.rb +91 -0
  118. data/lib/mittsu/math/spline.rb +128 -0
  119. data/lib/mittsu/math/triangle.rb +121 -0
  120. data/lib/mittsu/math/vector2.rb +238 -0
  121. data/lib/mittsu/math/vector3.rb +491 -0
  122. data/lib/mittsu/math/vector4.rb +414 -0
  123. data/lib/mittsu/objects.rb +3 -0
  124. data/lib/mittsu/objects/group.rb +8 -0
  125. data/lib/mittsu/objects/line.rb +143 -0
  126. data/lib/mittsu/objects/mesh.rb +243 -0
  127. data/lib/mittsu/renderers.rb +1 -0
  128. data/lib/mittsu/renderers/glfw_window.rb +216 -0
  129. data/lib/mittsu/renderers/opengl/opengl_debug.rb +38 -0
  130. data/lib/mittsu/renderers/opengl/opengl_program.rb +402 -0
  131. data/lib/mittsu/renderers/opengl/opengl_shader.rb +58 -0
  132. data/lib/mittsu/renderers/opengl/opengl_state.rb +207 -0
  133. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +416 -0
  134. data/lib/mittsu/renderers/opengl_render_target.rb +87 -0
  135. data/lib/mittsu/renderers/opengl_renderer.rb +3376 -0
  136. data/lib/mittsu/renderers/shaders/shader_chunk.rb +12 -0
  137. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +5 -0
  138. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +5 -0
  139. data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +5 -0
  140. data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +40 -0
  141. data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +5 -0
  142. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +5 -0
  143. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +5 -0
  144. data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +5 -0
  145. data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +60 -0
  146. data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +15 -0
  147. data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +21 -0
  148. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +62 -0
  149. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +21 -0
  150. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +7 -0
  151. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +17 -0
  152. data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +26 -0
  153. data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +15 -0
  154. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +5 -0
  155. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +6 -0
  156. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +5 -0
  157. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +5 -0
  158. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +43 -0
  159. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +196 -0
  160. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +243 -0
  161. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +58 -0
  162. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +5 -0
  163. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +5 -0
  164. data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +2 -0
  165. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +5 -0
  166. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +12 -0
  167. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +11 -0
  168. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +15 -0
  169. data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +9 -0
  170. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +11 -0
  171. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +6 -0
  172. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +5 -0
  173. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +6 -0
  174. data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +5 -0
  175. data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +12 -0
  176. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +13 -0
  177. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +20 -0
  178. data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +27 -0
  179. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +217 -0
  180. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +19 -0
  181. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +6 -0
  182. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +9 -0
  183. data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +8 -0
  184. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +47 -0
  185. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +20 -0
  186. data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +20 -0
  187. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +12 -0
  188. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +5 -0
  189. data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +17 -0
  190. data/lib/mittsu/renderers/shaders/shader_lib.rb +420 -0
  191. data/lib/mittsu/renderers/shaders/uniforms_lib.rb +107 -0
  192. data/lib/mittsu/renderers/shaders/uniforms_utils.rb +31 -0
  193. data/lib/mittsu/scenes.rb +1 -0
  194. data/lib/mittsu/scenes/scene.rb +27 -0
  195. data/lib/mittsu/textures.rb +5 -0
  196. data/lib/mittsu/textures/compressed_texture.rb +30 -0
  197. data/lib/mittsu/textures/cube_texture.rb +19 -0
  198. data/lib/mittsu/textures/data_texture.rb +17 -0
  199. data/lib/mittsu/textures/texture.rb +92 -0
  200. data/lib/mittsu/textures/video_texture.rb +17 -0
  201. data/lib/mittsu/version.rb +4 -0
  202. data/mittsu.gemspec +31 -0
  203. metadata +357 -0
@@ -0,0 +1,42 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '05 Earth Example'
11
+
12
+ box_geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
13
+ light = Mittsu::PointLight.new(0xffffff, 4.0, 10.0, 1.5) # white, 4x intensity
14
+ dot = Mittsu::Mesh.new(box_geometry, Mittsu::MeshBasicMaterial.new(color: 0xffffff))
15
+ dot.scale.set(0.1, 0.1, 0.1)
16
+ light.add(dot)
17
+ light.position.set(0.0, 1.5, 1.0)
18
+ light_object = Mittsu::Object3D.new
19
+ light_object.add(light)
20
+ scene.add(light_object)
21
+
22
+ geometry = Mittsu::SphereGeometry.new(1.0, 32, 16)
23
+ texture = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), 'earth.png')
24
+ material = Mittsu::MeshLambertMaterial.new(map: texture)
25
+ earth = Mittsu::Mesh.new(geometry, material)
26
+ scene.add(earth)
27
+
28
+ camera.position.z = 5.0
29
+
30
+ renderer.window.on_resize do |width, height|
31
+ renderer.set_viewport(0, 0, width, height)
32
+ camera.aspect = width.to_f / height.to_f
33
+ camera.update_projection_matrix
34
+ end
35
+
36
+ renderer.window.run do
37
+ light_object.rotation.z += 0.05
38
+ earth.rotation.x += 0.05
39
+ earth.rotation.y += 0.05
40
+
41
+ renderer.render(scene, camera)
42
+ end
@@ -0,0 +1,46 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '05 Earth Example'
11
+
12
+ light = Mittsu::HemisphereLight.new(0xffffff, 0x000000, 1)
13
+ light.position.x = 1000
14
+ scene.add(light)
15
+
16
+ moon_container = Mittsu::Object3D.new
17
+
18
+ geometry = Mittsu::SphereGeometry.new(1.0, 32, 16)
19
+ texture = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), 'earth.png')
20
+ material = Mittsu::MeshLambertMaterial.new(map: texture)
21
+ earth = Mittsu::Mesh.new(geometry, material)
22
+ scene.add(earth)
23
+
24
+ geometry = Mittsu::SphereGeometry.new(0.2725631769, 32, 16)
25
+ texture = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), 'moon.png')
26
+ material = Mittsu::MeshLambertMaterial.new(map: texture)
27
+ moon = Mittsu::Mesh.new(geometry, material)
28
+ moon.position.x = 30.167948517
29
+ moon_container.add(moon)
30
+
31
+ scene.add(moon_container)
32
+
33
+ camera.position.z = 30.0
34
+
35
+ renderer.window.on_resize do |width, height|
36
+ renderer.set_viewport(0, 0, width, height)
37
+ camera.aspect = width.to_f / height.to_f
38
+ camera.update_projection_matrix
39
+ end
40
+
41
+ renderer.window.run do
42
+ moon_container.rotation.y += 0.0003571428571
43
+ earth.rotation.y += 0.01
44
+
45
+ renderer.render(scene, camera)
46
+ end
@@ -0,0 +1,32 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '05 Texture Example'
11
+
12
+ geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
13
+ texture = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), 'texture.png')
14
+ material = Mittsu::MeshBasicMaterial.new(map: texture)
15
+ cube = Mittsu::Mesh.new(geometry, material)
16
+ scene.add(cube)
17
+
18
+ camera.position.z = 5.0
19
+
20
+ renderer.window.on_resize do |width, height|
21
+ renderer.set_viewport(0, 0, width, height)
22
+ camera.aspect = width.to_f / height.to_f
23
+ camera.update_projection_matrix
24
+ end
25
+
26
+ renderer.window.run do
27
+ cube.rotation.x += 0.1
28
+ cube.rotation.y += 0.1
29
+
30
+ renderer.render(scene, camera)
31
+ # break
32
+ end
@@ -0,0 +1,36 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '06 Cube Texture Example'
11
+
12
+ geometry = Mittsu::SphereGeometry.new(2.0, 32, 16)
13
+ texture = Mittsu::ImageUtils.load_texture_cube(
14
+ [ 'rt', 'lf', 'up', 'dn', 'bk', 'ft' ].map { |path|
15
+ File.join File.dirname(__FILE__), 'cubemap', "tron_#{path}.png"
16
+ }
17
+ )
18
+ material = Mittsu::MeshBasicMaterial.new(env_map: texture)
19
+ earth = Mittsu::Mesh.new(geometry, material)
20
+ scene.add(earth)
21
+
22
+ camera.position.z = 5.0
23
+ camera_container = Mittsu::Object3D.new
24
+ camera_container.add(camera)
25
+ scene.add(camera_container)
26
+
27
+ renderer.window.on_resize do |width, height|
28
+ renderer.set_viewport(0, 0, width, height)
29
+ camera.aspect = width.to_f / height.to_f
30
+ camera.update_projection_matrix
31
+ end
32
+
33
+ renderer.window.run do
34
+ camera_container.rotation.y += 0.01;
35
+ renderer.render(scene, camera)
36
+ end
@@ -0,0 +1,60 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ skybox_scene = Mittsu::Scene.new
9
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
10
+ skybox_camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 1.0, 100.0)
11
+
12
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '06 Skybox Example'
13
+ renderer.auto_clear = false
14
+
15
+ geometry = Mittsu::SphereGeometry.new(2.0, 32, 16)
16
+ texture = Mittsu::ImageUtils.load_texture_cube(
17
+ [ 'rt', 'lf', 'up', 'dn', 'bk', 'ft' ].map { |path|
18
+ File.join File.dirname(__FILE__), 'cubemap', "tron_#{path}.png"
19
+ }
20
+ )
21
+ material = Mittsu::MeshBasicMaterial.new(env_map: texture)
22
+ earth = Mittsu::Mesh.new(geometry, material)
23
+ scene.add(earth)
24
+
25
+ shader = Mittsu::ShaderLib[:cube]
26
+ shader.uniforms['tCube'].value = texture
27
+
28
+ skybox_material = Mittsu::ShaderMaterial.new({
29
+ fragment_shader: shader.fragment_shader,
30
+ vertex_shader: shader.vertex_shader,
31
+ uniforms: shader.uniforms,
32
+ depth_write: false,
33
+ side: Mittsu::BackSide
34
+ })
35
+
36
+ skybox = Mittsu::Mesh.new(Mittsu::BoxGeometry.new(100, 100, 100), skybox_material)
37
+ skybox_scene.add(skybox)
38
+
39
+ camera.position.z = 5.0
40
+
41
+ renderer.window.on_resize do |width, height|
42
+ renderer.set_viewport(0, 0, width, height)
43
+ camera.aspect = skybox_camera.aspect = width.to_f / height.to_f
44
+ camera.update_projection_matrix
45
+ skybox_camera.update_projection_matrix
46
+ end
47
+
48
+ x = 0
49
+ renderer.window.run do
50
+ camera.position.x = 5.0 * Math.sin(x * 0.01)
51
+ camera.position.z = 5.0 * Math.cos(x * 0.01)
52
+ camera.look_at(Mittsu::Vector3.new(0.0, 0.0, 0.0))
53
+ skybox_camera.rotation.copy(camera.rotation)
54
+
55
+ renderer.clear
56
+ renderer.render(skybox_scene, skybox_camera);
57
+ renderer.clear_depth
58
+ renderer.render(scene, camera)
59
+ x += 1
60
+ end
@@ -0,0 +1,36 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '07 Earth Normal Example'
11
+
12
+ light = Mittsu::SpotLight.new(0xffffff, 2.0)
13
+ light.position.x = 1000
14
+ light.look_at(scene.position)
15
+ scene.add(light)
16
+
17
+ geometry = Mittsu::SphereGeometry.new(2.0, 64, 64)
18
+ texture = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), './earth.png')
19
+ normal = Mittsu::ImageUtils.load_texture(File.join File.dirname(__FILE__), './earth_normal.png')
20
+ material = Mittsu::MeshPhongMaterial.new({ map: texture, normal_map: normal })
21
+ earth = Mittsu::Mesh.new(geometry, material)
22
+ scene.add(earth)
23
+
24
+ camera.position.z = 5.0
25
+
26
+ renderer.window.on_resize do |width, height|
27
+ renderer.set_viewport(0, 0, width, height)
28
+ camera.aspect = width.to_f / height.to_f
29
+ camera.update_projection_matrix
30
+ end
31
+
32
+ renderer.window.run do
33
+ earth.rotation.y += 0.01
34
+
35
+ renderer.render(scene, camera)
36
+ end
@@ -0,0 +1,87 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '08 Shadow Example'
11
+ renderer.shadow_map_enabled = true
12
+ renderer.shadow_map_type = Mittsu::PCFSoftShadowMap
13
+
14
+ floor = Mittsu::Mesh.new(
15
+ Mittsu::BoxGeometry.new(100.0, 1.0, 100.0),
16
+ Mittsu::MeshPhongMaterial.new(color: 0x00ff00)
17
+ )
18
+ floor.position.y = -1.0
19
+ floor.receive_shadow = true
20
+ scene.add(floor)
21
+
22
+ NB = 15
23
+ NR = 5
24
+ balls = NB.times.map do |index|
25
+ NR.times.map do |r|
26
+ ring = (3 + r)
27
+ i = r * 0.1 + (index.to_f / NB.to_f) * Math::PI * 2
28
+ Mittsu::Mesh.new(
29
+ Mittsu::SphereGeometry.new(0.5, 16, 16),
30
+ Mittsu::MeshLambertMaterial.new(color: r.even? ? 0x00ffff : 0xff00ff)
31
+ ).tap do |b|
32
+ b.cast_shadow = true
33
+ b.receive_shadow = true
34
+ b.position.z = Math.cos(i) * ring
35
+ b.position.x = Math.sin(i) * ring
36
+ scene.add(b)
37
+ end
38
+ end
39
+ end.flatten
40
+
41
+ ball = Mittsu::Mesh.new(
42
+ Mittsu::SphereGeometry.new(1.0, 32, 32),
43
+ Mittsu::MeshLambertMaterial.new(color: 0xffffff)
44
+ )
45
+ ball.cast_shadow = true
46
+ ball.receive_shadow = true
47
+ scene.add(ball)
48
+
49
+ light = Mittsu::SpotLight.new(0xffffff, 1.0)
50
+ light.position.set(20.0, 30.0, 0.0)
51
+
52
+ light.cast_shadow = true
53
+ light.shadow_darkness = 0.5
54
+
55
+ light.shadow_map_width = 1024
56
+ light.shadow_map_height = 1024
57
+
58
+ light.shadow_camera_near = 1.0
59
+ light.shadow_camera_far = 100.0
60
+ light.shadow_camera_fov = 60.0
61
+
62
+ light.shadow_camera_visible = true
63
+ scene.add(light)
64
+
65
+ camera.position.z = 10.0
66
+ camera.position.y = 10.0
67
+ camera.look_at(floor.position)
68
+
69
+ renderer.window.on_resize do |width, height|
70
+ renderer.set_viewport(0, 0, width, height)
71
+ camera.aspect = width.to_f / height.to_f
72
+ camera.update_projection_matrix
73
+ end
74
+
75
+ x = 0
76
+ renderer.window.run do
77
+ # break if x > 0
78
+ x += 1
79
+ light.position.x = Math::sin(x * 0.01) * 20.0
80
+ light.position.z = Math::cos(x * 0.01) * 20.0
81
+
82
+ balls.each_with_index do |b, i|
83
+ b.position.y = (1.0 + Math::sin(x * 0.05 + i)) * 2.0
84
+ end
85
+
86
+ renderer.render(scene, camera)
87
+ end
@@ -0,0 +1,52 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '09 Line Example'
11
+
12
+ ball = Mittsu::Mesh.new(
13
+ Mittsu::SphereGeometry.new(0.1),
14
+ Mittsu::MeshBasicMaterial.new(color: 0xff00ff)
15
+ )
16
+ scene.add(ball)
17
+
18
+ material = Mittsu::LineBasicMaterial.new(color: 0xff00ff)
19
+
20
+ geometry = Mittsu::Geometry.new()
21
+ NP = 10000
22
+ MD = 10.0
23
+ NR = 200
24
+ NP.times do |i|
25
+ d = (i.to_f / NP) * MD
26
+ r = (i.to_f / NP) * Math::PI * NR
27
+ x = Math.sin(r) * d
28
+ y = Math.cos(r) * d
29
+ geometry.vertices.push(Mittsu::Vector3.new(x, y, 0.0))
30
+ end
31
+
32
+ line = Mittsu::Line.new(geometry, material)
33
+ scene.add(line)
34
+
35
+ camera.position.z = 5.0
36
+ camera.position.y = 0.0
37
+ camera.look_at(line.position)
38
+
39
+ renderer.window.on_resize do |width, height|
40
+ renderer.set_viewport(0, 0, width, height)
41
+ camera.aspect = width.to_f / height.to_f
42
+ camera.update_projection_matrix
43
+ end
44
+
45
+ x = 0
46
+ renderer.window.run do
47
+ # break if x > 0
48
+ x += 1
49
+ line.rotation.z = x * 0.1
50
+
51
+ renderer.render(scene, camera)
52
+ end
@@ -0,0 +1,68 @@
1
+ require_relative './example_helper'
2
+
3
+ SCREEN_WIDTH = 800
4
+ SCREEN_HEIGHT = 600
5
+ ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
6
+
7
+ scene = Mittsu::Scene.new
8
+ camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
9
+
10
+ renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '10 OBJ Loader Example'
11
+ renderer.shadow_map_enabled = true
12
+ renderer.shadow_map_type = Mittsu::PCFSoftShadowMap
13
+
14
+ loader = Mittsu::OBJMTLLoader.new
15
+
16
+ object = loader.load('male02.obj', 'male02.mtl')
17
+
18
+ object.receive_shadow = true
19
+ object.cast_shadow = true
20
+
21
+ object.traverse do |child|
22
+ child.receive_shadow = true
23
+ child.cast_shadow = true
24
+ end
25
+
26
+ scene.add(object)
27
+
28
+ scene.print_tree
29
+
30
+ floor = Mittsu::Mesh.new(
31
+ Mittsu::BoxGeometry.new(1000.0, 1.0, 1000.0),
32
+ Mittsu::MeshPhongMaterial.new(color: 0xffffff)
33
+ )
34
+ floor.position.y = -1.0
35
+ floor.receive_shadow = true
36
+ scene.add(floor)
37
+
38
+ scene.add Mittsu::AmbientLight.new(0xffffff)
39
+
40
+ light = Mittsu::SpotLight.new(0xffffff, 1.0)
41
+ light.position.set(300.0, 200.0, 0.0)
42
+
43
+ light.cast_shadow = true
44
+ light.shadow_darkness = 0.5
45
+
46
+ light.shadow_map_width = 1024
47
+ light.shadow_map_height = 1024
48
+
49
+ light.shadow_camera_near = 1.0
50
+ light.shadow_camera_far = 2000.0
51
+ light.shadow_camera_fov = 60.0
52
+
53
+ light.shadow_camera_visible = false
54
+ scene.add(light)
55
+
56
+ camera.position.z = 200.0
57
+ camera.position.y = 100.0
58
+
59
+ renderer.window.on_resize do |width, height|
60
+ renderer.set_viewport(0, 0, width, height)
61
+ camera.aspect = width.to_f / height.to_f
62
+ camera.update_projection_matrix
63
+ end
64
+
65
+ renderer.window.run do
66
+ object.rotation.y += 0.1
67
+ renderer.render(scene, camera)
68
+ end