Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENELOADER_BSP1_H__
00009 #define __SP_SCENELOADER_BSP1_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013
00014 #ifdef SP_COMPILE_WITH_SCENELOADER_BSP1
00015
00016
00017 #include "Base/spInputOutputLog.hpp"
00018 #include "Base/spInputOutputFileSystem.hpp"
00019 #include "Base/spDimension.hpp"
00020 #include "SceneGraph/spSceneMesh.hpp"
00021 #include "RenderSystem/spTextureBase.hpp"
00022 #include "FileFormats/Mesh/spMeshLoader.hpp"
00023 #include "FileFormats/Image/spImageLoaderWAD.hpp"
00024
00025 #include <vector>
00026
00027
00028 namespace sp
00029 {
00030 namespace scene
00031 {
00032
00033
00035 class SP_EXPORT SceneLoaderBSP1 : public SceneLoader
00036 {
00037
00038 public:
00039
00040 SceneLoaderBSP1();
00041 ~SceneLoaderBSP1();
00042
00043 Mesh* loadScene(const io::stringc &Filename, const io::stringc &TexturePath, const s32 Flags);
00044
00045 private:
00046
00047 #ifdef SP_COMPILE_WITH_TEXLOADER_WAD
00048 friend class video::ImageLoaderWAD;
00049 #endif
00050
00051
00052
00053 enum ELumpTypes
00054 {
00055 BSP_LUMP_ENTITIES = 0,
00056 BSP_LUMP_PLANES,
00057 BSP_LUMP_WALLTEXTURES,
00058 BSP_LUMP_VERTICES,
00059 BSP_LUMP_VISDATA,
00060 BSP_LUMP_NODES,
00061 BSP_LUMP_TEXINFO,
00062 BSP_LUMP_FACES,
00063 BSP_LUMP_LIGHTMAPS,
00064 BSP_LUMP_CLIPNODES,
00065 BSP_LUMP_LEAFS,
00066 BSP_LUMP_FACESLIST,
00067 BSP_LUMP_EDGES,
00068 BSP_LUMP_EDGESLIST,
00069 BSP_LUMP_MODELS,
00070 };
00071
00072 enum EPLaneTypes
00073 {
00074 BSP_PLANE_AXIALX = 0,
00075 BSP_PLANE_AXIALY,
00076 BSP_PLANE_AXIALZ,
00077 BSP_PLANE_NONAXIALX,
00078 BSP_PLANE_NONAXIALY,
00079 BSP_PLANE_NONAXIALZ
00080 };
00081
00082
00083
00084 struct SDirEntryBSP
00085 {
00086 s32 Offset;
00087 s32 Length;
00088 };
00089
00090 struct SHeaderBSP
00091 {
00092 s32 Version;
00093 SDirEntryBSP DirEntries[15];
00094 };
00095
00096 struct SPlaneBSP
00097 {
00098 dim::vector3df Normal;
00099 f32 Dist;
00100 s32 Type;
00101 };
00102
00103 struct SWallTextureBSP
00104 {
00105 c8 Name[16];
00106 u32 Width, Height;
00107 u32 Offset1;
00108 u32 Offset2;
00109 u32 Offset4;
00110 u32 Offset8;
00111 };
00112
00113 struct STextureInfoBSP
00114 {
00115 dim::vector3df VectorS;
00116 f32 DistS;
00117
00118 dim::vector3df VectorT;
00119 f32 DistT;
00120
00121 u32 TextureID;
00122 u32 Animated;
00123 };
00124
00125 struct SEdgeBSP
00126 {
00127 inline void swap()
00128 {
00129 math::Swap(VertexStart, VertexEnd);
00130 }
00131
00132 u16 VertexStart;
00133 u16 VertexEnd;
00134 };
00135
00136 struct SFaceBSP
00137 {
00138 u16 PlaneID;
00139 u16 Side;
00140
00141 s32 FirstEdge;
00142 u16 CountEdges;
00143
00144 u16 TexInfoID;
00145
00146 u8 LightType;
00147 u8 LightBase;
00148 u8 Light[2];
00149
00150 s32 LightMap;
00151 };
00152
00153 struct SScriptBlockBSP
00154 {
00155 void clear()
00156 {
00157 ClassName = "";
00158 }
00159
00160 io::stringc ClassName;
00161 dim::vector3df Origin;
00162 dim::vector3df Angles;
00163 video::color Color;
00164 };
00165
00166
00167
00168
00169 inline void swapVector(dim::vector3df &Vec)
00170 {
00171 dim::vector3df tmp(Vec);
00172 Vec.X = tmp.Y;
00173 Vec.Y = tmp.Z;
00174 Vec.Z = - tmp.X;
00175 }
00176
00177
00178 bool readHeader();
00179 void readLumps();
00180
00181 void readLumpEntities();
00182 void readLumpPlanes();
00183 void readLumpWallTextures();
00184 void readLumpVertices();
00185 void readLumpVisData();
00186 void readLumpNodes();
00187 void readLumpTexInfo();
00188 void readLumpFaces();
00189 void readLumpLightMaps();
00190 void readLumpClipNodes();
00191 void readLumpLeafs();
00192 void readLumpFacesList();
00193 void readLumpEdges();
00194 void readLumpEdgesList();
00195 void readLumpModels();
00196
00197
00198 void readTexturesRAW();
00199
00200 void findNextTexturePath(io::stringc Filename, s32 &Pos);
00201
00202
00203 void examineScript(std::vector<io::stringc> &ScriptData);
00204 void executeScriptBlock(const SScriptBlockBSP &Block);
00205 dim::vector3df convertVector(io::stringc &Arg);
00206 video::color convertColor(io::stringc &Arg);
00207
00208 std::vector<io::stringc> readScriptSpecWAD(io::stringc &Arg);
00209
00210
00211 std::vector<SEdgeBSP> pairEdges(std::vector<s16> &EdgesIndicesList);
00212 std::vector<s16> pairTriangles(std::vector<SEdgeBSP> &EdgesList);
00213 void createPolygon(std::vector<s16> &IndicesList);
00214
00215 dim::point2df calcTexCoord(const dim::vector3df &Pos, const STextureInfoBSP &TexInfo);
00216
00217 void buildModel();
00218
00219
00220
00221 SHeaderBSP Header_;
00222 SFaceBSP CurFace_;
00223 STextureInfoBSP CurTexInfo_;
00224
00225 c8* EntDesc_;
00226 u8* LightMap_;
00227
00228
00229 std::list<video::Texture*> TextureList_, TextureListRAW_;
00230
00231
00232 std::vector<SWallTextureBSP> WallTextureList_;
00233 std::vector<STextureInfoBSP> TextureInfoList_;
00234
00235 std::vector<SPlaneBSP> PlaneList_;
00236 std::vector<SFaceBSP> FacesList_;
00237 std::vector<SEdgeBSP> EdgesList_;
00238 std::vector<s16> EdgesIndicesList_;
00239 std::vector<dim::vector3df> VerticesList_;
00240
00241 std::vector<io::stringc> ScriptWADList_;
00242
00243 };
00244
00245
00246 }
00247
00248 }
00249
00250
00251 #endif
00252
00253 #endif
00254
00255
00256
00257