Class: Blender3d::Model
- Inherits:
-
Object
- Object
- Blender3d::Model
- Defined in:
- lib/blender-3d/model.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#pointers ⇒ Object
readonly
Returns the value of attribute pointers.
Class Method Summary collapse
Instance Method Summary collapse
- #create_reader(file) ⇒ Object
- #deserialize(file) ⇒ Object
- #dna_block ⇒ Object
-
#initialize(file = nil) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(file = nil) ⇒ Model
Returns a new instance of Model.
9 10 11 12 |
# File 'lib/blender-3d/model.rb', line 9 def initialize(file = nil) @blocks = [] deserialize(file) if file end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
3 4 5 |
# File 'lib/blender-3d/model.rb', line 3 def blocks @blocks end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/blender-3d/model.rb', line 3 def header @header end |
#pointers ⇒ Object (readonly)
Returns the value of attribute pointers.
3 4 5 |
# File 'lib/blender-3d/model.rb', line 3 def pointers @pointers end |
Class Method Details
.from_file(path) ⇒ Object
5 6 7 |
# File 'lib/blender-3d/model.rb', line 5 def self.from_file(path) File.open(path, 'rb') { |file| new(file) } end |
Instance Method Details
#create_reader(file) ⇒ Object
42 43 44 |
# File 'lib/blender-3d/model.rb', line 42 def create_reader(file) ObjectReader.new(file, self) end |
#deserialize(file) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/blender-3d/model.rb', line 14 def deserialize(file) @header = FileHeader.new(file) reader = create_reader(file) @blocks.clear loop do @blocks << FileBlock.new(reader) break if reader.tell == reader.file.size end dna_block = self.dna_block return self unless dna_block @blocks.select { |block| block.type_index != 0 }.each do |block| block.type = dna_block.data.structures[block.type_index] block.parse_data(self) end @pointers = {} @blocks.each { |block| @pointers[block.pointer] = block.data } self end |
#dna_block ⇒ Object
38 39 40 |
# File 'lib/blender-3d/model.rb', line 38 def dna_block @blocks.find { |block| block.code == 'DNA1' } end |