aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h')
-rw-r--r--src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h491
1 files changed, 491 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h b/src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h
new file mode 100644
index 0000000..b7e9cf1
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/source/Irrlicht/CQ3LevelMesh.h
@@ -0,0 +1,491 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __C_Q3_LEVEL_MESH_H_INCLUDED__
6#define __C_Q3_LEVEL_MESH_H_INCLUDED__
7
8#include "IQ3LevelMesh.h"
9#include "IReadFile.h"
10#include "IFileSystem.h"
11#include "SMesh.h"
12#include "SMeshBufferLightMap.h"
13#include "IVideoDriver.h"
14#include "irrString.h"
15#include "ISceneManager.h"
16#include "os.h"
17
18namespace irr
19{
20namespace scene
21{
22 class CQ3LevelMesh : public IQ3LevelMesh
23 {
24 public:
25
26 //! constructor
27 CQ3LevelMesh(io::IFileSystem* fs, scene::ISceneManager* smgr,
28 const quake3::Q3LevelLoadParameter &loadParam);
29
30 //! destructor
31 virtual ~CQ3LevelMesh();
32
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);
36
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;
40
41 //! Gets the default animation speed of the animated mesh.
42 /** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
43 virtual f32 getAnimationSpeed() const
44 {
45 return FramesPerSecond;
46 }
47
48 //! Gets the frame count of the animated mesh.
49 /** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
50 The actual speed is set in the scene node the mesh is instantiated in.*/
51 virtual void setAnimationSpeed(f32 fps)
52 {
53 FramesPerSecond=fps;
54 }
55
56 //! returns the animated mesh based on a detail level. 0 is the
57 //! lowest, 255 the highest detail. Note, that some Meshes will
58 //! ignore the detail level.
59 virtual IMesh* getMesh(s32 frameInMs, s32 detailLevel=255,
60 s32 startFrameLoop=-1, s32 endFrameLoop=-1);
61
62 //! Returns an axis aligned bounding box of the mesh.
63 //! \return A bounding box of this mesh is returned.
64 virtual const core::aabbox3d<f32>& getBoundingBox() const;
65
66 virtual void setBoundingBox( const core::aabbox3df& box);
67
68 //! Returns the type of the animated mesh.
69 virtual E_ANIMATED_MESH_TYPE getMeshType() const;
70
71 //! loads the shader definition
72 virtual void getShader( io::IReadFile* file );
73
74 //! loads the shader definition
75 virtual const quake3::IShader * getShader( const c8 * filename, bool fileNameIsValid=true );
76
77 //! returns a already loaded Shader
78 virtual const quake3::IShader * getShader( u32 index ) const;
79
80
81 //! loads a configuration file
82 virtual void getConfiguration( io::IReadFile* file );
83 //! get's an interface to the entities
84 virtual quake3::tQ3EntityList & getEntityList();
85
86 //! returns the requested brush entity
87 virtual IMesh* getBrushEntityMesh(s32 num) const;
88
89 //! returns the requested brush entity
90 virtual IMesh* getBrushEntityMesh(quake3::IEntity &ent) const;
91
92 //Link to held meshes? ...
93
94
95 //! returns amount of mesh buffers.
96 virtual u32 getMeshBufferCount() const
97 {
98 return 0;
99 }
100
101 //! returns pointer to a mesh buffer
102 virtual IMeshBuffer* getMeshBuffer(u32 nr) const
103 {
104 return 0;
105 }
106
107 //! Returns pointer to a mesh buffer which fits a material
108 /** \param material: material to search for
109 \return Pointer to the mesh buffer or 0 if there is no such mesh buffer. */
110 virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const
111 {
112 return 0;
113 }
114
115 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
116 {
117 return;
118 }
119
120 //! set the hardware mapping hint, for driver
121 virtual void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
122 {
123 return;
124 }
125
126 //! flags the meshbuffer as changed, reloads hardware buffers
127 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
128 {
129 return;
130 }
131
132 private:
133
134
135 void constructMesh();
136 void solveTJunction();
137 void loadTextures();
138 scene::SMesh** buildMesh(s32 num);
139
140 struct STexShader
141 {
142 video::ITexture* Texture;
143 s32 ShaderID;
144 };
145
146 core::array< STexShader > Tex;
147 core::array<video::ITexture*> Lightmap;
148
149 enum eLumps
150 {
151 kEntities = 0, // Stores player/object positions, etc...
152 kShaders = 1, // Stores texture information
153 kPlanes = 2, // Stores the splitting planes
154 kNodes = 3, // Stores the BSP nodes
155 kLeafs = 4, // Stores the leafs of the nodes
156 kLeafFaces = 5, // Stores the leaf's indices into the faces
157 kLeafBrushes = 6, // Stores the leaf's indices into the brushes
158 kModels = 7, // Stores the info of world models
159 kBrushes = 8, // Stores the brushes info (for collision)
160 kBrushSides = 9, // Stores the brush surfaces info
161 kVertices = 10, // Stores the level vertices
162 kMeshVerts = 11, // Stores the model vertices offsets
163 kFogs = 12, // Stores the shader files (blending, anims..)
164 kFaces = 13, // Stores the faces for the level
165 kLightmaps = 14, // Stores the lightmaps for the level
166 kLightGrid = 15, // Stores extra world lighting information
167 kVisData = 16, // Stores PVS and cluster info (visibility)
168 kLightArray = 17, // RBSP
169 kMaxLumps // A constant to store the number of lumps
170 };
171
172 enum eBspSurfaceType
173 {
174 BSP_MST_BAD,
175 BSP_MST_PLANAR,
176 BSP_MST_PATCH,
177 BSP_MST_TRIANGLE_SOUP,
178 BSP_MST_FLARE,
179 BSP_MST_FOLIAGE
180
181 };
182
183 struct tBSPHeader
184 {
185 s32 strID; // This should always be 'IBSP'
186 s32 version; // This should be 0x2e for Quake 3 files
187 };
188 tBSPHeader header;
189
190 struct tBSPLump
191 {
192 s32 offset;
193 s32 length;
194 };
195
196
197 struct tBSPVertex
198 {
199 f32 vPosition[3]; // (x, y, z) position.
200 f32 vTextureCoord[2]; // (u, v) texture coordinate
201 f32 vLightmapCoord[2]; // (u, v) lightmap coordinate
202 f32 vNormal[3]; // (x, y, z) normal vector
203 u8 color[4]; // RGBA color for the vertex
204 };
205
206 struct tBSPFace
207 {
208 s32 textureID; // The index into the texture array
209 s32 fogNum; // The index for the effects (or -1 = n/a)
210 s32 type; // 1=polygon, 2=patch, 3=mesh, 4=billboard
211 s32 vertexIndex; // The index into this face's first vertex
212 s32 numOfVerts; // The number of vertices for this face
213 s32 meshVertIndex; // The index into the first meshvertex
214 s32 numMeshVerts; // The number of mesh vertices
215 s32 lightmapID; // The texture index for the lightmap
216 s32 lMapCorner[2]; // The face's lightmap corner in the image
217 s32 lMapSize[2]; // The size of the lightmap section
218 f32 lMapPos[3]; // The 3D origin of lightmap.
219 f32 lMapBitsets[2][3]; // The 3D space for s and t unit vectors.
220 f32 vNormal[3]; // The face normal.
221 s32 size[2]; // The bezier patch dimensions.
222 };
223
224 struct tBSPTexture
225 {
226 c8 strName[64]; // The name of the texture w/o the extension
227 u32 flags; // The surface flags (unknown)
228 u32 contents; // The content flags (unknown)
229 };
230
231 struct tBSPLightmap
232 {
233 u8 imageBits[128][128][3]; // The RGB data in a 128x128 image
234 };
235
236 struct tBSPNode
237 {
238 s32 plane; // The index into the planes array
239 s32 front; // The child index for the front node
240 s32 back; // The child index for the back node
241 s32 mins[3]; // The bounding box min position.
242 s32 maxs[3]; // The bounding box max position.
243 };
244
245 struct tBSPLeaf
246 {
247 s32 cluster; // The visibility cluster
248 s32 area; // The area portal
249 s32 mins[3]; // The bounding box min position
250 s32 maxs[3]; // The bounding box max position
251 s32 leafface; // The first index into the face array
252 s32 numOfLeafFaces; // The number of faces for this leaf
253 s32 leafBrush; // The first index for into the brushes
254 s32 numOfLeafBrushes; // The number of brushes for this leaf
255 };
256
257 struct tBSPPlane
258 {
259 f32 vNormal[3]; // Plane normal.
260 f32 d; // The plane distance from origin
261 };
262
263 struct tBSPVisData
264 {
265 s32 numOfClusters; // The number of clusters
266 s32 bytesPerCluster; // Bytes (8 bits) in the cluster's bitset
267 c8 *pBitsets; // Array of bytes holding the cluster vis.
268 };
269
270 struct tBSPBrush
271 {
272 s32 brushSide; // The starting brush side for the brush
273 s32 numOfBrushSides; // Number of brush sides for the brush
274 s32 textureID; // The texture index for the brush
275 };
276
277 struct tBSPBrushSide
278 {
279 s32 plane; // The plane index
280 s32 textureID; // The texture index
281 };
282
283 struct tBSPModel
284 {
285 f32 min[3]; // The min position for the bounding box
286 f32 max[3]; // The max position for the bounding box.
287 s32 faceIndex; // The first face index in the model
288 s32 numOfFaces; // The number of faces in the model
289 s32 brushIndex; // The first brush index in the model
290 s32 numOfBrushes; // The number brushes for the model
291 };
292
293 struct tBSPFog
294 {
295 c8 shader[64]; // The name of the shader file
296 s32 brushIndex; // The brush index for this shader
297 s32 visibleSide; // the brush side that ray tests need to clip against (-1 == none
298 };
299 core::array < STexShader > FogMap;
300
301 struct tBSPLights
302 {
303 u8 ambient[3]; // This is the ambient color in RGB
304 u8 directional[3]; // This is the directional color in RGB
305 u8 direction[2]; // The direction of the light: [phi,theta]
306 };
307
308 void loadTextures (tBSPLump* l, io::IReadFile* file); // Load the textures
309 void loadLightmaps (tBSPLump* l, io::IReadFile* file); // Load the lightmaps
310 void loadVerts (tBSPLump* l, io::IReadFile* file); // Load the vertices
311 void loadFaces (tBSPLump* l, io::IReadFile* file); // Load the faces
312 void loadPlanes (tBSPLump* l, io::IReadFile* file); // Load the Planes of the BSP
313 void loadNodes (tBSPLump* l, io::IReadFile* file); // load the Nodes of the BSP
314 void loadLeafs (tBSPLump* l, io::IReadFile* file); // load the Leafs of the BSP
315 void loadLeafFaces (tBSPLump* l, io::IReadFile* file); // load the Faces of the Leafs of the BSP
316 void loadVisData (tBSPLump* l, io::IReadFile* file); // load the visibility data of the clusters
317 void loadEntities (tBSPLump* l, io::IReadFile* file); // load the entities
318 void loadModels (tBSPLump* l, io::IReadFile* file); // load the models
319 void loadMeshVerts (tBSPLump* l, io::IReadFile* file); // load the mesh vertices
320 void loadBrushes (tBSPLump* l, io::IReadFile* file); // load the brushes of the BSP
321 void loadBrushSides (tBSPLump* l, io::IReadFile* file); // load the brushsides of the BSP
322 void loadLeafBrushes(tBSPLump* l, io::IReadFile* file); // load the brushes of the leaf
323 void loadFogs (tBSPLump* l, io::IReadFile* file); // load the shaders
324
325 //bi-quadratic bezier patches
326 void createCurvedSurface_bezier(SMeshBufferLightMap* meshBuffer,
327 s32 faceIndex, s32 patchTesselation, s32 storevertexcolor);
328
329 void createCurvedSurface_nosubdivision(SMeshBufferLightMap* meshBuffer,
330 s32 faceIndex, s32 patchTesselation, s32 storevertexcolor);
331
332 struct S3DVertex2TCoords_64
333 {
334 core::vector3d<f64> Pos;
335 core::vector3d<f64> Normal;
336 video::SColorf Color;
337 core::vector2d<f64> TCoords;
338 core::vector2d<f64> TCoords2;
339
340 void copy( video::S3DVertex2TCoords &dest ) const;
341
342 S3DVertex2TCoords_64() {}
343 S3DVertex2TCoords_64(const core::vector3d<f64>& pos, const core::vector3d<f64>& normal, const video::SColorf& color,
344 const core::vector2d<f64>& tcoords, const core::vector2d<f64>& tcoords2)
345 : Pos(pos), Normal(normal), Color(color), TCoords(tcoords), TCoords2(tcoords2) {}
346
347 S3DVertex2TCoords_64 getInterpolated_quadratic(const S3DVertex2TCoords_64& v2,
348 const S3DVertex2TCoords_64& v3, const f64 d) const
349 {
350 return S3DVertex2TCoords_64 (
351 Pos.getInterpolated_quadratic ( v2.Pos, v3.Pos, d ),
352 Normal.getInterpolated_quadratic ( v2.Normal, v3.Normal, d ),
353 Color.getInterpolated_quadratic ( v2.Color, v3.Color, (f32) d ),
354 TCoords.getInterpolated_quadratic ( v2.TCoords, v3.TCoords, d ),
355 TCoords2.getInterpolated_quadratic ( v2.TCoords2, v3.TCoords2, d ));
356 }
357 };
358
359 inline void copy( video::S3DVertex2TCoords * dest, const tBSPVertex * source,
360 s32 vertexcolor ) const;
361 void copy( S3DVertex2TCoords_64 * dest, const tBSPVertex * source, s32 vertexcolor ) const;
362
363
364 struct SBezier
365 {
366 SMeshBufferLightMap *Patch;
367 S3DVertex2TCoords_64 control[9];
368
369 void tesselate(s32 level);
370
371 private:
372 s32 Level;
373
374 core::array<S3DVertex2TCoords_64> column[3];
375
376 };
377 SBezier Bezier;
378
379 quake3::Q3LevelLoadParameter LoadParam;
380
381 tBSPLump Lumps[kMaxLumps];
382
383 tBSPTexture* Textures;
384 s32 NumTextures;
385
386 tBSPLightmap* LightMaps;
387 s32 NumLightMaps;
388
389 tBSPVertex* Vertices;
390 s32 NumVertices;
391
392 tBSPFace* Faces;
393 s32 NumFaces;
394
395 tBSPModel* Models;
396 s32 NumModels;
397
398 tBSPPlane* Planes;
399 s32 NumPlanes;
400
401 tBSPNode* Nodes;
402 s32 NumNodes;
403
404 tBSPLeaf* Leafs;
405 s32 NumLeafs;
406
407 s32 *LeafFaces;
408 s32 NumLeafFaces;
409
410 s32 *MeshVerts; // The vertex offsets for a mesh
411 s32 NumMeshVerts;
412
413 tBSPBrush* Brushes;
414 s32 NumBrushes;
415
416 scene::SMesh** BrushEntities;
417
418 scene::SMesh* Mesh[quake3::E_Q3_MESH_SIZE];
419 video::IVideoDriver* Driver;
420 core::stringc LevelName;
421 io::IFileSystem* FileSystem; // needs because there are no file extenstions stored in .bsp files.
422
423 // Additional content
424 scene::ISceneManager* SceneManager;
425 enum eToken
426 {
427 Q3_TOKEN_UNRESOLVED = 0,
428 Q3_TOKEN_EOF = 1,
429 Q3_TOKEN_START_LIST,
430 Q3_TOKEN_END_LIST,
431 Q3_TOKEN_ENTITY,
432 Q3_TOKEN_TOKEN,
433 Q3_TOKEN_EOL,
434 Q3_TOKEN_COMMENT,
435 Q3_TOKEN_MATH_DIVIDE,
436 Q3_TOKEN_MATH_ADD,
437 Q3_TOKEN_MATH_MULTIPY
438 };
439 struct SQ3Parser
440 {
441 const c8 *source;
442 u32 sourcesize;
443 u32 index;
444 core::stringc token;
445 eToken tokenresult;
446 };
447 SQ3Parser Parser;
448
449
450 typedef void( CQ3LevelMesh::*tParserCallback ) ( quake3::SVarGroupList *& groupList, eToken token );
451 void parser_parse( const void * data, u32 size, tParserCallback callback );
452 void parser_nextToken();
453
454 void dumpVarGroup( const quake3::SVarGroup * group, s32 stack ) const;
455
456 void scriptcallback_entity( quake3::SVarGroupList *& grouplist, eToken token );
457 void scriptcallback_shader( quake3::SVarGroupList *& grouplist, eToken token );
458 void scriptcallback_config( quake3::SVarGroupList *& grouplist, eToken token );
459
460 core::array < quake3::IShader > Shader;
461 core::array < quake3::IShader > Entity; //quake3::tQ3EntityList Entity;
462
463
464 quake3::tStringList ShaderFile;
465 void InitShader();
466 void ReleaseShader();
467 void ReleaseEntity();
468
469
470 s32 setShaderMaterial( video::SMaterial & material, const tBSPFace * face ) const;
471 s32 setShaderFogMaterial( video::SMaterial &material, const tBSPFace * face ) const;
472
473 struct SToBuffer
474 {
475 s32 takeVertexColor;
476 u32 index;
477 };
478
479 void cleanMeshes();
480 void cleanMesh(SMesh *m, const bool texture0important = false);
481 void cleanLoader ();
482 void calcBoundingBoxes();
483 c8 buf[128];
484 f32 FramesPerSecond;
485 };
486
487} // end namespace scene
488} // end namespace irr
489
490#endif
491