Class: Tracksperanto::Tool::Lerp

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

Overview

This tool adds linearly interpolated keyframes BETWEEN the keyframes passing through the exporter

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



4
5
6
# File 'lib/tools/lerp.rb', line 4

def self.action_description
  "Interpolate missing keyframes of all the trackers"
end

Instance Method Details

#end_tracker_segmentObject



8
9
10
11
# File 'lib/tools/lerp.rb', line 8

def end_tracker_segment
  @last_f, @last_x, @last_y, @last_res = nil, nil, nil, nil
  super
end

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tools/lerp.rb', line 13

def export_point(frame, float_x, float_y, float_residual)
  
  if @last_f && (frame - @last_f > 1) # Interpolate!
    interpolated_frames = []
    interpolated_x = []
    lerp(@last_f, @last_x, frame, float_x) do | interp_f, interp_x |
      interpolated_frames << interp_f
      interpolated_x << interp_x
    end
    
    interpolated_y = []
    lerp(@last_f, @last_y, frame, float_y) do | interp_f, interp_y |
      interpolated_y << interp_y
    end
    
    interpolated_res = []
    lerp(@last_f, @last_res, frame, float_residual) do | interp_f, interp_res |
      interpolated_res << interp_res
    end
    
    tuples = interpolated_frames.zip(interpolated_x).zip(interpolated_y).zip(interpolated_res).map{|e| e.flatten }
    tuples.each do | f, x, y, r |
      super(f.to_i, x, y, r)
    end
  else
    super(frame, float_x + (@x_shift || 0), float_y + (@y_shift || 0), float_residual)
  end
  
  @last_f, @last_x, @last_y, @last_res = frame, float_x, float_y, float_residual
end