cyberarm_engine 0.19.0 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -8
- data/.rubocop.yml +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +74 -74
- data/Rakefile +10 -10
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/cyberarm_engine.gemspec +39 -39
- data/lib/cyberarm_engine/animator.rb +219 -219
- data/lib/cyberarm_engine/background.rb +179 -179
- data/lib/cyberarm_engine/background_nine_slice.rb +142 -142
- data/lib/cyberarm_engine/bounding_box.rb +150 -150
- data/lib/cyberarm_engine/builtin/intro_state.rb +130 -130
- data/lib/cyberarm_engine/cache/download_manager.rb +121 -121
- data/lib/cyberarm_engine/cache.rb +4 -4
- data/lib/cyberarm_engine/common.rb +113 -113
- data/lib/cyberarm_engine/config_file.rb +46 -46
- data/lib/cyberarm_engine/console/command.rb +157 -157
- data/lib/cyberarm_engine/console/commands/help_command.rb +43 -43
- data/lib/cyberarm_engine/console/subcommand.rb +99 -99
- data/lib/cyberarm_engine/console.rb +248 -248
- data/lib/cyberarm_engine/game_object.rb +248 -248
- data/lib/cyberarm_engine/game_state.rb +97 -97
- data/lib/cyberarm_engine/model/material.rb +21 -21
- data/lib/cyberarm_engine/model/model_object.rb +131 -131
- data/lib/cyberarm_engine/model/parser.rb +74 -74
- data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -138
- data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -154
- data/lib/cyberarm_engine/model.rb +212 -212
- data/lib/cyberarm_engine/model_cache.rb +31 -31
- data/lib/cyberarm_engine/opengl/light.rb +50 -50
- data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -46
- data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -38
- data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -249
- data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -164
- data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +298 -298
- data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -22
- data/lib/cyberarm_engine/opengl/shader.rb +406 -406
- data/lib/cyberarm_engine/opengl/texture.rb +69 -69
- data/lib/cyberarm_engine/opengl.rb +28 -28
- data/lib/cyberarm_engine/ray.rb +56 -56
- data/lib/cyberarm_engine/stats.rb +21 -21
- data/lib/cyberarm_engine/text.rb +197 -197
- data/lib/cyberarm_engine/timer.rb +23 -23
- data/lib/cyberarm_engine/transform.rb +296 -296
- data/lib/cyberarm_engine/ui/border_canvas.rb +102 -102
- data/lib/cyberarm_engine/ui/dsl.rb +139 -139
- data/lib/cyberarm_engine/ui/element.rb +488 -488
- data/lib/cyberarm_engine/ui/elements/button.rb +97 -97
- data/lib/cyberarm_engine/ui/elements/check_box.rb +54 -54
- data/lib/cyberarm_engine/ui/elements/container.rb +256 -256
- data/lib/cyberarm_engine/ui/elements/edit_box.rb +179 -179
- data/lib/cyberarm_engine/ui/elements/edit_line.rb +263 -263
- data/lib/cyberarm_engine/ui/elements/flow.rb +15 -15
- data/lib/cyberarm_engine/ui/elements/image.rb +72 -72
- data/lib/cyberarm_engine/ui/elements/list_box.rb +88 -82
- data/lib/cyberarm_engine/ui/elements/progress.rb +51 -51
- data/lib/cyberarm_engine/ui/elements/radio.rb +6 -6
- data/lib/cyberarm_engine/ui/elements/slider.rb +104 -104
- data/lib/cyberarm_engine/ui/elements/stack.rb +11 -11
- data/lib/cyberarm_engine/ui/elements/text_block.rb +162 -162
- data/lib/cyberarm_engine/ui/elements/toggle_button.rb +65 -65
- data/lib/cyberarm_engine/ui/event.rb +54 -54
- data/lib/cyberarm_engine/ui/gui_state.rb +256 -256
- data/lib/cyberarm_engine/ui/style.rb +49 -49
- data/lib/cyberarm_engine/ui/theme.rb +207 -207
- data/lib/cyberarm_engine/vector.rb +293 -293
- data/lib/cyberarm_engine/version.rb +4 -4
- data/lib/cyberarm_engine/window.rb +120 -120
- data/lib/cyberarm_engine.rb +71 -71
- metadata +3 -3
@@ -1,212 +1,212 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Model
|
3
|
-
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
4
|
-
:current_material, :current_object, :vertex_count, :smoothing
|
5
|
-
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
6
|
-
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
|
7
|
-
:vertices_count
|
8
|
-
|
9
|
-
def initialize(file_path:)
|
10
|
-
@file_path = file_path
|
11
|
-
|
12
|
-
@material_file = nil
|
13
|
-
@current_object = nil
|
14
|
-
@current_material = nil
|
15
|
-
@vertex_count = 0
|
16
|
-
|
17
|
-
@objects = []
|
18
|
-
@materials = {}
|
19
|
-
@vertices = []
|
20
|
-
@colors = []
|
21
|
-
@uvs = []
|
22
|
-
@normals = []
|
23
|
-
@faces = []
|
24
|
-
@bones = []
|
25
|
-
@smoothing = 0
|
26
|
-
|
27
|
-
@vertices_count = 0
|
28
|
-
|
29
|
-
@bounding_box = BoundingBox.new
|
30
|
-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
31
|
-
|
32
|
-
type = File.basename(file_path).split(".").last.to_sym
|
33
|
-
parser = Model::Parser.find(type)
|
34
|
-
raise "Unsupported model type '.#{type}', supported models are: #{Model::Parser.supported_formats}" unless parser
|
35
|
-
|
36
|
-
parse(parser)
|
37
|
-
|
38
|
-
@vertices_count = @vertices.size
|
39
|
-
|
40
|
-
@has_texture = false
|
41
|
-
|
42
|
-
@materials.each do |_key, material|
|
43
|
-
@has_texture = true if material.texture_id
|
44
|
-
end
|
45
|
-
|
46
|
-
allocate_gl_objects
|
47
|
-
populate_vertex_buffer
|
48
|
-
configure_vao
|
49
|
-
|
50
|
-
@objects.each { |o| @vertex_count += o.vertices.size }
|
51
|
-
|
52
|
-
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
53
|
-
# build_collision_tree
|
54
|
-
end
|
55
|
-
|
56
|
-
def parse(parser)
|
57
|
-
parser.new(self).parse
|
58
|
-
end
|
59
|
-
|
60
|
-
def calculate_bounding_box(vertices, bounding_box)
|
61
|
-
unless bounding_box.min.x.is_a?(Float)
|
62
|
-
vertex = vertices.last
|
63
|
-
bounding_box.min.x = vertex.x
|
64
|
-
bounding_box.min.y = vertex.y
|
65
|
-
bounding_box.min.z = vertex.z
|
66
|
-
|
67
|
-
bounding_box.max.x = vertex.x
|
68
|
-
bounding_box.max.y = vertex.y
|
69
|
-
bounding_box.max.z = vertex.z
|
70
|
-
end
|
71
|
-
|
72
|
-
vertices.each do |vertex|
|
73
|
-
bounding_box.min.x = vertex.x if vertex.x <= bounding_box.min.x
|
74
|
-
bounding_box.min.y = vertex.y if vertex.y <= bounding_box.min.y
|
75
|
-
bounding_box.min.z = vertex.z if vertex.z <= bounding_box.min.z
|
76
|
-
|
77
|
-
bounding_box.max.x = vertex.x if vertex.x >= bounding_box.max.x
|
78
|
-
bounding_box.max.y = vertex.y if vertex.y >= bounding_box.max.y
|
79
|
-
bounding_box.max.z = vertex.z if vertex.z >= bounding_box.max.z
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def allocate_gl_objects
|
84
|
-
# Allocate arrays for future use
|
85
|
-
@vertex_array_id = nil
|
86
|
-
buffer = " " * 4
|
87
|
-
glGenVertexArrays(1, buffer)
|
88
|
-
@vertex_array_id = buffer.unpack1("L2")
|
89
|
-
|
90
|
-
# Allocate buffers for future use
|
91
|
-
@positions_buffer_id = nil
|
92
|
-
buffer = " " * 4
|
93
|
-
glGenBuffers(1, buffer)
|
94
|
-
@positions_buffer_id = buffer.unpack1("L2")
|
95
|
-
|
96
|
-
@colors_buffer_id = nil
|
97
|
-
buffer = " " * 4
|
98
|
-
glGenBuffers(1, buffer)
|
99
|
-
@colors_buffer_id = buffer.unpack1("L2")
|
100
|
-
|
101
|
-
@normals_buffer_id = nil
|
102
|
-
buffer = " " * 4
|
103
|
-
glGenBuffers(1, buffer)
|
104
|
-
@normals_buffer_id = buffer.unpack1("L2")
|
105
|
-
|
106
|
-
@uvs_buffer_id = nil
|
107
|
-
buffer = " " * 4
|
108
|
-
glGenBuffers(1, buffer)
|
109
|
-
@uvs_buffer_id = buffer.unpack1("L2")
|
110
|
-
end
|
111
|
-
|
112
|
-
def populate_vertex_buffer
|
113
|
-
pos = []
|
114
|
-
colors = []
|
115
|
-
norms = []
|
116
|
-
uvs = []
|
117
|
-
|
118
|
-
@faces.each do |face|
|
119
|
-
pos << face.vertices.map { |vert| [vert.x, vert.y, vert.z] }
|
120
|
-
colors << face.colors.map { |color| [color.red, color.green, color.blue] }
|
121
|
-
norms << face.normals.map { |vert| [vert.x, vert.y, vert.z, vert.weight] }
|
122
|
-
|
123
|
-
uvs << face.uvs.map { |vert| [vert.x, vert.y, vert.z] } if has_texture?
|
124
|
-
end
|
125
|
-
|
126
|
-
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
127
|
-
glBufferData(GL_ARRAY_BUFFER, pos.flatten.size * Fiddle::SIZEOF_FLOAT, pos.flatten.pack("f*"), GL_STATIC_DRAW)
|
128
|
-
|
129
|
-
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
130
|
-
glBufferData(GL_ARRAY_BUFFER, colors.flatten.size * Fiddle::SIZEOF_FLOAT, colors.flatten.pack("f*"),
|
131
|
-
GL_STATIC_DRAW)
|
132
|
-
|
133
|
-
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
134
|
-
glBufferData(GL_ARRAY_BUFFER, norms.flatten.size * Fiddle::SIZEOF_FLOAT, norms.flatten.pack("f*"), GL_STATIC_DRAW)
|
135
|
-
|
136
|
-
if has_texture?
|
137
|
-
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
138
|
-
glBufferData(GL_ARRAY_BUFFER, uvs.flatten.size * Fiddle::SIZEOF_FLOAT, uvs.flatten.pack("f*"), GL_STATIC_DRAW)
|
139
|
-
end
|
140
|
-
|
141
|
-
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
142
|
-
end
|
143
|
-
|
144
|
-
def configure_vao
|
145
|
-
glBindVertexArray(@vertex_array_id)
|
146
|
-
gl_error?
|
147
|
-
|
148
|
-
# index, size, type, normalized, stride, pointer
|
149
|
-
# vertices (positions)
|
150
|
-
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
151
|
-
gl_error?
|
152
|
-
|
153
|
-
# inPosition
|
154
|
-
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
155
|
-
gl_error?
|
156
|
-
# colors
|
157
|
-
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
158
|
-
# inColor
|
159
|
-
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
160
|
-
gl_error?
|
161
|
-
# normals
|
162
|
-
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
163
|
-
# inNormal
|
164
|
-
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
|
165
|
-
gl_error?
|
166
|
-
|
167
|
-
if has_texture?
|
168
|
-
# uvs
|
169
|
-
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
170
|
-
# inUV
|
171
|
-
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
172
|
-
gl_error?
|
173
|
-
end
|
174
|
-
|
175
|
-
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
176
|
-
glBindVertexArray(0)
|
177
|
-
end
|
178
|
-
|
179
|
-
def build_collision_tree
|
180
|
-
@aabb_tree = AABBTree.new
|
181
|
-
|
182
|
-
@faces.each do |face|
|
183
|
-
box = BoundingBox.new
|
184
|
-
box.min = face.vertices.first.dup
|
185
|
-
box.max = face.vertices.first.dup
|
186
|
-
|
187
|
-
face.vertices.each do |vertex|
|
188
|
-
if vertex.sum < box.min.sum
|
189
|
-
box.min = vertex.dup
|
190
|
-
elsif vertex.sum > box.max.sum
|
191
|
-
box.max = vertex.dup
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# FIXME: Handle negatives
|
196
|
-
box.min *= 1.5
|
197
|
-
box.max *= 1.5
|
198
|
-
@aabb_tree.insert(face, box)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def has_texture?
|
203
|
-
@has_texture
|
204
|
-
end
|
205
|
-
|
206
|
-
def release_gl_resources
|
207
|
-
if @vertex_array_id
|
208
|
-
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Model
|
3
|
+
attr_accessor :objects, :materials, :vertices, :uvs, :texures, :normals, :faces, :colors, :bones, :material_file,
|
4
|
+
:current_material, :current_object, :vertex_count, :smoothing
|
5
|
+
attr_reader :position, :bounding_box, :textured_material, :file_path, :positions_buffer_id, :colors_buffer_id,
|
6
|
+
:normals_buffer_id, :uvs_buffer_id, :textures_buffer_id, :vertex_array_id, :aabb_tree,
|
7
|
+
:vertices_count
|
8
|
+
|
9
|
+
def initialize(file_path:)
|
10
|
+
@file_path = file_path
|
11
|
+
|
12
|
+
@material_file = nil
|
13
|
+
@current_object = nil
|
14
|
+
@current_material = nil
|
15
|
+
@vertex_count = 0
|
16
|
+
|
17
|
+
@objects = []
|
18
|
+
@materials = {}
|
19
|
+
@vertices = []
|
20
|
+
@colors = []
|
21
|
+
@uvs = []
|
22
|
+
@normals = []
|
23
|
+
@faces = []
|
24
|
+
@bones = []
|
25
|
+
@smoothing = 0
|
26
|
+
|
27
|
+
@vertices_count = 0
|
28
|
+
|
29
|
+
@bounding_box = BoundingBox.new
|
30
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
31
|
+
|
32
|
+
type = File.basename(file_path).split(".").last.to_sym
|
33
|
+
parser = Model::Parser.find(type)
|
34
|
+
raise "Unsupported model type '.#{type}', supported models are: #{Model::Parser.supported_formats}" unless parser
|
35
|
+
|
36
|
+
parse(parser)
|
37
|
+
|
38
|
+
@vertices_count = @vertices.size
|
39
|
+
|
40
|
+
@has_texture = false
|
41
|
+
|
42
|
+
@materials.each do |_key, material|
|
43
|
+
@has_texture = true if material.texture_id
|
44
|
+
end
|
45
|
+
|
46
|
+
allocate_gl_objects
|
47
|
+
populate_vertex_buffer
|
48
|
+
configure_vao
|
49
|
+
|
50
|
+
@objects.each { |o| @vertex_count += o.vertices.size }
|
51
|
+
|
52
|
+
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
|
53
|
+
# build_collision_tree
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse(parser)
|
57
|
+
parser.new(self).parse
|
58
|
+
end
|
59
|
+
|
60
|
+
def calculate_bounding_box(vertices, bounding_box)
|
61
|
+
unless bounding_box.min.x.is_a?(Float)
|
62
|
+
vertex = vertices.last
|
63
|
+
bounding_box.min.x = vertex.x
|
64
|
+
bounding_box.min.y = vertex.y
|
65
|
+
bounding_box.min.z = vertex.z
|
66
|
+
|
67
|
+
bounding_box.max.x = vertex.x
|
68
|
+
bounding_box.max.y = vertex.y
|
69
|
+
bounding_box.max.z = vertex.z
|
70
|
+
end
|
71
|
+
|
72
|
+
vertices.each do |vertex|
|
73
|
+
bounding_box.min.x = vertex.x if vertex.x <= bounding_box.min.x
|
74
|
+
bounding_box.min.y = vertex.y if vertex.y <= bounding_box.min.y
|
75
|
+
bounding_box.min.z = vertex.z if vertex.z <= bounding_box.min.z
|
76
|
+
|
77
|
+
bounding_box.max.x = vertex.x if vertex.x >= bounding_box.max.x
|
78
|
+
bounding_box.max.y = vertex.y if vertex.y >= bounding_box.max.y
|
79
|
+
bounding_box.max.z = vertex.z if vertex.z >= bounding_box.max.z
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def allocate_gl_objects
|
84
|
+
# Allocate arrays for future use
|
85
|
+
@vertex_array_id = nil
|
86
|
+
buffer = " " * 4
|
87
|
+
glGenVertexArrays(1, buffer)
|
88
|
+
@vertex_array_id = buffer.unpack1("L2")
|
89
|
+
|
90
|
+
# Allocate buffers for future use
|
91
|
+
@positions_buffer_id = nil
|
92
|
+
buffer = " " * 4
|
93
|
+
glGenBuffers(1, buffer)
|
94
|
+
@positions_buffer_id = buffer.unpack1("L2")
|
95
|
+
|
96
|
+
@colors_buffer_id = nil
|
97
|
+
buffer = " " * 4
|
98
|
+
glGenBuffers(1, buffer)
|
99
|
+
@colors_buffer_id = buffer.unpack1("L2")
|
100
|
+
|
101
|
+
@normals_buffer_id = nil
|
102
|
+
buffer = " " * 4
|
103
|
+
glGenBuffers(1, buffer)
|
104
|
+
@normals_buffer_id = buffer.unpack1("L2")
|
105
|
+
|
106
|
+
@uvs_buffer_id = nil
|
107
|
+
buffer = " " * 4
|
108
|
+
glGenBuffers(1, buffer)
|
109
|
+
@uvs_buffer_id = buffer.unpack1("L2")
|
110
|
+
end
|
111
|
+
|
112
|
+
def populate_vertex_buffer
|
113
|
+
pos = []
|
114
|
+
colors = []
|
115
|
+
norms = []
|
116
|
+
uvs = []
|
117
|
+
|
118
|
+
@faces.each do |face|
|
119
|
+
pos << face.vertices.map { |vert| [vert.x, vert.y, vert.z] }
|
120
|
+
colors << face.colors.map { |color| [color.red, color.green, color.blue] }
|
121
|
+
norms << face.normals.map { |vert| [vert.x, vert.y, vert.z, vert.weight] }
|
122
|
+
|
123
|
+
uvs << face.uvs.map { |vert| [vert.x, vert.y, vert.z] } if has_texture?
|
124
|
+
end
|
125
|
+
|
126
|
+
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
127
|
+
glBufferData(GL_ARRAY_BUFFER, pos.flatten.size * Fiddle::SIZEOF_FLOAT, pos.flatten.pack("f*"), GL_STATIC_DRAW)
|
128
|
+
|
129
|
+
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
130
|
+
glBufferData(GL_ARRAY_BUFFER, colors.flatten.size * Fiddle::SIZEOF_FLOAT, colors.flatten.pack("f*"),
|
131
|
+
GL_STATIC_DRAW)
|
132
|
+
|
133
|
+
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
134
|
+
glBufferData(GL_ARRAY_BUFFER, norms.flatten.size * Fiddle::SIZEOF_FLOAT, norms.flatten.pack("f*"), GL_STATIC_DRAW)
|
135
|
+
|
136
|
+
if has_texture?
|
137
|
+
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
138
|
+
glBufferData(GL_ARRAY_BUFFER, uvs.flatten.size * Fiddle::SIZEOF_FLOAT, uvs.flatten.pack("f*"), GL_STATIC_DRAW)
|
139
|
+
end
|
140
|
+
|
141
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
142
|
+
end
|
143
|
+
|
144
|
+
def configure_vao
|
145
|
+
glBindVertexArray(@vertex_array_id)
|
146
|
+
gl_error?
|
147
|
+
|
148
|
+
# index, size, type, normalized, stride, pointer
|
149
|
+
# vertices (positions)
|
150
|
+
glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id)
|
151
|
+
gl_error?
|
152
|
+
|
153
|
+
# inPosition
|
154
|
+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
155
|
+
gl_error?
|
156
|
+
# colors
|
157
|
+
glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id)
|
158
|
+
# inColor
|
159
|
+
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
160
|
+
gl_error?
|
161
|
+
# normals
|
162
|
+
glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id)
|
163
|
+
# inNormal
|
164
|
+
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, nil)
|
165
|
+
gl_error?
|
166
|
+
|
167
|
+
if has_texture?
|
168
|
+
# uvs
|
169
|
+
glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id)
|
170
|
+
# inUV
|
171
|
+
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, nil)
|
172
|
+
gl_error?
|
173
|
+
end
|
174
|
+
|
175
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0)
|
176
|
+
glBindVertexArray(0)
|
177
|
+
end
|
178
|
+
|
179
|
+
def build_collision_tree
|
180
|
+
@aabb_tree = AABBTree.new
|
181
|
+
|
182
|
+
@faces.each do |face|
|
183
|
+
box = BoundingBox.new
|
184
|
+
box.min = face.vertices.first.dup
|
185
|
+
box.max = face.vertices.first.dup
|
186
|
+
|
187
|
+
face.vertices.each do |vertex|
|
188
|
+
if vertex.sum < box.min.sum
|
189
|
+
box.min = vertex.dup
|
190
|
+
elsif vertex.sum > box.max.sum
|
191
|
+
box.max = vertex.dup
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# FIXME: Handle negatives
|
196
|
+
box.min *= 1.5
|
197
|
+
box.max *= 1.5
|
198
|
+
@aabb_tree.insert(face, box)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def has_texture?
|
203
|
+
@has_texture
|
204
|
+
end
|
205
|
+
|
206
|
+
def release_gl_resources
|
207
|
+
if @vertex_array_id
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
module ModelCache
|
3
|
-
CACHE = {}
|
4
|
-
|
5
|
-
def self.find_or_cache(manifest:)
|
6
|
-
model_file = manifest.file_path + "/model/#{manifest.model}"
|
7
|
-
|
8
|
-
type = File.basename(model_file).split(".").last.to_sym
|
9
|
-
|
10
|
-
if model = load_model_from_cache(type, model_file)
|
11
|
-
model
|
12
|
-
else
|
13
|
-
model = CyberarmEngine::Model.new(file_path: model_file)
|
14
|
-
cache_model(type, model_file, model)
|
15
|
-
|
16
|
-
model
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.load_model_from_cache(type, model_file)
|
21
|
-
return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
|
22
|
-
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.cache_model(type, model_file, model)
|
27
|
-
CACHE[type] = {} unless CACHE[type].is_a?(Hash)
|
28
|
-
CACHE[type][model_file] = model
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
module ModelCache
|
3
|
+
CACHE = {}
|
4
|
+
|
5
|
+
def self.find_or_cache(manifest:)
|
6
|
+
model_file = manifest.file_path + "/model/#{manifest.model}"
|
7
|
+
|
8
|
+
type = File.basename(model_file).split(".").last.to_sym
|
9
|
+
|
10
|
+
if model = load_model_from_cache(type, model_file)
|
11
|
+
model
|
12
|
+
else
|
13
|
+
model = CyberarmEngine::Model.new(file_path: model_file)
|
14
|
+
cache_model(type, model_file, model)
|
15
|
+
|
16
|
+
model
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.load_model_from_cache(type, model_file)
|
21
|
+
return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])
|
22
|
+
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.cache_model(type, model_file, model)
|
27
|
+
CACHE[type] = {} unless CACHE[type].is_a?(Hash)
|
28
|
+
CACHE[type][model_file] = model
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class Light
|
3
|
-
DIRECTIONAL = 0
|
4
|
-
POINT = 1
|
5
|
-
SPOT = 2
|
6
|
-
|
7
|
-
attr_reader :light_id
|
8
|
-
attr_accessor :type, :ambient, :diffuse, :specular, :position, :direction, :intensity
|
9
|
-
|
10
|
-
def initialize(
|
11
|
-
id:,
|
12
|
-
type: Light::POINT,
|
13
|
-
ambient: Vector.new(0.5, 0.5, 0.5),
|
14
|
-
diffuse: Vector.new(1, 1, 1),
|
15
|
-
specular: Vector.new(0.2, 0.2, 0.2),
|
16
|
-
position: Vector.new(0, 0, 0),
|
17
|
-
direction: Vector.new(0, 0, 0),
|
18
|
-
intensity: 1
|
19
|
-
)
|
20
|
-
@light_id = id
|
21
|
-
@type = type
|
22
|
-
|
23
|
-
@ambient = ambient
|
24
|
-
@diffuse = diffuse
|
25
|
-
@specular = specular
|
26
|
-
@position = position
|
27
|
-
@direction = direction
|
28
|
-
|
29
|
-
@intensity = intensity
|
30
|
-
end
|
31
|
-
|
32
|
-
def draw
|
33
|
-
glLightfv(@light_id, GL_AMBIENT, convert(@ambient).pack("f*"))
|
34
|
-
glLightfv(@light_id, GL_DIFFUSE, convert(@diffuse, true).pack("f*"))
|
35
|
-
glLightfv(@light_id, GL_SPECULAR, convert(@specular, true).pack("f*"))
|
36
|
-
glLightfv(@light_id, GL_POSITION, convert(@position).pack("f*"))
|
37
|
-
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
|
38
|
-
glEnable(GL_LIGHTING)
|
39
|
-
glEnable(@light_id)
|
40
|
-
end
|
41
|
-
|
42
|
-
def convert(struct, apply_intensity = false)
|
43
|
-
if apply_intensity
|
44
|
-
struct.to_a.compact.map { |i| i * @intensity }
|
45
|
-
else
|
46
|
-
struct.to_a.compact
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class Light
|
3
|
+
DIRECTIONAL = 0
|
4
|
+
POINT = 1
|
5
|
+
SPOT = 2
|
6
|
+
|
7
|
+
attr_reader :light_id
|
8
|
+
attr_accessor :type, :ambient, :diffuse, :specular, :position, :direction, :intensity
|
9
|
+
|
10
|
+
def initialize(
|
11
|
+
id:,
|
12
|
+
type: Light::POINT,
|
13
|
+
ambient: Vector.new(0.5, 0.5, 0.5),
|
14
|
+
diffuse: Vector.new(1, 1, 1),
|
15
|
+
specular: Vector.new(0.2, 0.2, 0.2),
|
16
|
+
position: Vector.new(0, 0, 0),
|
17
|
+
direction: Vector.new(0, 0, 0),
|
18
|
+
intensity: 1
|
19
|
+
)
|
20
|
+
@light_id = id
|
21
|
+
@type = type
|
22
|
+
|
23
|
+
@ambient = ambient
|
24
|
+
@diffuse = diffuse
|
25
|
+
@specular = specular
|
26
|
+
@position = position
|
27
|
+
@direction = direction
|
28
|
+
|
29
|
+
@intensity = intensity
|
30
|
+
end
|
31
|
+
|
32
|
+
def draw
|
33
|
+
glLightfv(@light_id, GL_AMBIENT, convert(@ambient).pack("f*"))
|
34
|
+
glLightfv(@light_id, GL_DIFFUSE, convert(@diffuse, true).pack("f*"))
|
35
|
+
glLightfv(@light_id, GL_SPECULAR, convert(@specular, true).pack("f*"))
|
36
|
+
glLightfv(@light_id, GL_POSITION, convert(@position).pack("f*"))
|
37
|
+
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1)
|
38
|
+
glEnable(GL_LIGHTING)
|
39
|
+
glEnable(@light_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def convert(struct, apply_intensity = false)
|
43
|
+
if apply_intensity
|
44
|
+
struct.to_a.compact.map { |i| i * @intensity }
|
45
|
+
else
|
46
|
+
struct.to_a.compact
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
module CyberarmEngine
|
2
|
-
class OrthographicCamera
|
3
|
-
attr_accessor :position, :orientation, :zoom, :left, :right, :bottom, :top,
|
4
|
-
:min_view_distance, :max_view_distance
|
5
|
-
|
6
|
-
def initialize(
|
7
|
-
position:, right:, top:, orientation: Vector.new(0, 0, 0),
|
8
|
-
zoom: 1, left: 0, bottom: 0,
|
9
|
-
min_view_distance: 0.1, max_view_distance: 200.0
|
10
|
-
)
|
11
|
-
@position = position
|
12
|
-
@orientation = orientation
|
13
|
-
|
14
|
-
@zoom = zoom
|
15
|
-
|
16
|
-
@left = left
|
17
|
-
@right = right
|
18
|
-
@bottom = bottom
|
19
|
-
@top = top
|
20
|
-
|
21
|
-
@min_view_distance = min_view_distance
|
22
|
-
@max_view_distance = max_view_distance
|
23
|
-
end
|
24
|
-
|
25
|
-
# Immediate mode renderering fallback
|
26
|
-
def draw
|
27
|
-
glMatrixMode(GL_PROJECTION)
|
28
|
-
glLoadIdentity
|
29
|
-
glOrtho(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
30
|
-
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
31
|
-
glRotatef(@orientation.x, 1, 0, 0)
|
32
|
-
glRotatef(@orientation.y, 0, 1, 0)
|
33
|
-
glTranslatef(-@position.x, -@position.y, -@position.z)
|
34
|
-
glMatrixMode(GL_MODELVIEW)
|
35
|
-
glLoadIdentity
|
36
|
-
end
|
37
|
-
|
38
|
-
def projection_matrix
|
39
|
-
Transform.orthographic(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
40
|
-
end
|
41
|
-
|
42
|
-
def view_matrix
|
43
|
-
Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
module CyberarmEngine
|
2
|
+
class OrthographicCamera
|
3
|
+
attr_accessor :position, :orientation, :zoom, :left, :right, :bottom, :top,
|
4
|
+
:min_view_distance, :max_view_distance
|
5
|
+
|
6
|
+
def initialize(
|
7
|
+
position:, right:, top:, orientation: Vector.new(0, 0, 0),
|
8
|
+
zoom: 1, left: 0, bottom: 0,
|
9
|
+
min_view_distance: 0.1, max_view_distance: 200.0
|
10
|
+
)
|
11
|
+
@position = position
|
12
|
+
@orientation = orientation
|
13
|
+
|
14
|
+
@zoom = zoom
|
15
|
+
|
16
|
+
@left = left
|
17
|
+
@right = right
|
18
|
+
@bottom = bottom
|
19
|
+
@top = top
|
20
|
+
|
21
|
+
@min_view_distance = min_view_distance
|
22
|
+
@max_view_distance = max_view_distance
|
23
|
+
end
|
24
|
+
|
25
|
+
# Immediate mode renderering fallback
|
26
|
+
def draw
|
27
|
+
glMatrixMode(GL_PROJECTION)
|
28
|
+
glLoadIdentity
|
29
|
+
glOrtho(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
30
|
+
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
31
|
+
glRotatef(@orientation.x, 1, 0, 0)
|
32
|
+
glRotatef(@orientation.y, 0, 1, 0)
|
33
|
+
glTranslatef(-@position.x, -@position.y, -@position.z)
|
34
|
+
glMatrixMode(GL_MODELVIEW)
|
35
|
+
glLoadIdentity
|
36
|
+
end
|
37
|
+
|
38
|
+
def projection_matrix
|
39
|
+
Transform.orthographic(@left, @right, @bottom, @top, @min_view_distance, @max_view_distance)
|
40
|
+
end
|
41
|
+
|
42
|
+
def view_matrix
|
43
|
+
Transform.translate_3d(@position * -1) * Transform.rotate_3d(@orientation)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|