HMPLoader.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, ASSIMP Development 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 Development 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. //!
  34. //! @file Definition of HMP importer class
  35. //!
  36. #ifndef AI_HMPLOADER_H_INCLUDED
  37. #define AI_HMPLOADER_H_INCLUDED
  38. #include "BaseImporter.h"
  39. #include "../include/aiTypes.h"
  40. #include "../include/aiTexture.h"
  41. #include "../include/aiMaterial.h"
  42. struct aiNode;
  43. #include "MDLLoader.h"
  44. namespace Assimp
  45. {
  46. class MaterialHelper;
  47. #define AI_HMP_MAGIC_NUMBER_BE_4 'HMP4'
  48. #define AI_HMP_MAGIC_NUMBER_LE_4 '4PMH'
  49. #define AI_HMP_MAGIC_NUMBER_BE_5 'HMP5'
  50. #define AI_HMP_MAGIC_NUMBER_LE_5 '5PMH'
  51. #define AI_HMP_MAGIC_NUMBER_BE_7 'HMP7'
  52. #define AI_HMP_MAGIC_NUMBER_LE_7 '7PMH'
  53. namespace HMP
  54. {
  55. // ugly compiler dependent packing stuff
  56. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  57. # pragma pack(push,1)
  58. # define PACK_STRUCT
  59. #elif defined( __GNUC__ )
  60. # define PACK_STRUCT __attribute__((packed))
  61. #else
  62. # error Compiler not supported. Never do this again.
  63. #endif
  64. // ---------------------------------------------------------------------------
  65. /** Data structure for the header of a HMP5 file.
  66. * This is also used by HMP4 and HMP7, but with modifications
  67. */
  68. struct Header_HMP5
  69. {
  70. int8_t ident[4]; // "HMP5"
  71. int32_t version;
  72. // ignored
  73. float scale[3];
  74. float scale_origin[3];
  75. float boundingradius;
  76. //! Size of one triangle in x direction
  77. float ftrisize_x;
  78. //! Size of one triangle in y direction
  79. float ftrisize_y;
  80. //! Number of vertices in x direction
  81. float fnumverts_x;
  82. //! Number of skins in the file
  83. int32_t numskins;
  84. // can ignore this?
  85. int32_t skinwidth;
  86. int32_t skinheight;
  87. //!Number of vertices in the file
  88. int32_t numverts;
  89. // ignored and zero
  90. int32_t numtris;
  91. //! only one supported ...
  92. int32_t numframes;
  93. //! Always 0 ...
  94. int32_t num_stverts;
  95. int32_t flags;
  96. float size;
  97. } PACK_STRUCT;
  98. // ---------------------------------------------------------------------------
  99. /** Data structure for a terrain vertex in a HMP4 file
  100. */
  101. struct Vertex_HMP4
  102. {
  103. uint16_t p_pos[3];
  104. uint8_t normals162index;
  105. uint8_t pad;
  106. } PACK_STRUCT;
  107. // ---------------------------------------------------------------------------
  108. /** Data structure for a terrain vertex in a HMP5 file
  109. */
  110. struct Vertex_HMP5
  111. {
  112. uint16_t z;
  113. uint8_t normals162index;
  114. uint8_t pad;
  115. } PACK_STRUCT;
  116. // ---------------------------------------------------------------------------
  117. /** Data structure for a terrain vertex in a HMP7 file
  118. */
  119. struct Vertex_HMP7
  120. {
  121. uint16_t z;
  122. int8_t normal_x,normal_y;
  123. } PACK_STRUCT;
  124. // reset packing to the original value
  125. #if defined(_MSC_VER) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  126. # pragma pack( pop )
  127. #endif
  128. #undef PACK_STRUCT
  129. }; //! namespace HMP
  130. // ---------------------------------------------------------------------------
  131. /** Used to load 3D GameStudio HMP files (terrains)
  132. */
  133. class HMPImporter : public MDLImporter
  134. {
  135. friend class Importer;
  136. protected:
  137. /** Constructor to be privately used by Importer */
  138. HMPImporter();
  139. /** Destructor, private as well */
  140. ~HMPImporter();
  141. public:
  142. // -------------------------------------------------------------------
  143. /** Returns whether the class can handle the format of the given file.
  144. * See BaseImporter::CanRead() for details. */
  145. bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
  146. protected:
  147. // -------------------------------------------------------------------
  148. /** Called by Importer::GetExtensionList() for each loaded importer.
  149. * See BaseImporter::GetExtensionList() for details
  150. */
  151. void GetExtensionList(std::string& append)
  152. {
  153. append.append("*.hmp");
  154. }
  155. // -------------------------------------------------------------------
  156. /** Imports the given file into the given scene structure.
  157. * See BaseImporter::InternReadFile() for details
  158. */
  159. void InternReadFile( const std::string& pFile, aiScene* pScene,
  160. IOSystem* pIOHandler);
  161. protected:
  162. // -------------------------------------------------------------------
  163. /** Import a HMP4 file
  164. */
  165. void InternReadFile_HMP4( );
  166. // -------------------------------------------------------------------
  167. /** Import a HMP5 file
  168. */
  169. void InternReadFile_HMP5( );
  170. // -------------------------------------------------------------------
  171. /** Import a HMP7 file
  172. */
  173. void InternReadFile_HMP7( );
  174. // -------------------------------------------------------------------
  175. /** Validate a HMP 5,4,7 file header
  176. */
  177. void ValidateHeader_HMP457( );
  178. // -------------------------------------------------------------------
  179. /** Try to load one material from the file, if this fails create
  180. * a default material
  181. */
  182. void CreateMaterial(const unsigned char* szCurrent,
  183. const unsigned char** szCurrentOut);
  184. // -------------------------------------------------------------------
  185. /** Build a list of output faces and vertices. The function
  186. * triangulates the height map read from the file
  187. * \param width Width of the height field
  188. * \param width Height of the height field
  189. */
  190. void CreateOutputFaceList(unsigned int width,unsigned int height);
  191. // -------------------------------------------------------------------
  192. /** Generate planar texture coordinates for a terrain
  193. * \param width Width of the terrain, in vertices
  194. * \param height Height of the terrain, in vertices
  195. */
  196. void GenerateTextureCoords(const unsigned int width,
  197. const unsigned int height);
  198. // -------------------------------------------------------------------
  199. /** Read the first skin from the file and skip all others ...
  200. * \param iNumSkins Number of skins in the file
  201. * \param szCursor Position of the first skin (offset 84)
  202. */
  203. void ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szCursor,
  204. const unsigned char** szCursorOut);
  205. private:
  206. };
  207. }; // end of namespace Assimp
  208. #endif // AI_HMPIMPORTER_H_INC