mittsu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/01_-_Default1noCulling.png +0 -0
- data/examples/01_scene_example.rb +14 -0
- data/examples/02_box_mesh_example.rb +30 -0
- data/examples/02_sphere_mesh_example.rb +30 -0
- data/examples/03_complex_object_example.rb +52 -0
- data/examples/04_ambient_light_example.rb +33 -0
- data/examples/04_dir_light_example.rb +36 -0
- data/examples/04_hemi_light_example.rb +30 -0
- data/examples/04_point_light_example.rb +50 -0
- data/examples/04_spot_light_example.rb +44 -0
- data/examples/05_earth_example.rb +42 -0
- data/examples/05_earth_moon_example.rb +46 -0
- data/examples/05_texture_example.rb +32 -0
- data/examples/06_cube_texture_example.rb +36 -0
- data/examples/06_skybox_example.rb +60 -0
- data/examples/07_earth_normal_example.rb +36 -0
- data/examples/08_shadow_example.rb +87 -0
- data/examples/09_line_example.rb +52 -0
- data/examples/10_obj_loader_example.rb +68 -0
- data/examples/11_character_input_example.rb +18 -0
- data/examples/11_continuous_keyboard_input_example.rb +35 -0
- data/examples/11_keyboard_input_example.rb +43 -0
- data/examples/12_mouse_click_example.rb +38 -0
- data/examples/12_mouse_motion_example.rb +35 -0
- data/examples/12_mouse_scroll_example.rb +36 -0
- data/examples/12_orbit_zoom_example.rb +68 -0
- data/examples/13_joystick_example.rb +80 -0
- 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 +2 -0
- data/examples/male-02-1noCulling.png +0 -0
- data/examples/male02.mtl +54 -0
- data/examples/male02.obj +13888 -0
- data/examples/moon.png +0 -0
- data/examples/orig_02_-_Defaul1noCulling.png +0 -0
- data/examples/texture.png +0 -0
- data/lib/mittsu.rb +15 -0
- data/lib/mittsu/cameras.rb +4 -0
- data/lib/mittsu/cameras/camera.rb +34 -0
- data/lib/mittsu/cameras/cube_camera.rb +74 -0
- data/lib/mittsu/cameras/orthographic_camera.rb +53 -0
- data/lib/mittsu/cameras/perspective_camera.rb +115 -0
- data/lib/mittsu/constants.rb +160 -0
- data/lib/mittsu/core.rb +10 -0
- data/lib/mittsu/core/buffer_attribute.rb +87 -0
- data/lib/mittsu/core/buffer_geometry.rb +694 -0
- data/lib/mittsu/core/clock.rb +44 -0
- data/lib/mittsu/core/dynamic_buffer_attribute.rb +16 -0
- data/lib/mittsu/core/event_dispatcher.rb +39 -0
- data/lib/mittsu/core/face3.rb +30 -0
- data/lib/mittsu/core/geometry.rb +596 -0
- data/lib/mittsu/core/hash_array.rb +36 -0
- data/lib/mittsu/core/hash_object.rb +19 -0
- data/lib/mittsu/core/object_3d.rb +421 -0
- data/lib/mittsu/core/raycaster.rb +78 -0
- data/lib/mittsu/extras.rb +3 -0
- data/lib/mittsu/extras/geometries.rb +2 -0
- data/lib/mittsu/extras/geometries/box_geometry.rb +108 -0
- data/lib/mittsu/extras/geometries/sphere_geometry.rb +88 -0
- data/lib/mittsu/extras/helpers.rb +1 -0
- data/lib/mittsu/extras/helpers/camera_helper.rb +155 -0
- data/lib/mittsu/extras/image.rb +3 -0
- data/lib/mittsu/extras/image_utils.rb +80 -0
- data/lib/mittsu/lights.rb +7 -0
- data/lib/mittsu/lights/ambient_light.rb +16 -0
- data/lib/mittsu/lights/area_light.rb +24 -0
- data/lib/mittsu/lights/directional_light.rb +131 -0
- data/lib/mittsu/lights/hemisphere_light.rb +29 -0
- data/lib/mittsu/lights/light.rb +21 -0
- data/lib/mittsu/lights/point_light.rb +27 -0
- data/lib/mittsu/lights/spot_light.rb +104 -0
- data/lib/mittsu/loaders.rb +7 -0
- data/lib/mittsu/loaders/cache.rb +53 -0
- data/lib/mittsu/loaders/file_loader.rb +22 -0
- data/lib/mittsu/loaders/image_loader.rb +32 -0
- data/lib/mittsu/loaders/loader.rb +212 -0
- data/lib/mittsu/loaders/loading_manager.rb +17 -0
- data/lib/mittsu/loaders/mtl_loader.rb +242 -0
- data/lib/mittsu/loaders/obj_mtl_loader.rb +225 -0
- data/lib/mittsu/materials.rb +7 -0
- data/lib/mittsu/materials/line_basic_material.rb +39 -0
- data/lib/mittsu/materials/material.rb +156 -0
- data/lib/mittsu/materials/mesh_basic_material.rb +122 -0
- data/lib/mittsu/materials/mesh_face_material.rb +30 -0
- data/lib/mittsu/materials/mesh_lambert_material.rb +126 -0
- data/lib/mittsu/materials/mesh_phong_material.rb +152 -0
- data/lib/mittsu/materials/shader_material.rb +108 -0
- data/lib/mittsu/math.rb +105 -0
- data/lib/mittsu/math/box2.rb +135 -0
- data/lib/mittsu/math/box3.rb +194 -0
- data/lib/mittsu/math/color.rb +252 -0
- data/lib/mittsu/math/color_keywords.rb +151 -0
- data/lib/mittsu/math/euler.rb +182 -0
- data/lib/mittsu/math/frustum.rb +106 -0
- data/lib/mittsu/math/line3.rb +76 -0
- data/lib/mittsu/math/matrix3.rb +163 -0
- data/lib/mittsu/math/matrix4.rb +581 -0
- data/lib/mittsu/math/plane.rb +128 -0
- data/lib/mittsu/math/quaternion.rb +309 -0
- data/lib/mittsu/math/ray.rb +292 -0
- data/lib/mittsu/math/sphere.rb +91 -0
- data/lib/mittsu/math/spline.rb +128 -0
- data/lib/mittsu/math/triangle.rb +121 -0
- data/lib/mittsu/math/vector2.rb +238 -0
- data/lib/mittsu/math/vector3.rb +491 -0
- data/lib/mittsu/math/vector4.rb +414 -0
- data/lib/mittsu/objects.rb +3 -0
- data/lib/mittsu/objects/group.rb +8 -0
- data/lib/mittsu/objects/line.rb +143 -0
- data/lib/mittsu/objects/mesh.rb +243 -0
- data/lib/mittsu/renderers.rb +1 -0
- data/lib/mittsu/renderers/glfw_window.rb +216 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +38 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +402 -0
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +58 -0
- data/lib/mittsu/renderers/opengl/opengl_state.rb +207 -0
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +416 -0
- data/lib/mittsu/renderers/opengl_render_target.rb +87 -0
- data/lib/mittsu/renderers/opengl_renderer.rb +3376 -0
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +40 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +60 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +62 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +21 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +7 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +26 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +43 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +196 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +243 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +58 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +2 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +15 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +11 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +13 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +27 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +217 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +19 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +6 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +9 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +8 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +47 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +20 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +12 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +5 -0
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +17 -0
- data/lib/mittsu/renderers/shaders/shader_lib.rb +420 -0
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +107 -0
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +31 -0
- data/lib/mittsu/scenes.rb +1 -0
- data/lib/mittsu/scenes/scene.rb +27 -0
- data/lib/mittsu/textures.rb +5 -0
- data/lib/mittsu/textures/compressed_texture.rb +30 -0
- data/lib/mittsu/textures/cube_texture.rb +19 -0
- data/lib/mittsu/textures/data_texture.rb +17 -0
- data/lib/mittsu/textures/texture.rb +92 -0
- data/lib/mittsu/textures/video_texture.rb +17 -0
- data/lib/mittsu/version.rb +4 -0
- data/mittsu.gemspec +31 -0
- metadata +357 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
module Mittsu
|
2
|
+
module ImageUtils
|
3
|
+
def self.load_texture(url, mapping = Texture::DEFAULT_MAPPING)
|
4
|
+
loader = ImageLoader.new
|
5
|
+
|
6
|
+
Texture.new(nil, mapping).tap do |texture|
|
7
|
+
image = loader.load(url, flip: true)
|
8
|
+
texture.image = image
|
9
|
+
texture.needs_update = true
|
10
|
+
|
11
|
+
texture.source_file = url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.load_texture_cube(array, mapping = Texture::DEFAULT_MAPPING)
|
16
|
+
images = HashArray.new
|
17
|
+
|
18
|
+
loader = ImageLoader.new
|
19
|
+
CubeTexture.new(images, mapping).tap do |texture|
|
20
|
+
loaded = 0
|
21
|
+
|
22
|
+
array.length.times do |i|
|
23
|
+
texture.images[i] = loader.load(array[i])
|
24
|
+
loaded += 1
|
25
|
+
if loaded == 6
|
26
|
+
texture.needs_update = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_normal_map(image, depth)
|
33
|
+
# adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
|
34
|
+
|
35
|
+
# depth |= 1
|
36
|
+
#
|
37
|
+
# width = image.width
|
38
|
+
# height = image.height
|
39
|
+
|
40
|
+
# TODO: original version uses browser features ...
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.generate_data_texture(width, height, color)
|
44
|
+
size = width * height
|
45
|
+
data = Array.new(3 * size) # Uint8Array
|
46
|
+
|
47
|
+
r = (color.r * 255).floor
|
48
|
+
g = (color.g * 255).floor
|
49
|
+
b = (color.b * 255).floor
|
50
|
+
|
51
|
+
size.times do |i|
|
52
|
+
data[i * 3] = r
|
53
|
+
data[i * 3 + 1] = g
|
54
|
+
data[i * 3 + 2] = b
|
55
|
+
end
|
56
|
+
|
57
|
+
texture = DataTexture.new(data, width, height, RGBFormat)
|
58
|
+
texture.needs_update = true
|
59
|
+
|
60
|
+
texture
|
61
|
+
end
|
62
|
+
|
63
|
+
private_class_method def self.cross(a, b)
|
64
|
+
[
|
65
|
+
a[1] * b[2] - a[2] * b[1],
|
66
|
+
a[2] * b[0] - a[0] * b[2],
|
67
|
+
a[0] * b[1] - a[1] * b[0]
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
private_class_method def self.subtract(a, b)
|
72
|
+
[a[0] - b[0], a[1] - b[1], a[2] - b[2]]
|
73
|
+
end
|
74
|
+
|
75
|
+
private_class_method def self.normalize(a)
|
76
|
+
l = Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2])
|
77
|
+
[a[0] / l, a[1] / l, a[2] / l]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
require 'mittsu/lights/ambient_light'
|
3
|
+
require 'mittsu/lights/area_light'
|
4
|
+
require 'mittsu/lights/directional_light'
|
5
|
+
require 'mittsu/lights/hemisphere_light'
|
6
|
+
require 'mittsu/lights/point_light'
|
7
|
+
require 'mittsu/lights/spot_light'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class AreaLight < Light
|
5
|
+
attr_accessor :normal, :right, :intensity, :width, :height, :constant_attenuation, :linear_attenuation, :quadratic_attenuation
|
6
|
+
|
7
|
+
def initialize(color = nil, intensity = 1.0)
|
8
|
+
super(color)
|
9
|
+
@type = 'AreaLight'
|
10
|
+
|
11
|
+
@normal = Vector3.new(0.0, -1.0, 0.0)
|
12
|
+
@right = Vector3.new(1.0, 0.0, 0.0)
|
13
|
+
|
14
|
+
@intensity = intensity
|
15
|
+
|
16
|
+
@width = 1.0
|
17
|
+
@height = 1.0
|
18
|
+
|
19
|
+
@constant_attenuation = 1.5
|
20
|
+
@linear_attenuation = 0.5
|
21
|
+
@quadratic_attenuation = 0.1
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class DirectionalLight < Light
|
5
|
+
attr_accessor :target,
|
6
|
+
:cast_shadow,
|
7
|
+
:shadow_camera_near,
|
8
|
+
:shadow_camera_far,
|
9
|
+
:shadow_camera_left,
|
10
|
+
:shadow_camera_right,
|
11
|
+
:shadow_camera_top,
|
12
|
+
:shadow_camera_bottom,
|
13
|
+
:shadow_camera_visible,
|
14
|
+
:shadow_bias,
|
15
|
+
:shadow_darkness,
|
16
|
+
:shadow_map_width,
|
17
|
+
:shadow_map_height,
|
18
|
+
:shadow_cascade,
|
19
|
+
:shadow_cascade_offset,
|
20
|
+
:shadow_cascade_count,
|
21
|
+
:shadow_cascade_bias,
|
22
|
+
:shadow_cascade_width,
|
23
|
+
:shadow_cascade_height,
|
24
|
+
:shadow_cascade_near_z,
|
25
|
+
:shadow_cascade_far_z,
|
26
|
+
:shadow_cascade_array,
|
27
|
+
:shadow_map,
|
28
|
+
:shadow_map_size,
|
29
|
+
:shadow_camera,
|
30
|
+
:shadow_matrix
|
31
|
+
|
32
|
+
def initialize(color = nil, intensity = 1.0)
|
33
|
+
super(color)
|
34
|
+
|
35
|
+
@type = 'DirectionalLight'
|
36
|
+
|
37
|
+
@position.set(0.0, 1.0, 0.0)
|
38
|
+
@target = Object3D.new
|
39
|
+
|
40
|
+
@intensity = intensity
|
41
|
+
|
42
|
+
@cast_shadow = false
|
43
|
+
@only_shadow = false
|
44
|
+
|
45
|
+
#
|
46
|
+
|
47
|
+
@shadow_camera_near = 50.0
|
48
|
+
@shadow_camera_far = 5000.0
|
49
|
+
|
50
|
+
@shadow_camera_left = -500.0
|
51
|
+
@shadow_camera_right = 500.0
|
52
|
+
@shadow_camera_top = 500.0
|
53
|
+
@shadow_camera_bottom = -500.0
|
54
|
+
|
55
|
+
@shadow_camera_visible = false
|
56
|
+
|
57
|
+
@shadow_bias = 0
|
58
|
+
@shadow_darkness = 0.5
|
59
|
+
|
60
|
+
@shadow_map_width = 512
|
61
|
+
@shadow_map_height = 512
|
62
|
+
|
63
|
+
#
|
64
|
+
|
65
|
+
@shadow_cascade = false
|
66
|
+
|
67
|
+
@shadow_cascade_offset = Vector3.new(0.0, 0.0, -1000.0)
|
68
|
+
@shadow_cascade_count = 2
|
69
|
+
|
70
|
+
@shadow_cascade_bias = [0, 0, 0]
|
71
|
+
@shadow_cascade_width = [512, 512, 512]
|
72
|
+
@shadow_cascade_height = [512, 512, 512]
|
73
|
+
|
74
|
+
@shadow_cascade_near_z = [-1.000, 0.990, 0.998]
|
75
|
+
@shadow_cascade_far_z = [0.990, 0.998, 1.000]
|
76
|
+
|
77
|
+
@shadow_cascade_array = []
|
78
|
+
|
79
|
+
#
|
80
|
+
|
81
|
+
@shadow_map = nil
|
82
|
+
@shadow_map_size = nil
|
83
|
+
@shadow_camera = nil
|
84
|
+
@shadow_matrix = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def clone
|
88
|
+
light = DirectionalLight.new
|
89
|
+
super(light)
|
90
|
+
|
91
|
+
light.target = @target.clone
|
92
|
+
|
93
|
+
light.intensity = @intensity
|
94
|
+
|
95
|
+
light.cast_shadow = @cast_shadow
|
96
|
+
light.only_shadow = @only_shadow
|
97
|
+
|
98
|
+
#
|
99
|
+
|
100
|
+
light.shadow_camera_near = @shadow_camera_near
|
101
|
+
light.shadow_camera_far = @shadow_camera_far
|
102
|
+
|
103
|
+
light.shadow_camera_left = @shadow_camera_left
|
104
|
+
light.shadow_camera_right = @shadow_camera_right
|
105
|
+
light.shadow_camera_top = @shadow_camera_top
|
106
|
+
light.shadow_camera_bottom = @shadow_camera_bottom
|
107
|
+
|
108
|
+
light.shadow_camera_visible = @shadow_camera_visible
|
109
|
+
|
110
|
+
light.shadow_bias = @shadow_bias
|
111
|
+
light.shadow_darkness = @shadow_darkness
|
112
|
+
|
113
|
+
light.shadow_map_width = @shadow_map_width
|
114
|
+
light.shadow_map_height = @shadow_map_height
|
115
|
+
|
116
|
+
#
|
117
|
+
|
118
|
+
light.shadow_cascade = @shadow_cascade
|
119
|
+
|
120
|
+
light.shadow_cascade_offset.copy(@shadow_cascade_offset)
|
121
|
+
light.shadow_cascade_count = @shadow_cascade_count
|
122
|
+
|
123
|
+
light.shadow_cascade_bias = @shadow_cascade_bias.dup
|
124
|
+
light.shadow_cascade_width = @shadow_cascade_width.dup
|
125
|
+
light.shadow_cascade_height = @shadow_cascade_height.dup
|
126
|
+
|
127
|
+
light.shadow_cascade_near_z = @shadow_cascade_near_z.dup
|
128
|
+
light.shadow_cascade_far_z = @shadow_cascade_far_z.dup
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
|
5
|
+
class HemisphereLight < Light
|
6
|
+
attr_accessor :ground_color, :intensity
|
7
|
+
|
8
|
+
def initialize(sky_color = nil, ground_color = nil, intensity = 1.0)
|
9
|
+
super(sky_color)
|
10
|
+
|
11
|
+
@type = 'HemisphereLight'
|
12
|
+
|
13
|
+
@position.set(0.0, 100.0, 0.0)
|
14
|
+
|
15
|
+
@ground_color = Color.new(ground_color)
|
16
|
+
@intensity = intensity
|
17
|
+
end
|
18
|
+
|
19
|
+
def clone
|
20
|
+
light = HemisphereLight.new
|
21
|
+
super(light)
|
22
|
+
|
23
|
+
light.ground_color.copy(@ground_color)
|
24
|
+
light.intensity = @intensity
|
25
|
+
|
26
|
+
light
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'mittsu/core/object_3d'
|
2
|
+
require 'mittsu/math/color'
|
3
|
+
|
4
|
+
module Mittsu
|
5
|
+
class Light < Object3D
|
6
|
+
attr_accessor :color, :only_shadow, :intensity, :distance
|
7
|
+
|
8
|
+
def initialize(color = nil)
|
9
|
+
super()
|
10
|
+
@type = 'Light'
|
11
|
+
@color = Color.new(color)
|
12
|
+
end
|
13
|
+
|
14
|
+
def clone(light = Light.new)
|
15
|
+
super(light)
|
16
|
+
|
17
|
+
light.color.copy(@color)
|
18
|
+
light
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class PointLight < Light
|
5
|
+
attr_accessor :decay
|
6
|
+
|
7
|
+
def initialize(color = nil, intensity = 1.0, distance = 0.0, decay = 1.0)
|
8
|
+
super(color)
|
9
|
+
|
10
|
+
@type = 'PointLight'
|
11
|
+
|
12
|
+
@intensity = intensity
|
13
|
+
@distance = distance
|
14
|
+
@decay = decay # for physically correct light, should be 2
|
15
|
+
end
|
16
|
+
|
17
|
+
def clone
|
18
|
+
light = PointLight.new
|
19
|
+
super(light)
|
20
|
+
|
21
|
+
light.intensity = @intensity
|
22
|
+
light.distance = @distance
|
23
|
+
light.decay = @decay
|
24
|
+
light
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'mittsu/lights/light'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class SpotLight < Light
|
5
|
+
attr_accessor :target,
|
6
|
+
:angle,
|
7
|
+
:exponent,
|
8
|
+
:decay,
|
9
|
+
:cast_shadow,
|
10
|
+
:shadow_camera_near,
|
11
|
+
:shadow_camera_far,
|
12
|
+
:shadow_camera_fov,
|
13
|
+
:shadow_camera_visible,
|
14
|
+
:shadow_bias,
|
15
|
+
:shadow_darkness,
|
16
|
+
:shadow_map_width,
|
17
|
+
:shadow_map_height,
|
18
|
+
:shadow_map,
|
19
|
+
:shadow_map_size,
|
20
|
+
:shadow_camera,
|
21
|
+
:shadow_matrix
|
22
|
+
|
23
|
+
def initialize(color = nil, intensity = 1.0, distance = 0.0, angle = (Math::PI / 3.0), exponent = 10.0, decay = 1.0)
|
24
|
+
super(color)
|
25
|
+
|
26
|
+
@type = 'SpotLight'
|
27
|
+
|
28
|
+
@position.set( 0, 1, 0 )
|
29
|
+
@target = Object3D.new
|
30
|
+
|
31
|
+
@intensity = intensity
|
32
|
+
@distance = distance
|
33
|
+
@angle = angle
|
34
|
+
@exponent = exponent
|
35
|
+
@decay = decay # for physically correct lights, should be 2.
|
36
|
+
|
37
|
+
@cast_shadow = false
|
38
|
+
@only_shadow = false
|
39
|
+
|
40
|
+
#
|
41
|
+
|
42
|
+
@shadow_camera_near = 50.0
|
43
|
+
@shadow_camera_far = 5000.0
|
44
|
+
@shadow_camera_fov = 50.0
|
45
|
+
|
46
|
+
@shadow_camera_visible = false
|
47
|
+
|
48
|
+
@shadow_bias = 0
|
49
|
+
@shadow_darkness = 0.5
|
50
|
+
|
51
|
+
@shadow_map_width = 512
|
52
|
+
@shadow_map_height = 512
|
53
|
+
|
54
|
+
#
|
55
|
+
|
56
|
+
@shadow_map = nil
|
57
|
+
@shadow_map_size = nil
|
58
|
+
@shadow_camera = nil
|
59
|
+
@shadow_matrix = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def virtual?
|
63
|
+
@is_virtual
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_virtual=(value)
|
67
|
+
@is_virtual = value
|
68
|
+
end
|
69
|
+
|
70
|
+
def clone
|
71
|
+
|
72
|
+
light = SpotLight.new
|
73
|
+
|
74
|
+
super(light)
|
75
|
+
|
76
|
+
light.target = @target.clone
|
77
|
+
|
78
|
+
light.intensity = @intensity
|
79
|
+
light.distance = @distance
|
80
|
+
light.angle = @angle
|
81
|
+
light.exponent = @exponent
|
82
|
+
light.decay = @decay
|
83
|
+
|
84
|
+
light.cast_shadow = @cast_shadow
|
85
|
+
light.only_shadow = @only_shadow
|
86
|
+
|
87
|
+
#
|
88
|
+
|
89
|
+
light.shadow_camera_near = @shadow_camera_near
|
90
|
+
light.shadow_camera_far = @shadow_camera_far
|
91
|
+
light.shadow_camera_fov = @shadow_camera_fov
|
92
|
+
|
93
|
+
light.shadow_camera_visible = @shadow_camera_visible
|
94
|
+
|
95
|
+
light.shadow_bias = @shadow_bias
|
96
|
+
light.shadow_darkness = @shadow_darkness
|
97
|
+
|
98
|
+
light.shadow_map_width = @shadow_map_width
|
99
|
+
light.shadow_map_height = @shadow_map_height
|
100
|
+
|
101
|
+
return light
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|