Q3BSPFileData.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, assimp 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 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. #ifndef ASSIMP_Q3BSPFILEDATA_H_INC
  34. #define ASSIMP_Q3BSPFILEDATA_H_INC
  35. #include <vector>
  36. namespace Assimp
  37. {
  38. namespace Q3BSP
  39. {
  40. static const unsigned int CE_BSP_LIGHTMAPWIDTH = 128;
  41. static const unsigned int CE_BSP_LIGHTMAPHEIGHT = 128;
  42. static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * 128 ( height ) * 3 ( channels / RGB ).
  43. static const int VERION_Q3LEVEL = 46; ///< Supported version.
  44. /// Geometric type enumeration
  45. enum Q3BSPGeoType
  46. {
  47. Polygon = 1,
  48. Patch,
  49. TriangleMesh,
  50. Billboard
  51. };
  52. /// Integer vector.
  53. struct ceVec3i
  54. {
  55. int x, y, z;
  56. ceVec3i(): x( 0 ), y( 0 ), z( 0 ) { /* empty */ }
  57. ceVec3i( int iX, int iY=0, int iZ=0) : x( iX ), y( iY ), z( iZ ) { /* empty */ }
  58. };
  59. /// Fileheader
  60. struct sQ3BSPHeader
  61. {
  62. char strID[ 4 ]; //!< Should be "IBSP"
  63. int iVersion; //!< 46 for standard levels
  64. };
  65. /// Descripes an entry.
  66. struct sQ3BSPLump
  67. {
  68. int iOffset; ///< Offset from startpointer of file
  69. int iSize; ///< Size fo part
  70. };
  71. struct vec2f
  72. {
  73. float x,y;
  74. };
  75. struct vec3f
  76. {
  77. float x, y, z;
  78. };
  79. /// Vertex of a Q3 level
  80. struct sQ3BSPVertex
  81. {
  82. vec3f vPosition; ///< Position of vertex
  83. vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture
  84. vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap
  85. vec3f vNormal; ///< vertex normale
  86. unsigned char bColor[ 4 ]; ///< Color in RGBA
  87. };
  88. /// A face in bsp format info
  89. struct sQ3BSPFace
  90. {
  91. int iTextureID; ///< Index in texture array
  92. int iEffect; ///< Index in effectarray (-1 = no effect)
  93. int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
  94. int iVertexIndex; ///< Start index of polygon
  95. int iNumOfVerts; ///< Number of vertices
  96. int iFaceVertexIndex; ///< Index of first mesh vertex
  97. int iNumOfFaceVerts; ///< Anzahl der Meshvertices
  98. int iLightmapID; ///< Index to the lightmap array
  99. int iLMapCorner[ 2 ]; ///< Die Ecke der Lightmap in der Textur
  100. int iLMapSize[ 2 ]; ///< Size of the lightmap stored on the texture
  101. vec3f vLMapPos; ///< 3D-Ursprung der Lightmap
  102. vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-Vektoren
  103. vec3f vNormal; ///< Polygonnormale
  104. int patchWidth, patchHeight; ///< bezier patch
  105. };
  106. /// A quake3 texture name.
  107. struct sQ3BSPTexture
  108. {
  109. char strName[ 64 ]; ///< Name of the texture without extention
  110. int iFlags; ///< Not used
  111. int iContents; ///< Not used
  112. };
  113. /// A lightmap of the level, size 128 x 128, RGB components.
  114. struct sQ3BSPLightmap
  115. {
  116. unsigned char bLMapData[ CE_BSP_LIGHTMAPSIZE ];
  117. sQ3BSPLightmap()
  118. {
  119. memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE );
  120. }
  121. };
  122. struct SubPatch
  123. {
  124. std::vector<size_t> indices;
  125. int lightmapID;
  126. };
  127. enum eLumps
  128. {
  129. kEntities = 0,
  130. kTextures,
  131. kPlanes,
  132. kNodes,
  133. kLeafs,
  134. kLeafFaces,
  135. kLeafBrushes,
  136. kModels,
  137. kBrushes,
  138. kBrushSides,
  139. kVertices,
  140. kMeshVerts,
  141. kShaders,
  142. kFaces,
  143. kLightmaps,
  144. kLightVolumes,
  145. kVisData,
  146. kMaxLumps
  147. };
  148. struct Q3BSPModel
  149. {
  150. std::vector<unsigned char> m_Data;
  151. std::vector<sQ3BSPLump*> m_Lumps;
  152. std::vector<sQ3BSPVertex*> m_Vertices;
  153. std::vector<sQ3BSPFace*> m_Faces;
  154. std::vector<int> m_Indices;
  155. std::vector<sQ3BSPTexture*> m_Textures;
  156. std::vector<sQ3BSPLightmap*> m_Lightmaps;
  157. std::vector<char> m_EntityData;
  158. std::string m_ModelName;
  159. Q3BSPModel() :
  160. m_Data(),
  161. m_Lumps(),
  162. m_Vertices(),
  163. m_Faces(),
  164. m_Indices(),
  165. m_Textures(),
  166. m_Lightmaps(),
  167. m_EntityData(),
  168. m_ModelName( "" )
  169. {
  170. // empty
  171. }
  172. ~Q3BSPModel()
  173. {
  174. for ( unsigned int i=0; i<m_Lumps.size(); i++ )
  175. if ( NULL != m_Lumps[i] )
  176. delete m_Lumps[i];
  177. for ( unsigned int i=0; i<m_Vertices.size(); i++ )
  178. if ( NULL != m_Vertices[ i ] )
  179. delete m_Vertices[ i ];
  180. for ( unsigned int i=0; i<m_Faces.size(); i++ )
  181. if ( NULL != m_Faces[ i ] )
  182. delete m_Faces[ i ];
  183. for ( unsigned int i=0; i<m_Textures.size(); i++ )
  184. if ( NULL != m_Textures[ i ] )
  185. delete m_Textures[ i ];
  186. for ( unsigned int i=0; i<m_Lightmaps.size(); i++ )
  187. if ( NULL != m_Lightmaps[ i ] )
  188. delete m_Lightmaps[ i ];
  189. m_Lumps.clear();
  190. m_Vertices.clear();
  191. m_Faces.clear();
  192. m_Textures.clear();
  193. m_Lightmaps.clear();
  194. }
  195. };
  196. } // Namespace Q3BSP
  197. } // Namespace Assimp
  198. #endif // ASSIMP_Q3BSPFILEDATA_H_INC