bestguigui_lab 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bestguigui_lab/gltf_animator.rb +6 -3
- data/lib/bestguigui_lab/gltf_model.rb +14 -19
- data/lib/bestguigui_lab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ef2f3f88c26af654bbcc041f8bd7fc933a63c5609d747d97a7a293ddf76675ec
|
|
4
|
+
data.tar.gz: 788af1255f57430851b9c540cece24285f318ea815ec509b3a846ce314e0180b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54e63a9a9e6e8db8553290ee3b00dae55b774a8f935b164574af1504e5577683886bcea05f8c1a7c39b53436e479afbc5d1d7d3fe32fde3b287630027176b0fb
|
|
7
|
+
data.tar.gz: 941c362b66dc200c264f13fa6694a9c359f183a0de09784e4fcc1bdf438e99c11413b64d83678adc05de87c8ad3be51454c68fd3fa246d70873beb48dbc9e803
|
|
@@ -6,7 +6,9 @@ module Bestguigui
|
|
|
6
6
|
# temps de la transition, jamais de coupure nette d'une animation a
|
|
7
7
|
# l'autre. GLTFModel#play/#update s'en servent directement.
|
|
8
8
|
class GLTFAnimator
|
|
9
|
-
|
|
9
|
+
attr_accessor :speed
|
|
10
|
+
|
|
11
|
+
def initialize(speed: 1.0)
|
|
10
12
|
@current = nil
|
|
11
13
|
@time = 0.0
|
|
12
14
|
@loop = true
|
|
@@ -15,6 +17,7 @@ module Bestguigui
|
|
|
15
17
|
@previous_loop = true
|
|
16
18
|
@transition_duration = 0.0
|
|
17
19
|
@transition_elapsed = 0.0
|
|
20
|
+
@speed = speed
|
|
18
21
|
end
|
|
19
22
|
|
|
20
23
|
# loop: rejoue en boucle une fois la fin atteinte. transition: duree
|
|
@@ -35,10 +38,10 @@ module Bestguigui
|
|
|
35
38
|
def update(dt)
|
|
36
39
|
return unless @current
|
|
37
40
|
|
|
38
|
-
@time = advance_time(@time, dt, @current, @loop)
|
|
41
|
+
@time = advance_time(@time, dt * @speed, @current, @loop)
|
|
39
42
|
return unless @previous
|
|
40
43
|
|
|
41
|
-
@previous_time = advance_time(@previous_time, dt, @previous, @previous_loop)
|
|
44
|
+
@previous_time = advance_time(@previous_time, dt * @speed, @previous, @previous_loop)
|
|
42
45
|
@transition_elapsed += dt
|
|
43
46
|
@previous = nil if @transition_elapsed >= @transition_duration
|
|
44
47
|
end
|
|
@@ -3,34 +3,31 @@
|
|
|
3
3
|
require 'tempfile'
|
|
4
4
|
|
|
5
5
|
module Bestguigui
|
|
6
|
-
# Charge un modele .glb (glTF binaire
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# sur le CPU (voir GLTFPrimitive). Un seul skin/squelette par fichier
|
|
11
|
-
# (cf. GLTFSkeleton).
|
|
6
|
+
# Charge un modele .glb (glTF binaire auto-suffisant, cf. GLTFBuffer) :
|
|
7
|
+
# squelette + animations (GLTFSkeleton/GLTFAnimation/GLTFAnimator),
|
|
8
|
+
# skinning CPU (GLTFPrimitive), shading: :texture ou :gouraud, rigid:
|
|
9
|
+
# true pour ignorer la mise a l'echelle des os.
|
|
12
10
|
#
|
|
13
11
|
# model = Bestguigui::Assets.gltf_model('assets/jill.glb')
|
|
14
12
|
# model.play('Idle')
|
|
15
|
-
#
|
|
16
|
-
# model.
|
|
17
|
-
# model.draw
|
|
18
|
-
# model.play('walk', transition: 0.3) # fondu enchaine de 0.3s vers walk
|
|
19
|
-
#
|
|
20
|
-
# rigid: true interdit toute deformation du maillage par mise a
|
|
21
|
-
# l'echelle d'un os (seules rotation et translation l'articulent) — voir
|
|
22
|
-
# GLTFSkeleton.
|
|
13
|
+
# model.update(dt) # puis model.draw, dans ta Scene
|
|
14
|
+
# model.play('walk', transition: 0.3)
|
|
23
15
|
class GLTFModel
|
|
24
|
-
def initialize(path, shading: :texture, rigid: false)
|
|
16
|
+
def initialize(path, shading: :texture, rigid: false, speed: 1.0)
|
|
25
17
|
super()
|
|
26
18
|
@shading = shading
|
|
27
19
|
@rigid = rigid
|
|
28
20
|
load_scene(path)
|
|
29
|
-
@animator = GLTFAnimator.new
|
|
21
|
+
@animator = GLTFAnimator.new(speed: speed)
|
|
30
22
|
reskin
|
|
31
23
|
end
|
|
32
24
|
|
|
33
25
|
def animation_names = @animations.keys
|
|
26
|
+
def speed = @animator.speed
|
|
27
|
+
|
|
28
|
+
def speed=(value)
|
|
29
|
+
@animator.speed = value
|
|
30
|
+
end
|
|
34
31
|
|
|
35
32
|
def play(name, loop: true, transition: 0.0)
|
|
36
33
|
animation = @animations.fetch(name) { raise ArgumentError, "animation glTF inconnue : #{name.inspect}" }
|
|
@@ -121,9 +118,7 @@ module Bestguigui
|
|
|
121
118
|
return nil unless material_index
|
|
122
119
|
|
|
123
120
|
texture_ref = @json['materials'][material_index].dig('pbrMetallicRoughness', 'baseColorTexture')
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
@textures[@json['textures'][texture_ref['index']]['source']]
|
|
121
|
+
texture_ref && @textures[@json['textures'][texture_ref['index']]['source']]
|
|
127
122
|
end
|
|
128
123
|
|
|
129
124
|
# --- Texture embarquee : ecrite dans un fichier temporaire le temps
|