Animation.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/resource/ResourceObject.h>
  7. #include <anki/Math.h>
  8. #include <anki/util/String.h>
  9. namespace anki
  10. {
  11. // Forward
  12. class XmlElement;
  13. /// @addtogroup resource
  14. /// @{
  15. /// A keyframe
  16. template<typename T>
  17. class Key
  18. {
  19. friend class Animation;
  20. public:
  21. F32 getTime() const
  22. {
  23. return m_time;
  24. }
  25. const T& getValue() const
  26. {
  27. return m_value;
  28. }
  29. private:
  30. F32 m_time;
  31. T m_value;
  32. };
  33. /// Animation channel
  34. class AnimationChannel
  35. {
  36. public:
  37. String m_name;
  38. I32 m_boneIndex = -1; ///< For skeletal animations
  39. DArray<Key<Vec3>> m_positions;
  40. DArray<Key<Quat>> m_rotations;
  41. DArray<Key<F32>> m_scales;
  42. DArray<Key<F32>> m_cameraFovs;
  43. void destroy(ResourceAllocator<U8> alloc)
  44. {
  45. m_name.destroy(alloc);
  46. m_positions.destroy(alloc);
  47. m_rotations.destroy(alloc);
  48. m_scales.destroy(alloc);
  49. m_cameraFovs.destroy(alloc);
  50. }
  51. };
  52. /// Animation consists of keyframe data.
  53. class Animation : public ResourceObject
  54. {
  55. public:
  56. Animation(ResourceManager* manager);
  57. ~Animation();
  58. ANKI_USE_RESULT Error load(const ResourceFilename& filename);
  59. /// Get a vector of all animation channels
  60. const DArray<AnimationChannel>& getChannels() const
  61. {
  62. return m_channels;
  63. }
  64. /// Get the duration of the animation in seconds
  65. F32 getDuration() const
  66. {
  67. return m_duration;
  68. }
  69. /// Get the time (in seconds) the animation should start
  70. F32 getStartingTime() const
  71. {
  72. return m_startTime;
  73. }
  74. /// The animation repeats
  75. Bool getRepeat() const
  76. {
  77. return m_repeat;
  78. }
  79. /// Get the interpolated data
  80. void interpolate(U channelIndex,
  81. F32 time,
  82. Vec3& position,
  83. Quat& rotation,
  84. F32& scale) const;
  85. private:
  86. DArray<AnimationChannel> m_channels;
  87. F32 m_duration;
  88. F32 m_startTime;
  89. Bool8 m_repeat;
  90. };
  91. /// @}
  92. } // end namespace anki