Class: MagicaVoxel::Reader
- Inherits:
-
Object
- Object
- MagicaVoxel::Reader
- Defined in:
- lib/magica_voxel/reader.rb
Overview
The Data Reader
Class Method Summary collapse
-
.open(io) {|new(io)| ... } ⇒ Object
Open IO stream.
Instance Method Summary collapse
-
#dict ⇒ Hash
Read Dictionary.
-
#frames ⇒ Array<MagicaVoxel::Frame>
Read Frames.
-
#imap ⇒ Array<Number>
Read Pattle Index MAP.
-
#initialize(io) ⇒ Reader
constructor
A new instance of Reader.
-
#int32 ⇒ Number
Read int32.
-
#int32_array ⇒ Array<Number>
Read Int32 Array.
-
#pattle ⇒ Array<MagicaVoxel::Color]
Read Pattle.
-
#rgba ⇒ MagicaVoxel::Color
Read RGBA.
-
#shape_model ⇒ MagicaVoxel::Shape::Model
Read Shape’s Model.
-
#string ⇒ String
Read String.
-
#string_array ⇒ Array<String>
Read String Array.
-
#voxel ⇒ MagicaVoxel::Voxel
Read Voxel.
-
#voxels ⇒ Array<MagicaVoxel::Voxel>
Read Voxels.
Constructor Details
#initialize(io) ⇒ Reader
Returns a new instance of Reader.
23 24 25 |
# File 'lib/magica_voxel/reader.rb', line 23 def initialize(io) @io = io end |
Class Method Details
.open(io) {|new(io)| ... } ⇒ Object
Open IO stream
14 15 16 17 18 |
# File 'lib/magica_voxel/reader.rb', line 14 def open(io) io = io.is_a?(IO) ? io : StringIO.new(io) yield new(io) io.close end |
Instance Method Details
#dict ⇒ Hash
Read Dictionary
50 51 52 |
# File 'lib/magica_voxel/reader.rb', line 50 def dict Hash[*Array.new(int32 * 2).map { string }] end |
#frames ⇒ Array<MagicaVoxel::Frame>
Read Frames
77 78 79 |
# File 'lib/magica_voxel/reader.rb', line 77 def frames Array.new(int32).map { Frame.new(dict) } end |
#imap ⇒ Array<Number>
Read Pattle Index MAP
105 106 107 |
# File 'lib/magica_voxel/reader.rb', line 105 def imap Array.new(256).map { int32 } end |
#int32 ⇒ Number
Read int32
32 33 34 |
# File 'lib/magica_voxel/reader.rb', line 32 def int32 @io.read(4).unpack1('l') end |
#int32_array ⇒ Array<Number>
Read Int32 Array
59 60 61 |
# File 'lib/magica_voxel/reader.rb', line 59 def int32_array Array.new(int32).map { int32 } end |
#pattle ⇒ Array<MagicaVoxel::Color]
Read Pattle
86 87 88 |
# File 'lib/magica_voxel/reader.rb', line 86 def pattle Array.new(256).map { rgba } end |
#rgba ⇒ MagicaVoxel::Color
Read RGBA
95 96 97 98 |
# File 'lib/magica_voxel/reader.rb', line 95 def rgba r, g, b, a = @io.read(4).unpack('CCCC') Color.new(r, g, b, a) end |
#shape_model ⇒ MagicaVoxel::Shape::Model
Read Shape’s Model
133 134 135 |
# File 'lib/magica_voxel/reader.rb', line 133 def shape_model Array.new(int32).map { Shape::Model.new(int32, dict) } end |
#string ⇒ String
Read String
41 42 43 |
# File 'lib/magica_voxel/reader.rb', line 41 def string @io.read(int32) end |
#string_array ⇒ Array<String>
Read String Array
68 69 70 |
# File 'lib/magica_voxel/reader.rb', line 68 def string_array Array.new(int32).map { string } end |
#voxel ⇒ MagicaVoxel::Voxel
Read Voxel
123 124 125 126 |
# File 'lib/magica_voxel/reader.rb', line 123 def voxel x, y, z, i = @io.read.unpack('cccC') Voxel.new(x, y, z, i) end |
#voxels ⇒ Array<MagicaVoxel::Voxel>
Read Voxels
114 115 116 |
# File 'lib/magica_voxel/reader.rb', line 114 def voxels Array.new(int32).map { voxel } end |