Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::Mesh Class Reference

A component which can be attached as many times to an actor as one wants. It makes it possible to render a mesh attached to an object. More...

#include <MeshComponent.h>

Inheritance diagram for Engine::Components::Mesh:
Collaboration diagram for Engine::Components::Mesh:

Public Member Functions

 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.
 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.
 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.
 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.
 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.
 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.
 ~Mesh () override=default
 Destroys the mesh component.
void beginPlay () override
 Called when the component is added to the scene or the game starts.
void endPlay () override
 Called when the component is removed or the game ends.
bool drawImGui () override
 Draw the debug UI.
bool isVisible () const
 If this mesh component should be considered for rendering.
void setVisible (bool isVisible)
 Sets whether this mesh component should be rendered.
Assets::MeshAssetRef getMeshAsset () const
 Gets the asset used by this mesh rendering component.
glm::mat4 getWorldTransform () const
 Getter for the world transform of the mesh component.
glm::mat4 getLocalTransform () const
 Gets the local model matrix which isn't affected by its parent.
std::optional< Core::AnchorPoint > anchorPoint (std::string_view name) const
 Looks up an AnchorPoint on this renderable-backed mesh.
std::vector< std::string > anchorPointNames () const
 Lists this renderable's AnchorPoint names.
Rendering::PipelineNames getMaterialNames () const
 Gets the material name of this mesh component.
void setMaterialOverride (Assets::MaterialHandle material)
 Overrides the material used for rendering this mesh.
void clearMaterialOverride ()
 Clears the material override and returns to the mesh material.
std::optional< Assets::MaterialHandle > getMaterialOverride () const
 Gets the current material override.
std::string getAssetName () const
 Gets the asset name of this mesh component (e.g. "rat")
void attachCollisionChild (Collision *collision)
 Records a collision component owned by this mesh.
void attachCollisionChildren (const std::vector< Collision * > &collisions)
 Records multiple collision components owned by this mesh.
void detachCollisionChild (const Collision *collision)
 Removes a collision component from this mesh's child list.
const std::vector< Collision * > & getCollisionChildren () const
 Gets collision components owned by this mesh.
bool ownsCollisionChild (const Logic *component) const
 Checks whether a logic component is one of this mesh's collision children.
virtual void onMeshAssetResolved (Assets::MeshAssetRef meshAsset)
 Called when the mesh asset reference has resolved.
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
 Constructs a logic component owned by a scene.
 Logic (const Entities::SpawnContext &context)
 Constructs a logic component from spawn context data.
virtual ~Logic ()=default
 Destroys the logic component.
virtual std::string getComponentName () const
 Gets the component type name for debugging/UI.
virtual bool drawImGuiName ()
 Used to alter the name of the entity in the outliner.
virtual void tick (double deltaTime)
 Called every frame if ticking is enabled.
bool hasBegunPlay () const
 Checks whether beginPlay() has been called without a matching endPlay().
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::Entity * getOwningEntity () const
 Gets the entity this component belongs to.

Static Public Attributes

static constexpr const char * ComponentName = "Mesh"
 Component type name.
Static Public Attributes inherited from Engine::Components::Logic
static constexpr bool IsUnique = false
 Defines whether multiple instances of this component can exist on the same entity. Defaults to false (multiple allowed). Override in derived classes with static constexpr bool IsUnique = true; if needed.
static constexpr const char * ComponentName = "Logic"
 Fallback component type name. Derived classes may override getComponentName() for custom labels.

Protected Member Functions

std::shared_ptr< Entities::SceneNode > getSceneNode () const
 Gets the scene node used for mesh transforms.
Ecs::StaticMeshData * getStaticMeshData () const
 Gets the ECS static mesh data for derived components.
Protected Member Functions inherited from Engine::Components::Logic
Entities::Scene * getScene () const
 Gets the scene this component belongs to.
Core::SceneManager * getSceneManager () const
 Helper to get the SceneManager from the owning scene.

Protected Attributes

entt::entity componentEntity = entt::null
 ECS entity that stores this mesh component data.
