aiAnim.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2008, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Defines the data structures in which the imported animations
  35. are returned. */
  36. #ifndef AI_ANIM_H_INC
  37. #define AI_ANIM_H_INC
  38. #include "aiTypes.h"
  39. #include "aiQuaternion.h"
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. // ---------------------------------------------------------------------------
  44. /** A time-value pair specifying a certain 3D vector for the given time. */
  45. struct aiVectorKey
  46. {
  47. double mTime; ///< The time of this key
  48. C_STRUCT aiVector3D mValue; ///< The value of this key
  49. #ifdef __cplusplus
  50. // time is not compared
  51. bool operator == (const aiVectorKey& o) const
  52. {return o.mValue == this->mValue;}
  53. bool operator != (const aiVectorKey& o) const
  54. {return o.mValue != this->mValue;}
  55. // Only time is compared. This operator is defined
  56. // for use with std::sort
  57. bool operator < (const aiVectorKey& o) const
  58. {return mTime < o.mTime;}
  59. bool operator > (const aiVectorKey& o) const
  60. {return mTime > o.mTime;}
  61. #endif
  62. };
  63. // ---------------------------------------------------------------------------
  64. /** A time-value pair specifying a rotation for the given time. For joint
  65. * animations the rotation is usually expressed using a quaternion.
  66. */
  67. struct aiQuatKey
  68. {
  69. double mTime; ///< The time of this key
  70. C_STRUCT aiQuaternion mValue; ///< The value of this key
  71. #ifdef __cplusplus
  72. // time is not compared
  73. bool operator == (const aiQuatKey& o) const
  74. {return o.mValue == this->mValue;}
  75. bool operator != (const aiQuatKey& o) const
  76. {return o.mValue != this->mValue;}
  77. // Only time is compared. This operator is defined
  78. // for use with std::sort
  79. bool operator < (const aiQuatKey& o) const
  80. {return mTime < o.mTime;}
  81. bool operator > (const aiQuatKey& o) const
  82. {return mTime < o.mTime;}
  83. #endif
  84. };
  85. // ---------------------------------------------------------------------------
  86. /** Defines how an animation channel behaves outside the defined time
  87. * range. This corresponds to aiNodeAnim::mPreState and
  88. * aiNodeAnim::mPostState.
  89. */
  90. enum aiAnimBehaviour
  91. {
  92. /** The value from the default node transformation is taken
  93. */
  94. aiAnimBehaviour_DEFAULT = 0x0,
  95. /** The nearest key is used
  96. */
  97. aiAnimBehaviour_CONSTANT = 0x1,
  98. /** The value of the nearest two keys is linearly
  99. * extrapolated for the current time value.
  100. */
  101. aiAnimBehaviour_LINEAR = 0x2,
  102. /** The animation is repeated.
  103. *
  104. * If the animation key go from n to m and the current
  105. * time is t, use the value at (t-n) % (|m-n|).
  106. */
  107. aiAnimBehaviour_REPEAT = 0x3,
  108. /** This value is not used, it is just here to force the
  109. * the compiler to map this enum to a 32 Bit integer
  110. */
  111. _aiAnimBehaviour_Force32Bit = 0x8fffffff
  112. };
  113. // ---------------------------------------------------------------------------
  114. /** Describes the animation of a single node. The name specifies the
  115. * bone/node which is affected by this animation channel. The keyframes
  116. * are given in three separate series of values, one each for position,
  117. * rotation and scaling. The transformation matrix computed from these
  118. * values replaces the node's original transformation matrix at a
  119. * spefific time. The order in which the transformations are applied is
  120. * - as usual - scaling, rotation, translation.
  121. *
  122. * @note All keys are returned in their correct, chronological order.
  123. * Duplicate keys don't pass the validation step. Most likely there
  124. * will be no negative time keys, but they are not forbidden ...
  125. */
  126. struct aiNodeAnim
  127. {
  128. /** The name of the node affected by this animation. The node
  129. * must exist and it must be unique.
  130. */
  131. C_STRUCT aiString mNodeName;
  132. /** The number of position keys */
  133. unsigned int mNumPositionKeys;
  134. /** The position keys of this animation channel. Positions are
  135. * specified as 3D vector. The array is mNumPositionKeys in size.
  136. *
  137. * If there are position keys, there will also be at least one
  138. * scaling and one rotation key.
  139. */
  140. C_STRUCT aiVectorKey* mPositionKeys;
  141. /** The number of rotation keys */
  142. unsigned int mNumRotationKeys;
  143. /** The rotation keys of this animation channel. Rotations are
  144. * given as quaternions, which are 4D vectors. The array is
  145. * mNumRotationKeys in size.
  146. *
  147. * If there are rotation keys, there will also be at least one
  148. * scaling and one position key.
  149. */
  150. C_STRUCT aiQuatKey* mRotationKeys;
  151. /** The number of scaling keys */
  152. unsigned int mNumScalingKeys;
  153. /** The scaling keys of this animation channel. Scalings are
  154. * specified as 3D vector. The array is mNumScalingKeys in size.
  155. *
  156. * If there are scaling keys, there will also be at least one
  157. * position and one rotation key.
  158. */
  159. C_STRUCT aiVectorKey* mScalingKeys;
  160. /** Defines how the animation behaves before the first
  161. * key is encountered.
  162. *
  163. * The default value is aiAnimBehaviour_DEFAULT (the original
  164. * transformation matrix of the affacted node is taken).
  165. */
  166. aiAnimBehaviour mPreState;
  167. /** Defines how the animation behaves after the last
  168. * kway was encountered.
  169. *
  170. * The default value is aiAnimBehaviour_DEFAULT (the original
  171. * transformation matrix of the affacted node is taken).
  172. */
  173. aiAnimBehaviour mPostState;
  174. #ifdef __cplusplus
  175. aiNodeAnim()
  176. {
  177. mNumPositionKeys = 0; mPositionKeys = NULL;
  178. mNumRotationKeys= 0; mRotationKeys = NULL;
  179. mNumScalingKeys = 0; mScalingKeys = NULL;
  180. mPreState = mPostState = aiAnimBehaviour_DEFAULT;
  181. }
  182. ~aiNodeAnim()
  183. {
  184. delete [] mPositionKeys;
  185. delete [] mRotationKeys;
  186. delete [] mScalingKeys;
  187. }
  188. #endif // __cplusplus
  189. };
  190. // ---------------------------------------------------------------------------
  191. /** An animation consists of keyframe data for a number of nodes. For
  192. * each node affected by the animation a separate series of data is given.
  193. */
  194. struct aiAnimation
  195. {
  196. /** The name of the animation. If the modelling package this data was
  197. * exported from does support only a single animation channel, this
  198. * name is usually empty (length is zero).
  199. */
  200. C_STRUCT aiString mName;
  201. /** Duration of the animation in ticks.
  202. */
  203. double mDuration;
  204. /** Ticks per second. 0 if not specified in the imported file
  205. */
  206. double mTicksPerSecond;
  207. /** The number of bone animation channels. Each channel affects
  208. * a single node.
  209. */
  210. unsigned int mNumChannels;
  211. /** The node animation channels. Each channel affects a single node.
  212. * The array is mNumChannels in size.
  213. */
  214. C_STRUCT aiNodeAnim** mChannels;
  215. #ifdef __cplusplus
  216. aiAnimation()
  217. {
  218. mDuration = -1.;
  219. mTicksPerSecond = 0;
  220. mNumChannels = 0; mChannels = NULL;
  221. }
  222. ~aiAnimation()
  223. {
  224. // DO NOT REMOVE THIS ADDITIONAL CHECK
  225. if (mNumChannels && mChannels)
  226. {
  227. for( unsigned int a = 0; a < mNumChannels; a++)
  228. delete mChannels[a];
  229. delete [] mChannels;
  230. }
  231. }
  232. #endif // __cplusplus
  233. };
  234. #ifdef __cplusplus
  235. }
  236. #endif
  237. #endif // AI_ANIM_H_INC