VGearsAFile.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreSkeleton.h>
  17. #include <Ogre.h>
  18. #include "common/TypeDefine.h"
  19. #include "common/VGearsResource.h"
  20. namespace VGears{
  21. /**
  22. * Handles A files.
  23. *
  24. * A files are files with skeleton animation data.
  25. */
  26. class AFile : public Resource{
  27. public:
  28. /**
  29. * Constructor.
  30. *
  31. * @param[in] creator Pointer to the ResourceManager that is
  32. * creating this resource.
  33. * @param[in] name The unique name of the resource.
  34. * @param[in] handle @todo Understand and document.
  35. * @param[in] group The name of the resource group to which this
  36. * resource belong.
  37. * @param[in] is_manual True if the resource is manually loaded,
  38. * false otherwise.
  39. * @param[in] loader Pointer to a ManualResourceLoader
  40. * implementation which will be called when the Resource wishes to
  41. * load (should be supplied if is_manual is set to true). It can be
  42. * null, but the Resource will never be able to reload if anything
  43. * ever causes it to unload. Therefore provision of a proper
  44. * ManualResourceLoader instance is strongly recommended.
  45. */
  46. AFile(
  47. Ogre::ResourceManager *creator, const String &name, Ogre::ResourceHandle handle,
  48. const String &group, bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
  49. );
  50. /**
  51. * Destructor.
  52. */
  53. virtual ~AFile();
  54. /**
  55. * Duration of a frame.
  56. */
  57. static const Ogre::Real FRAME_DURATION;
  58. /**
  59. * The type of resource.
  60. */
  61. static const String RESOURCE_TYPE;
  62. /**
  63. * Adds an animation to an skeleton.
  64. *
  65. * @param[in,out] skeleton Skeleton to add the animation to.
  66. * @param[in] name Animation name.
  67. * @param[in] flip_forward_axis Reverse the root translation's forward axis.
  68. */
  69. void AddTo(Ogre::SkeletonPtr skeleton, const String &name, bool flip_forward_axis = false) const;
  70. /**
  71. * Retrieves the bounds of the animation's root translations.
  72. *
  73. * @param[in] flip_forward_axis Apply the field-model coordinate conversion.
  74. * @return Bounds containing the origin and all root translations.
  75. */
  76. Ogre::AxisAlignedBox GetRootTranslationBounds(bool flip_forward_axis = false) const;
  77. typedef std::vector<Ogre::Vector3> BoneRotationList;
  78. /**
  79. * A frame in an animation.
  80. */
  81. struct Frame{
  82. /**
  83. * The rotation of the whole skeleton in the frame.
  84. */
  85. Ogre::Vector3 root_rotation;
  86. /**
  87. * The translation of the whole skeleton in the frame.
  88. */
  89. Ogre::Vector3 root_translation;
  90. /**
  91. * The list of individual bone rotations in the frame.
  92. */
  93. BoneRotationList bone_rotations;
  94. };
  95. typedef std::vector<Frame> FrameList;
  96. /**
  97. * Retrieves the list of frames in the file.
  98. *
  99. * @return The list of frames.
  100. */
  101. FrameList& GetFrames(){return frames_;}
  102. /**
  103. * Sets the number of bones.
  104. *
  105. * @param[in] bone_count The number of bones.
  106. */
  107. void SetBoneCount(const uint32 bone_count);
  108. protected:
  109. /**
  110. * Loads the file.
  111. */
  112. virtual void loadImpl() override final;
  113. /**
  114. * Unloads the file.
  115. */
  116. virtual void unloadImpl() override final;
  117. /**
  118. * Calculates the size of the file.
  119. *
  120. * @return The size of the file.
  121. * @todo Units?
  122. */
  123. size_t CalculateSize() const;
  124. /**
  125. * Sets the rotation for a frame.
  126. *
  127. * @param[in] key_frame The frame.
  128. * @param[in] rotation The rotation for the frame
  129. */
  130. void SetFrameRotation(
  131. Ogre::TransformKeyFrame *key_frame,
  132. const Ogre::Vector3 &rotation
  133. ) const;
  134. private:
  135. /**
  136. * The number of bones.
  137. */
  138. uint32 bone_count_;
  139. /**
  140. * The list of frames.
  141. */
  142. FrameList frames_;
  143. };
  144. typedef Ogre::SharedPtr<AFile> AFilePtr;
  145. }