Vulkan Schnee 0.0.1 (22840dc8)
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")
 Constructs a collidable mesh from a glTF renderable handle using the engine rendering data manager.
 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")
 Constructs a collidable mesh from a geometry mesh handle using the engine rendering data manager.
 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")
 Constructs a collidable mesh from a glTF renderable handle with an explicit rendering data manager.
 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")
 Constructs a collidable mesh from a geometry mesh handle with an explicit rendering data manager.
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 markCollisionPropertiesResolved ()
 Marks authored collision metadata as already inspected for this mesh.
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")
 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.
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 = "CollidableMesh"
 Component registry name.
Static Public Attributes inherited from Engine::Components::Mesh
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.

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< CollisionProperties > collisionProperties_
std::vector< Collision * > ownedCollisionChildren_
bool collisionRequested_ = false
bool collisionPropertiesResolved_ = false
bool collisionStatic_ = false

Additional Inherited Members

Protected Member Functions inherited from Engine::Components::Mesh
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 inherited from Engine::Components::Mesh
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.

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" )

Constructs a collidable mesh from a glTF renderable handle using the engine rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
renderableRenderable handle to render.
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() [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" )

Constructs a collidable mesh from a geometry mesh handle using the engine rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
meshGeometry mesh handle to render.
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() [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" )

Constructs a collidable mesh from a glTF renderable handle with an explicit rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
renderableRenderable handle to render.
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() [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" )

Constructs a collidable mesh from a geometry mesh handle with an explicit rendering data manager.

Parameters
owningSceneScene that owns the actor and component.
actorECS entity associated with the owning actor.
meshGeometry mesh handle to render.
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.

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.

◆ markCollisionPropertiesResolved()

void Engine::Components::CollidableMesh::markCollisionPropertiesResolved ( )

Marks authored collision metadata as already inspected for this mesh.

Used by GLTF spawning when the node extension was parsed as part of the spawn plan. This keeps fallback collision generation from reparsing the whole GLTF file for every spawned mesh node.

◆ 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 236 of file CollidableMeshComponent.h.

◆ collisionPropertiesResolved_

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

Definition at line 239 of file CollidableMeshComponent.h.

◆ collisionRequested_

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

Definition at line 238 of file CollidableMeshComponent.h.

◆ collisionStatic_

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

Definition at line 240 of file CollidableMeshComponent.h.

◆ ComponentName

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

Component registry name.

Definition at line 23 of file CollidableMeshComponent.h.

◆ ownedCollisionChildren_

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

Definition at line 237 of file CollidableMeshComponent.h.


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