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 "nel/misc/bit_set.h"
00034 #include "3d/tessellation.h"
00035 #include "3d/patch.h"
00036 #include "3d/bezier_patch.h"
00037 #include "3d/point_light_named.h"
00038 #include "3d/point_light_named_array.h"
00039 #include <stdio.h>
00040 #include <vector>
00041 #include <map>
00042
00043
00044 namespace NL3D
00045 {
00046
00047
00048 class CZone;
00049 class CLandscape;
00050 class CZoneSymmetrisation;
00051 class CTileBank;
00052
00053 using NLMISC::CAABBoxExt;
00054
00055
00056
00057 typedef std::map<uint16, CZone*> TZoneMap;
00058 typedef std::map<uint16, CZone*>::iterator ItZoneMap;
00059
00060
00061
00065 struct CBorderVertex
00066 {
00067
00068 uint16 CurrentVertex;
00069
00070 uint16 NeighborZoneId;
00071
00072 uint16 NeighborVertex;
00073
00074 void serial(NLMISC::IStream &f);
00075 };
00076
00077
00078
00086 struct CPatchInfo
00087 {
00088 public:
00089
00095 struct CBindInfo
00096 {
00101 uint8 NPatchs;
00102
00104 uint16 ZoneId;
00106 uint16 Next[4];
00108 uint8 Edge[4];
00109
00110 public:
00111 void serial(NLMISC::IStream &f);
00112 CBindInfo() {NPatchs=0;}
00113 };
00114
00115
00116 public:
00118
00120 CBezierPatch Patch;
00122 uint8 OrderS, OrderT;
00124 float ErrorSize;
00126 uint16 BaseVertices[4];
00127
00130 uint8 Flags;
00131
00132
00134 uint8 NoiseRotation;
00135
00137 void setCornerSmoothFlag(uint corner, bool smooth);
00138 bool getCornerSmoothFlag(uint corner) const;
00139
00140
00141
00142
00144
00145
00149 std::vector<CTileElement> Tiles;
00150
00155 std::vector<CTileColor> TileColors;
00156
00161 std::vector<uint8> Lumels;
00162
00171 std::vector<CTileLightInfluence> TileLightInfluences;
00172
00173
00174
00176
00180 void setSmoothFlag (uint edge, bool flag)
00181 {
00182
00183 Flags&=~(1<<edge);
00184
00185
00186 Flags|=(((uint)flag)<<edge);
00187 }
00188
00192 bool getSmoothFlag (uint edge)
00193 {
00194
00195 return ((Flags&(1<<edge))!=0);
00196 }
00197
00213 bool getNeighborTile (uint patchId, uint edge, sint position, uint &patchOut, sint &sOut, sint &tOut, const std::vector<CPatchInfo> &patchInfos) const;
00214
00227 static bool transform (std::vector<CPatchInfo> &patchInfo, NL3D::CZoneSymmetrisation &zoneSymmetry, const NL3D::CTileBank &bank, bool symmetry, uint rotate, float snapCell, float weldThreshold, const NLMISC::CMatrix &toOriginalSpace);
00228
00229
00230 static bool getTileSymmetryRotate (const NL3D::CTileBank &bank, uint tile, bool &symmetry, uint &rotate);
00231 static bool transformTile (const NL3D::CTileBank &bank, uint &tile, uint &tileRotation, bool symmetry, uint rotate, bool goofy);
00232 static void transform256Case (const NL3D::CTileBank &bank, uint8 &case256, uint tileRotation, bool symmetry, uint rotate, bool goofy);
00233
00235
00236 CBindInfo BindEdges[4];
00237
00238
00239
00240 public:
00241 CPatchInfo()
00242 {
00243 ErrorSize= 0;
00244
00245 NoiseRotation= 0;
00246 _CornerSmoothFlag= 0;
00247 }
00248
00249 private:
00250
00251 uint8 _CornerSmoothFlag;
00252
00253 };
00254
00255
00256
00264 struct CZoneInfo
00265 {
00267 uint16 ZoneId;
00269 std::vector<CPatchInfo> Patchs;
00274 std::vector<CBorderVertex> BorderVertices;
00275
00279 std::vector<CPointLightNamed> PointLights;
00280 };
00281
00282
00283
00297 class CZone
00298 {
00299 public:
00300
00301 struct CPatchConnect
00302 {
00303
00304 uint8 OldOrderS, OldOrderT;
00305 float ErrorSize;
00306 uint16 BaseVertices[4];
00307 CPatchInfo::CBindInfo BindEdges[4];
00308
00309 public:
00310 void serial(NLMISC::IStream &f);
00311 };
00312
00313 public:
00314
00316 CZone();
00318 ~CZone();
00319
00320
00332 void build(const CZoneInfo &zoneInfo, uint32 numVertices=0);
00333
00334
00338 void build(uint16 zoneId, const std::vector<CPatchInfo> &patchs, const std::vector<CBorderVertex> &borderVertices, uint32 numVertices=0);
00339
00340
00346 void build(const CZone &zone);
00347
00348
00355 void retrieve(CZoneInfo &zoneInfo);
00356
00357
00361 void retrieve(std::vector<CPatchInfo> &patchs, std::vector<CBorderVertex> &borderVertices);
00362
00363
00364
00368 void debugBinds(FILE *f= stdout);
00369
00370
00383 void compile(CLandscape *landscape, TZoneMap &loadedZones);
00384
00395 void release(TZoneMap &loadedZones);
00396
00397
00401 void serial(NLMISC::IStream &f);
00402
00403
00411 void changePatchTextureAndColor (sint numPatch, const std::vector<CTileElement> *tiles, const std::vector<CTileColor> *colors);
00412
00413
00425 void refreshTesselationGeometry(sint numPatch);
00426
00427
00436 const std::vector<CTileElement> &getPatchTexture(sint numPatch) const;
00437
00446 const std::vector<CTileColor> &getPatchColor(sint numPatch) const;
00447
00454 void setTileColor(bool monochrome, float factor);
00455
00461 CLandscape* getLandscape () const
00462 {
00463 return Landscape;
00464 }
00465
00466
00468 void clip(const std::vector<CPlane> &pyramid);
00470 void preRender();
00471
00472 void resetRenderFarAndDeleteVBFV();
00474 void forceMergeAtTileLevel();
00475
00477 void refineAll();
00479 void excludePatchFromRefineAll(uint patch, bool exclude);
00482 void averageTesselationVertices();
00483
00484
00485 const CVector &getPatchBias() const {return PatchBias;}
00486 float getPatchScale() const {return PatchScale;}
00487 bool compiled() const {return Compiled;}
00488 uint16 getZoneId() const {return ZoneId;}
00489 sint getNumPatchs() const {return Patchs.size();}
00490
00491 const CAABBoxExt &getZoneBB() const {return ZoneBB;}
00492
00499 const CPatch *getPatch(sint patch) const {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(Patchs[patch]);}
00500
00507 const CPatchConnect *getPatchConnect(sint patch) const
00508 {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(PatchConnects[patch]);}
00509
00510
00515 void applyHeightField(const CLandscape &landScape);
00516
00525 void setupColorsFromTileFlags(const NLMISC::CRGBA colors[4]);
00526
00530 void copyTilesFlags(sint destPatchId, const CPatch *srcPatch);
00531
00536 const CBSphere &getPatchBSphere(uint patch) const;
00537
00539 bool isPatchRenderClipped(uint patch) const {return _PatchRenderClipped.get(patch);}
00540
00541
00542 private:
00543
00544
00545 struct CTessBaseVertex : public NLMISC::CRefCount
00546 {
00547 CTessVertex Vert;
00548 };
00549
00550
00551 typedef NLMISC::CSmartPtr<CTessBaseVertex> PBaseVertex;
00552 typedef std::vector<PBaseVertex> TBaseVerticesVec;
00553
00554
00555 private:
00556
00557
00558 CLandscape *Landscape;
00559
00560
00561 uint16 ZoneId;
00562 bool Compiled;
00563 CAABBoxExt ZoneBB;
00564 CVector PatchBias;
00565 float PatchScale;
00566
00567
00568 sint32 NumVertices;
00569
00570 TBaseVerticesVec BaseVertices;
00571
00572 std::vector<CBorderVertex> BorderVertices;
00573
00574
00575
00576 std::vector<CPatch> Patchs;
00577 std::vector<CPatchConnect> PatchConnects;
00578
00579 std::vector<CBSphere> _PatchBSpheres;
00580 NLMISC::CBitSet _PatchRenderClipped;
00581 NLMISC::CBitSet _PatchOldRenderClipped;
00582
00583
00586 CPointLightNamedArray _PointLightArray;
00587
00588
00589 private:
00590 friend class CLandscape;
00591 friend class CTessFace;
00592
00593 friend class CPatch;
00594
00595 sint ClipResult;
00596 enum TClipResult {ClipIn= 0, ClipOut= 1, ClipSide= 2};
00597
00598
00599 private:
00604 void rebindBorder(TZoneMap &loadedZones);
00605
00606 PBaseVertex getBaseVertex(sint vert) const {return BaseVertices[vert];}
00607 CPatch *getPatch(sint patch) {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(Patchs[patch]);}
00608 static CPatch *getZonePatch(TZoneMap &loadedZones, sint zoneId, sint patch);
00609
00610 static void unbindPatch(CPatch &pa);
00611 static void bindPatch(TZoneMap &loadedZones, CPatch &pa, CPatchConnect &pc, bool rebind);
00612
00613 bool patchOnBorder(const CPatchConnect &pc) const;
00614
00615
00616 void computeBBScaleBias(const CAABBox &bb);
00617
00618
00619
00620 void buildBindInfo(uint patchId, uint edge, CZone *neighborZone, CPatch::CBindInfo &paBind);
00621
00622
00623 void clipPatchs(const std::vector<CPlane> &pyramid);
00624 };
00625
00626
00627 }
00628
00629
00630 #endif // NL_ZONE_H
00631
00632