Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENELOADER_BSP3_H__
00009 #define __SP_SCENELOADER_BSP3_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_SCENELOADER_BSP3
00015
00016
00017 #include "Base/spInputOutputLog.hpp"
00018 #include "Base/spInputOutputFileSystem.hpp"
00019 #include "Base/spDimension.hpp"
00020 #include "RenderSystem/spTextureBase.hpp"
00021 #include "FileFormats/Mesh/spMeshLoader.hpp"
00022
00023 #include <vector>
00024
00025
00026 namespace sp
00027 {
00028 namespace scene
00029 {
00030
00031
00033 class SP_EXPORT SceneLoaderBSP3 : public SceneLoader
00034 {
00035
00036 public:
00037
00038 SceneLoaderBSP3();
00039 ~SceneLoaderBSP3();
00040
00041 Mesh* loadScene(const io::stringc &Filename, const io::stringc &TexturePath, const s32 Flags);
00042
00048 static void setTessellation(s32 Tessellation);
00049
00050 private:
00051
00052
00053
00054 enum ELumpTypes
00055 {
00056 BSP_LUMP_ENTITIES = 0,
00057 BSP_LUMP_TEXTURES,
00058 BSP_LUMP_PLANES,
00059 BSP_LUMP_NODES,
00060 BSP_LUMP_LEAFS,
00061 BSP_LUMP_LEAFFACES,
00062 BSP_LUMP_LEAFBRUSHES,
00063 BSP_LUMP_MODELS,
00064 BSP_LUMP_BRUSHES,
00065 BSP_LUMP_BRUSHSIDES,
00066 BSP_LUMP_VERTEXES,
00067 BSP_LUMP_MESHVERTS,
00068 BSP_LUMP_EFFECTS,
00069 BSP_LUMP_FACES,
00070 BSP_LUMP_LIGHTMAPS,
00071 BSP_LUMP_LIGHTVOLS,
00072 BSP_LUMP_VISDATA,
00073 };
00074
00075 enum EFaceTypes
00076 {
00077 BSP_FACE_POLYGON = 1,
00078 BSP_FACE_PATCH,
00079 BSP_FACE_MESH,
00080 BSP_FACE_BILLBOARD
00081 };
00082
00083 enum ELightVolsDirectionTypes
00084 {
00085 BSP_LMDIR_PHI = 0,
00086 BSP_LMDIR_THETA
00087 };
00088
00089
00090
00091 struct SDirEntryBSP
00092 {
00093 s32 Offset;
00094 s32 Length;
00095 };
00096
00097 struct SHeaderBSP
00098 {
00099 c8 Magic[4];
00100 s32 Version;
00101 SDirEntryBSP DirEntries[17];
00102 };
00103
00104 struct SNodeBSP
00105 {
00106 s32 Plane;
00107 s32 Children[2];
00108 dim::line3di BoundingBox;
00109 };
00110
00111 struct SLeafBSP
00112 {
00113 s32 Cluster;
00114 s32 Area;
00115 dim::line3di BoundingBox;
00116 s32 LeafFace;
00117 s32 CountLeafFaces;
00118 s32 LeafBrush;
00119 s32 CountLeafBrushes;
00120 };
00121
00122 struct SModelBSP
00123 {
00124 dim::line3df BoundingBox;
00125 s32 Face;
00126 s32 CountFaces;
00127 s32 Brush;
00128 s32 CountBrushes;
00129 };
00130
00131 struct SBrushBSP
00132 {
00133 s32 BrushSide;
00134 s32 CountBrushSides;
00135 s32 Texture;
00136 };
00137
00138 struct SBrushSideBSP
00139 {
00140 s32 Plane;
00141 s32 Texture;
00142 };
00143
00144 struct SVertexBSP
00145 {
00146
00147
00148 dim::vector3df Position;
00149 dim::point2df TexCoord[2];
00150 dim::vector3df Normal;
00151 video::color Color;
00152
00153
00154
00155 SVertexBSP operator + (const SVertexBSP &other) const
00156 {
00157 SVertexBSP Result;
00158
00159 Result.Position = Position + other.Position;
00160 Result.TexCoord[0] = TexCoord[0] + other.TexCoord[0];
00161 Result.TexCoord[1] = TexCoord[1] + other.TexCoord[1];
00162
00163 return Result;
00164 }
00165
00166 SVertexBSP operator * (const f32 size) const
00167 {
00168 SVertexBSP Result;
00169
00170 Result.Position = Position * size;
00171 Result.TexCoord[0] = TexCoord[0] * size;
00172 Result.TexCoord[1] = TexCoord[1] * size;
00173
00174 return Result;
00175 }
00176 };
00177
00178 struct SEffectBSP
00179 {
00180 c8 Name[64];
00181 s32 Brush;
00182 s32 Unknown;
00183 };
00184
00185 struct SFaceBSP
00186 {
00187 s32 Texture;
00188 s32 Effect;
00189 s32 Type;
00190 s32 FirstVertex;
00191 s32 CountVertices;
00192 s32 FirstMeshVerts;
00193 s32 CountMeshVerts;
00194 s32 LightMap;
00195 dim::point2di LightMapStart;
00196 dim::size2di LightMapSize;
00197 dim::vector3df LightMapSpaceOrigin;
00198 dim::vector3df LightMapUnitVectors[2];
00199 dim::vector3df SurfaceNormal;
00200 dim::size2di PatchSize;
00201 };
00202
00203 struct SLightMapBSP
00204 {
00205 u8 LightMap[128][128][3];
00206 };
00207
00208 struct SLightVolsBSP
00209 {
00210 u8 Ambient[3];
00211 u8 Directional[3];
00212 u8 Direction[2];
00213 };
00214
00215 struct SVisDataBSP
00216 {
00217 s32 CountVectors;
00218 s32 VectorSize;
00219 u8* VisibilityData;
00220 };
00221
00222
00223
00224 class BiQuadraticPatch
00225 {
00226
00227 public:
00228
00229 BiQuadraticPatch();
00230 ~BiQuadraticPatch();
00231
00232
00233
00234 void tessellate(s32 NewLevel);
00235
00236
00237
00238 SVertexBSP ControlPoints[9];
00239
00240 std::vector<SVertexBSP> VerticesList;
00241 std::vector< std::vector<u32> > IndicesList;
00242
00243 };
00244
00245
00246
00247 bool readHeader();
00248 void readLumps();
00249
00250 void readLumpEntities();
00251 void readLumpTextures();
00252 void readLumpPlanes();
00253 void readLumpNodes();
00254 void readLumpLeafs();
00255 void readLumpLeafFaces();
00256 void readLumpLeafBrushes();
00257 void readLumpModels();
00258 void readLumpBrushes();
00259 void readLumpBrushSides();
00260 void readLumpVertexes();
00261 void readLumpMeshVerts();
00262 void readLumpEffecs();
00263 void readLumpFaces();
00264 void readLumpLightMaps();
00265 void readLumpLightVols();
00266 void readLumpVisData();
00267
00268 void createNewVertex(SVertexBSP &Vertex, SFaceBSP &Face);
00269
00270 void buildModel();
00271
00272 void examineScript(std::vector<io::stringc> &ScriptData);
00273
00274 io::stringc getScriptLineType(io::stringc &Line);
00275 io::stringc getScriptLineValue(io::stringc &Line);
00276 dim::vector3df getScriptLineVector(io::stringc &Line, io::stringc Value);
00277
00278
00279
00280 SHeaderBSP Header_;
00281
00282
00283 std::vector<video::Texture*> TextureList_;
00284 std::vector<video::Texture*> LightMapList_;
00285 std::vector<dim::plane3df> PlaneList_;
00286 std::vector<SVertexBSP> VerticesList_;
00287 std::vector<SFaceBSP> FacesList_;
00288 std::vector<s32> MeshVertOffsetList_;
00289
00290 static s32 Tessellation_;
00291
00292 };
00293
00294
00295
00296
00297
00298
00299 class BSPLoaderExtensions
00300 {
00301
00302 public:
00303
00304 BSPLoaderExtensions();
00305 ~BSPLoaderExtensions();
00306
00307 static void createScript(std::vector<io::stringc> &ScriptData, c8* MeshDescription);
00308
00309 };
00310
00311
00312 }
00313
00314 }
00315
00316
00317 #endif
00318
00319 #endif
00320
00321
00322
00323