Class: Blender3d::SimpleType

Inherits:
Object
  • Object
show all
Defined in:
lib/blender-3d/types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SimpleType

Returns a new instance of SimpleType.



5
6
7
# File 'lib/blender-3d/types.rb', line 5

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/blender-3d/types.rb', line 3

def name
  @name
end

Instance Method Details

#inspectObject



13
14
15
# File 'lib/blender-3d/types.rb', line 13

def inspect
  @name
end

#read(reader) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/blender-3d/types.rb', line 17

def read(reader)
  case @name
    when 'char'     then reader.read(1)
    when 'double'   then reader.read_double
    when 'float'    then reader.read_float
    when 'int'      then reader.read_int32
    when 'int64_t'  then reader.read_int64
    when 'long'     then reader.read_int32
    when 'short'    then reader.read_int16
    when 'uchar'    then reader.read_uint8
    when 'uint64_t' then reader.read_uint64
    when 'ulong'    then reader.read_uint32
    when 'ushort'   then reader.read_uint16
    else
      dna = reader.model.dna_block.data
      struct = dna.structures.find { |struct| struct.name == @name }
      return struct.read(reader) if struct
      length = dna.types.find { |name, size| name == @name }&.last
      return reader.read(length) if length
      raise 'type not found'
  end
end

#to_sObject



9
10
11
# File 'lib/blender-3d/types.rb', line 9

def to_s
  @name
end