Class: Engine::Mesh

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

allowed_class?, #awake, get_class, included, register_class, #uuid

Instance Attribute Details

#mesh_fileObject (readonly)

Returns the value of attribute mesh_file.



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

def mesh_file
  @mesh_file
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Class Method Details

.for(mesh_file, source: :game) ⇒ Object



25
26
27
28
# File 'lib/engine/mesh.rb', line 25

def self.for(mesh_file, source: :game)
  cache_key = [mesh_file, source]
  mesh_cache[cache_key] ||= create(mesh_file: mesh_file, source: source)
end

.from_serializable_data(data) ⇒ Object



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

def self.from_serializable_data(data)
  self.for(data[:mesh_file], source: (data[:source] || :game).to_sym)
end

.index_cacheObject



48
49
50
51
52
# File 'lib/engine/mesh.rb', line 48

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

.load_index(base_path) ⇒ Object



44
45
46
# File 'lib/engine/mesh.rb', line 44

def self.load_index(base_path)
  index_cache[base_path + ".index_data"]
end

.load_vertex(base_path) ⇒ Object



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

def self.load_vertex(base_path)
  vertex_cache[base_path + ".vertex_data"]
end

.mesh_cacheObject



30
31
32
# File 'lib/engine/mesh.rb', line 30

def self.mesh_cache
  @mesh_cache ||= {}
end

.quadObject



54
55
56
# File 'lib/engine/mesh.rb', line 54

def self.quad
  @quad ||= QuadMesh.new
end

.vertex_cacheObject



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

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

Instance Method Details

#index_dataObject



21
22
23
# File 'lib/engine/mesh.rb', line 21

def index_data
  @index_data ||= Mesh.load_index(base_path)
end

#serializable_dataObject



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

def serializable_data
  { mesh_file: @mesh_file, source: @source }
end

#vertex_dataObject



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

def vertex_data
  @vertex_data ||= Mesh.load_vertex(base_path)
end