mittsu-opengl 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +18 -0
  3. data/.github/workflows/build-workflow.yml +67 -0
  4. data/.gitignore +12 -0
  5. data/.rubocop.yml +1158 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +9 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +195 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/install-glfw.ps1 +13 -0
  14. data/lib/mittsu/generic_lib.rb +116 -0
  15. data/lib/mittsu/glfw/lib.rb +58 -0
  16. data/lib/mittsu/glfw/window.rb +231 -0
  17. data/lib/mittsu/opengl/buffer.rb +13 -0
  18. data/lib/mittsu/opengl/default_target.rb +50 -0
  19. data/lib/mittsu/opengl/geometry_group.rb +758 -0
  20. data/lib/mittsu/opengl/geometry_like.rb +132 -0
  21. data/lib/mittsu/opengl/gl_debug.rb +85 -0
  22. data/lib/mittsu/opengl/gl_extensions.rb +42 -0
  23. data/lib/mittsu/opengl/gl_mittsu_params.rb +53 -0
  24. data/lib/mittsu/opengl/helper.rb +120 -0
  25. data/lib/mittsu/opengl/implementation.rb +31 -0
  26. data/lib/mittsu/opengl/lib.rb +19 -0
  27. data/lib/mittsu/opengl/light_renderer.rb +43 -0
  28. data/lib/mittsu/opengl/material_basics.rb +57 -0
  29. data/lib/mittsu/opengl/plugins/shadow_map_plugin.rb +416 -0
  30. data/lib/mittsu/opengl/plugins/sprite_fragment.glsl +38 -0
  31. data/lib/mittsu/opengl/plugins/sprite_plugin.rb +250 -0
  32. data/lib/mittsu/opengl/plugins/sprite_vertex.glsl +31 -0
  33. data/lib/mittsu/opengl/program.rb +250 -0
  34. data/lib/mittsu/opengl/renderer.rb +1028 -0
  35. data/lib/mittsu/opengl/shader/chunk.rb +11 -0
  36. data/lib/mittsu/opengl/shader/chunks/alphamap_fragment.glsl +5 -0
  37. data/lib/mittsu/opengl/shader/chunks/alphamap_pars_fragment.glsl +5 -0
  38. data/lib/mittsu/opengl/shader/chunks/alphatest_fragment.glsl +5 -0
  39. data/lib/mittsu/opengl/shader/chunks/bumpmap_pars_fragment.glsl +40 -0
  40. data/lib/mittsu/opengl/shader/chunks/color_fragment.glsl +5 -0
  41. data/lib/mittsu/opengl/shader/chunks/color_pars_fragment.glsl +5 -0
  42. data/lib/mittsu/opengl/shader/chunks/color_pars_vertex.glsl +5 -0
  43. data/lib/mittsu/opengl/shader/chunks/color_vertex.glsl +5 -0
  44. data/lib/mittsu/opengl/shader/chunks/common.glsl +60 -0
  45. data/lib/mittsu/opengl/shader/chunks/default_vertex.glsl +15 -0
  46. data/lib/mittsu/opengl/shader/chunks/defaultnormal_vertex.glsl +21 -0
  47. data/lib/mittsu/opengl/shader/chunks/envmap_fragment.glsl +62 -0
  48. data/lib/mittsu/opengl/shader/chunks/envmap_pars_fragment.glsl +21 -0
  49. data/lib/mittsu/opengl/shader/chunks/envmap_pars_vertex.glsl +7 -0
  50. data/lib/mittsu/opengl/shader/chunks/envmap_vertex.glsl +17 -0
  51. data/lib/mittsu/opengl/shader/chunks/fog_fragment.glsl +26 -0
  52. data/lib/mittsu/opengl/shader/chunks/fog_pars_fragment.glsl +15 -0
  53. data/lib/mittsu/opengl/shader/chunks/lightmap_fragment.glsl +5 -0
  54. data/lib/mittsu/opengl/shader/chunks/lightmap_pars_fragment.glsl +6 -0
  55. data/lib/mittsu/opengl/shader/chunks/lightmap_pars_vertex.glsl +5 -0
  56. data/lib/mittsu/opengl/shader/chunks/lightmap_vertex.glsl +5 -0
  57. data/lib/mittsu/opengl/shader/chunks/lights_lambert_pars_vertex.glsl +43 -0
  58. data/lib/mittsu/opengl/shader/chunks/lights_lambert_vertex.glsl +196 -0
  59. data/lib/mittsu/opengl/shader/chunks/lights_phong_fragment.glsl +243 -0
  60. data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_fragment.glsl +58 -0
  61. data/lib/mittsu/opengl/shader/chunks/lights_phong_pars_vertex.glsl +5 -0
  62. data/lib/mittsu/opengl/shader/chunks/lights_phong_vertex.glsl +5 -0
  63. data/lib/mittsu/opengl/shader/chunks/linear_to_gamma_fragment.glsl +2 -0
  64. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_fragment.glsl +5 -0
  65. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_fragment.glsl +12 -0
  66. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_pars_vertex.glsl +11 -0
  67. data/lib/mittsu/opengl/shader/chunks/logdepthbuf_vertex.glsl +15 -0
  68. data/lib/mittsu/opengl/shader/chunks/map_fragment.glsl +9 -0
  69. data/lib/mittsu/opengl/shader/chunks/map_pars_fragment.glsl +11 -0
  70. data/lib/mittsu/opengl/shader/chunks/map_pars_vertex.glsl +6 -0
  71. data/lib/mittsu/opengl/shader/chunks/map_particle_fragment.glsl +5 -0
  72. data/lib/mittsu/opengl/shader/chunks/map_particle_pars_fragment.glsl +6 -0
  73. data/lib/mittsu/opengl/shader/chunks/map_vertex.glsl +5 -0
  74. data/lib/mittsu/opengl/shader/chunks/morphnormal_vertex.glsl +12 -0
  75. data/lib/mittsu/opengl/shader/chunks/morphtarget_pars_vertex.glsl +13 -0
  76. data/lib/mittsu/opengl/shader/chunks/morphtarget_vertex.glsl +20 -0
  77. data/lib/mittsu/opengl/shader/chunks/normalmap_pars_fragment.glsl +27 -0
  78. data/lib/mittsu/opengl/shader/chunks/shadowmap_fragment.glsl +216 -0
  79. data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_fragment.glsl +19 -0
  80. data/lib/mittsu/opengl/shader/chunks/shadowmap_pars_vertex.glsl +6 -0
  81. data/lib/mittsu/opengl/shader/chunks/shadowmap_vertex.glsl +9 -0
  82. data/lib/mittsu/opengl/shader/chunks/skinbase_vertex.glsl +8 -0
  83. data/lib/mittsu/opengl/shader/chunks/skinning_pars_vertex.glsl +47 -0
  84. data/lib/mittsu/opengl/shader/chunks/skinning_vertex.glsl +20 -0
  85. data/lib/mittsu/opengl/shader/chunks/skinnormal_vertex.glsl +20 -0
  86. data/lib/mittsu/opengl/shader/chunks/specularmap_fragment.glsl +12 -0
  87. data/lib/mittsu/opengl/shader/chunks/specularmap_pars_fragment.glsl +5 -0
  88. data/lib/mittsu/opengl/shader/chunks/worldpos_vertex.glsl +17 -0
  89. data/lib/mittsu/opengl/shader/lib/basic/basic_fragment.rbsl +37 -0
  90. data/lib/mittsu/opengl/shader/lib/basic/basic_uniforms.rbslu +3 -0
  91. data/lib/mittsu/opengl/shader/lib/basic/basic_vertex.rbsl +33 -0
  92. data/lib/mittsu/opengl/shader/lib/cube/cube_fragment.rbsl +12 -0
  93. data/lib/mittsu/opengl/shader/lib/cube/cube_uniforms.rbslu +2 -0
  94. data/lib/mittsu/opengl/shader/lib/cube/cube_vertex.rbsl +12 -0
  95. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_fragment.rbsl +26 -0
  96. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
  97. data/lib/mittsu/opengl/shader/lib/depth_rgba/depth_rgba_vertex.rbsl +12 -0
  98. data/lib/mittsu/opengl/shader/lib/lambert/lambert_fragment.rbsl +56 -0
  99. data/lib/mittsu/opengl/shader/lib/lambert/lambert_uniforms.rbslu +7 -0
  100. data/lib/mittsu/opengl/shader/lib/lambert/lambert_vertex.rbsl +37 -0
  101. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_fragment.rbsl +27 -0
  102. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_uniforms.rbslu +2 -0
  103. data/lib/mittsu/opengl/shader/lib/particle_basic/particle_basic_vertex.rbsl +25 -0
  104. data/lib/mittsu/opengl/shader/lib/phong/phong_fragment.rbsl +45 -0
  105. data/lib/mittsu/opengl/shader/lib/phong/phong_uniforms.rbslu +11 -0
  106. data/lib/mittsu/opengl/shader/lib/phong/phong_vertex.rbsl +43 -0
  107. data/lib/mittsu/opengl/shader/lib.rb +45 -0
  108. data/lib/mittsu/opengl/shader/rbsl_loader.rb +168 -0
  109. data/lib/mittsu/opengl/shader/templates/fragment.glsl.erb +105 -0
  110. data/lib/mittsu/opengl/shader/templates/vertex.glsl.erb +143 -0
  111. data/lib/mittsu/opengl/shader/uniforms_lib.rb +86 -0
  112. data/lib/mittsu/opengl/shader/uniforms_utils.rb +31 -0
  113. data/lib/mittsu/opengl/shader.rb +56 -0
  114. data/lib/mittsu/opengl/state.rb +205 -0
  115. data/lib/mittsu/opengl/version.rb +5 -0
  116. data/lib/mittsu/opengl.rb +2 -0
  117. data/lib/mittsu/opengl_implementation/core/buffer_geometry.rb +11 -0
  118. data/lib/mittsu/opengl_implementation/core/geometry.rb +346 -0
  119. data/lib/mittsu/opengl_implementation/core/object_3d.rb +134 -0
  120. data/lib/mittsu/opengl_implementation/lights/ambient_light.rb +26 -0
  121. data/lib/mittsu/opengl_implementation/lights/directional_light.rb +35 -0
  122. data/lib/mittsu/opengl_implementation/lights/hemisphere_light.rb +39 -0
  123. data/lib/mittsu/opengl_implementation/lights/light.rb +55 -0
  124. data/lib/mittsu/opengl_implementation/lights/point_light.rb +36 -0
  125. data/lib/mittsu/opengl_implementation/lights/spot_light.rb +47 -0
  126. data/lib/mittsu/opengl_implementation/materials/line_basic_material.rb +16 -0
  127. data/lib/mittsu/opengl_implementation/materials/material.rb +274 -0
  128. data/lib/mittsu/opengl_implementation/materials/mesh_basic_material.rb +21 -0
  129. data/lib/mittsu/opengl_implementation/materials/mesh_lambert_material.rb +33 -0
  130. data/lib/mittsu/opengl_implementation/materials/mesh_phong_material.rb +44 -0
  131. data/lib/mittsu/opengl_implementation/materials/point_cloud_material.rb +27 -0
  132. data/lib/mittsu/opengl_implementation/materials/shader_material.rb +11 -0
  133. data/lib/mittsu/opengl_implementation/objects/group.rb +9 -0
  134. data/lib/mittsu/opengl_implementation/objects/line.rb +45 -0
  135. data/lib/mittsu/opengl_implementation/objects/mesh.rb +70 -0
  136. data/lib/mittsu/opengl_implementation/objects/point_cloud.rb +39 -0
  137. data/lib/mittsu/opengl_implementation/objects/sprite.rb +12 -0
  138. data/lib/mittsu/opengl_implementation/scenes/scene.rb +9 -0
  139. data/lib/mittsu/opengl_implementation/textures/compressed_texture.rb +20 -0
  140. data/lib/mittsu/opengl_implementation/textures/cube_texture.rb +77 -0
  141. data/lib/mittsu/opengl_implementation/textures/data_texture.rb +21 -0
  142. data/lib/mittsu/opengl_implementation/textures/render_target.rb +124 -0
  143. data/lib/mittsu/opengl_implementation/textures/texture.rb +107 -0
  144. data/mittsu-opengl.gemspec +36 -0
  145. metadata +314 -0
