Ported the obj parser.
This commit is contained in:
@@ -41,7 +41,7 @@ enum : z3d::size
|
||||
};
|
||||
}
|
||||
|
||||
enum class flags : z3d::u8
|
||||
enum class flags : z3d::u16
|
||||
{
|
||||
none = 0,
|
||||
ambient_filter = 1 << indices::ambient_filter,
|
||||
|
||||
@@ -45,6 +45,8 @@ enum class flags : z3d::u8
|
||||
using all = z3d::structure<
|
||||
position,
|
||||
normal,
|
||||
tangent,
|
||||
bi_tangent,
|
||||
tex_coord,
|
||||
color,
|
||||
reflectance
|
||||
|
||||
@@ -17,6 +17,10 @@ public:
|
||||
C component_flags;
|
||||
z3d::structure<z3d::vector<Ts>...> component_arrays{};
|
||||
|
||||
void add() {
|
||||
|
||||
}
|
||||
|
||||
protected:
|
||||
void clear_component_arrays()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
component_set() = default;
|
||||
|
||||
C component_flags{};
|
||||
z3d::structure<z3d::optional<Ts...>> components{};
|
||||
z3d::structure<z3d::optional<Ts>...> components{};
|
||||
|
||||
protected:
|
||||
void clear_components()
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
using id_type = ID;
|
||||
using container_type = std::vector<T>;
|
||||
using iterator = generic_basic_store_iterator<ID, T>;
|
||||
using const_iterator = generic_basic_store_iterator<std::add_const_t<T>...>;
|
||||
using const_iterator = generic_basic_store_iterator<ID, std::add_const_t<T>>;
|
||||
|
||||
using size_type = std::size_t;
|
||||
using data_type = T;
|
||||
|
||||
@@ -17,15 +17,14 @@ class generic_material_store_iterator
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using count_type = z3d::u32;
|
||||
using component_flag_type = material_components::flags;
|
||||
using id_type = material_id;
|
||||
using value_type = std::pair<id_type, material_view>;
|
||||
using flag_count_type = std::tuple<component_flag_type>;
|
||||
|
||||
using id_iterator_type = id_type*;
|
||||
using component_iterator_type = std::tuple<std::add_pointer_t<Ts>...>;
|
||||
using flag_count_iterator_type = const flag_count_type*;
|
||||
using flag_iterator_type = const component_flag_type*;
|
||||
|
||||
using offsets_type = std::array<size_type, 1 + sizeof...(Ts)>;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@@ -39,7 +38,7 @@ private:
|
||||
generic_material_store_iterator(
|
||||
id_iterator_type ids,
|
||||
const component_iterator_type& components,
|
||||
flag_count_iterator_type flag_counts,
|
||||
flag_iterator_type flags,
|
||||
std::size_t index,
|
||||
const offsets_type& offsets
|
||||
);
|
||||
@@ -88,7 +87,7 @@ protected:
|
||||
private:
|
||||
id_iterator_type m_ids{};
|
||||
component_iterator_type m_components{};
|
||||
flag_count_iterator_type m_flag_counts{};
|
||||
flag_iterator_type m_flags{};
|
||||
size_type m_index{};
|
||||
offsets_type m_offsets{};
|
||||
};
|
||||
@@ -99,7 +98,7 @@ class generic_material_store<z3d::structure<Ts...>>
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using count_type = z3d::u32;
|
||||
using component_flag_type = material_components::flags;
|
||||
using data_type = material_data;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class generic_mesh_store_iterator
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using count_type = z3d::u32;
|
||||
using triangle_type = z3d::index_triangle;
|
||||
using material_id_type = material_store::id_type;
|
||||
using component_flag_type = mesh_vertex_components::flags;
|
||||
@@ -109,7 +109,7 @@ class generic_mesh_store<z3d::structure<Ts...>>
|
||||
{
|
||||
public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
using count_type = z3d::u32;
|
||||
using triangle_type = z3d::index_triangle;
|
||||
using component_flag_type = mesh_vertex_components::flags;
|
||||
using material_id_type = material_id;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace assets
|
||||
|
||||
class pose_list_store;
|
||||
|
||||
template<typename Char>
|
||||
template<typename Pose>
|
||||
class pose_list_store_iterator
|
||||
{
|
||||
public:
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
using value_type = std::pair<id_type, pose_list_view>;
|
||||
|
||||
using id_iterator_type = id_type const*;
|
||||
using pose_iterator_type = Char*;
|
||||
using pose_iterator_type = Pose*;
|
||||
using length_iterator_type = const length_type*;
|
||||
|
||||
using offset_type = size_type;
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
using size_type = std::size_t;
|
||||
using count_type = ztu::u32;
|
||||
|
||||
using iterator = pose_list_store_iterator<char>;
|
||||
using const_iterator = pose_list_store_iterator<const char>;
|
||||
using iterator = pose_list_store_iterator<pose_data>;
|
||||
using const_iterator = pose_list_store_iterator<const pose_data>;
|
||||
using data_type = pose_list_data;
|
||||
using id_type = pose_list_id;
|
||||
|
||||
@@ -136,7 +136,7 @@ protected:
|
||||
|
||||
private:
|
||||
std::vector<id_type> m_ids;
|
||||
std::vector<char> m_poses;
|
||||
std::vector<pose_data> m_poses;
|
||||
std::vector<count_type> m_lengths;
|
||||
mutable std::shared_mutex m_mutex;
|
||||
};
|
||||
|
||||
@@ -111,7 +111,6 @@ public:
|
||||
|
||||
[[nodiscard]] std::pair<const_iterator, bool> find(id_type id) const;
|
||||
|
||||
|
||||
inline void remove(const iterator& it);
|
||||
|
||||
inline void clear();
|
||||
|
||||
@@ -7,31 +7,63 @@
|
||||
#include "glm/mat4x4.hpp"
|
||||
#include "util/result.hpp"
|
||||
#include "util/string_list.hpp"
|
||||
#include "assets/prefetch_queue.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"
|
||||
#include "assets/prefetch_lookup.hpp"
|
||||
|
||||
|
||||
namespace assets
|
||||
{
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
struct generic_3dtk_loader
|
||||
{
|
||||
[[nodiscard]] static std::error_code prefetch(
|
||||
const ztu::string_list& filenames,
|
||||
prefetch_queue& queue
|
||||
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]] static std::error_code load(
|
||||
dynamic_point_cloud_buffer& buffer,
|
||||
const file_dir_list& paths,
|
||||
dynamic_point_cloud_store& store,
|
||||
prefetch_lookup& id_lookup,
|
||||
[[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
|
||||
@@ -51,8 +83,13 @@ private:
|
||||
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 "../../data_parsers"
|
||||
#include "assets/file_parsers/generic/generic_3dtk_loader.ipp"
|
||||
#undef INCLUDE_GENERIC_3DTK_LOADER_IMPLEMENTATION
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#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"
|
||||
@@ -50,14 +48,35 @@ struct mtl_parser
|
||||
);
|
||||
|
||||
protected:
|
||||
class prefetcher_context
|
||||
{
|
||||
public:
|
||||
prefetcher_context(
|
||||
path_id_lookups& lookups
|
||||
);
|
||||
|
||||
void operator()(lookup_type::const_pointer entry) noexcept;
|
||||
|
||||
protected:
|
||||
|
||||
[[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_lookups;
|
||||
std::vector<char> m_buffer{};
|
||||
};
|
||||
|
||||
|
||||
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
|
||||
path_id_lookups& lookups,
|
||||
data_stores& stores
|
||||
);
|
||||
|
||||
void operator()(lookup_type::const_pointer entry) noexcept;
|
||||
@@ -72,21 +91,11 @@ protected:
|
||||
);
|
||||
|
||||
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;
|
||||
path_id_lookups* m_lookups;
|
||||
data_stores* m_stores;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
#include "assets/data/mesh_data.hpp"
|
||||
#include "assets/data_stores.hpp"
|
||||
#include "assets/path_id_lookups.hpp"
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include "util/array_hash.hpp"
|
||||
|
||||
namespace assets::obj_loader_error
|
||||
namespace assets::obj_parser_error
|
||||
{
|
||||
enum class codes {
|
||||
ok = 0,
|
||||
@@ -27,7 +28,7 @@ enum class codes {
|
||||
namespace assets
|
||||
{
|
||||
|
||||
struct obj_loader
|
||||
struct obj_parser
|
||||
{
|
||||
static constexpr auto name = std::string_view("obj");
|
||||
using data_type = mesh_data;
|
||||
@@ -46,28 +47,28 @@ struct obj_loader
|
||||
);
|
||||
|
||||
protected:
|
||||
struct indexed_vertex_type
|
||||
using component_indices = std::array<z3d::vertex_index, 3>;
|
||||
|
||||
class prefetcher_context
|
||||
{
|
||||
z3d::index_triangle vertex;
|
||||
z3d::vertex_index buffer_index;
|
||||
public:
|
||||
prefetcher_context(
|
||||
path_id_lookups& id_lookups
|
||||
);
|
||||
|
||||
friend auto operator<=>(const indexed_vertex_type& a, const indexed_vertex_type& b) {
|
||||
return a.vertex <=> b.vertex;
|
||||
}
|
||||
void operator()(lookup_type::const_pointer entry) noexcept;
|
||||
|
||||
bool operator==(const indexed_vertex_type& other) const noexcept {
|
||||
return other.vertex == vertex;
|
||||
}
|
||||
private:
|
||||
path_id_lookups* m_id_lookups;
|
||||
std::vector<char> m_buffer{};
|
||||
};
|
||||
|
||||
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
|
||||
path_id_lookups& m_id_lookups,
|
||||
data_stores& m_stores
|
||||
);
|
||||
|
||||
void operator()(lookup_type::const_pointer entry) noexcept;
|
||||
@@ -75,6 +76,8 @@ protected:
|
||||
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,
|
||||
@@ -82,34 +85,16 @@ protected:
|
||||
);
|
||||
|
||||
private:
|
||||
const path_id_lookups* m_id_lookups;
|
||||
path_id_lookups* m_id_lookups;
|
||||
data_stores* m_stores;
|
||||
data_type m_buffer{};
|
||||
data_type m_read_buffer{};
|
||||
std::set<indexed_vertex_type> vertex_ids{};
|
||||
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{};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
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_shader_source_store& store,
|
||||
bool pedantic
|
||||
);
|
||||
private:
|
||||
std::vector<lookup_type::const_pointer> m_path_buffer;
|
||||
};
|
||||
}
|
||||
@@ -3,28 +3,65 @@
|
||||
#include <filesystem>
|
||||
#include <system_error>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "assets/data_stores.hpp"
|
||||
#include "assets/data"
|
||||
#include "../data_stores"
|
||||
#include "assets/prefetch_lookup.hpp"
|
||||
#include "assets/prefetch_queue.hpp"
|
||||
#include "assets/data/mesh_data.hpp"
|
||||
#include "assets/data_stores.hpp"
|
||||
#include "assets/path_id_lookups.hpp"
|
||||
#include "util/vector_hash.hpp"
|
||||
|
||||
struct stl_loader {
|
||||
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]] static std::error_code prefetch(
|
||||
const file_dir_list& paths,
|
||||
prefetch_queue& queue
|
||||
[[nodiscard]] std::error_code prefetch(
|
||||
path_id_lookups& lookups
|
||||
);
|
||||
|
||||
[[nodiscard]] static std::error_code load(
|
||||
// space stuff that has to persist
|
||||
dynamic_mesh_buffer& buffer,
|
||||
const file_dir_list& paths,
|
||||
prefetch_lookup& id_lookup,
|
||||
shader_source_store& store,
|
||||
[[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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user