In the middle of multithreading parsers.

This commit is contained in:
zy4n
2025-03-30 22:38:06 +02:00
parent d18b40a7fc
commit 144126ee7a
80 changed files with 2904 additions and 1450 deletions

View File

@@ -5,51 +5,67 @@
#include "config/primitives.hpp"
#include "assets/identifiers.hpp"
#include "assets/data_stores/texture_store.hpp"
#include "assets/data/surface_properties.hpp"
#include "assets/data/uniform_surface_properties.hpp"
#include "util/enum_bitfield_operators.hpp"
namespace assets::material_components
{
using surface_properties = surface_properties;
using transparency = z3d::f32;
using ambient_color_texture = texture_id;
using diffuse_color_texture = texture_id;
using specular_color_texture = texture_id;
using ambient_filter = z3d::vec3;
using diffuse_filter = z3d::vec3;
using specular_filter = z3d::vec3;
using shininess = z3d::f32;
using alpha = z3d::f32;
using ambient_filter_texture = texture_id;
using diffuse_filter_texture = texture_id;
using specular_filter_texture = texture_id;
using shininess_texture = texture_id;
using alpha_texture = texture_id;
using bump_texture = texture_id;
namespace indices
{
inline constexpr z3d::size surface_properties = 0;
inline constexpr z3d::size transparency = 1;
inline constexpr z3d::size ambient_color_texture = 2;
inline constexpr z3d::size diffuse_color_texture = 3;
inline constexpr z3d::size specular_color_texture = 4;
inline constexpr z3d::size shininess_texture = 5;
inline constexpr z3d::size alpha_texture = 6;
inline constexpr z3d::size bump_texture = 7;
enum : z3d::size
{
ambient_filter,
diffuse_filter,
specular_filter,
shininess,
alpha,
ambient_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture
};
}
enum class flags : z3d::u8
{
none = 0,
surface_properties = 1 << indices::surface_properties,
transparency = 1 << indices::transparency,
ambient_filter_texture = 1 << indices::ambient_color_texture,
diffuse_filter_texture = 1 << indices::diffuse_color_texture,
specular_filter_texture = 1 << indices::specular_color_texture,
ambient_filter = 1 << indices::ambient_filter,
diffuse_filter = 1 << indices::diffuse_filter,
specular_filter = 1 << indices::specular_filter,
shininess = 1 << indices::shininess,
alpha = 1 << indices::alpha,
ambient_filter_texture = 1 << indices::ambient_filter_texture,
diffuse_filter_texture = 1 << indices::diffuse_filter_texture,
specular_filter_texture = 1 << indices::specular_filter_texture,
shininess_texture = 1 << indices::shininess_texture,
alpha_texture = 1 << indices::alpha_texture,
bump_texture = 1 << indices::bump_texture
};
using all = z3d::structure<
surface_properties,
transparency,
ambient_color_texture,
diffuse_color_texture,
specular_color_texture,
ambient_filter,
diffuse_filter,
specular_filter,
shininess,
alpha,
ambient_filter_texture,
diffuse_filter_texture,
specular_filter_texture,
shininess_texture,
alpha_texture,
bump_texture

View File

@@ -0,0 +1,58 @@
#pragma once
#include "config/primitives.hpp"
#include "util/enum_bitfield_operators.hpp"
#include <array>
#include <string_view>
namespace assets::mesh_shader_components
{
namespace indices
{
enum : z3d::size
{
face,
line,
point,
luminance,
color,
alpha,
color_texture,
uniform_lighting,
textured_lighting,
uniform_color
};
}
enum class flags : std::uint16_t
{
none = 0,
face = 1 << indices::face,
line = 1 << indices::line,
point = 1 << indices::point,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
color_texture = 1 << indices::color_texture,
uniform_lighting = 1 << indices::uniform_lighting,
textured_lighting = 1 << indices::textured_lighting,
uniform_color = 1 << indices::uniform_color
};
constexpr inline auto names = std::array<std::string_view, 10>{
"face",
"line",
"point",
"luminance",
"color",
"alpha",
"color_texture",
"uniform_lighting",
"textured_lighting",
"uniform_color"
};
}
DEFINE_ENUM_BITFIELD_OPERATORS(assets::mesh_shader_components::flags)

View File

@@ -16,11 +16,14 @@ using reflectance = z3d::f32;
namespace indices
{
inline constexpr z3d::size position = 0;
inline constexpr z3d::size normal = 1;
inline constexpr z3d::size tex_coord = 2;
inline constexpr z3d::size color = 3;
inline constexpr z3d::size reflectance = 4;
enum : z3d::size
{
position,
normal,
tex_coord,
color,
reflectance
};
}
enum class flags : z3d::u8

View File

@@ -0,0 +1,46 @@
#pragma once
#include "config/primitives.hpp"
#include "util/enum_bitfield_operators.hpp"
#include <array>
#include <string_view>
namespace assets::point_cloud_shader_components
{
enum indices : z3d::size
{
square,
lighting,
luminance,
color,
alpha,
uniform_color,
rainbow
};
enum class flags : std::uint16_t
{
none = 0,
square = 1 << indices::square,
lighting = 1 << indices::lighting,
luminance = 1 << indices::luminance,
color = 1 << indices::color,
alpha = 1 << indices::alpha,
uniform_color = 1 << indices::uniform_color,
rainbow = 1 << indices::rainbow
};
constexpr inline auto names = std::array<std::string_view, 7>{
"square",
"lighting",
"luminance",
"color",
"alpha",
"uniform_color",
"rainbow"
};
}
DEFINE_ENUM_BITFIELD_OPERATORS(assets::point_cloud_shader_components::flags)

View File

@@ -15,10 +15,13 @@ using reflectance = z3d::f32;
namespace indices
{
inline constexpr z3d::size position = 0;
inline constexpr z3d::size normal = 1;
inline constexpr z3d::size color = 2;
inline constexpr z3d::size reflectance = 3;
enum : z3d::size
{
position,
normal,
color,
reflectance
};
} // namespace indices
enum class flags : z3d::u8

View File

@@ -0,0 +1,35 @@
#pragma once
#include <type_traits>
#include "mesh_shader_components.hpp"
#include "point_cloud_shader_components.hpp"
namespace assets::shader_components
{
enum class stage : z3d::u8
{
vertex = 0,
tesselation_control = 1,
tesselation_evaluation = 2,
geometry = 3,
fragment = 4
};
inline constexpr std::size_t count = 5;
inline constexpr auto stage_names = std::array<std::string_view, count>{
"vertex",
"tesselation_control",
"tesselation_evaluation",
"geometry",
"fragment"
};
using flags = std::make_unsigned_t<std::common_type_t<
std::underlying_type_t<mesh_shader_components::flags>,
std::underlying_type_t<point_cloud_shader_components::flags>
>>;
}

View File

@@ -11,8 +11,12 @@ class component_array_set {};
template<typename C, typename... Ts>
class component_array_set<C, z3d::structure<Ts...>>
{
public:
component_array_set() = default;
C component_flags;
z3d::structure<z3d::vector<Ts>...> component_arrays{};
protected:
void clear_component_arrays()
{
@@ -24,10 +28,6 @@ protected:
component_arrays
);
}
C component_flags;
z3d::structure<z3d::vector<Ts>...> component_arrays{};
};
}

