lib/import/shake_script.rb in tracksperanto-2.2.2 vs lib/import/shake_script.rb in tracksperanto-2.2.4
- old
+ new
@@ -10,30 +10,48 @@
def self.distinct_file_ext
".shk"
end
def each
- progress_proc = lambda{|msg| report_progress(msg) }
- TrackExtractor.new(@io, [Proc.new, progress_proc])
+ s = Sentinel.new
+ s.progress_proc = method(:report_progress)
+ s.tracker_proc = Proc.new
+ TrackExtractor.new(@io, s)
end
private
+ #:nodoc:
+
+ class Sentinel
+ attr_accessor :start_frame, :tracker_proc, :progress_proc
+ def start_frame
+ @start_frame.to_i
+ end
+ end
+
# Extractor. Here we define copies of Shake's standard node creation functions.
class TrackExtractor < Tracksperanto::ShakeGrammar::Catcher
include Tracksperanto::ZipTuples
+ # SetTimeRange("-5-15") // sets time range of comp
+ # We use it to avoid producing keyframes which start at negative frames
+ def settimerange(str)
+ sentinel.start_frame = str.to_i if str.to_i < 0
+ end
+
# Normally, we wouldn't need to look for the variable name from inside of the funcall. However,
# in this case we DO want to take this shortcut so we know how the tracker node is called
def push(atom)
return super unless atom_is_tracker_assignment?(atom)
node_name = atom[1][-1]
trackers = atom[2][1][1..-1]
trackers.map do | tracker |
tracker.name = [node_name, tracker.name].join("_")
- sentinel[0].call(tracker)
+ # THIS IS THE MOST IMPORTANT THINGO
+ sentinel.tracker_proc.call(tracker)
end
end
def atom_is_tracker_assignment?(a)
(a.is_a?(Array)) && (a[0] == :assign) && (a[2][0] == :retval) && (a[2][1][0] == :trk)
@@ -41,24 +59,32 @@
# For Linear() curve calls. If someone selected JSpline or Hermite it's his problem.
# We put the frame number at the beginning since it works witih oru tuple zipper
def linear(extrapolation_type, *keyframes)
report_progress("Translating Linear animation")
- keyframes.map { |kf| [kf.at, kf.value] }
+ remap_keyframes_against_negative_at!(keyframes)
+ keyframes.map { |kf| [kf.at , kf.value] }
end
alias_method :nspline, :linear
alias_method :jspline, :linear
# Hermite interpolation looks like this
# Hermite(0,[1379.04,-0.02,-0.02]@1,[1379.04,-0.03,-0.03]@2)
# The first value in the array is the keyframe value, the other two are
# tangent positions (which we discard)
def hermite(extrapolation_type, *keyframes)
report_progress("Translating Hermite curve, removing tangents")
+ remap_keyframes_against_negative_at!(keyframes)
keyframes.map{ |kf| [kf.at, kf.value[0]] }
end
+ def remap_keyframes_against_negative_at!(kfs)
+ frame_start_of_script = sentinel.start_frame
+ kfs.each{|k| k.at = (k.at - frame_start_of_script) }
+ end
+ private :remap_keyframes_against_negative_at!
+
# image Tracker(
# image In,
# const char * trackRange,
# const char * subPixelRes,
# const char * matchSpace,
@@ -197,10 +223,10 @@
end
private
def report_progress(with_message)
- sentinel[1].call(with_message) if sentinel[1]
+ sentinel.progress_proc.call(with_message)
end
def collect_trackers_from(array)
parameters_per_node = 16
nb_trackers = array.length / parameters_per_node
\ No newline at end of file