From 8068d0a816b3efd17ebb0dcf468c6d333e3577d3 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Feb 2023 14:36:02 -0800 Subject: Add support for skeletal animation. --- gltfview/src/game.c | 41 +++++++++++++++++++++++++---------------- gltfview/src/game.h | 11 ++++++----- 2 files changed, 31 insertions(+), 21 deletions(-) (limited to 'gltfview') 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) { } /// Load the 3D scene. -static bool load_scene( +static SceneNode* load_scene( Game* game, const char* scene_filepath, const char* view_mode) { assert(game); game->camera = gfx_make_camera(); if (!game->camera) { - return false; + return 0; } Camera* camera = gfx_get_camera_camera(game->camera); // Sponza. @@ -105,7 +105,7 @@ static bool load_scene( SceneNode* sky_light_node = load_skyquad(game); if (!sky_light_node) { - return false; + return 0; } // TODO: Move the debug rendering to the renderer. @@ -114,16 +114,16 @@ static bool load_scene( // return false; // } - if (!gfx_load_scene( - game->gfx, sky_light_node, - &(LoadSceneCmd){ - .origin = SceneFromFile, .filepath = scene_filepath})) { - return false; + SceneNode* scene_node = gfx_load_scene( + game->gfx, sky_light_node, + &(LoadSceneCmd){.origin = SceneFromFile, .filepath = scene_filepath}); + if (!scene_node) { + return 0; } gfx_log_node_hierarchy(gfx_get_scene_root(game->scene)); - return true; + return scene_node; } /// Load a scene for debugging textures. @@ -207,13 +207,23 @@ bool game_new(Game* game, int argc, const char** argv) { goto cleanup; } - if (!load_scene(game, scene_filepath, view_mode)) { + game->root_node = load_scene(game, scene_filepath, view_mode); + if (!game->root_node) { goto cleanup; } /*if (!load_texture_debugger_scene(game)) { goto cleanup; }*/ + Anima* anima = gfx_get_node_anima(game->root_node); + + // const bool play_result = gfx_play_animation( + // anima, &(AnimationPlaySettings){.name = "Defiant stance", .loop = + // false}); + const bool play_result = gfx_play_animation( + anima, &(AnimationPlaySettings){.name = "Walk", .loop = true}); + assert(play_result); + return true; cleanup: @@ -227,12 +237,11 @@ cleanup: void game_end(Game* game) { gfx_destroy(&game->gfx); } void game_update(Game* game, double t, double dt) { - game->elapsed += dt; - while (game->elapsed >= 1.0) { - // LOGD("Tick"); - usleep(1000); - game->elapsed -= 1.0; - } + // LOGD("Tick"); + + Anima* anima = gfx_get_node_anima(game->root_node); + gfx_update_animation(anima, t); + // TODO: Compute bounding boxes to then find a good orbit point and radius // for each scene. 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 @@ #include #include #include +#include #include #include @@ -13,12 +14,12 @@ static const double game_dt = 1.0 / 60.0; /// Game state. typedef struct { - Gfx* gfx; + Gfx* gfx; RenderBackend* render_backend; - Renderer* renderer; - Scene* scene; - SceneCamera* camera; - double elapsed; + Renderer* renderer; + Scene* scene; + SceneCamera* camera; + SceneNode* root_node; } Game; bool game_new(Game*, int argc, const char** argv); -- cgit v1.2.3