QGearsPFile.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-11 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #ifndef __QGearsPFile_H__
  23. #define __QGearsPFile_H__
  24. #include <OgreAxisAlignedBox.h>
  25. #include <OgreColourValue.h>
  26. #include <OgreMesh.h>
  27. #include <OgreResource.h>
  28. #include <Ogre.h>
  29. #include "common/TypeDefine.h"
  30. #include "common/QGearsManualObject.h"
  31. #include "data/QGearsRSDFile.h"
  32. namespace QGears
  33. {
  34. class PFile : public Ogre::Resource
  35. {
  36. public:
  37. PFile( Ogre::ResourceManager *creator, const String &name
  38. ,Ogre::ResourceHandle handle, const String &group
  39. ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
  40. virtual ~PFile();
  41. virtual bool isValid( void );
  42. virtual bool isPolygonDefinitionListValid( void );
  43. virtual void addGroups( Ogre::Mesh *mesh, const String &bone_name
  44. ,const RSDFilePtr &rsd ) const;
  45. struct Edge
  46. {
  47. uint16 index[2];
  48. };
  49. struct PolygonDefinition
  50. {
  51. uint16 unknown_00;
  52. uint16 vertex[3];
  53. uint16 normal[3];
  54. uint16 edge[3];
  55. uint16 unknown_14;
  56. uint16 unknown_16;
  57. };
  58. struct MaterialInformation
  59. {
  60. uint8 unknown[100];
  61. };
  62. struct Group
  63. {
  64. uint32 primitive_type;
  65. uint32 polygon_start_index;
  66. uint32 num_polygons;
  67. uint32 vertex_start_index;
  68. uint32 num_vertices;
  69. uint32 edge_start_index;
  70. uint32 num_edges;
  71. uint32 unknown_1C;
  72. uint32 unknown_20;
  73. uint32 unknown_24;
  74. uint32 unknown_28;
  75. uint32 texture_coordinate_start_index;
  76. uint32 has_texture;
  77. uint32 texture_index;
  78. };
  79. struct BBoxEntry
  80. {
  81. uint32 unknown;
  82. Ogre::AxisAlignedBox bbox;
  83. };
  84. typedef Ogre::ColourValue Colour;
  85. typedef std::vector<Ogre::Vector3> VertexList;
  86. typedef std::vector<Ogre::Vector3> NormalList;
  87. typedef std::vector<Ogre::Vector3> Unkown1List;
  88. typedef std::vector<Ogre::Vector2> TextureCoordinateList;
  89. typedef std::vector<Colour> VertexColorList;
  90. typedef std::vector<Colour> PolygonColorList;
  91. typedef std::vector<Edge> EdgeList;
  92. typedef std::vector<PolygonDefinition> PolygonDefinitionList;
  93. typedef std::vector<Group> GroupList;
  94. typedef std::vector<BBoxEntry> BBoxList;
  95. virtual VertexList& getVertices() { return m_vertices; }
  96. virtual NormalList& getNormals() { return m_normals; }
  97. virtual Unkown1List& getUnknown1() { return m_unknown1; }
  98. virtual TextureCoordinateList& getTextureCoordinates() { return m_texture_coordinates; }
  99. virtual VertexColorList& getVertexColors() { return m_vertex_colors; }
  100. virtual PolygonColorList& getPolygonColors() { return m_polygon_colors; }
  101. virtual EdgeList& getEdges() { return m_edges; }
  102. virtual PolygonDefinitionList& getPolygonDefinitions() { return m_polygon_definitions; }
  103. virtual GroupList& getGroups() { return m_groups; }
  104. virtual BBoxList& getBBoxes() { return m_bboxes; }
  105. static const String RESOURCE_TYPE;
  106. protected:
  107. virtual void loadImpl();
  108. virtual void unloadImpl();
  109. virtual size_t calculateSize() const;
  110. virtual void addGroup( const Group &group, ManualObject &mo
  111. ,const String &sub_name
  112. ,const String &material_base_name
  113. ,const Ogre::Bone *bone ) const;
  114. virtual Ogre::Vector3 getPosition( const Ogre::Bone *bone ) const;
  115. static const Ogre::Quaternion STATIC_ROTATION;
  116. static Ogre::Quaternion createStaticRotation();
  117. private:
  118. VertexList m_vertices;
  119. NormalList m_normals;
  120. Unkown1List m_unknown1;
  121. TextureCoordinateList m_texture_coordinates;
  122. VertexColorList m_vertex_colors;
  123. PolygonColorList m_polygon_colors;
  124. EdgeList m_edges;
  125. PolygonDefinitionList m_polygon_definitions;
  126. GroupList m_groups;
  127. BBoxList m_bboxes;
  128. };
  129. typedef Ogre::SharedPtr<PFile> PFilePtr;
  130. }
  131. #endif // __QGearsPFile_H__