Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
MeshComponent.cpp
Go to the documentation of this file.
6
7namespace EngineCore
8{
10 Scene* owningScene,
11 entt::entity & actor,
12 Asset::Path asset,
13 std::shared_ptr<SceneNode> sceneNode,
14 bool isVisible_,
15 const std::string & name_
16 )
17 : MeshComponent( owningScene, actor, asset, sceneNode, nullptr, isVisible_, name_ )
18 {
19 }
20
22 Scene* owningScene,
23 entt::entity & actor,
24 Asset::Path asset,
25 std::shared_ptr<SceneNode> sceneNode,
26 RenderingDataManager* renderingDataManager,
27 bool isVisible_,
28 const std::string & name_
29 )
30 : LogicComponent( owningScene ), name( name_ ), visible( isVisible_ ), sceneNode( sceneNode ),
31 renderingDataManager_( renderingDataManager )
32 {
33 auto & registry = Ecs::RegistryManager::get();
34 componentEntity = registry.create();
35
36 AssetManager* assetManager = owningScene->getAssetManager();
37 if (assetManager == nullptr) throw std::runtime_error("AssetManager not available on Scene");
38 MeshAsset * meshAsset = assetManager->getMeshAsset( asset );
39
41 staticMeshData->asset = asset;
42
43 if ( meshAsset == nullptr )
44 {
45 staticMeshData->assetData = nullptr;
46 registry.emplace<Ecs::AssetRequested>( componentEntity );
47 }
48 else
49 {
50 staticMeshData->assetData = meshAsset;
51 }
52
53 auto & parent = registry.emplace<Ecs::Parent>( componentEntity );
54 parent.parent = actor;
55 }
56
58 {
60
61 // Register MeshComponentRef on the SceneNode's entity for ECS-based iteration
62 // This enables efficient querying without iterating all actors
63 if ( sceneNode.has_value() )
64 {
65 auto & registry = Ecs::RegistryManager::get();
66 entt::entity nodeEntity = sceneNode.value()->getEntity();
67 registry.emplace_or_replace<Ecs::MeshComponentRef>( nodeEntity, Ecs::MeshComponentRef{ this } );
68 }
69
70 // Resolve RenderingDataManager if not injected (production path)
71 if ( renderingDataManager_ == nullptr )
72 {
74 if ( engine != nullptr && engine->getRenderer() != nullptr )
75 {
77 }
78 }
79
80 if ( renderingDataManager_ != nullptr )
81 {
82 renderingDataManager_->onRenderableSpawned( this );
83 }
84 }
85
87 {
88 // Unregister MeshComponentRef from the SceneNode's entity
89 if ( sceneNode.has_value() )
90 {
91 auto & registry = Ecs::RegistryManager::get();
92 entt::entity nodeEntity = sceneNode.value()->getEntity();
93 if ( registry.valid( nodeEntity ) && registry.any_of<Ecs::MeshComponentRef>( nodeEntity ) )
94 {
95 registry.remove<Ecs::MeshComponentRef>( nodeEntity );
96 }
97 }
98
99 if ( renderingDataManager_ != nullptr )
100 {
101 renderingDataManager_->onRenderableDestroyed( this );
102 }
103
105 }
106
108 {
109 return visible;
110 }
111
113 {
114 if (staticMeshData == nullptr) throw std::runtime_error("MeshAsset does not exist");
115 return staticMeshData->assetData;
116 }
117
119 {
120 return sceneNode->get()->getWorldMatrix();
121 }
122
124 {
125 return sceneNode->get()->getLocalTransform().matrix;
126 }
127
132} // namespace EngineCore
static entt::registry & get()
Gets the registry for all components.
MeshAsset * getMeshAsset(const Asset::Path &asset)
Get a mesh from the asset manager. If it does not exist it requests the asset from the asset loader.
EngineCore::Engine * getEngineModule()
gets the pointer to the engine object
Definition Engine.cpp:1140
static EngineManager & getInstance()
gets a reference to the engine manager
Definition Engine.cpp:1135
Renderer * getRenderer() const
Getter for the renderer.
Definition Engine.cpp:126
virtual void endPlay()
Called when the component is removed or the game ends.
virtual void beginPlay()
Called when the component is added to the scene or the game starts.
LogicComponent(Scene *owningScene)
The mesh asset stores geometry data and.
Definition MeshAsset.h:15
RenderingDataManager * renderingDataManager_
MeshAsset * getMeshAsset() const
Gets the asset used by this mesh rendering component.
PipelineNames getMaterialNames() const
Gets the material name of this mesh component.
Ecs::StaticMeshData * staticMeshData
std::optional< std::shared_ptr< SceneNode > > sceneNode
void beginPlay() override
Called when the component is added to the scene or the game starts.
bool isVisible() const
If this mesh component should be considered for rendering.
MeshComponent(Scene *owningScene, entt::entity &actor, Asset::Path asset, std::shared_ptr< SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
Production constructor - uses EngineManager singleton to get RenderingDataManager.
glm::mat4 getLocalTransform() const
Gets the local model matrix which isn't affected by its parent.
glm::mat4 getWorldTransform() const
Getter for the world transform of the mesh component.
void endPlay() override
Called when the component is removed or the game ends.
const std::unique_ptr< RenderingDataManager > & getRenderingDataManager() const
Getter for the rendering data manager.
The rendering data manager is supposed to hold all methods to update the contents of the buffers whic...
A scene is the overarching structure which can spawn actors.
Definition Scene.h:17
AssetManager * getAssetManager() const
Gets the asset manager for this scene.
Definition Scene.cpp:53
Log category system implementation.
Is a tag for asset loading. When an asset has been rquested for loading but isnt yet created this tag...
Definition EcsData.h:53
Reference to a MeshComponent for ECS-based iteration. Allows efficient querying of all mesh component...
Definition EcsData.h:138
Stores parent relationships.
Definition EcsData.h:44
entt::entity parent
Definition EcsData.h:45