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

included, #parameter, #parameters

Methods included from SimpleExport

#just_export

Methods included from ConstName

#const_name, included

Methods included from BlockInit

#initialize

Methods included from Casts

#cast_to_bool, #cast_to_float, #cast_to_int, #cast_to_string, included

Constructor Details

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

Class Method Details

.action_descriptionObject



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

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

Instance Method Details

#end_exportObject



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

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



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

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

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



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

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



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

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

#start_tracker_segment(tracker_name) ⇒ Object



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

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