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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a1f361bd9c5e37267db5e1e076dcb88d5149678
|
4
|
+
data.tar.gz: 32b0587711b8409e79e420f5ec3a5e41508ca7dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a69094dcb1f20b7d5582cc24d6e260fc4ee7194877a1687e6d6bf851b576eda7e18dc094d424cb4ecafb13eb0913cf11e8038d8d1c87d212161de798a8e83e38
|
7
|
+
data.tar.gz: 96272baf7be394553b5e1019b029209b029f89787dfa6de84e086fc848e1d9bfa5c7e61c0730afe971d799f6e26741e156b9cba40dc78b51ca0c70ec2c29cf95
|
data/.travis.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
2.4.0
|
4
|
+
|
5
|
+
env:
|
6
|
+
- MITTSU_LIBGLFW_PATH=/usr/local/lib MITTSU_LIBGLFW_FILE=libglfw.so MINITEST_REPORTER=JUnit
|
7
|
+
|
8
|
+
addons:
|
9
|
+
apt:
|
10
|
+
sources:
|
11
|
+
- george-edison55-precise-backports # cmake 3.2.3 / doxygen 1.8.3
|
12
|
+
packages:
|
13
|
+
- cmake
|
14
|
+
- cmake-data
|
15
|
+
|
16
|
+
before_install:
|
17
|
+
- sudo apt-get update; sudo apt-get install xorg-dev libgl1-mesa-dev
|
18
|
+
- bash ./install-glfw-3.1.2.sh
|
19
|
+
|
20
|
+
script: bundle exec rake test
|
data/circle.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
## Customize the test machine
|
2
2
|
machine:
|
3
|
+
xcode:
|
4
|
+
version: 8.2
|
5
|
+
|
3
6
|
environment:
|
4
7
|
MITTSU_LIBGLFW_PATH: /usr/local/lib
|
5
|
-
MITTSU_LIBGLFW_FILE: libglfw.
|
8
|
+
MITTSU_LIBGLFW_FILE: libglfw.dylib
|
6
9
|
MINITEST_REPORTER: JUnit
|
7
10
|
|
8
11
|
# Version of ruby to use
|
@@ -12,11 +15,8 @@ machine:
|
|
12
15
|
|
13
16
|
## Customize dependencies
|
14
17
|
dependencies:
|
15
|
-
cache_directories:
|
16
|
-
- glfw-3.1.2
|
17
18
|
pre:
|
18
|
-
-
|
19
|
-
- bash ./install-glfw-3.1.2.sh
|
19
|
+
- brew install glfw
|
20
20
|
|
21
21
|
test:
|
22
22
|
post:
|
@@ -2,9 +2,9 @@ require 'mittsu'
|
|
2
2
|
|
3
3
|
module Mittsu
|
4
4
|
class Raycaster
|
5
|
-
attr_accessor :near, :far, :ray, :params
|
5
|
+
attr_accessor :near, :far, :ray, :params, :precision
|
6
6
|
|
7
|
-
def initialize(origin, direction, near = 0.0, far = Float::INFINITY)
|
7
|
+
def initialize(origin = Vector3.new, direction = Vector3.new, near = 0.0, far = Float::INFINITY)
|
8
8
|
@ray = Mittsu::Ray.new(origin, direction)
|
9
9
|
# direction is assumed to be normalized (for accurate distance calculations)
|
10
10
|
|
@@ -16,7 +16,7 @@ module Mittsu
|
|
16
16
|
@params = {
|
17
17
|
sprite: {},
|
18
18
|
mesh: {},
|
19
|
-
point_cloud: { threshold: 1 },
|
19
|
+
point_cloud: { threshold: 1.0 },
|
20
20
|
lod:{},
|
21
21
|
line: {}
|
22
22
|
}
|
@@ -49,7 +49,7 @@ module Mittsu
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def intersect_objects(objects, recursive)
|
52
|
+
def intersect_objects(objects, recursive = false)
|
53
53
|
intersects = []
|
54
54
|
if !objects.is_a? Array
|
55
55
|
puts 'WARNING: Mittsu::Raycaster#intersect_objects: objects is not an array'
|
@@ -61,7 +61,7 @@ module Mittsu
|
|
61
61
|
end
|
62
62
|
|
63
63
|
intersects.sort do |a, b|
|
64
|
-
a
|
64
|
+
a[:distance] <=> b[:distance]
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
data/lib/mittsu/materials.rb
CHANGED
@@ -5,3 +5,5 @@ require 'mittsu/materials/mesh_phong_material'
|
|
5
5
|
require 'mittsu/materials/shader_material'
|
6
6
|
require 'mittsu/materials/line_basic_material'
|
7
7
|
require 'mittsu/materials/mesh_face_material'
|
8
|
+
require 'mittsu/materials/sprite_material'
|
9
|
+
require 'mittsu/materials/point_cloud_material'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# parameters = {
|
2
|
+
# color: <hex>,
|
3
|
+
# opacity: <float>,
|
4
|
+
# map: new THREE.Texture( <Image> ),
|
5
|
+
#
|
6
|
+
# size: <float>,
|
7
|
+
# sizeAttenuation: <bool>,
|
8
|
+
#
|
9
|
+
# blending: THREE.NormalBlending,
|
10
|
+
# depthTest: <bool>,
|
11
|
+
# depthWrite: <bool>,
|
12
|
+
#
|
13
|
+
# vertexColors: <bool>,
|
14
|
+
#
|
15
|
+
# fog: <bool>
|
16
|
+
# }
|
17
|
+
|
18
|
+
module Mittsu
|
19
|
+
class PointCloudMaterial < Material
|
20
|
+
attr_accessor :size, :size_attenuation
|
21
|
+
|
22
|
+
def initialize(parameters = {})
|
23
|
+
super()
|
24
|
+
|
25
|
+
@type = 'PointCloudMaterial'
|
26
|
+
|
27
|
+
@color = Color.new(0xffffff)
|
28
|
+
|
29
|
+
@map = nil
|
30
|
+
|
31
|
+
@size = 1.0
|
32
|
+
@size_attenuation = true
|
33
|
+
|
34
|
+
@vertex_colors = NoColors
|
35
|
+
|
36
|
+
@fog = true
|
37
|
+
|
38
|
+
self.set_values(parameters)
|
39
|
+
end
|
40
|
+
|
41
|
+
def clone
|
42
|
+
material = PointCloudMaterial.new
|
43
|
+
super(material)
|
44
|
+
material.color.copy(@color)
|
45
|
+
material.map = @map
|
46
|
+
material.size = @size
|
47
|
+
material.size_attenuation = @size_attenuation
|
48
|
+
material.vertex_colors = @vertex_colors
|
49
|
+
material.fog = @fog
|
50
|
+
material
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mittsu/math'
|
2
|
+
require 'mittsu/materials/material'
|
3
|
+
|
4
|
+
# @author alteredq / http://alteredqualia.com/
|
5
|
+
#
|
6
|
+
# parameters = {
|
7
|
+
# color: <hex>,
|
8
|
+
# opacity: <float>,
|
9
|
+
# map: new THREE.Texture( <Image> ),
|
10
|
+
#
|
11
|
+
# blending: THREE.NormalBlending,
|
12
|
+
# depthTest: <bool>,
|
13
|
+
# depthWrite: <bool>,
|
14
|
+
#
|
15
|
+
# uvOffset: new THREE.Vector2(),
|
16
|
+
# uvScale: new THREE.Vector2(),
|
17
|
+
#
|
18
|
+
# fog: <bool>
|
19
|
+
# }
|
20
|
+
module Mittsu
|
21
|
+
class SpriteMaterial < Material
|
22
|
+
attr_accessor :map, :rotation, :fog
|
23
|
+
|
24
|
+
def initialize(parameters = {})
|
25
|
+
super()
|
26
|
+
|
27
|
+
@type = 'SpriteMaterial'
|
28
|
+
|
29
|
+
@color = Color.new(0xffffff)
|
30
|
+
@map = nil
|
31
|
+
|
32
|
+
@rotation = 0.0
|
33
|
+
|
34
|
+
@fog = false
|
35
|
+
|
36
|
+
set_values(parameters)
|
37
|
+
end
|
38
|
+
|
39
|
+
def clone
|
40
|
+
material = SpriteMaterial.new
|
41
|
+
super(material)
|
42
|
+
|
43
|
+
material.color.copy(@color)
|
44
|
+
material.map = @map
|
45
|
+
|
46
|
+
material.rotation = @rotation
|
47
|
+
|
48
|
+
material.fog = @fog
|
49
|
+
|
50
|
+
material
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/mittsu/math/euler.rb
CHANGED
data/lib/mittsu/math/ray.rb
CHANGED
data/lib/mittsu/objects.rb
CHANGED
data/lib/mittsu/objects/mesh.rb
CHANGED
@@ -37,6 +37,39 @@ module Mittsu
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def check_intersection object, raycaster, ray, pA, pB, pC, point
|
41
|
+
|
42
|
+
intersect = nil;
|
43
|
+
material = object.material;
|
44
|
+
|
45
|
+
if material.side == BackSide
|
46
|
+
|
47
|
+
intersect = ray.intersect_triangle( pC, pB, pA, true, point );
|
48
|
+
|
49
|
+
else
|
50
|
+
|
51
|
+
intersect = ray.intersect_triangle( pA, pB, pC, material.side != DoubleSide, point );
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
return nil if intersect.nil?
|
56
|
+
|
57
|
+
@intersectionPointWorld ||= Vector3.new
|
58
|
+
@intersectionPointWorld.copy( point );
|
59
|
+
@intersectionPointWorld.apply_matrix4( @matrix_world );
|
60
|
+
|
61
|
+
distance = raycaster.ray.origin.distance_to( @intersectionPointWorld );
|
62
|
+
|
63
|
+
return nil if ( distance < raycaster.near || distance > raycaster.far )
|
64
|
+
|
65
|
+
return {
|
66
|
+
distance: distance,
|
67
|
+
point: @intersectionPointWorld.clone(),
|
68
|
+
object: object
|
69
|
+
};
|
70
|
+
|
71
|
+
end
|
72
|
+
|
40
73
|
def raycast(raycaster, intersects)
|
41
74
|
@_inverse_matrix ||= Matrix4.new
|
42
75
|
@_ray ||= Ray.new
|
@@ -45,25 +78,30 @@ module Mittsu
|
|
45
78
|
@_v_a ||= Vector3.new
|
46
79
|
@_v_b ||= Vector3.new
|
47
80
|
@_v_c ||= Vector3.new
|
81
|
+
v_a = @_v_a
|
82
|
+
v_b = @_v_b
|
83
|
+
v_c = @_v_c
|
48
84
|
|
49
85
|
# Checking bounding_sphere distance to ray
|
50
86
|
|
51
87
|
@geometry.compute_bounding_sphere if @geometry.bounding_sphere.nil?
|
52
88
|
|
53
|
-
|
54
|
-
|
89
|
+
@_sphere.copy(geometry.bounding_sphere)
|
90
|
+
@_sphere.apply_matrix4(@matrix_world)
|
55
91
|
|
56
|
-
return unless raycaster.intersection_sphere?(
|
92
|
+
return unless raycaster.ray.intersection_sphere?(@_sphere)
|
57
93
|
|
58
94
|
# check bounding box before continuing
|
59
95
|
|
60
|
-
|
61
|
-
|
96
|
+
@_inverse_matrix = Matrix4.new
|
97
|
+
@_inverse_matrix.inverse(@matrix_world)
|
98
|
+
@_ray.copy(raycaster.ray).apply_matrix4(@_inverse_matrix)
|
62
99
|
|
63
|
-
if !geometry.
|
100
|
+
if !geometry.bounding_box.nil?
|
64
101
|
return unless ray.intersection_box?(geometry.bounding_box)
|
65
102
|
end
|
66
103
|
|
104
|
+
|
67
105
|
if geometry.is_a?(BufferGeometry)
|
68
106
|
return if @material.nil?
|
69
107
|
|
@@ -93,13 +131,13 @@ module Mittsu
|
|
93
131
|
v_b.from_array(positions, b * 3)
|
94
132
|
v_c.from_array(positions, c * 3)
|
95
133
|
|
96
|
-
if material.side
|
134
|
+
if material.side == BackSide
|
97
135
|
intersection_point = ray.intersect_triangle(v_c, v_b, v_a, true)
|
98
136
|
else
|
99
137
|
intersection_point = ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
|
100
138
|
end
|
101
139
|
|
102
|
-
next if
|
140
|
+
next if intersection_point.nil?
|
103
141
|
|
104
142
|
intersection_point.apply_matrix4(@matrix_world)
|
105
143
|
|
@@ -138,7 +176,7 @@ module Mittsu
|
|
138
176
|
intersection_point = ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
|
139
177
|
end
|
140
178
|
|
141
|
-
next if
|
179
|
+
next if intersection_point.nil?
|
142
180
|
|
143
181
|
intersection_point.apply_matrix4(@matrix_world)
|
144
182
|
|
@@ -210,27 +248,15 @@ module Mittsu
|
|
210
248
|
c = v_c
|
211
249
|
end
|
212
250
|
|
213
|
-
if material.side = BackSide
|
214
|
-
intersection_point = ray.intersect_triangle(v_c, v_b, v_a, true)
|
215
|
-
else
|
216
|
-
intersection_point = ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
|
217
|
-
end
|
218
251
|
|
219
|
-
|
252
|
+
intersection_point = Vector3.new
|
253
|
+
intersection = check_intersection self, raycaster, @_ray, a, b, c, intersection_point
|
220
254
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
intersects << {
|
228
|
-
distance: distance,
|
229
|
-
point: intersection_point,
|
230
|
-
face: face,
|
231
|
-
face_index: f,
|
232
|
-
object: self
|
233
|
-
}
|
255
|
+
next if not intersection
|
256
|
+
if intersection
|
257
|
+
intersection[:face] = face
|
258
|
+
end
|
259
|
+
intersects << intersection
|
234
260
|
end
|
235
261
|
end
|
236
262
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class PointCloud < Object3D
|
3
|
+
attr_accessor :geometry, :material
|
4
|
+
|
5
|
+
def initialize(geometry = Geometry.new, material = PointCloudMaterial.new(color: rand * 0xffffff))
|
6
|
+
super()
|
7
|
+
|
8
|
+
@type = 'PointCloud'
|
9
|
+
|
10
|
+
@geometry = geometry
|
11
|
+
@material = material
|
12
|
+
|
13
|
+
@_inverse_matrix = Matrix4.new
|
14
|
+
@_ray = Ray.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def raycast(raycaster, intersects)
|
18
|
+
threshold = raycaster.params[:point_cloud][:threshold]
|
19
|
+
@_inverse_matrix.inverse(self.materix_world)
|
20
|
+
@_ray.copy(raycaster.ray).apply_matrix4(@_inverse_matrix)
|
21
|
+
|
22
|
+
if !geometry.bounding_box.nil?
|
23
|
+
return if ray.intersection_box?(geometry.bounding_box) == false
|
24
|
+
end
|
25
|
+
|
26
|
+
local_threshold = threshold / ((self.scale.x + self.scale.y + self.scale.z) / 3.0)
|
27
|
+
position = Vector3.new
|
28
|
+
|
29
|
+
if geometry.is_a?(BufferGeometry)
|
30
|
+
attributes = geometry.attributes
|
31
|
+
positions = attributes.position.array
|
32
|
+
|
33
|
+
if !attributes[:index].nil?
|
34
|
+
indices = attributes[:index][:array]
|
35
|
+
offsets = geometry.compute_offsets
|
36
|
+
|
37
|
+
if offsets.empty?
|
38
|
+
offsets = [{
|
39
|
+
start: 0,
|
40
|
+
count: indices.length,
|
41
|
+
index: 0
|
42
|
+
}]
|
43
|
+
end
|
44
|
+
|
45
|
+
offsets.each do |offset|
|
46
|
+
start = offset[:start]
|
47
|
+
count = offset[:count]
|
48
|
+
index = offset[:index]
|
49
|
+
|
50
|
+
(start...start+count).each do |i|
|
51
|
+
a = index + indices[i]
|
52
|
+
position.from_array(positions, a * 3)
|
53
|
+
test_point(position, a, local_threshold, raycaster, intersects)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
else
|
57
|
+
point_count = positions.count / 3
|
58
|
+
|
59
|
+
point_count.times do |i|
|
60
|
+
position.set(
|
61
|
+
positions[3 * i],
|
62
|
+
positions[3 * i + 1],
|
63
|
+
positions[3 * i + 2]
|
64
|
+
)
|
65
|
+
|
66
|
+
test_point(position, i, local_threshold, raycaster, intersects)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
geometry.vertices.each_with_index do |vertex, i|
|
71
|
+
test_point(vertex, i, local_threshold, raycaster, intersects)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def clone(object = PointCloud.new(@geometry, @material))
|
77
|
+
super(object)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def test_point(point, index, local_threshold, raycaster, intersects)
|
83
|
+
ray_point_distance = @_ray.distance_to_point(point)
|
84
|
+
if ray_point_distance < local_threshold
|
85
|
+
intersect_point = @_ray.closes_point_to_point(point)
|
86
|
+
intersect_point.apply_matrix4(self.matrix_world)
|
87
|
+
|
88
|
+
distance = raycaster.ray.origin.distance_to(intersect_point)
|
89
|
+
intersects << {
|
90
|
+
distance: distance,
|
91
|
+
distance_to_ray: ray_point_distance,
|
92
|
+
point: intersect_point.clone,
|
93
|
+
index: index,
|
94
|
+
face: nil,
|
95
|
+
object: self
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|