diff --git a/client/render/scene_loader.cpp b/client/render/scene_loader.cpp index 2658b273..83c5fe62 100644 --- a/client/render/scene_loader.cpp +++ b/client/render/scene_loader.cpp @@ -594,7 +594,7 @@ public: return std::shared_ptr(image_ptr, &image_ptr->image_view); } - std::vector> load_all_textures() + std::vector> load_all_textures(std::function progress_cb) { // Determine which texture is sRGB std::vector srgb_array; @@ -610,6 +610,9 @@ public: std::vector> textures; textures.reserve(gltf.textures.size()); + + int loaded_textures = 0; + int total_textures = gltf.textures.size(); for (auto && [srgb, gltf_texture]: std::views::zip(srgb_array, gltf.textures)) { auto & texture_ref = *textures.emplace_back(std::make_shared()); @@ -624,6 +627,9 @@ public: try { texture_ref.image_view = load_image(*gltf_texture.basisuImageIndex, srgb); + loaded_textures++; + if (progress_cb) + progress_cb((float)loaded_textures / total_textures); continue; } catch (std::exception & e) @@ -647,6 +653,9 @@ public: try { texture_ref.image_view = load_image(*gltf_texture.imageIndex, srgb); + loaded_textures++; + if (progress_cb) + progress_cb((float)loaded_textures / total_textures); continue; } catch (std::exception & e) @@ -1039,7 +1048,7 @@ public: } // namespace -std::shared_ptr scene_loader::operator()(std::span data, const std::string & name, const std::filesystem::path & parent_path) +std::shared_ptr scene_loader::operator()(std::span data, const std::string & name, const std::filesystem::path & parent_path, std::function progress_cb) { vk::PhysicalDeviceProperties physical_device_properties = physical_device.getProperties(); vk::raii::CommandPool cb_pool{device, vk::CommandPoolCreateInfo{ @@ -1065,7 +1074,7 @@ std::shared_ptr scene_loader::operator()(std::span scene_loader::operator()(std::span scene_loader::operator()(const std::filesystem::path & gltf_path) +std::shared_ptr scene_loader::operator()(const std::filesystem::path & gltf_path, std::function progress_cb) { spdlog::debug("Loading {}", gltf_path.native()); @@ -1103,5 +1112,5 @@ std::shared_ptr scene_loader::operator()(const std::filesystem:: if (auto error = data_buffer.error(); error != fastgltf::Error::None) throw std::system_error((int)error, fastgltf_error_category); - return (*this)(asset_file, gltf_path.filename(), gltf_path.parent_path()); + return (*this)(asset_file, gltf_path.filename(), gltf_path.parent_path(), progress_cb); } diff --git a/client/render/scene_loader.h b/client/render/scene_loader.h index cee82627..f80b7bc8 100644 --- a/client/render/scene_loader.h +++ b/client/render/scene_loader.h @@ -20,6 +20,7 @@ #include #include +#include #include #include "scene_components.h" @@ -43,6 +44,6 @@ public: {} scene_loader(const scene_loader &) = default; - std::shared_ptr operator()(const std::filesystem::path & gltf_path); - std::shared_ptr operator()(std::span data, const std::string & name = "", const std::filesystem::path & parent_path = ""); + std::shared_ptr operator()(const std::filesystem::path & gltf_path, std::function progress_cb = {}); + std::shared_ptr operator()(std::span data, const std::string & name = "", const std::filesystem::path & parent_path = "", std::function progress_cb = {}); };