2
0

ISkinnedMesh.h 6.1 KB

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