mittsu 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-workflow.yml +5 -44
- data/Gemfile +0 -4
- data/README.md +16 -130
- data/bin/console +0 -4
- data/lib/mittsu/cameras/cube_camera.rb +1 -1
- data/lib/mittsu/core/geometry.rb +3 -3
- data/lib/mittsu/core/object_3d.rb +29 -47
- data/lib/mittsu/core/uniform.rb +23 -0
- data/lib/mittsu/core.rb +1 -0
- data/lib/mittsu/loaders/obj_loader.rb +11 -5
- data/lib/mittsu/loaders/stl_loader.rb +186 -0
- data/lib/mittsu/loaders.rb +1 -0
- data/lib/mittsu/math/box3.rb +4 -4
- data/lib/mittsu/objects/line.rb +1 -3
- data/lib/mittsu/objects/mesh.rb +9 -12
- data/lib/mittsu/objects/point_cloud.rb +3 -3
- data/lib/mittsu/textures/render_target.rb +93 -0
- data/lib/mittsu/textures/render_target_cube.rb +8 -0
- data/lib/mittsu/textures/texture.rb +1 -1
- data/lib/mittsu/textures.rb +2 -0
- data/lib/mittsu/version.rb +1 -1
- data/lib/mittsu.rb +0 -1
- data/mittsu.gemspec +8 -12
- metadata +33 -204
- data/install-glfw.ps1 +0 -13
- data/lib/mittsu/renderers/generic_lib.rb +0 -122
- data/lib/mittsu/renderers/glfw_lib.rb +0 -62
- data/lib/mittsu/renderers/glfw_window.rb +0 -233
- data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
- data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
- data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
- data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
- data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
- data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
- data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
- data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
- data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
- data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
- data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
- data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
- data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
- data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
- data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
- data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
- data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
- data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
- data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
- data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
- data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
- data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
- data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
- data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
- data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
- data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
- data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
- data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
- data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
- data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
- data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
- data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
- data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
- data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
- data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
- data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
- data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
- data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
- data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
- data/lib/mittsu/renderers.rb +0 -1
@@ -1,346 +0,0 @@
|
|
1
|
-
require 'mittsu/renderers/opengl/opengl_geometry_like'
|
2
|
-
|
3
|
-
module Mittsu
|
4
|
-
class Geometry
|
5
|
-
include OpenGLGeometryLike
|
6
|
-
|
7
|
-
attr_accessor :groups, :initted
|
8
|
-
|
9
|
-
def init_geometry_groups(object)
|
10
|
-
material = object.material
|
11
|
-
add_buffers = false
|
12
|
-
|
13
|
-
if @groups.nil? || @groups_need_update
|
14
|
-
@renderer.remove_opengl_object(object)
|
15
|
-
|
16
|
-
@groups = make_groups(material.is_a?(MeshFaceMaterial))
|
17
|
-
|
18
|
-
@groups_need_update = false
|
19
|
-
end
|
20
|
-
|
21
|
-
# create separate VBOs per geometry chunk
|
22
|
-
|
23
|
-
@groups.each do |geometry_group|
|
24
|
-
# initialize VBO on the first access
|
25
|
-
if geometry_group.vertex_buffer.nil?
|
26
|
-
geometry_group.create_mesh_buffers
|
27
|
-
geometry_group.init_mesh_buffers(object)
|
28
|
-
|
29
|
-
@vertices_need_update = true
|
30
|
-
@morph_targets_need_update = true
|
31
|
-
@elements_need_update = true
|
32
|
-
@uvs_need_update = true
|
33
|
-
@normals_need_update = true
|
34
|
-
@tangents_need_update = true
|
35
|
-
@colors_need_update = true
|
36
|
-
|
37
|
-
add_buffers = true
|
38
|
-
else
|
39
|
-
add_buffers = false
|
40
|
-
end
|
41
|
-
|
42
|
-
if add_buffers || !object.active?
|
43
|
-
@renderer.add_opengl_object(geometry_group, object)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
object.active = true
|
48
|
-
end
|
49
|
-
|
50
|
-
def init_line_buffers(object)
|
51
|
-
nvertices = @vertices.length
|
52
|
-
|
53
|
-
@vertex_array = Array.new(nvertices * 3, 0.0) # Float32Array
|
54
|
-
@color_array = Array.new(nvertices * 3, 0.0) # Float32Array
|
55
|
-
@line_distance_array = Array.new(nvertices, 0.0) # Float32Array
|
56
|
-
|
57
|
-
@line_count = nvertices
|
58
|
-
|
59
|
-
init_custom_attributes(object)
|
60
|
-
end
|
61
|
-
|
62
|
-
def init_particle_buffers(object)
|
63
|
-
nvertices = @vertices.length
|
64
|
-
|
65
|
-
@vertex_array = Array.new(nvertices * 3, 0.0) # Float32Array
|
66
|
-
@color_array = Array.new(nvertices * 3, 0.0) # Float32Array
|
67
|
-
|
68
|
-
@particle_count = nvertices
|
69
|
-
|
70
|
-
init_custom_attributes(object)
|
71
|
-
end
|
72
|
-
|
73
|
-
def create_line_buffers
|
74
|
-
@vertex_array_object = glCreateVertexArray
|
75
|
-
|
76
|
-
@vertex_buffer = glCreateBuffer
|
77
|
-
@color_buffer = glCreateBuffer
|
78
|
-
@line_distance_buffer = glCreateBuffer
|
79
|
-
|
80
|
-
@renderer.info[:memory][:geometries] += 1
|
81
|
-
end
|
82
|
-
|
83
|
-
def create_particle_buffers
|
84
|
-
@vertex_array_object = glCreateVertexArray
|
85
|
-
|
86
|
-
@vertex_buffer = glCreateBuffer
|
87
|
-
@color_buffer = glCreateBuffer
|
88
|
-
|
89
|
-
@renderer.info[:memory][:geometries] += 1
|
90
|
-
end
|
91
|
-
|
92
|
-
def set_line_buffers(hint)
|
93
|
-
if @vertices_need_update
|
94
|
-
@vertices.each_with_index do |vertex, v|
|
95
|
-
offset = v * 3
|
96
|
-
|
97
|
-
@vertex_array[offset] = vertex.x
|
98
|
-
@vertex_array[offset + 1] = vertex.y
|
99
|
-
@vertex_array[offset + 2] = vertex.z
|
100
|
-
end
|
101
|
-
|
102
|
-
glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
|
103
|
-
glBufferData_easy(GL_ARRAY_BUFFER, @vertex_array, hint)
|
104
|
-
end
|
105
|
-
|
106
|
-
if @colors_need_update
|
107
|
-
@colors.each_with_index do |color, c|
|
108
|
-
offset = c * 3
|
109
|
-
|
110
|
-
@color_array[offset] = color.r
|
111
|
-
@color_array[offset + 1] = color.g
|
112
|
-
@color_array[offset + 2] = color.b
|
113
|
-
end
|
114
|
-
|
115
|
-
glBindBuffer(GL_ARRAY_BUFFER, @color_buffer)
|
116
|
-
glBufferData_easy(GL_ARRAY_BUFFER, @color_array, hint)
|
117
|
-
end
|
118
|
-
|
119
|
-
if @line_distances_need_update
|
120
|
-
@line_distances.each_with_index do |l, d|
|
121
|
-
@line_distance_array[d] = l
|
122
|
-
end
|
123
|
-
|
124
|
-
glBindBuffer(GL_ARRAY_BUFFER, @line_distance_buffer)
|
125
|
-
glBufferData_easy(GL_ARRAY_BUFFER, @line_distance_array, hint)
|
126
|
-
end
|
127
|
-
|
128
|
-
if @custom_attributes
|
129
|
-
@custom_attributes.each do |custom_attribute|
|
130
|
-
offset = 0
|
131
|
-
|
132
|
-
values = custom_attribute.value
|
133
|
-
|
134
|
-
case custom_attribute.size
|
135
|
-
when 1
|
136
|
-
value.each_with_index do |value, ca|
|
137
|
-
custom_attribute.array[ca] = value
|
138
|
-
end
|
139
|
-
when 2
|
140
|
-
values.each do |value|
|
141
|
-
custom_attribute.array[offset ] = value.x
|
142
|
-
custom_attribute.array[offset + 1] = value.y
|
143
|
-
|
144
|
-
offset += 2
|
145
|
-
end
|
146
|
-
when 3
|
147
|
-
if custom_attribute.type === :c
|
148
|
-
values.each do |value|
|
149
|
-
custom_attribute.array[offset ] = value.r
|
150
|
-
custom_attribute.array[offset + 1] = value.g
|
151
|
-
custom_attribute.array[offset + 2] = value.b
|
152
|
-
|
153
|
-
offset += 3
|
154
|
-
end
|
155
|
-
else
|
156
|
-
values.each do |value|
|
157
|
-
custom_attribute.array[offset ] = value.x
|
158
|
-
custom_attribute.array[offset + 1] = value.y
|
159
|
-
custom_attribute.array[offset + 2] = value.z
|
160
|
-
|
161
|
-
offset += 3
|
162
|
-
end
|
163
|
-
end
|
164
|
-
when 4
|
165
|
-
values.each do |value|
|
166
|
-
custom_attribute.array[offset ] = value.x
|
167
|
-
custom_attribute.array[offset + 1] = value.y
|
168
|
-
custom_attribute.array[offset + 2] = value.z
|
169
|
-
custom_attribute.array[offset + 3] = value.w
|
170
|
-
|
171
|
-
offset += 4
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
glBindBuffer(GL_ARRAY_BUFFER, custom_attribute.buffer)
|
176
|
-
glBufferData_easy(GL_ARRAY_BUFFER, custom_attribute.array, hint)
|
177
|
-
|
178
|
-
custom_attribute.needs_update = false
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
def set_particle_buffers(hint)
|
184
|
-
if @vertices_need_update
|
185
|
-
@vertices.each_with_index do |vertex, v|
|
186
|
-
offset = v * 3
|
187
|
-
|
188
|
-
@vertex_array[offset] = vertex.x
|
189
|
-
@vertex_array[offset + 1] = vertex.y
|
190
|
-
@vertex_array[offset + 2] = vertex.z
|
191
|
-
end
|
192
|
-
|
193
|
-
|
194
|
-
glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
|
195
|
-
glBufferData_easy(GL_ARRAY_BUFFER, @vertex_array, hint)
|
196
|
-
end
|
197
|
-
|
198
|
-
if @colors_need_update
|
199
|
-
@colors.each_with_index do |color, c|
|
200
|
-
offset = c * 3;
|
201
|
-
|
202
|
-
@color_array[offset] = color.r
|
203
|
-
@color_array[offset + 1] = color.g
|
204
|
-
@color_array[offset + 2] = color.b
|
205
|
-
end
|
206
|
-
|
207
|
-
glBindBuffer(GL_ARRAY_BUFFER, @color_buffer)
|
208
|
-
glBufferData_easy(GL_ARRAY_BUFFER, @color_array, hint)
|
209
|
-
end
|
210
|
-
|
211
|
-
if @custom_attribute
|
212
|
-
@custom_attributes.each do |custom_attribute|
|
213
|
-
if custom_attribute.needs_update? && (custom_attribute.bount_to.nil? || custom_attribute.bount_to == 'vertices')
|
214
|
-
offset = 0
|
215
|
-
|
216
|
-
if custom_attribute.size == 1
|
217
|
-
custom_attribute.value.each_with_index do |value, ca|
|
218
|
-
custom_attribute.array[ca] = value
|
219
|
-
end
|
220
|
-
elsif custom_attribute.size == 2
|
221
|
-
custom_attribute.value.each do |value|
|
222
|
-
custom_attribute.array[offset] = value.x
|
223
|
-
custom_attribute.array[offset + 1] = value.y
|
224
|
-
|
225
|
-
offset += 2
|
226
|
-
end
|
227
|
-
elsif custom_attribute.size == 3
|
228
|
-
if custom_attribute.type == :c
|
229
|
-
custom_attribute.value.each do |value|
|
230
|
-
custom_attribute.array[offset] = value.r
|
231
|
-
custom_attribute.array[offset + 1] = value.g
|
232
|
-
custom_attribute.array[offset + 2] = value.b
|
233
|
-
|
234
|
-
offset += 3
|
235
|
-
end
|
236
|
-
else
|
237
|
-
custom_attribute.value.each do |value|
|
238
|
-
custom_attribute.array[offset] = value.x
|
239
|
-
custom_attribute.array[offset + 1] = value.y
|
240
|
-
custom_attribute.array[offset + 2] = value.z
|
241
|
-
|
242
|
-
offset += 3
|
243
|
-
end
|
244
|
-
end
|
245
|
-
elsif custom_attribute.size == 4
|
246
|
-
custom_attribute.value.each do |value|
|
247
|
-
custom_attribute.array[offset] = value.x
|
248
|
-
custom_attribute.array[offset + 1] = value.y
|
249
|
-
custom_attribute.array[offset + 2] = value.z
|
250
|
-
custom_attribute.array[offset + 3] = value.w
|
251
|
-
|
252
|
-
offset += 3
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
glBindBuffer(GL_ARRAY_BUFFER, customAttribute.buffer)
|
258
|
-
glBufferData(GL_ARRAY_BUFFER, customAttribute.array, hint)
|
259
|
-
|
260
|
-
custom_attribute.needs_update = false
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
private
|
266
|
-
|
267
|
-
def make_groups(uses_face_material = false)
|
268
|
-
max_vertices_in_group = 65535 # TODO: OES_element_index_uint ???
|
269
|
-
|
270
|
-
hash_map = {}
|
271
|
-
|
272
|
-
num_morph_targets = @morph_targets.length
|
273
|
-
num_morph_normals = @morph_normals.length
|
274
|
-
|
275
|
-
groups = {}
|
276
|
-
groups_list = []
|
277
|
-
|
278
|
-
@faces.each_with_index do |face, f|
|
279
|
-
material_index = uses_face_material ? face.material_index : 0
|
280
|
-
|
281
|
-
if !hash_map.include? material_index
|
282
|
-
hash_map[material_index] = { hash: material_index, counter: 0 }
|
283
|
-
end
|
284
|
-
|
285
|
-
group_hash = "#{hash_map[material_index][:hash]}_#{hash_map[material_index][:counter]}"
|
286
|
-
|
287
|
-
if !groups.include? group_hash
|
288
|
-
group = OpenGLGeometryGroup.new(material_index, num_morph_targets, num_morph_normals, @renderer)
|
289
|
-
|
290
|
-
groups[group_hash] = group
|
291
|
-
groups_list << group
|
292
|
-
end
|
293
|
-
|
294
|
-
if groups[group_hash].num_vertices + 3 > max_vertices_in_group
|
295
|
-
hash_map[material_index][:counter] += 1
|
296
|
-
group_hash = "#{hash_map[material_index][:hash]}_#{hash_map[material_index][:counter]}"
|
297
|
-
|
298
|
-
if !groups.include? group_hash
|
299
|
-
group = OpenGLGeometryGroup.new(material_index, num_morph_targets, num_morph_normals, @renderer)
|
300
|
-
|
301
|
-
groups[group_hash] = group
|
302
|
-
groups_list << group
|
303
|
-
end
|
304
|
-
end
|
305
|
-
groups[group_hash].faces3 << f
|
306
|
-
groups[group_hash].num_vertices += 3
|
307
|
-
end
|
308
|
-
groups_list
|
309
|
-
end
|
310
|
-
|
311
|
-
def init_custom_attributes(object)
|
312
|
-
material = object.material
|
313
|
-
|
314
|
-
nvertices = @vertices.length
|
315
|
-
|
316
|
-
if material.attributes
|
317
|
-
@custom_attributes_list ||= []
|
318
|
-
|
319
|
-
material.attributes.each do |(name, attribute)|
|
320
|
-
if !attribute[:_opengl_initialized] || attribute.create_unique_buffers
|
321
|
-
attribute[:_opengl_initialized] = true
|
322
|
-
|
323
|
-
size = case attribute.type
|
324
|
-
when :v2 then 2
|
325
|
-
when :v3 then 3
|
326
|
-
when :v4 then 4
|
327
|
-
when :c then 3
|
328
|
-
else 1
|
329
|
-
end
|
330
|
-
|
331
|
-
attribute.size = size
|
332
|
-
|
333
|
-
attribute.array = Array.new(nvertices * size) # Float32Array
|
334
|
-
|
335
|
-
attribute.buffer = glCreateBuffer
|
336
|
-
attribute.buffer.belongs_to_attribute = name
|
337
|
-
|
338
|
-
attribute.needs_update = true
|
339
|
-
end
|
340
|
-
|
341
|
-
@custom_attributes_list << attribute
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class Object3D
|
3
|
-
attr_accessor :morph_target_influences, :renderer, :initted
|
4
|
-
attr_reader :model_view_matrix
|
5
|
-
attr_writer :active
|
6
|
-
|
7
|
-
def active?
|
8
|
-
@active
|
9
|
-
end
|
10
|
-
|
11
|
-
def init
|
12
|
-
if !@initted
|
13
|
-
puts " --- INIT #{self.name}" if DEBUG
|
14
|
-
|
15
|
-
@initted = true
|
16
|
-
@model_view_matrix = Matrix4.new
|
17
|
-
@normal_matrix = Matrix3.new
|
18
|
-
|
19
|
-
add_event_listener(:removed, @renderer.method(:on_object_removed))
|
20
|
-
end
|
21
|
-
|
22
|
-
if geometry.nil?
|
23
|
-
# ImmediateRenderObject
|
24
|
-
else
|
25
|
-
if !geometry.initted
|
26
|
-
geometry.initted = true
|
27
|
-
geometry.add_event_listener(:dispose, @renderer.method(:on_geometry_dispose))
|
28
|
-
if geometry.is_a?(BufferGeometry)
|
29
|
-
@renderer.info[:memory][:geometries] += 1
|
30
|
-
else
|
31
|
-
init_geometry
|
32
|
-
end
|
33
|
-
# TODO: when PointCloud exists
|
34
|
-
# when PointCloud
|
35
|
-
# if geometry[:_opengl_vertex_buffer].nil?
|
36
|
-
# create_particle_buffers(geometry)
|
37
|
-
# init_particle_buffers(geometry, object)
|
38
|
-
#
|
39
|
-
# geometry.vertices_need_update = true
|
40
|
-
# geometry.colors_need_update = true
|
41
|
-
# end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
if !@active
|
46
|
-
@active = true
|
47
|
-
|
48
|
-
add_opengl_object
|
49
|
-
# TODO: when ImmediateRenderObject exists
|
50
|
-
# if object.is_a? ImmediateRenderObject || object.immediate_render_callback
|
51
|
-
# add_buffer_immediate(@renderer.instance_variable_get(:@_opengl_objects_immediate), self)
|
52
|
-
# end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def project(renderer)
|
57
|
-
puts " --- PROJECT #{self.name}" if DEBUG
|
58
|
-
@renderer = renderer
|
59
|
-
return unless visible
|
60
|
-
init
|
61
|
-
|
62
|
-
# TODO!!! FIXME!!!
|
63
|
-
opengl_objects = @renderer.instance_variable_get(:@_opengl_objects)[id]
|
64
|
-
|
65
|
-
if opengl_objects && (!frustum_culled || @renderer.object_in_frustum?(self))
|
66
|
-
opengl_objects.each do |opengl_object|
|
67
|
-
# TODO!!! FIXME!!!
|
68
|
-
@renderer.send(:unroll_buffer_material, opengl_object)
|
69
|
-
|
70
|
-
opengl_object.render = true
|
71
|
-
if @renderer.sort_objects?
|
72
|
-
@_vector3 ||= Vector3.new
|
73
|
-
|
74
|
-
@_vector3.set_from_matrix_position(matrix_world)
|
75
|
-
@_vector3.apply_projection(@renderer.proj_screen_matrix)
|
76
|
-
|
77
|
-
opengl_object[:z] = @_vector3.z
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
project_children
|
83
|
-
end
|
84
|
-
|
85
|
-
def setup_matrices(camera)
|
86
|
-
@model_view_matrix.multiply_matrices(camera.matrix_world_inverse, matrix_world)
|
87
|
-
@normal_matrix.normal_matrix(@model_view_matrix)
|
88
|
-
@model_view_matrix
|
89
|
-
end
|
90
|
-
|
91
|
-
def load_uniforms_matrices(uniforms)
|
92
|
-
glUniformMatrix4fv(uniforms['modelViewMatrix'],
|
93
|
-
1, GL_FALSE,
|
94
|
-
array_to_ptr_easy(@model_view_matrix.elements))
|
95
|
-
|
96
|
-
if uniforms['normalMatrix']
|
97
|
-
glUniformMatrix3fv(uniforms['normalMatrix'],
|
98
|
-
1, GL_FALSE,
|
99
|
-
array_to_ptr_easy(@normal_matrix.elements))
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def buffer_material(geometry_group)
|
104
|
-
if material.is_a?(MeshFaceMaterial)
|
105
|
-
material.materials[geometry_group.material_index]
|
106
|
-
else
|
107
|
-
material
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def init_geometry
|
112
|
-
# NOOP
|
113
|
-
end
|
114
|
-
|
115
|
-
def add_opengl_object
|
116
|
-
# NOOP
|
117
|
-
end
|
118
|
-
|
119
|
-
def deinit
|
120
|
-
@initted = nil
|
121
|
-
@model_view_matrix = nil
|
122
|
-
@normal_matrix = nil
|
123
|
-
@active = nil
|
124
|
-
end
|
125
|
-
|
126
|
-
protected
|
127
|
-
|
128
|
-
def project_children
|
129
|
-
children.each do |child|
|
130
|
-
child.project(@renderer)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class AmbientLight
|
3
|
-
TYPE = :ambient
|
4
|
-
|
5
|
-
class Cache < Struct.new(:length, :count, :value)
|
6
|
-
def initialize
|
7
|
-
super(0, 0, [0.0, 0.0, 0.0])
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
self.length = 0
|
12
|
-
self.value[0] = 0.0
|
13
|
-
self.value[1] = 0.0
|
14
|
-
self.value[2] = 0.0
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def setup_specific(_)
|
19
|
-
@cache.value[0] += color.r
|
20
|
-
@cache.value[1] += color.g
|
21
|
-
@cache.value[2] += color.b
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.null_remaining_lights(_); end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class DirectionalLight
|
3
|
-
TYPE = :directional
|
4
|
-
|
5
|
-
class Cache < Struct.new(:length, :count, :colors, :positions)
|
6
|
-
def initialize
|
7
|
-
super(0, 0, [], [])
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
self.length = 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup_specific(index)
|
16
|
-
offset = index * 3
|
17
|
-
|
18
|
-
@_direction.set_from_matrix_position(matrix_world)
|
19
|
-
@_vector3.set_from_matrix_position(target.matrix_world)
|
20
|
-
@_direction.sub(@_vector3)
|
21
|
-
@_direction.normalize
|
22
|
-
|
23
|
-
positions = @cache.positions
|
24
|
-
positions[offset] = @_direction.x
|
25
|
-
positions[offset + 1] = @_direction.y
|
26
|
-
positions[offset + 2] = @_direction.z
|
27
|
-
|
28
|
-
OpenGLHelper.set_color_linear(@cache.colors, offset, color, intensity)
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_sym
|
32
|
-
:directional
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class HemisphereLight
|
3
|
-
TYPE = :hemi
|
4
|
-
|
5
|
-
class Cache < Struct.new(:length, :count, :sky_colors, :ground_colors, :positions)
|
6
|
-
def initialize
|
7
|
-
super(0, 0, [], [], [])
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
self.length = 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup_specific(index)
|
16
|
-
offset = index * 3
|
17
|
-
|
18
|
-
@_direction.set_from_matrix_position(matrix_world)
|
19
|
-
@_direction.normalize
|
20
|
-
|
21
|
-
positions = @cache.positions
|
22
|
-
positions[offset] = @_direction.x
|
23
|
-
positions[offset + 1] = @_direction.y
|
24
|
-
positions[offset + 2] = @_direction.z
|
25
|
-
|
26
|
-
OpenGLHelper.set_color_linear(@cache.sky_colors, offset, color, intensity)
|
27
|
-
OpenGLHelper.set_color_linear(@cache.ground_colors, offset, ground_color, intensity)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.null_remaining_lights(cache)
|
31
|
-
super(cache, cache.ground_colors)
|
32
|
-
super(cache, cache.sky_colors)
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_sym
|
36
|
-
:hemi
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class Light
|
3
|
-
attr_accessor :camera_helper
|
4
|
-
|
5
|
-
# def initialize(light, renderer)
|
6
|
-
# super
|
7
|
-
# @light = light
|
8
|
-
# @light_renderer = renderer.light_renderer
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# @_direction = Vector3.new
|
12
|
-
# @_vector3 = Vector3.new
|
13
|
-
# end
|
14
|
-
|
15
|
-
def type
|
16
|
-
self.class::TYPE
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup(light_renderer)
|
20
|
-
@light_renderer = light_renderer
|
21
|
-
@cache ||= @light_renderer.cache[type]
|
22
|
-
@cache.count += 1
|
23
|
-
|
24
|
-
return unless visible
|
25
|
-
|
26
|
-
@_direction ||= Vector3.new
|
27
|
-
@_vector3 ||= Vector3.new
|
28
|
-
|
29
|
-
setup_specific(@cache.length)
|
30
|
-
|
31
|
-
@cache.length += 1
|
32
|
-
end
|
33
|
-
|
34
|
-
def project(renderer)
|
35
|
-
@renderer = renderer
|
36
|
-
return unless visible
|
37
|
-
init
|
38
|
-
# TODO!!! FIXME!!!
|
39
|
-
@renderer.instance_variable_get(:@lights) << self
|
40
|
-
project_children
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.null_remaining_lights(cache, colors = nil)
|
44
|
-
colors ||= cache.colors
|
45
|
-
count = [colors.length, cache.count * 3].max
|
46
|
-
(cache.length * 3).upto(count - 1).each { |i|
|
47
|
-
colors[i] = 0.0
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_sym
|
52
|
-
:other
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Mittsu
|
2
|
-
class PointLight
|
3
|
-
TYPE = :point
|
4
|
-
|
5
|
-
class Cache < Struct.new(:length, :count, :colors, :distances, :positions, :decays)
|
6
|
-
def initialize
|
7
|
-
super(0, 0, [], [], [], [])
|
8
|
-
end
|
9
|
-
|
10
|
-
def reset
|
11
|
-
self.length = 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup_specific(index)
|
16
|
-
offset = index * 3;
|
17
|
-
|
18
|
-
OpenGLHelper.set_color_linear(@cache.colors, offset, color, intensity)
|
19
|
-
|
20
|
-
@_vector3.set_from_matrix_position(matrix_world)
|
21
|
-
|
22
|
-
positions = @cache.positions
|
23
|
-
positions[offset] = @_vector3.x
|
24
|
-
positions[offset + 1] = @_vector3.y
|
25
|
-
positions[offset + 2] = @_vector3.z
|
26
|
-
|
27
|
-
# distance is 0 if decay is 0, because there is no attenuation at all.
|
28
|
-
@cache.distances[index] = distance
|
29
|
-
@cache.decays[index] = distance.zero? ? 0.0 : decay
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_sym
|
33
|
-
:point
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|