#!/usr/bin/env ruby # == Synopsis # # Translate a 2D track file from a single format to many others # # == Usage # # tracksperanto -f shakescript /Films/Blockbuster/Shots/001/script.shk -w 1920 -h 1080 # # == Author # Julik require File.dirname(__FILE__) + '/../lib/tracksperanto' require File.dirname(__FILE__) + '/../lib/pipeline' require 'optparse' # Sane defaults reader_klass = Tracksperanto::Import::ShakeScript width = 1920 height = 1080 scale_x = 1.0 scale_y = 1.0 slip = 0 golden_tracks = false readers = Tracksperanto::Import.constants.map{|e| e.to_s }.reject{|e| e == 'Base'} informative_readers = readers.reject{|e| e == 'ShakeScript'} parser = OptionParser.new do | p | p.banner = "Usage: tracksperanto -f ShakeScript -w 1920 -h 1080 /Films/Blockbuster/Shots/001/script.shk" p.on(" -f", "--from TRANSLATOR", String, "Use the specific import translator (defaults to ShakeScript, but can be \ #{informative_readers.join(', ')})") do | f | begin reader_klass = Tracksperanto::Import.const_get(f) rescue NameError => e reader_list = readers.join("\n\t") STDERR.puts "Unknown reader #{f.inspect}, available readers:\n\t#{readers}" exit(-1) end end p.on(" -w", "--width WIDTH_IN_PIXELS", Integer, "Absolute input comp width in pixels") { |w| width = w } p.on(" -h", "--height HEIGHT_IN_PIXELS", Integer, "Absolute input comp height in pixels") {|w| height = w } p.on(" -xs", "--xscale X_SCALING_FACTOR", Float, "Scale the result in X by this factor (1.0 is the default)") {|sx| scale_x = sx } p.on(" -ys", "--yscale Y_SCALING_FACTOR", Float, "Scale the result in Y by this factor (1.0 is the default)") {|sy| scale_y = sy } p.on(" -s", "--slip FRAMES", Integer, "Slip the result by this number of frames, positive is 'later'") {|sy| slip = sy } p.on(" -g", "--golden", "Reset the residuals of all trackers to 0 (ignore correlation)") {|g_flag| golden_tracks = g_flag } end begin parser.parse! rescue OptionParser::MissingArgument => e STDERR.puts "Unknown argument: #{e.message}" puts parser exit(-1) end input_file = ARGV.pop if !input_file STDERR.puts "No input file provided - should be the last argument" puts parser exit(-1) end pipe = Tracksperanto::Pipeline::Base.new pipe.progress_block = lambda{|percent, msg| puts("#{msg}..#{percent.to_i}% complete") } pipe.run(input_file, width, height, reader_klass) do | scaler, slipper, golden | slipper.slip = slip scaler.x_factor = scale_x scaler.y_factor = scale_y golden.enabled = golden_tracks end puts "Converted #{pipe.converted_points} trackers"