lib/import/flame_stabilizer.rb in tracksperanto-2.2.4 vs lib/import/flame_stabilizer.rb in tracksperanto-2.3.0
- old
+ new
@@ -73,17 +73,19 @@
def each
report_progress("Extracting setup size")
self.width, self.height = extract_width_and_height_from_stream(@io)
report_progress("Extracting all animation channels")
- channels = extract_channels_from_stream(@io)
+ channels, names = extract_channels_from_stream(@io)
raise "The setup contained no channels that we could process" if channels.empty?
raise "A channel was nil" if channels.find{|e| e.nil? }
report_progress("Assembling tracker curves from channels")
- scavenge_trackers_from_channels(channels) {|t| yield(t) }
+ scavenge_trackers_from_channels(channels, names) {|t| yield(t) }
+ ensure
+ channels.clear
end
private
def extract_width_and_height_from_stream(io)
w, h = nil, nil
@@ -101,58 +103,24 @@
return [w, h] if (w && h)
end
end
-=begin
-Here's how a Flame channel looks like
-The Size will not be present if there are no keyframes
-
-Channel tracker1/ref/x
- Extrapolation constant
- Value 770.41
- Size 4
- KeyVersion 1
- Key 0
- Frame 1
- Value 770.41
- Interpolation constant
- End
- Key 1
- Frame 44
- Value 858.177
- Interpolation constant
- RightSlope 2.31503
- LeftSlope 2.31503
- End
- Key 2
- Frame 74
- Value 939.407
- Interpolation constant
- RightSlope 2.24201
- LeftSlope 2.24201
- End
- Key 3
- Frame 115
- Value 1017.36
- Interpolation constant
- End
- Colour 50 50 50
- End
-=end
def extract_channels_from_stream(io)
- channels = []
+ channels = Tracksperanto::Accumulator.new
+ names = []
channel_matcher = /Channel (.+)\n/
until io.eof?
line = io.gets
if line =~ channel_matcher && channel_is_useful?(line)
report_progress("Extracting channel #{$1}")
channels << ChannelBlock.new(io, $1)
+ names << $1
end
end
- channels
+ [channels, names]
end
USEFUL_CHANNELS = %w( /shift/x /shift/y /ref/x /ref/y ).map(&Regexp.method(:new))
# This method tells the importer whether a channel that has been found in the source
@@ -164,26 +132,37 @@
USEFUL_CHANNELS.any?{|e| channel_name =~ e }
end
REF_CHANNEL = "ref" # or "track" - sometimes works sometimes don't
- def scavenge_trackers_from_channels(channels)
- channels.select{|e| e.name =~ /\/#{REF_CHANNEL}\/x/}.each do | track_x |
- report_progress("Detected reference channel #{track_x}")
- yield grab_tracker(channels, track_x)
+ def scavenge_trackers_from_channels(channels, names)
+
+
+ channels.each do |c|
+ next unless c.name =~ /\/#{REF_CHANNEL}\/x/
+
+ report_progress("Detected reference channel #{c.name}")
+
+ yield grab_tracker(channels, c, names)
end
end
- def grab_tracker(channels, track_x)
+ def grab_tracker(channels, track_x, names)
t = Tracksperanto::Tracker.new(:name => track_x.name.split('/').shift)
report_progress("Extracting tracker #{t.name}")
- track_y = channels.find{|e| e.name == "#{t.name}/#{REF_CHANNEL}/y" }
- shift_x = channels.find{|e| e.name == "#{t.name}/shift/x" }
- shift_y = channels.find{|e| e.name == "#{t.name}/shift/y" }
+ # This takes a LONG time when we have alot of channels, we need a precache of
+ # some sort to do this
+ ref_idx = names.index("#{t.name}/#{REF_CHANNEL}/y")
+ shift_x_idx = names.index("#{t.name}/shift/x")
+ shift_y_idx = names.index("#{t.name}/shift/y")
+ track_y = channels[ref_idx]
+ shift_x = channels[shift_x_idx]
+ shift_y = channels[shift_y_idx]
+
shift_tuples = zip_curve_tuples(shift_x, shift_y)
track_tuples = zip_curve_tuples(track_x, track_y)
report_progress("Detecting base value")
base_x, base_y = find_base_x_and_y(track_tuples, shift_tuples)
@@ -205,6 +184,43 @@
base_track_tuple = track_tuples.find do | track_tuple |
shift_tuples.find { |shift_tuple| shift_tuple[0] == track_tuple [0] }
end || track_tuples[0]
base_track_tuple[1..2]
end
-end
+end
+
+__END__
+
+Here's how a Flame channel looks like
+The Size will not be present if there are no keyframes
+
+Channel tracker1/ref/x
+ Extrapolation constant
+ Value 770.41
+ Size 4
+ KeyVersion 1
+ Key 0
+ Frame 1
+ Value 770.41
+ Interpolation constant
+ End
+ Key 1
+ Frame 44
+ Value 858.177
+ Interpolation constant
+ RightSlope 2.31503
+ LeftSlope 2.31503
+ End
+ Key 2
+ Frame 74
+ Value 939.407
+ Interpolation constant
+ RightSlope 2.24201
+ LeftSlope 2.24201
+ End
+ Key 3
+ Frame 115
+ Value 1017.36
+ Interpolation constant
+ End
+ Colour 50 50 50
+ End
\ No newline at end of file