1#include <Engine/Scene/Component.hpp>
3#include <Core/Math/LinearAlgebra.hpp>
4#include <Core/Utils/Log.hpp>
5#include <Engine/Data/Mesh.hpp>
6#include <Engine/RadiumEngine.hpp>
7#include <Engine/Rendering/RenderObject.hpp>
8#include <Engine/Rendering/RenderObjectManager.hpp>
9#include <Engine/Scene/ComponentMessenger.hpp>
10#include <Engine/Scene/Entity.hpp>
11#include <Engine/Scene/SignalManager.hpp>
12#include <Engine/Scene/System.hpp>
18using namespace Core::Utils;
21 m_name { name }, m_entity { entity } {
26 for (
const auto& ro : m_renderObjects ) {
27 getRoMgr()->removeRenderObject( ro );
30 auto cm = ComponentMessenger::getInstance();
33 RadiumEngine::getInstance()->getSignalManager()->fireComponentRemoved(
38 return RadiumEngine::getInstance()->getRenderObjectManager();
44 return m_renderObjects.
back();
49 CORE_WARN_IF( found == m_renderObjects.
cend(),
" Render object not found in component" );
50 if ( ( found != m_renderObjects.
cend() ) &&
getRoMgr() ) {
51 getRoMgr()->removeRenderObject( *found );
52 m_renderObjects.
erase( found );
57void Component::notifyRenderObjectExpired(
const Core::Utils::Index& idx ) {
59 CORE_WARN_IF( found == m_renderObjects.
cend(),
" Render object not found in component" );
60 if ( found != m_renderObjects.
cend() ) { m_renderObjects.
erase( found ); }
63Core::Aabb Component::computeAabb() {
64 if ( !m_isAabbValid ) {
67 for (
const auto& roIndex : m_renderObjects ) {
69 RadiumEngine::getInstance()->getRenderObjectManager()->getRenderObject( roIndex );
70 if ( ro->isVisible() ) { aabb.extend( ro->computeAabb() ); }
80void Component::invalidateAabb() {
81 m_isAabbValid =
false;
82 m_entity->invalidateAabb();
Component(const std::string &name, Entity *entity)
CONSTRUCTOR.
virtual Entity * getEntity() const
Return the entity the component belongs to.
static Rendering::RenderObjectManager * getRoMgr()
Shortcut to access the render object manager.
virtual ~Component()
DESTRUCTOR.
void removeRenderObject(const Core::Utils::Index &roIdx)
Remove the render object from the component.
Core::Utils::Index addRenderObject(Rendering::RenderObject *renderObject)
Add a new render object to the component. This adds the RO to the manager for drawing.
An entity is an scene element. It ties together components with a transform.
void addComponent(Component *component)
Add a component to the given entity. Component ownership is transfered to the entity.
virtual void unregisterComponent(const Entity *entity, Component *component)
hepler function to manage enum as underlying types in VariableSet