BsAnimationClip.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsResource.h"
  6. #include "BsVector3.h"
  7. #include "BsQuaternion.h"
  8. #include "BsAnimationCurve.h"
  9. namespace BansheeEngine
  10. {
  11. /** @addtogroup Animation
  12. * @{
  13. */
  14. /** A set of animation curves representing translation/rotation/scale and generic animation. */
  15. struct AnimationCurves
  16. {
  17. Vector<TNamedAnimationCurve<Vector3>> position;
  18. Vector<TNamedAnimationCurve<Quaternion>> rotation;
  19. Vector<TNamedAnimationCurve<Vector3>> scale;
  20. Vector<TNamedAnimationCurve<float>> generic;
  21. };
  22. class BS_CORE_EXPORT AnimationClip : public Resource
  23. {
  24. public:
  25. virtual ~AnimationClip() { }
  26. /**
  27. * Registers a new curve used for animating position.
  28. *
  29. * @param[in] name Unique name of the curve. This name will be used mapping the curve to the relevant bone
  30. * in a skeleton, if any.
  31. * @param[in] curve Curve to add to the clip.
  32. *
  33. * @note Adding a new curve to a clip is a relatively slow operations and shouldn't be done at runtime.
  34. */
  35. void addPositionCurve(const String& name, const TAnimationCurve<Vector3>& curve);
  36. /**
  37. * Registers a new curve used for animating rotation.
  38. *
  39. * @param[in] name Unique name of the curve. This name will be used mapping the curve to the relevant bone
  40. * in a skeleton, if any.
  41. * @param[in] curve Curve to add to the clip.
  42. *
  43. * @note Adding a new curve to a clip is a relatively slow operations and shouldn't be done at runtime.
  44. */
  45. void addRotationCurve(const String& name, const TAnimationCurve<Quaternion>& curve);
  46. /**
  47. * Registers a new curve used for animating scale.
  48. *
  49. * @param[in] name Unique name of the curve. This name will be used mapping the curve to the relevant bone
  50. * in a skeleton, if any.
  51. * @param[in] curve Curve to add to the clip.
  52. *
  53. * @note Adding a new curve to a clip is a relatively slow operations and shouldn't be done at runtime.
  54. */
  55. void addScaleCurve(const String& name, const TAnimationCurve<Vector3>& curve);
  56. /**
  57. * Registers a new curve used for generic animation.
  58. *
  59. * @param[in] name Unique name of the curve. This can be used for retrieving the value of the curve
  60. * from animation.
  61. * @param[in] curve Curve to add to the clip.
  62. *
  63. * @note Adding a new curve to a clip is a relatively slow operations and shouldn't be done at runtime.
  64. */
  65. void addGenericCurve(const String& name, const TAnimationCurve<float>& curve);
  66. /**
  67. * Removes an existing curve from the clip.
  68. *
  69. * @param[in] name Name of the curve to remove.
  70. *
  71. * @note Removing curve from a clip is a relatively slow operations and shouldn't be done at runtime.
  72. */
  73. void removePositionCurve(const String& name);
  74. /**
  75. * Removes an existing curve from the clip.
  76. *
  77. * @param[in] name Name of the curve to remove.
  78. *
  79. * @note Removing curve from a clip is a relatively slow operations and shouldn't be done at runtime.
  80. */
  81. void removeRotationCurve(const String& name);
  82. /**
  83. * Removes an existing curve from the clip.
  84. *
  85. * @param[in] name Name of the curve to remove.
  86. *
  87. * @note Removing curve from a clip is a relatively slow operations and shouldn't be done at runtime.
  88. */
  89. void removeScaleCurve(const String& name);
  90. /**
  91. * Removes an existing curve from the clip.
  92. *
  93. * @param[in] name Name of the curve to remove.
  94. *
  95. * @note Removing curve from a clip is a relatively slow operations and shouldn't be done at runtime.
  96. */
  97. void removeGenericCurve(const String& name);
  98. /**
  99. * Creates an animation clip with no curves. After creation make sure to register some animation curves before
  100. * using it.
  101. */
  102. static HAnimationClip create();
  103. /**
  104. * Creates an animation clip with specified curves.
  105. *
  106. * @param[in] curves Curves to initialize the animation with.
  107. */
  108. static HAnimationClip create(const SPtr<AnimationCurves>& curves);
  109. public: // ***** INTERNAL ******
  110. /** @name Internal
  111. * @{
  112. */
  113. /** Creates a new AnimationClip without initializing it. Use create() for normal use. */
  114. static SPtr<AnimationClip> _createPtr(const SPtr<AnimationCurves>& curves);
  115. /** @} */
  116. protected:
  117. AnimationClip();
  118. AnimationClip(const SPtr<AnimationCurves>& curves);
  119. /**
  120. * Contains all the animation curves in the clip. It's important this field is immutable so it may be used on other
  121. * threads. This means any modifications to the field will require a brand new data structure to be generated and
  122. * all existing data copied (plus the modification).
  123. */
  124. SPtr<AnimationCurves> mCurves;
  125. /************************************************************************/
  126. /* SERIALIZATION */
  127. /************************************************************************/
  128. public:
  129. friend class AnimationClipRTTI;
  130. static RTTITypeBase* getRTTIStatic();
  131. RTTITypeBase* getRTTI() const override;
  132. /**
  133. * Creates an AnimationClip with no data. You must populate its data manually followed by a call to initialize().
  134. *
  135. * @note For serialization use only.
  136. */
  137. static SPtr<AnimationClip> createEmpty();
  138. };
  139. /** @} */
  140. }