QGearsHRCFile.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 <OgreResource.h>
  17. #include <OgreMesh.h>
  18. #include <OgreSkeleton.h>
  19. #include "common/TypeDefine.h"
  20. namespace QGears{
  21. class HRCMeshLoader;
  22. class HRCSkeletonLoader;
  23. /**
  24. * Handles HRC files.
  25. *
  26. * HRC files describe bone hierarchy in an skeleton.
  27. */
  28. class HRCFile : public Ogre::Resource{
  29. public:
  30. /**
  31. * Scale down constant.
  32. */
  33. static const float DOWN_SCALER;
  34. /**
  35. * Constructor.
  36. *
  37. * @param creator[in] Pointer to the ResourceManager that is
  38. * creating this resource.
  39. * @param name[in] The unique name of the resource.
  40. * @param handle[in] @todo Understand and document.
  41. * @param group[in] The name of the resource group to which this
  42. * resource belong.
  43. * @param is_manual[in] True if the resource is manually loaded,
  44. * false otherwise.
  45. * @param loader[in] Pointer to a ManualResourceLoader
  46. * implementation which will be called when the Resource wishes to
  47. * load (should be supplied if is_manual is set to true). It can be
  48. * null, but the Resource will never be able to reload if anything
  49. * ever causes it to unload. Therefore provision of a proper
  50. * ManualResourceLoader instance is strongly recommended.
  51. */
  52. HRCFile(
  53. Ogre::ResourceManager *creator, const String &name,
  54. Ogre::ResourceHandle handle, const String &group,
  55. bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
  56. );
  57. /**
  58. * Destructor.
  59. */
  60. virtual ~HRCFile();
  61. typedef std::vector<String> RSDNameList;
  62. /**
  63. * A bone in a skeleton.
  64. */
  65. struct Bone{
  66. /**
  67. * Bone name.
  68. */
  69. String name;
  70. /**
  71. * Parent bone name.
  72. */
  73. String parent;
  74. /**
  75. * Bone length
  76. *
  77. * @todo In pixels?
  78. */
  79. Ogre::Real length;
  80. /**
  81. * List of RDS file assigned to the bone.
  82. *
  83. * RSD are Resource Data Files.
  84. */
  85. RSDNameList rsd_names;
  86. };
  87. typedef std::vector<Bone> BoneList;
  88. /**
  89. * Sets a name for the skelenton.
  90. *
  91. * @param name[in] The name for the skeleton.
  92. */
  93. virtual void SetSkeletonName(const String& name);
  94. /**
  95. * Retrieves the skeleton name.
  96. *
  97. * @return The skeleton name.
  98. */
  99. virtual const String& GetSkeletonName() const{
  100. return skeleton_name_;
  101. }
  102. /**
  103. * Retrieves the skeleton file name.
  104. *
  105. * @return The skeleton file name.
  106. */
  107. virtual String GetSkeletonFileName() const;
  108. /**
  109. * Retrieves the file name of the mesh assigned to the skeleton.
  110. *
  111. * @return The mesh file name.
  112. */
  113. virtual String GetMeshFileName() const;
  114. /**
  115. * Retrieves the list of bones in the skeleton.
  116. *
  117. * @return The list of bones.
  118. */
  119. virtual BoneList& GetBones(){return bones_;}
  120. /**
  121. * Retrieves the list of bones in the skeleton.
  122. *
  123. * @return The list of bones.
  124. */
  125. virtual const BoneList& GetBones() const{return bones_;}
  126. /**
  127. * Retrieves the skeleton.
  128. *
  129. * @return The skeleton.
  130. */
  131. virtual Ogre::SkeletonPtr GetSkeleton() const;
  132. /**
  133. * The type of resource.
  134. */
  135. static const String RESOURCE_TYPE;
  136. protected:
  137. /**
  138. * Loads the file.
  139. */
  140. virtual void loadImpl() override final;
  141. /**
  142. * Unloads the file.
  143. */
  144. virtual void unloadImpl() override final;
  145. /**
  146. * Calculates the size of the skeleton.
  147. *
  148. * @return The size of the skeleton.
  149. * @todo Units?
  150. */
  151. virtual size_t CalculateSize() const;
  152. /**
  153. * Calculates the size of a bone.
  154. *
  155. * @param bone[in] The bone whose size to calculate.
  156. * @return The size of the bone.
  157. * @todo Units?
  158. */
  159. virtual size_t CalculateSize(const Bone &bone) const;
  160. private:
  161. /**
  162. * The skeleton name.
  163. */
  164. String skeleton_name_;
  165. /**
  166. * The bones in the skeleton.
  167. */
  168. BoneList bones_;
  169. /**
  170. * The mesh loader.
  171. */
  172. HRCMeshLoader *mesh_loader_;
  173. /**
  174. * The skeleton loader.
  175. */
  176. HRCSkeletonLoader *skeleton_loader_;
  177. /**
  178. * The skeleton.
  179. */
  180. Ogre::SkeletonPtr skeleton_;
  181. /**
  182. * The mesh assigned to the skeleton.
  183. */
  184. Ogre::MeshPtr mesh_;
  185. };
  186. typedef Ogre::SharedPtr<HRCFile> HRCFilePtr;
  187. }