IAnimatedMeshSceneNode.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. #ifndef __I_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
  5. #define __I_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
  6. #include "ISceneNode.h"
  7. #include "IBoneSceneNode.h"
  8. #include "IAnimatedMeshMD2.h"
  9. #include "IAnimatedMeshMD3.h"
  10. namespace irr
  11. {
  12. namespace scene
  13. {
  14. class IShadowVolumeSceneNode;
  15. enum E_JOINT_UPDATE_ON_RENDER
  16. {
  17. //! do nothing
  18. EJUOR_NONE = 0,
  19. //! get joints positions from the mesh (for attached nodes, etc)
  20. EJUOR_READ,
  21. //! control joint positions in the mesh (eg. ragdolls, or set the animation from animateJoints() )
  22. EJUOR_CONTROL
  23. };
  24. class IAnimatedMeshSceneNode;
  25. //! Callback interface for catching events of ended animations.
  26. /** Implement this interface and use
  27. IAnimatedMeshSceneNode::setAnimationEndCallback to be able to
  28. be notified if an animation playback has ended.
  29. **/
  30. class IAnimationEndCallBack : public virtual IReferenceCounted
  31. {
  32. public:
  33. //! Will be called when the animation playback has ended.
  34. /** See IAnimatedMeshSceneNode::setAnimationEndCallback for
  35. more informations.
  36. \param node: Node of which the animation has ended. */
  37. virtual void OnAnimationEnd(IAnimatedMeshSceneNode* node) = 0;
  38. };
  39. //! Scene node capable of displaying an animated mesh and its shadow.
  40. /** The shadow is optional: If a shadow should be displayed too, just
  41. invoke the IAnimatedMeshSceneNode::createShadowVolumeSceneNode().*/
  42. class IAnimatedMeshSceneNode : public ISceneNode
  43. {
  44. public:
  45. //! Constructor
  46. IAnimatedMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
  47. const core::vector3df& position = core::vector3df(0,0,0),
  48. const core::vector3df& rotation = core::vector3df(0,0,0),
  49. const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
  50. : ISceneNode(parent, mgr, id, position, rotation, scale) {}
  51. //! Destructor
  52. virtual ~IAnimatedMeshSceneNode() {}
  53. //! Sets the current frame number.
  54. /** From now on the animation is played from this frame.
  55. \param frame: Number of the frame to let the animation be started from.
  56. The frame number must be a valid frame number of the IMesh used by this
  57. scene node. Set IAnimatedMesh::getMesh() for details. */
  58. virtual void setCurrentFrame(f32 frame) = 0;
  59. //! Sets the frame numbers between the animation is looped.
  60. /** The default is 0 - MaximalFrameCount of the mesh.
  61. \param begin: Start frame number of the loop.
  62. \param end: End frame number of the loop.
  63. \return True if successful, false if not. */
  64. virtual bool setFrameLoop(s32 begin, s32 end) = 0;
  65. //! Sets the speed with which the animation is played.
  66. /** \param framesPerSecond: Frames per second played. */
  67. virtual void setAnimationSpeed(f32 framesPerSecond) = 0;
  68. //! Gets the speed with which the animation is played.
  69. /** \return Frames per second played. */
  70. virtual f32 getAnimationSpeed() const =0;
  71. //! Creates shadow volume scene node as child of this node.
  72. /** The shadow can be rendered using the ZPass or the zfail
  73. method. ZPass is a little bit faster because the shadow volume
  74. creation is easier, but with this method there occur ugly
  75. looking artifacs when the camera is inside the shadow volume.
  76. These error do not occur with the ZFail method.
  77. \param shadowMesh: Optional custom mesh for shadow volume.
  78. \param id: Id of the shadow scene node. This id can be used to
  79. identify the node later.
  80. \param zfailmethod: If set to true, the shadow will use the
  81. zfail method, if not, zpass is used.
  82. \param infinity: Value used by the shadow volume algorithm to
  83. scale the shadow volume (for zfail shadow volume we support only
  84. finite shadows, so camera zfar must be larger than shadow back cap,
  85. which is depend on infinity parameter).
  86. \return Pointer to the created shadow scene node. This pointer
  87. should not be dropped. See IReferenceCounted::drop() for more
  88. information. */
  89. virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh=0,
  90. s32 id=-1, bool zfailmethod=true, f32 infinity=1000.0f) = 0;
  91. //! Get a pointer to a joint in the mesh (if the mesh is a bone based mesh).
  92. /** With this method it is possible to attach scene nodes to
  93. joints for example possible to attach a weapon to the left hand
  94. of an animated model. This example shows how:
  95. \code
  96. ISceneNode* hand =
  97. yourAnimatedMeshSceneNode->getJointNode("LeftHand");
  98. hand->addChild(weaponSceneNode);
  99. \endcode
  100. Please note that the joint returned by this method may not exist
  101. before this call and the joints in the node were created by it.
  102. \param jointName: Name of the joint.
  103. \return Pointer to the scene node which represents the joint
  104. with the specified name. Returns 0 if the contained mesh is not
  105. an skinned mesh or the name of the joint could not be found. */
  106. virtual IBoneSceneNode* getJointNode(const c8* jointName)=0;
  107. //! same as getJointNode(const c8* jointName), but based on id
  108. virtual IBoneSceneNode* getJointNode(u32 jointID) = 0;
  109. //! Gets joint count.
  110. /** \return Amount of joints in the mesh. */
  111. virtual u32 getJointCount() const = 0;
  112. //! Starts a default MD2 animation.
  113. /** With this method it is easily possible to start a Run,
  114. Attack, Die or whatever animation, if the mesh contained in
  115. this scene node is an md2 mesh. Otherwise, nothing happens.
  116. \param anim: An MD2 animation type, which should be played, for
  117. example EMAT_STAND for the standing animation.
  118. \return True if successful, and false if not, for example if
  119. the mesh in the scene node is not a md2 mesh. */
  120. virtual bool setMD2Animation(EMD2_ANIMATION_TYPE anim) = 0;
  121. //! Starts a special MD2 animation.
  122. /** With this method it is easily possible to start a Run,
  123. Attack, Die or whatever animation, if the mesh contained in
  124. this scene node is an md2 mesh. Otherwise, nothing happens.
  125. This method uses a character string to identify the animation.
  126. If the animation is a standard md2 animation, you might want to
  127. start this animation with the EMD2_ANIMATION_TYPE enumeration
  128. instead.
  129. \param animationName: Name of the animation which should be
  130. played.
  131. \return Returns true if successful, and false if not, for
  132. example if the mesh in the scene node is not an md2 mesh, or no
  133. animation with this name could be found. */
  134. virtual bool setMD2Animation(const c8* animationName) = 0;
  135. //! Returns the currently displayed frame number.
  136. virtual f32 getFrameNr() const = 0;
  137. //! Returns the current start frame number.
  138. virtual s32 getStartFrame() const = 0;
  139. //! Returns the current end frame number.
  140. virtual s32 getEndFrame() const = 0;
  141. //! Sets looping mode which is on by default.
  142. /** If set to false, animations will not be played looped. */
  143. virtual void setLoopMode(bool playAnimationLooped) = 0;
  144. //! returns the current loop mode
  145. /** When true the animations are played looped */
  146. virtual bool getLoopMode() const = 0;
  147. //! Sets a callback interface which will be called if an animation playback has ended.
  148. /** Set this to 0 to disable the callback again.
  149. Please note that this will only be called when in non looped
  150. mode, see IAnimatedMeshSceneNode::setLoopMode(). */
  151. virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0) = 0;
  152. //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
  153. /** In this way it is possible to change the materials a mesh
  154. causing all mesh scene nodes referencing this mesh to change
  155. too. */
  156. virtual void setReadOnlyMaterials(bool readonly) = 0;
  157. //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
  158. virtual bool isReadOnlyMaterials() const = 0;
  159. //! Sets a new mesh
  160. virtual void setMesh(IAnimatedMesh* mesh) = 0;
  161. //! Returns the current mesh
  162. virtual IAnimatedMesh* getMesh(void) = 0;
  163. //! Get the absolute transformation for a special MD3 Tag if the mesh is a md3 mesh, or the absolutetransformation if it's a normal scenenode
  164. virtual const SMD3QuaternionTag* getMD3TagTransformation( const core::stringc & tagname) = 0;
  165. //! Set how the joints should be updated on render
  166. virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode)=0;
  167. //! Sets the transition time in seconds
  168. /** Note: This needs to enable joints, and setJointmode set to
  169. EJUOR_CONTROL. You must call animateJoints(), or the mesh will
  170. not animate. */
  171. virtual void setTransitionTime(f32 Time) =0;
  172. //! animates the joints in the mesh based on the current frame.
  173. /** Also takes in to account transitions. */
  174. virtual void animateJoints(bool CalculateAbsolutePositions=true) = 0;
  175. //! render mesh ignoring its transformation.
  176. /** Culling is unaffected. */
  177. virtual void setRenderFromIdentity( bool On )=0;
  178. //! Creates a clone of this scene node and its children.
  179. /** \param newParent An optional new parent.
  180. \param newManager An optional new scene manager.
  181. \return The newly created clone of this node. */
  182. virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) = 0;
  183. };
  184. } // end namespace scene
  185. } // end namespace irr
  186. #endif