1 /* 2 Open Asset Import Library (assimp) 3 ---------------------------------------------------------------------- 4 5 Copyright (c) 2006-2021, assimp team 6 7 8 All rights reserved. 9 10 Redistribution and use of this software in source and binary forms, 11 with or without modification, are permitted provided that the 12 following conditions are met: 13 14 * Redistributions of source code must retain the above 15 copyright notice, this list of conditions and the 16 following disclaimer. 17 18 * Redistributions in binary form must reproduce the above 19 copyright notice, this list of conditions and the 20 following disclaimer in the documentation and/or other 21 materials provided with the distribution. 22 23 * Neither the name of the assimp team, nor the names of its 24 contributors may be used to endorse or promote products 25 derived from this software without specific prior 26 written permission of the assimp team. 27 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 40 ---------------------------------------------------------------------- 41 */ 42 #ifndef ASSIMP_Q3BSPFILEDATA_H_INC 43 #define ASSIMP_Q3BSPFILEDATA_H_INC 44 45 #include <vector> 46 #include <string.h> 47 #include <string> 48 49 namespace Assimp { 50 namespace Q3BSP { 51 52 static const unsigned int CE_BSP_LIGHTMAPWIDTH = 128; 53 static const unsigned int CE_BSP_LIGHTMAPHEIGHT = 128; 54 55 static const unsigned int CE_BSP_LIGHTMAPSIZE = 128*128*3; ///< = 128( width ) * 128 ( height ) * 3 ( channels / RGB ). 56 static const int VERION_Q3LEVEL = 46; ///< Supported version. 57 58 /// Geometric type enumeration 59 enum Q3BSPGeoType { 60 Polygon = 1, 61 Patch, 62 TriangleMesh, 63 Billboard 64 }; 65 66 /// Integer vector. 67 struct ceVec3i { 68 int x, y, z; ceVec3iceVec3i69 ceVec3i(): x( 0 ), y( 0 ), z( 0 ) { /* empty */ } xceVec3i70 ceVec3i( int iX, int iY=0, int iZ=0) : x( iX ), y( iY ), z( iZ ) { /* empty */ } 71 }; 72 73 /// the file header 74 struct sQ3BSPHeader { 75 char strID[ 4 ]; ///< Should be "IBSP" 76 int iVersion; ///< 46 for standard levels 77 }; 78 79 /// Describes an entry. 80 struct sQ3BSPLump { 81 int iOffset; ///< Offset from start pointer of file 82 int iSize; ///< Size of part 83 }; 84 85 struct vec2f { 86 float x,y; 87 }; 88 89 struct vec3f { 90 float x, y, z; 91 }; 92 93 /// Vertex of a Q3 level 94 struct sQ3BSPVertex { 95 vec3f vPosition; ///< Position of vertex 96 vec2f vTexCoord; ///< (u,v) Texturecoordinate of detailtexture 97 vec2f vLightmap; ///< (u,v) Texturecoordinate of lightmap 98 vec3f vNormal; ///< vertex normal 99 unsigned char bColor[ 4 ]; ///< Color in RGBA 100 }; 101 102 /// A face in bsp format info 103 struct sQ3BSPFace { 104 int iTextureID; ///< Index in texture array 105 int iEffect; ///< Index in effect array (-1 = no effect) 106 int iType; ///< 1=Polygon, 2=Patch, 3=Mesh, 4=Billboard 107 int iVertexIndex; ///< Start index of polygon 108 int iNumOfVerts; ///< Number of vertices 109 int iFaceVertexIndex; ///< Index of first mesh vertex 110 int iNumOfFaceVerts; ///< number of mesh vertices 111 int iLightmapID; ///< Index to the light-map array 112 int iLMapCorner[ 2 ]; ///< edge of the light-map in texture 113 int iLMapSize[ 2 ]; ///< Size of the light-map stored on the texture 114 vec3f vLMapPos; ///< 3D origin of the light-map 115 vec3f vLMapVecs[ 2 ]; ///< 3D-s-t-vectors 116 vec3f vNormal; ///< Polygon normals 117 int patchWidth, patchHeight; ///< bezier patch 118 }; 119 120 /// A quake3 texture name. 121 struct sQ3BSPTexture { 122 char strName[ 64 ]; ///< Name of the texture without extension 123 int iFlags; ///< Not used 124 int iContents; ///< Not used 125 }; 126 127 /// A light-map of the level, size 128 x 128, RGB components. 128 struct sQ3BSPLightmap { 129 unsigned char bLMapData[ CE_BSP_LIGHTMAPSIZE ]; sQ3BSPLightmapsQ3BSPLightmap130 sQ3BSPLightmap() { 131 ::memset(bLMapData, 0, CE_BSP_LIGHTMAPSIZE ); 132 } 133 }; 134 135 struct SubPatch { 136 std::vector<size_t> indices; 137 int lightmapID; 138 }; 139 140 enum eLumps { 141 kEntities = 0, 142 kTextures, 143 kPlanes, 144 kNodes, 145 kLeafs, 146 kLeafFaces, 147 kLeafBrushes, 148 kModels, 149 kBrushes, 150 kBrushSides, 151 kVertices, 152 kMeshVerts, 153 kShaders, 154 kFaces, 155 kLightmaps, 156 kLightVolumes, 157 kVisData, 158 kMaxLumps 159 }; 160 161 struct Q3BSPModel { 162 std::vector<unsigned char> m_Data; 163 std::vector<sQ3BSPLump*> m_Lumps; 164 std::vector<sQ3BSPVertex*> m_Vertices; 165 std::vector<sQ3BSPFace*> m_Faces; 166 std::vector<int> m_Indices; 167 std::vector<sQ3BSPTexture*> m_Textures; 168 std::vector<sQ3BSPLightmap*> m_Lightmaps; 169 std::vector<char> m_EntityData; 170 std::string m_ModelName; 171 Q3BSPModelQ3BSPModel172 Q3BSPModel() : 173 m_Data(), 174 m_Lumps(), 175 m_Vertices(), 176 m_Faces(), 177 m_Indices(), 178 m_Textures(), 179 m_Lightmaps(), 180 m_EntityData(), 181 m_ModelName() 182 { 183 // empty 184 } 185 ~Q3BSPModelQ3BSPModel186 ~Q3BSPModel() { 187 for ( unsigned int i=0; i<m_Lumps.size(); i++ ) { 188 delete m_Lumps[ i ]; 189 } 190 for ( unsigned int i=0; i<m_Vertices.size(); i++ ) { 191 delete m_Vertices[ i ]; 192 } 193 for ( unsigned int i=0; i<m_Faces.size(); i++ ) { 194 delete m_Faces[ i ]; 195 } 196 for ( unsigned int i=0; i<m_Textures.size(); i++ ) { 197 delete m_Textures[ i ]; 198 } 199 for ( unsigned int i=0; i<m_Lightmaps.size(); i++ ) { 200 delete m_Lightmaps[ i ]; 201 } 202 203 m_Lumps.clear(); 204 m_Vertices.clear(); 205 m_Faces.clear(); 206 m_Textures.clear(); 207 m_Lightmaps.clear(); 208 } 209 }; 210 211 } // Namespace Q3BSP 212 } // Namespace Assimp 213 214 #endif // ASSIMP_Q3BSPFILEDATA_H_INC 215