2021-12-07 19:51:12 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "shader.h"
|
2022-08-19 04:20:53 +00:00
|
|
|
#include "../event/event.h"
|
2021-12-07 19:51:12 +00:00
|
|
|
#include "vao.h"
|
|
|
|
#include "vbo.h"
|
|
|
|
#include "../vertex.h"
|
|
|
|
#include "../renderable.h"
|
|
|
|
#include "../transformable.h"
|
2022-08-19 04:20:53 +00:00
|
|
|
#include "material.h"
|
2021-12-07 19:51:12 +00:00
|
|
|
|
2022-08-19 04:20:53 +00:00
|
|
|
#include <optional>
|
2021-12-07 19:51:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace simpleengine::gfx {
|
2022-08-19 04:20:53 +00:00
|
|
|
/**
|
|
|
|
* @brief A Model is a object that will be shown on the screen by a renderer.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Model : public simpleengine::Event, public simpleengine::Transformable {
|
2021-12-07 19:51:12 +00:00
|
|
|
public:
|
2022-08-19 04:20:53 +00:00
|
|
|
std::optional<Material> material;
|
2022-08-18 20:03:51 +00:00
|
|
|
std::vector<LitVertex> vertices;
|
2021-12-07 19:51:12 +00:00
|
|
|
std::vector<GLuint> indicies;
|
|
|
|
|
2022-09-10 22:39:39 +00:00
|
|
|
// Buffer objects
|
|
|
|
gfx::VBO ebo;
|
|
|
|
gfx::VBO vbo;
|
|
|
|
gfx::VAO vao;
|
|
|
|
|
2022-08-30 23:39:24 +00:00
|
|
|
Model(std::vector<LitVertex> vertices, std::vector<GLuint> indicies, Material material);
|
2022-08-19 04:20:53 +00:00
|
|
|
Model(std::vector<LitVertex> vertices, std::vector<GLuint> indicies = std::vector<GLuint>(), std::optional<Material> material = std::nullopt);
|
2022-09-16 21:39:24 +00:00
|
|
|
Model(Material material, std::string filename);
|
|
|
|
Model(Material material, std::ifstream file_stream);
|
2021-12-07 19:51:12 +00:00
|
|
|
|
2022-09-10 22:39:39 +00:00
|
|
|
virtual void destroy() override;
|
|
|
|
|
2021-12-07 19:51:12 +00:00
|
|
|
virtual void update(const float& delta_time) override;
|
2022-08-18 20:03:51 +00:00
|
|
|
|
|
|
|
glm::vec3 compute_face_normal(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calculate the normals of the model.
|
|
|
|
*
|
|
|
|
* @note This **will** overwrite the existing normals.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void calculate_normals();
|
2022-09-16 21:39:24 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void process_vertex(const std::vector<std::string>& vertex_data, const std::vector<glm::vec2>& in_textures,
|
|
|
|
const std::vector<glm::vec3>& in_normals, std::vector<GLuint>& out_indicies,
|
|
|
|
std::vector<glm::vec2>& out_textures, std::vector<glm::vec3>& out_normals);
|
2021-12-07 19:51:12 +00:00
|
|
|
};
|
|
|
|
}
|