This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

View File

@@ -0,0 +1,195 @@
#pragma once
#include <system_error>
#include <vector>
#include <filesystem>
#include "assets/data_loaders/glsl_loader.hpp"
#include "../assets/dynamic_read_buffers"
#include "opengl/handles/mesh_handle.hpp"
#include "opengl/handles/material_handle.hpp"
#include "opengl/handles/point_cloud_handle.hpp"
#include "SFML/Window.hpp"
#include "opengl/data/mesh_data.hpp"
#include "opengl/data/material_data.hpp"
#include "opengl/data/point_cloud_data.hpp"
#include "opengl/data/shader_program_data.hpp"
#include "assets/dynamic_data_loaders/dynamic_mesh_loader.hpp"
#include "assets/data_loaders/obj_loader.hpp"
#include "assets/data_loaders/stl_loader.hpp"
#include "assets/dynamic_data_loaders/dynamic_point_cloud_loader.hpp"
#include "assets/data_loaders/kitti_loader.hpp"
#include "assets/data_loaders/uos_loader.hpp"
#include "assets/data_loaders/uos_normal_loader.hpp"
#include "assets/data_loaders/uos_rgb_loader.hpp"
#include "assets/data_loaders/uosr_loader.hpp"
#include "geometry/aabb.hpp"
#include "opengl/data/shader_data.hpp"
namespace viewer
{
class asset_loader
{
public:
using dynamic_mesh_loader_type = dynamic_mesh_loader<
obj_loader, stl_loader
>;
using dynamic_point_cloud_loader_type = dynamic_point_cloud_loader<
kitti_loader,
uos_loader,
uos_normal_loader,
uos_rgb_loader,
uos_loader,
uosr_loader
>;
struct dynamic_point_cloud_handle_type
{
zgl::point_cloud_handle handle;
aabb bounding_box;
components::point_cloud_vertex::flags components;
};
struct dynamic_material_handle_type
{
zgl::material_handle handle;
material_component::flags components;
};
struct dynamic_mesh_handle_type
{
zgl::mesh_handle handle;
aabb bounding_box;
components::mesh_vertex::flags components;
};
using material_reference_entry_type = std::pair<ztu::u32, ztu::u32>;
std::error_code init(
components::mesh_vertex::flags enabled_mesh_components,
material_component::flags enabled_material_components,
components::point_cloud_vertex::flags enabled_point_cloud_components,
const dynamic_material_data& default_material
);
std::error_code load_shader(
GLenum type,
const std::filesystem::path& filename,
zgl::shader_handle& shader_handle
);
std::error_code build_shader_program(
const zgl::shader_handle& vertex_shader,
const zgl::shader_handle& geometry_shader,
const zgl::shader_handle& fragment_shader,
zgl::shader_program_handle& shader_program_handle
);
std::error_code load_asset(
const std::string& format,
const std::filesystem::path& filename,
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles,
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
);
std::error_code load_asset_directory(
const std::string& format,
const std::filesystem::path& path,
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles,
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
);
bool unload(const zgl::shader_program_handle& shader_handle);
void unload_shader_data();
bool unload(const zgl::mesh_handle& mesh_handle);
bool unload(const zgl::point_cloud_handle& point_cloud_handle);
protected:
std::error_code load_mesh(
const std::string& format,
const std::filesystem::path& filename,
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
);
std::error_code load_point_cloud(
const std::string& format,
const std::filesystem::path& filename,
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
);
std::error_code load_mesh_directory(
const std::string& format,
const std::filesystem::path& path,
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
);
std::error_code load_point_cloud_directory(
const std::string& format,
const std::filesystem::path& path,
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
);
std::error_code process_materials_and_meshes(
std::vector<std::pair<dynamic_mesh_handle_type, dynamic_material_handle_type>>& dynamic_mesh_handles
);
std::error_code process_point_clouds(
std::vector<dynamic_point_cloud_handle_type>& dynamic_point_cloud_handles
);
std::error_code create_gl_materials();
void create_gl_meshes(std::span<const material_reference_entry_type> material_references);
void create_gl_point_clouds();
std::error_code create_gl_shader();
private:
//sf::Context m_ctx;
components::mesh_vertex::flags m_enabled_mesh_components{
components::mesh_vertex::flags::none
};
material_component::flags m_enabled_material_components{
material_component::flags::none
};
components::point_cloud_vertex::flags m_enabled_point_cloud_components{
components::point_cloud_vertex::flags::none
};
glsl_loader m_shader_loader{};
dynamic_mesh_loader_type m_mesh_loader{};
dynamic_point_cloud_loader_type m_point_cloud_loader{};
dynamic_shader_data m_dynamic_shader_data_buffer{};
std::vector<dynamic_mesh_data> m_dynamic_mesh_data_buffer{};
std::vector<dynamic_material_data> m_dynamic_material_data_buffer{};
std::vector<dynamic_point_cloud_data> m_dynamic_point_cloud_buffer{};
std::vector<ztu::u8> m_vertex_buffer{};
std::vector<zgl::shader_data> m_gl_shader_data{};
std::vector<zgl::shader_program_data> m_gl_shader_program_data{};
std::vector<std::pair<zgl::mesh_data, aabb>> m_gl_mesh_data{};
std::vector<std::pair<zgl::point_cloud_data, aabb>> m_gl_point_cloud_data{};
std::vector<zgl::material_data> m_gl_material_data{};
std::vector<material_reference_entry_type> m_gl_material_data_references{};
ztu::u32 next_materials_id{ 0 };
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
namespace viewer
{
enum class asset_types {
mesh,
point_cloud
};
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include <filesystem>
#include "asset_loader.hpp"
#include "instance.hpp"
namespace viewer::dynamic_shader_program_loading
{
void load_directory(
asset_loader& loader,
instance& z3d,
std::mutex& gl_resource_lock,
std::mutex& progress_lock,
std::string& progress_title,
float& progress_ratio,
const std::filesystem::path& path
);
std::size_t count_shader_files(
const std::filesystem::path& path
);
}

118
include/viewer/instance.hpp Normal file
View File

@@ -0,0 +1,118 @@
#pragma once
#include <vector>
#include <variant>
#include "viewer/settings.hpp"
#include <mutex>
#include "asset_types.hpp"
#include "geometry/aabb.hpp"
#include "rendering/modes/mesh_modes.hpp"
#include "rendering/modes/point_cloud_modes.hpp"
#include "scene/flying_camera.hpp"
#include "scene/camera_view.hpp"
#include "scene/lighting_setup.hpp"
#include "opengl/data/mesh_data.hpp"
#include "opengl/data/material_data.hpp"
#include "opengl/data/point_cloud_data.hpp"
#include "opengl/data/shader_program_data.hpp"
#include "rendering/batch_renderers/mesh_batch_renderer.hpp"
#include "rendering/batch_renderers/point_cloud_batch_renderer.hpp"
#include "rendering/shader_program_lookups/mesh_lookup.hpp"
#include "rendering/shader_program_lookups/point_cloud_lookup.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "SFML/Graphics/Font.hpp"
#include "SFML/Graphics/Image.hpp"
namespace viewer {
class instance
{
static constexpr auto id_mesh_index = static_cast<int>(asset_types::mesh);
static constexpr auto id_point_cloud_index = static_cast<int>(asset_types::point_cloud);
public:
using asset_id = std::variant<
rendering::mesh_batch_renderer::id_type,
rendering::point_cloud_batch_renderer::id_type
>;
instance();
std::error_code init(std::string title);
std::optional<asset_id> add_mesh(
const zgl::mesh_handle& mesh,
const aabb& bounding_box,
components::mesh_vertex::flags mesh_components,
const zgl::material_handle& material,
material_component::flags material_components
);
std::optional<asset_id> add_point_cloud(
const zgl::point_cloud_handle& point_cloud,
const aabb& bounding_box,
components::point_cloud_vertex::flags point_cloud_components
);
void add_shader_program(
asset_types type, zgl::shader_program_handle shader_program_handle
);
void set_background_color(const glm::vec4& color);
bool remove(asset_id id);
void run_progress(
std::mutex& lock,
std::string& title,
float& progress,
double fps = 30.0f
);
bool look_at(asset_id id);
void run(std::mutex& gl_resource_lock, double fps = std::numeric_limits<double>::max());
void windowed(unsigned int width, unsigned int height, bool decorations = true);
void fullscreen();
void size(unsigned int width, unsigned int height);
protected:
bool update(double dt);
void render();
public: // TODO fix
sf::ContextSettings m_context_settings;
sf::RenderWindow m_window;
std::string m_title;
glm::ivec2 m_screen_size;
sf::Font m_font{};
sf::Image m_logo{}, m_spinner{};
rendering::shader_program_lookups::mesh_lookup m_mesh_shader_program_lookup;
rendering::shader_program_lookups::point_cloud_lookup m_point_cloud_shader_program_lookup;
rendering::mesh_batch_renderer m_mesh_renderer;
rendering::point_cloud_batch_renderer m_point_cloud_renderer;
rendering::modes::mesh m_mesh_render_mode;
rendering::modes::point_cloud m_point_cloud_render_mode;
flying_camera m_camera;
camera_view m_view;
settings m_settings;
bool m_mouse_locked{ false };
};
} // namespace viewer

View File

@@ -0,0 +1,18 @@
#pragma once
#include "scene/lighting_setup.hpp"
namespace viewer
{
struct settings
{
float mouse_sensitivity{ 0.001f };
float scroll_speed{ 0.1f };
lighting_setup lighting{
.point_light_direction = { 1, -1, 1 },
//.point_light_direction = { -1, -1, -1 },
.point_light_color = { 3.0f, 3.0f, 3.0f },
.ambient_light_color = { 0.5f, 0.5f, 0.5f }
};
};
}