| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Components/BsCRenderable.h"
- #include "Private/RTTI/BsCRenderableRTTI.h"
- #include "Scene/BsSceneObject.h"
- #include "Mesh/BsMesh.h"
- #include "Material/BsMaterial.h"
- #include "Components/BsCAnimation.h"
- #include "Math/BsBounds.h"
- #include "Scene/BsSceneManager.h"
- namespace bs
- {
- CRenderable::CRenderable()
- {
- setName("Renderable");
- setFlag(ComponentFlag::AlwaysRun, true);
- }
- CRenderable::CRenderable(const HSceneObject& parent)
- :Component(parent)
- {
- setName("Renderable");
- setFlag(ComponentFlag::AlwaysRun, true);
- }
- void CRenderable::setMesh(HMesh mesh)
- {
- mInternal->setMesh(mesh);
- if (mAnimation != nullptr)
- mAnimation->_updateBounds(false);
- }
- void CRenderable::onInitialized()
- {
- // If mInternal already exists this means this object was deserialized,
- // so all we need to do is initialize it.
- if (mInternal != nullptr)
- mInternal->initialize();
- else
- mInternal = Renderable::create();
- gSceneManager()._bindActor(mInternal, sceneObject());
- mAnimation = SO()->getComponent<CAnimation>();
- if (mAnimation != nullptr)
- {
- _registerAnimation(mAnimation);
- mAnimation->_registerRenderable(mThisHandle);
- }
- }
- Bounds CRenderable::getBounds() const
- {
- mInternal->_updateState(*SO());
- return mInternal->getBounds();
- }
- bool CRenderable::calculateBounds(Bounds& bounds)
- {
- bounds = getBounds();
- return true;
- }
- void CRenderable::_registerAnimation(const HAnimation& animation)
- {
- mAnimation = animation;
- if (mInternal != nullptr)
- {
- mInternal->setAnimation(animation->_getInternal());
- // Need to update transform because animated renderables handle local transforms through bones, so it
- // shouldn't be included in the renderable's transform.
- mInternal->_updateState(*SO(), true);
- }
- }
- void CRenderable::_unregisterAnimation()
- {
- mAnimation = nullptr;
- if(mInternal != nullptr)
- {
- mInternal->setAnimation(nullptr);
- // Need to update transform because animated renderables handle local transforms through bones, so it
- // shouldn't be included in the renderable's transform.
- mInternal->_updateState(*SO(), true);
- }
- }
- void CRenderable::update()
- {
- }
- void CRenderable::onDestroyed()
- {
- if (mAnimation != nullptr)
- mAnimation->_unregisterRenderable();
- gSceneManager()._unbindActor(mInternal);
- mInternal->destroy();
- }
- RTTITypeBase* CRenderable::getRTTIStatic()
- {
- return CRenderableRTTI::instance();
- }
- RTTITypeBase* CRenderable::getRTTI() const
- {
- return CRenderable::getRTTIStatic();
- }
- }
|