QGearsAFile.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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/QGearsResource.h"
  20. namespace QGears{
  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 creator[in] Pointer to the ResourceManager that is
  32. * creating this resource.
  33. * @param name[in] The unique name of the resource.
  34. * @param handle[in] @todo Understand and document.
  35. * @param group[in] The name of the resource group to which this
  36. * resource belong.
  37. * @param is_manual[in] True if the resource is manually loaded,
  38. * false otherwise.
  39. * @param loader[in] 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,
  48. Ogre::ResourceHandle handle, const String &group,
  49. bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
  50. );
  51. /**
  52. * Destructor.
  53. */
  54. virtual ~AFile();
  55. /**
  56. * Duration of a frame.
  57. */
  58. static const Ogre::Real FRAME_DURATION;
  59. /**
  60. * The type of resource.
  61. */
  62. static const String RESOURCE_TYPE;
  63. /**
  64. * Adds an animation to an skeleton.
  65. *
  66. * @parma skeleton[in|out] Skeleton to add the animation to.
  67. * @param name[in] Animation name.
  68. */
  69. void AddTo(Ogre::SkeletonPtr skeleton, const String &name) const;
  70. typedef std::vector<Ogre::Vector3> BoneRotationList;
  71. /**
  72. * A frame in an animation.
  73. */
  74. struct Frame{
  75. /**
  76. * The rotation of the whole skeleton in the frame.
  77. */
  78. Ogre::Vector3 root_rotation;
  79. /**
  80. * The translation of the whole skeleton in the frame.
  81. */
  82. Ogre::Vector3 root_translation;
  83. /**
  84. * The list of individual bone rotations in the frame.
  85. */
  86. BoneRotationList bone_rotations;
  87. };
  88. typedef std::vector<Frame> FrameList;
  89. /**
  90. * Retrieves the list of frames in the file.
  91. *
  92. * @return The list of frames.
  93. */
  94. FrameList& GetFrames(){return frames_;}
  95. /**
  96. * Sets the number of bones.
  97. *
  98. * @param bone_count[in] The number of bones.
  99. */
  100. void SetBoneCount(const uint32 bone_count);
  101. protected:
  102. /**
  103. * Loads the file.
  104. */
  105. virtual void loadImpl() override final;
  106. /**
  107. * Unloads the file.
  108. */
  109. virtual void unloadImpl() override final;
  110. /**
  111. * Calculates the size of the file.
  112. *
  113. * @return The size of the file.
  114. * @todo Units?
  115. */
  116. size_t CalculateSize() const;
  117. /**
  118. * Sets the rotation for a frame.
  119. *
  120. * @param key_frame[in] The frame.
  121. * @param rotation[in] The rotation for the frame
  122. */
  123. void SetFrameRotation(
  124. Ogre::TransformKeyFrame *key_frame,
  125. const Ogre::Vector3 &rotation
  126. ) const;
  127. private:
  128. /**
  129. * The number of bones.
  130. */
  131. uint32 bone_count_;
  132. /**
  133. * The list of frames.
  134. */
  135. FrameList frames_;
  136. };
  137. typedef Ogre::SharedPtr<AFile> AFilePtr;
  138. }