Class: Engine::ObjImporter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, destination_vertex, destination_index) ⇒ ObjImporter

Returns a new instance of ObjImporter.



7
8
9
10
11
# File 'lib/engine/importers/obj_importer.rb', line 7

def initialize(source, destination_vertex, destination_index)
  @source = source
  @destination_vertex = destination_vertex
  @destination_index = destination_index
end

Instance Attribute Details

#destination_indexObject (readonly)

Returns the value of attribute destination_index.



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

def destination_index
  @destination_index
end

#destination_vertexObject (readonly)

Returns the value of attribute destination_vertex.



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

def destination_vertex
  @destination_vertex
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#importObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/engine/importers/obj_importer.rb', line 13

def import
  obj_file = Engine::ObjFile.new(source)

  vertex_data = obj_file.vertex_data

  FileUtils.mkdir_p(File.dirname(destination_vertex)) unless File.exist?(destination_vertex)
  File.delete(destination_vertex) if File.exist?(destination_vertex)
  File.open(destination_vertex, "w") do |file|
    vertex_data.each { |d| file.puts d }
  end

  index_data = obj_file.index_data

  FileUtils.mkdir_p(File.dirname(destination_index)) unless File.exist?(destination_index)
  File.delete(destination_index) if File.exist?(destination_index)
  File.open(destination_index, "w") do |file|
    index_data.each { |i| file.puts i }
  end
end