AnimationResource.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // Forward
  11. class XmlElement;
  12. /// @addtogroup resource
  13. /// @{
  14. /// A keyframe
  15. template<typename T>
  16. class AnimationKeyframe
  17. {
  18. friend class AnimationResource;
  19. public:
  20. Second getTime() const
  21. {
  22. return m_time;
  23. }
  24. const T& getValue() const
  25. {
  26. return m_value;
  27. }
  28. private:
  29. Second m_time;
  30. T m_value;
  31. };
  32. /// Animation channel
  33. class AnimationChannel
  34. {
  35. public:
  36. String m_name;
  37. I32 m_boneIndex = -1; ///< For skeletal animations
  38. DynamicArray<AnimationKeyframe<Vec3>> m_positions;
  39. DynamicArray<AnimationKeyframe<Quat>> m_rotations;
  40. DynamicArray<AnimationKeyframe<F32>> m_scales;
  41. DynamicArray<AnimationKeyframe<F32>> m_cameraFovs;
  42. void destroy(ResourceAllocator<U8> alloc)
  43. {
  44. m_name.destroy(alloc);
  45. m_positions.destroy(alloc);
  46. m_rotations.destroy(alloc);
  47. m_scales.destroy(alloc);
  48. m_cameraFovs.destroy(alloc);
  49. }
  50. };
  51. /// Animation consists of keyframe data.
  52. class AnimationResource : public ResourceObject
  53. {
  54. public:
  55. AnimationResource(ResourceManager* manager);
  56. ~AnimationResource();
  57. ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
  58. /// Get a vector of all animation channels
  59. const DynamicArray<AnimationChannel>& getChannels() const
  60. {
  61. return m_channels;
  62. }
  63. /// Get the duration of the animation in seconds
  64. Second getDuration() const
  65. {
  66. return m_duration;
  67. }
  68. /// Get the time (in seconds) the animation should start
  69. Second getStartingTime() const
  70. {
  71. return m_startTime;
  72. }
  73. /// Get the interpolated data
  74. void interpolate(U32 channelIndex, Second time, Vec3& position, Quat& rotation, F32& scale) const;
  75. private:
  76. DynamicArray<AnimationChannel> m_channels;
  77. Second m_duration;
  78. Second m_startTime;
  79. };
  80. /// @}
  81. } // end namespace anki