This commit is contained in:
ZY4N
2025-03-28 13:09:34 +01:00
parent 6f60cc11c8
commit d18b40a7fc
34 changed files with 393 additions and 272 deletions

View File

@@ -0,0 +1,33 @@
#pragma once
#include "config/primitives.hpp"
namespace assets::detail
{
template<typename C, typename T>
class component_array_set {};
template<typename C, typename... Ts>
class component_array_set<C, z3d::structure<Ts...>>
{
component_array_set() = default;
protected:
void clear_component_arrays()
{
std::apply(
[](auto&... component_array)
{
(component_array.clear(), ...);
},
component_arrays
);
}
C component_flags;
z3d::structure<z3d::vector<Ts>...> component_arrays{};
};
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "config/primitives.hpp"
namespace assets::detail {
template<typename T>
class component_set {};
template<typename... Ts>
class component_set<z3d::structure<Ts...>>
{
public:
component_set() = default;
protected:
void clear_components()
{
std::apply(
[](std::optional<Ts>&... component)
{
(component.reset(), ...);
},
components
);
}
z3d::structure<z3d::optional<Ts...>> components{};
};
}

View File

@@ -1,21 +0,0 @@
#pragma once
#include <vector>
template<typename C, typename... Ts>
struct vertex_array_data
{
C component_flags;
std::tuple<std::vector<Ts>...> vertices{};
protected:
void clear_vertices()
{
std::apply(
[](auto&... vertex_opt) {
(vertex_opt.clear(), ...);
},
vertices
);
}
};

View File

@@ -3,50 +3,37 @@
#include <optional>
#include "assets/components/material_components.hpp"
#include "assets/data_stores/texture_store.hpp"
#include "generic/component_set.hpp"
namespace assets
{
struct material_data
struct material_data : detail::component_set<material_components::all>
{
material_data() = default;
material_components::surface_properties& initialized_surface_properties();
[[nodiscard]] inline std::optional<material_components::surface_properties>& surface_properties();
[[nodiscard]] inline std::optional<material_components::transparency>& transparency();
[[nodiscard]] inline std::optional<material_components::ambient_color_texture>& ambient_color_texture_id();
[[nodiscard]] inline std::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id();
[[nodiscard]] inline std::optional<material_components::specular_color_texture>& specular_color_texture_id();
[[nodiscard]] inline std::optional<material_components::shininess_texture>& shininess_texture_id();
[[nodiscard]] inline std::optional<material_components::alpha_texture>& alpha_texture_id();
[[nodiscard]] inline std::optional<material_components::bump_texture>& bump_texture_id();
[[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::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 std::optional<material_components::surface_properties>& surface_properties() const;
[[nodiscard]] inline const std::optional<material_components::transparency>& transparency() const;
[[nodiscard]] inline const std::optional<material_components::ambient_color_texture>& ambient_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::diffuse_color_texture>& diffuse_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::specular_color_texture>& specular_color_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::shininess_texture>& shininess_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::alpha_texture>& alpha_texture_id() const;
[[nodiscard]] inline const std::optional<material_components::bump_texture>& bump_texture_id() const;
[[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::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;
inline void clear();
std::tuple<
std::optional<material_components::surface_properties>,
std::optional<material_components::transparency>,
std::optional<material_components::ambient_color_texture>,
std::optional<material_components::diffuse_color_texture>,
std::optional<material_components::specular_color_texture>,
std::optional<material_components::shininess_texture>,
std::optional<material_components::alpha_texture>,
std::optional<material_components::bump_texture>
> data{
std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt
};
};
}

View File

@@ -1,11 +1,11 @@
#pragma once
#include "util/string_lookup.hpp"
#include "assets/data_stores/material_store.hpp"
#include "assets/identifiers.hpp"
namespace assets
{
using material_library_data = ztu::string_lookup<material_store::id_type>;
using material_library_data = ztu::string_lookup<material_id>;
}

View File

@@ -1,49 +1,39 @@
#pragma once
#include <array>
#include <vector>
#include "util/uix.hpp"
#include "assets/components/mesh_vertex_components.hpp"
#include "generic/vertex_array_data.hpp"
#include "assets/data_stores/material_store.hpp"
#include "generic/component_array_set.hpp"
#include "assets/identifiers.hpp"
namespace assets
{
class mesh_data : public vertex_array_data<
class mesh_data : detail::component_array_set<
mesh_vertex_components::flags,
mesh_vertex_components::position,
mesh_vertex_components::normal,
mesh_vertex_components::tex_coord,
mesh_vertex_components::color,
mesh_vertex_components::reflectance
mesh_vertex_components::all
> {
public:
using index_type = ztu::u32;
using triangle_type = std::array<index_type, 3>;
[[nodiscard]] inline std::vector<mesh_vertex_components::position>& positions();
[[nodiscard]] inline std::vector<mesh_vertex_components::normal>& normals();
[[nodiscard]] inline std::vector<mesh_vertex_components::tex_coord>& tex_coords();
[[nodiscard]] inline std::vector<mesh_vertex_components::color>& colors();
[[nodiscard]] inline std::vector<mesh_vertex_components::reflectance>& reflectances();
[[nodiscard]] inline std::vector<triangle_type>& triangles();
[[nodiscard]] inline auto& material_id();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::position>& positions();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::normal>& normals();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::tex_coord>& tex_coords();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::color>& colors();
[[nodiscard]] inline z3d::vector<mesh_vertex_components::reflectance>& reflectances();
[[nodiscard]] inline z3d::vector<z3d::index_triangle>& triangles();
[[nodiscard]] inline auto& material();
[[nodiscard]] inline const std::vector<mesh_vertex_components::position>& positions() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::normal>& normals() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::tex_coord>& tex_coords() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::color>& colors() const;
[[nodiscard]] inline const std::vector<mesh_vertex_components::reflectance>& reflectances() const;
[[nodiscard]] inline const std::vector<triangle_type>& triangles() const;
[[nodiscard]] inline const auto& material_id() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::position>& positions() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::normal>& normals() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::tex_coord>& tex_coords() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::color>& colors() const;
[[nodiscard]] inline const z3d::vector<mesh_vertex_components::reflectance>& reflectances() const;
[[nodiscard]] inline const z3d::vector<z3d::index_triangle>& triangles() const;
[[nodiscard]] inline const auto& material() const;
inline void clear();
private:
std::vector<triangle_type> m_triangles{};
material_store::id_type m_material_id{};
z3d::vector<z3d::index_triangle> m_triangles{};
material_id m_material_id{};
};
}

View File

@@ -4,17 +4,14 @@
#include <array>
#include <vector>
#include "generic/vertex_array_data.hpp"
#include "generic/component_array_set.hpp"
namespace assets
{
class point_cloud_data : public vertex_array_data<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::position,
point_cloud_vertex_components::normal,
point_cloud_vertex_components::color,
point_cloud_vertex_components::reflectance
class point_cloud_data : detail::component_array_set<
point_cloud_vertex_components::flags,
point_cloud_vertex_components::all
> {
public:
[[nodiscard]] inline std::vector<point_cloud_vertex_components::position>& positions();

View File

@@ -1,10 +1,10 @@
#pragma once
#include "glm/mat4x4.hpp"
#include "config/primitives.hpp"
namespace assets
{
using pose_data = glm::mat4;
using pose_data = z3d::mat4;
}

View File

@@ -1,13 +1,13 @@
#pragma once
#include <vector>
#include "config/primitives.hpp"
namespace assets
{
struct shader_source_data
{
std::vector<char> source{};
z3d::vector<char> source{};
void clear()
{

View File

@@ -1,16 +1,16 @@
#pragma once
#include <array>
#include "config/primitives.hpp"
namespace assets
{
struct surface_properties
{
std::array<float, 3> ambient_filter{ 0.7f, 0.7f, 0.7f };
std::array<float, 3> diffuse_filter{ 0.466f, 0.466f, 0.7922f };
std::array<float, 3> specular_filter{ 0.5974f, 0.2084f, 0.2084f };
float shininess{ 100.2237f };
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

@@ -12,21 +12,22 @@ namespace assets
class texture_data
{
public:
using value_type = std::uint8_t;
using dim_type = std::int32_t;
using size_type = std::make_signed_t<std::size_t>;
using value_type = z3d::u8;
using dim_type = z3d::i32;
using size_type = z3d::size;
using difference_type = size_type;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = std::uint8_t*;
using const_pointer = const std::uint8_t*;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = pointer;
using const_iterator = const_pointer;
using container_type = std::unique_ptr<value_type[]>;
texture_data() = default;
inline texture_data(
std::unique_ptr<value_type[]>&& data,
container_type&& data,
dim_type width,
dim_type height,
texture_components::flags components
@@ -73,7 +74,7 @@ public:
void inline clear();
private:
std::unique_ptr<value_type[]> m_data{ nullptr };
container_type m_data{ nullptr };
dim_type m_width{ 0 }, m_height{ 0 };
texture_components::flags m_components{ texture_components::flags::none };
};