Coverage Report

Created: 2026-09-14 07:44

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