Class: Bestguigui::GLTFModel

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

Overview

Charge un modele .glb (glTF binaire auto-suffisant, cf. GLTFBuffer) : squelette + animations (GLTFSkeleton/GLTFAnimation/GLTFAnimator), skinning CPU (GLTFPrimitive), shading: :texture ou :gouraud, rigid: true pour ignorer la mise a l'echelle des os.

model = Bestguigui::Assets.gltf_model('assets/jill.glb')
model.play('Idle')
model.update(dt) # puis model.draw, dans ta Scene
model.play('walk', transition: 0.3)

Instance Method Summary collapse

Constructor Details

#initialize(path, shading: :texture, rigid: false, speed: 1.0) ⇒ GLTFModel

Returns a new instance of GLTFModel.



16
17
18
19
20
21
22
23
# File 'lib/bestguigui_lab/gltf_model.rb', line 16

def initialize(path, shading: :texture, rigid: false, speed: 1.0)
    super()
    @shading = shading
    @rigid = rigid
    load_scene(path)
    @animator = GLTFAnimator.new(speed: speed)
    reskin
end

Instance Method Details

#animation_names ⇒ Object



25
# File 'lib/bestguigui_lab/gltf_model.rb', line 25

def animation_names = @animations.keys

#draw ⇒ Object



42
43
44
# File 'lib/bestguigui_lab/gltf_model.rb', line 42

def draw
    @primitives.each(&:draw)
end

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



32
33
34
35
# File 'lib/bestguigui_lab/gltf_model.rb', line 32

def play(name, loop: true, transition: 0.0)
    animation = @animations.fetch(name) { raise ArgumentError, "animation glTF inconnue : #{name.inspect}" }
    @animator.play(animation, loop: loop, transition: transition)
end

#speed ⇒ Object



26
# File 'lib/bestguigui_lab/gltf_model.rb', line 26

def speed = @animator.speed

#speed=(value) ⇒ Object



28
29
30
# File 'lib/bestguigui_lab/gltf_model.rb', line 28

def speed=(value)
    @animator.speed = value
end

#update(dt) ⇒ Object



37
38
39
40
# File 'lib/bestguigui_lab/gltf_model.rb', line 37

def update(dt)
    @animator.update(dt)
    reskin
end