BsCBone.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Components/BsCBone.h"
  4. #include "Scene/BsSceneObject.h"
  5. #include "Components/BsCAnimation.h"
  6. #include "RTTI/BsCBoneRTTI.h"
  7. using namespace std::placeholders;
  8. namespace bs
  9. {
  10. CBone::CBone(const HSceneObject& parent)
  11. : Component(parent)
  12. {
  13. setName("Bone");
  14. mNotifyFlags = TCF_Parent;
  15. }
  16. void CBone::setBoneName(const String& name)
  17. {
  18. if (mBoneName == name)
  19. return;
  20. mBoneName = name;
  21. if (mParent != nullptr)
  22. mParent->_notifyBoneChanged(getHandle());
  23. }
  24. void CBone::onDestroyed()
  25. {
  26. if (mParent != nullptr)
  27. mParent->_removeBone(getHandle());
  28. mParent = nullptr;
  29. }
  30. void CBone::onDisabled()
  31. {
  32. if (mParent != nullptr)
  33. mParent->_removeBone(getHandle());
  34. mParent = nullptr;
  35. }
  36. void CBone::onEnabled()
  37. {
  38. updateParentAnimation();
  39. }
  40. void CBone::onTransformChanged(TransformChangedFlags flags)
  41. {
  42. if (!SO()->getActive())
  43. return;
  44. if ((flags & TCF_Parent) != 0)
  45. updateParentAnimation();
  46. }
  47. void CBone::updateParentAnimation()
  48. {
  49. HSceneObject currentSO = SO();
  50. while (currentSO != nullptr)
  51. {
  52. HAnimation parent = currentSO->getComponent<CAnimation>();
  53. if (parent != nullptr)
  54. {
  55. if (currentSO->getActive())
  56. _setParent(parent);
  57. else
  58. _setParent(HAnimation());
  59. return;
  60. }
  61. currentSO = currentSO->getParent();
  62. }
  63. _setParent(HAnimation());
  64. }
  65. void CBone::_setParent(const HAnimation& animation, bool isInternal)
  66. {
  67. if (animation == mParent)
  68. return;
  69. if (!isInternal)
  70. {
  71. if (mParent != nullptr)
  72. mParent->_removeBone(getHandle());
  73. if (animation != nullptr)
  74. animation->_addBone(getHandle());
  75. }
  76. mParent = animation;
  77. }
  78. RTTITypeBase* CBone::getRTTIStatic()
  79. {
  80. return CBoneRTTI::instance();
  81. }
  82. RTTITypeBase* CBone::getRTTI() const
  83. {
  84. return CBone::getRTTIStatic();
  85. }
  86. }