Class: Engine::ObjImporter
- Inherits:
-
Object
- Object
- Engine::ObjImporter
- Defined in:
- lib/engine/importers/obj_importer.rb
Instance Attribute Summary collapse
-
#destination_index ⇒ Object
readonly
Returns the value of attribute destination_index.
-
#destination_vertex ⇒ Object
readonly
Returns the value of attribute destination_vertex.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(source, destination_vertex, destination_index) ⇒ ObjImporter
constructor
A new instance of ObjImporter.
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_index ⇒ Object (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_vertex ⇒ Object (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 |
#source ⇒ Object (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
#import ⇒ Object
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 |