From e1cb638adcaeabad632a3deb14eb67087cfce889 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Wed, 9 Jul 2025 19:50:55 -0700 Subject: Use new LLR module --- src/plugins/viewer.c | 57 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/plugins/viewer.c b/src/plugins/viewer.c index 84fcca4..97c718e 100644 --- a/src/plugins/viewer.c +++ b/src/plugins/viewer.c @@ -2,11 +2,14 @@ #include #include +#include #include +#include #include #include #include #include +#include #include @@ -34,6 +37,10 @@ static const char* FLIGHT_HELMET = static const char* DAMAGED_HELMET = "/home/jeanne/Nextcloud/assets/glTF-Sample-Models/2.0/DamagedHelmet/glTF/" "DamagedHelmet.gltf"; +static const char* CHRONOGRAPH_WATCH = + "/home/jeanne/Nextcloud/assets/glTF-Sample-Models/2.0/ChronographWatch/" + "glTF/" + "ChronographWatch.gltf"; static const char* GIRL = "/home/jeanne/Nextcloud/assets/models/girl/girl-with-ground.gltf"; static const char* BOXES = @@ -41,7 +48,7 @@ static const char* BOXES = #define DEFAULT_SCENE_FILE GIRL -static const bool RenderBoundingBoxes = false; +static const bool RenderBoundingBoxes = true; static const R DefaultCameraSpeed = (R)6.0; static const R DefaultMouseSensitivity = (R)(10 * TO_RAD); static const vec3 DefaultCameraPosition = (vec3){0, 2, 5}; @@ -52,13 +59,13 @@ typedef struct CameraCommand { bool CameraMoveForward : 1; bool CameraMoveBackward : 1; bool CameraIsRotating : 1; // When true, subsequent mouse movements cause the - // camera to rotate. + // camera to rotate. } CameraCommand; typedef struct CameraController { - R camera_speed; // Camera movement speed. - R mouse_sensitivity; // Controls the degree with which mouse movements - // rotate the camera. + R camera_speed; // Camera movement speed. + R mouse_sensitivity; // Controls the degree with which mouse movements + // rotate the camera. vec2 prev_mouse_position; // Mouse position in the previous frame. } CameraController; @@ -95,7 +102,7 @@ static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) { const Texture* environment_map = load_environment_map(gfx); if (!environment_map) { - return 0; + return nullptr; } return gfx_setup_skyquad(gfxcore, root, environment_map); @@ -114,18 +121,18 @@ static Model* load_model(Game* game, State* state, const char* scene_filepath) { SceneNode* root = gfx_get_scene_root(state->scene); SceneNode* sky_light_node = load_skyquad(game->gfx, root); if (!sky_light_node) { - return 0; // test + return nullptr; } Model* model = gfx_load_model( game->gfx, &(LoadModelCmd){.origin = AssetFromFile, .filepath = mstring_make(scene_filepath)}); if (!model) { - return 0; + return nullptr; } SceneNode* model_node = gfx_make_model_node(model); if (!model_node) { - return 0; + return nullptr; } gfx_set_node_parent(model_node, sky_light_node); @@ -146,10 +153,10 @@ bool init(Game* game, State** pp_state) { goto cleanup; } - if (!(state->scene = gfx_make_scene())) { + if (!((state->scene = gfx_make_scene()))) { goto cleanup; } - if (!(state->camera = gfx_make_camera())) { + if (!((state->camera = gfx_make_camera()))) { goto cleanup; } @@ -267,8 +274,9 @@ void update(Game* game, State* state, double t, double dt) { /// Render the bounding boxes of all scene objects. static void render_bounding_boxes_rec( - ImmRenderer* imm, const Anima* anima, const mat4* parent_model_matrix, - const SceneNode* node) { + LLR* llr, ImmRenderer* imm, const Anima* anima, + const mat4* parent_model_matrix, const SceneNode* node) { + assert(llr); assert(imm); assert(node); @@ -280,16 +288,17 @@ static void render_bounding_boxes_rec( 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, anima, &model_matrix, root); + render_bounding_boxes_rec(llr, imm, anima, &model_matrix, root); } else if (node_type == AnimaNode) { anima = gfx_get_node_anima(node); } else if (node_type == ObjectNode) { - gfx_imm_set_model_matrix(imm, &model_matrix); + gfx_llr_set_model_matrix(llr, &model_matrix); const SceneObject* obj = gfx_get_node_object(node); const Skeleton* skeleton = gfx_get_object_skeleton(obj); - if (skeleton) { // Animated model. + if (skeleton) { + // Animated model. assert(anima); const size_t num_joints = gfx_get_skeleton_num_joints(skeleton); for (size_t i = 0; i < num_joints; ++i) { @@ -298,16 +307,19 @@ static void render_bounding_boxes_rec( gfx_imm_draw_box3(imm, box.vertices); } } - } else { // Static model. + } else { + // Static model. const aabb3 box = gfx_get_object_aabb(obj); gfx_imm_draw_aabb3(imm, box); } + + gfx_imm_flush(imm); } // Render children's boxes. const SceneNode* child = gfx_get_node_child(node); while (child) { - render_bounding_boxes_rec(imm, anima, &model_matrix, child); + render_bounding_boxes_rec(llr, imm, anima, &model_matrix, child); child = gfx_get_node_sibling(child); } } @@ -318,8 +330,10 @@ static void render_bounding_boxes(const Game* game, const State* state) { assert(state); GfxCore* gfxcore = gfx_get_core(game->gfx); + LLR* llr = gfx_get_llr(game->gfx); ImmRenderer* imm = gfx_get_imm_renderer(game->gfx); assert(gfxcore); + assert(llr); assert(imm); const mat4 id = mat4_id(); @@ -330,9 +344,10 @@ static void render_bounding_boxes(const Game* game, const State* state) { gfx_set_polygon_offset(gfxcore, -1.5f, -1.0f); gfx_imm_start(imm); - gfx_imm_set_camera(imm, gfx_get_camera_camera(state->camera)); - gfx_imm_set_colour(imm, vec4_make(0.3, 0.3, 0.9, 0.1)); - render_bounding_boxes_rec(imm, anima, &id, gfx_get_scene_root(state->scene)); + gfx_llr_set_camera(llr, gfx_get_camera_camera(state->camera)); + gfx_imm_set_colour(imm, vec4_make(0.3f, 0.3f, 0.9f, 0.1f)); + render_bounding_boxes_rec( + llr, imm, anima, &id, gfx_get_scene_root(state->scene)); gfx_imm_end(imm); gfx_reset_polygon_offset(gfxcore); -- cgit v1.2.3