worked on obj and mtl prefetching nad parsing
This commit is contained in:
@@ -12,30 +12,25 @@
|
||||
#include "util/string_lookup.hpp"
|
||||
#include "util/result.hpp"
|
||||
|
||||
namespace mtl_loader_error {
|
||||
|
||||
namespace mtl_loader_error
|
||||
{
|
||||
enum class codes {
|
||||
ok = 0,
|
||||
mtl_cannot_open_file,
|
||||
mtl_cannot_open_texture,
|
||||
mtl_malformed_ambient_color,
|
||||
mtl_malformed_diffuse_color,
|
||||
mtl_malformed_specular_color,
|
||||
mtl_malformed_specular_exponent,
|
||||
mtl_malformed_dissolve,
|
||||
mlt_unknown_line_begin
|
||||
cannot_open_file,
|
||||
cannot_open_texture,
|
||||
malformed_ambient_color,
|
||||
malformed_diffuse_color,
|
||||
malformed_specular_color,
|
||||
malformed_specular_exponent,
|
||||
malformed_dissolve,
|
||||
unknown_line_begin
|
||||
};
|
||||
|
||||
} // namespace mtl_loader_error
|
||||
|
||||
class mtl_loader {
|
||||
public:
|
||||
struct mtl_loader
|
||||
{
|
||||
static constexpr auto name = std::string_view("mtl");
|
||||
|
||||
std::optional<dynamic_material_store::id_type> find_id(std::string_view name);
|
||||
|
||||
void clear_name_lookup();
|
||||
|
||||
[[nodiscard]] static std::error_code prefetch(
|
||||
const file_dir_list& paths,
|
||||
prefetch_queue& queue
|
||||
@@ -50,7 +45,12 @@ public:
|
||||
bool pedantic = false
|
||||
);
|
||||
|
||||
|
||||
private:
|
||||
ztu::string_lookup<dynamic_material_store::id_type> m_id_lookup;
|
||||
protected:
|
||||
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
|
||||
);
|
||||
};
|
||||
|
||||
@@ -6,18 +6,21 @@
|
||||
#include "assets/dynamic_data_loaders/dynamic_material_loader.hpp"
|
||||
#include "assets/dynamic_data_stores/dynamic_mesh_store.hpp"
|
||||
#include "assets/prefetch_lookup.hpp"
|
||||
#include <set>
|
||||
|
||||
namespace obj_loader_error {
|
||||
|
||||
enum class codes {
|
||||
ok = 0,
|
||||
obj_cannot_open_file,
|
||||
obj_malformed_vertex,
|
||||
obj_malformed_texture_coordinate,
|
||||
obj_malformed_normal,
|
||||
obj_malformed_face,
|
||||
obj_face_index_out_of_range,
|
||||
obj_unknown_line_begin
|
||||
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
|
||||
@@ -32,11 +35,48 @@ struct obj_loader {
|
||||
);
|
||||
|
||||
[[nodiscard]] static std::error_code load(
|
||||
components::mesh_vertex::flags enabled_components,
|
||||
dynamic_mesh_buffer& buffer,
|
||||
const file_dir_list& paths,
|
||||
prefetch_lookup& id_lookup,
|
||||
dynamic_data_store& store,
|
||||
bool pedantic = false
|
||||
);
|
||||
|
||||
protected:
|
||||
using index_type = dynamic_mesh_buffer::index_type;
|
||||
using vertex_type = std::array<index_type, 3>;
|
||||
|
||||
struct indexed_vertex_type
|
||||
{
|
||||
vertex_type vertex;
|
||||
index_type buffer_index;
|
||||
|
||||
friend auto operator<=>(const indexed_vertex_type& a, const indexed_vertex_type& b) {
|
||||
return a.vertex <=> b.vertex;
|
||||
}
|
||||
|
||||
bool operator==(const indexed_vertex_type& other) const noexcept {
|
||||
return other.vertex == vertex;
|
||||
}
|
||||
};
|
||||
|
||||
static void find_materials(
|
||||
std::span<char> buffer,
|
||||
std::filesystem::path& path_buffer,
|
||||
const std::filesystem::path& base_directory,
|
||||
std::ifstream& in,
|
||||
ztu::string_list& material_filenames
|
||||
);
|
||||
|
||||
[[nodiscard]] static std::error_code obj_loader::parse_file(
|
||||
dynamic_mesh_buffer& read_buffer,
|
||||
dynamic_mesh_buffer& mesh_buffer,
|
||||
std::filesystem::path& path_buffer,
|
||||
const std::filesystem::path& base_directory,
|
||||
std::set<indexed_vertex_type>& vertex_ids,
|
||||
std::ifstream& in,
|
||||
prefetch_lookup& id_lookup,
|
||||
dynamic_data_store& store,
|
||||
bool pedantic
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user