BsCBone.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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()
  11. {
  12. setName("Bone");
  13. mNotifyFlags = TCF_Parent;
  14. }
  15. CBone::CBone(const HSceneObject& parent)
  16. : Component(parent)
  17. {
  18. setName("Bone");
  19. mNotifyFlags = TCF_Parent;
  20. }
  21. void CBone::setBoneName(const String& name)
  22. {
  23. if (mBoneName == name)
  24. return;
  25. mBoneName = name;
  26. if (mParent != nullptr)
  27. mParent->_notifyBoneChanged(getHandle());
  28. }
  29. void CBone::onDestroyed()
  30. {
  31. if (mParent != nullptr)
  32. mParent->_removeBone(getHandle());
  33. mParent = nullptr;
  34. }
  35. void CBone::onDisabled()
  36. {
  37. if (mParent != nullptr)
  38. mParent->_removeBone(getHandle());
  39. mParent = nullptr;
  40. }
  41. void CBone::onEnabled()
  42. {
  43. updateParentAnimation();
  44. }
  45. void CBone::onTransformChanged(TransformChangedFlags flags)
  46. {
  47. if (!SO()->getActive())
  48. return;
  49. if ((flags & TCF_Parent) != 0)
  50. updateParentAnimation();
  51. }
  52. void CBone::updateParentAnimation()
  53. {
  54. HSceneObject currentSO = SO();
  55. while (currentSO != nullptr)
  56. {
  57. HAnimation parent = currentSO->getComponent<CAnimation>();
  58. if (parent != nullptr)
  59. {
  60. if (currentSO->getActive())
  61. _setParent(parent);
  62. else
  63. _setParent(HAnimation());
  64. return;
  65. }
  66. currentSO = currentSO->getParent();
  67. }
  68. _setParent(HAnimation());
  69. }
  70. void CBone::_setParent(const HAnimation& animation, bool isInternal)
  71. {
  72. if (animation == mParent)
  73. return;
  74. if (!isInternal)
  75. {
  76. if (mParent != nullptr)
  77. mParent->_removeBone(getHandle());
  78. if (animation != nullptr)
  79. animation->_addBone(getHandle());
  80. }
  81. mParent = animation;
  82. }
  83. RTTITypeBase* CBone::getRTTIStatic()
  84. {
  85. return CBoneRTTI::instance();
  86. }
  87. RTTITypeBase* CBone::getRTTI() const
  88. {
  89. return CBone::getRTTIStatic();
  90. }
  91. }