Class: Stagecraft::Animation::Track
- Inherits:
-
Object
- Object
- Stagecraft::Animation::Track
- Defined in:
- lib/stagecraft/animation/track.rb
Constant Summary collapse
- PATH_COMPONENTS =
{ translation: 3, rotation: 4, scale: 3 }.freeze
- INTERPOLATIONS =
%i[linear step cubicspline].freeze
Instance Attribute Summary collapse
-
#interpolation ⇒ Object
readonly
Returns the value of attribute interpolation.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#target_path ⇒ Object
readonly
Returns the value of attribute target_path.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
-
#value_size ⇒ Object
readonly
Returns the value of attribute value_size.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(times:, values:, target:, target_path:, interpolation: :linear, value_size: nil) ⇒ Track
constructor
A new instance of Track.
- #sample(time, out = nil) ⇒ Object
Constructor Details
#initialize(times:, values:, target:, target_path:, interpolation: :linear, value_size: nil) ⇒ Track
Returns a new instance of Track.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/stagecraft/animation/track.rb', line 11 def initialize(times:, values:, target:, target_path:, interpolation: :linear, value_size: nil) @times = unpack(times) @values = unpack(values) @target = target @target_path = target_path.to_sym @interpolation = interpolation.to_sym raise ArgumentError, "unsupported interpolation #{interpolation.inspect}" unless INTERPOLATIONS.include?(@interpolation) raise ArgumentError, "animation times cannot be empty" if @times.empty? raise ArgumentError, "animation times must be sorted" unless @times.each_cons(2).all? { |left, right| left <= right } @value_size = value_size || infer_value_size expected = @times.length * @value_size * (cubicspline? ? 3 : 1) raise ArgumentError, "animation value count #{values_count} does not match expected #{expected}" unless values_count == expected end |
Instance Attribute Details
#interpolation ⇒ Object (readonly)
Returns the value of attribute interpolation.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def interpolation @interpolation end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def target @target end |
#target_path ⇒ Object (readonly)
Returns the value of attribute target_path.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def target_path @target_path end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def times @times end |
#value_size ⇒ Object (readonly)
Returns the value of attribute value_size.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def value_size @value_size end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
9 10 11 |
# File 'lib/stagecraft/animation/track.rb', line 9 def values @values end |
Instance Method Details
#duration ⇒ Object
26 27 28 |
# File 'lib/stagecraft/animation/track.rb', line 26 def duration times.last end |
#sample(time, out = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/stagecraft/animation/track.rb', line 30 def sample(time, out = nil) value = sample_value(Float(time)) assign(out, value) if out value end |