Class: Bestguigui::GLTFAnimation

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

Overview

Un clip d'animation glTF : un nom, une duree, et des canaux — chacun anime UNE propriete (:translation, :rotation ou :scale) d'UN noeud. local_pose_at echantillonne tous les canaux a un instant donne ; ne renvoie que les noeuds/proprietes reellement animes ici — GLTFSkeleton complete le reste avec la pose de repos de chaque noeud.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, channels) ⇒ GLTFAnimation

channels : tableau de path:, times:, values:, interpolation: — times triees (secondes), values un tableau de tableaux (une entree par keyframe : 3 composantes pour translation/scale, 4 pour rotation), interpolation 'LINEAR' ou 'STEP' (le seul autre cas standard, CUBICSPLINE, n'est pas gere — retombe sur un LINEAR).



17
18
19
20
21
# File 'lib/bestguigui_lab/gltf_animation.rb', line 17

def initialize(name, channels)
    @name = name
    @channels = channels
    @duration = channels.map { |channel| channel[:times].last || 0.0 }.max || 0.0
end

Instance Attribute Details

#duration ⇒ Object (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#local_pose_at(time) ⇒ Object



23
24
25
26
27
# File 'lib/bestguigui_lab/gltf_animation.rb', line 23

def local_pose_at(time)
    pose = Hash.new { |h, k| h[k] = {} }
    @channels.each { |channel| pose[channel[:node]][channel[:path]] = sample_channel(channel, time) }
    pose
end