home *** CD-ROM | disk | FTP | other *** search
- #ifndef __Q3bspLoader_h__
- #define __Q3bspLoader_h__
-
- //#include "texture.h"
- //#include "mesh.h"
- #include <stdlib.h>
- #include <string.h>
- #include "vectormath.h"
- #include "Model.h"
- #include "SpacePartitioningTree.h"
-
- #define Q3BSP_FACE_POLYGON 1
- #define Q3BSP_FACE_BEZIER_PATCH 2
- #define Q3BSP_FACE_MESH 3
- #define Q3BSP_FACE_BILLBOARD 4
-
- #define Q3BSP_GAMMA_SHIFT 5.0f
- #define Q3BSP_SCALE 0.033f
-
- //#define Q3BSP_SWITCH_TO_MESH 4 //!< faces with more vertices than this will be drawn as meshes
-
- #define Q3BSP_MAX_TEXTURES 512
-
- // This is our integer vector structure
- typedef struct vector3i_s{
- int x, y, z; // The x y and z position of our integer vector
- }vector3i_t;
-
-
- // This is our BSP header structure
- typedef struct Q3BSPHeader_s{
- char strID[4]; // This should always be 'IBSP'
- int version; // This should be 0x2e for Quake 3 files
- }Q3BSPHeader_t;
-
-
- // This is our BSP lump structure
- typedef struct Q3BSPLump_s{
- int offset; // The offset into the file for the start of this lump
- int length; // The length in bytes for this lump
- }Q3BSPLump_t;
-
-
- // This is our BSP vertex structure
- typedef struct Q3BSPVertex_s{
- vec3_t position; // (x, y, z) position.
- vec2_t texCoords; // (u, v) texture coordinate
- vec2_t lmCoords; // (u, v) lightmap coordinate
- vec3_t normal; // (x, y, z) normal vector
- unsigned char color[4]; // RGBA color for the vertex
- }Q3BSPVertex_t;
-
- typedef struct Q3BSPMeshVertex_s{
- int offset;
- }Q3BSPMeshVertex_t;
-
- // This is our BSP face structure
- typedef struct Q3BSPFace_s{
- int textureID; // The index into the texture array
- int effect; // The index for the effects (or -1 = n/a)
- int type; // 1=polygon, 2=patch, 3=mesh, 4=billboard
- int startVertIndex; // The starting index into this face's first vertex
- int numOfVerts; // The number of vertices for this face
- int meshVertIndex; // The index into the first meshvertex
- int numMeshVerts; // The number of mesh vertices
- int lightmapID; // The texture index for the lightmap
- int lMapCorner[2]; // The face's lightmap corner in the image
- int lMapSize[2]; // The size of the lightmap section
- vec3_t lMapPos; // The 3D origin of lightmap.
- vec3_t lMapVecs[2]; // The 3D space for s and t unit vectors.
- vec3_t normal; // The face normal.
- int size[2]; // The bezier patch dimensions.
- }Q3BSPFace_t;
-
-
- // This is our BSP texture structure
- typedef struct Q3BSPTexture_s{
- char strName[64]; // The name of the texture w/o the extension
- int flags; // The surface flags (unknown)
- int contents; // The content flags (unknown)
- }Q3BSPTexture_t;
-
- // This is our BSP lightmap structure which stores the 128x128 RGB values
- typedef struct Q3BSPLightmap_s{
- unsigned char imageBits[128][128][3]; // The RGB data in a 128x128 image
- }Q3BSPLightmap_t;
-
-
- // This stores a node in the BSP tree
- typedef struct Q3BSPNode_s{
- int plane; // The index into the planes array
- int front; // The child index for the front node
- int back; // The child index for the back node
- vector3i_t min; // The bounding box min position.
- vector3i_t max; // The bounding box max position.
- }Q3BSPNode_t;
-
- // This stores a leaf (end node) in the BSP tree
- typedef struct Q3BSPLeaf_s{
- int cluster; // The visibility cluster
- int area; // The area portal
- vector3i_s min; // The bounding box min position
- vector3i_s max; // The bounding box max position
- int leafface; // The first index into the face array
- int numOfLeafFaces; // The number of faces for this leaf
- int leafBrush; // The first index for into the brushes
- int numOfLeafBrushes; // The number of brushes for this leaf
- }Q3BSPLeaf_t;
-
- // This stores a splitter plane in the BSP tree
- typedef struct Q3BSPPlane_s{
- vec3_t normal; // Plane normal.
- float d; // The plane distance from origin
- }Q3BSPPlane_t;
-
- // This stores the cluster data for the PVS's
- typedef struct Q3BSPVisData_s{
- int numOfClusters; // The number of clusters
- int bytesPerCluster; // The amount of bytes (8 bits) in the cluster's bitset
- unsigned char* pBitsets; // The array of bytes that holds the cluster bitsets
- }Q3BSPVisData_t;
-
-
-
- // This is our lumps enumeration
- enum Q3BSPLumps_e{
- kEntities = 0, // Stores player/object positions, etc...
- kTextures, // Stores texture information
- kPlanes, // Stores the splitting planes
- kNodes, // Stores the BSP nodes
- kLeafs, // Stores the leafs of the nodes
- kLeafFaces, // Stores the leaf's indices into the faces
- kLeafBrushes, // Stores the leaf's indices into the brushes
- kModels, // Stores the info of world models
- kBrushes, // Stores the brushes info (for collision)
- kBrushSides, // Stores the brush surfaces info
- kVertices, // Stores the level vertices
- kMeshVerts, // Stores the model vertices offsets
- kShaders, // Stores the shader files (blending, anims..)
- kFaces, // Stores the faces for the level
- kLightmaps, // Stores the lightmaps for the level
- kLightVolumes, // Stores extra world lighting information
- kVisData, // Stores PVS and cluster info (visibility)
- kMaxLumps // A constant to store the number of lumps
- };
-
-
- // This is our Quake3 BSP class
- class Q3BSP{
- public:
- Q3BSP(const char* filename);
- ~Q3BSP();
-
- void clear();
-
- int getLeafIndex(vec3_t pos);
-
- Q3bspExtension* buildQ3bspExtension();
-
- protected:
- // This loads a .bsp file by it's file name (Returns true if successful)
- bool loadBSP(const char* filename);
- bool faceShouldBeConverted(Q3BSPFace_t* face);
- Mesh* convertToMesh();
- PotentialVisibilitySet* buildPVS();
-
- bool clusterIsVisible(int current, int test);
-
-
- int numVerts; // The number of verts in the model
- int numMeshVerts;
- int numFaces; // The number of faces in the model
- int numTextures; // The number of texture maps
- int numLightmaps; // The number of light maps
-
- int numNodes;
- int numLeafs;
- int numLeafFaces;
- int numPlanes;
-
-
-
- Q3BSPVertex_t *pVerts; // The object's vertices
- Q3BSPMeshVertex_t* pMeshVerts;
- Q3BSPFace_t *pFaces; // The faces information of the object
-
-
-
- Q3BSPNode_t *pNodes;
- Q3BSPLeaf_t *pLeafs;
- Q3BSPPlane_t *pPlanes;
- int *pLeafFaces;
- Q3BSPVisData_t clusters;
-
-
- Texture* textures[Q3BSP_MAX_TEXTURES];
- Texture* lightmaps[Q3BSP_MAX_TEXTURES]; // The lightmap texture array
- };
-
-
-
-
- class Q3bspLoader{
- public:
- static Q3bspExtension* q3bspExtension;
-
- static bool loadBSP(const char* filename, Model* model);
- };
-
- #endif /* __Q3bspLoader_h__*/
-