mittsu 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +20 -0
- data/circle.yml +5 -5
- data/lib/mittsu/core/raycaster.rb +5 -5
- data/lib/mittsu/materials.rb +2 -0
- data/lib/mittsu/materials/point_cloud_material.rb +53 -0
- data/lib/mittsu/materials/sprite_material.rb +53 -0
- data/lib/mittsu/math/euler.rb +1 -1
- data/lib/mittsu/math/ray.rb +0 -1
- data/lib/mittsu/objects.rb +2 -0
- data/lib/mittsu/objects/mesh.rb +54 -28
- data/lib/mittsu/objects/point_cloud.rb +100 -0
- data/lib/mittsu/objects/sprite.rb +53 -0
- data/lib/mittsu/renderers/glfw_window.rb +8 -0
- data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +11 -0
- data/lib/mittsu/renderers/opengl/core/geometry.rb +119 -17
- data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +27 -0
- data/lib/mittsu/renderers/opengl/objects/line.rb +1 -1
- data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +39 -0
- data/lib/mittsu/renderers/opengl/objects/sprite.rb +12 -0
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +4 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +6 -6
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +1 -0
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +7 -7
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +5 -0
- data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +38 -0
- data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +250 -0
- data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +31 -0
- data/lib/mittsu/renderers/opengl_renderer.rb +8 -28
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +27 -0
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +2 -0
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +25 -0
- data/lib/mittsu/version.rb +1 -1
- metadata +18 -3
@@ -0,0 +1,53 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class Sprite < Object3D
|
3
|
+
attr_accessor :material, :z
|
4
|
+
|
5
|
+
INDICES = [0, 1, 2,
|
6
|
+
0, 2, 3] # Uint16Array
|
7
|
+
VERTICES = [-0.5, -0.5, 0.0,
|
8
|
+
0.5, -0.5, 0.0,
|
9
|
+
0.5, 0.5, 0.0,
|
10
|
+
-0.5, 0.5, 0.0] # Float32Array
|
11
|
+
UVS = [0.0, 0.0,
|
12
|
+
1.0, 0.0,
|
13
|
+
1.0, 1.0,
|
14
|
+
0.0, 1.0] # Float32Array
|
15
|
+
|
16
|
+
GEOMETRY = BufferGeometry.new
|
17
|
+
GEOMETRY[:index] = BufferAttribute.new(INDICES, 1)
|
18
|
+
GEOMETRY[:position] = BufferAttribute.new(VERTICES, 3)
|
19
|
+
GEOMETRY[:uv] = BufferAttribute.new(UVS, 2)
|
20
|
+
|
21
|
+
def initialize(material = SpriteMaterial.new)
|
22
|
+
super()
|
23
|
+
|
24
|
+
@type = 'Sprite'
|
25
|
+
|
26
|
+
@geometry = GEOMETRY
|
27
|
+
@material = material
|
28
|
+
@z = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def raycast(raycaster, intersects)
|
32
|
+
@_matrix_position ||= Vector3.new
|
33
|
+
|
34
|
+
@_matrix_position.set_from_matrix_position(@matrix_world)
|
35
|
+
|
36
|
+
distance = raycaster.ray.distance_to_pint(@_matrix_position)
|
37
|
+
|
38
|
+
return if distance > @scale.x
|
39
|
+
|
40
|
+
intersects.push({
|
41
|
+
distance: distance,
|
42
|
+
point: @position,
|
43
|
+
face: nil,
|
44
|
+
object: self
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
def clone(object = Sprite.new(@material))
|
49
|
+
super(object)
|
50
|
+
object
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -178,6 +178,14 @@ module Mittsu
|
|
178
178
|
glfwGetJoystickName(joystick)
|
179
179
|
end
|
180
180
|
|
181
|
+
def set_mouselock(value)
|
182
|
+
if value
|
183
|
+
glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED)
|
184
|
+
else
|
185
|
+
glfwSetInputMode(@handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
181
189
|
private
|
182
190
|
|
183
191
|
def poll_all_joysticks_buttons
|
@@ -34,7 +34,7 @@ module Mittsu
|
|
34
34
|
@tangents_need_update = true
|
35
35
|
@colors_need_update = true
|
36
36
|
|
37
|
-
|
37
|
+
add_buffers = true
|
38
38
|
else
|
39
39
|
add_buffers = false
|
40
40
|
end
|
@@ -59,6 +59,17 @@ module Mittsu
|
|
59
59
|
init_custom_attributes(object)
|
60
60
|
end
|
61
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
|
+
|
62
73
|
def create_line_buffers
|
63
74
|
@vertex_array_object = glCreateVertexArray
|
64
75
|
|
@@ -69,6 +80,15 @@ module Mittsu
|
|
69
80
|
@renderer.info[:memory][:geometries] += 1
|
70
81
|
end
|
71
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
|
+
|
72
92
|
def set_line_buffers(hint)
|
73
93
|
if @vertices_need_update
|
74
94
|
@vertices.each_with_index do |vertex, v|
|
@@ -117,36 +137,36 @@ module Mittsu
|
|
117
137
|
custom_attribute.array[ca] = value
|
118
138
|
end
|
119
139
|
when 2
|
120
|
-
values.
|
121
|
-
custom_attribute[offset ] = value.x
|
122
|
-
custom_attribute[offset + 1] = value.y
|
140
|
+
values.each do |value|
|
141
|
+
custom_attribute.array[offset ] = value.x
|
142
|
+
custom_attribute.array[offset + 1] = value.y
|
123
143
|
|
124
144
|
offset += 2
|
125
145
|
end
|
126
146
|
when 3
|
127
147
|
if custom_attribute.type === :c
|
128
|
-
values.
|
129
|
-
custom_attribute[offset ] = value.r
|
130
|
-
custom_attribute[offset + 1] = value.g
|
131
|
-
custom_attribute[offset + 2] = value.b
|
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
|
132
152
|
|
133
153
|
offset += 3
|
134
154
|
end
|
135
155
|
else
|
136
|
-
values.
|
137
|
-
custom_attribute[offset ] = value.x
|
138
|
-
custom_attribute[offset + 1] = value.y
|
139
|
-
custom_attribute[offset + 2] = value.z
|
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
|
140
160
|
|
141
161
|
offset += 3
|
142
162
|
end
|
143
163
|
end
|
144
164
|
when 4
|
145
|
-
values.
|
146
|
-
custom_attribute[offset ] = value.x
|
147
|
-
custom_attribute[offset + 1] = value.y
|
148
|
-
custom_attribute[offset + 2] = value.z
|
149
|
-
custom_attribute[offset + 3] = value.w
|
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
|
150
170
|
|
151
171
|
offset += 4
|
152
172
|
end
|
@@ -160,6 +180,88 @@ module Mittsu
|
|
160
180
|
end
|
161
181
|
end
|
162
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
|
+
|
163
265
|
private
|
164
266
|
|
165
267
|
def make_groups(uses_face_material = false)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class PointCloudMaterial
|
3
|
+
def refresh_uniforms(uniforms)
|
4
|
+
uniforms['psColor'].value = color
|
5
|
+
uniforms['opacity'].value = opacity
|
6
|
+
uniforms['size'].value = size
|
7
|
+
# uniforms['scale'].value = _canvas.height / 2.0 # TODO get window height?
|
8
|
+
|
9
|
+
uniforms['map'].value = map
|
10
|
+
|
11
|
+
if !map.nil?
|
12
|
+
offset = material.map.offset
|
13
|
+
repeat = material.map.repeat
|
14
|
+
|
15
|
+
uniforms['offsetRepeat'].value.set(offset.x, offset.y, repeat.x, repeat.y)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def init_shader
|
20
|
+
@shader = ShaderLib.create_shader(shader_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def shader_id
|
24
|
+
:particle_basic
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class PointCloud
|
3
|
+
def render_buffer(camera, lights, fog, material, geometry_group, update_buffers)
|
4
|
+
glDrawArrays(GL_POINTS, 0, geometry_group.particle_count)
|
5
|
+
|
6
|
+
@renderer.info[:render][:calls] += 1
|
7
|
+
@renderer.info[:render][:points] += geometry_group.particle_count
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
material = buffer_material(geometry)
|
12
|
+
custom_attributes_dirty = material.attributes && material.custom_attributes_dirty?
|
13
|
+
|
14
|
+
if geometry.vertices_need_update || geometry.colors_need_update || custom_attributes_dirty
|
15
|
+
geometry.set_particle_buffers(GL_DYNAMIC_DRAW)
|
16
|
+
end
|
17
|
+
|
18
|
+
geometry.vertices_need_update = false
|
19
|
+
geometry.colors_need_update = false
|
20
|
+
|
21
|
+
material.attributes && material.clear_custom_attributes
|
22
|
+
end
|
23
|
+
|
24
|
+
def init_geometry
|
25
|
+
geometry.renderer = @renderer
|
26
|
+
if geometry.vertex_buffer.nil?
|
27
|
+
geometry.create_particle_buffers
|
28
|
+
geometry.init_particle_buffers(self)
|
29
|
+
|
30
|
+
geometry.vertices_need_update = true
|
31
|
+
geometry.colors_need_update = true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_opengl_object
|
36
|
+
@renderer.add_opengl_object(geometry, self)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -39,7 +39,7 @@ module OpenGLDebug
|
|
39
39
|
const_set c, OpenGL.const_get(c)
|
40
40
|
end
|
41
41
|
|
42
|
-
def call_debug_method m, *args
|
42
|
+
def call_debug_method m, called_from = caller[0], *args
|
43
43
|
if m.to_s.start_with?('glUniform')
|
44
44
|
uniform_name = @@current_shader.get_uniform_name(args.first)
|
45
45
|
call = "#{m}('#{uniform_name}',#{args[1..-1].map { |s| s.to_s[0..20] }.join(', ')})"
|
@@ -49,7 +49,7 @@ module OpenGLDebug
|
|
49
49
|
print call
|
50
50
|
r = OpenGLProxy.send(m, *args)
|
51
51
|
ret = r.nil? ? '' : " => #{r}"
|
52
|
-
puts "#{ret} (#{
|
52
|
+
puts "#{ret} (#{called_from})"
|
53
53
|
e = OpenGLProxy.glGetError
|
54
54
|
raise "ERROR: #{m} => #{ERROR_STRINGS[e]}" unless e == OpenGL::GL_NO_ERROR
|
55
55
|
r
|
@@ -57,12 +57,12 @@ module OpenGLDebug
|
|
57
57
|
|
58
58
|
OpenGL.instance_methods.each do |m|
|
59
59
|
define_method m do |*args|
|
60
|
-
self.call_debug_method(m, *args)
|
60
|
+
self.call_debug_method(m, caller[0], *args)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
def glCreateProgram
|
65
|
-
call_debug_method(:glCreateProgram).tap do |handle|
|
65
|
+
call_debug_method(:glCreateProgram, caller[0]).tap do |handle|
|
66
66
|
@@shaders ||= {}
|
67
67
|
@@shaders[handle] = DebugShader.new(handle)
|
68
68
|
end
|
@@ -70,11 +70,11 @@ module OpenGLDebug
|
|
70
70
|
|
71
71
|
def glUseProgram(handle)
|
72
72
|
@@current_shader = @@shaders[handle]
|
73
|
-
call_debug_method(:glUseProgram, handle)
|
73
|
+
call_debug_method(:glUseProgram, caller[0], handle)
|
74
74
|
end
|
75
75
|
|
76
76
|
def glGetUniformLocation(program, name)
|
77
|
-
call_debug_method(:glGetUniformLocation, program, name).tap do |handle|
|
77
|
+
call_debug_method(:glGetUniformLocation, caller[0], program, name).tap do |handle|
|
78
78
|
@@shaders[program].set_uniform(handle, name)
|
79
79
|
end
|
80
80
|
end
|
@@ -137,23 +137,23 @@ module Mittsu
|
|
137
137
|
|
138
138
|
def painter_sort_stable(a, b)
|
139
139
|
if a.object.render_order != b.object.render_order
|
140
|
-
a.object.render_order
|
140
|
+
a.object.render_order <=> b.object.render_order
|
141
141
|
elsif a.material.id != b.material.id
|
142
|
-
a.material.id
|
142
|
+
a.material.id <=> b.material.id
|
143
143
|
elsif a.z != b.z
|
144
|
-
a.z
|
144
|
+
a.z <=> b.z
|
145
145
|
else
|
146
|
-
a.object.id
|
146
|
+
a.object.id <=> b.object.id
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
150
|
def reverse_painter_sort_stable(a, b)
|
151
151
|
if a.object.render_order != b.object.render_order
|
152
|
-
a.object.render_order
|
152
|
+
a.object.render_order <=> b.object.render_order
|
153
153
|
elsif a.z != b.z
|
154
|
-
b.z
|
154
|
+
b.z <=> a.z
|
155
155
|
else
|
156
|
-
|
156
|
+
b.id <=> a.id
|
157
157
|
end
|
158
158
|
end
|
159
159
|
end
|