Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
MeshComponent.h
Go to the documentation of this file.
1#pragma once
2
5#include "Engine/Core/Asset.h"
9
10#include <string>
11#include <vector>
12
13#ifdef ENABLE_TRACY
14#include <tracy/Tracy.hpp>
15#endif
16
17namespace Engine::Assets
18{
19 class Mesh;
20} // namespace Engine::Assets
21
22namespace Engine::Entities
23{
24 class SceneNode;
25} // namespace Engine::Entities
26
27namespace Engine::Core
28{
29 class Engine;
30 class SceneNode;
31 class Mesh;
32 class RenderingDataManager;
33} // namespace EngineCore
34
35namespace Engine::Components
36{
37 class Collision;
38 class MaterialShader;
39
44 class Mesh : public Logic
45 {
46 public:
47 static constexpr const char* ComponentName = "Mesh";
48
49 private:
50 std::string name = "game object";
51 bool visible = true;
52
53 public:
58 Entities::Scene * owningScene,
59 entt::entity & actor,
60 Asset::MeshPath asset,
61 std::shared_ptr<Entities::SceneNode> sceneNode,
62 bool isVisible_ = true,
63 const std::string & name_ = "game object"
64 );
65
67 Entities::Scene * owningScene,
68 entt::entity & actor,
70 std::shared_ptr<Entities::SceneNode> sceneNode,
71 bool isVisible_ = true,
72 const std::string & name_ = "game object"
73 );
74
76 Entities::Scene * owningScene,
77 entt::entity & actor,
79 std::shared_ptr<Entities::SceneNode> sceneNode,
80 bool isVisible_ = true,
81 const std::string & name_ = "game object"
82 );
83
88 Entities::Scene * owningScene,
89 entt::entity & actor,
90 Asset::MeshPath asset,
91 std::shared_ptr<Entities::SceneNode> sceneNode,
92 Core::RenderingDataManager * renderingDataManager,
93 bool isVisible_ = true,
94 const std::string & name_ = "game object"
95 );
96
98 Entities::Scene * owningScene,
99 entt::entity & actor,
101 std::shared_ptr<Entities::SceneNode> sceneNode,
102 Core::RenderingDataManager * renderingDataManager,
103 bool isVisible_ = true,
104 const std::string & name_ = "game object"
105 );
106
108 Entities::Scene * owningScene,
109 entt::entity & actor,
111 std::shared_ptr<Entities::SceneNode> sceneNode,
112 Core::RenderingDataManager * renderingDataManager,
113 bool isVisible_ = true,
114 const std::string & name_ = "game object"
115 );
116
117 ~Mesh() override = default;
118
119 void beginPlay() override;
120 void endPlay() override;
121
125 bool drawImGui() override;
126
131 [[nodiscard]] bool isVisible() const;
132
137 [[nodiscard]] Assets::MeshAssetRef getMeshAsset() const;
138
143 [[nodiscard]] glm::mat4 getWorldTransform() const;
148 [[nodiscard]] glm::mat4 getLocalTransform() const;
149
155
158 [[nodiscard]] std::optional<Assets::MaterialHandle> getMaterialOverride() const;
159
164 [[nodiscard]] std::string getAssetName() const;
165
167 void attachCollisionChildren(const std::vector<Collision *> & collisions);
168 void detachCollisionChild(const Collision * collision);
169 [[nodiscard]] const std::vector<Collision *> & getCollisionChildren() const;
170 [[nodiscard]] bool ownsCollisionChild(const Logic * component) const;
171
173
174 protected:
175 [[nodiscard]] std::shared_ptr<Entities::SceneNode> getSceneNode() const;
176 [[nodiscard]] Ecs::StaticMeshData * getStaticMeshData() const;
177
178 entt::entity componentEntity = entt::null;
179 std::optional<std::shared_ptr<Entities::SceneNode>> sceneNode;
180
182
183 private:
185 Entities::Scene * owningScene,
186 entt::entity & actor,
187 Asset::MeshPath asset,
188 std::optional<Assets::GltfRenderableHandle> renderable,
190 );
191
192 Core::RenderingDataManager * renderingDataManager_ = nullptr;
193 std::vector<Collision *> collisionChildren_;
194 std::optional<Assets::MaterialHandle> materialOverride_;
195 };
196} // namespace EngineCore
The mesh asset stores geometry data and.
Definition MeshAsset.h:20
Base class for collision shape components.
Logic(Entities::Scene *owningScene)
std::vector< Collision * > collisionChildren_
void initializeMeshData(Entities::Scene *owningScene, entt::entity &actor, Asset::MeshPath asset, std::optional< Assets::GltfRenderableHandle > renderable, Assets::GeometryMeshHandle mesh)
Assets::MeshAssetRef getMeshAsset() const
Gets the asset used by this mesh rendering component.
void setMaterialOverride(Assets::MaterialHandle material)
bool ownsCollisionChild(const Logic *component) const
void beginPlay() override
Called when the component is added to the scene or the game starts.
void attachCollisionChild(Collision *collision)
std::optional< std::shared_ptr< Entities::SceneNode > > sceneNode
static constexpr const char * ComponentName
void attachCollisionChildren(const std::vector< Collision * > &collisions)
glm::mat4 getWorldTransform() const
Getter for the world transform of the mesh component.
Mesh(Entities::Scene *owningScene, entt::entity &actor, Asset::MeshPath asset, std::shared_ptr< Entities::SceneNode > sceneNode, Core::RenderingDataManager *renderingDataManager, bool isVisible_=true, const std::string &name_="game object")
Testable constructor - allows injecting RenderingDataManager for testing.
std::string getAssetName() const
Gets the asset name of this mesh component (e.g. "rat")
~Mesh() override=default
const std::vector< Collision * > & getCollisionChildren() const
bool isVisible() const
If this mesh component should be considered for rendering.
std::optional< Assets::MaterialHandle > materialOverride_
Mesh(Entities::Scene *owningScene, entt::entity &actor, Assets::GeometryMeshHandle mesh, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
Rendering::PipelineNames getMaterialNames() const
Gets the material name of this mesh component.
Mesh(Entities::Scene *owningScene, entt::entity &actor, Assets::GltfRenderableHandle renderable, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
bool drawImGui() override
Draw the debug UI.
Mesh(Entities::Scene *owningScene, entt::entity &actor, Assets::GltfRenderableHandle renderable, std::shared_ptr< Entities::SceneNode > sceneNode, Core::RenderingDataManager *renderingDataManager, bool isVisible_=true, const std::string &name_="game object")
Ecs::StaticMeshData * getStaticMeshData() const
Mesh(Entities::Scene *owningScene, entt::entity &actor, Asset::MeshPath asset, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
Production constructor - uses EngineManager singleton to get RenderingDataManager.
virtual void onMeshAssetResolved(Assets::MeshAssetRef meshAsset)
Ecs::StaticMeshData * staticMeshData
Core::RenderingDataManager * renderingDataManager_
std::optional< Assets::MaterialHandle > getMaterialOverride() const
glm::mat4 getLocalTransform() const
Gets the local model matrix which isn't affected by its parent.
Mesh(Entities::Scene *owningScene, entt::entity &actor, Assets::GeometryMeshHandle mesh, std::shared_ptr< Entities::SceneNode > sceneNode, Core::RenderingDataManager *renderingDataManager, bool isVisible_=true, const std::string &name_="game object")
void detachCollisionChild(const Collision *collision)
void endPlay() override
Called when the component is removed or the game ends.
std::shared_ptr< Entities::SceneNode > getSceneNode() const
Represents a node in the scene graph, containing information about its position, rotation,...
Definition SceneGraph.h:18
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:62
AssetHandle< GltfRenderableHandleTag > GltfRenderableHandle
Asset::Ref< Asset::MeshPath, Mesh > MeshAssetRef
AssetHandle< GeometryMeshHandleTag > GeometryMeshHandle
AssetHandle< MaterialHandleTag > MaterialHandle
Manages IBL (Image-Based Lighting) resources for specular reflections.
PipelineNames
Named graphics pipelines used by material selection and shader lookup.
Identifies a named mesh-like asset inside an asset file.
Definition AssetPath.h:40