std::optional< std::shared_ptr< Entities::SceneNode > > sceneNode
 Scene node used for transforms.

Private Member Functions

void initializeMeshData (Entities::Scene *owningScene, entt::entity &actor, Asset::MeshPath asset, std::optional< Assets::GltfRenderableHandle > renderable, Assets::GeometryMeshHandle mesh)

Private Attributes

std::string name = "game object"
bool visible = true
Core::RenderingDataManager * renderingDataManager_ = nullptr
std::vector< Collision * > collisionChildren_
std::optional< Assets::MaterialHandle > materialOverride_

Detailed Description

A component which can be attached as many times to an actor as one wants. It makes it possible to render a mesh attached to an object.

Definition at line 46 of file MeshComponent.h.

Constructor & Destructor Documentation

◆ Mesh() [1/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ Mesh() [2/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ Mesh() [3/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ Mesh() [4/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ Mesh() [5/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ Mesh() [6/6]

Engine::Components::Mesh::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.

References sceneNode.

◆ ~Mesh()

Engine::Components::Mesh::~Mesh ( )
overridedefault

Destroys the mesh component.

Member Function Documentation

◆ anchorPoint()

std::optional< Core::AnchorPoint > Engine::Components::Mesh::anchorPoint ( std::string_view name) const
nodiscard

Looks up an AnchorPoint on this renderable-backed mesh.

Parameters
nameAuthored direct-child empty node name.
Returns
AnchorPoint by value, or std::nullopt when this component has no renderable or the name is unknown.

References name.

◆ anchorPointNames()

std::vector< std::string > Engine::Components::Mesh::anchorPointNames ( ) const
nodiscard

Lists this renderable's AnchorPoint names.

Returns
Names sorted lexicographically, or an empty vector when this component has no renderable or AnchorPoints.

◆ attachCollisionChild()

void Engine::Components::Mesh::attachCollisionChild ( Collision * collision)

Records a collision component owned by this mesh.

Parameters
collisionCollision child to attach.

◆ attachCollisionChildren()

void Engine::Components::Mesh::attachCollisionChildren ( const std::vector< Collision * > & collisions)

Records multiple collision components owned by this mesh.

Parameters
collisionsCollision children to attach.

◆ beginPlay()

void Engine::Components::Mesh::beginPlay ( )
overridevirtual

Called when the component is added to the scene or the game starts.

Reimplemented from Engine::Components::Logic.

◆ clearMaterialOverride()

void Engine::Components::Mesh::clearMaterialOverride ( )

Clears the material override and returns to the mesh material.

◆ detachCollisionChild()

void Engine::Components::Mesh::detachCollisionChild ( const Collision * collision)

Removes a collision component from this mesh's child list.

Parameters
collisionCollision child to detach.

◆ drawImGui()

bool Engine::Components::Mesh::drawImGui ( )
overridevirtual

Draw the debug UI.

Reimplemented from Engine::Components::Logic.

◆ endPlay()

void Engine::Components::Mesh::endPlay ( )
overridevirtual

Called when the component is removed or the game ends.

Reimplemented from Engine::Components::Logic.

◆ getAssetName()

std::string Engine::Components::Mesh::getAssetName ( ) const
nodiscard

Gets the asset name of this mesh component (e.g. "rat")

Returns
asset name string, or empty if not available

◆ getCollisionChildren()

const std::vector< Collision * > & Engine::Components::Mesh::getCollisionChildren ( ) const
nodiscard

Gets collision components owned by this mesh.

Returns
Collision child list.

◆ getLocalTransform()

glm::mat4 Engine::Components::Mesh::getLocalTransform ( ) const
nodiscard

Gets the local model matrix which isn't affected by its parent.

Returns
glm local model matrix

◆ getMaterialNames()

Rendering::PipelineNames Engine::Components::Mesh::getMaterialNames ( ) const
nodiscard

Gets the material name of this mesh component.

Returns
name of the material used or defaults ot normals if none is used

◆ getMaterialOverride()

std::optional< Assets::MaterialHandle > Engine::Components::Mesh::getMaterialOverride ( ) const
nodiscard

Gets the current material override.

Returns
Material handle when an override is active.

◆ getMeshAsset()

Assets::MeshAssetRef Engine::Components::Mesh::getMeshAsset ( ) const
nodiscard

Gets the asset used by this mesh rendering component.

Returns
Pointer to the mesh asset used by this mesh renderer

◆ getSceneNode()

std::shared_ptr< Entities::SceneNode > Engine::Components::Mesh::getSceneNode ( ) const
nodiscardprotected

Gets the scene node used for mesh transforms.

Returns
Scene node pointer, or nullptr when none was provided.

◆ getStaticMeshData()

Ecs::StaticMeshData * Engine::Components::Mesh::getStaticMeshData ( ) const
nodiscardprotected

Gets the ECS static mesh data for derived components.

Returns
Static mesh data pointer, or nullptr after teardown.

◆ getWorldTransform()

glm::mat4 Engine::Components::Mesh::getWorldTransform ( ) const
nodiscard

Getter for the world transform of the mesh component.

Returns
model matrix which is affected by the scene graph hierarchy

◆ initializeMeshData()

void Engine::Components::Mesh::initializeMeshData ( Entities::Scene * owningScene,
entt::entity & actor,
Asset::MeshPath asset,
std::optional< Assets::GltfRenderableHandle > renderable,
Assets::GeometryMeshHandle mesh )
private

◆ isVisible()

bool Engine::Components::Mesh::isVisible ( ) const
nodiscard

If this mesh component should be considered for rendering.

Returns
visible = true

Referenced by setVisible().

Here is the caller graph for this function:

◆ onMeshAssetResolved()

virtual void Engine::Components::Mesh::onMeshAssetResolved ( Assets::MeshAssetRef meshAsset)
virtual

Called when the mesh asset reference has resolved.

Parameters
meshAssetResolved mesh asset reference.

Reimplemented in Engine::Components::CollidableMesh.

◆ ownsCollisionChild()

bool Engine::Components::Mesh::ownsCollisionChild ( const Logic * component) const
nodiscard

Checks whether a logic component is one of this mesh's collision children.

Parameters
componentComponent to test.
Returns
True when the component is an attached collision child.

References Engine::Components::Logic::Logic().

Here is the call graph for this function:

◆ setMaterialOverride()

void Engine::Components::Mesh::setMaterialOverride ( Assets::MaterialHandle material)

Overrides the material used for rendering this mesh.

Parameters
materialMaterial handle to apply.

◆ setVisible()

void Engine::Components::Mesh::setVisible ( bool isVisible)

Sets whether this mesh component should be rendered.

References isVisible().

Here is the call graph for this function:

Member Data Documentation

◆ collisionChildren_

std::vector<Collision *> Engine::Components::Mesh::collisionChildren_
private

Definition at line 277 of file MeshComponent.h.

◆ componentEntity

entt::entity Engine::Components::Mesh::componentEntity = entt::null
protected

ECS entity that stores this mesh component data.

Definition at line 264 of file MeshComponent.h.

◆ ComponentName

const char* Engine::Components::Mesh::ComponentName = "Mesh"
staticconstexpr

Component type name.

Definition at line 49 of file MeshComponent.h.

◆ materialOverride_

std::optional<Assets::MaterialHandle> Engine::Components::Mesh::materialOverride_
private

Definition at line 278 of file MeshComponent.h.

◆ name

std::string Engine::Components::Mesh::name = "game object"
private

Definition at line 52 of file MeshComponent.h.

Referenced by anchorPoint().

◆ renderingDataManager_

Core::RenderingDataManager* Engine::Components::Mesh::renderingDataManager_ = nullptr
private

Definition at line 276 of file MeshComponent.h.

◆ sceneNode

◆ visible

bool Engine::Components::Mesh::visible = true
private

Definition at line 53 of file MeshComponent.h.


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Component/MeshComponent.h