Class: Tracksperanto::Export::NukeScript

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

Overview

Export each tracker as a single Tracker3 node

Constant Summary collapse

NODE_TEMPLATE =

:nodoc

%[
Tracker3 {
     track1 {%s}
     name %s
     xpos 0
     ypos %d
}
]
KEYFRAME_PRECISION_TEMPLATE =
"%.4f"
PREAMBLE =
%[
version 5.1200
Root {
 inputs 0
 frame 1
 last_frame %d
}
Constant {
 inputs 0
 channels rgb
 format "%d %d 0 0 %d %d 1"
 name CompSize_%dx%d
 postage_stamp false
 xpos 0
 ypos -60
}]
SCHEMATIC_OFFSET =

Offset by which the new nodes will be shifted down in the node graph

30

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



36
37
38
# File 'lib/export/nuke_script.rb', line 36

def self.desc_and_extension
  "nuke.nk"
end

.human_nameObject



40
41
42
# File 'lib/export/nuke_script.rb', line 40

def self.human_name
  "Nuke .nk script"
end

Instance Method Details

#end_exportObject



72
73
74
75
76
77
78
# File 'lib/export/nuke_script.rb', line 72

def end_export
  @trackers_io.rewind
  preamble_values = [@max_frame + 1, @w, @h, @w, @h, @w, @h]
  @io.puts(PREAMBLE % preamble_values)
  @io.write(@trackers_io.read) until @trackers_io.eof?
  @trackers_io.close!
end

#end_tracker_segmentObject



59
60
61
62
63
64
# File 'lib/export/nuke_script.rb', line 59

def end_tracker_segment
  coord_tuples = @tracker.map{|kf| [kf.frame, kf.abs_x, kf.abs_y]}
  @trackers_io.puts(
    NODE_TEMPLATE % [curves_from_tuples(coord_tuples), @tracker.name, (@ypos += SCHEMATIC_OFFSET)]
  )
end

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



66
67
68
69
70
# File 'lib/export/nuke_script.rb', line 66

def export_point(frame, abs_float_x, abs_float_y, float_residual)
  # Nuke uses 1-based frames
  @tracker.keyframe!(:frame => frame + 1, :abs_x => abs_float_x, :abs_y => abs_float_y)
  @max_frame = frame if frame > @max_frame
end

#start_export(w, h) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/export/nuke_script.rb', line 44

def start_export(w, h)
  @max_frame, @ypos, @w, @h = 0, 0, w, h
  # At the start of the file we need to provide the length of the script.
  # We allocate an IO for the file being output that will contain all the trackers,
  # and then write that one into the script preceded by the preamble that sets length
  # based on the last frame position in time
  @trackers_io = Tracksperanto::BufferIO.new
end

#start_tracker_segment(tracker_name) ⇒ Object

We accumulate a tracker and on end dump it out in one piece



54
55
56
57
# File 'lib/export/nuke_script.rb', line 54

def start_tracker_segment(tracker_name)
  # Setup for the next tracker
  @tracker = Tracksperanto::Tracker.new(:name => tracker_name)
end