@@ -0,0 +1,758 @@
1
+ require 'mittsu/opengl/geometry_like'
2
+
3
+ module Mittsu
4
+ class OpenGL::GeometryGroup
5
+ include OpenGL::GeometryLike
6
+
7
+ attr_reader :id, :material_index
8
+
9
+ alias :initted_arrays? :initted_arrays
10
+
11
+ def initialize material_index, num_morph_targets, num_morph_normals, renderer
12
+ @id = (@@id ||= 1).tap { @@id += 1 }
13
+
14
+ @faces3 = []
15
+ @num_vertices = 0
16
+
17
+ @material_index = material_index
18
+
19
+ @num_morph_targets = num_morph_targets
20
+ @num_morph_normals = num_morph_normals
21
+
22
+ @renderer = renderer
23
+ @custom_attributes_list = []
24
+ end
25
+
26
+ def create_mesh_buffers
27
+ @vertex_array_object = GL.CreateVertexArray
28
+
29
+ @vertex_buffer = GL.CreateBuffer
30
+ @normal_buffer = GL.CreateBuffer
31
+ @tangent_buffer = GL.CreateBuffer
32
+ @color_buffer = GL.CreateBuffer
33
+ @uv_buffer = GL.CreateBuffer
34
+ @uv2_buffer = GL.CreateBuffer
35
+
36
+ @skin_indices_buffer = GL.CreateBuffer
37
+ @skin_weights_buffer = GL.CreateBuffer
38
+
39
+ @face_buffer = GL.CreateBuffer
40
+ @line_buffer = GL.CreateBuffer
41
+
42
+ if !@num_morph_targets.nil?
43
+ @morph_targets_buffers = []
44
+
45
+ @num_morph_targets.times do |m|
46
+ @morph_targets_buffers << GL.CreateBuffer
47
+ end
48
+ end
49
+
50
+ if !@num_morph_normals.nil?
51
+ @morph_normals_buffers = []
52
+
53
+ @num_morph_normals.times do |m|
54
+ @morph_normals_buffers << GL.CreateBuffer
55
+ end
56
+ end
57
+ end
58
+
59
+ def init_mesh_buffers(object)
60
+ geometry = object.geometry
61
+
62
+ nvertices = @faces3.length * 3
63
+ nvertices2 = nvertices * 2
64
+ nvertices3 = nvertices * 3
65
+ nvertices4 = nvertices * 4
66
+ ntris = @faces3.length * 1
67
+ nlines = @faces3.length * 3
68
+
69
+ material = object.buffer_material(self)
70
+
71
+ @vertex_array = Array.new(nvertices3) # Float32Array
72
+ @normal_array = Array.new(nvertices3) # Float32Array
73
+ @color_array = Array.new(nvertices3) # Float32Array
74
+ @uv_array = Array.new(nvertices2) # Float32Array
75
+
76
+ if geometry.face_vertex_uvs.length > 1
77
+ @uv2_array = Array.new(nvertices2) # Float32Array
78
+ end
79
+
80
+ if geometry.has_tangents
81
+ @tangent_array = Array.new(nvertices4) # Float32Array
82
+ end
83
+
84
+ if !object.geometry.skin_weights.empty? && !object.geometry.skin_indices.empty?
85
+ @skin_indices_array = Array.new(nvertices4) # Float32Array
86
+ @skin_weight_array = Array.new(nvertices4)
87
+ end
88
+
89
+ # UintArray from OES_element_index_uint ???
90
+
91
+ @type_array = Array # UintArray ???
92
+ @face_array = Array.new(ntris * 3)
93
+ @line_array = Array.new(nlines * 2)
94
+
95
+ num_morph_targets = @num_morph_targets
96
+
97
+ if !num_morph_targets.zero?
98
+ @morph_targets_arrays = []
99
+
100
+ num_morph_targets.times do |m|
101
+ @morph_targets_arrays << Array.new(nvertices3) # Float32Array ???
102
+ end
103
+ end
104
+
105
+ num_morph_normals = @num_morph_normals
106
+
107
+ if !num_morph_targets.zero?
108
+ @morph_normals_arrays = []
109
+
110
+ num_morph_normals.times do |m|
111
+ @morph_normals_arrays << Array.new(nvertices3) # Float32Array ???
112
+ end
113
+ end
114
+
115
+ @face_count = ntris * 3
116
+ @line_count = nlines * 2
117
+
118
+ # custom attributes
119
+
120
+ if material.attributes
121
+ if @custom_attributes_list.nil?
122
+ @custom_attributes_list = []
123
+ end
124
+
125
+ material.attributes.each do |(name, original_attribute)|
126
+ attribute = {}
127
+ original_attribute.each do |(key, value)|
128
+ attribute[key] = value
129
+ end
130
+
131
+ if !attribute[:_opengl_initialized] || attribute[:create_unique_buffers]
132
+ attribute[:_opengl_initialized] = true
133
+
134
+ size = case attribute[:type]
135
+ when :v2 then 2
136
+ when :v3, :c then 3
137
+ when :v4 then 4
138
+ else 1 # :f and :i
139
+ end
140
+
141
+ attribute[:size] = size
142
+ attribute[:array] = Array.new(nvertices * size) # Float32Array
143
+
144
+ attribute[:buffer] = GL.CreateBuffer
145
+ attribute[:buffer_belongs_to_attribute] = name
146
+
147
+ original_attribute[:needs_update] = true
148
+ attribute[:_original] = original_attribute
149
+ end
150
+
151
+ @custom_attributes_list << attribute
152
+ end
153
+ end
154
+
155
+ @initted_arrays = true
156
+ end
157
+
158
+ def set_mesh_buffers(object, hint, should_dispose, material)
159
+ return unless @initted_arrays
160
+
161
+ geometry = object.geometry
162
+
163
+ needs_face_normals = material.needs_face_normals?
164
+
165
+ vertex_index = 0
166
+
167
+ offset = 0
168
+ offset_uv = 0
169
+ offset_uv2 = 0
170
+ offset_face = 0
171
+ offset_normal = 0
172
+ offset_tangent = 0
173
+ offset_line = 0
174
+ offset_color = 0
175
+ offset_skin = 0
176
+ offset_morph_target = 0
177
+ offset_custom = 0
178
+
179
+ vertices = geometry.vertices
180
+ obj_faces = geometry.faces
181
+
182
+ obj_uvs = geometry.face_vertex_uvs[0]
183
+ obj_uvs2 = geometry.face_vertex_uvs[1]
184
+
185
+ obj_skin_indices = geometry.skin_indices
186
+ obj_skin_weights = geometry.skin_weights
187
+
188
+ morph_targets = geometry.morph_targets
189
+ morph_normals = geometry.morph_normals
190
+
191
+ if geometry.vertices_need_update
192
+ @faces3.each do |chf|
193
+ face = obj_faces[chf]
194
+
195
+ v1 = vertices[face.a]
196
+ v2 = vertices[face.b]
197
+ v3 = vertices[face.c]
198
+
199
+ @vertex_array[offset] = v1.x
200
+ @vertex_array[offset + 1] = v1.y
201
+ @vertex_array[offset + 2] = v1.z
202
+
203
+ @vertex_array[offset + 3] = v2.x
204
+ @vertex_array[offset + 4] = v2.y
205
+ @vertex_array[offset + 5] = v2.z
206
+
207
+ @vertex_array[offset + 6] = v3.x
208
+ @vertex_array[offset + 7] = v3.y
209
+ @vertex_array[offset + 8] = v3.z
210
+
211
+ offset += 9
212
+ end
213
+
214
+ GL.BindBuffer(GL::ARRAY_BUFFER, @vertex_buffer)
215
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @vertex_array, hint)
216
+ end
217
+
218
+ if geometry.morph_targets_need_update
219
+ morph_targets.each_index do |vk|
220
+ @faces3.each do |chf|
221
+ face = obj_faces[chf]
222
+
223
+ # morph positions
224
+
225
+ v1 = morph_targets[vk].vertices[face.a]
226
+ v2 = morph_targets[vk].vertices[face.b]
227
+ v3 = morph_targets[vk].vertices[face.c]
228
+
229
+ vka = @morph_targets_arrays[vk]
230
+
231
+ vka[offset_morph_target] = v1.x
232
+ vka[offset_morph_target + 1] = v1.y
233
+ vka[offset_morph_target + 2] = v1.z
234
+
235
+ vka[offset_morph_target + 3] = v2.x
236
+ vka[offset_morph_target + 4] = v2.y
237
+ vka[offset_morph_target + 5] = v2.z
238
+
239
+ vka[offset_morph_target + 6] = v3.x
240
+ vka[offset_morph_target + 7] = v3.y
241
+ vka[offset_morph_target + 8] = v3.z
242
+
243
+ # morph normals
244
+
245
+ if material.morph_normals
246
+ if needs_face_normals
247
+ n1 = morph_normals[vk].face_normals[chf]
248
+ n2 = n1
249
+ n3 = n1
250
+ else
251
+ face_vertex_normals = morph_normals[vk].vertex_normals[chf]
252
+
253
+ n1 = face_vertex_normals.a
254
+ n2 = face_vertex_normals.b
255
+ n3 = face_vertex_normals.c
256
+ end
257
+
258
+ nka = @morph_normals_arrays[vk]
259
+
260
+ nka[offset_morph_target] = n1.x
261
+ nka[offset_morph_target + 1] = n1.y
262
+ nka[offset_morph_target + 2] = n1.z
263
+
264
+ nka[offset_morph_target + 3] = n2.x
265
+ nka[offset_morph_target + 4] = n2.y
266
+ nka[offset_morph_target + 5] = n2.z
267
+
268
+ nka[offset_morph_target + 6] = n3.x
269
+ nka[offset_morph_target + 7] = n3.y
270
+ nka[offset_morph_target + 8] = n3.z
271
+ end
272
+
273
+ #
274
+
275
+ offset_morph_target += 9
276
+ end
277
+
278
+ GL.BindBuffer(GL::ARRAY_BUFFER, @morph_targets_buffers[vk])
279
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @morph_targets_arrays[vk], hint)
280
+
281
+ if material.morph_normals
282
+ GL.BindBuffer(GL::ARRAY_BUFFER, @morph_normals_buffers[vk])
283
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @morph_normals_arrays[vk], hint)
284
+ end
285
+ end
286
+ end
287
+
288
+ if !obj_skin_weights.empty?
289
+ @faces3.each do |chf|
290
+ face = obj_faces[chf]
291
+
292
+ # weights
293
+
294
+ sw1 = obj_skin_weights[face.a]
295
+ sw2 = obj_skin_weights[face.b]
296
+ sw3 = obj_skin_weights[face.c]
297
+
298
+ @skin_weight_array[offset_skin] = sw1.x
299
+ @skin_weight_array[offset_skin + 1] = sw1.y
300
+ @skin_weight_array[offset_skin + 2] = sw1.z
301
+ @skin_weight_array[offset_skin + 3] = sw1.w
302
+
303
+ @skin_weight_array[offset_skin + 4] = sw2.x
304
+ @skin_weight_array[offset_skin + 5] = sw2.y
305
+ @skin_weight_array[offset_skin + 6] = sw2.z
306
+ @skin_weight_array[offset_skin + 7] = sw2.w
307
+
308
+ @skin_weight_array[offset_skin + 8] = sw3.x
309
+ @skin_weight_array[offset_skin + 9] = sw3.y
310
+ @skin_weight_array[offset_skin + 10] = sw3.z
311
+ @skin_weight_array[offset_skin + 11] = sw3.w
312
+
313
+ # indices
314
+
315
+ si1 = obj_skin_indices[face.a]
316
+ si2 = obj_skin_indices[face.b]
317
+ si3 = obj_skin_indices[face.c]
318
+
319
+ @skin_indices_array[offset_skin] = si1.x
320
+ @skin_indices_array[offset_skin + 1] = si1.y
321
+ @skin_indices_array[offset_skin + 2] = si1.z
322
+ @skin_indices_array[offset_skin + 3] = si1.w
323
+
324
+ @skin_indices_array[offset_skin + 4] = si2.x
325
+ @skin_indices_array[offset_skin + 5] = si2.y
326
+ @skin_indices_array[offset_skin + 6] = si2.z
327
+ @skin_indices_array[offset_skin + 7] = si2.w
328
+
329
+ @skin_indices_array[offset_skin + 8] = si3.x
330
+ @skin_indices_array[offset_skin + 9] = si3.y
331
+ @skin_indices_array[offset_skin + 10] = si3.z
332
+ @skin_indices_array[offset_skin + 11] = si3.w
333
+
334
+ offset_skin += 12
335
+ end
336
+
337
+ if offset_skin > 0
338
+ GL.BindBuffer(GL::ARRAY_BUFFER, @skin_indices_buffer)
339
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @skin_indices_array, hint)
340
+
341
+ GL.BindBuffer(GL::ARRAY_BUFFER, @skin_weights_buffer)
342
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @skin_weight_array, hint)
343
+ end
344
+ end
345
+
346
+ if geometry.colors_need_update
347
+ @faces3.each do |chf|
348
+ face = obj_faces[chf]
349
+
350
+ face_vertex_colors = face.vertex_colors
351
+ face_color = face.color
352
+
353
+ if face_vertex_colors.length == 3 && material.vertex_colors == VertexColors
354
+ c1 = face_vertex_colors[0]
355
+ c2 = face_vertex_colors[1]
356
+ c3 = face_vertex_colors[2]
357
+ else
358
+ c1 = face_color
359
+ c2 = face_color
360
+ c3 = face_color
361
+ end
362
+
363
+ @color_array[offset_color] = c1.r
364
+ @color_array[offset_color + 1] = c1.g
365
+ @color_array[offset_color + 2] = c1.b
366
+
367
+ @color_array[offset_color + 3] = c2.r
368
+ @color_array[offset_color + 4] = c2.g
369
+ @color_array[offset_color + 5] = c2.b
370
+
371
+ @color_array[offset_color + 6] = c3.r
372
+ @color_array[offset_color + 7] = c3.g
373
+ @color_array[offset_color + 8] = c3.b
374
+
375
+ offset_color += 9
376
+ end
377
+
378
+ if offset_color > 0
379
+ GL.BindBuffer(GL::ARRAY_BUFFER, @color_buffer)
380
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @color_array, hint)
381
+ end
382
+ end
383
+
384
+ if geometry.tangents_need_update && geometry.has_tangents
385
+ @faces3.each do |chf|
386
+ face = obj_faces[chf]
387
+
388
+ face_vertex_tangents = face.vertex_tangents
389
+
390
+ t1 = face_vertex_tangents[0]
391
+ t2 = face_vertex_tangents[1]
392
+ t3 = face_vertex_tangents[2]
393
+
394
+ @tangent_array[offset_tangent] = t1.x
395
+ @tangent_array[offset_tangent + 1] = t1.y
396
+ @tangent_array[offset_tangent + 2] = t1.z
397
+ @tangent_array[offset_tangent + 3] = t1.w
398
+
399
+ @tangent_array[offset_tangent + 4] = t2.x
400
+ @tangent_array[offset_tangent + 5] = t2.y
401
+ @tangent_array[offset_tangent + 6] = t2.z
402
+ @tangent_array[offset_tangent + 7] = t2.w
403
+
404
+ @tangent_array[offset_tangent + 8] = t3.x
405
+ @tangent_array[offset_tangent + 9] = t3.y
406
+ @tangent_array[offset_tangent + 10] = t3.z
407
+ @tangent_array[offset_tangent + 11] = t3.w
408
+
409
+ offset_tangent += 12
410
+ end
411
+
412
+ GL.BindBuffer(GL::ARRAY_BUFFER, @angent_buffer)
413
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @tangent_array, hint)
414
+ end
415
+
416
+ if geometry.normals_need_update
417
+ @faces3.each do |chf|
418
+ face = obj_faces[chf]
419
+
420
+ face_vertex_normals = face.vertex_normals
421
+ face_normal = face.normal
422
+
423
+ if face_vertex_normals.length == 3 && !needs_face_normals
424
+ 3.times do |i|
425
+ vn = face_vertex_normals[i]
426
+
427
+ @normal_array[offset_normal] = vn.x
428
+ @normal_array[offset_normal + 1] = vn.y
429
+ @normal_array[offset_normal + 2] = vn.z
430
+
431
+ offset_normal += 3
432
+ end
433
+ else
434
+ 3.times do |i|
435
+ @normal_array[offset_normal] = face_normal.x
436
+ @normal_array[offset_normal + 1] = face_normal.y
437
+ @normal_array[offset_normal + 2] = face_normal.z
438
+
439
+ offset_normal += 3
440
+ end
441
+ end
442
+ end
443
+
444
+ GL.BindBuffer(GL::ARRAY_BUFFER, @normal_buffer)
445
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @normal_array, hint)
446
+ end
447
+
448
+ if geometry.uvs_need_update && obj_uvs
449
+ @faces3.each do |fi|
450
+ uv = obj_uvs[fi]
451
+
452
+ next if uv.nil?
453
+
454
+ 3.times do |i|
455
+ uvi = uv[i]
456
+
457
+ @uv_array[offset_uv] = uvi.x
458
+ @uv_array[offset_uv + 1] = uvi.y
459
+
460
+ offset_uv += 2
461
+ end
462
+ end
463
+
464
+ if offset_uv > 0
465
+ GL.BindBuffer(GL::ARRAY_BUFFER, @uv_buffer)
466
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @uv_array, hint)
467
+ end
468
+ end
469
+
470
+ if geometry.uvs_need_update && obj_uvs2
471
+ @faces3.each do |fi|
472
+ uv2 = obj_uvs2[fi]
473
+
474
+ next if uv2.nil?
475
+
476
+ 3.times do |i|
477
+ uv2i = uv2[i]
478
+
479
+ @uv2_array[offset_uv2] = uv2i.x
480
+ @uv2_array[offset_uv2 + 1] = uv2i.y
481
+
482
+ offset_uv2 += 2
483
+ end
484
+ end
485
+
486
+ if offset_uv2 > 0
487
+ GL.BindBuffer(GL::ARRAY_BUFFER, @uv2_buffer)
488
+ GL.BufferData_easy(GL::ARRAY_BUFFER, @uv2_array, hint)
489
+ end
490
+ end
491
+
492
+ if geometry.elements_need_update
493
+ @faces3.each do |chf|
494
+ @face_array[offset_face] = vertex_index
495
+ @face_array[offset_face + 1] = vertex_index + 1
496
+ @face_array[offset_face + 2] = vertex_index + 2
497
+
498
+ offset_face += 3
499
+
500
+ @line_array[offset_line] = vertex_index
501
+ @line_array[offset_line + 1] = vertex_index + 1
502
+
503
+ @line_array[offset_line + 2] = vertex_index
504
+ @line_array[offset_line + 3] = vertex_index + 2
505
+
506
+ @line_array[offset_line + 4] = vertex_index + 1
507
+ @line_array[offset_line + 5] = vertex_index + 2
508
+
509
+ offset_line += 6
510
+
511
+ vertex_index += 3
512
+ end
513
+
514
+ GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @face_buffer)
515
+ GL.BufferData_easy(GL::ELEMENT_ARRAY_BUFFER, @face_array, hint)
516
+
517
+ GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @line_buffer)
518
+ GL.BufferData_easy(GL::ELEMENT_ARRAY_BUFFER, @line_array, hint)
519
+ end
520
+
521
+ if @custom_attributes_list
522
+ @custom_attributes_list.each do |custom_attribute|
523
+ next if !custom_attribute[:_original][:needs_update]
524
+
525
+ offset_custom = 0
526
+
527
+ if custom_attribute[:size] == 1
528
+ if custom_attribute[:bound_to].nil? || custom_attribute[:bound_to] == :vertices
529
+ @faces3.each do |chf|
530
+ face = obj_faces[chf]
531
+
532
+ custom_attribute[:array][offset_custom] = custom_attribute[:value][face.a]
533
+ custom_attribute[:array][offset_custom + 1] = custom_attribute[:value][face.b]
534
+ custom_attribute[:array][offset_custom + 2] = custom_attribute[:value][face.c]
535
+
536
+ offset_custom += 3
537
+ end
538
+ elsif custom_attribute[:bound_to] == :faces
539
+ value = custom_attribute[:value][chf]
540
+
541
+ custom_attribute[:array][offset_custom] = value
542
+ custom_attribute[:array][offset_custom + 1] = value
543
+ custom_attribute[:array][offset_custom + 2] = value
544
+
545
+ offset_custom += 3
546
+ end
547
+ elsif custom_attribute[:size] == 2
548
+ if custom_attribute[:bound_to].nil? || custom_attribute[:bound_to] == :vertices
549
+ @faces3.each do |chf|
550
+ face = obj_faces[chf]
551
+
552
+ v1 = custom_attribute[:value][face.a]
553
+ v2 = custom_attribute[:value][face.b]
554
+ v3 = custom_attribute[:value][face.c]
555
+
556
+ custom_attribute[:array][offset_custom] = v1.x
557
+ custom_attribute[:array][offset_custom + 1] = v1.y
558
+
559
+ custom_attribute[:array][offset_custom + 2] = v2.x
560
+ custom_attribute[:array][offset_custom + 3] = v2.y
561
+
562
+ custom_attribute[:array][offset_custom + 4] = v3.x
563
+ custom_attribute[:array][offset_custom + 5] = v3.y
564
+
565
+ offset_custom += 6
566
+ end
567
+ elsif custom_attribute[:bound_to] == :faces
568
+ @faces3.each do |chf|
569
+ value = custom_attribute[:value][chf]
570
+
571
+ v1 = value
572
+ v2 = value
573
+ v3 = value
574
+
575
+ custom_attribute[:array][offset_custom] = v1.x
576
+ custom_attribute[:array][offset_custom + 1] = v1.y
577
+
578
+ custom_attribute[:array][offset_custom + 2] = v2.x
579
+ custom_attribute[:array][offset_custom + 3] = v2.y
580
+
581
+ custom_attribute[:array][offset_custom + 4] = v3.x
582
+ custom_attribute[:array][offset_custom + 5] = v3.y
583
+
584
+ offset_custom += 6
585
+ end
586
+ end
587
+ elsif custom_attribute[:size] == 3
588
+ if custom_attribute[:bound_to].nil? || custom_attribute[:bound_to] == :vertices
589
+ @faces3.each do |chf|
590
+ face = obj_faces[chf];
591
+
592
+ v1 = custom_attribute[:value][face.a]
593
+ v2 = custom_attribute[:value][face.b]
594
+ v3 = custom_attribute[:value][face.c]
595
+
596
+ custom_attribute[:array][offset_custom] = v1[0]
597
+ custom_attribute[:array][offset_custom + 1] = v1[1]
598
+ custom_attribute[:array][offset_custom + 2] = v1[2]
599
+
600
+ custom_attribute[:array][offset_custom + 3] = v2[0]
601
+ custom_attribute[:array][offset_custom + 4] = v2[1]
602
+ custom_attribute[:array][offset_custom + 5] = v2[2]
603
+
604
+ custom_attribute[:array][offset_custom + 6] = v3[0]
605
+ custom_attribute[:array][offset_custom + 7] = v3[1]
606
+ custom_attribute[:array][offset_custom + 8] = v3[2]
607
+
608
+ offset_custom += 9
609
+ end
610
+ elsif custom_attribute[:bound_to] == :faces
611
+ @faces3.each do |chf|
612
+ value = custom_attribute[:value][chf]
613
+
614
+ v1 = value
615
+ v2 = value
616
+ v3 = value
617
+
618
+ custom_attribute[:array][offset_custom] = v1[0]
619
+ custom_attribute[:array][offset_custom + 1] = v1[1]
620
+ custom_attribute[:array][offset_custom + 2] = v1[2]
621
+
622
+ custom_attribute[:array][offset_custom + 3] = v2[0]
623
+ custom_attribute[:array][offset_custom + 4] = v2[1]
624
+ custom_attribute[:array][offset_custom + 5] = v2[2]
625
+
626
+ custom_attribute[:array][offset_custom + 6] = v3[0]
627
+ custom_attribute[:array][offset_custom + 7] = v3[1]
628
+ custom_attribute[:array][offset_custom + 8] = v3[2]
629
+
630
+ offset_custom += 9
631
+ end
632
+ elsif custom_attribute[:bound_to] == :face_vertices
633
+ @faces3.each do |chf|
634
+ value = custom_attribute[:value][chf]
635
+
636
+ v1 = value[0]
637
+ v2 = value[1]
638
+ v3 = value[2]
639
+
640
+ custom_attribute[:array][offset_custom] = v1[0]
641
+ custom_attribute[:array][offset_custom + 1] = v1[1]
642
+ custom_attribute[:array][offset_custom + 2] = v1[2]
643
+
644
+ custom_attribute[:array][offset_custom + 3] = v2[0]
645
+ custom_attribute[:array][offset_custom + 4] = v2[1]
646
+ custom_attribute[:array][offset_custom + 5] = v2[2]
647
+
648
+ custom_attribute[:array][offset_custom + 6] = v3[0]
649
+ custom_attribute[:array][offset_custom + 7] = v3[1]
650
+ custom_attribute[:array][offset_custom + 8] = v3[2]
651
+
652
+ offset_custom += 9
653
+ end
654
+ end
655
+ elsif custom_attribute[:size] == 4
656
+ if custom_attribute[:bound_to].nil? || custom_attribute[:bound_to] == :vertices
657
+ @faces3.each do |chf|
658
+ face = obj_faces[chf]
659
+
660
+ v1 = custom_attribute[:value][face.a]
661
+ v2 = custom_attribute[:value][face.b]
662
+ v3 = custom_attribute[:value][face.c]
663
+
664
+ custom_attribute[:array][offset_custom] = v1.x
665
+ custom_attribute[:array][offset_custom + 1 ] = v1.y
666
+ custom_attribute[:array][offset_custom + 2 ] = v1.z
667
+ custom_attribute[:array][offset_custom + 3 ] = v1.w
668
+
669
+ custom_attribute[:array][offset_custom + 4 ] = v2.x
670
+ custom_attribute[:array][offset_custom + 5 ] = v2.y
671
+ custom_attribute[:array][offset_custom + 6 ] = v2.z
672
+ custom_attribute[:array][offset_custom + 7 ] = v2.w
673
+
674
+ custom_attribute[:array][offset_custom + 8 ] = v3.x
675
+ custom_attribute[:array][offset_custom + 9 ] = v3.y
676
+ custom_attribute[:array][offset_custom + 10] = v3.z
677
+ custom_attribute[:array][offset_custom + 11] = v3.w
678
+
679
+ offset_custom += 12
680
+ end
681
+ elsif custom_attribute[:bound_to] == :faces
682
+ @faces3.each do |chf|
683
+ value = custom_attribute[:value][chf]
684
+
685
+ v1 = value
686
+ v2 = value
687
+ v3 = value
688
+
689
+ custom_attribute[:array][offset_custom] = v1.x
690
+ custom_attribute[:array][offset_custom + 1 ] = v1.y
691
+ custom_attribute[:array][offset_custom + 2 ] = v1.z
692
+ custom_attribute[:array][offset_custom + 3 ] = v1.w
693
+
694
+ custom_attribute[:array][offset_custom + 4 ] = v2.x
695
+ custom_attribute[:array][offset_custom + 5 ] = v2.y
696
+ custom_attribute[:array][offset_custom + 6 ] = v2.z
697
+ custom_attribute[:array][offset_custom + 7 ] = v2.w
698
+
699
+ custom_attribute[:array][offset_custom + 8 ] = v3.x
700
+ custom_attribute[:array][offset_custom + 9 ] = v3.y
701
+ custom_attribute[:array][offset_custom + 10] = v3.z
702
+ custom_attribute[:array][offset_custom + 11] = v3.w
703
+
704
+ offset_custom += 12
705
+ end
706
+ elsif custom_attribute[:bound_to] == :face_vertices
707
+ @faces3.each do |chf|
708
+ value = custom_attribute[:value][chf]
709
+
710
+ v1 = value[0]
711
+ v2 = value[1]
712
+ v3 = value[2]
713
+
714
+ custom_attribute[:array][offset_custom] = v1.x
715
+ custom_attribute[:array][offset_custom + 1 ] = v1.y
716
+ custom_attribute[:array][offset_custom + 2 ] = v1.z
717
+ custom_attribute[:array][offset_custom + 3 ] = v1.w
718
+
719
+ custom_attribute[:array][offset_custom + 4 ] = v2.x
720
+ custom_attribute[:array][offset_custom + 5 ] = v2.y
721
+ custom_attribute[:array][offset_custom + 6 ] = v2.z
722
+ custom_attribute[:array][offset_custom + 7 ] = v2.w
723
+
724
+ custom_attribute[:array][offset_custom + 8 ] = v3.x
725
+ custom_attribute[:array][offset_custom + 9 ] = v3.y
726
+ custom_attribute[:array][offset_custom + 10] = v3.z
727
+ custom_attribute[:array][offset_custom + 11] = v3.w
728
+
729
+ offset_custom += 12
730
+ end
731
+ end
732
+ end
733
+
734
+ GL.BindBuffer(GL::ARRAY_BUFFER, custom_attribute[:buffer])
735
+ GL.BufferData_easy(GL::ARRAY_BUFFER, custom_attribute[:array], hint)
736
+ end
737
+ end
738
+
739
+ if should_dispose
740
+ self.dispose
741
+ end
742
+ end
743
+
744
+ def dispose
745
+ @initted_arrays = nil
746
+ @color_array = nil
747
+ @normal_array = nil
748
+ @tangent_array = nil
749
+ @uv_array = nil
750
+ @uv2_array = nil
751
+ @face_array = nil
752
+ @vertex_array = nil
753
+ @line_array = nil
754
+ @skin_index_array = nil
755
+ @skin_weight_array = nil
756
+ end
757
+ end
758
+ end