#pragma once #include #include #include #include "assets/data/mesh_data.hpp" #include "assets/data_stores.hpp" #include "assets/path_id_lookups.hpp" #include #include "util/array_hash.hpp" namespace assets::obj_parser_error { enum class codes { ok = 0, cannot_open_file, malformed_vertex, malformed_texture_coordinate, malformed_normal, malformed_face, face_index_out_of_range, unknown_line_begin, use_material_without_material_library, unknown_material_name }; } // namespace obj_loader_error namespace assets { struct obj_parser { static constexpr auto name = std::string_view("obj"); using data_type = mesh_data; using store_type = mesh_store; using lookup_type = mesh_id_lookup; // TODO port this mess to the new interface [[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: using component_indices = std::array; class prefetcher_context { public: prefetcher_context( path_id_lookups& id_lookups ); void operator()(lookup_type::const_pointer entry) noexcept; private: path_id_lookups* m_id_lookups; std::vector m_buffer{}; }; class parser_context { public: parser_context( path_id_lookups& m_id_lookups, data_stores& m_stores ); void operator()(lookup_type::const_pointer entry) noexcept; protected: void reset(); z3d::vertex_index find_or_push_vertex(const component_indices& vertex_comp_indices); [[nodiscard]] std::optional fetch_texture_id( const std::filesystem::path& mtl_dir, std::string_view filename, std::string_view texture_type_name ); private: path_id_lookups* m_id_lookups; data_stores* m_stores; data_type m_mesh{}; std::vector m_position_buffer{}; std::vector m_normal_buffer{}; std::vector m_tex_coord_buffer{}; std::unordered_map m_vertex_comp_indices_to_vertex_index{}; }; private: std::vector m_path_buffer; }; }