4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'server/lib/game_machine/wavefront_ext.rb', line 4
def triangle_from_face_components face_components
triangle_vertices = []
face_components.each do |vertex_str|
vertex_str_components = vertex_str.split('/').map { |index| index.size > 0 ? index.to_i : nil }
position_index = vertex_str_components[0]
tex_index = vertex_str_components[1]
normal_index = vertex_str_components[2]
position = vertices[position_index-1]
tex_coordinate = tex_index ? texture_coordinates[tex_index-1] : nil
normal = normal_index ? normals[normal_index-1] : nil
triangle_vertices << Wavefront::Vertex.new(position, tex_coordinate, normal, position_index, tex_index, normal_index)
end
Wavefront::Triangle.new triangle_vertices
end
|