AnimationResource.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  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 AnimationKeyframe
  18. {
  19. friend class AnimationResource;
  20. public:
  21. Second getTime() const
  22. {
  23. return m_time;
  24. }
  25. const T& getValue() const
  26. {
  27. return m_value;
  28. }
  29. private:
  30. Second 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. DynamicArray<AnimationKeyframe<Vec3>> m_positions;
  40. DynamicArray<AnimationKeyframe<Quat>> m_rotations;
  41. DynamicArray<AnimationKeyframe<F32>> m_scales;
  42. DynamicArray<AnimationKeyframe<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 AnimationResource : public ResourceObject
  54. {
  55. public:
  56. AnimationResource(ResourceManager* manager);
  57. ~AnimationResource();
  58. ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
  59. /// Get a vector of all animation channels
  60. const DynamicArray<AnimationChannel>& getChannels() const
  61. {
  62. return m_channels;
  63. }
  64. /// Get the duration of the animation in seconds
  65. Second getDuration() const
  66. {
  67. return m_duration;
  68. }
  69. /// Get the time (in seconds) the animation should start
  70. Second getStartingTime() const
  71. {
  72. return m_startTime;
  73. }
  74. /// Get the interpolated data
  75. void interpolate(U32 channelIndex, Second time, Vec3& position, Quat& rotation, F32& scale) const;
  76. private:
  77. DynamicArray<AnimationChannel> m_channels;
  78. Second m_duration;
  79. Second m_startTime;
  80. };
  81. /// @}
  82. } // end namespace anki