Finality Engine
Loading...
Searching...
No Matches
Components.h
Go to the documentation of this file.
1
11#pragma once
12#include <string>
13#include <memory>
14#include <glm/glm.hpp>
15#include <glm/gtc/matrix_transform.hpp>
16#include <Core/Mesh.h>
17#include <Core/Pipeline.h>
18#include <Renderer/Camera.h>
19#include <Renderer/Material.h>
20#include "LODGroup.h"
21
22namespace FINALITY
23{
26 {
27 std::string tag;
29
30 TagComponent() = default;
31 TagComponent(const TagComponent&) = default;
32 TagComponent(const std::string& tag)
33 : tag(tag), uuid(UUID()) {}
34 };
35
38 {
39 glm::vec3 Position{ 0.0f };
40 glm::vec3 Rotation{ 0.0f };
41 glm::vec3 Scale{ 1.0f };
42
43 glm::mat4 Matrix{ 1.0f };
44 glm::mat4 Basis{ 1.0f };
45
46 TransformComponent() = default;
48
49 TransformComponent(const glm::vec3& pos, const glm::vec3& rot, const glm::vec3& scale)
50 : Position(pos), Rotation(rot), Scale(scale) {}
51 TransformComponent(const glm::vec3& pos, const glm::vec3& rot)
52 : Position(pos), Rotation(rot) {}
53 TransformComponent(const glm::vec3& pos)
54 : Position(pos) {}
55
56 glm::mat4 GetTransformMatrix() const
57 {
58 glm::mat4 transform = glm::translate(glm::mat4(1.0f), Position);
59
60 transform = glm::rotate(transform, glm::radians(Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f));
61 transform = glm::rotate(transform, glm::radians(Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f));
62 transform = glm::rotate(transform, glm::radians(Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
63
64 transform = glm::scale(transform, Scale);
65
66 return transform * Basis;
67 }
68 };
69
72 {
73 std::shared_ptr<Material> MaterialInstance;
74 std::string MaterialIdentifier; // Path of the .fmat asset (empty for runtime-only materials)
75
76 MaterialComponent() = default;
81 {
82 if (this != &other)
83 {
84 MaterialInstance = other.MaterialInstance ? other.MaterialInstance->Clone() : nullptr;
86 }
87 return *this;
88 }
89 MaterialComponent(const std::shared_ptr<Material>& materialInstance)
90 : MaterialInstance(materialInstance) {}
91 MaterialComponent(const std::shared_ptr<Material>& instance, const std::string& identifier)
92 : MaterialInstance(instance), MaterialIdentifier(identifier) {}
93 };
94
97 {
98 std::shared_ptr<Mesh> MeshData;
99 std::string MeshIdentifier;
100 bool Occluder = false;
101
102 MeshComponent() = default;
103 MeshComponent(const MeshComponent&) = default;
104 MeshComponent(const std::shared_ptr<Mesh>& meshData)
105 : MeshData(meshData) {}
106 MeshComponent(const std::shared_ptr<Mesh>& meshData, const std::string& identifier)
107 : MeshData(meshData), MeshIdentifier(identifier) {}
108 MeshComponent(const std::string& identifier)
109 : MeshData(Mesh::Create(identifier)), MeshIdentifier(identifier) {}
110 };
111
114 {
115 std::unique_ptr<Camera> CameraInstance;
116 bool IsPrimary = true;
117 bool OcclusionCulling = false;
118
119 float FOV = 45.0f;
120 float AspectRatio = 1.778f;
121 float NearClip = 0.1f;
122 float FarClip = 1000.0f;
123
125 {
127 }
128
129 CameraComponent(float fov, float aspect, float nearClip, float farClip)
130 : FOV(fov), AspectRatio(aspect), NearClip(nearClip), FarClip(farClip)
131 {
133 }
134
137 {
138 if (other.CameraInstance)
140 }
141
143 {
144 if (this != &other)
145 {
146 IsPrimary = other.IsPrimary;
148 FOV = other.FOV;
149 AspectRatio = other.AspectRatio;
150 NearClip = other.NearClip;
151 FarClip = other.FarClip;
152 if (other.CameraInstance)
154 else
155 CameraInstance.reset();
156 }
157 return *this;
158 }
159
160 CameraComponent(CameraComponent&&) noexcept = default;
161 CameraComponent& operator=(CameraComponent&&) noexcept = default;
162
164 {
165 CameraInstance = std::make_unique<Camera>(FOV, AspectRatio, NearClip, FarClip);
166 CameraInstance->SetOcclusionCulling(OcclusionCulling);
167 }
168 };
169}
Stores camera projection and view configuration.
Stores authored level-of-detail thresholds and renderer membership.
CameraComponent & operator=(const CameraComponent &other)
Definition Components.h:142
CameraComponent(const CameraComponent &other)
Definition Components.h:135
CameraComponent(float fov, float aspect, float nearClip, float farClip)
Definition Components.h:129
CameraComponent(CameraComponent &&) noexcept=default
std::unique_ptr< Camera > CameraInstance
Definition Components.h:115
MaterialComponent(const MaterialComponent &other)
Definition Components.h:77
MaterialComponent(const std::shared_ptr< Material > &instance, const std::string &identifier)
Definition Components.h:91
MaterialComponent & operator=(const MaterialComponent &other)
Definition Components.h:80
std::shared_ptr< Material > MaterialInstance
Definition Components.h:73
MaterialComponent(const std::shared_ptr< Material > &materialInstance)
Definition Components.h:89
MeshComponent(const std::shared_ptr< Mesh > &meshData, const std::string &identifier)
Definition Components.h:106
MeshComponent(const MeshComponent &)=default
MeshComponent(const std::shared_ptr< Mesh > &meshData)
Definition Components.h:104
std::shared_ptr< Mesh > MeshData
Definition Components.h:98
MeshComponent(const std::string &identifier)
Definition Components.h:108
std::string MeshIdentifier
Definition Components.h:99
TagComponent(const TagComponent &)=default
TagComponent(const std::string &tag)
Definition Components.h:32
TransformComponent(const glm::vec3 &pos, const glm::vec3 &rot, const glm::vec3 &scale)
Definition Components.h:49
TransformComponent(const glm::vec3 &pos, const glm::vec3 &rot)
Definition Components.h:51
TransformComponent(const glm::vec3 &pos)
Definition Components.h:53
TransformComponent(const TransformComponent &)=default
glm::mat4 GetTransformMatrix() const
Definition Components.h:56