Finality Engine
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <vector>
9#include <memory>
10#include <glm/glm.hpp>
11
12#include <Core/Core.h>
13#include <string>
14
15namespace FINALITY
16{
18 struct Vertex
19 {
20 glm::vec3 Position;
21 glm::vec3 Color;
22 glm::vec2 TexCoord;
23 glm::vec3 Normal{0.0f, 1.0f, 0.0f};
24 glm::vec4 Tangent{1.0f, 0.0f, 0.0f, 1.0f};
25 };
26
29 {
30 glm::mat4 MVP;
31
32 float CustomFloat0 = 0.0f;
33 float CustomFloat1 = 0.0f;
34 float Time = 0.0f;
35 float Padding = 0.0f;
36 };
37
39 class FAPI Mesh
40 {
41 public:
42 virtual ~Mesh() = default;
43 Mesh(const Mesh&) = delete;
44 Mesh& operator=(const Mesh&) = delete;
45 Mesh() = default;
46
47 static std::shared_ptr<Mesh> Create(const std::vector<Vertex>& vertices);
48 static std::shared_ptr<Mesh> Create(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
49 static std::shared_ptr<Mesh> Create(const std::string& meshPath);
50 static void CalculateNormalsAndTangents(std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
51
52 virtual void Destroy() = 0;
53 virtual void UpdateVertices(const std::vector<Vertex>& vertices) = 0;
54
55 virtual uint32_t GetVertexCount() const = 0;
56 virtual uint32_t GetIndexCount() const = 0;
57 virtual bool HasIndices() const = 0;
58
59 glm::vec3 GetBoundsCenter() const { return m_BoundsCenter; }
60 float GetBoundsRadius() const { return m_BoundsRadius; }
61 const std::vector<Vertex>& GetVertices() const { return m_Vertices; }
62 const std::vector<uint32_t>& GetIndices() const { return m_Indices; }
63 bool Raycast(const glm::vec3& origin, const glm::vec3& direction, const glm::mat4& world, float& distance) const;
64
65 private:
66 glm::vec3 m_BoundsCenter = glm::vec3(0.0f);
67 float m_BoundsRadius = 0.0f;
68 std::vector<Vertex> m_Vertices;
69 std::vector<uint32_t> m_Indices;
70 protected:
71 void ComputeBounds(const std::vector<Vertex>& vertices);
72 void SetIndices(const std::vector<uint32_t>& indices) { m_Indices = indices; }
73 };
74}
#define FAPI
Definition Core.h:22
static std::shared_ptr< Mesh > Create(const std::vector< Vertex > &vertices)
virtual uint32_t GetIndexCount() const =0
static std::shared_ptr< Mesh > Create(const std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices)
void ComputeBounds(const std::vector< Vertex > &vertices)
virtual uint32_t GetVertexCount() const =0
virtual void UpdateVertices(const std::vector< Vertex > &vertices)=0
const std::vector< Vertex > & GetVertices() const
Definition Mesh.h:61
virtual void Destroy()=0
glm::vec3 GetBoundsCenter() const
Definition Mesh.h:59
Mesh()=default
static std::shared_ptr< Mesh > Create(const std::string &meshPath)
float GetBoundsRadius() const
Definition Mesh.h:60
static void CalculateNormalsAndTangents(std::vector< Vertex > &vertices, const std::vector< uint32_t > &indices)
bool Raycast(const glm::vec3 &origin, const glm::vec3 &direction, const glm::mat4 &world, float &distance) const
virtual bool HasIndices() const =0
Mesh(const Mesh &)=delete
const std::vector< uint32_t > & GetIndices() const
Definition Mesh.h:62
void SetIndices(const std::vector< uint32_t > &indices)
Definition Mesh.h:72
virtual ~Mesh()=default
Mesh & operator=(const Mesh &)=delete
glm::vec3 Normal
Definition Mesh.h:23
glm::vec2 TexCoord
Definition Mesh.h:22
glm::vec3 Color
Definition Mesh.h:21
glm::vec4 Tangent
Definition Mesh.h:24
glm::vec3 Position
Definition Mesh.h:20