#pragma once #include #include #include "assets/data_stores.hpp" #include "assets/path_id_lookups.hpp" #include "assets/prefetch_lookup.hpp" #include "assets/prefetch_queue.hpp" #include "assets/data/material_data.hpp" #include "assets/data/material_library_data.hpp" #include "assets/data_stores/material_store.hpp" #include "assets/data_stores/material_library_store.hpp" #include "util/result.hpp" namespace assets { namespace mtl_parser_error { enum class codes { ok = 0, cannot_open_file, // TODO these are incomplete cannot_open_texture, malformed_ambient_color, malformed_diffuse_color, malformed_specular_color, malformed_specular_exponent, malformed_dissolve, unknown_line_begin }; } // namespace mtl_loader_error struct mtl_parser { static constexpr auto name = std::string_view("mtl"); using data_type = material_library_data; using store_type = material_library_store; using lookup_type = material_library_id_lookup; [[nodiscard]] std::error_code prefetch( path_id_lookups& lookups ); [[nodiscard]] std::error_code load( path_id_lookups& lookups, data_stores& stores, bool pedantic = false ); protected: class parser_context { public: parser_context( const texture_id_lookup& texture_id_lookup, material_id_lookup& material_id_lookup, material_store& material_store, store_type& store ); void operator()(lookup_type::const_pointer entry) noexcept; protected: void reset(); [[nodiscard]] std::optional fetch_texture_id( const std::filesystem::path& mtl_dir, std::string_view filename, std::string_view texture_type_name ); private: const texture_id_lookup* m_texture_id_lookup; material_id_lookup* m_material_id_lookup; material_store* m_material_store; store_type* m_store; data_type m_buffer{}; }; static void find_textures( std::span buffer, std::filesystem::path& path_buffer, const std::filesystem::path& base_directory, std::ifstream& in, ztu::string_list& texture_filenames ); private: std::vector m_path_buffer; }; }