Class: Bestguigui::GLTFAnimator

Inherits:
Object
  • Object
show all
Defined in:
lib/bestguigui_lab/gltf_animator.rb

Overview

Lit le temps d'une GLTFAnimation et renvoie sa pose locale — fondu enchaine (en temps reel, quel que soit speed) depuis la pose FIGEE de l'animation precedente au moment du #play, jamais depuis une pose qu'on continuerait a faire avancer/boucler pendant le fondu (ca blend deux cibles mouvantes, incoherent des que speed est eleve).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(speed: 1.0) ⇒ GLTFAnimator

Returns a new instance of GLTFAnimator.



12
13
14
15
16
17
18
19
20
# File 'lib/bestguigui_lab/gltf_animator.rb', line 12

def initialize(speed: 1.0)
    @current = nil
    @time = 0.0
    @loop = true
    @previous_pose = nil
    @transition_duration = 0.0
    @transition_elapsed = 0.0
    @speed = speed
end

Instance Attribute Details

#speed ⇒ Object

Returns the value of attribute speed.



10
11
12
# File 'lib/bestguigui_lab/gltf_animator.rb', line 10

def speed
  @speed
end

Instance Method Details

#play(animation, loop: true, transition: 0.0) ⇒ Object

transition: duree reelle (secondes) du fondu, independante de speed.



23
24
25
26
27
28
29
30
# File 'lib/bestguigui_lab/gltf_animator.rb', line 23

def play(animation, loop: true, transition: 0.0)
    @previous_pose = transition.positive? && @current ? pose : nil
    @current = animation
    @loop = loop
    @time = 0.0
    @transition_duration = transition
    @transition_elapsed = 0.0
end

#pose ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/bestguigui_lab/gltf_animator.rb', line 42

def pose
    return {} unless @current

    current_pose = @current.local_pose_at(@time)
    return current_pose unless @previous_pose

    blend_t = @transition_duration.zero? ? 1.0 : (@transition_elapsed / @transition_duration).clamp(0.0, 1.0)
    blend_poses(@previous_pose, current_pose, blend_t)
end

#update(dt) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/bestguigui_lab/gltf_animator.rb', line 32

def update(dt)
    return unless @current

    @time = advance_time(@time, dt * @speed, @current, @loop)
    return unless @previous_pose

    @transition_elapsed += dt
    @previous_pose = nil if @transition_elapsed >= @transition_duration
end