|
Monad Engine da02fba2
> Undercity Codex_
|
Node in the scene graph: a named transform that owns components and children. More...
#include <GameObject.h>
Public Member Functions | |
| virtual | ~GameObject ()=default |
| virtual void | LoadProperties (const nlohmann::json &json) |
| virtual void | Init () |
| virtual void | Update (f32 deltaTime) |
| Update this object and all its components and children recursively. | |
| const str & | GetName () const |
| Returns the object's display name. | |
| void | SetName (const str &name) |
| Sets the display name (used by FindChildByName). | |
| GameObject * | GetParent () |
| Returns the parent node, or nullptr for root objects. | |
| bool | IsAlive () const |
| Returns false after MarkForDestroy() is called. | |
| void | MarkForDestroy () |
| Flag this object for removal at end of frame. | |
| void | AddComponent (Component *component) |
| Attach a component to this object (takes ownership). | |
| template<typename T , typename = typename std::enable_if_t<std::is_base_of_v<Component, T>>> | |
| T * | GetComponent () |
| Find and return the first component of type T attached to this object. | |
| bool | SetParent (GameObject *parent) |
| Re-parent this object in the scene hierarchy. | |
| Scene * | GetScene () |
| Returns the Scene that owns this object. | |
| void | SetActive (bool active) |
| Show/hide this object (and stop Update calls). | |
| bool | IsActive () const |
| Returns false if the object is hidden. | |
| void | SetWorldPosition (const vec3 &pos) |
| quat | GetWorldRotation () |
| void | SetWorldRotation (const quat &rot) |
| GameObject * | FindChildByName (const std::string &name) |
| Depth-first search for a child with the given name. | |
| const std::vector< std::unique_ptr< GameObject > > & | GetChildren () const |
| Editor access: iterate immediate children (non-owning). | |
| const std::vector< std::unique_ptr< Component > > & | GetComponents () const |
| Editor access: iterate attached components (non-owning). | |
Local Transform | |
Position, rotation, and scale are all relative to the parent object. | |
| const vec3 & | GetPosition () const |
| void | SetPosition (const vec3 &pos) |
| void | SetRotation (const quat &rot) |
| const quat & | GetRotation () const |
| const vec3 & | GetScale () const |
| void | SetScale (const vec3 &scale) |
World-Space Queries | |
| mat4 | GetLocalTransform () const |
| Compute the local transform matrix (TRS order). | |
| mat4 | GetWorldTransform () const |
| Compute the world transform by walking up the parent chain. | |
| vec3 | GetWorldPosition () const |
| Extract the world-space position from GetWorldTransform(). | |
Static Public Member Functions | |
| static GameObject * | LoadGLTF (const std::string &path, Scene *scene) |
| Load a GLTF / GLB file and build a matching GameObject hierarchy. | |
Protected Member Functions | |
| GameObject ()=default | |
Friends | |
| class | Scene |
Node in the scene graph: a named transform that owns components and children.
GameObjects are created and owned exclusively by Scene (via Scene::CreateObject). They are never constructed directly to ensure the scene always holds ownership.
Definition at line 90 of file GameObject.h.
|
virtualdefault |
|
protecteddefault |
| void mnd::GameObject::AddComponent | ( | Component * | component | ) |
Attach a component to this object (takes ownership).
| component | Heap-allocated Component subclass. The GameObject owns it. |
Definition at line 100 of file GameObject.cpp.
References mnd::Component::Init(), LOG_ERROR, LOG_INFO, and mnd::Component::m_owner.
| GameObject * mnd::GameObject::FindChildByName | ( | const std::string & | name | ) |
Depth-first search for a child with the given name.
| name | Exact name to search for (case-sensitive). |
Definition at line 624 of file GameObject.cpp.
|
inline |
Editor access: iterate immediate children (non-owning).
Definition at line 210 of file GameObject.h.
|
inline |
Find and return the first component of type T attached to this object.
| T | A Component subclass decorated with the COMPONENT macro. |
Definition at line 125 of file GameObject.h.
References mnd::T.
|
inline |
Editor access: iterate attached components (non-owning).
Definition at line 213 of file GameObject.h.
| mat4 mnd::GameObject::GetLocalTransform | ( | ) | const |
Compute the local transform matrix (TRS order).
Definition at line 149 of file GameObject.cpp.
Referenced by GetWorldTransform().
| const str & mnd::GameObject::GetName | ( | ) | const |
Returns the object's display name.
Definition at line 574 of file GameObject.cpp.
Referenced by mnd::Scene::CreateObject(), mnd::Scene::SetParent(), and mnd::MeshComponent::Update().
| GameObject * mnd::GameObject::GetParent | ( | ) |
Returns the parent node, or nullptr for root objects.
Definition at line 598 of file GameObject.cpp.
Referenced by mnd::CameraComponent::GetViewMatrix(), and mnd::Scene::SetParent().
| const vec3 & mnd::GameObject::GetPosition | ( | ) | const |
Definition at line 113 of file GameObject.cpp.
Referenced by mnd::CameraComponent::GetViewMatrix(), and mnd::InspectTransform().
| const quat & mnd::GameObject::GetRotation | ( | ) | const |
Definition at line 123 of file GameObject.cpp.
Referenced by mnd::CameraComponent::GetViewMatrix(), mnd::InspectTransform(), and mnd::PlayerControllerComponent::Update().
| const vec3 & mnd::GameObject::GetScale | ( | ) | const |
Definition at line 133 of file GameObject.cpp.
Referenced by mnd::InspectTransform().
| Scene * mnd::GameObject::GetScene | ( | ) |
Returns the Scene that owns this object.
Definition at line 593 of file GameObject.cpp.
Referenced by mnd::ParseGLTFNode().
| vec3 mnd::GameObject::GetWorldPosition | ( | ) | const |
Extract the world-space position from GetWorldTransform().
Definition at line 143 of file GameObject.cpp.
References GetWorldTransform().
Referenced by mnd::PhysicsComponent::Init(), mnd::PlayerControllerComponent::Init(), mnd::AudioComponent::Update(), and mnd::AudioListenerComponent::Update().
| quat mnd::GameObject::GetWorldRotation | ( | ) |
Definition at line 207 of file GameObject.cpp.
References GetWorldRotation().
Referenced by GetWorldRotation(), mnd::PhysicsComponent::Init(), and SetWorldRotation().
| mat4 mnd::GameObject::GetWorldTransform | ( | ) | const |
Compute the world transform by walking up the parent chain.
Definition at line 168 of file GameObject.cpp.
References GetLocalTransform(), and GetWorldTransform().
Referenced by mnd::CameraComponent::GetViewMatrix(), GetWorldPosition(), GetWorldTransform(), SetWorldPosition(), mnd::MeshComponent::Update(), and mnd::SkinnedMeshComponent::Update().
|
inlinevirtual |
Definition at line 97 of file GameObject.h.
| bool mnd::GameObject::IsActive | ( | ) | const |
Returns false if the object is hidden.
Definition at line 619 of file GameObject.cpp.
| bool mnd::GameObject::IsAlive | ( | ) | const |
Returns false after MarkForDestroy() is called.
Definition at line 603 of file GameObject.cpp.
|
static |
Load a GLTF / GLB file and build a matching GameObject hierarchy.
Each GLTF node becomes a child GameObject. Meshes get a MeshComponent, animations get an AnimationComponent attached to the root.
| path | Filesystem path to the .gltf or .glb file. |
Definition at line 426 of file GameObject.cpp.
References mnd::Scene::CreateObject(), mnd::FileSystem::GetAssetsFolder(), mnd::Engine::GetFileSystem(), mnd::Engine::GetInstance(), mnd::FileSystem::LoadAssetFileText(), LOG_ERROR, mnd::ParseGLTFNode(), mnd::ReadOutputQuat, mnd::ReadOutputVec3, mnd::ReadTimes, and mnd::TransformTrack::targetName.
|
inlinevirtual |
Definition at line 95 of file GameObject.h.
| void mnd::GameObject::MarkForDestroy | ( | ) |
Flag this object for removal at end of frame.
Definition at line 608 of file GameObject.cpp.
References LOG_INFO.
Referenced by mnd::HealthComponent::ApplyDamage().
| void mnd::GameObject::SetActive | ( | bool | active | ) |
Show/hide this object (and stop Update calls).
Definition at line 614 of file GameObject.cpp.
| void mnd::GameObject::SetName | ( | const str & | name | ) |
Sets the display name (used by FindChildByName).
Definition at line 579 of file GameObject.cpp.
Referenced by mnd::Scene::CreateObject(), and mnd::Scene::CreateObject().
| bool mnd::GameObject::SetParent | ( | GameObject * | parent | ) |
Re-parent this object in the scene hierarchy.
| parent | New parent node, or nullptr to make this a root object. |
Definition at line 584 of file GameObject.cpp.
References mnd::Scene::SetParent().
| void mnd::GameObject::SetPosition | ( | const vec3 & | pos | ) |
Definition at line 118 of file GameObject.cpp.
Referenced by mnd::InspectTransform(), SetWorldPosition(), and mnd::PlayerControllerComponent::Update().
| void mnd::GameObject::SetRotation | ( | const quat & | rot | ) |
Definition at line 128 of file GameObject.cpp.
Referenced by mnd::InspectTransform(), SetWorldRotation(), and mnd::PlayerControllerComponent::Update().
| void mnd::GameObject::SetScale | ( | const vec3 & | scale | ) |
Definition at line 138 of file GameObject.cpp.
Referenced by mnd::InspectTransform().
| void mnd::GameObject::SetWorldPosition | ( | const vec3 & | pos | ) |
Definition at line 179 of file GameObject.cpp.
References GetWorldTransform(), and SetPosition().
Referenced by mnd::PhysicsComponent::Update().
| void mnd::GameObject::SetWorldRotation | ( | const quat & | rot | ) |
Definition at line 193 of file GameObject.cpp.
References GetWorldRotation(), and SetRotation().
Referenced by mnd::PhysicsComponent::Update().
|
virtual |
Update this object and all its components and children recursively.
| deltaTime | Seconds since the previous frame. |
Definition at line 75 of file GameObject.cpp.
|
friend |
Definition at line 232 of file GameObject.h.