Files
Z3D/include/assets/file_parsers/stl_loader.hpp
2025-04-01 21:51:56 +02:00

68 lines
1.4 KiB
C++

#pragma once
#include <filesystem>
#include <system_error>
#include <string_view>
#include <unordered_map>
#include "assets/data_stores.hpp"
#include "assets/data/mesh_data.hpp"
#include "assets/data_stores.hpp"
#include "assets/path_id_lookups.hpp"
#include "util/vector_hash.hpp"
namespace assets
{
struct stl_loader
{
static constexpr auto name = std::string_view("stl");
using data_type = mesh_data;
using store_type = mesh_store;
using lookup_type = mesh_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(
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<texture_id> 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::unordered_map<mesh_vertex_components::position, z3d::vertex_index> m_vertex_index_lookup{};
};
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}