|
VisuTwin Canvas
C++ 3D Engine — Metal Backend
|
ECS entity — a GraphNode that hosts components defining its behavior. More...
#include <framework/entity.h>
Public Member Functions | |
| template<class ComponentType> | |
| Component * | addComponent () |
| Component * | addComponentInstance (std::unique_ptr< Component > component, ComponentTypeID typeId) |
| Entity * | clone () const |
| const std::unordered_map< ComponentTypeID, Component * > & | components () const |
| Engine * | engine () const |
| template<class T> | |
| T * | findComponent () |
| template<class T> | |
| std::vector< T * > | findComponents () |
| Engine * | findEngine () const |
| void | onHierarchyStateChanged (bool enabled) override |
| ScriptComponent * | script () 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. | |
| GraphNode * | findByName (const std::string &name) |
| GraphNode (const std::string &name="Untitled") | |
| bool | isDescendantOf (const GraphNode *node) const |
| const Vector3 & | localPosition () const |
| const Quaternion & | localRotation () const |
| const Vector3 & | localScale () const |
| const std::string & | name () const |
| GraphNode * | parent () 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 Matrix4 & | worldTransform () |
| virtual | ~GraphNode () |
| Public Member Functions inherited from visutwin::canvas::EventHandler | |
| template<typename... Args> | |
| EventHandler * | fire (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>) | |
| EventHandler * | off (const std::string &name, Callback &&callback, void *scope=nullptr) |
| EventHandler * | off (const std::string &name="", const HandleEventCallback &callback=HandleEventCallback(), void *scope=nullptr) |
| EventHandler * | offByHandle (EventHandle *handle) |
| template<typename Callback> requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>) | |
| EventHandle * | on (const std::string &name, Callback &&callback, void *scope=nullptr) |
| EventHandle * | on (const std::string &name, HandleEventCallback callback, void *scope=nullptr) |
| template<typename Callback> requires (!std::is_same_v<std::decay_t<Callback>, HandleEventCallback>) | |
| EventHandle * | once (const std::string &name, Callback &&callback, void *scope=nullptr) |
| EventHandle * | once (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 | |
| EventHandle * | addCallback (const std::string &name, HandleEventCallback callback, void *scope=nullptr, bool once=false) |
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.
|
virtual |
Definition at line 13 of file entity.cpp.
|
inline |
Definition at line 57 of file entity.h.
References visutwin::canvas::componentTypeID().
|
inline |
Definition at line 36 of file entity.h.
References visutwin::canvas::componentTypeID().
| 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().
|
inline |
|
inline |
Definition at line 123 of file entity.h.
Referenced by visutwin::canvas::Annotation::activate(), clone(), visutwin::canvas::AnnotationManager::initialize(), and setEngine().
|
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().
|
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().
| 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().
|
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().
|
inline |
|
inline |