Class: Engine::Mesh

Inherits:
Object
  • Object
show all
Defined in:
lib/engine/mesh.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mesh_file) ⇒ Mesh

Returns a new instance of Mesh.



8
9
10
11
# File 'lib/engine/mesh.rb', line 8

def initialize(mesh_file)
  @vertex_data = Mesh.open_vertex(mesh_file)
  @index_data = Mesh.open_index(mesh_file)
end

Instance Attribute Details

#index_dataObject (readonly)

Returns the value of attribute index_data.



5
6
7
# File 'lib/engine/mesh.rb', line 5

def index_data
  @index_data
end

#vertex_dataObject (readonly)

Returns the value of attribute vertex_data.



5
6
7
# File 'lib/engine/mesh.rb', line 5

def vertex_data
  @vertex_data
end

Class Method Details

.for(mesh_file) ⇒ Object



13
14
15
# File 'lib/engine/mesh.rb', line 13

def self.for(mesh_file)
  mesh_cache[mesh_file]
end

.index_cacheObject



37
38
39
40
41
# File 'lib/engine/mesh.rb', line 37

def self.index_cache
  @index_data_cache ||= Hash.new do |hash, key|
    hash[key] = File.readlines(key).reject{|l| l == ""}.map(&:to_i)
  end
end

.mesh_cacheObject



17
18
19
20
21
# File 'lib/engine/mesh.rb', line 17

def self.mesh_cache
  @mesh_cache ||= Hash.new do |hash, key|
    hash[key] = new(key)
  end
end

.open_index(mesh_file) ⇒ Object



33
34
35
# File 'lib/engine/mesh.rb', line 33

def self.open_index(mesh_file)
  index_cache[File.join(GAME_DIR, "_imported", mesh_file + ".index_data")]
end

.open_vertex(mesh_file) ⇒ Object



23
24
25
# File 'lib/engine/mesh.rb', line 23

def self.open_vertex(mesh_file)
  vertex_cache[File.join(GAME_DIR, "_imported", mesh_file + ".vertex_data")]
end

.vertex_cacheObject



27
28
29
30
31
# File 'lib/engine/mesh.rb', line 27

def self.vertex_cache
  @index_data_cache ||= Hash.new do |hash, key|
    hash[key] = File.readlines(key).reject{|l| l == ""}.map(&:to_f)
  end
end