2
0

Q3BSPFileData.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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. #include <string.h>
  37. #include <string>
  38. namespace Assimp {
  39. namespace Q3BSP {
  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. Polygon = 1,
  47. Patch,
  48. TriangleMesh,
  49. Billboard
  50. };
  51. /// Integer vector.
  52. struct ceVec3i {
  53. int x, y, z;
  54. ceVec3i(): x( 0 ), y( 0 ), z( 0 ) { /* empty */ }
  55. ceVec3i( int iX, int iY=0, int iZ=0) : x( iX ), y( iY ), z( iZ ) { /* empty */ }
  56. };
  57. /// the file header
  58. struct sQ3BSPHeader {
  59. char strID[ 4 ]; ///< Should be "IBSP"
  60. int iVersion; ///< 46 for standard levels
  61. };
  62. /// Describes an entry.
  63. struct sQ3BSPLump {
  64. int iOffset; ///< Offset from start pointer of file
  65. int iSize; ///< Size of part
  66. };
  67. struct vec2f {
  68. float x,y;
  69. };
  70. struct vec3f {
  71. float x, y, z;
  72. };
  73. /// Vertex of a Q3 level
  74. struct sQ3BSPVertex {
  75. vec3f vPosition; ///< Position of vertex
  76. vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture
  77. vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap
  78. vec3f vNormal; ///< vertex normal
  79. unsigned char bColor[ 4 ]; ///< Color in RGBA
  80. };
  81. /// A face in bsp format info
  82. struct sQ3BSPFace {
  83. int iTextureID; ///< Index in texture array
  84. int iEffect; ///< Index in effect array (-1 = no effect)
  85. int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard
  86. int iVertexIndex; ///< Start index of polygon
  87. int iNumOfVerts; ///< Number of vertices
  88. int iFaceVertexIndex; ///< Index of first mesh vertex
  89. int iNumOfFaceVerts; ///< number of mesh vertices
  90. int iLightmapID; ///< Index to the light-map array
  91. int iLMapCorner[ 2 ]; ///< edge of the light-map in texture
  92. int iLMapSize[ 2 ]; ///< Size of the light-map stored on the texture
  93. vec3f vLMapPos; ///< 3D origin of the light-map
  94. vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-vectors
  95. vec3f vNormal; ///< Polygon normals
  96. int patchWidth, patchHeight; ///< bezier patch
  97. };
  98. /// A quake3 texture name.
  99. struct sQ3BSPTexture {
  100. char strName[ 64 ]; ///< Name of the texture without extension
  101. int iFlags; ///< Not used
  102. int iContents; ///< Not used
  103. };
  104. /// A light-map of the level, size 128 x 128, RGB components.
  105. struct sQ3BSPLightmap {
  106. unsigned char bLMapData[ CE_BSP_LIGHTMAPSIZE ];
  107. sQ3BSPLightmap() {
  108. ::memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE );
  109. }
  110. };
  111. struct SubPatch {
  112. std::vector<size_t> indices;
  113. int lightmapID;
  114. };
  115. enum eLumps {
  116. kEntities = 0,
  117. kTextures,
  118. kPlanes,
  119. kNodes,
  120. kLeafs,
  121. kLeafFaces,
  122. kLeafBrushes,
  123. kModels,
  124. kBrushes,
  125. kBrushSides,
  126. kVertices,
  127. kMeshVerts,
  128. kShaders,
  129. kFaces,
  130. kLightmaps,
  131. kLightVolumes,
  132. kVisData,
  133. kMaxLumps
  134. };
  135. struct Q3BSPModel {
  136. std::vector<unsigned char> m_Data;
  137. std::vector<sQ3BSPLump*> m_Lumps;
  138. std::vector<sQ3BSPVertex*> m_Vertices;
  139. std::vector<sQ3BSPFace*> m_Faces;
  140. std::vector<int> m_Indices;
  141. std::vector<sQ3BSPTexture*> m_Textures;
  142. std::vector<sQ3BSPLightmap*> m_Lightmaps;
  143. std::vector<char> m_EntityData;
  144. std::string m_ModelName;
  145. Q3BSPModel() = default;
  146. ~Q3BSPModel() {
  147. for ( unsigned int i=0; i<m_Lumps.size(); i++ ) {
  148. delete m_Lumps[ i ];
  149. }
  150. for ( unsigned int i=0; i<m_Vertices.size(); i++ ) {
  151. delete m_Vertices[ i ];
  152. }
  153. for ( unsigned int i=0; i<m_Faces.size(); i++ ) {
  154. delete m_Faces[ i ];
  155. }
  156. for ( unsigned int i=0; i<m_Textures.size(); i++ ) {
  157. delete m_Textures[ i ];
  158. }
  159. for ( unsigned int i=0; i<m_Lightmaps.size(); i++ ) {
  160. delete m_Lightmaps[ i ];
  161. }
  162. m_Lumps.clear();
  163. m_Vertices.clear();
  164. m_Faces.clear();
  165. m_Textures.clear();
  166. m_Lightmaps.clear();
  167. }
  168. };
  169. } // Namespace Q3BSP
  170. } // Namespace Assimp
  171. #endif // ASSIMP_Q3BSPFILEDATA_H_INC