AnimationResource.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2009-present, 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. #include <AnKi/Util/WeakArray.h>
  10. namespace anki {
  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. ResourceString m_name;
  38. I32 m_boneIndex = -1; ///< For skeletal animations
  39. ResourceDynamicArray<AnimationKeyframe<Vec3>> m_positions;
  40. ResourceDynamicArray<AnimationKeyframe<Quat>> m_rotations;
  41. ResourceDynamicArray<AnimationKeyframe<F32>> m_scales;
  42. ResourceDynamicArray<AnimationKeyframe<F32>> m_cameraFovs;
  43. };
  44. /// Animation consists of keyframe data.
  45. class AnimationResource : public ResourceObject
  46. {
  47. public:
  48. AnimationResource(CString fname, U32 uuid)
  49. : ResourceObject(fname, uuid)
  50. {
  51. }
  52. ~AnimationResource() = default;
  53. Error load(const ResourceFilename& filename, Bool async);
  54. /// Get a vector of all animation channels
  55. ConstWeakArray<AnimationChannel> getChannels() const
  56. {
  57. return m_channels;
  58. }
  59. /// Get the duration of the animation in seconds
  60. Second getDuration() const
  61. {
  62. return m_duration;
  63. }
  64. /// Get the time (in seconds) the animation should start
  65. Second getStartingTime() const
  66. {
  67. return m_startTime;
  68. }
  69. /// Get the interpolated data
  70. void interpolate(U32 channelIndex, Second time, Vec3& position, Quat& rotation, F32& scale) const;
  71. private:
  72. ResourceDynamicArray<AnimationChannel> m_channels;
  73. Second m_duration;
  74. Second m_startTime;
  75. };
  76. /// @}
  77. } // end namespace anki