IAnimatedMeshSceneNode.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #pragma once
  5. #include "ISceneNode.h"
  6. #include "IBoneSceneNode.h"
  7. #include "IAnimatedMesh.h"
  8. namespace irr
  9. {
  10. namespace scene
  11. {
  12. enum E_JOINT_UPDATE_ON_RENDER
  13. {
  14. //! do nothing
  15. EJUOR_NONE = 0,
  16. //! get joints positions from the mesh (for attached nodes, etc)
  17. EJUOR_READ,
  18. //! control joint positions in the mesh (eg. ragdolls, or set the animation from animateJoints() )
  19. EJUOR_CONTROL
  20. };
  21. class IAnimatedMeshSceneNode;
  22. //! Callback interface for catching events of ended animations.
  23. /** Implement this interface and use
  24. IAnimatedMeshSceneNode::setAnimationEndCallback to be able to
  25. be notified if an animation playback has ended.
  26. **/
  27. class IAnimationEndCallBack : public virtual IReferenceCounted
  28. {
  29. public:
  30. //! Will be called when the animation playback has ended.
  31. /** See IAnimatedMeshSceneNode::setAnimationEndCallback for
  32. more information.
  33. \param node: Node of which the animation has ended. */
  34. virtual void OnAnimationEnd(IAnimatedMeshSceneNode *node) = 0;
  35. };
  36. //! Scene node capable of displaying an animated mesh.
  37. class IAnimatedMeshSceneNode : public ISceneNode
  38. {
  39. public:
  40. //! Constructor
  41. IAnimatedMeshSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id,
  42. const core::vector3df &position = core::vector3df(0, 0, 0),
  43. const core::vector3df &rotation = core::vector3df(0, 0, 0),
  44. const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f)) :
  45. ISceneNode(parent, mgr, id, position, rotation, scale) {}
  46. //! Destructor
  47. virtual ~IAnimatedMeshSceneNode() {}
  48. //! Sets the current frame number.
  49. /** From now on the animation is played from this frame.
  50. \param frame: Number of the frame to let the animation be started from.
  51. The frame number must be a valid frame number of the IMesh used by this
  52. scene node. Set IAnimatedMesh::getMesh() for details. */
  53. virtual void setCurrentFrame(f32 frame) = 0;
  54. //! Sets the frame numbers between the animation is looped.
  55. /** The default is 0 to getFrameCount()-1 of the mesh.
  56. Number of played frames is end-start.
  57. It interpolates toward the last frame but stops when it is reached.
  58. It does not interpolate back to start even when looping.
  59. Looping animations should ensure last and first frame-key are identical.
  60. \param begin: Start frame number of the loop.
  61. \param end: End frame number of the loop.
  62. \return True if successful, false if not. */
  63. virtual bool setFrameLoop(s32 begin, s32 end) = 0;
  64. //! Sets the speed with which the animation is played.
  65. /** \param framesPerSecond: Frames per second played. */
  66. virtual void setAnimationSpeed(f32 framesPerSecond) = 0;
  67. //! Gets the speed with which the animation is played.
  68. /** \return Frames per second played. */
  69. virtual f32 getAnimationSpeed() const = 0;
  70. //! Get a pointer to a joint in the mesh (if the mesh is a bone based mesh).
  71. /** With this method it is possible to attach scene nodes to
  72. joints for example possible to attach a weapon to the left hand
  73. of an animated model. This example shows how:
  74. \code
  75. ISceneNode* hand =
  76. yourAnimatedMeshSceneNode->getJointNode("LeftHand");
  77. hand->addChild(weaponSceneNode);
  78. \endcode
  79. Please note that the joint returned by this method may not exist
  80. before this call and the joints in the node were created by it.
  81. \param jointName: Name of the joint.
  82. \return Pointer to the scene node which represents the joint
  83. with the specified name. Returns 0 if the contained mesh is not
  84. an skinned mesh or the name of the joint could not be found. */
  85. virtual IBoneSceneNode *getJointNode(const c8 *jointName) = 0;
  86. //! same as getJointNode(const c8* jointName), but based on id
  87. virtual IBoneSceneNode *getJointNode(u32 jointID) = 0;
  88. //! Gets joint count.
  89. /** \return Amount of joints in the mesh. */
  90. virtual u32 getJointCount() const = 0;
  91. //! Returns the currently displayed frame number.
  92. virtual f32 getFrameNr() const = 0;
  93. //! Returns the current start frame number.
  94. virtual s32 getStartFrame() const = 0;
  95. //! Returns the current end frame number.
  96. virtual s32 getEndFrame() const = 0;
  97. //! Sets looping mode which is on by default.
  98. /** If set to false, animations will not be played looped. */
  99. virtual void setLoopMode(bool playAnimationLooped) = 0;
  100. //! returns the current loop mode
  101. /** When true the animations are played looped */
  102. virtual bool getLoopMode() const = 0;
  103. //! Sets a callback interface which will be called if an animation playback has ended.
  104. /** Set this to 0 to disable the callback again.
  105. Please note that this will only be called when in non looped
  106. mode, see IAnimatedMeshSceneNode::setLoopMode(). */
  107. virtual void setAnimationEndCallback(IAnimationEndCallBack *callback = 0) = 0;
  108. //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
  109. /** In this way it is possible to change the materials a mesh
  110. causing all mesh scene nodes referencing this mesh to change
  111. too. */
  112. virtual void setReadOnlyMaterials(bool readonly) = 0;
  113. //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
  114. virtual bool isReadOnlyMaterials() const = 0;
  115. //! Sets a new mesh
  116. virtual void setMesh(IAnimatedMesh *mesh) = 0;
  117. //! Returns the current mesh
  118. virtual IAnimatedMesh *getMesh(void) = 0;
  119. //! Set how the joints should be updated on render
  120. virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode) = 0;
  121. //! Sets the transition time in seconds
  122. /** Note: This needs to enable joints, and setJointmode set to
  123. EJUOR_CONTROL. You must call animateJoints(), or the mesh will
  124. not animate. */
  125. virtual void setTransitionTime(f32 Time) = 0;
  126. //! animates the joints in the mesh based on the current frame.
  127. /** Also takes in to account transitions. */
  128. virtual void animateJoints(bool CalculateAbsolutePositions = true) = 0;
  129. //! render mesh ignoring its transformation.
  130. /** Culling is unaffected. */
  131. virtual void setRenderFromIdentity(bool On) = 0;
  132. //! Creates a clone of this scene node and its children.
  133. /** \param newParent An optional new parent.
  134. \param newManager An optional new scene manager.
  135. \return The newly created clone of this node. */
  136. virtual ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) = 0;
  137. };
  138. } // end namespace scene
  139. } // end namespace irr