flame_timewarp_extractor 0.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.0 / 2011-05-17
2
+
3
+ * Update the dependency version
4
+
5
+ === 1.0.0 / 2011-05-13
6
+
7
+ * Use the flame_channel_parser_gem
8
+
1
9
  === 0.0.2 / 2011-03-21
2
10
 
3
11
  * Specify the missing Tracksperanto dependency
data/Manifest.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  History.txt
2
2
  Manifest.txt
3
- README.txt
3
+ README.rdoc
4
4
  Rakefile
5
5
  bin/flametwextract
6
6
  lib/flame_timewarp_extractor.rb
@@ -4,8 +4,7 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Extract timewarp channels from Flame setup files, for usage in say Maya or Houdini or whathaveyou.
8
-
7
+ Extract timewarp channels from Flame setup files into a simple list of "to-frame" to "from-frame" mappings.
9
8
 
10
9
  == SYNOPSIS:
11
10
 
data/Rakefile CHANGED
@@ -4,8 +4,9 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  Hoe.spec 'flame_timewarp_extractor' do | s |
7
+ s.readme_file = 'README.rdoc'
7
8
  s.developer('Julik', 'me@julik.nl')
8
- s.extra_deps = {"tracksperanto" => ">=1.9.6"}
9
+ s.extra_deps = {"flame_channel_parser" => ">=1.1.1"}
9
10
  end
10
11
 
11
12
  # vim: syntax=ruby
data/bin/flametwextract CHANGED
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/../lib/flame_timewarp_extractor'
3
-
4
3
  FlameTimewarpExtractor.new.extract(ARGV.shift)
@@ -1,79 +1,35 @@
1
1
  require "rubygems"
2
- require "tracksperanto"
2
+ require "flame_channel_parser"
3
3
 
4
4
  class FlameTimewarpExtractor
5
5
 
6
- VERSION = "0.0.2"
7
-
8
- class Output
9
- def initialize(io, first_f, last_f)
10
- @io, @first, @last = io, first_f, last_f
11
- end
12
- attr_reader :output_header, :output_tail
13
- def write_kf(to_f, from_f)
14
- end
15
- end
16
-
17
- class Import < Tracksperanto::Import::FlameStabilizer
18
- def initialize
19
- @progress_block = nil
20
- end
21
-
22
- def channel_is_useful?(name)
23
- true
24
- end
25
-
26
- def extract_channels(from_io)
27
- extract_channels_from_stream(from_io)
28
- end
29
- end
30
-
31
- class OutputChan < Output
32
- def write_kf(to_f, from_f)
33
- @io.puts("%d\t%.5f" % [to_f, from_f])
34
- end
35
- end
6
+ VERSION = "1.1.0"
36
7
 
37
8
  CHANNELS = %( Timing/Timing Frame )
38
9
 
39
- def extract(path)
40
- f = File.open(path)
41
- channels = Import.new.extract_channels(f)
42
- timing_channel = channels.find{|c| CHANNELS.include?(c.name) }
43
- raise "No timing channel found in this setup" unless timing_channel
44
-
45
- write_channel(timing_channel)
10
+ # Pass the path to the Kronos or Timewarp setup here and you will get the timewarp curve on STDOUT
11
+ def extract(path, to_io = $stdout)
12
+ File.open(path) do | f |
13
+ channels = FlameChannelParser.parse(f)
14
+
15
+ timing_channel = channels.find{|c| CHANNELS.include?(c.name) }
16
+ raise "No timing channel found in this setup" unless timing_channel
17
+
18
+ write_channel(timing_channel, to_io)
19
+ end
46
20
  end
47
21
 
48
22
  private
49
23
 
50
- def write_channel(ch)
24
+ def write_channel(channel, to_io)
25
+ interpolator = FlameChannelParser::Interpolator.new(channel)
26
+
27
+ from_frame = interpolator.first_defined_frame
28
+ to_frame = interpolator.last_defined_frame
51
29
 
52
- o = OutputChan.new($stdout, ch[0][0], (ch[0][0] + ch.length))
53
- o.output_header
54
- last_at, last_value = nil, nil
55
- ch.each do | at, value |
56
- last_at, last_value = lerp(last_at, last_value, at, value) do | interp_at, interp_value |
57
- o.write_kf(interp_at, interp_value)
58
- end
30
+ (from_frame..to_frame).each do | frame |
31
+ to_io.puts("%d\t%.5f" % [frame, interpolator.sample_at(frame)])
59
32
  end
60
- o.output_tail
61
33
  end
62
34
 
