TargetAnimation.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Defines a helper class for the ASE and 3DS loaders to
  34. help them compute camera and spot light animation channels */
  35. #ifndef AI_TARGET_ANIMATION_H_INC
  36. #define AI_TARGET_ANIMATION_H_INC
  37. #include <assimp/anim.h>
  38. #include <vector>
  39. namespace Assimp {
  40. // ---------------------------------------------------------------------------
  41. /** Helper class to iterate through all keys in an animation channel.
  42. *
  43. * Missing tracks are interpolated. This is a helper class for
  44. * TargetAnimationHelper, but it can be freely used for other purposes.
  45. */
  46. class KeyIterator {
  47. public:
  48. // ------------------------------------------------------------------
  49. /** Constructs a new key iterator
  50. *
  51. * @param _objPos Object position track. May be nullptr.
  52. * @param _targetObjPos Target object position track. May be nullptr.
  53. * @param defaultObjectPos Default object position to be used if
  54. * no animated track is available. May be nullptr.
  55. * @param defaultTargetPos Default target position to be used if
  56. * no animated track is available. May be nullptr.
  57. */
  58. KeyIterator(const std::vector<aiVectorKey> *_objPos,
  59. const std::vector<aiVectorKey> *_targetObjPos,
  60. const aiVector3D *defaultObjectPos = nullptr,
  61. const aiVector3D *defaultTargetPos = nullptr);
  62. // ------------------------------------------------------------------
  63. /** Returns true if all keys have been processed
  64. */
  65. bool Finished() const { return reachedEnd; }
  66. // ------------------------------------------------------------------
  67. /** Increment the iterator
  68. */
  69. void operator++();
  70. inline void operator++(int) { return ++(*this); }
  71. // ------------------------------------------------------------------
  72. /** Getters to retrieve the current state of the iterator
  73. */
  74. inline const aiVector3D &GetCurPosition() const { return curPosition; }
  75. inline const aiVector3D &GetCurTargetPosition() const { return curTargetPosition; }
  76. inline double GetCurTime() const { return curTime; }
  77. private:
  78. //! Did we reach the end?
  79. bool reachedEnd;
  80. //! Represents the current position of the iterator
  81. aiVector3D curPosition, curTargetPosition;
  82. double curTime;
  83. //! Input tracks and the next key to process
  84. const std::vector<aiVectorKey> *objPos, *targetObjPos;
  85. unsigned int nextObjPos, nextTargetObjPos;
  86. std::vector<aiVectorKey> defaultObjPos, defaultTargetObjPos;
  87. };
  88. // ---------------------------------------------------------------------------
  89. /** Helper class for the 3DS and ASE loaders to compute camera and spot light
  90. * animations.
  91. *
  92. * 3DS and ASE store the differently to Assimp - there is an animation
  93. * channel for the camera/spot light itself and a separate position
  94. * animation channels specifying the position of the camera/spot light
  95. * look-at target */
  96. class TargetAnimationHelper {
  97. public:
  98. /// @brief The class constructor.
  99. TargetAnimationHelper() :
  100. targetPositions(nullptr),
  101. objectPositions(nullptr) {
  102. // empty
  103. }
  104. /// @brief The class destructor.
  105. ~TargetAnimationHelper() = default;
  106. // ------------------------------------------------------------------
  107. /** Sets the target animation channel
  108. *
  109. * This channel specifies the position of the camera/spot light
  110. * target at a specific position.
  111. *
  112. * @param targetPositions Translation channel*/
  113. void SetTargetAnimationChannel(const std::vector<aiVectorKey> *targetPositions);
  114. // ------------------------------------------------------------------
  115. /** Sets the main animation channel
  116. *
  117. * @param objectPositions Translation channel */
  118. void SetMainAnimationChannel(const std::vector<aiVectorKey> *objectPositions);
  119. // ------------------------------------------------------------------
  120. /** Sets the main animation channel to a fixed value
  121. *
  122. * @param fixed Fixed value for the main animation channel*/
  123. void SetFixedMainAnimationChannel(const aiVector3D &fixed);
  124. // ------------------------------------------------------------------
  125. /** Computes final animation channels
  126. * @param distanceTrack Receive camera translation keys ... != nullptr. */
  127. void Process(std::vector<aiVectorKey> *distanceTrack);
  128. private:
  129. const std::vector<aiVectorKey> *targetPositions, *objectPositions;
  130. aiVector3D fixedMain;
  131. };
  132. } // namespace Assimp
  133. #endif // include guard