From 7b756cc336f076fe95deb59847492b4127f82132 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 17 Feb 2024 13:08:35 -0800 Subject: Introduce Model. --- game/src/plugins/viewer.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) (limited to 'game/src/plugins') diff --git a/game/src/plugins/viewer.c b/game/src/plugins/viewer.c index 40213e4..dd7f451 100644 --- a/game/src/plugins/viewer.c +++ b/game/src/plugins/viewer.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -26,6 +25,7 @@ static const char* GIRL = struct State { Scene* scene; + Model* model; SceneCamera* camera; }; @@ -65,8 +65,8 @@ static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) { } /// Load the 3D scene. -static SceneNode* load_scene( - Game* game, State* state, const char* scene_filepath) { +/// Return the loaded model. +static Model* load_scene(Game* game, State* state, const char* scene_filepath) { assert(game); assert(game->gfx); assert(state); @@ -81,17 +81,22 @@ static SceneNode* load_scene( return 0; // test } - SceneNode* scene_node = gfx_load_scene( - game->gfx, sky_light_node, - &(LoadSceneCmd){ + Model* model = gfx_load_model( + game->gfx, + &(LoadModelCmd){ .origin = AssetFromFile, .filepath = mstring_make(scene_filepath)}); - if (!scene_node) { + if (!model) { return 0; } + SceneNode* model_node = gfx_make_model_node(model); + if (!model_node) { + return 0; + } + gfx_set_node_parent(model_node, sky_light_node); gfx_log_node_hierarchy(root); - return scene_node; + return model; } bool init(Game* game, State** pp_state) { @@ -115,13 +120,13 @@ bool init(Game* game, State** pp_state) { // Usage: const char* scene_filepath = argc > 1 ? argv[1] : DEFAULT_SCENE_FILE; - SceneNode* node = load_scene(game, state, scene_filepath); - if (!node) { + state->model = load_scene(game, state, scene_filepath); + if (!state->model) { goto cleanup; } - if (gfx_get_node_type(node) == AnimaNode) { - Anima* anima = gfx_get_node_anima(node); + Anima* anima = gfx_get_model_anima(state->model); + if (anima) { gfx_play_animation( anima, &(AnimationPlaySettings){.name = "Walk", .loop = true}); } @@ -156,7 +161,13 @@ void update(Game* game, State* state, double t, double dt) { assert(state->scene); assert(state->camera); - gfx_animate_scene(state->scene, (R)t); + // TODO: Move this to some sort of update_scene(). Note that models do not + // need to be animated if they are not visible to the camera. The camera + // update also should happen first. + Anima* anima = gfx_get_model_anima(state->model); + if (anima) { + gfx_update_animation(anima, (R)t); + } const vec3 orbit_point = vec3_make(0, 2, 0); Camera* camera = gfx_get_camera_camera(state->camera); @@ -171,7 +182,14 @@ void update(Game* game, State* state, double t, double dt) { static void render_bounding_boxes_rec(ImmRenderer* imm, const SceneNode* node) { assert(imm); assert(node); - if (gfx_get_node_type(node) == ObjectNode) { + + const NodeType node_type = gfx_get_node_type(node); + + if (node_type == ModelNode) { + const Model* model = gfx_get_node_model(node); + const SceneNode* root = gfx_get_model_root(model); + render_bounding_boxes_rec(imm, root); + } else if (node_type == ObjectNode) { // TODO: Look at the scene log. The JointNodes are detached from the // ObjectNodes. This is why the boxes are not being transformed as expected // here. Anima needs to animate boxes? Use OOBB in addition to AABB? -- cgit v1.2.3