Class: Tracksperanto::Tool::MoveToFirst

Inherits:
Base
  • Object
show all
Defined in:
lib/tools/move_to_first.rb

Overview

Sometimes your tracked sequence has been loaded from say frame 73282381, but you want to import into an application that expects the trackers to start at frame 1. This tool autoslips everything so that your trackers start at frame 1.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize

Methods included from Parameters

#parameter, #parameters

Methods included from SimpleExport

#just_export

Methods included from ConstName

#const_name

Methods included from BlockInit

#initialize

Methods included from Casts

#cast_to_bool, #cast_to_float, #cast_to_int, #cast_to_string

Constructor Details

This class inherits a constructor from Tracksperanto::Tool::Base

Class Method Details

.action_descriptionObject



5
6
7
# File 'lib/tools/move_to_first.rb', line 5

def self.action_description
  "Move all the keyframes in time so that the track starts at frame 1"
end

Instance Method Details

#end_exportObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tools/move_to_first.rb', line 34

def end_export
  actual_start = @start_frames.sort.shift
  
  @exporter.start_export(@width, @height)
  @buf.each do | tracker |
    @exporter.start_tracker_segment(tracker.name)
    tracker.each do | kf |
      @exporter.export_point(kf.frame - actual_start, kf.abs_x, kf.abs_y, kf.residual)
    end
    @exporter.end_tracker_segment
  end
  @exporter.end_export
  
  @buf.clear
end

#end_tracker_segmentObject



20
21
22
23
# File 'lib/tools/move_to_first.rb', line 20

def end_tracker_segment
  @buf.push(@current)
  @registered = false
end

#export_point(frame, float_x, float_y, float_residual) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/tools/move_to_first.rb', line 25

def export_point(frame, float_x, float_y, float_residual)
  @current.keyframe!(:frame => frame, :abs_x => float_x, :abs_y => float_y, :residual => float_residual)
  return if @registered
  
  # Note where this tracker starts
  @start_frames.push(frame)
  @registered = true
end

#start_export(width, height) ⇒ Object



9
10
11
12
13
14
# File 'lib/tools/move_to_first.rb', line 9

def start_export(width, height)
  @width, @height = width, height
  @start_frames = []
  @buf = Obuf.new
  @registered = false
end

#start_tracker_segment(tracker_name) ⇒ Object



16
17
18
# File 'lib/tools/move_to_first.rb', line 16

def start_tracker_segment(tracker_name)
  @current = Tracksperanto::Tracker.new(:name => tracker_name)
end