lib/export/nuke_script.rb in tracksperanto-1.7.1 vs lib/export/nuke_script.rb in tracksperanto-1.7.2
- old
+ new
@@ -9,15 +9,20 @@
}
]
KEYFRAME_PRECISION_TEMPLATE = "%.4f"
PREAMBLE = %[
version 5.1200
+Root {
+ inputs 0
+ frame 1
+ last_frame %d
+}
Constant {
inputs 0
channels rgb
- format "1920 1080 0 0 1920 1080 1"
- name CompSize_1920x1080
+ format "%d %d 0 0 %d %d 1"
+ name CompSize_%dx%d
postage_stamp false
xpos 0
ypos -60
}]
SCHEMATIC_OFFSET = 30
@@ -33,29 +38,41 @@
def self.human_name
"Nuke .nk script"
end
def start_export(w, h)
- @io.puts(PREAMBLE.gsub(/1920/, w.to_s).gsub(/1080/, h.to_s))
- @ypos = 0
+ @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 = Tempfile.new("nukex")
end
# We accumulate a tracker and on end dump it out in one piece
def start_tracker_segment(tracker_name)
# Setup for the next tracker
- @tracker = T.new
- @tracker.name = tracker_name
+ @tracker = T.new(:name => tracker_name)
end
def end_tracker_segment
- @io.puts(
+ @trackers_io.puts(
NODE_TEMPLATE % [curves_from_tuples(@tracker), @tracker.name, (@ypos += SCHEMATIC_OFFSET)]
)
end
def export_point(frame, abs_float_x, abs_float_y, float_residual)
# Nuke uses 1-based frames
@tracker << [frame + 1, abs_float_x, abs_float_y]
+ @max_frame = frame if frame > @max_frame
+ end
+
+ 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
private
# Generates a couple of Nuke curves (x and y) from the passed tuples of [frame, x, y]
\ No newline at end of file