lib/import/nuke_script.rb in tracksperanto-1.5.2 vs lib/import/nuke_script.rb in tracksperanto-1.5.3

- old
+ new

@@ -30,17 +30,12 @@ def scan_tracker_node(io) tracks_in_tracker = [] while line = io.gets_and_strip if line =~ TRACK_PATTERN - tuples = scan_track(line) - tk = Tracksperanto::Tracker.new( - :keyframes => tuples.map do | (f, x, y) | - Tracksperanto::Keyframe.new(:frame => f -1, :abs_x => x, :abs_y => y) - end - ) - tracks_in_tracker.push(tk) + t = extract_tracker(line) + tracks_in_tracker.push(t) if t elsif line =~ NODENAME tracks_in_tracker.each_with_index do | t, i | t.name = "#{$1}_track#{i+1}" end return tracks_in_tracker @@ -49,17 +44,18 @@ raise "Tracker node went all the way to end of stream" end def scan_track(line_with_curve) x_curve, y_curve = line_with_curve.split(/\}/).map{ | one_curve| parse_curve(one_curve) } + return nil unless (x_curve && y_curve) zip_curve_tuples(x_curve, y_curve) end # Scan a curve to a number of triplets def parse_curve(curve_text) # Replace the closing curly brace with a curly brace with space so that it gets caught by split - atoms, tuples = curve_text.gsub(/\}/, ' }').split, [] + atoms, tuples = curve_text.gsub(/\}/m, ' }').split, [] # Nuke saves curves very efficiently. x(keyframe_number) means that an uninterrupted sequence of values will start, # after which values follow. When the curve is interrupted in some way a new x(keyframe_number) will signifu that we # skip to that specified keyframe and the curve continues from there section_start = /^x(\d+)$/ keyframe = /^([-\d\.]+)$/ @@ -76,6 +72,16 @@ end end tuples end + def extract_tracker(line) + tuples = scan_track(line) + return nil unless (tuples && tuples.any?) + + Tracksperanto::Tracker.new( + :keyframes => tuples.map do | (f, x, y) | + Tracksperanto::Keyframe.new(:frame => f -1, :abs_x => x, :abs_y => y) + end + ) + end end \ No newline at end of file