63
- # Do a simple linear interpolxion. The function will yield
64
- # the interim X and Y, one tuple per whole value between the set points,
65
- # and return the last tuple (so you can return-assign from it in a loop)
66
- def lerp(last_x, last_y, x, y) #:yields: interp_x, interp_y
67
- if last_x.nil?
68
- yield(x, y)
69
- else
70
- gap_size = x - last_x
71
- increment = (y.to_f - last_y) / gap_size.to_f
72
- (1..gap_size).each do | index |
73
- yield(last_x + index, last_y + (increment * index))
74
- end
75
- end
76
-
77
- return [x, y]
78
- end
79
35
  end
@@ -3,17 +3,44 @@ require "flame_timewarp_extractor"
3
3
  require "stringio"
4
4
 
5
5
  class TestTwextract < Test::Unit::TestCase
6
- def test_parse
7
- bkup = $stdout
8
- output = StringIO.new
9
- begin
10
- $stdout = output
11
- FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_015_010_v01_Baked.timewarp")
12
- ensure
13
- $stdout = bkup
14
- end
6
+ def test_parse_with_basic_baked_setup
7
+ io = StringIO.new
8
+ FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_015_010_v01_Baked.timewarp", io)
9
+
10
+ compare_outputs(File.read(File.dirname(__FILE__) + "/samples/output.txt"), io.string)
11
+ end
12
+
13
+ def test_parse_with_interpolated_setup
14
+ interpolated_io = StringIO.new
15
+ baked_io = StringIO.new
16
+
17
+ FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_016_010_v01.timewarp", interpolated_io)
18
+ FlameTimewarpExtractor.new.extract(File.dirname(__FILE__) + "/samples/TW_016_010_v01_Baked.timewarp", baked_io)
15
19
 
16
- ref = File.read(File.dirname(__FILE__) + "/samples/output.txt")
17
- assert_equal ref, output.string, "Should have the same output"
20
+ compare_outputs(baked_io.string, interpolated_io.string)
21
+ end
22
+
23
+ private
24
+ D = 0.1
25
+
26
+ def compare_outputs(ref, out)
27
+ ref = ref.split("\n")
28
+ out = out.split("\n")
29
+
30
+ puts ref
31
+ puts out
32
+
33
+ ref.zip(out).each_with_index do | (reference_line, output_line), lineno |
34
+ assert_not_nil output_line, "at #{lineno} the output should not be shorter than the reference"
35
+ assert_not_nil reference_line, "at #{lineno} the output should not be longer than the reference"
36
+
37
+ from_f, from_d = reference_line.strip.split
38
+ to_f, to_d = output_line.strip.split
39
+
40
+ assert_equal from_f, to_f, "at #{lineno} the line should have the same frame"
41
+
42
+ assert_in_delta from_d.to_f, to_d.to_f, D, "At frame #{to_f}"
43
+ end
18
44
  end
45
+
19
46
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame_timewarp_extractor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
+ - 1
8
+ - 1
7
9
  - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Julik
@@ -15,23 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-21 00:00:00 +01:00
18
+ date: 2011-05-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: tracksperanto
22
+ name: flame_channel_parser
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 63
29
+ hash: 17
30
30
  segments:
31
31
  - 1
32
- - 9
33
- - 6
34
- version: 1.9.6
32
+ - 1
33
+ - 1
34
+ version: 1.1.1
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 2.9.1
51
51
  type: :development
52
52
  version_requirements: *id002
53
- description: Extract timewarp channels from Flame setup files, for usage in say Maya or Houdini or whathaveyou.
53
+ description: Extract timewarp channels from Flame setup files into a simple list of "to-frame" to "from-frame" mappings.
54
54
  email:
55
55
  - me@julik.nl
56
56
  executables:
@@ -60,11 +60,10 @@ extensions: []
60
60
  extra_rdoc_files:
61
61
  - History.txt
62
62
  - Manifest.txt
63
- - README.txt
64
63
  files:
65
64
  - History.txt
66
65
  - Manifest.txt
67
- - README.txt
66
+ - README.rdoc
68
67
  - Rakefile
69
68
  - bin/flametwextract
70
69
  - lib/flame_timewarp_extractor.rb
@@ -79,7 +78,7 @@ licenses: []
79
78
  post_install_message:
80
79
  rdoc_options:
81
80
  - --main
82
- - README.txt
81
+ - README.rdoc
83
82
  require_paths:
84
83
  - lib
85
84
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -106,6 +105,6 @@ rubyforge_project: flame_timewarp_extractor
106
105
  rubygems_version: 1.4.1
107
106
  signing_key:
108
107
  specification_version: 3
109
- summary: Extract timewarp channels from Flame setup files, for usage in say Maya or Houdini or whathaveyou.
108
+ summary: Extract timewarp channels from Flame setup files into a simple list of "to-frame" to "from-frame" mappings.
110
109
  test_files:
111
110
  - test/test_twextract.rb