Class: Stagecraft::Animation::Mixer

Inherits:
Object
  • Object
show all
Defined in:
lib/stagecraft/animation/mixer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Mixer

Returns a new instance of Mixer.



8
9
10
11
12
# File 'lib/stagecraft/animation/mixer.rb', line 8

def initialize(root)
  @root = root
  @actions = []
  @resolved_targets = {}
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/stagecraft/animation/mixer.rb', line 6

def actions
  @actions
end

#rootObject (readonly)

Returns the value of attribute root.



6
7
8
# File 'lib/stagecraft/animation/mixer.rb', line 6

def root
  @root
end

Instance Method Details

#play(clip, loop: :repeat, fade_in: 0.0) ⇒ Object



14
15
16
17
18
19
# File 'lib/stagecraft/animation/mixer.rb', line 14

def play(clip, loop: :repeat, fade_in: 0.0)
  action = Action.new(clip, loop:, fade_in:)
  actions << action
  clip.tracks.each { |track| resolve_target(track) }
  action
end

#stop_allObject



21
22
23
24
25
# File 'lib/stagecraft/animation/mixer.rb', line 21

def stop_all
  actions.each(&:stop)
  actions.clear
  self
end

#update(dt) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/stagecraft/animation/mixer.rb', line 27

def update(dt)
  samples = Hash.new { |hash, key| hash[key] = [] }
  actions.each do |action|
    next unless action.enabled

    action.advance(dt)
    action.clip.tracks.each do |track|
      target = resolve_target(track)
      next unless target

      samples[[target, track.target_path]] << [track.sample(action.time), action.weight]
    end
  end
  samples.each { |(target, path), values| apply_blend(target, path, values) }
  self
end