VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
visutwin::canvas::Entity Class Reference

ECS entity — a GraphNode that hosts components defining its behavior. More...

#include <framework/entity.h>

Inheritance diagram for visutwin::canvas::Entity:
[legend]

Public Member Functions

template<class ComponentType>
ComponentaddComponent ()
ComponentaddComponentInstance (std::unique_ptr< Component > component, ComponentTypeID typeId)
Entityclone () const
const std::unordered_map< ComponentTypeID, Component * > & components () const
Engineengine () const
template<class T>
T * findComponent ()
template<class T>
std::vector< T * > findComponents ()
EnginefindEngine () const
void onHierarchyStateChanged (bool enabled) override
ScriptComponentscript () const
void setEngine (Engine *engine)
virtual ~Entity ()
Public Member Functions inherited from visutwin::canvas::GraphNode
int aabbVer () const
void addChild (GraphNode *node)
const std::vector< GraphNode * > & children () const
bool enabled () const
bool enabledLocal () const
std::vector< GraphNode * > find (const std::function< bool(GraphNode *)> &predicate)
 Find all descendants (and self) matching a predicate.
GraphNodefindByName (const std::string &name)
 GraphNode (const std::string &name="Untitled")
bool isDescendantOf (const GraphNode *node) const
const Vector3localPosition () const
const QuaternionlocalRotation () const
const Vector3localScale () const
const std::string & name () const
GraphNodeparent () const
const Vector3 position ()
void remove ()
void removeChild (GraphNode *child)
void rotateLocal (float x, float y, float z)
Quaternion rotation ()
void setEnabled (bool value)
void setEnabledInHierarchy (bool value)
void setLocalEulerAngles (float x, float y, float z)
void setLocalPosition (const Vector3 &position)
void setLocalPosition (float x, float y, float z)
void setLocalRotation (const Quaternion &rotation)
void setLocalScale (const Vector3 &scale)
void setLocalScale (float x, float y, float z)
void setName (const std::string &name)
void setPosition (const Vector3 &position)
void setPosition (float x, float y, float z)
void setRotation (const Quaternion &rotation)
void translateLocal (float x, float y, float z)
float worldScaleSign ()
const Matrix4worldTransform ()
virtual ~GraphNode ()
Public Member Functions inherited from visutwin::canvas::EventHandler
template<typename... Args>
EventHandlerfire (const std::string &name, Args &&... args)
bool hasEvent (const std::string &name) const
void initEventHandler ()
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleroff (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleroff (const std::string &name="", const HandleEventCallback &callback=HandleEventCallback(), void *scope=nullptr)
EventHandleroffByHandle (EventHandle *handle)
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleon (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleon (const std::string &name, HandleEventCallback callback, void *scope=nullptr)
template<typename Callback>
requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>)
EventHandleonce (const std::string &name, Callback &&callback, void *scope=nullptr)
EventHandleonce (const std::string &name, HandleEventCallback callback, void *scope=nullptr)
virtual ~EventHandler ()=default

Additional Inherited Members

Protected Member Functions inherited from visutwin::canvas::GraphNode
void notifyHierarchyStateChanged (GraphNode *node, bool enabled)
Protected Member Functions inherited from visutwin::canvas::EventHandler
EventHandleaddCallback (const std::string &name, HandleEventCallback callback, void *scope=nullptr, bool once=false)

Detailed Description

ECS entity — a GraphNode that hosts components defining its behavior.

Entities form the leaves of the scene graph. Functionality is added by attaching Component instances (Camera, Render, Light, Script, etc.) via addComponent<T>(). Component lookup is O(1) through an internal type-ID map.

Definition at line 31 of file entity.h.

Constructor & Destructor Documentation

◆ ~Entity()

visutwin::canvas::Entity::~Entity ( )
virtual

Definition at line 13 of file entity.cpp.

Member Function Documentation

◆ addComponent()

template<class ComponentType>
Component * visutwin::canvas::Entity::addComponent ( )
inline

Definition at line 57 of file entity.h.

References visutwin::canvas::componentTypeID().

◆ addComponentInstance()

Component * visutwin::canvas::Entity::addComponentInstance ( std::unique_ptr< Component > component,
ComponentTypeID typeId )
inline

Definition at line 36 of file entity.h.

References visutwin::canvas::componentTypeID().

◆ clone()

Entity * visutwin::canvas::Entity::clone ( ) const

Create a deep clone of the entity. Creates a new entity with the same transform, components, and children hierarchy. Component data is cloned via Component::cloneFrom(). The clone is NOT automatically added to any parent.

/ _cloneRecursively().

Definition at line 56 of file entity.cpp.

References visutwin::canvas::GraphNode::children(), visutwin::canvas::componentTypeID(), visutwin::canvas::GraphNode::enabledLocal(), engine(), findEngine(), visutwin::canvas::GraphNode::localPosition(), visutwin::canvas::GraphNode::localRotation(), visutwin::canvas::GraphNode::localScale(), and visutwin::canvas::GraphNode::name().

◆ components()

const std::unordered_map< ComponentTypeID, Component * > & visutwin::canvas::Entity::components ( ) const
inline

Access the component type map (for iteration during clone).

Definition at line 145 of file entity.h.

◆ engine()

Engine * visutwin::canvas::Entity::engine ( ) const
inline

◆ findComponent()

template<class T>
T * visutwin::canvas::Entity::findComponent ( )
inline

Get the component of the specified type from this entity. Returns nullptr if the entity does not have a component of that type.

Definition at line 95 of file entity.h.

References visutwin::canvas::componentTypeID().

Referenced by visutwin::canvas::RigidBodyComponent::collision(), and visutwin::canvas::ElementInput::handleMouseButtonDown().

◆ findComponents()

template<class T>
std::vector< T * > visutwin::canvas::Entity::findComponents ( )
inline

Search the entity and all of its descendants for all components of specified type.

Definition at line 109 of file entity.h.

References visutwin::canvas::componentTypeID().

◆ findEngine()

Engine * visutwin::canvas::Entity::findEngine ( ) const

Find the Engine reference by walking up the hierarchy. Entities created by parsers (e.g., GLB) may not have _engine set directly, but their ancestor (typically the root) does.

Definition at line 40 of file entity.cpp.

References visutwin::canvas::GraphNode::parent().

Referenced by clone().

◆ onHierarchyStateChanged()

void visutwin::canvas::Entity::onHierarchyStateChanged ( bool enabled)
overridevirtual

Called when the entity's enabled-in-hierarchy state changes. Propagates onEnable/onDisable to components.

Reimplemented from visutwin::canvas::GraphNode.

Definition at line 18 of file entity.cpp.

References visutwin::canvas::GraphNode::enabled(), and visutwin::canvas::GraphNode::onHierarchyStateChanged().

◆ script()

ScriptComponent * visutwin::canvas::Entity::script ( ) const
inline

Definition at line 121 of file entity.h.

◆ setEngine()

void visutwin::canvas::Entity::setEngine ( Engine * engine)
inline

Definition at line 124 of file entity.h.

References engine().


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