@@ -24,20 +24,35 @@ fn main() {
24
24
. run ( ) ;
25
25
}
26
26
27
- const ANIMATIONS : [ ( & str , Transform , f32 ) ; 3 ] = [
28
- (
29
- // Model being loaded
27
+ struct Example {
28
+ model_name : & ' static str ,
29
+ camera_transform : Transform ,
30
+ speed : f32 ,
31
+ }
32
+ impl Example {
33
+ const fn new ( model_name : & ' static str , camera_transform : Transform , speed : f32 ) -> Self {
34
+ Self {
35
+ model_name,
36
+ camera_transform,
37
+ speed,
38
+ }
39
+ }
40
+ }
41
+
42
+ // const ANIMATIONS: [(&str, Transform, f32); 3] = [
43
+ const ANIMATIONS : [ Example ; 3 ] = [
44
+ // https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedTriangle
45
+ Example :: new (
30
46
"models/animated/AnimatedTriangle.gltf" ,
31
- // Position of the camera
32
47
Transform {
33
48
translation : const_vec3 ! ( [ 0.0 , 0.0 , 3.0 ] ) ,
34
49
rotation : const_quat ! ( [ 0.0 , 0.0 , 0.0 , 1.0 ] ) ,
35
50
scale : const_vec3 ! ( [ 1.0 ; 3 ] ) ,
36
51
} ,
37
- // Speed of the animation
38
52
0.12 ,
39
53
) ,
40
- (
54
+ // https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/BoxAnimated
55
+ Example :: new (
41
56
"models/animated/BoxAnimated.gltf" ,
42
57
Transform {
43
58
translation : const_vec3 ! ( [ 4.0 , 2.0 , 4.0 ] ) ,
@@ -46,7 +61,7 @@ const ANIMATIONS: [(&str, Transform, f32); 3] = [
46
61
} ,
47
62
0.4 ,
48
63
) ,
49
- (
64
+ Example :: new (
50
65
"models/animated/animations.gltf" ,
51
66
Transform {
52
67
translation : const_vec3 ! ( [ -10.0 , 5.0 , -3.0 ] ) ,
@@ -76,16 +91,17 @@ fn setup(
76
91
// Insert a resource with the current scene information
77
92
commands. insert_resource ( CurrentScene {
78
93
// Its instance id, to be able to check that it's loaded
79
- instance_id : scene_spawner. spawn ( asset_server. load ( & format ! ( "{}#Scene0" , ANIMATIONS [ 0 ] . 0 ) ) ) ,
94
+ instance_id : scene_spawner
95
+ . spawn ( asset_server. load ( & format ! ( "{}#Scene0" , ANIMATIONS [ 0 ] . model_name) ) ) ,
80
96
// The handle to the first animation
81
- animation : asset_server. load ( & format ! ( "{}#Animation0" , ANIMATIONS [ 0 ] . 0 ) ) ,
97
+ animation : asset_server. load ( & format ! ( "{}#Animation0" , ANIMATIONS [ 0 ] . model_name ) ) ,
82
98
// The animation speed modifier
83
- speed : ANIMATIONS [ 0 ] . 2 ,
99
+ speed : ANIMATIONS [ 0 ] . speed ,
84
100
} ) ;
85
101
86
102
// Add a camera
87
103
commands. spawn_bundle ( PerspectiveCameraBundle {
88
- transform : ANIMATIONS [ 0 ] . 1 ,
104
+ transform : ANIMATIONS [ 0 ] . camera_transform ,
89
105
..Default :: default ( )
90
106
} ) ;
91
107
@@ -107,13 +123,14 @@ fn switch_scene(
107
123
108
124
// Despawn the existing scene, then start loading the next one
109
125
commands. entity ( scene_root. single ( ) ) . despawn_recursive ( ) ;
110
- current_scene. instance_id =
111
- scene_spawner. spawn ( asset_server. load ( & format ! ( "{}#Scene0" , ANIMATIONS [ * current] . 0 ) ) ) ;
112
- current_scene. animation = asset_server. load ( & format ! ( "{}#Animation0" , ANIMATIONS [ * current] . 0 ) ) ;
113
- current_scene. speed = ANIMATIONS [ * current] . 2 ;
126
+ current_scene. instance_id = scene_spawner
127
+ . spawn ( asset_server. load ( & format ! ( "{}#Scene0" , ANIMATIONS [ * current] . model_name) ) ) ;
128
+ current_scene. animation =
129
+ asset_server. load ( & format ! ( "{}#Animation0" , ANIMATIONS [ * current] . model_name) ) ;
130
+ current_scene. speed = ANIMATIONS [ * current] . speed ;
114
131
115
132
// Update the camera position
116
- * camera. single_mut ( ) = ANIMATIONS [ * current] . 1 ;
133
+ * camera. single_mut ( ) = ANIMATIONS [ * current] . camera_transform ;
117
134
118
135
// Reset the current animation
119
136
commands. remove_resource :: < CurrentAnimation > ( ) ;
0 commit comments