ISkinnedMesh.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_SKINNED_MESH_H_INCLUDED
  5. #define IRR_I_SKINNED_MESH_H_INCLUDED
  6. #include "irrArray.h"
  7. #include "IAnimatedMesh.h"
  8. #include "SSkinMeshBuffer.h"
  9. #include "quaternion.h"
  10. #include "irrString.h"
  11. namespace irr
  12. {
  13. namespace scene
  14. {
  15. enum E_INTERPOLATION_MODE
  16. {
  17. // constant does use the current key-values without interpolation
  18. EIM_CONSTANT = 0,
  19. // linear interpolation
  20. EIM_LINEAR,
  21. //! count of all available interpolation modes
  22. EIM_COUNT
  23. };
  24. //! Interface for using some special functions of Skinned meshes
  25. class ISkinnedMesh : public IAnimatedMesh
  26. {
  27. public:
  28. //! Gets joint count.
  29. /** \return Amount of joints in the skeletal animated mesh. */
  30. virtual u32 getJointCount() const = 0;
  31. //! Gets the name of a joint.
  32. /** \param number: Zero based index of joint. The last joint
  33. has the number getJointCount()-1;
  34. \return Name of joint and null if an error happened. */
  35. virtual const c8* getJointName(u32 number) const = 0;
  36. //! Gets a joint number from its name
  37. /** \param name: Name of the joint.
  38. \return Number of the joint or -1 if not found. */
  39. virtual s32 getJointNumber(const c8* name) const = 0;
  40. //! Use animation from another mesh
  41. /** The animation is linked (not copied) based on joint names
  42. so make sure they are unique.
  43. \return True if all joints in this mesh were
  44. matched up (empty names will not be matched, and it's case
  45. sensitive). Unmatched joints will not be animated. */
  46. virtual bool useAnimationFrom(const ISkinnedMesh *mesh) = 0;
  47. //! Update Normals when Animating
  48. /** \param on If false don't animate, which is faster.
  49. Else update normals, which allows for proper lighting of
  50. animated meshes. */
  51. virtual void updateNormalsWhenAnimating(bool on) = 0;
  52. //! Sets Interpolation Mode
  53. virtual void setInterpolationMode(E_INTERPOLATION_MODE mode) = 0;
  54. //! Animates this mesh's joints based on frame input
  55. virtual void animateMesh(f32 frame, f32 blend)=0;
  56. //! Preforms a software skin on this mesh based of joint positions
  57. virtual void skinMesh() = 0;
  58. //! converts the vertex type of all meshbuffers to tangents.
  59. /** E.g. used for bump mapping. */
  60. virtual void convertMeshToTangents() = 0;
  61. //! Allows to enable hardware skinning.
  62. /* This feature is not implemented in Irrlicht yet */
  63. virtual bool setHardwareSkinning(bool on) = 0;
  64. //! A vertex weight
  65. struct SWeight
  66. {
  67. //! Index of the mesh buffer
  68. u16 buffer_id; //I doubt 32bits is needed
  69. //! Index of the vertex
  70. u32 vertex_id; //Store global ID here
  71. //! Weight Strength/Percentage (0-1)
  72. f32 strength;
  73. private:
  74. //! Internal members used by CSkinnedMesh
  75. friend class CSkinnedMesh;
  76. bool *Moved;
  77. core::vector3df StaticPos;
  78. core::vector3df StaticNormal;
  79. };
  80. //! Animation keyframe which describes a new position
  81. struct SPositionKey
  82. {
  83. f32 frame;
  84. core::vector3df position;
  85. };
  86. //! Animation keyframe which describes a new scale
  87. struct SScaleKey
  88. {
  89. f32 frame;
  90. core::vector3df scale;
  91. };
  92. //! Animation keyframe which describes a new rotation
  93. struct SRotationKey
  94. {
  95. f32 frame;
  96. core::quaternion rotation;
  97. };
  98. //! Joints
  99. struct SJoint
  100. {
  101. SJoint() : UseAnimationFrom(0), GlobalSkinningSpace(false),
  102. positionHint(-1),scaleHint(-1),rotationHint(-1)
  103. {
  104. }
  105. //! The name of this joint
  106. core::stringc Name;
  107. //! Local matrix of this joint
  108. core::matrix4 LocalMatrix;
  109. //! List of child joints
  110. core::array<SJoint*> Children;
  111. //! List of attached meshes
  112. core::array<u32> AttachedMeshes;
  113. //! Animation keys causing translation change
  114. core::array<SPositionKey> PositionKeys;
  115. //! Animation keys causing scale change
  116. core::array<SScaleKey> ScaleKeys;
  117. //! Animation keys causing rotation change
  118. core::array<SRotationKey> RotationKeys;
  119. //! Skin weights
  120. core::array<SWeight> Weights;
  121. //! Unnecessary for loaders, will be overwritten on finalize
  122. core::matrix4 GlobalMatrix;
  123. core::matrix4 GlobalAnimatedMatrix;
  124. core::matrix4 LocalAnimatedMatrix;
  125. core::vector3df Animatedposition;
  126. core::vector3df Animatedscale;
  127. core::quaternion Animatedrotation;
  128. core::matrix4 GlobalInversedMatrix; //the x format pre-calculates this
  129. private:
  130. //! Internal members used by CSkinnedMesh
  131. friend class CSkinnedMesh;
  132. SJoint *UseAnimationFrom;
  133. bool GlobalSkinningSpace;
  134. s32 positionHint;
  135. s32 scaleHint;
  136. s32 rotationHint;
  137. };
  138. //Interface for the mesh loaders (finalize should lock these functions, and they should have some prefix like loader_
  139. //these functions will use the needed arrays, set values, etc to help the loaders
  140. //! exposed for loaders: to add mesh buffers
  141. virtual core::array<SSkinMeshBuffer*>& getMeshBuffers() = 0;
  142. //! exposed for loaders: joints list
  143. virtual core::array<SJoint*>& getAllJoints() = 0;
  144. //! exposed for loaders: joints list
  145. virtual const core::array<SJoint*>& getAllJoints() const = 0;
  146. //! loaders should call this after populating the mesh
  147. virtual void finalize() = 0;
  148. //! Adds a new meshbuffer to the mesh, access it as last one
  149. virtual SSkinMeshBuffer* addMeshBuffer() = 0;
  150. //! Adds a new joint to the mesh, access it as last one
  151. virtual SJoint* addJoint(SJoint *parent=0) = 0;
  152. //! Adds a new weight to the mesh, access it as last one
  153. virtual SWeight* addWeight(SJoint *joint) = 0;
  154. //! Adds a new position key to the mesh, access it as last one
  155. virtual SPositionKey* addPositionKey(SJoint *joint) = 0;
  156. //! Adds a new scale key to the mesh, access it as last one
  157. virtual SScaleKey* addScaleKey(SJoint *joint) = 0;
  158. //! Adds a new rotation key to the mesh, access it as last one
  159. virtual SRotationKey* addRotationKey(SJoint *joint) = 0;
  160. //! Check if the mesh is non-animated
  161. virtual bool isStatic()=0;
  162. };
  163. } // end namespace scene
  164. } // end namespace irr
  165. #endif