diff options
Diffstat (limited to 'game/src/plugins')
| -rw-r--r-- | game/src/plugins/viewer.c | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/game/src/plugins/viewer.c b/game/src/plugins/viewer.c index 83fc8ed..1ed3b9d 100644 --- a/game/src/plugins/viewer.c +++ b/game/src/plugins/viewer.c | |||
| @@ -30,31 +30,33 @@ struct State { | |||
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | /// Load the skyquad texture. | 32 | /// Load the skyquad texture. |
| 33 | static Texture* load_environment_map(RenderBackend* render_backend) { | 33 | static Texture* load_environment_map(Gfx* gfx) { |
| 34 | assert(gfx); | ||
| 34 | return gfx_load_texture( | 35 | return gfx_load_texture( |
| 35 | render_backend, | 36 | gfx, &(LoadTextureCmd){ |
| 36 | &(LoadTextureCmd){ | 37 | .origin = AssetFromFile, |
| 37 | .origin = TextureFromFile, | 38 | .type = LoadCubemap, |
| 38 | .type = LoadCubemap, | 39 | .colour_space = sRGB, |
| 39 | .colour_space = sRGB, | 40 | .filtering = NearestFiltering, |
| 40 | .filtering = NearestFiltering, | 41 | .mipmaps = false, |
| 41 | .mipmaps = false, | 42 | .data.cubemap.filepaths = { |
| 42 | .data.cubemap.filepaths = { | 43 | mstring_make("/assets/skybox/clouds1/clouds1_east.bmp"), |
| 43 | mstring_make("/assets/skybox/clouds1/clouds1_east.bmp"), | 44 | mstring_make("/assets/skybox/clouds1/clouds1_west.bmp"), |
| 44 | mstring_make("/assets/skybox/clouds1/clouds1_west.bmp"), | 45 | mstring_make("/assets/skybox/clouds1/clouds1_up.bmp"), |
| 45 | mstring_make("/assets/skybox/clouds1/clouds1_up.bmp"), | 46 | mstring_make("/assets/skybox/clouds1/clouds1_down.bmp"), |
| 46 | mstring_make("/assets/skybox/clouds1/clouds1_down.bmp"), | 47 | mstring_make("/assets/skybox/clouds1/clouds1_south.bmp"), |
| 47 | mstring_make("/assets/skybox/clouds1/clouds1_south.bmp"), | 48 | mstring_make("/assets/skybox/clouds1/clouds1_north.bmp")} |
| 48 | mstring_make("/assets/skybox/clouds1/clouds1_north.bmp")} | ||
| 49 | }); | 49 | }); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | /// Load the skyquad and return the environment light node. | 52 | /// Load the skyquad and return the environment light node. |
| 53 | static SceneNode* load_skyquad(RenderBackend* render_backend, SceneNode* root) { | 53 | static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) { |
| 54 | assert(render_backend); | 54 | assert(gfx); |
| 55 | assert(root); | 55 | assert(root); |
| 56 | 56 | ||
| 57 | Texture* environment_map = load_environment_map(render_backend); | 57 | RenderBackend* render_backend = gfx_get_render_backend(gfx); |
| 58 | |||
| 59 | Texture* environment_map = load_environment_map(gfx); | ||
| 58 | if (!environment_map) { | 60 | if (!environment_map) { |
| 59 | return 0; | 61 | return 0; |
| 60 | } | 62 | } |
| @@ -70,20 +72,19 @@ static SceneNode* load_scene( | |||
| 70 | assert(state); | 72 | assert(state); |
| 71 | assert(state->scene); | 73 | assert(state->scene); |
| 72 | 74 | ||
| 73 | SceneNode* root = gfx_get_scene_root(state->scene); | ||
| 74 | RenderBackend* render_backend = gfx_get_render_backend(game->gfx); | ||
| 75 | |||
| 76 | Camera* camera = gfx_get_camera_camera(state->camera); | 75 | Camera* camera = gfx_get_camera_camera(state->camera); |
| 77 | spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); | 76 | spatial3_set_position(&camera->spatial, vec3_make(0, 0, 2)); |
| 78 | 77 | ||
| 79 | SceneNode* sky_light_node = load_skyquad(render_backend, root); | 78 | SceneNode* root = gfx_get_scene_root(state->scene); |
| 79 | SceneNode* sky_light_node = load_skyquad(game->gfx, root); | ||
| 80 | if (!sky_light_node) { | 80 | if (!sky_light_node) { |
| 81 | return 0; | 81 | return 0; // test |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | SceneNode* scene_node = gfx_load_scene( | 84 | SceneNode* scene_node = gfx_load_scene( |
| 85 | game->gfx, sky_light_node, | 85 | game->gfx, sky_light_node, |
| 86 | &(LoadSceneCmd){.origin = SceneFromFile, .filepath = scene_filepath}); | 86 | &(LoadSceneCmd){ |
| 87 | .origin = AssetFromFile, .filepath = mstring_make(scene_filepath)}); | ||
| 87 | if (!scene_node) { | 88 | if (!scene_node) { |
| 88 | return 0; | 89 | return 0; |
| 89 | } | 90 | } |
| @@ -136,6 +137,10 @@ cleanup: | |||
| 136 | void shutdown(Game* game, State* state) { | 137 | void shutdown(Game* game, State* state) { |
| 137 | assert(game); | 138 | assert(game); |
| 138 | if (state) { | 139 | if (state) { |
| 140 | // TODO: Destroying the scene here currently does not play well with asset | ||
| 141 | // reloading. The issue is that we expect to mutate the scene/model during | ||
| 142 | // animation. This needs to change if we want to be able to cache assets | ||
| 143 | // in memory. | ||
| 139 | gfx_destroy_camera(&state->camera); | 144 | gfx_destroy_camera(&state->camera); |
| 140 | gfx_destroy_scene(&state->scene); | 145 | gfx_destroy_scene(&state->scene); |
| 141 | // State freed by plugin engine. | 146 | // State freed by plugin engine. |
| @@ -165,8 +170,20 @@ static void render_bounding_boxes_rec(ImmRenderer* imm, const SceneNode* node) { | |||
| 165 | assert(node); | 170 | assert(node); |
| 166 | if (gfx_get_node_type(node) == ObjectNode) { | 171 | if (gfx_get_node_type(node) == ObjectNode) { |
| 167 | // TODO: Look at the scene log. The JointNodes are detached from the | 172 | // TODO: Look at the scene log. The JointNodes are detached from the |
| 168 | // ObjectNodes. This is why the boxes are not being transformed as expected | 173 | // ObjectNodes. This is why the boxes are not being transformed as expected |
| 169 | // here. Anima needs to animate boxes? Use OOBB in addition to AABB? | 174 | // here. Anima needs to animate boxes? Use OOBB in addition to AABB? |
| 175 | // | ||
| 176 | // TODO: Idea: when a model is loaded, compute an OOBB per joint using the | ||
| 177 | // vertices that are affected by the joint. Then transform this OOBB when | ||
| 178 | // animating the skeleton. Start with AABB for simplicity. The AABB/OOBB | ||
| 179 | // in the skeleton should be const. The transform AABB/OOBB is derived | ||
| 180 | // on demand. Stack allocator would be best for this kind of per-frame | ||
| 181 | // data. | ||
| 182 | // | ||
| 183 | // TODO: After computing joint AABB/OOBBs, check here whether the node has | ||
| 184 | // a skeleton, and if so, render the skeleton's boxes instead of the | ||
| 185 | // node's (the node's boxes are not animated, but computer from the rest | ||
| 186 | // pose). | ||
| 170 | const mat4 model = gfx_get_node_global_transform(node); | 187 | const mat4 model = gfx_get_node_global_transform(node); |
| 171 | const SceneObject* obj = gfx_get_node_object(node); | 188 | const SceneObject* obj = gfx_get_node_object(node); |
| 172 | const aabb3 box = gfx_calc_object_aabb(obj); | 189 | const aabb3 box = gfx_calc_object_aabb(obj); |
