IAnimatedMeshSceneNode.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 IRR_I_ANIMATED_MESH_SCENE_NODE_H_INCLUDED
  5. #define IRR_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 information.
  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.
  40. class IAnimatedMeshSceneNode : public ISceneNode
  41. {
  42. public:
  43. //! Constructor
  44. IAnimatedMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
  45. const core::vector3df& position = core::vector3df(0,0,0),
  46. const core::vector3df& rotation = core::vector3df(0,0,0),
  47. const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
  48. : ISceneNode(parent, mgr, id, position, rotation, scale) {}
  49. //! Destructor
  50. virtual ~IAnimatedMeshSceneNode() {}
  51. //! Sets the current frame number.
  52. /** From now on the animation is played from this frame.
  53. \param frame: Number of the frame to let the animation be started from.
  54. The frame number must be a valid frame number of the IMesh used by this
  55. scene node. Set IAnimatedMesh::getMesh() for details. */
  56. virtual void setCurrentFrame(f32 frame) = 0;
  57. //! Sets the frame numbers between the animation is looped.
  58. /** The default is 0 to getFrameCount()-1 of the mesh.
  59. Number of played frames is end-start.
  60. It interpolates toward the last frame but stops when it is reached.
  61. It does not interpolate back to start even when looping.
  62. Looping animations should ensure last and first frame-key are identical.
  63. \param begin: Start frame number of the loop.
  64. \param end: End frame number of the loop.
  65. \return True if successful, false if not. */
  66. virtual bool setFrameLoop(s32 begin, s32 end) = 0;
  67. //! Sets the speed with which the animation is played.
  68. /** \param framesPerSecond: Frames per second played. */
  69. virtual void setAnimationSpeed(f32 framesPerSecond) = 0;
  70. //! Gets the speed with which the animation is played.
  71. /** \return Frames per second played. */
  72. virtual f32 getAnimationSpeed() const =0;
  73. /** The shadow can be rendered using the ZPass or the zfail
  74. method. ZPass is a little bit faster because the shadow volume
  75. creation is easier, but with this method there occur ugly
  76. looking artifacts when the camera is inside the shadow volume.
  77. These error do not occur with the ZFail method, but it can
  78. have trouble with clipping to the far-plane (it usually works
  79. well in OpenGL and fails with other drivers).
  80. \param shadowMesh: Optional custom mesh for shadow volume.
  81. \param id: Id of the shadow scene node. This id can be used to
  82. identify the node later.
  83. \param zfailmethod: If set to true, the shadow will use the
  84. zfail method, if not, zpass is used.
  85. \param infinity: Value used by the shadow volume algorithm to
  86. scale the shadow volume. For zfail shadow volumes on some drivers
  87. only support finite shadows, so camera zfar must be larger than
  88. shadow back cap,which is depending on the infinity parameter).
  89. Infinity value also scales by the scaling factors of the model.
  90. If shadows don't show up with zfail then try reducing infinity.
  91. If shadows are cut-off then try increasing infinity.
  92. \return Pointer to the created shadow scene node. This pointer
  93. should not be dropped. See IReferenceCounted::drop() for more
  94. information. */
  95. virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh=0,
  96. s32 id=-1, bool zfailmethod=true, f32 infinity=1000.0f) = 0;
  97. //! Get a pointer to a joint in the mesh (if the mesh is a bone based mesh).
  98. /** With this method it is possible to attach scene nodes to
  99. joints for example possible to attach a weapon to the left hand
  100. of an animated model. This example shows how:
  101. \code
  102. ISceneNode* hand =
  103. yourAnimatedMeshSceneNode->getJointNode("LeftHand");
  104. hand->addChild(weaponSceneNode);
  105. \endcode
  106. Please note that the joint returned by this method may not exist
  107. before this call and the joints in the node were created by it.
  108. \param jointName: Name of the joint.
  109. \return Pointer to the scene node which represents the joint
  110. with the specified name. Returns 0 if the contained mesh is not
  111. an skinned mesh or the name of the joint could not be found. */
  112. virtual IBoneSceneNode* getJointNode(const c8* jointName)=0;
  113. //! same as getJointNode(const c8* jointName), but based on id
  114. virtual IBoneSceneNode* getJointNode(u32 jointID) = 0;
  115. //! Gets joint count.
  116. /** \return Amount of joints in the mesh. */
  117. virtual u32 getJointCount() const = 0;
  118. //! Starts a default MD2 animation.
  119. /** With this method it is easily possible to start a Run,
  120. Attack, Die or whatever animation, if the mesh contained in
  121. this scene node is an md2 mesh. Otherwise, nothing happens.
  122. \param anim: An MD2 animation type, which should be played, for
  123. example EMAT_STAND for the standing animation.
  124. \return True if successful, and false if not, for example if
  125. the mesh in the scene node is not a md2 mesh. */
  126. virtual bool setMD2Animation(EMD2_ANIMATION_TYPE anim) = 0;
  127. //! Starts a special MD2 animation.
  128. /** With this method it is easily possible to start a Run,
  129. Attack, Die or whatever animation, if the mesh contained in
  130. this scene node is an md2 mesh. Otherwise, nothing happens.
  131. This method uses a character string to identify the animation.
  132. If the animation is a standard md2 animation, you might want to
  133. start this animation with the EMD2_ANIMATION_TYPE enumeration
  134. instead.
  135. \param animationName: Name of the animation which should be
  136. played.
  137. \return Returns true if successful, and false if not, for
  138. example if the mesh in the scene node is not an md2 mesh, or no
  139. animation with this name could be found. */
  140. virtual bool setMD2Animation(const c8* animationName) = 0;
  141. //! Returns the currently displayed frame number.
  142. virtual f32 getFrameNr() const = 0;
  143. //! Returns the current start frame number.
  144. virtual s32 getStartFrame() const = 0;
  145. //! Returns the current end frame number.
  146. virtual s32 getEndFrame() const = 0;
  147. //! Sets looping mode which is on by default.
  148. /** If set to false, animations will not be played looped. */
  149. virtual void setLoopMode(bool playAnimationLooped) = 0;
  150. //! returns the current loop mode
  151. /** When true the animations are played looped */
  152. virtual bool getLoopMode() const = 0;
  153. //! Sets a callback interface which will be called if an animation playback has ended.
  154. /** Set this to 0 to disable the callback again.
  155. Please note that this will only be called when in non looped
  156. mode, see IAnimatedMeshSceneNode::setLoopMode(). */
  157. virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0) = 0;
  158. //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
  159. /** In this way it is possible to change the materials a mesh
  160. causing all mesh scene nodes referencing this mesh to change
  161. too. */
  162. virtual void setReadOnlyMaterials(bool readonly) = 0;
  163. //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
  164. virtual bool isReadOnlyMaterials() const = 0;
  165. //! Sets a new mesh
  166. virtual void setMesh(IAnimatedMesh* mesh) = 0;
  167. //! Returns the current mesh
  168. virtual IAnimatedMesh* getMesh(void) = 0;
  169. //! 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
  170. virtual const SMD3QuaternionTag* getMD3TagTransformation( const core::stringc & tagname) = 0;
  171. //! Set how the joints should be updated on render
  172. virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode)=0;
  173. //! Sets the transition time in seconds
  174. /** Note: This needs to enable joints, and setJointmode set to
  175. EJUOR_CONTROL. You must call animateJoints(), or the mesh will
  176. not animate. */
  177. virtual void setTransitionTime(f32 Time) =0;
  178. //! animates the joints in the mesh based on the current frame.
  179. /** Also takes in to account transitions. */
  180. virtual void animateJoints(bool CalculateAbsolutePositions=true) = 0;
  181. //! render mesh ignoring its transformation.
  182. /** Culling is unaffected. */
  183. virtual void setRenderFromIdentity( bool On )=0;
  184. //! Creates a clone of this scene node and its children.
  185. /** \param newParent An optional new parent.
  186. \param newManager An optional new scene manager.
  187. \return The newly created clone of this node. */
  188. virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) = 0;
  189. };
  190. } // end namespace scene
  191. } // end namespace irr
  192. #endif