mittsu 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +18 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1158 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -1
- data/LICENSE.txt +1 -1
- data/README.md +173 -7
- data/circle.yml +20 -0
- data/install-glfw-3.1.2.sh +14 -0
- data/lib/mittsu.rb +0 -2
- data/lib/mittsu/extras/image_utils.rb +59 -55
- data/lib/mittsu/renderers/glfw_window.rb +17 -2
- data/lib/mittsu/renderers/opengl_renderer.rb +1 -1
- data/lib/mittsu/renderers/shaders/shader_lib.rb +4 -4
- data/lib/mittsu/version.rb +1 -1
- data/mittsu.gemspec +11 -5
- metadata +53 -71
- data/.travis.yml +0 -3
- data/examples/01_-_Default1noCulling.png +0 -0
- data/examples/01_scene_example.rb +0 -14
- data/examples/02_box_mesh_example.rb +0 -30
- data/examples/02_sphere_mesh_example.rb +0 -30
- data/examples/03_complex_object_example.rb +0 -52
- data/examples/04_ambient_light_example.rb +0 -33
- data/examples/04_dir_light_example.rb +0 -36
- data/examples/04_hemi_light_example.rb +0 -30
- data/examples/04_point_light_example.rb +0 -50
- data/examples/04_spot_light_example.rb +0 -44
- data/examples/05_earth_example.rb +0 -42
- data/examples/05_earth_moon_example.rb +0 -46
- data/examples/05_texture_example.rb +0 -32
- data/examples/06_cube_texture_example.rb +0 -36
- data/examples/06_skybox_example.rb +0 -60
- data/examples/07_earth_normal_example.rb +0 -36
- data/examples/08_shadow_example.rb +0 -87
- data/examples/09_line_example.rb +0 -52
- data/examples/10_obj_loader_example.rb +0 -68
- data/examples/11_character_input_example.rb +0 -18
- data/examples/11_continuous_keyboard_input_example.rb +0 -35
- data/examples/11_keyboard_input_example.rb +0 -43
- data/examples/12_mouse_click_example.rb +0 -38
- data/examples/12_mouse_motion_example.rb +0 -35
- data/examples/12_mouse_scroll_example.rb +0 -36
- data/examples/12_orbit_zoom_example.rb +0 -68
- data/examples/13_joystick_example.rb +0 -80
- data/examples/cubemap/tron_bk.png +0 -0
- data/examples/cubemap/tron_dn.png +0 -0
- data/examples/cubemap/tron_ft.png +0 -0
- data/examples/cubemap/tron_lf.png +0 -0
- data/examples/cubemap/tron_rt.png +0 -0
- data/examples/cubemap/tron_up.png +0 -0
- data/examples/earth.png +0 -0
- data/examples/earth_normal.png +0 -0
- data/examples/example_helper.rb +0 -2
- data/examples/male-02-1noCulling.png +0 -0
- data/examples/male02.mtl +0 -54
- data/examples/male02.obj +0 -13888
- data/examples/moon.png +0 -0
- data/examples/orig_02_-_Defaul1noCulling.png +0 -0
- data/examples/texture.png +0 -0
@@ -1,33 +0,0 @@
|
|
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: '04 Ambient Light Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::SphereGeometry.new(1.0)
|
13
|
-
material = Mittsu::MeshLambertMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
light = Mittsu::AmbientLight.new(0x404040) # soft white light
|
18
|
-
scene.add(light)
|
19
|
-
|
20
|
-
camera.position.z = 5.0
|
21
|
-
|
22
|
-
renderer.window.on_resize do |width, height|
|
23
|
-
renderer.set_viewport(0, 0, width, height)
|
24
|
-
camera.aspect = width.to_f / height.to_f
|
25
|
-
camera.update_projection_matrix
|
26
|
-
end
|
27
|
-
|
28
|
-
renderer.window.run do
|
29
|
-
cube.rotation.x += 0.1
|
30
|
-
cube.rotation.y += 0.1
|
31
|
-
|
32
|
-
renderer.render(scene, camera)
|
33
|
-
end
|
@@ -1,36 +0,0 @@
|
|
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: '04 Directional Light Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::SphereGeometry.new(1.0)
|
13
|
-
material = Mittsu::MeshLambertMaterial.new(color: 0x00ff00)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
light = Mittsu::DirectionalLight.new(0xffffff, 0.5) # white, half intensity
|
18
|
-
light.position.set(0.5, 1.0, 0.0)
|
19
|
-
light_object = Mittsu::Object3D.new
|
20
|
-
light_object.add(light)
|
21
|
-
scene.add(light_object)
|
22
|
-
|
23
|
-
camera.position.z = 5.0
|
24
|
-
|
25
|
-
renderer.window.on_resize do |width, height|
|
26
|
-
renderer.set_viewport(0, 0, width, height)
|
27
|
-
camera.aspect = width.to_f / height.to_f
|
28
|
-
camera.update_projection_matrix
|
29
|
-
end
|
30
|
-
|
31
|
-
renderer.window.run do
|
32
|
-
light_object.rotation.x += 0.1
|
33
|
-
light_object.rotation.y += 0.1
|
34
|
-
|
35
|
-
renderer.render(scene, camera)
|
36
|
-
end
|
@@ -1,30 +0,0 @@
|
|
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: '04 Hemisphere Light Example'
|
11
|
-
|
12
|
-
geometry = Mittsu::SphereGeometry.new(1.0)
|
13
|
-
material = Mittsu::MeshLambertMaterial.new(color: 0xffffff)
|
14
|
-
cube = Mittsu::Mesh.new(geometry, material)
|
15
|
-
scene.add(cube)
|
16
|
-
|
17
|
-
light = Mittsu::HemisphereLight.new(0xCCF2FF, 0x055E00, 0.5) # blue/green, half intensity
|
18
|
-
scene.add(light)
|
19
|
-
|
20
|
-
camera.position.z = 5.0
|
21
|
-
|
22
|
-
renderer.window.on_resize do |width, height|
|
23
|
-
renderer.set_viewport(0, 0, width, height)
|
24
|
-
camera.aspect = width.to_f / height.to_f
|
25
|
-
camera.update_projection_matrix
|
26
|
-
end
|
27
|
-
|
28
|
-
renderer.window.run do
|
29
|
-
renderer.render(scene, camera)
|
30
|
-
end
|
@@ -1,50 +0,0 @@
|
|
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: '04 Point Light Example'
|
11
|
-
|
12
|
-
sphere_geometry = Mittsu::SphereGeometry.new(1.0)
|
13
|
-
box_geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
14
|
-
green_material = Mittsu::MeshLambertMaterial.new(color: 0x00ff00)
|
15
|
-
blue_material = Mittsu::MeshLambertMaterial.new(color: 0x0000ff)
|
16
|
-
magenta_material = Mittsu::MeshLambertMaterial.new(color: 0xff00ff)
|
17
|
-
cube = Mittsu::Mesh.new(box_geometry, green_material)
|
18
|
-
sphere1 = Mittsu::Mesh.new(sphere_geometry, blue_material)
|
19
|
-
sphere1.position.set(3.0, 0.0, 0.0)
|
20
|
-
sphere2 = Mittsu::Mesh.new(sphere_geometry, magenta_material)
|
21
|
-
sphere2.position.set(-3.0, 0.0, 0.0)
|
22
|
-
|
23
|
-
scene.add(cube)
|
24
|
-
scene.add(sphere1)
|
25
|
-
scene.add(sphere2)
|
26
|
-
|
27
|
-
light = Mittsu::PointLight.new(0xffffff, 0.5, 10.0, 1.5) # white, half intensity
|
28
|
-
dot = Mittsu::Mesh.new(box_geometry, Mittsu::MeshBasicMaterial.new(color: 0xffffff))
|
29
|
-
dot.scale.set(0.1, 0.1, 0.1)
|
30
|
-
light.add(dot)
|
31
|
-
light.position.set(0.0, 1.5, 0.0)
|
32
|
-
light_object = Mittsu::Object3D.new
|
33
|
-
light_object.add(light)
|
34
|
-
scene.add(light_object)
|
35
|
-
|
36
|
-
camera.position.z = 5.0
|
37
|
-
|
38
|
-
renderer.window.on_resize do |width, height|
|
39
|
-
renderer.set_viewport(0, 0, width, height)
|
40
|
-
camera.aspect = width.to_f / height.to_f
|
41
|
-
camera.update_projection_matrix
|
42
|
-
end
|
43
|
-
|
44
|
-
renderer.window.run do
|
45
|
-
light_object.rotation.z += 0.1
|
46
|
-
cube.rotation.x += 0.1
|
47
|
-
cube.rotation.y += 0.1
|
48
|
-
|
49
|
-
renderer.render(scene, camera)
|
50
|
-
end
|
@@ -1,44 +0,0 @@
|
|
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: '04 Spot Light Example'
|
11
|
-
|
12
|
-
box_geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
|
13
|
-
sphere_geometry = Mittsu::SphereGeometry.new(1.0)
|
14
|
-
floor_geometry = Mittsu::BoxGeometry.new(20.0, 0.1, 20.0, 20, 1, 20)
|
15
|
-
green_material = Mittsu::MeshLambertMaterial.new(color: 0x00ff00)
|
16
|
-
blue_material = Mittsu::MeshLambertMaterial.new(color: 0x0000ff)
|
17
|
-
sphere = Mittsu::Mesh.new(sphere_geometry, blue_material)
|
18
|
-
floor = Mittsu::Mesh.new(floor_geometry, green_material)
|
19
|
-
floor.position.set(0.0, -2.0, 0.0)
|
20
|
-
scene.add(sphere)
|
21
|
-
scene.add(floor)
|
22
|
-
|
23
|
-
light = Mittsu::SpotLight.new(0xffffff, 0.5, 10.0) # white, half intensity
|
24
|
-
light.position.set(3.0, 1.0, 0.0)
|
25
|
-
dot = Mittsu::Mesh.new(box_geometry, Mittsu::MeshBasicMaterial.new(color: 0xffffff))
|
26
|
-
dot.scale.set(0.1, 0.1, 0.1)
|
27
|
-
light.add(dot)
|
28
|
-
light_object = Mittsu::Object3D.new
|
29
|
-
light_object.add(light)
|
30
|
-
scene.add(light_object)
|
31
|
-
|
32
|
-
camera.position.z = 5.0
|
33
|
-
|
34
|
-
renderer.window.on_resize do |width, height|
|
35
|
-
renderer.set_viewport(0, 0, width, height)
|
36
|
-
camera.aspect = width.to_f / height.to_f
|
37
|
-
camera.update_projection_matrix
|
38
|
-
end
|
39
|
-
|
40
|
-
renderer.window.run do
|
41
|
-
light_object.rotation.y += 0.1
|
42
|
-
|
43
|
-
renderer.render(scene, camera)
|
44
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
|
@@ -1,46 +0,0 @@
|
|
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
|
@@ -1,32 +0,0 @@
|
|
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
|
@@ -1,36 +0,0 @@
|
|
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
|
@@ -1,60 +0,0 @@
|
|
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
|
@@ -1,36 +0,0 @@
|
|
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
|