Class: Wavefront::File
- Inherits:
-
Object
- Object
- Wavefront::File
- Defined in:
- lib/wavefront/wavefront_file.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
- #compute_vertex_and_index_buffer ⇒ Object
- #compute_vertex_buffer ⇒ Object
- #export(out_path) ⇒ Object
- #export_simple(out_path, export_index_buffer = false) ⇒ Object
-
#initialize(file_path) ⇒ File
constructor
A new instance of File.
- #object ⇒ Object
Constructor Details
#initialize(file_path) ⇒ File
Returns a new instance of File.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wavefront/wavefront_file.rb', line 5 def initialize file_path @file_path = file_path unless /\.obj$/.match @file_path @file_path += ".obj" end @objects = [] file = ::File.new @file_path, 'r' while line = file.gets components = line.split type = components.shift if 'o' == type name = components.first objects << Wavefront::Object.new(name, file) end end #no object was found so let's create one, rewind back to file, and try parsing again if objects.size.zero? file.rewind objects << Wavefront::Object.new("default", file) end file.close end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/wavefront/wavefront_file.rb', line 3 def file_path @file_path end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
3 4 5 |
# File 'lib/wavefront/wavefront_file.rb', line 3 def objects @objects end |
Instance Method Details
#compute_vertex_and_index_buffer ⇒ Object
46 47 48 |
# File 'lib/wavefront/wavefront_file.rb', line 46 def compute_vertex_and_index_buffer object.compute_vertex_and_index_buffer end |
#compute_vertex_buffer ⇒ Object
42 43 44 |
# File 'lib/wavefront/wavefront_file.rb', line 42 def compute_vertex_buffer object.compute_vertex_buffer end |
#export(out_path) ⇒ Object
32 33 34 35 |
# File 'lib/wavefront/wavefront_file.rb', line 32 def export out_path raise "no objects to export!" if objects.size.zero? object.export out_path end |
#export_simple(out_path, export_index_buffer = false) ⇒ Object
37 38 39 40 |
# File 'lib/wavefront/wavefront_file.rb', line 37 def export_simple out_path, export_index_buffer = false raise "no objects to export!" if objects.size.zero? object.export_simple out_path, export_index_buffer end |
#object ⇒ Object
50 51 52 |
# File 'lib/wavefront/wavefront_file.rb', line 50 def object objects.first end |