lib/import/shake_script.rb in tracksperanto-1.6.8 vs lib/import/shake_script.rb in tracksperanto-1.6.9
- old
+ new
@@ -1,8 +1,7 @@
require File.dirname(__FILE__) + "/shake_grammar/lexer"
require File.dirname(__FILE__) + "/shake_grammar/catcher"
-
class Tracksperanto::Import::ShakeScript < Tracksperanto::Import::Base
def self.human_name
"Shake .shk script file"
end
@@ -14,30 +13,38 @@
# Extractor. The injection should be an array of two elements: the array collecting
# trackers and the progress proc
class Traxtractor < Tracksperanto::ShakeGrammar::Catcher
include Tracksperanto::ZipTuples
+ # 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 will intersperse the data into the sentinel
+ def push(atom)
+ return super unless (atom.is_a?(Array) && atom[0] == :assign)
+ return super unless (atom[2][0] == :retval)
+ node_name = atom[1]
+ atom[2][1].map do | tracker |
+ tracker.name = [node_name, tracker.name].join("_")
+ sentinel[0].push(tracker)
+ end
+ end
+
# 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(first_arg, *keyframes)
report_progress("Translating Linear animation")
- keyframes.map do | kf |
- [kf[1][1], kf[0][1]]
- end
+ 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(initial_value, *keyframes)
report_progress("Translating Hermite curve, removing tangents")
- values, at_frames = keyframes.partition{|e| e.is_a?(Array)}
- values = values.map{|v| v[0] }
- at_frames.zip(values)
+ keyframes.map{ |kf| [kf.at, kf.value[0]] }
end
# image Tracker(
# image In,
# const char * trackRange,
@@ -54,12 +61,11 @@
def tracker(input, trackRange, subPixelRes, matchSpace,
referenceTolerance, referenceBehavior, failureTolerance, failureBehavior, limitProcessing, referencFrame, s1, s2,
s3, s4, s5, s6, *trackers)
report_progress("Parsing Tracker node")
- collect_trackers_from(get_variable_name, trackers)
- true
+ collect_trackers_from(trackers)
end
# stabilize {
# image In,
# int applyTransform,
@@ -96,15 +102,16 @@
track3X, track3Y,
track4X, track4Y,
*useless_args)
report_progress("Parsing Stabilize node")
- node_name = get_variable_name
- collect_stabilizer_tracker("#{node_name}_track1", track1X, track1Y)
- collect_stabilizer_tracker("#{node_name}_track2", track2X, track2Y)
- collect_stabilizer_tracker("#{node_name}_track3", track3X, track3Y)
- collect_stabilizer_tracker("#{node_name}_track4", track4X, track4Y)
+ [
+ collect_stabilizer_tracker("track1", track1X, track1Y),
+ collect_stabilizer_tracker("track2", track2X, track2Y),
+ collect_stabilizer_tracker("track3", track3X, track3Y),
+ collect_stabilizer_tracker("track4", track4X, track4Y),
+ ].compact
end
# image = MatchMove(
# Background,
# Foreground,
@@ -162,43 +169,44 @@
track3Y,
track4X,
track4Y, *others)
report_progress("Parsing MatchMove node")
- node_name = get_variable_name
- collect_stabilizer_tracker("#{node_name}_track1", track1X, track1Y)
- collect_stabilizer_tracker("#{node_name}_track2", track2X, track2Y)
- collect_stabilizer_tracker("#{node_name}_track3", track3X, track3Y)
- collect_stabilizer_tracker("#{node_name}_track4", track4X, track4Y)
-
+ [
+ collect_stabilizer_tracker("track1", track1X, track1Y),
+ collect_stabilizer_tracker("track2", track2X, track2Y),
+ collect_stabilizer_tracker("track3", track3X, track3Y),
+ collect_stabilizer_tracker("track4", track4X, track4Y),
+ ].compact
end
private
def report_progress(with_message)
sentinel[1].call(with_message) if sentinel[1]
end
- def collect_trackers_from(name, array)
+ def collect_trackers_from(array)
parameters_per_node = 16
nb_trackers = array.length / parameters_per_node
- nb_trackers.times do | idx |
+
+ (0...nb_trackers).map do | idx |
from_index, to_index = (idx * parameters_per_node), (idx+1) * parameters_per_node
tracker_args = array[from_index...to_index]
- tracker_args[0] = "#{name}_#{tracker_args[0]}"
+ tracker_args[0] = "#{tracker_args[0]}"
collect_tracker(*tracker_args)
- end
+ end.compact
end
def collect_stabilizer_tracker(name, x_curve, y_curve)
return if (x_curve == :unknown || y_curve == :unknown)
keyframes = zip_curve_tuples(x_curve, y_curve).map do | (frame, x, y) |
Tracksperanto::Keyframe.new(:frame => frame - 1, :abs_x => x, :abs_y => y)
end
- push_tracker(:name => name, :keyframes => keyframes)
+ Tracksperanto::Tracker.new(:name => name, :keyframes => keyframes)
end
def collect_tracker(name, x_curve, y_curve, corr_curve, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12)
unless x_curve.is_a?(Array) && y_curve.is_a?(Array)
report_progress("Tracker #{name} had no anim or unsupported interpolation and can't be recovered")
@@ -210,20 +218,17 @@
curve_set = combine_curves(x_curve, y_curve, corr_curve)
keyframes = zip_curve_tuples(*curve_set).map do | (frame, x, y, corr) |
Tracksperanto::Keyframe.new(:frame => frame - 1, :abs_x => x, :abs_y => y, :residual => (1 - corr.to_f))
end
- push_tracker(:name => name, :keyframes => keyframes)
+
+ Tracksperanto::Tracker.new(:name => name, :keyframes => keyframes)
end
def combine_curves(x, y, corr_curve)
curve_set = [x, y]
curve_set << corr_curve if (corr_curve.respond_to?(:length) && corr_curve.length >= x.length)
curve_set
- end
-
- def push_tracker(tracker_options)
- sentinel[0].push(Tracksperanto::Tracker.new(tracker_options))
end
end
def parse(script_io)
trackers = []
\ No newline at end of file