View File

@@ -1,7 +1,5 @@
#pragma once
#include <optional>
#include "assets/components/material_components.hpp"
#include "generic/component_set.hpp"
@@ -13,22 +11,27 @@ struct material_data : detail::component_set<material_components::all>
material_data() = default;
material_components::surface_properties& initialized_surface_properties();
[[nodiscard]] inline z3d::optional<material_components::surface_properties>& surface_properties();
[[nodiscard]] inline z3d::optional<material_components::transparency>& transparency();
[[nodiscard]] inline z3d::optional<material_components::ambient_color_texture>& ambient_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::specular_color_texture>& specular_color_texture_id();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter>& ambient_filter();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter>& diffuse_filter();
[[nodiscard]] inline z3d::optional<material_components::specular_filter>& specular_filter();
[[nodiscard]] inline z3d::optional<material_components::shininess>& shininess();
[[nodiscard]] inline z3d::optional<material_components::alpha>& alpha();
[[nodiscard]] inline z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id();
[[nodiscard]] inline z3d::optional<material_components::shininess_texture>& shininess_texture_id();
[[nodiscard]] inline z3d::optional<material_components::alpha_texture>& alpha_texture_id();
[[nodiscard]] inline z3d::optional<material_components::bump_texture>& bump_texture_id();
[[nodiscard]] inline const z3d::optional<material_components::surface_properties>& surface_properties() const;
[[nodiscard]] inline const z3d::optional<material_components::transparency>& transparency() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_color_texture>& ambient_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_color_texture>& specular_color_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter>& ambient_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter>& diffuse_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_filter>& specular_filter() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess>& shininess() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& alpha() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha>& transparency() const;
[[nodiscard]] inline const z3d::optional<material_components::ambient_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::diffuse_filter_texture>& diffuse_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::specular_filter_texture>& specular_filter_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::shininess_texture>& shininess_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::alpha_texture>& alpha_texture_id() const;
[[nodiscard]] inline const z3d::optional<material_components::bump_texture>& bump_texture_id() const;
@@ -38,6 +41,6 @@ struct material_data : detail::component_set<material_components::all>
}
#define INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#define INCLUDE_MATERIAL_DATA_IMPLEMENTATION
#include "assets/data/material_data.ipp"
#undef INCLUDE_DYNAMIC_MATERIAL_DATA_IMPLEMENTATION
#undef INCLUDE_MATERIAL_DATA_IMPLEMENTATION

