96 lines
2.3 KiB
C++
96 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <charconv>
|
|
#include <string_view>
|
|
|
|
#include "glm/mat4x4.hpp"
|
|
#include "util/result.hpp"
|
|
#include "util/string_list.hpp"
|
|
#include "assets/data_stores.hpp"
|
|
#include "assets/path_id_lookups.hpp"
|
|
|
|
#include "assets/data/point_cloud_data.hpp"
|
|
#include "assets/data_stores/point_cloud_store.hpp"
|
|
|
|
namespace assets
|
|
{
|
|
|
|
template<bool Normal, bool Color, bool Reflectance>
|
|
struct generic_3dtk_loader
|
|
{
|
|
using data_type = point_cloud_data;
|
|
using store_type = point_cloud_data;
|
|
using lookup_type = point_cloud_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::vector<mesh_vertex_components::position> m_position_buffer{};
|
|
std::vector<mesh_vertex_components::normal> m_normal_buffer{};
|
|
std::vector<mesh_vertex_components::tex_coord> m_tex_coord_buffer{};
|
|
std::unordered_map<component_indices, z3d::vertex_index> m_vertex_comp_indices_to_vertex_index{};
|
|
};
|
|
|
|
[[nodiscard]] static ztu::result<pose_prefetch_lookup::index_type> parse_index(
|
|
std::string_view filename
|
|
);
|
|
|
|
ztu::result<std::pair<ztu::u32, std::chars_format>> analyze_component_format(
|
|
std::string_view line
|
|
);
|
|
|
|
void transform_point_cloud(
|
|
std::span<point_cloud_vertex_components::position::value_type> points,
|
|
const glm::mat4& pose
|
|
);
|
|
|
|
private:
|
|
std::error_code read_point_file(
|
|
const std::filesystem::path& filename,
|
|
dynamic_point_cloud_buffer& point_cloud
|
|
);
|
|
|
|
private:
|
|
std::vector<lookup_type::const_pointer> m_path_buffer;
|
|
};
|
|
|
|
}
|
|
|
|
#define INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
|
|
#include "assets/file_parsers/generic/generic_3dtk_loader.ipp"
|
|
#undef INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
|