Sha256: ce6bfe8d1e1920682ae5bc9f9adf8c9487e04f1ecb11de07a5d7984a7ba1b9d1

Contents?: true

Size: 1.43 KB

Versions: 62

Compression:

Stored size: 1.43 KB

Contents

class Tracksperanto::Export::MayaLive < Tracksperanto::Export::Base
  
  # Maya Live exports and imports tracks in "aspect units", so a point at 0,0
  # will be at -1.78,-1 in MayaLive coordinates with aspect of 1.78. Therefore
  # we offer an override for the aspect being exported
  attr_accessor :aspect
  
  def self.desc_and_extension
    "mayalive.txt"
  end
  
  def self.human_name
    "MayaLive track export"
  end
  
  def start_export( img_width, img_height)
    @aspect ||= img_width.to_f / img_height
    
    @w, @h = img_width, img_height
    
    first_line = (%w( # Size) + [@w, @h, "%.2f" % @aspect]).join("  ")
    @io.puts(first_line)
    @tracker_number = 0
  end
  
  def start_tracker_segment(tracker_name)
    @io.puts('#  Name %s' % tracker_name)
  end
  
  def end_tracker_segment
    @tracker_number += 1
  end
  
  FORMAT_LINE = "%d %d %.10f %.10f %s"
  
  def export_point(frame, abs_float_x, abs_float_y, float_residual)
    values = [
      @tracker_number, frame,
      aspectize_x(abs_float_x), aspectize_y(abs_float_y),
      residual_with_reset(float_residual)
    ]
    @io.puts(FORMAT_LINE % values)
  end
  
  private
    
    def aspectize_x(pix)
      aspectized_pixel = @w.to_f / (@aspect * 2)
      (pix / aspectized_pixel) - @aspect
    end
    
    def aspectize_y(pix)
      aspectized_pixel = @h.to_f / 2
      (pix / aspectized_pixel) - 1
    end
    
    def residual_with_reset(r)
      "%.10f" % (r/10)
    end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
tracksperanto-1.7.3 lib/export/maya_live.rb
tracksperanto-1.7.2 lib/export/maya_live.rb
tracksperanto-1.7.1 lib/export/maya_live.rb
tracksperanto-1.7.0 lib/export/maya_live.rb
tracksperanto-1.6.9 lib/export/maya_live.rb
tracksperanto-1.6.8 lib/export/maya_live.rb
tracksperanto-1.6.7 lib/export/maya_live.rb
tracksperanto-1.6.6 lib/export/maya_live.rb
tracksperanto-1.6.5 lib/export/maya_live.rb
tracksperanto-1.6.4 lib/export/maya_live.rb
tracksperanto-1.6.3 lib/export/maya_live.rb
tracksperanto-1.6.2 lib/export/maya_live.rb
tracksperanto-1.6.1 lib/export/maya_live.rb
tracksperanto-1.6.0 lib/export/maya_live.rb
tracksperanto-1.5.7 lib/export/maya_live.rb
tracksperanto-1.5.6 lib/export/maya_live.rb
tracksperanto-1.5.5 lib/export/maya_live.rb
tracksperanto-1.5.4 lib/export/maya_live.rb
tracksperanto-1.5.3 lib/export/maya_live.rb
tracksperanto-1.5.2 lib/export/maya_live.rb