| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Components/BsCBone.h"
- #include "Scene/BsSceneObject.h"
- #include "Components/BsCAnimation.h"
- #include "RTTI/BsCBoneRTTI.h"
- using namespace std::placeholders;
- namespace bs
- {
- CBone::CBone()
- {
- setName("Bone");
- mNotifyFlags = TCF_Parent;
- }
- CBone::CBone(const HSceneObject& parent)
- : Component(parent)
- {
- setName("Bone");
- mNotifyFlags = TCF_Parent;
- }
- void CBone::setBoneName(const String& name)
- {
- if (mBoneName == name)
- return;
- mBoneName = name;
- if (mParent != nullptr)
- mParent->_notifyBoneChanged(getHandle());
- }
- void CBone::onDestroyed()
- {
- if (mParent != nullptr)
- mParent->_removeBone(getHandle());
- mParent = nullptr;
- }
- void CBone::onDisabled()
- {
- if (mParent != nullptr)
- mParent->_removeBone(getHandle());
- mParent = nullptr;
- }
- void CBone::onEnabled()
- {
- updateParentAnimation();
- }
- void CBone::onTransformChanged(TransformChangedFlags flags)
- {
- if (!SO()->getActive())
- return;
- if ((flags & TCF_Parent) != 0)
- updateParentAnimation();
- }
- void CBone::updateParentAnimation()
- {
- HSceneObject currentSO = SO();
- while (currentSO != nullptr)
- {
- HAnimation parent = currentSO->getComponent<CAnimation>();
- if (parent != nullptr)
- {
- if (currentSO->getActive())
- _setParent(parent);
- else
- _setParent(HAnimation());
- return;
- }
- currentSO = currentSO->getParent();
- }
- _setParent(HAnimation());
- }
- void CBone::_setParent(const HAnimation& animation, bool isInternal)
- {
- if (animation == mParent)
- return;
- if (!isInternal)
- {
- if (mParent != nullptr)
- mParent->_removeBone(getHandle());
- if (animation != nullptr)
- animation->_addBone(getHandle());
- }
- mParent = animation;
- }
-
- RTTITypeBase* CBone::getRTTIStatic()
- {
- return CBoneRTTI::instance();
- }
- RTTITypeBase* CBone::getRTTI() const
- {
- return CBone::getRTTIStatic();
- }
- }
|