CBoneSceneNode.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "IrrCompileConfig.h"
  5. #ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
  6. #include "CBoneSceneNode.h"
  7. namespace irr
  8. {
  9. namespace scene
  10. {
  11. //! constructor
  12. CBoneSceneNode::CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
  13. u32 boneIndex, const c8* boneName)
  14. : IBoneSceneNode(parent, mgr, id), BoneIndex(boneIndex),
  15. AnimationMode(EBAM_AUTOMATIC), SkinningSpace(EBSS_LOCAL)
  16. {
  17. #ifdef _DEBUG
  18. setDebugName("CBoneSceneNode");
  19. #endif
  20. setName(boneName);
  21. }
  22. //! Returns the index of the bone
  23. u32 CBoneSceneNode::getBoneIndex() const
  24. {
  25. return BoneIndex;
  26. }
  27. //! Sets the animation mode of the bone. Returns true if successful.
  28. bool CBoneSceneNode::setAnimationMode(E_BONE_ANIMATION_MODE mode)
  29. {
  30. AnimationMode = mode;
  31. return true;
  32. }
  33. //! Gets the current animation mode of the bone
  34. E_BONE_ANIMATION_MODE CBoneSceneNode::getAnimationMode() const
  35. {
  36. return AnimationMode;
  37. }
  38. //! returns the axis aligned bounding box of this node
  39. const core::aabbox3d<f32>& CBoneSceneNode::getBoundingBox() const
  40. {
  41. return Box;
  42. }
  43. /*
  44. //! Returns the relative transformation of the scene node.
  45. core::matrix4 CBoneSceneNode::getRelativeTransformation() const
  46. {
  47. return core::matrix4(); // RelativeTransformation;
  48. }
  49. */
  50. void CBoneSceneNode::OnAnimate(u32 timeMs)
  51. {
  52. if (IsVisible)
  53. {
  54. // animate this node with all animators
  55. ISceneNodeAnimatorList::Iterator ait = Animators.begin();
  56. for (; ait != Animators.end(); ++ait)
  57. (*ait)->animateNode(this, timeMs);
  58. // update absolute position
  59. //updateAbsolutePosition();
  60. // perform the post render process on all children
  61. ISceneNodeList::Iterator it = Children.begin();
  62. for (; it != Children.end(); ++it)
  63. (*it)->OnAnimate(timeMs);
  64. }
  65. }
  66. void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node)
  67. {
  68. Node->updateAbsolutePosition();
  69. ISceneNodeList::ConstIterator it = Node->getChildren().begin();
  70. for (; it != Node->getChildren().end(); ++it)
  71. {
  72. helper_updateAbsolutePositionOfAllChildren( (*it) );
  73. }
  74. }
  75. void CBoneSceneNode::updateAbsolutePositionOfAllChildren()
  76. {
  77. helper_updateAbsolutePositionOfAllChildren( this );
  78. }
  79. void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
  80. {
  81. IBoneSceneNode::serializeAttributes(out, options);
  82. out->addInt("BoneIndex", BoneIndex);
  83. out->addEnum("AnimationMode", AnimationMode, BoneAnimationModeNames);
  84. }
  85. void CBoneSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
  86. {
  87. BoneIndex = in->getAttributeAsInt("BoneIndex");
  88. AnimationMode = (E_BONE_ANIMATION_MODE)in->getAttributeAsEnumeration("AnimationMode", BoneAnimationModeNames);
  89. // for legacy files (before 1.5)
  90. const core::stringc boneName = in->getAttributeAsString("BoneName");
  91. setName(boneName);
  92. IBoneSceneNode::deserializeAttributes(in, options);
  93. // TODO: add/replace bone in parent with bone from mesh
  94. }
  95. } // namespace scene
  96. } // namespace irr
  97. #endif