Class: Blender3d::ObjectReader
- Inherits:
-
Object
- Object
- Blender3d::ObjectReader
- Defined in:
- lib/blender-3d/object_reader.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(file, model = nil) ⇒ ObjectReader
constructor
A new instance of ObjectReader.
- #read(length) ⇒ Object
- #read_string ⇒ Object
- #seek(position) ⇒ Object
- #tell ⇒ Object
Constructor Details
#initialize(file, model = nil) ⇒ ObjectReader
Returns a new instance of ObjectReader.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/blender-3d/object_reader.rb', line 6 def initialize(file, model = nil) @file, @model = file, model endian = @model.header.endian_code %w'c s l q'.each.with_index do |code, i| bytes = 1 << i bits = 8 * bytes name = 'int' + bits.to_s define_reader name, bytes, code + endian define_reader 'u' + name, bytes, code.upcase + endian end code = @model.header.little_endian? ? 'e' : 'g' define_reader 'float', 4, code define_reader 'double', 8, code.upcase define_reader 'pointer', @model.header.pointer_size, @model.header.size_code + endian end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/blender-3d/object_reader.rb', line 3 def file @file end |
#model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/blender-3d/object_reader.rb', line 4 def model @model end |
Instance Method Details
#read(length) ⇒ Object
29 30 31 |
# File 'lib/blender-3d/object_reader.rb', line 29 def read(length) @file.read(length) end |
#read_string ⇒ Object
33 34 35 |
# File 'lib/blender-3d/object_reader.rb', line 33 def read_string @file.gets("\0") end |
#seek(position) ⇒ Object
37 38 39 |
# File 'lib/blender-3d/object_reader.rb', line 37 def seek(position) @file.seek(position) end |
#tell ⇒ Object
41 42 43 |
# File 'lib/blender-3d/object_reader.rb', line 41 def tell @file.tell end |