diff options
author | 3gg <3gg@shellblade.net> | 2024-02-17 13:08:35 -0800 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2024-02-17 13:08:35 -0800 |
commit | 7b756cc336f076fe95deb59847492b4127f82132 (patch) | |
tree | 365fc9a388bff1d0d347b8e86ba6b8c97490d4fb /game | |
parent | 13c7adb42168a566c97f36db76080d80e02a6aae (diff) |
Introduce Model.
Diffstat (limited to 'game')
-rw-r--r-- | game/src/plugins/viewer.c | 46 |
1 files changed, 32 insertions, 14 deletions
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 @@ | |||
3 | #include <gfx/asset.h> | 3 | #include <gfx/asset.h> |
4 | #include <gfx/renderer.h> | 4 | #include <gfx/renderer.h> |
5 | #include <gfx/scene.h> | 5 | #include <gfx/scene.h> |
6 | #include <gfx/scene/scene.h> | ||
7 | #include <gfx/util/skyquad.h> | 6 | #include <gfx/util/skyquad.h> |
8 | #include <math/camera.h> | 7 | #include <math/camera.h> |
9 | #include <math/spatial3.h> | 8 | #include <math/spatial3.h> |
@@ -26,6 +25,7 @@ static const char* GIRL = | |||
26 | 25 | ||
27 | struct State { | 26 | struct State { |
28 | Scene* scene; | 27 | Scene* scene; |
28 | Model* model; | ||
29 | SceneCamera* camera; | 29 | SceneCamera* camera; |
30 | }; | 30 | }; |
31 | 31 | ||
@@ -65,8 +65,8 @@ static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | /// Load the 3D scene. | 67 | /// Load the 3D scene. |
68 | static SceneNode* load_scene( | 68 | /// Return the loaded model. |
69 | Game* game, State* state, const char* scene_filepath) { | 69 | static Model* load_scene(Game* game, State* state, const char* scene_filepath) { |
70 | assert(game); | 70 | assert(game); |
71 | assert(game->gfx); | 71 | assert(game->gfx); |
72 | assert(state); | 72 | assert(state); |
@@ -81,17 +81,22 @@ static SceneNode* load_scene( | |||
81 | return 0; // test | 81 | return 0; // test |
82 | } | 82 | } |
83 | 83 | ||
84 | SceneNode* scene_node = gfx_load_scene( | 84 | Model* model = gfx_load_model( |
85 | game->gfx, sky_light_node, | 85 | game->gfx, |
86 | &(LoadSceneCmd){ | 86 | &(LoadModelCmd){ |
87 | .origin = AssetFromFile, .filepath = mstring_make(scene_filepath)}); | 87 | .origin = AssetFromFile, .filepath = mstring_make(scene_filepath)}); |
88 | if (!scene_node) { | 88 | if (!model) { |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | SceneNode* model_node = gfx_make_model_node(model); | ||
92 | if (!model_node) { | ||
93 | return 0; | ||
94 | } | ||
95 | gfx_set_node_parent(model_node, sky_light_node); | ||
91 | 96 | ||
92 | gfx_log_node_hierarchy(root); | 97 | gfx_log_node_hierarchy(root); |
93 | 98 | ||
94 | return scene_node; | 99 | return model; |
95 | } | 100 | } |
96 | 101 | ||
97 | bool init(Game* game, State** pp_state) { | 102 | bool init(Game* game, State** pp_state) { |
@@ -115,13 +120,13 @@ bool init(Game* game, State** pp_state) { | |||
115 | // Usage: <scene file> | 120 | // Usage: <scene file> |
116 | const char* scene_filepath = argc > 1 ? argv[1] : DEFAULT_SCENE_FILE; | 121 | const char* scene_filepath = argc > 1 ? argv[1] : DEFAULT_SCENE_FILE; |
117 | 122 | ||
118 | SceneNode* node = load_scene(game, state, scene_filepath); | 123 | state->model = load_scene(game, state, scene_filepath); |
119 | if (!node) { | 124 | if (!state->model) { |
120 | goto cleanup; | 125 | goto cleanup; |
121 | } | 126 | } |
122 | 127 | ||
123 | if (gfx_get_node_type(node) == AnimaNode) { | 128 | Anima* anima = gfx_get_model_anima(state->model); |
124 | Anima* anima = gfx_get_node_anima(node); | 129 | if (anima) { |
125 | gfx_play_animation( | 130 | gfx_play_animation( |
126 | anima, &(AnimationPlaySettings){.name = "Walk", .loop = true}); | 131 | anima, &(AnimationPlaySettings){.name = "Walk", .loop = true}); |
127 | } | 132 | } |
@@ -156,7 +161,13 @@ void update(Game* game, State* state, double t, double dt) { | |||
156 | assert(state->scene); | 161 | assert(state->scene); |
157 | assert(state->camera); | 162 | assert(state->camera); |
158 | 163 | ||
159 | gfx_animate_scene(state->scene, (R)t); | 164 | // TODO: Move this to some sort of update_scene(). Note that models do not |
165 | // need to be animated if they are not visible to the camera. The camera | ||
166 | // update also should happen first. | ||
167 | Anima* anima = gfx_get_model_anima(state->model); | ||
168 | if (anima) { | ||
169 | gfx_update_animation(anima, (R)t); | ||
170 | } | ||
160 | 171 | ||
161 | const vec3 orbit_point = vec3_make(0, 2, 0); | 172 | const vec3 orbit_point = vec3_make(0, 2, 0); |
162 | Camera* camera = gfx_get_camera_camera(state->camera); | 173 | Camera* camera = gfx_get_camera_camera(state->camera); |
@@ -171,7 +182,14 @@ void update(Game* game, State* state, double t, double dt) { | |||
171 | static void render_bounding_boxes_rec(ImmRenderer* imm, const SceneNode* node) { | 182 | static void render_bounding_boxes_rec(ImmRenderer* imm, const SceneNode* node) { |
172 | assert(imm); | 183 | assert(imm); |
173 | assert(node); | 184 | assert(node); |
174 | if (gfx_get_node_type(node) == ObjectNode) { | 185 | |
186 | const NodeType node_type = gfx_get_node_type(node); | ||
187 | |||
188 | if (node_type == ModelNode) { | ||
189 | const Model* model = gfx_get_node_model(node); | ||
190 | const SceneNode* root = gfx_get_model_root(model); | ||
191 | render_bounding_boxes_rec(imm, root); | ||
192 | } else if (node_type == ObjectNode) { | ||
175 | // TODO: Look at the scene log. The JointNodes are detached from the | 193 | // TODO: Look at the scene log. The JointNodes are detached from the |
176 | // ObjectNodes. This is why the boxes are not being transformed as expected | 194 | // ObjectNodes. This is why the boxes are not being transformed as expected |
177 | // here. Anima needs to animate boxes? Use OOBB in addition to AABB? | 195 | // here. Anima needs to animate boxes? Use OOBB in addition to AABB? |