diff options
author | 3gg <3gg@shellblade.net> | 2023-02-04 14:36:02 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-02-04 14:36:02 -0800 |
commit | 8068d0a816b3efd17ebb0dcf468c6d333e3577d3 (patch) | |
tree | f88f0845c34efbb1c43f88ea71fcbf32ea5adae9 /gltfview | |
parent | f319f0bb59f5e05bd06dcd160699f2b0f2f14e8a (diff) |
Add support for skeletal animation.
Diffstat (limited to 'gltfview')
-rw-r--r-- | gltfview/src/game.c | 41 | ||||
-rw-r--r-- | gltfview/src/game.h | 11 |
2 files changed, 31 insertions, 21 deletions
diff --git a/gltfview/src/game.c b/gltfview/src/game.c index 612ec67..1db7cba 100644 --- a/gltfview/src/game.c +++ b/gltfview/src/game.c | |||
@@ -89,13 +89,13 @@ static SceneNode* load_skyquad(Game* game) { | |||
89 | } | 89 | } |
90 | 90 | ||
91 | /// Load the 3D scene. | 91 | /// Load the 3D scene. |
92 | static bool load_scene( | 92 | static SceneNode* load_scene( |
93 | Game* game, const char* scene_filepath, const char* view_mode) { | 93 | Game* game, const char* scene_filepath, const char* view_mode) { |
94 | assert(game); | 94 | assert(game); |
95 | 95 | ||
96 | game->camera = gfx_make_camera(); | 96 | game->camera = gfx_make_camera(); |
97 | if (!game->camera) { | 97 | if (!game->camera) { |
98 | return false; | 98 | return 0; |
99 | } | 99 | } |
100 | Camera* camera = gfx_get_camera_camera(game->camera); | 100 | Camera* camera = gfx_get_camera_camera(game->camera); |
101 | // Sponza. | 101 | // Sponza. |
@@ -105,7 +105,7 @@ static bool load_scene( | |||
105 | 105 | ||
106 | SceneNode* sky_light_node = load_skyquad(game); | 106 | SceneNode* sky_light_node = load_skyquad(game); |
107 | if (!sky_light_node) { | 107 | if (!sky_light_node) { |
108 | return false; | 108 | return 0; |
109 | } | 109 | } |
110 | 110 | ||
111 | // TODO: Move the debug rendering to the renderer. | 111 | // TODO: Move the debug rendering to the renderer. |
@@ -114,16 +114,16 @@ static bool load_scene( | |||
114 | // return false; | 114 | // return false; |
115 | // } | 115 | // } |
116 | 116 | ||
117 | if (!gfx_load_scene( | 117 | SceneNode* scene_node = gfx_load_scene( |
118 | game->gfx, sky_light_node, | 118 | game->gfx, sky_light_node, |
119 | &(LoadSceneCmd){ | 119 | &(LoadSceneCmd){.origin = SceneFromFile, .filepath = scene_filepath}); |
120 | .origin = SceneFromFile, .filepath = scene_filepath})) { | 120 | if (!scene_node) { |
121 | return false; | 121 | return 0; |
122 | } | 122 | } |
123 | 123 | ||
124 | gfx_log_node_hierarchy(gfx_get_scene_root(game->scene)); | 124 | gfx_log_node_hierarchy(gfx_get_scene_root(game->scene)); |
125 | 125 | ||
126 | return true; | 126 | return scene_node; |
127 | } | 127 | } |
128 | 128 | ||
129 | /// Load a scene for debugging textures. | 129 | /// Load a scene for debugging textures. |
@@ -207,13 +207,23 @@ bool game_new(Game* game, int argc, const char** argv) { | |||
207 | goto cleanup; | 207 | goto cleanup; |
208 | } | 208 | } |
209 | 209 | ||
210 | if (!load_scene(game, scene_filepath, view_mode)) { | 210 | game->root_node = load_scene(game, scene_filepath, view_mode); |
211 | if (!game->root_node) { | ||
211 | goto cleanup; | 212 | goto cleanup; |
212 | } | 213 | } |
213 | /*if (!load_texture_debugger_scene(game)) { | 214 | /*if (!load_texture_debugger_scene(game)) { |
214 | goto cleanup; | 215 | goto cleanup; |
215 | }*/ | 216 | }*/ |
216 | 217 | ||
218 | Anima* anima = gfx_get_node_anima(game->root_node); | ||
219 | |||
220 | // const bool play_result = gfx_play_animation( | ||
221 | // anima, &(AnimationPlaySettings){.name = "Defiant stance", .loop = | ||
222 | // false}); | ||
223 | const bool play_result = gfx_play_animation( | ||
224 | anima, &(AnimationPlaySettings){.name = "Walk", .loop = true}); | ||
225 | assert(play_result); | ||
226 | |||
217 | return true; | 227 | return true; |
218 | 228 | ||
219 | cleanup: | 229 | cleanup: |
@@ -227,12 +237,11 @@ cleanup: | |||
227 | void game_end(Game* game) { gfx_destroy(&game->gfx); } | 237 | void game_end(Game* game) { gfx_destroy(&game->gfx); } |
228 | 238 | ||
229 | void game_update(Game* game, double t, double dt) { | 239 | void game_update(Game* game, double t, double dt) { |
230 | game->elapsed += dt; | 240 | // LOGD("Tick"); |
231 | while (game->elapsed >= 1.0) { | 241 | |
232 | // LOGD("Tick"); | 242 | Anima* anima = gfx_get_node_anima(game->root_node); |
233 | usleep(1000); | 243 | gfx_update_animation(anima, t); |
234 | game->elapsed -= 1.0; | 244 | |
235 | } | ||
236 | // TODO: Compute bounding boxes to then find a good orbit point and radius | 245 | // TODO: Compute bounding boxes to then find a good orbit point and radius |
237 | // for each scene. | 246 | // for each scene. |
238 | const vec3 orbit_point = vec3_make(0, 2, 0); | 247 | const vec3 orbit_point = vec3_make(0, 2, 0); |
diff --git a/gltfview/src/game.h b/gltfview/src/game.h index 92c0885..4aeb5ea 100644 --- a/gltfview/src/game.h +++ b/gltfview/src/game.h | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <gfx/render_backend.h> | 4 | #include <gfx/render_backend.h> |
5 | #include <gfx/renderer.h> | 5 | #include <gfx/renderer.h> |
6 | #include <gfx/scene/camera.h> | 6 | #include <gfx/scene/camera.h> |
7 | #include <gfx/scene/node.h> | ||
7 | #include <gfx/scene/scene.h> | 8 | #include <gfx/scene/scene.h> |
8 | 9 | ||
9 | #include <stdbool.h> | 10 | #include <stdbool.h> |
@@ -13,12 +14,12 @@ static const double game_dt = 1.0 / 60.0; | |||
13 | 14 | ||
14 | /// Game state. | 15 | /// Game state. |
15 | typedef struct { | 16 | typedef struct { |
16 | Gfx* gfx; | 17 | Gfx* gfx; |
17 | RenderBackend* render_backend; | 18 | RenderBackend* render_backend; |
18 | Renderer* renderer; | 19 | Renderer* renderer; |
19 | Scene* scene; | 20 | Scene* scene; |
20 | SceneCamera* camera; | 21 | SceneCamera* camera; |
21 | double elapsed; | 22 | SceneNode* root_node; |
22 | } Game; | 23 | } Game; |
23 | 24 | ||
24 | bool game_new(Game*, int argc, const char** argv); | 25 | bool game_new(Game*, int argc, const char** argv); |