Class: FlameChannelParser::Interpolator
- Inherits:
-
Object
- Object
- FlameChannelParser::Interpolator
- Includes:
- Segments
- Defined in:
- lib/interpolator.rb
Overview
Used to sample Flame animation curves. Pass a Channel object to the interpolator and you can then sample values at arbitrary frames.
i = Interpolator.new(parsed_channel)
i.value_at(245.5) # => will interpolate and return the value at frame 245.5
Constant Summary collapse
- NEG_INF =
(-1.0/0.0)
- POS_INF =
(1.0/0.0)
Instance Method Summary collapse
-
#first_defined_frame ⇒ Object
Returns the first frame number that is concretely defined as a keyframe after the prepolation ends.
-
#initialize(channel) ⇒ Interpolator
constructor
The constructor will accept a ChannelBlock object and convert it internally to a number of segments from which samples can be made.
-
#last_defined_frame ⇒ Object
Returns the last frame number that is concretely defined as a keyframe before the extrapolation starts.
-
#sample_at(frame) ⇒ Object
Sample the value of the animation curve at this frame.
Constructor Details
#initialize(channel) ⇒ Interpolator
The constructor will accept a ChannelBlock object and convert it internally to a number of segments from which samples can be made
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/interpolator.rb', line 17 def initialize(channel) @segments = [] @extrap = channel.extrapolation # Edge case - channel has no anim at all @segments = if channel.length.zero? [ConstantFunction.new(channel.base_value)] else create_segments_from_channel(channel) end end |
Instance Method Details
#first_defined_frame ⇒ Object
Returns the first frame number that is concretely defined as a keyframe after the prepolation ends
42 43 44 45 46 |
# File 'lib/interpolator.rb', line 42 def first_defined_frame first_f = @segments[0].end_frame return 1 if first_f == NEG_INF return first_f end |
#last_defined_frame ⇒ Object
Returns the last frame number that is concretely defined as a keyframe before the extrapolation starts
50 51 52 53 54 |
# File 'lib/interpolator.rb', line 50 def last_defined_frame last_f = @segments[-1].start_frame return 100 if last_f == POS_INF return last_f end |
#sample_at(frame) ⇒ Object
Sample the value of the animation curve at this frame
30 31 32 33 34 35 36 37 38 |
# File 'lib/interpolator.rb', line 30 def sample_at(frame) if :cycle == @extrap return sample_from_segments(frame_number_in_cycle(frame)) elsif :revcycle == @extrap return sample_from_segments(frame_number_in_revcycle(frame)) else sample_from_segments(frame) end end |