| 1 | |
|---|
| 2 | |
|---|
| 3 | #ifndef Q3BSPLOAD_H |
|---|
| 4 | #define Q3BSPLOAD_H |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | #include <osg/Vec3f> |
|---|
| 8 | #include <osg/GL> |
|---|
| 9 | |
|---|
| 10 | #include <vector> |
|---|
| 11 | #include <string> |
|---|
| 12 | |
|---|
| 13 | #include <fstream> |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | namespace bsp |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class BSP_DIRECTORY_ENTRY |
|---|
| 22 | { |
|---|
| 23 | public: |
|---|
| 24 | int m_offset; |
|---|
| 25 | int m_length; |
|---|
| 26 | }; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | enum BSP_DIRECTORY_ENTRY_TYPE |
|---|
| 30 | { |
|---|
| 31 | bspEntities=0, |
|---|
| 32 | bspTextures, |
|---|
| 33 | bspPlanes, |
|---|
| 34 | bspNodes, |
|---|
| 35 | bspLeaves, |
|---|
| 36 | bspLeafFaces, |
|---|
| 37 | bspLeafBrushes, |
|---|
| 38 | bspModels, |
|---|
| 39 | bspBrushes, |
|---|
| 40 | bspBrushSides, |
|---|
| 41 | bspVertices, |
|---|
| 42 | bspMeshIndices, |
|---|
| 43 | bspEffect, |
|---|
| 44 | bspFaces, |
|---|
| 45 | bspLightmaps, |
|---|
| 46 | bspLightVols, |
|---|
| 47 | bspVisData |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | class BSP_HEADER |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | char m_string[4]; |
|---|
| 57 | int m_version; |
|---|
| 58 | BSP_DIRECTORY_ENTRY m_directoryEntries[17]; |
|---|
| 59 | }; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | class BSP_LOAD_VERTEX |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | osg::Vec3f m_position; |
|---|
| 68 | float m_decalS, m_decalT; |
|---|
| 69 | float m_lightmapS, m_lightmapT; |
|---|
| 70 | osg::Vec3f m_normal; |
|---|
| 71 | unsigned char m_color[4]; |
|---|
| 72 | }; |
|---|
| 73 | |
|---|
| 74 | struct BSP_LoadPlane |
|---|
| 75 | { |
|---|
| 76 | osg::Vec3f m_Normal; |
|---|
| 77 | float m_Dist; |
|---|
| 78 | }; |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | class BSP_LOAD_FACE |
|---|
| 84 | { |
|---|
| 85 | public: |
|---|
| 86 | int m_texture; |
|---|
| 87 | int m_effect; |
|---|
| 88 | int m_type; |
|---|
| 89 | int m_firstVertexIndex; |
|---|
| 90 | int m_numVertices; |
|---|
| 91 | unsigned int m_firstMeshIndex; |
|---|
| 92 | unsigned int m_numMeshIndices; |
|---|
| 93 | int m_lightmapIndex; |
|---|
| 94 | int m_lightmapStart[2]; |
|---|
| 95 | int m_lightmapSize[2]; |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | osg::Vec3f m_lightmapOrigin; |
|---|
| 101 | osg::Vec3f m_sTangent, m_tTangent; |
|---|
| 102 | osg::Vec3f m_normal; |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | int m_patchSize[2]; |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | class BSP_LOAD_TEXTURE |
|---|
| 115 | { |
|---|
| 116 | public: |
|---|
| 117 | char m_name[64]; |
|---|
| 118 | int m_flags, m_contents; |
|---|
| 119 | }; |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | class BSP_LOAD_LIGHTMAP |
|---|
| 123 | { |
|---|
| 124 | public: |
|---|
| 125 | unsigned char m_lightmapData[128*128*3]; |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | class BSP_LOAD_LEAF |
|---|
| 134 | { |
|---|
| 135 | public: |
|---|
| 136 | int m_cluster; |
|---|
| 137 | int m_area; |
|---|
| 138 | int m_mins[3]; |
|---|
| 139 | int m_maxs[3]; |
|---|
| 140 | int m_firstLeafFace; |
|---|
| 141 | int m_numFaces; |
|---|
| 142 | int m_firstLeafBrush; |
|---|
| 143 | int m_numBrushes; |
|---|
| 144 | }; |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | class BSP_NODE |
|---|
| 151 | { |
|---|
| 152 | public: |
|---|
| 153 | int m_planeIndex; |
|---|
| 154 | int m_front, m_back; |
|---|
| 155 | int m_mins[3]; |
|---|
| 156 | int m_maxs[3]; |
|---|
| 157 | }; |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | class BSP_VISIBILITY_DATA |
|---|
| 164 | { |
|---|
| 165 | public: |
|---|
| 166 | int m_numClusters; |
|---|
| 167 | int m_bytesPerCluster; |
|---|
| 168 | std::vector<unsigned char> m_bitset; |
|---|
| 169 | |
|---|
| 170 | }; |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | class Q3BSPLoad |
|---|
| 179 | { |
|---|
| 180 | public: |
|---|
| 181 | |
|---|
| 182 | bool Load(const std::string& filename, int curveTessellation); |
|---|
| 183 | void LoadVertices(std::ifstream& aFile); |
|---|
| 184 | void LoadFaces(std::ifstream& aFile, int curveTessellation); |
|---|
| 185 | void LoadTextures(std::ifstream& aFile); |
|---|
| 186 | void LoadLightmaps(std::ifstream& aFile); |
|---|
| 187 | void LoadBSPData(std::ifstream& aFile); |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | std::string m_entityString; |
|---|
| 191 | |
|---|
| 192 | BSP_HEADER m_header; |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | std::vector<BSP_LOAD_VERTEX> m_loadVertices; |
|---|
| 196 | std::vector<GLuint> m_loadMeshIndices; |
|---|
| 197 | std::vector<BSP_LOAD_FACE> m_loadFaces; |
|---|
| 198 | std::vector<BSP_LOAD_TEXTURE> m_loadTextures; |
|---|
| 199 | std::vector<BSP_LOAD_LIGHTMAP> m_loadLightmaps; |
|---|
| 200 | std::vector<BSP_LOAD_LEAF> m_loadLeaves; |
|---|
| 201 | std::vector<int> m_loadLeafFaces; |
|---|
| 202 | std::vector<BSP_LoadPlane> m_loadPlanes; |
|---|
| 203 | std::vector<BSP_NODE> m_loadNodes; |
|---|
| 204 | BSP_VISIBILITY_DATA m_loadVisibilityData; |
|---|
| 205 | }; |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | #endif // Q3BSPLOAD_H |
|---|