Class: Tracksperanto::Export::FlameStabilizer

Inherits:
Base
  • Object
show all
Defined in:
lib/export/flame_stabilizer.rb

Overview

TODO: this exporter is MAJORLY slow now

Direct Known Subclasses

FlameStabilizerCornerpin

Constant Summary collapse

COLOR =
"50 50 50"
DATETIME_FORMAT =
'%a %b %d %H:%M:%S %Y'

Instance Attribute Summary

Attributes inherited from Base

#io

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from ConstName

#const_name

Methods included from SimpleExport

#just_export

Constructor Details

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

Class Method Details

.desc_and_extensionObject



7
8
9
# File 'lib/export/flame_stabilizer.rb', line 7

def self.desc_and_extension
  "flame.stabilizer"
end

.human_nameObject



11
12
13
# File 'lib/export/flame_stabilizer.rb', line 11

def self.human_name
  "Flame/Smoke 2D Stabilizer setup"
end

Instance Method Details

#end_exportObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/export/flame_stabilizer.rb', line 22

def end_export
  # Now make another writer, this time for our main IO
  @writer = FlameChannelParser::Builder.new(@io)
  
  # Now we know how many trackers we have so we can write the header
  # data along with NbTrackers
  write_header_with_number_of_trackers(@counter)
  
  # Now write everything that we accumulated earlier into the base IO
  @temp.rewind
  @io.write(@temp.read) until @temp.eof?
  @temp.close!
  
  # Send the ChannelEnd command and list the trackers
  @writer.channel_end
  @counter.times do |i|
    @writer.write_unterminated_block!("tracker", i) do |t|
      t.active true
      t.color_hash!("colour", 0, 100, 0)
      t.fixed_ref true
      t.fixed_x false
      t.fixed_y false
      t.tolerance 100
    end
  end
  
  # Write the finalizing "End"
  @writer.write_loose!("end")
end

#end_tracker_segmentObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/export/flame_stabilizer.rb', line 67

def end_tracker_segment
  # We write these at tracker end since we need to know in advance
  # how many keyframes they should contain
  write_shift_channel("shift/x", @x_shift_values)
  write_shift_channel("shift/y", @y_shift_values)
  
  # And finish with the offset channels. The order of channels is important!
  # (otherwise the last tracker's shift animation is not imported by Flame)
  # https://github.com/guerilla-di/tracksperanto/issues/1
  write_offset_channels
end

#export_point(frame, abs_float_x, abs_float_y, float_residual) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/export/flame_stabilizer.rb', line 57

def export_point(frame, abs_float_x, abs_float_y, float_residual)
  flame_frame = frame + 1
  if @write_first_frame
    export_first_point(flame_frame, abs_float_x, abs_float_y)
    @write_first_frame = false
  else
    export_remaining_point(flame_frame, abs_float_x, abs_float_y)
  end
end

#start_export(img_width, img_height) ⇒ Object



15
16
17
18
19
20
# File 'lib/export/flame_stabilizer.rb', line 15

def start_export( img_width, img_height)
  @counter = 0
  @width, @height = img_width, img_height
  @temp = Tracksperanto::BufferIO.new
  @writer = FlameChannelParser::Builder.new(@temp)
end

#start_tracker_segment(tracker_name) ⇒ Object



52
53
54
55
# File 'lib/export/flame_stabilizer.rb', line 52

def start_tracker_segment(tracker_name)
  @counter += 1
  @write_first_frame = true
end