Class: Tracksperanto::Import::ShakeText

Inherits:
Base
  • Object
show all
Defined in:
lib/import/shake_text.rb

Instance Attribute Summary

Attributes inherited from Base

#height, #progress_block, #width

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

autodetects_size?, distinct_file_ext, inherited, #report_progress

Methods included from ZipTuples

#zip_curve_tuples

Methods included from BlockInit

#initialize

Methods included from Casts

#cast_to_float, #cast_to_int, #cast_to_string, included

Methods included from Safety

included, #safe_reader

Class Method Details

.human_nameObject



4
5
6
# File 'lib/import/shake_text.rb', line 4

def self.human_name
  "Shake .txt tracker file"
end

Instance Method Details

#parse(io) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/import/shake_text.rb', line 8

def parse(io)
  trackers = []
  until io.eof?
    line = io.gets
    if line =~ /TrackName (.+)/
      trackers << Tracksperanto::Tracker.new{|t| t.name = $1 }
      # Toss the next following string - header
      io.gets
    else
      keyframe_values = line.split
      next if keyframe_values.length < 4
      
      trackers[-1].keyframes << Tracksperanto::Keyframe.new do | kf |
        kf.frame = (keyframe_values[0].to_i - 1)
        kf.abs_x = keyframe_values[1]
        kf.abs_y = keyframe_values[2]
        kf.residual = (1 - keyframe_values[3].to_f)
      end
    end
  end
  
  trackers
end