1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_Q3_LEVEL_MESH_H_INCLUDED__
6
#define __C_Q3_LEVEL_MESH_H_INCLUDED__
8
#include "IQ3LevelMesh.h"
10
#include "IFileSystem.h"
12
#include "SMeshBufferLightMap.h"
13
#include "IVideoDriver.h"
14
#include "irrString.h"
15
#include "ISceneManager.h"
22
class CQ3LevelMesh : public IQ3LevelMesh
27
CQ3LevelMesh(io::IFileSystem* fs, scene::ISceneManager* smgr,
28
const quake3::Q3LevelLoadParameter &loadParam);
31
virtual ~CQ3LevelMesh();
33
//! loads a level from a .bsp-File. Also tries to load all
34
//! needed textures. Returns true if successful.
35
bool loadFile(io::IReadFile* file);
37
//! returns the amount of frames in milliseconds. If the amount
38
//! is 1, it is a static (=non animated) mesh.
39
virtual u32 getFrameCount() const;
41
//! returns the animated mesh based on a detail level. 0 is the
42
//! lowest, 255 the highest detail. Note, that some Meshes will
43
//! ignore the detail level.
44
virtual IMesh* getMesh(s32 frameInMs, s32 detailLevel=255,
45
s32 startFrameLoop=-1, s32 endFrameLoop=-1);
47
//! Returns an axis aligned bounding box of the mesh.
48
//! \return A bounding box of this mesh is returned.
49
virtual const core::aabbox3d<f32>& getBoundingBox() const;
51
virtual void setBoundingBox( const core::aabbox3df& box);
54
//! Returns the type of the animated mesh.
55
virtual E_ANIMATED_MESH_TYPE getMeshType() const;
57
//! loads the shader definition
58
virtual void getShader( io::IReadFile* file );
60
//! loads the shader definition
61
virtual const quake3::IShader * getShader( const c8 * filename, bool fileNameIsValid=true );
63
//! returns a already loaded Shader
64
virtual const quake3::IShader * getShader( u32 index ) const;
67
//! loads a configuration file
68
virtual void getConfiguration( io::IReadFile* file );
69
//! get's an interface to the entities
70
virtual quake3::tQ3EntityList & getEntityList();
73
//Link to held meshes? ...
76
//! returns amount of mesh buffers.
77
virtual u32 getMeshBufferCount() const
82
//! returns pointer to a mesh buffer
83
virtual IMeshBuffer* getMeshBuffer(u32 nr) const
88
//! Returns pointer to a mesh buffer which fits a material
89
/** \param material: material to search for
90
\return Pointer to the mesh buffer or 0 if there is no such mesh buffer. */
91
virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const
96
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
101
//! set the hardware mapping hint, for driver
102
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
107
//! flags the meshbuffer as changed, reloads hardware buffers
108
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
116
void constructMesh();
117
void solveTJunction();
122
video::ITexture* Texture;
126
core::array< STexShader > Tex;
127
core::array<video::ITexture*> Lightmap;
131
kEntities = 0, // Stores player/object positions, etc...
132
kShaders = 1, // Stores texture information
133
kPlanes = 2, // Stores the splitting planes
134
kNodes = 3, // Stores the BSP nodes
135
kLeafs = 4, // Stores the leafs of the nodes
136
kLeafFaces = 5, // Stores the leaf's indices into the faces
137
kLeafBrushes = 6, // Stores the leaf's indices into the brushes
138
kModels = 7, // Stores the info of world models
139
kBrushes = 8, // Stores the brushes info (for collision)
140
kBrushSides = 9, // Stores the brush surfaces info
141
kVertices = 10, // Stores the level vertices
142
kMeshVerts = 11, // Stores the model vertices offsets
143
kFogs = 12, // Stores the shader files (blending, anims..)
144
kFaces = 13, // Stores the faces for the level
145
kLightmaps = 14, // Stores the lightmaps for the level
146
kLightGrid = 15, // Stores extra world lighting information
147
kVisData = 16, // Stores PVS and cluster info (visibility)
148
kLightArray = 17, // RBSP
149
kMaxLumps // A constant to store the number of lumps
157
BSP_MST_TRIANGLE_SOUP,
165
s32 strID; // This should always be 'IBSP'
166
s32 version; // This should be 0x2e for Quake 3 files
179
f32 vPosition[3]; // (x, y, z) position.
180
f32 vTextureCoord[2]; // (u, v) texture coordinate
181
f32 vLightmapCoord[2]; // (u, v) lightmap coordinate
182
f32 vNormal[3]; // (x, y, z) normal vector
183
u8 color[4]; // RGBA color for the vertex
188
s32 textureID; // The index into the texture array
189
s32 fogNum; // The index for the effects (or -1 = n/a)
190
s32 type; // 1=polygon, 2=patch, 3=mesh, 4=billboard
191
s32 vertexIndex; // The index into this face's first vertex
192
s32 numOfVerts; // The number of vertices for this face
193
s32 meshVertIndex; // The index into the first meshvertex
194
s32 numMeshVerts; // The number of mesh vertices
195
s32 lightmapID; // The texture index for the lightmap
196
s32 lMapCorner[2]; // The face's lightmap corner in the image
197
s32 lMapSize[2]; // The size of the lightmap section
198
f32 lMapPos[3]; // The 3D origin of lightmap.
199
f32 lMapBitsets[2][3]; // The 3D space for s and t unit vectors.
200
f32 vNormal[3]; // The face normal.
201
s32 size[2]; // The bezier patch dimensions.
206
c8 strName[64]; // The name of the texture w/o the extension
207
u32 flags; // The surface flags (unknown)
208
u32 contents; // The content flags (unknown)
213
u8 imageBits[128][128][3]; // The RGB data in a 128x128 image
218
s32 plane; // The index into the planes array
219
s32 front; // The child index for the front node
220
s32 back; // The child index for the back node
221
s32 mins[3]; // The bounding box min position.
222
s32 maxs[3]; // The bounding box max position.
227
s32 cluster; // The visibility cluster
228
s32 area; // The area portal
229
s32 mins[3]; // The bounding box min position
230
s32 maxs[3]; // The bounding box max position
231
s32 leafface; // The first index into the face array
232
s32 numOfLeafFaces; // The number of faces for this leaf
233
s32 leafBrush; // The first index for into the brushes
234
s32 numOfLeafBrushes; // The number of brushes for this leaf
239
f32 vNormal[3]; // Plane normal.
240
f32 d; // The plane distance from origin
245
s32 numOfClusters; // The number of clusters
246
s32 bytesPerCluster; // Bytes (8 bits) in the cluster's bitset
247
c8 *pBitsets; // Array of bytes holding the cluster vis.
252
s32 brushSide; // The starting brush side for the brush
253
s32 numOfBrushSides; // Number of brush sides for the brush
254
s32 textureID; // The texture index for the brush
259
s32 plane; // The plane index
260
s32 textureID; // The texture index
265
f32 min[3]; // The min position for the bounding box
266
f32 max[3]; // The max position for the bounding box.
267
s32 faceIndex; // The first face index in the model
268
s32 numOfFaces; // The number of faces in the model
269
s32 brushIndex; // The first brush index in the model
270
s32 numOfBrushes; // The number brushes for the model
275
c8 shader[64]; // The name of the shader file
276
s32 brushIndex; // The brush index for this shader
277
s32 visibleSide; // the brush side that ray tests need to clip against (-1 == none
279
core::array < STexShader > FogMap;
283
u8 ambient[3]; // This is the ambient color in RGB
284
u8 directional[3]; // This is the directional color in RGB
285
u8 direction[2]; // The direction of the light: [phi,theta]
288
void loadTextures (tBSPLump* l, io::IReadFile* file); // Load the textures
289
void loadLightmaps (tBSPLump* l, io::IReadFile* file); // Load the lightmaps
290
void loadVerts (tBSPLump* l, io::IReadFile* file); // Load the vertices
291
void loadFaces (tBSPLump* l, io::IReadFile* file); // Load the faces
292
void loadPlanes (tBSPLump* l, io::IReadFile* file); // Load the Planes of the BSP
293
void loadNodes (tBSPLump* l, io::IReadFile* file); // load the Nodes of the BSP
294
void loadLeafs (tBSPLump* l, io::IReadFile* file); // load the Leafs of the BSP
295
void loadLeafFaces (tBSPLump* l, io::IReadFile* file); // load the Faces of the Leafs of the BSP
296
void loadVisData (tBSPLump* l, io::IReadFile* file); // load the visibility data of the clusters
297
void loadEntities (tBSPLump* l, io::IReadFile* file); // load the entities
298
void loadModels (tBSPLump* l, io::IReadFile* file); // load the models
299
void loadMeshVerts (tBSPLump* l, io::IReadFile* file); // load the mesh vertices
300
void loadBrushes (tBSPLump* l, io::IReadFile* file); // load the brushes of the BSP
301
void loadBrushSides (tBSPLump* l, io::IReadFile* file); // load the brushsides of the BSP
302
void loadLeafBrushes(tBSPLump* l, io::IReadFile* file); // load the brushes of the leaf
303
void loadFogs (tBSPLump* l, io::IReadFile* file); // load the shaders
305
//bi-quadratic bezier patches
306
void createCurvedSurface_bezier(SMeshBufferLightMap* meshBuffer,
307
s32 faceIndex, s32 patchTesselation, s32 storevertexcolor);
309
void createCurvedSurface_nosubdivision(SMeshBufferLightMap* meshBuffer,
310
s32 faceIndex, s32 patchTesselation, s32 storevertexcolor);
312
struct S3DVertex2TCoords_64
314
core::vector3d<f64> Pos;
315
core::vector3d<f64> Normal;
316
video::SColorf Color;
317
core::vector2d<f64> TCoords;
318
core::vector2d<f64> TCoords2;
320
void copy( video::S3DVertex2TCoords &dest ) const;
322
S3DVertex2TCoords_64() {}
323
S3DVertex2TCoords_64(const core::vector3d<f64>& pos, const core::vector3d<f64>& normal, const video::SColorf& color,
324
const core::vector2d<f64>& tcoords, const core::vector2d<f64>& tcoords2)
325
: Pos(pos), Normal(normal), Color(color), TCoords(tcoords), TCoords2(tcoords2) {}
327
S3DVertex2TCoords_64 getInterpolated_quadratic(const S3DVertex2TCoords_64& v2,
328
const S3DVertex2TCoords_64& v3, const f64 d) const
330
return S3DVertex2TCoords_64 (
331
Pos.getInterpolated_quadratic ( v2.Pos, v3.Pos, d ),
332
Normal.getInterpolated_quadratic ( v2.Normal, v3.Normal, d ),
333
Color.getInterpolated_quadratic ( v2.Color, v3.Color, (f32) d ),
334
TCoords.getInterpolated_quadratic ( v2.TCoords, v3.TCoords, d ),
335
TCoords2.getInterpolated_quadratic ( v2.TCoords2, v3.TCoords2, d ));
339
inline void copy( video::S3DVertex2TCoords * dest, const tBSPVertex * source,
340
s32 vertexcolor ) const;
341
void copy( S3DVertex2TCoords_64 * dest, const tBSPVertex * source, s32 vertexcolor ) const;
346
SMeshBufferLightMap *Patch;
347
S3DVertex2TCoords_64 control[9];
349
void tesselate(s32 level);
354
core::array<S3DVertex2TCoords_64> column[3];
359
quake3::Q3LevelLoadParameter LoadParam;
361
tBSPLump Lumps[kMaxLumps];
363
tBSPTexture* Textures;
366
tBSPLightmap* LightMaps;
369
tBSPVertex* Vertices;
387
s32 *MeshVerts; // The vertex offsets for a mesh
393
scene::SMesh* Mesh[quake3::E_Q3_MESH_SIZE];
394
video::IVideoDriver* Driver;
395
core::stringc LevelName;
396
io::IFileSystem* FileSystem; // needs because there are no file extenstions stored in .bsp files.
398
// Additional content
399
scene::ISceneManager* SceneManager;
402
Q3_TOKEN_UNRESOLVED = 0,
410
Q3_TOKEN_MATH_DIVIDE,
412
Q3_TOKEN_MATH_MULTIPY
425
typedef void( CQ3LevelMesh::*tParserCallback ) ( quake3::SVarGroupList *& groupList, eToken token );
426
void parser_parse( const void * data, u32 size, tParserCallback callback );
427
void parser_nextToken();
429
void dumpVarGroup( const quake3::SVarGroup * group, s32 stack ) const;
431
void scriptcallback_entity( quake3::SVarGroupList *& grouplist, eToken token );
432
void scriptcallback_shader( quake3::SVarGroupList *& grouplist, eToken token );
433
void scriptcallback_config( quake3::SVarGroupList *& grouplist, eToken token );
435
core::array < quake3::IShader > Shader;
436
core::array < quake3::IShader > Entity; //quake3::tQ3EntityList Entity;
439
quake3::tStringList ShaderFile;
441
void ReleaseShader();
442
void ReleaseEntity();
445
s32 setShaderMaterial( video::SMaterial & material, const tBSPFace * face ) const;
446
s32 setShaderFogMaterial( video::SMaterial &material, const tBSPFace * face ) const;
456
void calcBoundingBoxes();
460
} // end namespace scene
461
} // end namespace irr