Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::CollidableMesh Class Reference

Mesh component that can create and own collision shapes for its actor. More...

#include <CollidableMeshComponent.h>

Inheritance diagram for Engine::Components::CollidableMesh:
Collaboration diagram for Engine::Components::CollidableMesh:

Public Member Functions

 CollidableMesh (Entities::Scene *owningScene, entt::entity &actor, Asset::MeshPath asset, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
 Constructs a collidable mesh using the engine rendering data manager.
 CollidableMesh (Entities::Scene *owningScene, entt::entity &actor, Assets::GltfRenderableHandle renderable, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
 CollidableMesh (Entities::Scene *owningScene, entt::entity &actor, Assets::GeometryMeshHandle mesh, std::shared_ptr< Entities::SceneNode > sceneNode, bool isVisible_=true, const std::string &name_="game object")
 CollidableMesh (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")
 Constructs a collidable mesh with an explicit rendering data manager.
 CollidableMesh (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")
 CollidableMesh (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 endPlay () override
 Removes collision owned by this component, then ends mesh playback.
void enableCollision (bool enabled)
 Enables or disables generated collision for this mesh.
bool isCollisionEnabled () const
 Returns whether collision generation has been requested.
void setCollisionProperties (const Assets::Loaders::GltfLoader::VulkanSchneeExtension::CollisionProperties &properties)
 Sets imported collision properties used to build collision components.
void clearCollisionProperties ()
 Clears imported collision properties and falls back to mesh bounds when collision is enabled.
void setCollisionStatic (bool isStatic)
 Sets whether the generated PhysicsBody should be static.
void onMeshAssetResolved (Assets::MeshAssetRef meshAsset) override
 Handles mesh asset resolution and builds deferred fallback collision when requested.
Public Member Functions inherited from 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.
 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")
 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")
 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")
 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")
 ~Mesh () override=default
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.
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.
Rendering::PipelineNames getMaterialNames () const
 Gets the material name of this mesh component.
void setMaterialOverride (Assets::MaterialHandle material)
void clearMaterialOverride ()
std::optional< Assets::MaterialHandlegetMaterialOverride () const
std::string getAssetName () const
 Gets the asset name of this mesh component (e.g. "rat")
void attachCollisionChild (Collision *collision)
void attachCollisionChildren (const std::vector< Collision * > &collisions)
void detachCollisionChild (const Collision *collision)
const std::vector< Collision * > & getCollisionChildren () const
bool ownsCollisionChild (const Logic *component) const
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
 Logic (const Entities::SpawnContext &context)
virtual ~Logic ()=default
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
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::EntitygetOwningEntity () const
 Gets the entity this component belongs to.

Static Public Attributes

static constexpr const char * ComponentName = "CollidableMesh"
Static Public Attributes inherited from Engine::Components::Mesh
static constexpr const char * ComponentName = "Mesh"
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.

Private Types

using CollisionProperties = Assets::Loaders::GltfLoader::VulkanSchneeExtension::CollisionProperties

Private Member Functions

void rebuildOwnedCollision ()
 Rebuilds all collision owned by this component from imported properties or fallback bounds.
void loadCollisionPropertiesFromAsset ()
 Loads authored glTF collision properties for this mesh asset when available.
bool createCollisionFromProperties ()
 Creates collision components from imported glTF collision properties.
bool createFallbackBoxCollision ()
 Creates a BoxCollision from the resolved mesh asset's local vertex bounds.
void ensurePhysicsBody ()
 Adds a PhysicsBody to the owning actor if needed and applies the static flag.
void removeOwnedCollision ()
 Removes collision components created and owned by this component.

Private Attributes

std::optional< CollisionPropertiescollisionProperties_
std::vector< Collision * > ownedCollisionChildren_
bool collisionRequested_ = false
bool collisionStatic_ = false

Additional Inherited Members

Protected Member Functions inherited from Engine::Components::Mesh
std::shared_ptr< Entities::SceneNodegetSceneNode () const
Ecs::StaticMeshDatagetStaticMeshData () const
Protected Member Functions inherited from Engine::Components::Logic
Entities::ScenegetScene () const
 Gets the scene this component belongs to.
Core::SceneManagergetSceneManager () const
 Helper to get the SceneManager from the owning scene.
Protected Attributes inherited from Engine::Components::Mesh
entt::entity componentEntity = entt::null
std::optional< std::shared_ptr< Entities::SceneNode > > sceneNode
Ecs::StaticMeshDatastaticMeshData = nullptr

Detailed Description

Mesh component that can create and own collision shapes for its actor.

CollidableMesh renders the same mesh data as Engine::Components::Mesh and can optionally add collision components to the owning actor. Imported collision properties are used when available; otherwise the component builds a fallback box from the resolved mesh's local vertex bounds.

Enabling collision also ensures that the owning actor has a PhysicsBody component. Collision created by this component is removed when collision is disabled or when the component ends play.

Definition at line 20 of file CollidableMeshComponent.h.

Member Typedef Documentation

◆ CollisionProperties

Constructor & Destructor Documentation

◆ CollidableMesh() [1/6]

Engine::Components::CollidableMesh::CollidableMesh ( Entities::Scene * owningScene,
entt::entity & actor,
Asset::MeshPath asset,
std::shared_ptr< Entities::SceneNode > sceneNode,
bool isVisible_ = true,
const std::string & name_ = "game object" )

Constructs a collidable mesh using the engine rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
assetMesh asset path to render and use for fallback collision bounds.
sceneNodeScene graph node used for the mesh transform and generated PhysicsBody.
isVisible_True when the mesh should be submitted for rendering.
name_Display name for the mesh component.

References Engine::Components::Mesh::sceneNode.

◆ CollidableMesh() [2/6]

Engine::Components::CollidableMesh::CollidableMesh ( Entities::Scene * owningScene,
entt::entity & actor,
Assets::GltfRenderableHandle renderable,
std::shared_ptr< Entities::SceneNode > sceneNode,
bool isVisible_ = true,
const std::string & name_ = "game object" )

◆ CollidableMesh() [3/6]

Engine::Components::CollidableMesh::CollidableMesh ( Entities::Scene * owningScene,
entt::entity & actor,
Assets::GeometryMeshHandle mesh,
std::shared_ptr< Entities::SceneNode > sceneNode,
bool isVisible_ = true,
const std::string & name_ = "game object" )

◆ CollidableMesh() [4/6]

Engine::Components::CollidableMesh::CollidableMesh ( 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" )

Constructs a collidable mesh with an explicit rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
assetMesh asset path to render and use for fallback collision bounds.
sceneNodeScene graph node used for the mesh transform and generated PhysicsBody.
renderingDataManagerRendering data manager used by the base Mesh component.
isVisible_True when the mesh should be submitted for rendering.
name_Display name for the mesh component.

References Engine::Components::Mesh::sceneNode.

◆ CollidableMesh() [5/6]

Engine::Components::CollidableMesh::CollidableMesh ( 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" )

◆ CollidableMesh() [6/6]

Engine::Components::CollidableMesh::CollidableMesh ( 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" )

Member Function Documentation

◆ clearCollisionProperties()

void Engine::Components::CollidableMesh::clearCollisionProperties ( )

Clears imported collision properties and falls back to mesh bounds when collision is enabled.

◆ createCollisionFromProperties()

bool Engine::Components::CollidableMesh::createCollisionFromProperties ( )
private

Creates collision components from imported glTF collision properties.

Returns
True when at least one collision component was created.

◆ createFallbackBoxCollision()

bool Engine::Components::CollidableMesh::createFallbackBoxCollision ( )
private

Creates a BoxCollision from the resolved mesh asset's local vertex bounds.

Returns
True when a fallback collision component was created.

◆ enableCollision()

void Engine::Components::CollidableMesh::enableCollision ( bool enabled)

Enables or disables generated collision for this mesh.

Parameters
enabledTrue to create collision, false to remove collision owned by this component.

Enabling collision uses imported collision properties first. If no usable imported collision exists, the component creates a fallback BoxCollision from the mesh asset's local-space bounds after the asset is available.

◆ endPlay()

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

Removes collision owned by this component, then ends mesh playback.

Reimplemented from Engine::Components::Logic.

◆ ensurePhysicsBody()

void Engine::Components::CollidableMesh::ensurePhysicsBody ( )
private

Adds a PhysicsBody to the owning actor if needed and applies the static flag.

◆ isCollisionEnabled()

bool Engine::Components::CollidableMesh::isCollisionEnabled ( ) const
nodiscard

Returns whether collision generation has been requested.

Returns
True after enableCollision(true), false after enableCollision(false).

This reports the requested state, not whether collision components currently exist. Collision can be requested before the mesh asset has resolved.

◆ loadCollisionPropertiesFromAsset()

void Engine::Components::CollidableMesh::loadCollisionPropertiesFromAsset ( )
private

Loads authored glTF collision properties for this mesh asset when available.

◆ onMeshAssetResolved()

void Engine::Components::CollidableMesh::onMeshAssetResolved ( Assets::MeshAssetRef meshAsset)
overridevirtual

Handles mesh asset resolution and builds deferred fallback collision when requested.

Parameters
meshAssetResolved mesh asset passed through to Mesh::onMeshAssetResolved().

Reimplemented from Engine::Components::Mesh.

◆ rebuildOwnedCollision()

void Engine::Components::CollidableMesh::rebuildOwnedCollision ( )
private

Rebuilds all collision owned by this component from imported properties or fallback bounds.

◆ removeOwnedCollision()

void Engine::Components::CollidableMesh::removeOwnedCollision ( )
private

Removes collision components created and owned by this component.

◆ setCollisionProperties()

void Engine::Components::CollidableMesh::setCollisionProperties ( const Assets::Loaders::GltfLoader::VulkanSchneeExtension::CollisionProperties & properties)

Sets imported collision properties used to build collision components.

Parameters
propertiesCollision shape data parsed from the VulkanSchnee glTF extension.

If collision is already enabled, existing collision owned by this component is rebuilt immediately.

◆ setCollisionStatic()

void Engine::Components::CollidableMesh::setCollisionStatic ( bool isStatic)

Sets whether the generated PhysicsBody should be static.

Parameters
isStaticTrue for a static rigid body, false for a dynamic rigid body.

The value is applied to an existing PhysicsBody immediately and to any PhysicsBody created later by enableCollision(true).

Member Data Documentation

◆ collisionProperties_

std::optional<CollisionProperties> Engine::Components::CollidableMesh::collisionProperties_
private

Definition at line 190 of file CollidableMeshComponent.h.

◆ collisionRequested_

bool Engine::Components::CollidableMesh::collisionRequested_ = false
private

Definition at line 192 of file CollidableMeshComponent.h.

◆ collisionStatic_

bool Engine::Components::CollidableMesh::collisionStatic_ = false
private

Definition at line 193 of file CollidableMeshComponent.h.

◆ ComponentName

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

Definition at line 23 of file CollidableMeshComponent.h.

◆ ownedCollisionChildren_

std::vector<Collision *> Engine::Components::CollidableMesh::ownedCollisionChildren_
private

Definition at line 191 of file CollidableMeshComponent.h.


The documentation for this class was generated from the following file: