00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_ZONE_H
00027 #define NL_ZONE_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/misc/stream.h"
00032 #include "nel/misc/debug.h"
00033 #include "3d/tessellation.h"
00034 #include "3d/patch.h"
00035 #include "3d/bezier_patch.h"
00036 #include "3d/point_light_named.h"
00037 #include "3d/point_light_named_array.h"
00038 #include <stdio.h>
00039 #include <vector>
00040 #include <map>
00041
00042
00043 namespace NL3D
00044 {
00045
00046
00047 class CZone;
00048 class CLandscape;
00049
00050 using NLMISC::CAABBoxExt;
00051
00052
00053
00054 typedef std::map<uint16, CZone*> TZoneMap;
00055 typedef std::map<uint16, CZone*>::iterator ItZoneMap;
00056
00057
00058
00062 struct CBorderVertex
00063 {
00064
00065 uint16 CurrentVertex;
00066
00067 uint16 NeighborZoneId;
00068
00069 uint16 NeighborVertex;
00070
00071 void serial(NLMISC::IStream &f);
00072 };
00073
00074
00075
00083 struct CPatchInfo
00084 {
00085 public:
00086
00092 struct CBindInfo
00093 {
00098 uint8 NPatchs;
00099
00101 uint16 ZoneId;
00103 uint16 Next[4];
00105 uint8 Edge[4];
00106
00107 public:
00108 void serial(NLMISC::IStream &f);
00109 CBindInfo() {NPatchs=0;}
00110 };
00111
00112
00113 public:
00115
00117
00119
00121
00123
00124
00127 uint8 Flags;
00128
00129
00131 uint8 NoiseRotation;
00132
00134 void setCornerSmoothFlag(uint corner, bool smooth);
00135 bool getCornerSmoothFlag(uint corner) const;
00136
00137
00138
00139
00141
00142
00146 std::vector<CTileElement> Tiles;
00147
00152 std::vector<CTileColor> TileColors;
00153
00158 std::vector<uint8> Lumels;
00159
00168 std::vector<CTileLightInfluence> TileLightInfluences;
00169
00170
00171
00173
00177 void setSmoothFlag (uint edge, bool flag)
00178 {
00179
00180 Flags&=~(1<<edge);
00181
00182
00183 Flags|=(((uint)flag)<<edge);
00184 }
00185
00189 bool getSmoothFlag (uint edge)
00190 {
00191
00192 return ((Flags&(1<<edge))!=0);
00193 }
00194
00196
00197 CBindInfo BindEdges[4];
00198
00199
00200
00201 public:
00202 CPatchInfo()
00203 {
00204 ErrorSize= 0;
00205
00206 NoiseRotation= 0;
00207 _CornerSmoothFlag= 0;
00208 }
00209
00210 private:
00211
00212 uint8 _CornerSmoothFlag;
00213
00214 };
00215
00216
00217
00225 struct CZoneInfo
00226 {
00228 uint16 ZoneId;
00230 std::vector<CPatchInfo> Patchs;
00235 std::vector<CBorderVertex> BorderVertices;
00236
00240 std::vector<CPointLightNamed> PointLights;
00241 };
00242
00243
00244
00258 class CZone
00259 {
00260 public:
00261
00262 struct CPatchConnect
00263 {
00264
00265 uint8 OldOrderS, OldOrderT;
00266 float ErrorSize;
00267 uint16 BaseVertices[4];
00268 CPatchInfo::CBindInfo BindEdges[4];
00269
00270 public:
00271 void serial(NLMISC::IStream &f);
00272 };
00273
00274 public:
00275
00277 CZone();
00279 ~CZone();
00280
00281
00293 void build(const CZoneInfo &zoneInfo, uint32 numVertices=0);
00294
00295
00299 void build(uint16 zoneId, const std::vector<CPatchInfo> &patchs, const std::vector<CBorderVertex> &borderVertices, uint32 numVertices=0);
00300
00301
00307 void build(const CZone &zone);
00308
00309
00316 void retrieve(CZoneInfo &zoneInfo);
00317
00318
00322 void retrieve(std::vector<CPatchInfo> &patchs, std::vector<CBorderVertex> &borderVertices);
00323
00324
00325
00329 void debugBinds(FILE *f= stdout);
00330
00331
00344 void compile(CLandscape *landscape, TZoneMap &loadedZones);
00345
00356 void release(TZoneMap &loadedZones);
00357
00358
00362 void serial(NLMISC::IStream &f);
00363
00364
00372 void changePatchTextureAndColor (sint numPatch, const std::vector<CTileElement> *tiles, const std::vector<CTileColor> *colors);
00373
00374
00386 void refreshTesselationGeometry(sint numPatch);
00387
00388
00397 const std::vector<CTileElement> &getPatchTexture(sint numPatch) const;
00398
00407 const std::vector<CTileColor> &getPatchColor(sint numPatch) const;
00408
00414 CLandscape* getLandscape () const
00415 {
00416 return Landscape;
00417 }
00418
00419
00421
00423
00424
00425 void resetRenderFarAndDeleteVBFV();
00427 void forceMergeAtTileLevel();
00428
00430 void refineAll();
00432 void excludePatchFromRefineAll(uint patch, bool exclude);
00435 void averageTesselationVertices();
00436
00437
00438 const CVector &getPatchBias() const {return PatchBias;}
00439 float getPatchScale() const {return PatchScale;}
00440 bool compiled() const {return Compiled;}
00441 uint16 getZoneId() const {return ZoneId;}
00442 sint getNumPatchs() const {return Patchs.size();}
00443
00444 const CAABBoxExt &getZoneBB() const {return ZoneBB;}
00445
00452 const CPatch *getPatch(sint patch) const {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(Patchs[patch]);}
00453
00460 const CPatchConnect *getPatchConnect(sint patch) const
00461 {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(PatchConnects[patch]);}
00462
00463
00468 void applyHeightField(const CLandscape &landScape);
00469
00478 void setupColorsFromTileFlags(const NLMISC::CRGBA colors[4]);
00479
00483 void copyTilesFlags(sint destPatchId, const CPatch *srcPatch);
00484
00485
00486 private:
00487
00488
00489 struct CTessBaseVertex : public NLMISC::CRefCount
00490 {
00491 CTessVertex Vert;
00492 };
00493
00494
00495 typedef NLMISC::CSmartPtr<CTessBaseVertex> PBaseVertex;
00496 typedef std::vector<PBaseVertex> TBaseVerticesVec;
00497
00498
00499 private:
00500
00501
00502 CLandscape *Landscape;
00503
00504
00505 uint16 ZoneId;
00506 bool Compiled;
00507 CAABBoxExt ZoneBB;
00508 CVector PatchBias;
00509 float PatchScale;
00510
00511
00512 sint32 NumVertices;
00513
00514 TBaseVerticesVec BaseVertices;
00515
00516 std::vector<CBorderVertex> BorderVertices;
00517
00518
00519
00520 std::vector<CPatch> Patchs;
00521 std::vector<CPatchConnect> PatchConnects;
00522
00525 CPointLightNamedArray _PointLightArray;
00526
00527
00528 private:
00529 friend class CLandscape;
00530 friend class CTessFace;
00531
00532 friend class CPatch;
00533
00534 sint ClipResult;
00535 enum TClipResult {ClipIn= 0, ClipOut= 1, ClipSide= 2};
00536
00537
00538 private:
00543 void rebindBorder(TZoneMap &loadedZones);
00544
00545 PBaseVertex getBaseVertex(sint vert) const {return BaseVertices[vert];}
00546 CPatch *getPatch(sint patch) {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(Patchs[patch]);}
00547 static CPatch *getZonePatch(TZoneMap &loadedZones, sint zoneId, sint patch);
00548
00549 static void unbindPatch(CPatch &pa);
00550 static void bindPatch(TZoneMap &loadedZones, CPatch &pa, CPatchConnect &pc, bool rebind);
00551
00552 bool patchOnBorder(const CPatchConnect &pc) const;
00553
00554
00555 void computeBBScaleBias(const CAABBox &bb);
00556
00557
00558
00559 void buildBindInfo(uint patchId, uint edge, CZone *neighborZone, CPatch::CBindInfo &paBind);
00560
00561 };
00562
00563
00564 }
00565
00566
00567 #endif // NL_ZONE_H
00568
00569