View File

@@ -9,11 +9,16 @@
namespace assets
{
class point_cloud_data : detail::component_array_set<
class point_cloud_data : public detail::component_array_set<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::all
> {
public:
using detail::component_array_set<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::all
>::component_array_set;
[[nodiscard]] inline std::vector<point_cloud_vertex_components::position>& positions();
[[nodiscard]] inline std::vector<point_cloud_vertex_components::normal>& normals();
[[nodiscard]] inline std::vector<point_cloud_vertex_components::color>& colors();

View File

@@ -0,0 +1,11 @@
#pragma once
#include "pose_data.hpp"
namespace assets
{
using pose_list_data = std::vector<pose_data>;
}

View File

@@ -1,6 +1,8 @@
#pragma once
#include "config/primitives.hpp"
#include "assets/components/shader_components.hpp"
#include "assets/model_geometry.hpp"
namespace assets
{
@@ -9,9 +11,20 @@ struct shader_source_data
{
z3d::vector<char> source{};
struct metadata
{
model_geometry::types geometry_type;
shader_components::stage stage{};
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
} meta;
void clear()
{
source.clear();
meta.stage = {};
meta.components = {};
}
};

View File

@@ -1,16 +0,0 @@
#pragma once
#include "config/primitives.hpp"
namespace assets
{
struct surface_properties
{
z3d::vec3 ambient_filter{ 0.7f, 0.7f, 0.7f };
z3d::vec3 diffuse_filter{ 0.466f, 0.466f, 0.7922f };
z3d::vec3 specular_filter{ 0.5974f, 0.2084f, 0.2084f };
z3d::f32 shininess{ 100.2237f };
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "config/primitives.hpp"
namespace assets
{
}

View File

@@ -10,7 +10,7 @@
#include "assets/prefetch_lookups/point_cloud_prefetch_lookup.hpp"
#include "util/string_list.hpp"
#include "assets/file_parsers/kitti_loader.hpp"
#include "assets/file_parsers/kitti_parser.hpp"
#include "assets/file_parsers/uos_loader.hpp"
#include "assets/file_parsers/uos_normal_loader.hpp"
#include "assets/file_parsers/uos_rgb_loader.hpp"
@@ -21,7 +21,7 @@ namespace assets
class point_cloud_loader : public base_dynamic_loader<
point_cloud_vertex_components::flags,
kitti_loader,
kitti_parser,
uos_loader,
uos_normal_loader,
uos_rgb_loader,

View File

@@ -4,6 +4,7 @@
#include "data_stores/material_store.hpp"
#include "data_stores/mesh_store.hpp"
#include "data_stores/point_cloud_store.hpp"
#include "data_stores/pose_list_store.hpp"
#include "data_stores/pose_store.hpp"
#include "data_stores/shader_source_store.hpp"
#include "data_stores/texture_store.hpp"
@@ -18,6 +19,7 @@ struct data_stores
mesh_store meshes;
point_cloud_store point_clouds;
pose_store poses;
pose_list_store pose_lists;
shader_source_store shader_sources;
texture_store textures;
};

View File

@@ -105,13 +105,12 @@ public:
using count_type = ztu::u32;
using component_flag_type = point_cloud_vertex_components::flags;
using data_type = point_cloud_data;
using iterator_type = generic_point_cloud_store_iterator<Ts...>;
using const_iterator = generic_point_cloud_store_iterator<std::add_const_t<Ts>...>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
using id_type = point_cloud_id;
id_type add(const point_cloud_data& point_cloud);
id_type add(id_type id, const data_type& point_cloud);
[[nodiscard]] std::pair<iterator_type, bool> find(id_type id);
@@ -133,10 +132,6 @@ public:
const_iterator cend() const;
view_type view();
const_view_type view() const;
protected:
std::tuple<std::add_pointer_t<Ts>...> component_iterators();

View File

@@ -7,7 +7,7 @@ namespace assets
using material_store = detail::generic_material_store<
material_components::surface_properties,
material_components::transparency,
material_components::alpha,
texture_store::id_type,
texture_store::id_type,
texture_store::id_type,

View File

@@ -0,0 +1,137 @@
#pragma once
#include "generic/generic_basic_store.hpp"
#include "assets/identifiers.hpp"
#include "assets/data/pose_list_data.hpp"
#include "assets/data_views/pose_list_view.hpp"
namespace assets
{
class pose_list_store;
template<typename Char>
class pose_list_store_iterator
{
public:
using size_type = std::size_t;
using length_type = ztu::u32;
using id_type = pose_list_id;
using value_type = std::pair<id_type, pose_list_view>;
using id_iterator_type = id_type const*;
using pose_iterator_type = Char*;
using length_iterator_type = const length_type*;
using offset_type = size_type;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type;
using iterator_category = std::random_access_iterator_tag;
private:
friend pose_list_store;
pose_list_store_iterator(
id_iterator_type ids,
pose_iterator_type poses,
length_iterator_type lengths,
std::size_t index,
const offset_type& offset
);
public:
constexpr pose_list_store_iterator() noexcept = default;
constexpr pose_list_store_iterator(const pose_list_store_iterator&) noexcept = default;
constexpr pose_list_store_iterator(pose_list_store_iterator&&) noexcept = default;
constexpr pose_list_store_iterator& operator=(const pose_list_store_iterator&) noexcept = default;
constexpr pose_list_store_iterator& operator=(pose_list_store_iterator&&) noexcept = default;
reference operator*() const;
pose_list_store_iterator& operator++();
pose_list_store_iterator operator++(int);
pose_list_store_iterator& operator--();
pose_list_store_iterator operator--(int);
pose_list_store_iterator& operator+=(difference_type n);
pose_list_store_iterator& operator-=(difference_type n);
pose_list_store_iterator operator+(difference_type n) const;
pose_list_store_iterator operator-(difference_type n) const;
difference_type operator-(const pose_list_store_iterator& other) const;
reference operator[](difference_type n) const;
bool operator==(const pose_list_store_iterator& other) const;
bool operator!=(const pose_list_store_iterator& other) const;
bool operator<(const pose_list_store_iterator& other) const;
bool operator<=(const pose_list_store_iterator& other) const;
bool operator>(const pose_list_store_iterator& other) const;
bool operator>=(const pose_list_store_iterator& other) const;
protected:
void calc_offset(difference_type n);
reference dereference() const;
private:
id_iterator_type m_ids{};
pose_iterator_type m_poses{};
length_iterator_type m_lengths{};
size_type m_index{};
offset_type m_offset{};
};
class pose_list_store
{
public:
using size_type = std::size_t;
using count_type = ztu::u32;
using iterator_type = pose_list_store_iterator<char>;
using const_iterator = pose_list_store_iterator<const char>;
using data_type = pose_list_data;
using id_type = pose_list_id;
// TODO not storing metadata
inline id_type add(
id_type id,
const data_type& pose_list
);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
[[nodiscard]] inline std::pair<const_iterator, bool> find(id_type id) const;
inline void remove(const iterator_type& it);
inline void clear();
[[nodiscard]] inline iterator_type begin();
[[nodiscard]] inline iterator_type end();
[[nodiscard]] inline const_iterator begin() const;
[[nodiscard]] inline const_iterator end() const;
[[nodiscard]] inline const_iterator cbegin() const;
[[nodiscard]] inline const_iterator cend() const;
private:
std::vector<id_type> m_ids;
std::vector<char> m_poses;
std::vector<count_type> m_lengths;
};
}
#define INCLUDE_POSE_LIST_STORE_IMPLEMENTATION
#include "assets/data_stores/pose_list_store.ipp"
#undef INCLUDE_POSE_LIST_STORE_IMPLEMENTATION

View File

@@ -15,12 +15,14 @@ class shader_source_store_iterator
public:
using size_type = std::size_t;
using length_type = ztu::u32;
using id_type = ztu::id_type_for<shader_source_store, ztu::u32>;
using id_type = shader_source_id;
using metadata_type = shader_source_data::metadata;
using value_type = std::pair<id_type, shader_source_view>;
using id_iterator_type = id_type const*;
using string_iterator_type = Char*;
using length_iterator_type = const length_type*;
using metadata_iterator_type = const metadata_type*;
using offset_type = size_type;
using difference_type = std::ptrdiff_t;
@@ -35,6 +37,7 @@ private:
id_iterator_type ids,
string_iterator_type strings,
length_iterator_type lengths,
metadata_iterator_type metadata,
std::size_t index,
const offset_type& offset
);
@@ -80,6 +83,7 @@ private:
id_iterator_type m_ids{};
string_iterator_type m_strings{};
length_iterator_type m_lengths{};
metadata_iterator_type m_metadata{};
size_type m_index{};
offset_type m_offset{};
};
@@ -95,9 +99,13 @@ public:
using const_iterator = shader_source_store_iterator<const char>;
using view_type = std::ranges::subrange<iterator_type>;
using const_view_type = std::ranges::subrange<const_iterator>;
using id_type = ztu::id_type_for<shader_source_store, ztu::u32>;
using id_type = shader_source_id;
inline id_type add(const shader_source_data& shader_source);
// TODO not storing metadata
inline id_type add(
shader_source_id id,
const shader_source_data& shader_source
);
[[nodiscard]] inline std::pair<iterator_type, bool> find(id_type id);
@@ -119,15 +127,12 @@ public:
[[nodiscard]] inline const_iterator cend() const;
[[nodiscard]] inline view_type view();
[[nodiscard]] inline const_view_type view() const;
private:
std::vector<id_type> m_ids;
std::vector<char> m_strings;
std::vector<count_type> m_lengths;
id_type m_next_data_id{ 1 };
std::vector<shader_source_data::metadata> m_metadata;
};
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include "generic/generic_point_cloud_viwe.hpp"
#include "generic/generic_point_cloud_view.hpp"
namespace assets
{

View File

@@ -0,0 +1,11 @@
#pragma once
#include "assets/data/pose_data.hpp"
namespace assets
{
using pose_list_view = std::span<pose_data>;
}

View File

@@ -1,5 +1,20 @@
#pragma once
#include "config/primitives.hpp"
#include <string_view>
#include "assets/model_geometry.hpp"
#include "assets/components/shader_components.hpp"
using shader_source_view = z3d::string_view;
namespace assets
{
struct shader_source_view
{
std::string_view source;
model_geometry::types geometry_type;
shader_components::stage stage;
shader_components::flags components{};
shader_components::flags static_enable{};
shader_components::flags dynamic_enable{};
};
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "assets/data/material_data.hpp"
namespace assets
{
material_data generate_fallback_material();
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include "assets/components/texture_components.hpp"
#include "assets/data/texture_data.hpp"
namespace assets
{
struct fallback_color
{
static constexpr auto components = (
texture_components::flags::red |
texture_components::flags::green |
texture_components::flags::blue
);
texture_data::value_type r, g, b;
};
texture_data generate_fallback_texture(
int width = 4,
int height = 4,
std::span<const fallback_color> colors = std::array{
fallback_color{ .r = 255, .g = 0, b = 255 },
fallback_color{ .r = 0, .g = 0, b = 0 }
}
);
}

View File

@@ -1,35 +0,0 @@
#pragma once
#include <filesystem>
#include <vector>
#include <string>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/prefetch_lookups/mesh_prefetch_lookup.hpp"
#include "assets/data/shader_source_data.hpp"
#include "util/string_list.hpp"
namespace assets
{
struct glsl_loader
{
static constexpr auto name = std::string_view("glsl");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
shader_source_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
};
}

View File

@@ -0,0 +1,122 @@
#pragma once
#include <filesystem>
#include "assets/path_id_lookups.hpp"
#include "assets/data_stores/shader_source_store.hpp"
#include "assets/data/shader_source_data.hpp"
namespace assets
{
struct glsl_parser
{
static constexpr auto name = std::string_view("glsl");
using data_type = shader_source_data;
using store_type = shader_source_store;
using lookup_type = shader_source_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code load(
const path_id_lookups& lookups,
store_type& store,
bool pedantic = false
);
protected:
class parser_context
{
public:
parser_context(
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
void tokenize_declarations();
[[nodiscard]] bool parse_metadata_from_tokens();
void remove_metadata_declarations();
private:
store_type* m_store;
std::mutex* m_store_mutex;
shader_source_data m_buffer{};
std::vector<std::string_view> m_value_buffer{};
std::vector<std::size_t> m_declaration_value_count_buffer{};
std::array<std::size_t, 4> m_declaration_type_index_buffer{};
};
[[nodiscard]] static std::error_code read_file(
const std::filesystem::path& filename,
std::vector<char>& source
);
static void tokenize_declarations(
std::string_view source,
std::vector<std::string_view>& value_buffer,
std::vector<std::size_t>& declaration_value_count_buffer,
std::array<std::size_t, 4>& declaration_type_index_buffer
);
static [[nodiscard]] bool parse_metadata_from_tokens(
const std::vector<std::string_view>& value_buffer,
const std::vector<std::size_t>& declaration_value_count_buffer,
const std::array<std::size_t, 4>& declaration_type_index_buffer,
shader_source_data& buffer
);
static void remove_metadata_declarations(
const std::vector<std::string_view>& value_buffer,
const std::vector<std::size_t>& declaration_value_count_buffer,
const std::array<std::size_t, 4>& declaration_type_index_buffer,
std::vector<char>& source
);
[[nodiscard]] static bool parse_geometry_declaration(
std::span<const std::string_view> values,
model_geometry::types& geometry_type
);
[[nodiscard]] static bool parse_stage_declaration(
std::span<const std::string_view> values,
shader_components::stage& stage
);
[[nodiscard]] static bool parse_components_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_static_enable_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_dynamic_enable_declaration(
std::span<const std::string_view> values,
shader_source_data& buffer
);
[[nodiscard]] static bool parse_component_tokens(
std::span<const std::string_view> values,
model_geometry::types geometry_type,
shader_components::flags& components
);
private:
std::vector<std::string_view> m_value_token_buffer;
std::vector<std::size_t> m_declaration_token_count_buffer;
std::array<std::size_t, 4> m_declaration_type_index_buffer;
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -1,19 +0,0 @@
struct X {
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
// space stuff that has to persist
dynamic_X_buffer& buffer,
const file_dir_list& paths,
dynamic_X_store& store,
prefetch_lookup& id_lookup,
bool pedantic = false
);
}

View File

@@ -1,59 +0,0 @@
#pragma once
#include <filesystem>
#include <vector>
#include <span>
#include "assets/data_stores.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/data/point_cloud_data.hpp"
#include "assets/data_stores/point_cloud_store.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "glm/mat4x4.hpp"
#include "util/result.hpp"
namespace assets
{
struct kitti_loader
{
static constexpr auto name = std::string_view("kitti");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
point_cloud_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
private:
inline static constexpr auto frame_folder = "frames";
[[nodiscard]] static ztu::result<std::size_t> frame_id_from_filename(
std::string_view filename
);
[[nodiscard]] static std::error_code load_point_file(
const std::filesystem::path& filename,
dynamic_point_cloud_buffer& point_cloud
);
static void transform_point_cloud(
std::span<point_cloud_vertex_components::position> points,
const glm::mat4& pose
);
[[nodiscard]] static ztu::result<std::string_view> parent_directory(std::string_view path);
};
}

View File

@@ -0,0 +1,98 @@
#pragma once
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/path_id_lookups.hpp"
#include "assets/components/point_cloud_vertex_components.hpp"
#include "assets/data/point_cloud_data.hpp"
#include "assets/data/pose_data.hpp"
#include "assets/data_stores/point_cloud_store.hpp"
#include "assets/data_stores/pose_list_store.hpp"
#include "assets/data_views/pose_list_view.hpp"
#include "util/result.hpp"
namespace assets
{
struct kitti_parser
{
static constexpr auto name = std::string_view("kitti");
using data_type = point_cloud_data;
using store_type = point_cloud_store;
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:
static constexpr auto frame_folder = "frames";
class parser_context
{
public:
parser_context(
const pose_list_id_lookup& pose_list_lookup,
const pose_list_store& pose_list_store,
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
void tokenize_declarations();
[[nodiscard]] bool parse_metadata_from_tokens();
void remove_metadata_declarations();
private:
pose_list_id_lookup const* m_pose_list_lookup;
pose_list_store const* m_pose_list_store;
store_type* m_store;
std::mutex* m_store_mutex;
data_type m_buffer{};
std::filesystem::path m_last_pose_path{};
pose_list_view m_last_pose_list{};
};
[[nodiscard]] static ztu::result<std::size_t> frame_id_from_filename(
std::string_view filename
);
[[nodiscard]] static std::error_code load_point_file(
const std::filesystem::path& filename,
data_type& point_cloud
);
static void transform_point_cloud(
z3d::array_view<point_cloud_vertex_components::position> points,
const pose_data& pose
);
[[nodiscard]] static ztu::result<std::filesystem::path> parent_directory(
const std::filesystem::path& path
);
#
[[nodiscard]] static ztu::result<std::filesystem::path> get_pose_path(
const std::filesystem::path& path
);
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -1,37 +0,0 @@
#pragma once
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "util/string_list.hpp"
#include "../data_stores"
#include "assets/data"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
struct kitti_pose_loader
{
static constexpr auto name = std::string_view("kitti_pose");
[[nodiscard]] static std::error_code prefetch(
const file_dir_list& paths,
prefetch_queue& queue
);
[[nodiscard]] static std::error_code load(
dynamic_pose_buffer& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
bool pedantic = false
);
private:
static constexpr auto pose_filename = std::string_view{ "pose.txt" };
static std::error_code parse_pose(
std::ifstream& in,
dynamic_pose_buffer& pose
);
};

View File

@@ -0,0 +1,66 @@
#pragma once
#include <filesystem>
#include "assets/path_id_lookups.hpp"
#include "assets/data_stores/pose_list_store.hpp"
#include "assets/data/pose_list_data.hpp"
namespace assets
{
struct kitti_pose_parser
{
static constexpr auto name = std::string_view("kitti_pose");
using data_type = pose_list_data;
using store_type = pose_list_store;
using lookup_type = pose_list_id_lookup;
[[nodiscard]] std::error_code prefetch(
path_id_lookups& lookups
);
[[nodiscard]] std::error_code parse(
const path_id_lookups& lookups,
store_type& store,
bool pedantic = false
);
private:
static constexpr auto pose_filename = std::string_view{ "pose.txt" };
class parser_context
{
public:
parser_context(
store_type& m_store,
std::mutex& m_store_mutex
);
void operator()(lookup_type::const_pointer entry) noexcept;
protected:
void reset();
private:
store_type* m_store;
std::mutex* m_store_mutex;
data_type m_buffer{};
};
static std::error_code parse_file(
const std::filesystem::path& filename,
data_type &poses
);
static std::error_code parse_pose(
std::ifstream& in,
pose_data& pose
);
private:
std::vector<lookup_type::const_pointer> m_path_buffer;
};
}

View File

@@ -3,15 +3,17 @@
#include <filesystem>
#include <system_error>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data"
#include "../data_stores"
#include "../data_stores"
#include "util/string_lookup.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_loader_error
{
enum class codes {
@@ -54,3 +56,5 @@ protected:
ztu::string_list& texture_filenames
);
};
}

View File

@@ -2,14 +2,15 @@
#include <filesystem>
#include "assets/data_stores.hpp"
#include "assets/prefetch_lookup.hpp"
#include "assets/prefetch_queue.hpp"
#include "assets/data"
#include "util/string_list.hpp"
#include "assets/data/pose_data.hpp"
#include "util/result.hpp"
#include "assets/prefetch_lookups/pose_prefetch_lookup.hpp"
namespace assets
{
struct threedtk_pose_loader
{
static constexpr auto name = std::string_view("3dtk_pose");
@@ -20,7 +21,7 @@ struct threedtk_pose_loader
);
[[nodiscard]] static std::error_code load(
dynamic_pose_buffer& buffer,
pose_data& buffer,
const file_dir_list& paths,
prefetch_lookup& id_lookup,
shader_source_store& store,
@@ -38,3 +39,5 @@ protected:
std::string_view filename
);
};
}

View File

@@ -5,12 +5,27 @@
namespace assets
{
using material_id = z3d::identifier<0>;
using material_library_id = z3d::identifier<1>;
using mesh_id = z3d::identifier<2>;
using point_cloud_id = z3d::identifier<3>;
using pose_id = z3d::identifier<4>;
using shader_source_id = z3d::identifier<5>;
using texture_id = z3d::identifier<6>;
namespace identifier_uuids
{
enum : int {
material,
material_library,
mesh,
point_cloud,
pose,
pose_list,
shader_source,
texture
};
}
using material_id = z3d::identifier<identifier_uuids::material>;
using material_library_id = z3d::identifier<identifier_uuids::material_library>;
using mesh_id = z3d::identifier<identifier_uuids::mesh>;
using point_cloud_id = z3d::identifier<identifier_uuids::point_cloud>;
using pose_id = z3d::identifier<identifier_uuids::pose>;
using pose_list_id = z3d::identifier<identifier_uuids::pose_list>;
using shader_source_id = z3d::identifier<identifier_uuids::shader_source>;
using texture_id = z3d::identifier<identifier_uuids::texture>;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "config/primitives.hpp"
namespace assets::model_geometry
{
enum class types : z3d::u8
{
mesh = 0,
point_cloud = 1
};
inline constexpr z3d::size count = 2;
inline constexpr auto names = z3d::array<z3d::string_view, 2>{
"mesh",
"point_cloud"
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "identifiers.hpp"
#include "util/file_id_lookup.hpp"
namespace assets
{
using material_id_lookup = file_id_lookup<material_id>;
using material_library_id_lookup = file_id_lookup<material_library_id>;
using mesh_id_lookup = file_id_lookup<mesh_id>;
using point_cloud_id_lookup = file_id_lookup<point_cloud_id>;
using pose_id_lookup = file_id_lookup<pose_id>;
using pose_list_id_lookup = file_id_lookup<pose_id>;
using shader_source_id_lookup = file_id_lookup<shader_source_id>;
using texture_id_lookup = file_id_lookup<texture_id>;
struct path_id_lookups
{
material_id_lookup materials;
material_library_id_lookup material_libraries;
mesh_id_lookup meshes;
point_cloud_id_lookup point_clouds;
pose_id_lookup poses;
pose_list_id_lookup pose_lists;
shader_source_id_lookup shader_sources;
texture_id_lookup textures;
};
}