00001
00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024
00025
00026 #ifndef NL_LANDSCAPE_H
00027 #define NL_LANDSCAPE_H
00028
00029
00030 #include "nel/misc/types_nl.h"
00031 #include "nel/misc/class_id.h"
00032 #include "nel/misc/smart_ptr.h"
00033 #include "nel/misc/triangle.h"
00034 #include "nel/3d/zone.h"
00035 #include "nel/3d/tile_bank.h"
00036 #include "nel/3d/patch_rdr_pass.h"
00037 #include "nel/3d/vertex_buffer.h"
00038 #include "nel/3d/primitive_block.h"
00039 #include "nel/3d/material.h"
00040 #include "nel/3d/tile_far_bank.h"
00041 #include "nel/3d/texture_near.h"
00042 #include <map>
00043
00044 #define NL_MAX_SIZE_OF_TEXTURE_EDGE_SHIFT (NL_MAX_TILES_BY_PATCH_EDGE_SHIFT+NL_NUM_PIXELS_ON_FAR_TILE_EDGE_SHIFT)
00045 #define NL_MAX_SIZE_OF_TEXTURE_EDGE (1<<NL_MAX_SIZE_OF_TEXTURE_EDGE_SHIFT) // Size max of a far texture edge in pixel
00046
00047
00048 namespace NL3D
00049 {
00050
00051
00052 class CHeightMap;
00053
00054
00055
00056
00057 const sint NbTilesMax= 65536;
00058
00059
00060 const sint TextureNearSize= 256;
00061 const sint NbTilesByLine= TextureNearSize/NL_TILE_LIGHTMAP_SIZE;
00062 const sint NbTilesByTexture= NbTilesByLine*NbTilesByLine;
00063
00064
00065
00066 00073 struct EBadBind : public Exception
00074 {
00075 private:
00076 mutable std::string _Output;
00077
00078 public:
00079 struct CBindError
00080 {
00081 CBindError(sint z, sint p) {ZoneId= z; PatchId= p;}
00082 sint ZoneId;
00083 sint PatchId;
00084 };
00085
00086
00087
00088 std::list<CBindError> BindErrors;
00089
00090 public:
00091 EBadBind() : Exception( "Landscape Bind Error in (3DSMax indices!! (+1) ): " ) {}
00092 virtual const char *what() const throw();
00093
00094 };
00095
00096
00097
00098 00119 class CLandscape : public NLMISC::CRefCount
00120 {
00121 public:
00122
00123 CTileBank TileBank;
00124 CTileFarBank TileFarBank;
00125
00126 public:
00127
00129 CLandscape();
00131 ~CLandscape();
00132
00133
00135 00137
00138
00144 bool addZone(const CZone &newZone);
00145
00151 bool removeZone(uint16 zoneId);
00152
00154 void clear();
00155
00157 void checkBinds() throw(EBadBind);
00159 void checkBinds(uint16 zoneId) throw(EBadBind);
00160
00166 bool initTileBanks ();
00167
00168
00169
00171 00173 00175 00177 00179
00180 void setRefineMode(bool enabled) {_RefineMode= enabled;}
00181 bool getRefineMode() const {return _RefineMode;}
00183 void setTileMaxSubdivision (uint tileDiv);
00185 uint getTileMaxSubdivision ();
00186
00187
00188
00189
00190
00191
00193 00197 void clip(const CVector &refineCenter, const std::vector<CPlane> &pyramid);
00199 void refine(const CVector &refineCenter);
00201 void render(IDriver *drv, const CVector &refineCenter, const std::vector<CPlane> &pyramid, bool doTileAddPass=false);
00203 void refineAll(const CVector &refineCenter);
00204
00205
00206
00208 00216 void buildCollideFaces(const CAABBoxExt &bbox, std::vector<CTriangle> &faces, bool faceSplit);
00220 void buildCollideFaces(sint zoneId, sint patch, std::vector<CTriangle> &faces);
00221
00222
00223
00224
00226 00232 CZone* getZone (sint zoneId);
00238 const CZone* getZone (sint zoneId) const;
00239
00240
00241
00243 00245 00247
00248
00250 NLMISC::CSmartPtr<ITexture> getTileTexture(uint16 tileId, CTile::TBitmap bitmapType, CVector &uvScaleBias);
00251
00252
00254 00262 void setupStaticLight (const CRGBA &diffuse, const CRGBA &ambiant, float multiply);
00268 const CRGBA* getStaticLight () const
00269 {
00270 return _LightValue;
00271 }
00272
00273
00274
00276 00278 00284 void setHeightField(const CHeightMap &hf);
00285
00286
00287
00288
00289
00290 private:
00291
00292 friend class CPatch;
00293 friend class CZone;
00294
00295
00296 CPatchRdrPass *getFarRenderPass(CPatch* pPatch, uint farIndex, float& far1UScale, float& far1VScale, float& far1UBias, float& far1VBias, bool& bRot);
00297
00298 void freeFarRenderPass (CPatch* pPatch, CPatchRdrPass* pass, uint farIndex);
00299
00300 CPatchRdrPass *getTileRenderPass(uint16 tileId, bool additiveRdrPass);
00301
00302
00303 void getTileUvScaleBiasRot(uint16 tileId, CTile::TBitmap bitmapType, CVector &uvScaleBias, uint8 &rotAlpha);
00304
00305
00306 void resetRenderFar();
00308 void forceMergeAtTileLevel();
00309
00310
00311 void updateGlobals (const CVector &refineCenter) const;
00312
00313 private:
00314 TZoneMap Zones;
00315
00316
00317 float _TileDistNear;
00318 float _Threshold;
00319 bool _RefineMode;
00320 float _FarTransition;
00321 uint _TileMaxSubdivision;
00322
00323
00324 CVertexBuffer FarVB;
00325 CVertexBuffer TileVB;
00326
00327
00328
00329
00330
00331 typedef NLMISC::CRefPtr<ITexture> RPTexture;
00332 typedef std::map<std::string, RPTexture> TTileTextureMap;
00333 typedef TTileTextureMap::iterator ItTileTextureMap;
00334
00335 typedef std::set<CPatchRdrPass> TTileRdrPassSet;
00336 typedef TTileRdrPassSet::iterator ItTileRdrPassSet;
00337 typedef NLMISC::CSmartPtr<CPatchRdrPass> TSPRenderPass;
00338
00339
00340 struct CTileInfo
00341 {
00342
00343
00344
00345 CPatchRdrPass *DiffuseRdrPass;
00346
00347 CPatchRdrPass *AdditiveRdrPass;
00348
00349
00350
00351 CVector DiffuseUvScaleBias;
00352 CVector AlphaUvScaleBias;
00353 CVector AdditiveUvScaleBias;
00354
00355 uint8 RotAlpha;
00356 };
00357
00358
00359
00360
00361
00362 TTileTextureMap TileTextureMap;
00363
00364 TTileRdrPassSet TileRdrPassSet;
00365
00366 std::vector<CTileInfo*> TileInfos;
00367
00368
00369 std::vector<TSPRenderPass> _TextureNears;
00370 uint _NFreeLightMaps;
00371
00372
00373
00374 CMaterial TileMaterial;
00375
00376
00377 CMaterial FarMaterial;
00378
00379
00380
00381
00382
00383
00384
00385 typedef std::set<TSPRenderPass> TSPRenderPassSet;
00386 typedef TSPRenderPassSet::iterator ItSPRenderPassSet;
00387 typedef std::vector<TSPRenderPassSet> TSPRdrPassSetVector;
00388 TSPRenderPassSet _FarRdrPassSet;
00389 TSPRdrPassSetVector _FarRdrPassSetVectorFree;
00390 bool _FarInitialized;
00391
00392
00393 bool eraseTileFarIfNotGood (uint tileNumber, uint sizeOrder0, uint sizeOrder1, uint sizeOrder2);
00394
00395
00396 static uint getRdrPassIndexWithSize (uint width, uint height);
00397 void addPatch ();
00398 void removePatch ();
00399
00400
00401
00402 CRGBA _LightValue[256];
00403
00404 private:
00405
00406 void loadTile(uint16 tileId);
00407 void releaseTile(uint16 tileId);
00408 ITexture *findTileTexture(const std::string &textName);
00409 CPatchRdrPass *findTileRdrPass(const CPatchRdrPass &pass);
00410
00411
00412
00413
00414
00415 uint getTileLightMap(CRGBA map[NL_TILE_LIGHTMAP_SIZE*NL_TILE_LIGHTMAP_SIZE], CPatchRdrPass *&lightmapRdrPass);
00416
00417 void getTileLightMapUvInfo(uint tileLightMapId, CVector &uvScaleBias);
00418
00419 void releaseTileLightMap(uint tileLightMapId);
00420
00421
00422
00423
00424 void checkZoneBinds(CZone &curZone, EBadBind &bindError);
00425
00426
00430 struct CBezierPatchZ
00431 {
00433 float Vertices[4];
00435 float Tangents[8];
00437 float Interiors[4];
00438
00440 void makeInteriors();
00442 float eval(float s, float t) const;
00443 };
00444
00445
00446
00447 struct CHeightField
00448 {
00449 std::vector<CBezierPatchZ> ZPatchs;
00450
00452 float OriginX, OriginY;
00454 float SizeX, SizeY;
00455 float OOSizeX, OOSizeY;
00457 uint Width, Height;
00458 };
00459 CHeightField _HeightField;
00460
00461 };
00462
00463
00464
00465 }
00466
00467
00468 #endif // NL_LANDSCAPE_H
00469
00470