97 lines
2.1 KiB
C++
97 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <system_error>
|
|
|
|
#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,
|
|
std::mutex& store_mutex
|
|
);
|
|
|
|
void operator()(lookup_type::const_pointer entry) noexcept;
|
|
|
|
protected:
|
|
void reset();
|
|
|
|
[[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:
|
|
const texture_id_lookup* m_texture_id_lookup;
|
|
material_id_lookup* m_material_id_lookup;
|
|
material_store* m_material_store;
|
|
store_type* m_store;
|
|
std::mutex* m_store_mutex;
|
|
data_type m_buffer{};
|
|
};
|
|
|
|
static void find_textures(
|
|
std::span<char> buffer,
|
|
std::filesystem::path& path_buffer,
|
|
const std::filesystem::path& base_directory,
|
|
std::ifstream& in,
|
|
ztu::string_list& texture_filenames
|
|
);
|
|
|
|
private:
|
|
std::vector<lookup_type::const_pointer> m_path_buffer;
|
|
};
|
|
|
|
}
|