Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
MeshComponent.h
1#pragma once
2
3#include "Engine/Component/LogicComponent.h"
4#include "Engine/Asset/AssetRegistry.h"
5#include "Engine/Asset/AssetHandles.h"
6#include "Engine/Core/Asset.h"
7#include "Engine/Ecs/EcsData.h"
8#include "Engine/Material/MaterialTypes.h"
9#include "Engine/Mesh/MeshAssetRef.h"
10
11#include <string>
12#include <string_view>
13#include <vector>
14
15#ifdef ENABLE_TRACY
16#include <tracy/Tracy.hpp>
17#endif
18
19namespace Engine::Assets
20{
21 class Mesh;
22} // namespace Engine::Assets
23
24namespace Engine::Entities
25{
26 class SceneNode;
27} // namespace Engine::Entities
28
29namespace Engine::Core
30{
31 class Engine;
32 class SceneNode;
33 class Mesh;
34 class RenderingDataManager;
35} // namespace EngineCore
36
37namespace Engine::Components
38{
39 class Collision;
40 class MaterialShader;
41
46 class Mesh : public Logic
47 {
48 public:
49 static constexpr const char* ComponentName = "Mesh";
50
51 private:
52 std::string name = "game object";
53 bool visible = true;
54
55 public:
60 Entities::Scene * owningScene,
61 entt::entity & actor,
62 Asset::MeshPath asset,
63 std::shared_ptr<Entities::SceneNode> sceneNode,
64 bool isVisible_ = true,
65 const std::string & name_ = "game object"
66 );
67
72 Entities::Scene * owningScene,
73 entt::entity & actor,
75 std::shared_ptr<Entities::SceneNode> sceneNode,
76 bool isVisible_ = true,
77 const std::string & name_ = "game object"
78 );
79
84 Entities::Scene * owningScene,
85 entt::entity & actor,
87 std::shared_ptr<Entities::SceneNode> sceneNode,
88 bool isVisible_ = true,
89 const std::string & name_ = "game object"
90 );
91
96 Entities::Scene * owningScene,
97 entt::entity & actor,
98 Asset::MeshPath asset,
99 std::shared_ptr<Entities::SceneNode> sceneNode,
100 Core::RenderingDataManager * renderingDataManager,
101 bool isVisible_ = true,
102 const std::string & name_ = "game object"
103 );
104
109 Entities::Scene * owningScene,
110 entt::entity & actor,
112 std::shared_ptr<Entities::SceneNode> sceneNode,
113 Core::RenderingDataManager * renderingDataManager,
114 bool isVisible_ = true,
115 const std::string & name_ = "game object"
116 );
117
122 Entities::Scene * owningScene,
123 entt::entity & actor,
125 std::shared_ptr<Entities::SceneNode> sceneNode,
126 Core::RenderingDataManager * renderingDataManager,
127 bool isVisible_ = true,
128 const std::string & name_ = "game object"
129 );
130
134 ~Mesh() override = default;
135
136 void beginPlay() override;
137 void endPlay() override;
138
142 bool drawImGui() override;
143
148 [[nodiscard]] bool isVisible() const;
149
153 void setVisible( bool isVisible );
154
159 [[nodiscard]] Assets::MeshAssetRef getMeshAsset() const;
160
165 [[nodiscard]] glm::mat4 getWorldTransform() const;
170 [[nodiscard]] glm::mat4 getLocalTransform() const;
171
177 [[nodiscard]] std::optional<Core::AnchorPoint> anchorPoint( std::string_view name ) const;
178
183 [[nodiscard]] std::vector<std::string> anchorPointNames() const;
184
190
196
201
206 [[nodiscard]] std::optional<Assets::MaterialHandle> getMaterialOverride() const;
207
212 [[nodiscard]] std::string getAssetName() const;
213
219
224 void attachCollisionChildren(const std::vector<Collision *> & collisions);
225
230 void detachCollisionChild(const Collision * collision);
231
236 [[nodiscard]] const std::vector<Collision *> & getCollisionChildren() const;
237
243 [[nodiscard]] bool ownsCollisionChild(const Logic * component) const;
244
250
251 protected:
256 [[nodiscard]] std::shared_ptr<Entities::SceneNode> getSceneNode() const;
257
262 [[nodiscard]] Ecs::StaticMeshData * getStaticMeshData() const;
263
264 entt::entity componentEntity = entt::null;
265 std::optional<std::shared_ptr<Entities::SceneNode>> sceneNode;
266
267 private:
269 Entities::Scene * owningScene,
270 entt::entity & actor,
271 Asset::MeshPath asset,
272 std::optional<Assets::GltfRenderableHandle> renderable,
274 );
275
276 Core::RenderingDataManager * renderingDataManager_ = nullptr;
277 std::vector<Collision *> collisionChildren_;
278 std::optional<Assets::MaterialHandle> materialOverride_;
279 };
280} // namespace EngineCore
The mesh asset stores geometry data and.
Definition MeshAsset.h:20
Base class for collision shape components.
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
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)
Overrides the material used for rendering this mesh.
bool ownsCollisionChild(const Logic *component) const
Checks whether a logic component is one of this mesh's collision children.
std::optional< Core::AnchorPoint > anchorPoint(std::string_view name) const
Looks up an AnchorPoint on this renderable-backed mesh.
void setVisible(bool isVisible)
Sets whether this mesh component should be rendered.
void beginPlay() override
Called when the component is added to the scene or the game starts.
void attachCollisionChild(Collision *collision)
Records a collision component owned by this mesh.
std::optional< std::shared_ptr< Entities::SceneNode > > sceneNode
Scene node used for transforms.
static constexpr const char * ComponentName
Component type name.
void attachCollisionChildren(const std::vector< Collision * > &collisions)
Records multiple collision components owned by this mesh.
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
Destroys the mesh component.
const std::vector< Collision * > & getCollisionChildren() const
Gets collision components owned by this mesh.
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")
Production constructor for a geometry mesh handle.
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")
Production constructor for a GLTF renderable handle.
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")
Testable constructor for a GLTF renderable handle.
Ecs::StaticMeshData * getStaticMeshData() const
Gets the ECS static mesh data for derived components.
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.
entt::entity componentEntity
ECS entity that stores this mesh component data.
virtual void onMeshAssetResolved(Assets::MeshAssetRef meshAsset)
Called when the mesh asset reference has resolved.
void clearMaterialOverride()
Clears the material override and returns to the mesh material.
Core::RenderingDataManager * renderingDataManager_
std::vector< std::string > anchorPointNames() const
Lists this renderable's AnchorPoint names.
std::optional< Assets::MaterialHandle > getMaterialOverride() const
Gets the current material override.
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")
Testable constructor for a geometry mesh handle.
void detachCollisionChild(const Collision *collision)
Removes a collision component from this mesh's child list.
void endPlay() override
Called when the component is removed or the game ends.
std::shared_ptr< Entities::SceneNode > getSceneNode() const
Gets the scene node used for mesh transforms.
Represents a node in the scene graph, containing information about its position, rotation,...
Definition SceneGraph.h:27
Owns scene entities, actor lifetime, and the scene graph root.
Definition Scene.h:84
AssetHandle< GltfRenderableHandleTag > GltfRenderableHandle
Handle to one mesh-bearing node inside a glTF file.
Asset::Ref< Asset::MeshPath, Mesh > MeshAssetRef
Asset reference to mesh geometry loaded from a mesh asset path.
AssetHandle< GeometryMeshHandleTag > GeometryMeshHandle
Handle to non-skinned mesh geometry.
AssetHandle< MaterialHandleTag > MaterialHandle
Handle to a material payload.
PipelineNames
Named graphics pipelines used by material selection and shader lookup.
Identifies a named mesh-like asset inside an asset file.
Definition AssetPath.h:89
Mesh component state for one static mesh reference.
Definition EcsData.h:100