Class: MD2::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/md2/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame_data) ⇒ Frame

Returns a new instance of Frame.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/md2/frame.rb', line 27

def initialize(frame_data)
  @scale = []
  @translation = []
  @vertices = []
  @normal_indices = []
  
  # 3 floats (scale), 3 floats (transl), 16 bytes (name), and variable num of unsigned chars (vertices)
  frame_data = frame_data.unpack("f3f3a16C*")
  3.times { @scale << frame_data.shift }
  3.times { @translation << frame_data.shift }
  @name = frame_data.shift.strip
  while !frame_data.empty?
    packed_vertex = MD2::Vertex.new(frame_data.shift, frame_data.shift, frame_data.shift)
    @vertices << unpack_vertex_data(packed_vertex)
    @normal_indices << frame_data.shift
  end
end

Instance Attribute Details

#nameObject (readonly)

The name of this frame (string)



9
10
11
# File 'lib/md2/frame.rb', line 9

def name
  @name
end

#normal_indicesObject (readonly)

The indices of the normal vectors.



15
16
17
# File 'lib/md2/frame.rb', line 15

def normal_indices
  @normal_indices
end

#scaleObject (readonly)

Float containing X, Y, Z scale values



3
4
5
# File 'lib/md2/frame.rb', line 3

def scale
  @scale
end

#translationObject (readonly)

Float containing X, Y, Z translations



6
7
8
# File 'lib/md2/frame.rb', line 6

def translation
  @translation
end

#verticesObject (readonly)

The vertices for this frame.



12
13
14
# File 'lib/md2/frame.rb', line 12

def vertices
  @vertices
end

Instance Method Details

#reduceObject



17
18
19
20
21
22
23
24
25
# File 'lib/md2/frame.rb', line 17

def reduce
  {        
    :name => name,
    :translation => @translation,
    :scale => @scale,
    :vertices => packed_vertices,
    :normal_indices => normal_indices.flatten
  }
end