#include <zone.h>
Before a zone may be rendered, it must be compile()-ed, to compile and bind patch, to make vertices etc...
NB: you must call release() before deleting a compiled zone. (else assert in destruction).
Nevrax France
Definition at line 297 of file src/3d/zone.h.
Public Member Functions | |
void | applyHeightField (const CLandscape &landScape) |
void | averageTesselationVertices () |
void | build (const CZone &zone) |
void | build (uint16 zoneId, const std::vector< CPatchInfo > &patchs, const std::vector< CBorderVertex > &borderVertices, uint32 numVertices=0) |
void | build (const CZoneInfo &zoneInfo, uint32 numVertices=0) |
void | changePatchTextureAndColor (sint numPatch, const std::vector< CTileElement > *tiles, const std::vector< CTileColor > *colors) |
void | clip (const std::vector< CPlane > &pyramid) |
Clip a zone. To know if must be rendered etc... A zone is IN if in BACK of at least one plane of the pyramid. | |
void | compile (CLandscape *landscape, TZoneMap &loadedZones) |
bool | compiled () const |
void | copyTilesFlags (sint destPatchId, const CPatch *srcPatch) |
CZone () | |
Constructor. | |
void | debugBinds (FILE *f=stdout) |
void | excludePatchFromRefineAll (uint patch, bool exclude) |
This is especially for Pacs. exlude a patch to be refineAll()ed. | |
void | forceMergeAtTileLevel () |
For changing TileMaxSubdivision. force tesselation to be under tile. | |
CLandscape * | getLandscape () const |
sint | getNumPatchs () const |
const CPatch * | getPatch (sint patch) const |
const CVector & | getPatchBias () const |
const CBSphere & | getPatchBSphere (uint patch) const |
const std::vector< CTileColor > & | getPatchColor (sint numPatch) const |
const CPatchConnect * | getPatchConnect (sint patch) const |
float | getPatchScale () const |
const std::vector< CTileElement > & | getPatchTexture (sint numPatch) const |
const CAABBoxExt & | getZoneBB () const |
uint16 | getZoneId () const |
bool | isPatchRenderClipped (uint patch) const |
Is the patch clipped (ie not visible). crash if bad Id. | |
void | preRender () |
PreRender a zone (if needed). | |
void | refineAll () |
force Refine a zone. | |
void | refreshTesselationGeometry (sint numPatch) |
void | release (TZoneMap &loadedZones) |
void | resetRenderFarAndDeleteVBFV () |
void | retrieve (std::vector< CPatchInfo > &patchs, std::vector< CBorderVertex > &borderVertices) |
void | retrieve (CZoneInfo &zoneInfo) |
void | serial (NLMISC::IStream &f) |
void | setTileColor (bool monochrome, float factor) |
void | setupColorsFromTileFlags (const NLMISC::CRGBA colors[4]) |
~CZone () | |
Destructor. | |
Private Types | |
typedef NLMISC::CSmartPtr< CTessBaseVertex > | PBaseVertex |
typedef std::vector< PBaseVertex > | TBaseVerticesVec |
enum | TClipResult { ClipIn = 0, ClipOut = 1, ClipSide = 2 } |
Private Member Functions | |
void | buildBindInfo (uint patchId, uint edge, CZone *neighborZone, CPatch::CBindInfo &paBind) |
void | clipPatchs (const std::vector< CPlane > &pyramid) |
void | computeBBScaleBias (const CAABBox &bb) |
PBaseVertex | getBaseVertex (sint vert) const |
CPatch * | getPatch (sint patch) |
bool | patchOnBorder (const CPatchConnect &pc) const |
void | rebindBorder (TZoneMap &loadedZones) |
Static Private Member Functions | |
void | bindPatch (TZoneMap &loadedZones, CPatch &pa, CPatchConnect &pc, bool rebind) |
CPatch * | getZonePatch (TZoneMap &loadedZones, sint zoneId, sint patch) |
void | unbindPatch (CPatch &pa) |
Private Attributes | |
std::vector< CBSphere > | _PatchBSpheres |
NLMISC::CBitSet | _PatchOldRenderClipped |
NLMISC::CBitSet | _PatchRenderClipped |
CPointLightNamedArray | _PointLightArray |
TBaseVerticesVec | BaseVertices |
std::vector< CBorderVertex > | BorderVertices |
sint | ClipResult |
bool | Compiled |
CLandscape * | Landscape |
sint32 | NumVertices |
CVector | PatchBias |
std::vector< CPatchConnect > | PatchConnects |
std::vector< CPatch > | Patchs |
float | PatchScale |
CAABBoxExt | ZoneBB |
uint16 | ZoneId |
Friends | |
class | CLandscape |
class | CPatch |
class | CTessFace |
|
Definition at line 551 of file src/3d/zone.h. Referenced by getBaseVertex(). |
|
Definition at line 552 of file src/3d/zone.h. |
|
Definition at line 596 of file src/3d/zone.h.
|
|
Constructor.
Definition at line 83 of file 3d/zone.cpp. References ClipOut, ClipResult, and Compiled.
00084 { 00085 ZoneId= 0; 00086 Compiled= false; 00087 Landscape= NULL; 00088 ClipResult= ClipOut; 00089 } |
|
Destructor.
Definition at line 91 of file 3d/zone.cpp. References Compiled, and nlassert.
00092 { 00093 // release() must have been called. 00094 nlassert(!Compiled); 00095 } |
|
apply a landscape heightfield on a zone (modification of Z control points values). NB: this is done in Landscape addZone(), before compile().
Definition at line 1452 of file 3d/zone.cpp. References computeBBScaleBias(), NLMISC::CAABBox::extend(), NL3D::CLandscape::getHeightFieldDeltaZ(), NL3D::CBezierPatch::Interiors, NL3D::CPatch::Interiors, NL3D::CVector3s::pack(), PatchBias, PatchScale, NLMISC::CAABBox::setCenter(), NLMISC::CAABBox::setHalfSize(), sint, NL3D::CBezierPatch::Tangents, NL3D::CPatch::Tangents, NL3D::CVector3s::unpack(), NL3D::CBezierPatch::Vertices, NL3D::CPatch::Vertices, NLMISC::CVector::x, and NLMISC::CVector::y. Referenced by NL3D::CLandscape::addZone().
01453 { 01454 sint i,j; 01455 vector<CBezierPatch> patchs; 01456 01457 // no patch, do nothing. 01458 if(Patchs.size()==0) 01459 return; 01460 01461 // 0. Unpack patchs to Bezier Patchs. 01462 //=================================== 01463 patchs.resize(Patchs.size()); 01464 for(j=0;j<(sint)patchs.size();j++) 01465 { 01466 CBezierPatch &p= patchs[j]; 01467 CPatch &pa= Patchs[j]; 01468 01469 // re-Build the uncompressed bezier patch. 01470 for(i=0;i<4;i++) 01471 pa.Vertices[i].unpack(p.Vertices[i], PatchBias, PatchScale); 01472 for(i=0;i<8;i++) 01473 pa.Tangents[i].unpack(p.Tangents[i], PatchBias, PatchScale); 01474 for(i=0;i<4;i++) 01475 pa.Interiors[i].unpack(p.Interiors[i], PatchBias, PatchScale); 01476 } 01477 01478 // 1. apply heightfield on bezier patchs. 01479 //=================================== 01480 for(j=0;j<(sint)patchs.size();j++) 01481 { 01482 CBezierPatch &p= patchs[j]; 01483 01484 // apply delta. 01485 for(i=0;i<4;i++) 01486 p.Vertices[i]+= landScape.getHeightFieldDeltaZ(p.Vertices[i].x, p.Vertices[i].y); 01487 for(i=0;i<8;i++) 01488 p.Tangents[i]+= landScape.getHeightFieldDeltaZ(p.Tangents[i].x, p.Tangents[i].y); 01489 for(i=0;i<4;i++) 01490 p.Interiors[i]+= landScape.getHeightFieldDeltaZ(p.Interiors[i].x, p.Interiors[i].y); 01491 } 01492 01493 01494 // 2. Re-compute Patch Scale/Bias, and Zone BBox. 01495 //=================================== 01496 CAABBox bb; 01497 bb.setCenter(patchs[0].Vertices[0]); 01498 bb.setHalfSize(CVector::Null); 01499 for(j=0;j<(sint)patchs.size();j++) 01500 { 01501 // extend bbox. 01502 const CBezierPatch &p= patchs[j]; 01503 for(i=0;i<4;i++) 01504 bb.extend(p.Vertices[i]); 01505 for(i=0;i<8;i++) 01506 bb.extend(p.Tangents[i]); 01507 for(i=0;i<4;i++) 01508 bb.extend(p.Interiors[i]); 01509 } 01510 // Compute BBox, and Patch Scale Bias, according to Noise. 01511 computeBBScaleBias(bb); 01512 01513 01514 // 3. Re-pack patchs. 01515 //=================================== 01516 for(j=0;j<(sint)patchs.size();j++) 01517 { 01518 CBezierPatch &p= patchs[j]; 01519 CPatch &pa= Patchs[j]; 01520 01521 // Build the packed patch. 01522 for(i=0;i<4;i++) 01523 pa.Vertices[i].pack(p.Vertices[i], PatchBias, PatchScale); 01524 for(i=0;i<8;i++) 01525 pa.Tangents[i].pack(p.Tangents[i], PatchBias, PatchScale); 01526 for(i=0;i<4;i++) 01527 pa.Interiors[i].pack(p.Interiors[i], PatchBias, PatchScale); 01528 } 01529 } |
|
This is especially for Pacs. see CLandscape desc. Definition at line 1157 of file 3d/zone.cpp. References NL3D::CPatch::averageTesselationVertices(), Compiled, nlassert, and sint.
01158 { 01159 nlassert(Compiled); 01160 01161 // Fuck stlport.... 01162 if(Patchs.size()==0) 01163 return; 01164 01165 // averageTesselationVertices of ALL patchs. 01166 CPatch *pPatch= &(*Patchs.begin()); 01167 for(sint n=(sint)Patchs.size();n>0;n--, pPatch++) 01168 { 01169 pPatch->averageTesselationVertices(); 01170 } 01171 } |
|
Definition at line 776 of file 3d/zone.cpp. References NL3D::CPatch::bind(), NL3D::CZone::CPatchConnect::BindEdges, NL3D::CPatchInfo::CBindInfo::Edge, NL3D::CPatch::CBindInfo::Edge, NL3D::CPatch::getBindNeighbor(), NL3D::CPatchInfo::CBindInfo::Next, NL3D::CPatch::CBindInfo::Next, nlassert, NL3D::CPatch::CBindInfo::NPatchs, NL3D::CPatchInfo::CBindInfo::NPatchs, sint, NL3D::TZoneMap, NL3D::CPatch::unbind(), NL3D::CPatch::CBindInfo::Zone, and NL3D::CPatchInfo::CBindInfo::ZoneId. Referenced by compile(), and rebindBorder().
00777 { 00778 CPatch::CBindInfo edges[4]; 00779 00780 // Fill all edges. 00781 for(sint i=0;i<4;i++) 00782 { 00783 CPatchInfo::CBindInfo &pcBind= pc.BindEdges[i]; 00784 CPatch::CBindInfo &paBind= edges[i]; 00785 00786 nlassert(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); 00787 paBind.NPatchs= pcBind.NPatchs; 00788 00789 00790 // Find the zone. 00791 TZoneMap::iterator itZoneMap; 00792 // If no neighbor, or if zone neighbor not loaded. 00793 if( paBind.NPatchs==0 || (itZoneMap=loadedZones.find(pcBind.ZoneId)) == loadedZones.end() ) 00794 paBind.Zone= NULL; 00795 else 00796 paBind.Zone= itZoneMap->second; 00797 00798 00799 // Special case of a small patch connected to a bigger. 00800 if(paBind.NPatchs==5) 00801 { 00802 paBind.Edge[0]= pcBind.Edge[0]; 00803 paBind.Next[0]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[0]); 00804 // If not loaded, don't bind to this edge. 00805 if(!paBind.Next[0]) 00806 paBind.NPatchs=0; 00807 else 00808 { 00809 // Get the BindInfo on me stored in our neighbor bigger CPatch 00810 CPatch::CBindInfo nbOnMe; 00811 paBind.Next[0]->getBindNeighbor(paBind.Edge[0], nbOnMe); 00812 // if this patch has not already been binded on me, nbOnMe.Zone==NULL 00813 if( nbOnMe.Zone == NULL ) 00814 { 00815 // Simple case: do nothing: don't need to rebind() to the bigger patch since 00816 // himself is not bound 00817 paBind.NPatchs=0; 00818 paBind.Zone= NULL; 00819 } 00820 else 00821 { 00822 // pa.bind() will do the job. 00823 // Leave it flagged with NPatchs==5. 00824 continue; 00825 } 00826 } 00827 } 00828 00829 00830 // Bind 1/1 and 1/2,1/4 00831 if(paBind.NPatchs>=1) 00832 { 00833 paBind.Edge[0]= pcBind.Edge[0]; 00834 paBind.Next[0]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[0]); 00835 // If not loaded, don't bind to this edge. 00836 if(!paBind.Next[0]) 00837 paBind.NPatchs=0; 00838 } 00839 if(paBind.NPatchs>=2) 00840 { 00841 paBind.Edge[1]= pcBind.Edge[1]; 00842 paBind.Next[1]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[1]); 00843 // If not loaded, don't bind to this edge. 00844 if(!paBind.Next[1]) 00845 paBind.NPatchs=0; 00846 } 00847 if(paBind.NPatchs>=4) 00848 { 00849 paBind.Edge[2]= pcBind.Edge[2]; 00850 paBind.Edge[3]= pcBind.Edge[3]; 00851 paBind.Next[2]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[2]); 00852 paBind.Next[3]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[3]); 00853 // If not loaded, don't bind to this edge. 00854 if(!paBind.Next[2] || !paBind.Next[3]) 00855 paBind.NPatchs=0; 00856 } 00857 } 00858 00859 // First, unbind. 00860 pa.unbind(); 00861 00862 // Then bind. 00863 pa.bind(edges, rebind); 00864 } |
|
Build a copy of a zone. This method do a copy of zone (should be builded but maybe not compiled). NB: cannot build on a compiled zone. must release the zone before.... Definition at line 365 of file 3d/zone.cpp. References _PatchOldRenderClipped, _PatchRenderClipped, _PointLightArray, BorderVertices, Compiled, nlassert, NumVertices, PatchBias, PatchConnects, Patchs, PatchScale, NLMISC::CBitSet::resize(), NLMISC::CBitSet::setAll(), ZoneBB, and ZoneId.
00366 { 00367 nlassert(!Compiled); 00368 00369 ZoneId= zone.ZoneId; 00370 BorderVertices= zone.BorderVertices; 00371 00372 // Compute the bbox and the bias/scale. 00373 //===================================== 00374 ZoneBB= zone.ZoneBB; 00375 PatchScale= zone.PatchScale; 00376 PatchBias= zone.PatchBias; 00377 00378 00379 // Compute/compress Patchs. 00380 //========================= 00381 Patchs= zone.Patchs; 00382 PatchConnects= zone.PatchConnects; 00383 00384 // Init the Clip Arrays 00385 _PatchRenderClipped.resize(Patchs.size()); 00386 _PatchOldRenderClipped.resize(Patchs.size()); 00387 _PatchRenderClipped.setAll(); 00388 _PatchOldRenderClipped.setAll(); 00389 00390 00391 // copy pointLights. 00392 //========================= 00393 _PointLightArray= zone._PointLightArray; 00394 00395 00396 NumVertices= zone.NumVertices; 00397 } |
|
Build a zone. Deprecated. Should use build(CZoneInfo &) instead. see this method Definition at line 112 of file 3d/zone.cpp. References NL3D::CZoneInfo::BorderVertices, build(), NL3D::CZoneInfo::Patchs, uint16, uint32, and NL3D::CZoneInfo::ZoneId.
00113 { 00114 CZoneInfo zinfo; 00115 zinfo.ZoneId= zoneId; 00116 zinfo.Patchs= patchs; 00117 zinfo.BorderVertices= borderVertices; 00118 00119 build(zinfo, numVertices); 00120 } |
|
Build a zone. This method do:
NB: cannot build on a compiled zone. must release the zone before....
Definition at line 122 of file 3d/zone.cpp. References _PatchOldRenderClipped, _PatchRenderClipped, NL3D::CPatchInfo::BaseVertices, NL3D::CZone::CPatchConnect::BaseVertices, NL3D::CPatchInfo::BindEdges, NL3D::CZone::CPatchConnect::BindEdges, NL3D::CZoneInfo::BorderVertices, NL3D::CPointLightNamedArray::build(), Compiled, computeBBScaleBias(), NL3D::CPatchInfo::ErrorSize, NL3D::CZone::CPatchConnect::ErrorSize, NLMISC::CAABBox::extend(), NL3D::CPatchInfo::Flags, NL3D::CPatch::Flags, NL3D::CPatchInfo::getCornerSmoothFlag(), NL3D::CPointLightNamedArray::getPointLights(), NL3D::CPatch::Interiors, NL3D::CBezierPatch::Interiors, NL3D::CTileLightInfluence::Light, NL3D::CPatchInfo::Lumels, NL_LUMEL_BY_TILE, NL_PATCH_SMOOTH_FLAG_MASK, NL_PATCH_SMOOTH_FLAG_SHIFT, nlassert, NL3D::CPatchInfo::NoiseRotation, NL3D::CPatch::NoiseRotation, NL3D::CPatchInfo::OrderS, NL3D::CPatch::OrderS, NL3D::CPatchInfo::OrderT, NL3D::CPatch::OrderT, NL3D::CVector3s::pack(), NL3D::CPatch::packShadowMap(), NL3D::CPatchInfo::Patch, PatchBias, PatchConnects, NL3D::CZoneInfo::Patchs, PatchScale, NL3D::CZoneInfo::PointLights, NL3D::CPatch::resetCompressedLumels(), NL3D::CPatch::resetTileLightInfluences(), NLMISC::CBitSet::resize(), NLMISC::CBitSet::setAll(), NLMISC::CAABBox::setCenter(), NL3D::CPatch::setCornerSmoothFlag(), NLMISC::CAABBox::setHalfSize(), sint, NL3D::CPatch::Tangents, NL3D::CBezierPatch::Tangents, NL3D::CPatchInfo::TileColors, NL3D::CPatch::TileColors, NL3D::CPatch::TileLightInfluences, NL3D::CPatchInfo::TileLightInfluences, NL3D::CPatchInfo::Tiles, NL3D::CPatch::Tiles, uint, uint16, uint32, NL3D::CPatch::Vertices, NL3D::CBezierPatch::Vertices, and NL3D::CZoneInfo::ZoneId. Referenced by NL3D::CLandscape::addZone(), build(), and NL3D::CZoneLighter::light().
00123 { 00124 sint i,j; 00125 nlassert(!Compiled); 00126 00127 // Ref inupt 00128 uint16 zoneId= zoneInfo.ZoneId; 00129 const std::vector<CPatchInfo> &patchs= zoneInfo.Patchs; 00130 const std::vector<CBorderVertex> &borderVertices= zoneInfo.BorderVertices; 00131 00132 00133 ZoneId= zoneId; 00134 BorderVertices= borderVertices; 00135 00136 // Compute the bbox and the bias/scale. 00137 //===================================== 00138 CAABBox bb; 00139 if(patchs.size()) 00140 bb.setCenter(patchs[0].Patch.Vertices[0]); 00141 bb.setHalfSize(CVector::Null); 00142 for(j=0;j<(sint)patchs.size();j++) 00143 { 00144 const CBezierPatch &p= patchs[j].Patch; 00145 for(i=0;i<4;i++) 00146 bb.extend(p.Vertices[i]); 00147 for(i=0;i<8;i++) 00148 bb.extend(p.Tangents[i]); 00149 for(i=0;i<4;i++) 00150 bb.extend(p.Interiors[i]); 00151 } 00152 // Compute BBox, and Patch Scale Bias, according to Noise. 00153 computeBBScaleBias(bb); 00154 00155 00156 // Compute/compress Patchs. 00157 //========================= 00158 Patchs.resize(patchs.size()); 00159 PatchConnects.resize(patchs.size()); 00160 sint maxVertex=-1; 00161 for(j=0;j<(sint)patchs.size();j++) 00162 { 00163 const CPatchInfo &pi= patchs[j]; 00164 const CBezierPatch &p= pi.Patch; 00165 CPatch &pa= Patchs[j]; 00166 CPatchConnect &pc= PatchConnects[j]; 00167 00168 // Smoothing flags 00169 pa.Flags&=~NL_PATCH_SMOOTH_FLAG_MASK; 00170 pa.Flags|=NL_PATCH_SMOOTH_FLAG_MASK&(pi.Flags<<NL_PATCH_SMOOTH_FLAG_SHIFT); 00171 00172 00173 // Noise Data 00174 // copy noise rotation. 00175 pa.NoiseRotation= pi.NoiseRotation; 00176 // copy all noise smoothing info. 00177 for(i=0;i<4;i++) 00178 { 00179 pa.setCornerSmoothFlag(i, pi.getCornerSmoothFlag(i)); 00180 } 00181 00182 // Copy order of the patch 00183 pa.OrderS= pi.OrderS; 00184 pa.OrderT= pi.OrderT; 00185 00186 // Build the patch. 00187 for(i=0;i<4;i++) 00188 pa.Vertices[i].pack(p.Vertices[i], PatchBias, PatchScale); 00189 for(i=0;i<8;i++) 00190 pa.Tangents[i].pack(p.Tangents[i], PatchBias, PatchScale); 00191 for(i=0;i<4;i++) 00192 pa.Interiors[i].pack(p.Interiors[i], PatchBias, PatchScale); 00193 pa.Tiles= pi.Tiles; 00194 pa.TileColors= pi.TileColors; 00195 /* Copy TileLightInfluences. It is possible that pi.TileLightInfluences.size()!= 0 00196 and pi.TileLightInfluences.size()!= (uint)(pi.OrderS/2+1)*(pi.OrderT/2+1) 00197 Because of a preceding bug where pa.OrderS and pa.OrderT were not initialized before the 00198 pa.resetTileLightInfluences(); 00199 */ 00200 if( pi.TileLightInfluences.size()!= (uint)(pi.OrderS/2+1)*(pi.OrderT/2+1) ) 00201 { 00202 pa.resetTileLightInfluences(); 00203 } 00204 else 00205 { 00206 pa.TileLightInfluences= pi.TileLightInfluences; 00207 } 00208 00209 // Number of lumels in this patch 00210 uint lumelCount=(pi.OrderS*NL_LUMEL_BY_TILE)*(pi.OrderT*NL_LUMEL_BY_TILE); 00211 00212 // Lumel empty ? 00213 if (pi.Lumels.size ()==lumelCount) 00214 { 00215 // Pack the lumel map 00216 pa.packShadowMap (&pi.Lumels[0]); 00217 } 00218 else 00219 { 00220 // Reset lightmap 00221 pa.resetCompressedLumels (); 00222 } 00223 00224 nlassert(pa.Tiles.size()== (uint)pi.OrderS*pi.OrderT); 00225 nlassert(pa.TileColors.size()== (uint)(pi.OrderS+1)*(pi.OrderT+1)); 00226 00227 // Build the patchConnect. 00228 pc.ErrorSize= pi.ErrorSize; 00229 for(i=0;i<4;i++) 00230 { 00231 pc.BaseVertices[i]= pi.BaseVertices[i]; 00232 maxVertex= max((sint)pc.BaseVertices[i], maxVertex); 00233 } 00234 for(i=0;i<4;i++) 00235 pc.BindEdges[i]= pi.BindEdges[i]; 00236 } 00237 00238 NumVertices= maxVertex+1; 00239 NumVertices= max((uint32)NumVertices, numVertices); 00240 00241 // Init the Clip Arrays 00242 _PatchRenderClipped.resize(Patchs.size()); 00243 _PatchOldRenderClipped.resize(Patchs.size()); 00244 _PatchRenderClipped.setAll(); 00245 _PatchOldRenderClipped.setAll(); 00246 00247 // Copy PointLights. 00248 //========================= 00249 // build array, lights are sorted 00250 std::vector<uint> plRemap; 00251 _PointLightArray.build(zoneInfo.PointLights, plRemap); 00252 // Check TileLightInfluences integrity, and remap PointLight Indices. 00253 for(j=0;j<(sint)patchs.size();j++) 00254 { 00255 CPatch &pa= Patchs[j]; 00256 for(uint k= 0; k<pa.TileLightInfluences.size(); k++) 00257 { 00258 CTileLightInfluence &tli= pa.TileLightInfluences[k]; 00259 for(uint l=0; l<CTileLightInfluence::NumLightPerCorner; l++) 00260 { 00261 // If NULL light, break and continue to next TileLightInfluence. 00262 if(tli.Light[l]== 0xFF) 00263 break; 00264 else 00265 { 00266 // Check good index. 00267 nlassert(tli.Light[l] < _PointLightArray.getPointLights().size()); 00268 // Remap index, because of light sorting. 00269 tli.Light[l]= plRemap[tli.Light[l]]; 00270 } 00271 00272 } 00273 } 00274 } 00275 } |
|
Definition at line 718 of file 3d/zone.cpp. References NL3D::CZone::CPatchConnect::BindEdges, NL3D::CPatchInfo::CBindInfo::Edge, NL3D::CPatch::CBindInfo::Edge, getPatch(), getPatchConnect(), NL3D::CPatch::CBindInfo::MultipleBindId, NL3D::CPatch::CBindInfo::MultipleBindNum, NL3D::CPatchInfo::CBindInfo::Next, NL3D::CPatch::CBindInfo::Next, nlassert, NL3D::CPatch::CBindInfo::NPatchs, NL3D::CPatchInfo::CBindInfo::NPatchs, PatchConnects, sint, uint, and NL3D::CPatch::CBindInfo::Zone. Referenced by NL3D::CPatch::getBindNeighbor().
00719 { 00720 nlassert(patchId < Patchs.size()); 00721 nlassert(neighborZone); 00722 00723 CPatchConnect &pc= PatchConnects[patchId]; 00724 00725 00726 // Get the bind info of this patch to his neighbor on "edge". 00727 CPatchInfo::CBindInfo &pcBind= pc.BindEdges[edge]; 00728 nlassert(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); 00729 00730 00731 // copy zone ptr. 00732 paBind.Zone= neighborZone; 00733 00734 00735 // Special case of a small patch connected to a bigger. 00736 if(pcBind.NPatchs==5) 00737 { 00738 paBind.NPatchs= 1; 00739 paBind.Next[0]= neighborZone->getPatch(pcBind.Next[0]); 00740 paBind.Edge[0]= pcBind.Edge[0]; 00741 00742 // Get the twin bindInfo of pcBind. 00743 const CPatchInfo::CBindInfo &pcBindNeighbor= 00744 neighborZone->getPatchConnect(pcBind.Next[0])->BindEdges[pcBind.Edge[0]]; 00745 // must have a multiple bind. 00746 nlassert(pcBindNeighbor.NPatchs == 2 || pcBindNeighbor.NPatchs == 4); 00747 00748 // number of bind is stored on the twin bindInfo. 00749 paBind.MultipleBindNum= pcBindNeighbor.NPatchs; 00750 00751 // Search our patchId on neighbor; 00752 paBind.MultipleBindId= 255; 00753 for(sint i=0; i<paBind.MultipleBindNum; i++) 00754 { 00755 if(pcBindNeighbor.Next[i]==patchId) 00756 paBind.MultipleBindId= i; 00757 } 00758 nlassert(paBind.MultipleBindId!= 255); 00759 } 00760 else 00761 { 00762 paBind.MultipleBindNum= 0; 00763 paBind.NPatchs= pcBind.NPatchs; 00764 for(sint i=0;i<paBind.NPatchs; i++) 00765 { 00766 paBind.Next[i]= neighborZone->getPatch(pcBind.Next[i]); 00767 paBind.Edge[i]= pcBind.Edge[i]; 00768 } 00769 } 00770 00771 00772 } |
|
Update and refresh a patch texture. Usefull for Tile edition. Even if patch is in tile mode, it is refreshed...
Definition at line 1279 of file 3d/zone.cpp. References _PatchRenderClipped, Compiled, getNumPatchs(), nlassert, sint, NL3D::CLandscape::unlockBuffers(), NL3D::CLandscape::updateGlobalsAndLockBuffers(), and NL3D::CLandscape::updateTessBlocksFaceVector().
01280 { 01281 nlassert(numPatch>=0); 01282 nlassert(numPatch<getNumPatchs()); 01283 01284 01285 // Update the patch texture. 01286 if (tiles) 01287 { 01288 nlassert( Patchs[numPatch].Tiles.size() == tiles->size() ); 01289 Patchs[numPatch].Tiles = *tiles; 01290 } 01291 01292 // Update the patch colors. 01293 if (colors) 01294 { 01295 nlassert( Patchs[numPatch].TileColors.size() == colors->size() ); 01296 Patchs[numPatch].TileColors = *colors; 01297 } 01298 01299 if (Compiled) 01300 { 01301 // If the patch is visible, then we must LockBuffers, because new VertexVB may be created. 01302 if(!_PatchRenderClipped[numPatch]) 01303 Landscape->updateGlobalsAndLockBuffers(CVector::Null); 01304 01305 // Recompute UVs for new setup of Tiles. 01306 Patchs[numPatch].deleteTileUvs(); 01307 Patchs[numPatch].recreateTileUvs(); 01308 01309 // unlockBuffers() if necessary. 01310 if(!_PatchRenderClipped[numPatch]) 01311 { 01312 Landscape->unlockBuffers(); 01313 // This patch is visible, and TileFaces have been deleted / added. 01314 // So must update TessBlock. 01315 Landscape->updateTessBlocksFaceVector(); 01316 } 01317 } 01318 } |
|
Clip a zone. To know if must be rendered etc... A zone is IN if in BACK of at least one plane of the pyramid.
Definition at line 922 of file 3d/zone.cpp. References _PatchOldRenderClipped, _PatchRenderClipped, NLMISC::CBitSet::clearAll(), NLMISC::CAABBoxExt::clipBack(), NLMISC::CAABBoxExt::clipFront(), ClipIn, ClipOut, clipPatchs(), ClipResult, ClipSide, Compiled, NLMISC::CBitSet::getVector(), H_AUTO, min, nlassert, NLMISC::CBitSet::setAll(), sint, uint, uint32, and ZoneBB.
00923 { 00924 H_AUTO( NLMISC_ClipZone ); 00925 00926 nlassert(Compiled); 00927 00928 // bkup old ClipResult. NB: by default, it is ClipOut (no VB created). 00929 sint oldClipResult= ClipResult; 00930 00931 // Pyramid with only the planes that clip the zone 00932 static std::vector<CPlane> patchPyramid(10); 00933 static std::vector<uint> patchPyramidIndex(10); 00934 patchPyramidIndex.clear(); 00935 00936 // Compute ClipResult. 00937 //------------------- 00938 ClipResult= ClipIn; 00939 for(sint i=0;i<(sint)pyramid.size();i++) 00940 { 00941 // If entirely out. 00942 if(!ZoneBB.clipBack(pyramid[i])) 00943 { 00944 ClipResult= ClipOut; 00945 // If out of only one plane, out of all. 00946 break; 00947 } 00948 // If partially IN (ie not entirely out, and not entirely IN) 00949 else if(ZoneBB.clipFront(pyramid[i])) 00950 { 00951 // Force ClipResult to be ClipSide, and not ClipIn. 00952 ClipResult=ClipSide; 00953 // Append the plane index to list to test 00954 patchPyramidIndex.push_back(i); 00955 } 00956 } 00957 00958 00959 // Easy Clip :) 00960 if(Patchs.empty()) 00961 { 00962 ClipResult= ClipOut; 00963 // don't need to go below... 00964 return; 00965 } 00966 00967 00968 // Clip By Patch Pass. 00969 //-------------------- 00970 if(ClipResult==ClipOut) 00971 { 00972 H_AUTO( NLMISC_ClipZone_Out ); 00973 00974 // Set All RenderClip flags to true. 00975 _PatchRenderClipped.setAll(); 00976 } 00977 else if(ClipResult==ClipIn) 00978 { 00979 H_AUTO( NLMISC_ClipZone_In ); 00980 00981 // Set All RenderClip flags to false. 00982 _PatchRenderClipped.clearAll(); 00983 } 00984 else 00985 { 00986 H_AUTO( NLMISC_ClipZone_Side ); 00987 00988 // Copy only the pyramid planes of interest 00989 patchPyramid.resize(patchPyramidIndex.size()); 00990 uint i; 00991 for(i=0;i<patchPyramidIndex.size();i++) 00992 { 00993 patchPyramid[i]= pyramid[patchPyramidIndex[i]]; 00994 } 00995 00996 // clip all patchs with the simplified pyramid 00997 clipPatchs(patchPyramid); 00998 } 00999 01000 01001 // delete / reallocate / fill VBuffers. 01002 //------------------- 01003 // If there is a change in the Clip of the zone, or if patchs may have change (ie ClipSide is undetermined). 01004 if(oldClipResult!=ClipResult || oldClipResult==ClipSide) 01005 { 01006 // get BitSet as Raw Array of uint32 01007 uint32 *oldRenderClip= const_cast<uint32*>(&_PatchOldRenderClipped.getVector()[0]); 01008 const uint32 *newRenderClip= &_PatchRenderClipped.getVector()[0]; 01009 uint numPatchs= Patchs.size(); 01010 // Then, we must test by patch. 01011 for(uint i=0;i<numPatchs;oldRenderClip++, newRenderClip++) 01012 { 01013 uint32 oldWord= *oldRenderClip; 01014 uint32 newWord= *newRenderClip; 01015 // process at max 32 patch 01016 uint maxNumBits= min((numPatchs-i), 32U); 01017 uint32 mask= 1; 01018 for(;maxNumBits>0;maxNumBits--, mask<<=1, i++) 01019 { 01020 // same as: if(_PatchOldRenderClipped[i] != _PatchRenderClipped[i]) 01021 if( (oldWord^newWord)&mask ) 01022 { 01023 // set the flag. 01024 *oldRenderClip&= ~mask; 01025 *oldRenderClip|= newWord&mask; 01026 // update clip patch 01027 Patchs[i].updateClipPatchVB( (newWord&mask)!=0 ); 01028 } 01029 } 01030 } 01031 01032 } 01033 01034 } |
|
Definition at line 1038 of file 3d/zone.cpp. References _PatchBSpheres, _PatchRenderClipped, NLMISC::CBitSet::clearAll(), NLMISC::CBSphere::clipBack(), NLMISC::CBitSet::set(), sint, and uint. Referenced by clip().
01039 { 01040 // Init all to Not clipped 01041 _PatchRenderClipped.clearAll(); 01042 01043 for(uint j=0;j<_PatchBSpheres.size();j++) 01044 { 01045 CBSphere &bSphere= _PatchBSpheres[j]; 01046 for(sint i=0;i<(sint)pyramid.size();i++) 01047 { 01048 // If entirely out. 01049 if(!bSphere.clipBack(pyramid[i])) 01050 { 01051 _PatchRenderClipped.set(j, true); 01052 break; 01053 } 01054 } 01055 } 01056 } |
|
Compile a zone. Make it usable for clip()/refine()/render(). This method do:
A zone must keep a pointer on a landscape, for texture management. NB: assert if already compiled. assert if zone already exist in loadedZones. Definition at line 499 of file 3d/zone.cpp. References _PatchBSpheres, NL3D::CZone::CPatchConnect::BaseVertices, bindPatch(), NL3D::CPatch::buildBBox(), NL3D::CPatch::compile(), Compiled, NL3D::CZone::CPatchConnect::ErrorSize, NLMISC::CAABBox::getCenter(), NLMISC::CAABBox::getRadius(), NL3D::ItZoneMap, nlassert, NL3D::CPatch::OrderS, NL3D::CPatch::OrderT, PatchConnects, sint, and NL3D::TZoneMap. Referenced by NL3D::CLandscape::addZone().
00500 { 00501 sint i,j; 00502 TZoneMap neighborZones; 00503 00504 //nlinfo("Compile Zone: %d \n", (sint32)getZoneId()); 00505 00506 // Can't compile if compiled. 00507 nlassert(!Compiled); 00508 Landscape= landscape; 00509 00510 // Attach this to loadedZones. 00511 //============================ 00512 nlassert(loadedZones.find(ZoneId)==loadedZones.end()); 00513 loadedZones[ZoneId]= this; 00514 00515 // Create/link the base vertices according to present neigbor zones. 00516 //============================ 00517 BaseVertices.clear(); 00518 BaseVertices.resize(NumVertices); 00519 // First try to link vertices to other. 00520 for(i=0;i<(sint)BorderVertices.size();i++) 00521 { 00522 sint cur= BorderVertices[i].CurrentVertex; 00523 sint vertto= BorderVertices[i].NeighborVertex; 00524 sint zoneto= BorderVertices[i].NeighborZoneId; 00525 nlassert(cur<NumVertices); 00526 00527 if(loadedZones.find(zoneto)!=loadedZones.end()) 00528 { 00529 CZone *zone; 00530 zone= (*loadedZones.find(zoneto)).second; 00531 nlassert(zone!=this); 00532 // insert the zone in the neigborood (if not done...). 00533 neighborZones[zoneto]= zone; 00534 // Doesn't matter if BaseVertices is already linked to an other zone... 00535 // This should be the same pointer in this case... 00536 BaseVertices[cur]= zone->getBaseVertex(vertto); 00537 } 00538 } 00539 // Else, create unbounded vertices. 00540 for(i=0;i<(sint)BaseVertices.size();i++) 00541 { 00542 if(BaseVertices[i]==NULL) 00543 { 00544 BaseVertices[i]= new CTessBaseVertex; 00545 } 00546 } 00547 00548 00549 // compile() the patchs. 00550 //====================== 00551 for(j=0;j<(sint)Patchs.size();j++) 00552 { 00553 CPatch &pa= Patchs[j]; 00554 CPatchConnect &pc= PatchConnects[j]; 00555 CTessVertex *baseVertices[4]; 00556 00557 baseVertices[0]= &(BaseVertices[pc.BaseVertices[0]]->Vert); 00558 baseVertices[1]= &(BaseVertices[pc.BaseVertices[1]]->Vert); 00559 baseVertices[2]= &(BaseVertices[pc.BaseVertices[2]]->Vert); 00560 baseVertices[3]= &(BaseVertices[pc.BaseVertices[3]]->Vert); 00561 pa.compile(this, j, pa.OrderS, pa.OrderT, baseVertices, pc.ErrorSize); 00562 }; 00563 00564 // compile() the Clip information for the patchs. 00565 //====================== 00566 _PatchBSpheres.resize(Patchs.size()); 00567 for(j=0;j<(sint)Patchs.size();j++) 00568 { 00569 CPatch &pa= Patchs[j]; 00570 00571 // Buil the BSPhere of the patch. 00572 CAABBox bb= pa.buildBBox(); 00573 _PatchBSpheres[j].Center= bb.getCenter(); 00574 _PatchBSpheres[j].Radius= bb.getRadius(); 00575 } 00576 00577 // bind() the patchs. (after all compiled). 00578 //=================== 00579 for(j=0;j<(sint)Patchs.size();j++) 00580 { 00581 CPatch &pa= Patchs[j]; 00582 CPatchConnect &pc= PatchConnects[j]; 00583 00584 // bind the patch. This is the original bind, not a rebind. 00585 bindPatch(loadedZones, pa, pc, false); 00586 } 00587 00588 00589 // rebindBorder() on neighbor zones. 00590 //================================== 00591 ItZoneMap zoneIt; 00592 // Traverse the neighborood. 00593 for(zoneIt= neighborZones.begin(); zoneIt!=neighborZones.end(); zoneIt++) 00594 { 00595 (*zoneIt).second->rebindBorder(loadedZones); 00596 } 00597 00598 // End!! 00599 Compiled= true; 00600 } |
|
Definition at line 487 of file src/3d/zone.h. References Compiled.
00487 {return Compiled;} |
|
Definition at line 99 of file 3d/zone.cpp. References NLMISC::CAABBoxExt::getCenter(), NLMISC::CAABBoxExt::getHalfSize(), NL3D_NOISE_MAX, PatchBias, PatchScale, NLMISC::CAABBoxExt::setHalfSize(), NLMISC::CVector::x, NLMISC::CVector::y, NLMISC::CVector::z, and ZoneBB. Referenced by applyHeightField(), and build().
00100 { 00101 ZoneBB= bb; 00102 // Take a security for noise. (usefull for zone clipping). 00103 ZoneBB.setHalfSize(ZoneBB.getHalfSize()+CVector(NL3D_NOISE_MAX, NL3D_NOISE_MAX, NL3D_NOISE_MAX)); 00104 CVector hs= ZoneBB.getHalfSize(); 00105 float rmax= maxof(hs.x, hs.y, hs.z); 00106 PatchScale= rmax / 32760; // Prevent from float imprecision by taking 32760 and not 32767. 00107 PatchBias= ZoneBB.getCenter(); 00108 } |
|
Copy the tiles flags from a src patch to a patch of this zone. the patch must match of course... Definition at line 1542 of file 3d/zone.cpp. References NL3D::CPatch::copyTileFlagsFromPatch(), getPatch(), and sint. Referenced by NL3D::CZoneLighter::copyTileFlags().
|
|
Debug a zone, print binds in display. Definition at line 1420 of file 3d/zone.cpp. References NL3D::CZone::CPatchConnect::BindEdges, NL3D::CPatchInfo::CBindInfo::Edge, NL3D::CPatchInfo::CBindInfo::Next, NL3D::CPatchInfo::CBindInfo::NPatchs, PatchConnects, sint, and NL3D::CPatchInfo::CBindInfo::ZoneId.
01421 { 01422 fprintf(f, "*****************************\n"); 01423 fprintf(f, "ZoneId: %d. NPatchs:%d\n", ZoneId, PatchConnects.size()); 01424 sint i; 01425 for(i=0;i<(sint)PatchConnects.size();i++) 01426 { 01427 CPatchConnect &pc= PatchConnects[i]; 01428 fprintf(f, "patch%d:\n", i); 01429 for(sint j=0;j<4;j++) 01430 { 01431 CPatchInfo::CBindInfo &bd= pc.BindEdges[j]; 01432 fprintf(f, " edge%d: Zone:%d. NPatchs:%d. ", j, bd.ZoneId, bd.NPatchs); 01433 for(sint k=0;k<bd.NPatchs;k++) 01434 { 01435 fprintf(f, "p%de%d - ", bd.Next[k], bd.Edge[k]); 01436 } 01437 fprintf(f, "\n"); 01438 } 01439 } 01440 01441 fprintf(f,"Vertices :\n"); 01442 for(i=0;i<(sint)BorderVertices.size();i++) 01443 { 01444 fprintf(f,"current : %d -> (zone %d) vertex %d\n",BorderVertices[i].CurrentVertex, 01445 BorderVertices[i].NeighborZoneId, 01446 BorderVertices[i].NeighborVertex); 01447 } 01448 } |
|
This is especially for Pacs. exlude a patch to be refineAll()ed.
Definition at line 1119 of file 3d/zone.cpp. References Compiled, nlassert, and uint.
|
|
For changing TileMaxSubdivision. force tesselation to be under tile.
Definition at line 1259 of file 3d/zone.cpp. References NL3D::CPatch::forceMergeAtTileLevel(), and sint.
|
|
Definition at line 606 of file src/3d/zone.h. References PBaseVertex, and sint.
00606 {return BaseVertices[vert];} |
|
Get the landscape in which is placed this zone. If no landscape, return NULL.
Definition at line 461 of file src/3d/zone.h. Referenced by NL3D::CPatch::computeDisplaceRawInteger(), NL3D::CPatch::getLandscape(), and NL3D::CTextureFar::rebuildPatch().
00462 { 00463 return Landscape; 00464 } |
|
|
Definition at line 607 of file src/3d/zone.h. References nlassert, and sint.
|
|
Get a read only patch pointer.
Definition at line 499 of file src/3d/zone.h. References nlassert, and sint. Referenced by buildBindInfo(), NL3D::CZoneLighter::copyTileFlags(), and copyTilesFlags().
|
|
Definition at line 485 of file src/3d/zone.h. References PatchBias. Referenced by NL3D::CPatch::unpack().
00485 {return PatchBias;} |
|
Get the Bounding spehere of a patch. Stored in Zone as an array and not in CPatch for Fast Memory access consideration during clipping. Work only when zone compiled. Definition at line 911 of file 3d/zone.cpp. References _PatchBSpheres, and uint. Referenced by NL3D::CMiniCol::addZone(), and NL3D::CLandscape::computeDynamicLighting().
00912 { 00913 static CBSphere dummySphere; 00914 if(patch<_PatchBSpheres.size()) 00915 return _PatchBSpheres[patch]; 00916 else 00917 return dummySphere; 00918 } |
|
Get a patch colors Return the color array.
Definition at line 1347 of file 3d/zone.cpp. References getNumPatchs(), nlassert, and sint.
01348 { 01349 nlassert(numPatch>=0); 01350 nlassert(numPatch<getNumPatchs()); 01351 01352 // Update the patch texture. 01353 return Patchs[numPatch].TileColors; 01354 } |
|
Get a read only patch connect pointer.
Definition at line 507 of file src/3d/zone.h. References nlassert, PatchConnects, and sint. Referenced by buildBindInfo(), NL3D::CLandscape::checkZoneBinds(), and NL3D::CZoneCornerSmoother::computeAllCornerSmoothFlags().
00508 {nlassert(patch>=0 && patch<(sint)Patchs.size()); return &(PatchConnects[patch]);} |
|
Definition at line 486 of file src/3d/zone.h. References PatchScale. Referenced by NL3D::CPatch::unpack().
00486 {return PatchScale;} |
|
Get a patch texture. Return the tile array.
Definition at line 1336 of file 3d/zone.cpp. References getNumPatchs(), nlassert, and sint.
01337 { 01338 nlassert(numPatch>=0); 01339 nlassert(numPatch<getNumPatchs()); 01340 01341 // Update the patch texture. 01342 return Patchs[numPatch].Tiles; 01343 } |
|
Definition at line 491 of file src/3d/zone.h. References ZoneBB. Referenced by NL3D::CMiniCol::addZone(), NL3D::CLandscape::addZone(), NL3D::CZoneLighter::buildZoneInformation(), NL3D::CZoneLighter::light(), and NL3D::CLandscape::removeZone().
00491 {return ZoneBB;} |
|
Definition at line 488 of file src/3d/zone.h. References uint16. Referenced by NL3D::CLandscape::addZone(), NL3D::CZoneLighter::buildZoneInformation(), NL3D::CLandscape::checkZoneBinds(), NL3D::CZoneLighter::copyTileFlags(), NL3D::CZoneLighter::getNormal(), NL3D::CLandscapeUser::refreshZonesAround(), NL3D::CLandscape::removeZone(), and retrieve().
00488 {return ZoneId;} |
|
Definition at line 705 of file 3d/zone.cpp. References sint, and NL3D::TZoneMap.
00706 { 00707 #ifdef NL3D_DEBUG_DONT_BIND_PATCH 00708 return NULL; 00709 #endif 00710 if(loadedZones.find(zoneId)==loadedZones.end()) 00711 return NULL; 00712 else 00713 return (loadedZones[zoneId])->getPatch(patch); 00714 } |
|
Is the patch clipped (ie not visible). crash if bad Id.
Definition at line 539 of file src/3d/zone.h. References _PatchRenderClipped, NLMISC::CBitSet::get(), and uint. Referenced by NL3D::CPatch::isRenderClipped().
00539 {return _PatchRenderClipped.get(patch);} |
|
Definition at line 882 of file 3d/zone.cpp. References NL3D::CZone::CPatchConnect::BindEdges, nlassert, NL3D::CPatchInfo::CBindInfo::NPatchs, sint, and NL3D::CPatchInfo::CBindInfo::ZoneId. Referenced by rebindBorder().
00883 { 00884 // If only one of neighbor patch is not of this zone, we are on a border. 00885 00886 // Test all edges. 00887 for(sint i=0;i<4;i++) 00888 { 00889 const CPatchInfo::CBindInfo &pcBind= pc.BindEdges[i]; 00890 00891 nlassert(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); 00892 if(pcBind.NPatchs>=1) 00893 { 00894 if(pcBind.ZoneId != ZoneId) 00895 return true; 00896 } 00897 } 00898 00899 return false; 00900 } |
|
PreRender a zone (if needed).
Definition at line 1175 of file 3d/zone.cpp. References _PatchBSpheres, _PatchRenderClipped, ClipOut, ClipResult, ClipSide, Compiled, nlassert, and uint.
01176 { 01177 nlassert(Compiled); 01178 01179 // Must be 2^X-1. 01180 static const uint updateFarRefineFreq= 15; 01181 // Take the renderDate here. 01182 uint curDateMod= CLandscapeGlobals::CurrentRenderDate & updateFarRefineFreq; 01183 01184 // If no patchs, do nothing. 01185 if(Patchs.empty()) 01186 return; 01187 01188 /* If patchs invisible, must still update their Far Textures, 01189 else, there may be slowdown when we turn the head. 01190 */ 01191 01192 01193 // If all the zone is invisible. 01194 if(ClipResult==ClipOut) 01195 { 01196 // No patchs are visible, but maybe update the far textures. 01197 if( curDateMod==(ZoneId & updateFarRefineFreq) ) 01198 { 01199 // updateTextureFarOnly for all patchs. 01200 for(uint i=0;i<Patchs.size();i++) 01201 { 01202 Patchs[i].updateTextureFarOnly(_PatchBSpheres[i]); 01203 } 01204 } 01205 } 01206 // else If some patchs only are visible. 01207 else if(ClipResult==ClipSide) 01208 { 01209 // PreRender Pass, or updateTextureFarOnly(), according to _PatchRenderClipped state. 01210 for(uint i=0;i<Patchs.size();i++) 01211 { 01212 // If the patch is visible 01213 if(!_PatchRenderClipped[i]) 01214 { 01215 // Then preRender it. 01216 Patchs[i].preRender(_PatchBSpheres[i]); 01217 } 01218 else 01219 { 01220 // else maybe updateFar it. 01221 // ZoneId+i for better repartition. 01222 if( curDateMod==((ZoneId+i) & updateFarRefineFreq) ) 01223 Patchs[i].updateTextureFarOnly(_PatchBSpheres[i]); 01224 } 01225 } 01226 } 01227 else // ClipResult==ClipIn 01228 { 01229 // PreRender Pass for All 01230 for(uint i=0;i<Patchs.size();i++) 01231 { 01232 Patchs[i].preRender(_PatchBSpheres[i]); 01233 } 01234 } 01235 01236 } |
|
Force border patchs (those who don't bind to current zone) to re bind() them, using new neighborood. no-op if zone is not compiled. Definition at line 686 of file 3d/zone.cpp. References bindPatch(), PatchConnects, patchOnBorder(), sint, and NL3D::TZoneMap.
00687 { 00688 sint j; 00689 00690 // rebind patchs which are on border. 00691 for(j=0;j<(sint)Patchs.size();j++) 00692 { 00693 CPatch &pa= Patchs[j]; 00694 CPatchConnect &pc= PatchConnects[j]; 00695 00696 if(patchOnBorder(pc)) 00697 { 00698 // rebind the patch. This is a rebind. 00699 bindPatch(loadedZones, pa, pc, true); 00700 } 00701 } 00702 } |
|
force Refine a zone.
Definition at line 1132 of file 3d/zone.cpp. References Compiled, NL3D::CPatch::ExcludeFromRefineAll, nlassert, NL3D::CPatch::refineAll(), and sint.
01133 { 01134 nlassert(Compiled); 01135 01136 // Fuck stlport.... 01137 if(Patchs.size()==0) 01138 return; 01139 01140 // DO NOT do a forceNoRenderClip(), to avoid big allocation of Near/Far VB vertices in driver. 01141 // DO NOT modify ClipResult, to avoid big allocation of Near/Far VB vertices in driver. 01142 01143 // refine ALL patchs (even those which may be invisible). 01144 CPatch *pPatch= &(*Patchs.begin()); 01145 sint n; 01146 for(n=(sint)Patchs.size();n>0;n--, pPatch++) 01147 { 01148 // For Pacs construction: may exclude some patch from refineAll (for speed improvement). 01149 if(!pPatch->ExcludeFromRefineAll) 01150 pPatch->refineAll(); 01151 } 01152 01153 } |
|
refresh the geometry (re-compute vertices). Usefull for Tile Noise edition. Do it after calling changePatchTextureAndColor(). NB: a refreshTesselationGeometry() should be done on All patchs, and all direct neighbors of this patch (including patchs on corners). WARNING: specially coded for Tile edition. Result is not perfect:
Definition at line 1322 of file 3d/zone.cpp. References NL3D::CLandscape::_RenderMustRefillVB, Compiled, getNumPatchs(), nlassert, and sint.
01323 { 01324 nlassert(numPatch>=0); 01325 nlassert(numPatch<getNumPatchs()); 01326 nlassert(Compiled); 01327 01328 // At next render, we must re-fill the entire unclipped VB, so change are taken into account. 01329 Landscape->_RenderMustRefillVB= true; 01330 01331 Patchs[numPatch].refreshTesselationGeometry(); 01332 } |
|
Release a zone. This method do:
NB: no-op if not compiled. Definition at line 603 of file 3d/zone.cpp. References ClipOut, ClipResult, Compiled, NL3D::ItZoneMap, nlassert, NL3D::CPatch::release(), sint, NL3D::TZoneMap, and unbindPatch(). Referenced by NL3D::CLandscape::removeZone().
00604 { 00605 sint i,j; 00606 00607 if(!Compiled) 00608 return; 00609 00610 // detach this zone to loadedZones. 00611 //================================= 00612 nlassert(loadedZones.find(ZoneId)!=loadedZones.end()); 00613 loadedZones.erase(ZoneId); 00614 // It doesn't server to unbindPatch(), since patch is not binded to neigbors. 00615 00616 00617 // unbind() the patchs. 00618 //===================== 00619 for(j=0;j<(sint)Patchs.size();j++) 00620 { 00621 CPatch &pa= Patchs[j]; 00622 unbindPatch(pa); 00623 } 00624 00625 00626 // rebindBorder() on neighbor zones. 00627 //================================== 00628 // Build the nieghborood. 00629 TZoneMap neighborZones; 00630 for(i=0;i<(sint)BorderVertices.size();i++) 00631 { 00632 sint cur= BorderVertices[i].CurrentVertex; 00633 sint zoneto= BorderVertices[i].NeighborZoneId; 00634 nlassert(cur<NumVertices); 00635 00636 if(loadedZones.find(zoneto)!=loadedZones.end()) 00637 { 00638 CZone *zone; 00639 zone= (*loadedZones.find(zoneto)).second; 00640 nlassert(zone!=this); 00641 // insert the zone in the neigborood (if not done...). 00642 neighborZones[zoneto]= zone; 00643 } 00644 } 00645 // rebind borders. 00646 ItZoneMap zoneIt; 00647 // Traverse the neighborood. 00648 for(zoneIt= neighborZones.begin(); zoneIt!=neighborZones.end(); zoneIt++) 00649 { 00650 // Since 00651 (*zoneIt).second->rebindBorder(loadedZones); 00652 } 00653 00654 00655 // release() the patchs. 00656 //====================== 00657 // unbind() need compiled neigbor patchs, so do the release after all unbind (so after rebindBorder() too...). 00658 for(j=0;j<(sint)Patchs.size();j++) 00659 { 00660 CPatch &pa= Patchs[j]; 00661 pa.release(); 00662 } 00663 00664 00665 // destroy/unlink the base vertices (internal..), according to present neigbor zones. 00666 //================================= 00667 // Just release the smartptrs (easy!!). Do it after patchs released... 00668 BaseVertices.clear(); 00669 00670 00671 // End!! 00672 Compiled= false; 00673 Landscape= NULL; 00674 ClipResult= ClipOut; 00675 } |
|
Definition at line 1240 of file 3d/zone.cpp. References _PatchRenderClipped, NLMISC::CBitSet::set(), and uint.
01241 { 01242 for(uint i=0;i<Patchs.size();i++) 01243 { 01244 // If patch is visible 01245 if(!_PatchRenderClipped[i]) 01246 { 01247 // release VertexBuffer, and FaceBuffer 01248 Patchs[i].deleteVBAndFaceVector(); 01249 // Flag. 01250 _PatchRenderClipped.set(i, true); 01251 } 01252 01253 Patchs[i].resetRenderFar(); 01254 } 01255 } |
|
Retrieve zone patchinfo. Deprecated. Should use retrieve(CZoneInfo &) instead. see this method. Definition at line 278 of file 3d/zone.cpp. References NL3D::CZoneInfo::BorderVertices, NL3D::CZoneInfo::Patchs, and retrieve().
00279 { 00280 CZoneInfo zinfo; 00281 00282 retrieve(zinfo); 00283 00284 patchs= zinfo.Patchs; 00285 borderVertices= zinfo.BorderVertices; 00286 } |
|
Retrieve zone patchinfo. This method uncompress the patchs coordinates and all info into the patch info/borderVertices. Warning!!! Due to compression, data won't be the same as those given in build(). Same remark for TileLightInfluences, due to light sorting. Definition at line 289 of file 3d/zone.cpp. References NL3D::CZone::CPatchConnect::BaseVertices, NL3D::CPatchInfo::BaseVertices, NL3D::CZone::CPatchConnect::BindEdges, NL3D::CPatchInfo::BindEdges, NL3D::CZoneInfo::BorderVertices, NL3D::CZone::CPatchConnect::ErrorSize, NL3D::CPatchInfo::ErrorSize, NL3D::CPatch::Flags, NL3D::CPatchInfo::Flags, NL3D::CPatch::getCornerSmoothFlag(), NL3D::CPointLightNamedArray::getPointLights(), getZoneId(), NL3D::CBezierPatch::Interiors, NL3D::CPatch::Interiors, NL3D::CPatchInfo::Lumels, NL_PATCH_SMOOTH_FLAG_MASK, NL_PATCH_SMOOTH_FLAG_SHIFT, NL3D::CPatch::NoiseRotation, NL3D::CPatchInfo::NoiseRotation, NL3D::CPatchInfo::OrderS, NL3D::CPatch::OrderS, NL3D::CPatchInfo::OrderT, NL3D::CPatch::OrderT, NL3D::CPatchInfo::Patch, PatchBias, PatchConnects, NL3D::CZoneInfo::Patchs, PatchScale, NL3D::CZoneInfo::PointLights, NL3D::CPatchInfo::setCornerSmoothFlag(), sint, NL3D::CBezierPatch::Tangents, NL3D::CPatch::Tangents, NL3D::CPatch::TileColors, NL3D::CPatchInfo::TileColors, NL3D::CPatch::TileLightInfluences, NL3D::CPatchInfo::TileLightInfluences, NL3D::CPatch::Tiles, NL3D::CPatchInfo::Tiles, NL3D::CVector3s::unpack(), NL3D::CPatch::unpackShadowMap(), NL3D::CBezierPatch::Vertices, NL3D::CPatch::Vertices, and NL3D::CZoneInfo::ZoneId. Referenced by NL3D::CZoneLighter::light(), and retrieve().
00290 { 00291 sint i,j; 00292 00293 // Ref on input. 00294 std::vector<CPatchInfo> &patchs= zoneInfo.Patchs; 00295 std::vector<CBorderVertex> &borderVertices= zoneInfo.BorderVertices; 00296 // Copy zoneId. 00297 zoneInfo.ZoneId= getZoneId(); 00298 00299 00300 // uncompress Patchs. 00301 //========================= 00302 patchs.resize(Patchs.size()); 00303 for(j=0;j<(sint)patchs.size();j++) 00304 { 00305 CPatchInfo &pi= patchs[j]; 00306 CBezierPatch &p= pi.Patch; 00307 CPatch &pa= Patchs[j]; 00308 CPatchConnect &pc= PatchConnects[j]; 00309 00310 00311 // Smoothing flags 00312 pi.Flags= (pa.Flags&NL_PATCH_SMOOTH_FLAG_MASK)>>NL_PATCH_SMOOTH_FLAG_SHIFT; 00313 00314 00315 // Noise Data 00316 // copy noise rotation. 00317 pi.NoiseRotation= pa.NoiseRotation; 00318 // copy all noise smoothing info. 00319 for(i=0;i<4;i++) 00320 { 00321 pi.setCornerSmoothFlag(i, pa.getCornerSmoothFlag(i)); 00322 } 00323 00324 00325 // re-Build the uncompressed bezier patch. 00326 for(i=0;i<4;i++) 00327 pa.Vertices[i].unpack(p.Vertices[i], PatchBias, PatchScale); 00328 for(i=0;i<8;i++) 00329 pa.Tangents[i].unpack(p.Tangents[i], PatchBias, PatchScale); 00330 for(i=0;i<4;i++) 00331 pa.Interiors[i].unpack(p.Interiors[i], PatchBias, PatchScale); 00332 pi.Tiles= pa.Tiles; 00333 pi.TileColors= pa.TileColors; 00334 pi.TileLightInfluences= pa.TileLightInfluences; 00335 pi.Lumels.resize ((pa.OrderS*4)*(pa.OrderT*4)); 00336 pi.Flags=(pa.Flags&NL_PATCH_SMOOTH_FLAG_MASK)>>NL_PATCH_SMOOTH_FLAG_SHIFT; 00337 00338 // Unpack the lumel map 00339 pa.unpackShadowMap (&pi.Lumels[0]); 00340 00341 // from the patchConnect. 00342 pi.OrderS= pa.OrderS; 00343 pi.OrderT= pa.OrderT; 00344 pi.ErrorSize= pc.ErrorSize; 00345 for(i=0;i<4;i++) 00346 { 00347 pi.BaseVertices[i]= pc.BaseVertices[i]; 00348 } 00349 for(i=0;i<4;i++) 00350 pi.BindEdges[i]= pc.BindEdges[i]; 00351 } 00352 00353 // retrieve bordervertices. 00354 //========================= 00355 borderVertices= BorderVertices; 00356 00357 // retrieve PointLights. 00358 //========================= 00359 zoneInfo.PointLights= _PointLightArray.getPointLights(); 00360 00361 } |
|
Load/save a zone. Save work even if zone is not compiled, but load must be done on a not compiled zone... Definition at line 432 of file 3d/zone.cpp. References _PatchOldRenderClipped, _PatchRenderClipped, NLMISC::IStream::isReading(), PatchBias, PatchConnects, PatchScale, NLMISC::CBitSet::resize(), NLMISC::IStream::serial(), NLMISC::IStream::serialCheck(), NLMISC::IStream::serialCont(), NLMISC::IStream::serialVersion(), NLMISC::CBitSet::setAll(), uint, uint32, NLMISC::IStream::xmlPop(), NLMISC::IStream::xmlPush(), NLMISC::IStream::xmlSerial(), and ZoneBB. Referenced by NL3D::CZoneLoadingTask::run().
00433 { 00434 /* 00435 Version 4: 00436 - PointLights 00437 Version 3: 00438 - Lumels compression version 2. 00439 Version 2: 00440 - Lumels. 00441 Version 1: 00442 - Tile color. 00443 Version 0: 00444 - base verison. 00445 */ 00446 uint ver= f.serialVersion(4); 00447 00448 // No more compatibility before version 3 00449 if (ver<3) 00450 { 00451 throw EOlderStream(f); 00452 } 00453 00454 f.serialCheck((uint32)'ENOZ'); 00455 00456 f.xmlSerial (ZoneId, "ZONE_ID"); 00457 f.xmlSerial (ZoneBB, "BB"); 00458 f.xmlSerial (PatchBias, "PATCH_BIAS"); 00459 f.xmlSerial (PatchScale, "PATCH_SCALE"); 00460 f.xmlSerial (NumVertices, "NUM_VERTICES"); 00461 00462 f.xmlPush ("BORDER_VERTICES"); 00463 f.serialCont(BorderVertices); 00464 f.xmlPop (); 00465 00466 f.xmlPush ("PATCHES"); 00467 f.serialCont(Patchs); 00468 f.xmlPop (); 00469 00470 f.xmlPush ("PATCH_CONNECTS"); 00471 f.serialCont(PatchConnects); 00472 f.xmlPop (); 00473 00474 if (ver>=4) 00475 { 00476 f.xmlPush ("POINT_LIGHTS"); 00477 f.serial(_PointLightArray); 00478 f.xmlPop (); 00479 } 00480 00481 // If read, must create and init Patch Clipped state to true (clipped even if not compiled) 00482 if(f.isReading()) 00483 { 00484 _PatchRenderClipped.resize(Patchs.size()); 00485 _PatchOldRenderClipped.resize(Patchs.size()); 00486 _PatchRenderClipped.setAll(); 00487 _PatchOldRenderClipped.setAll(); 00488 } 00489 00490 // If read and version 0, must init default TileColors of patchs. 00491 //=============================================================== 00492 // if(f.isReading() && ver<2) ... 00493 // Deprecated, because ver<3 not supported 00494 } |
|
Set the zone tile color to monochrome or not and apply multiplier factor Set all tile colors of all patch of this zone to monochrome or not and apply a multiplier factor convertion to monochrome is done by that formula : newR = newG = newB = 0.28 * R + 0.59 * G + 0.13 * B; for monochrome the factor is applied like for the color mode Definition at line 1357 of file 3d/zone.cpp. References nlassert, uint16, and uint32. Referenced by NL3D::CZoneLoadingTask::run().
01358 { 01359 nlassert(factor >= 0.0f); // factor must not be negative as its a multiplier 01360 01361 if (monochrome) 01362 { 01363 for (uint32 i = 0; i < Patchs.size(); ++i) 01364 { 01365 vector<CTileColor> &rTC = Patchs[i].TileColors; 01366 for (uint32 j = 0; j < rTC.size(); ++j) 01367 { 01368 float fR = (rTC[j].Color565 & 31) / 32.0f; 01369 float fG = ((rTC[j].Color565 >> 5) & 63) / 64.0f; 01370 float fB = ((rTC[j].Color565 >> 11) & 31) / 32.0f; 01371 01372 fR = 0.28f * fR + 0.59f * fG + 0.13f * fB; 01373 01374 nlassert(fR < 0.99f); 01375 01376 fR *= factor; 01377 if (fR > 0.99f) fR = 0.99f; // Avoid reaching 1 01378 01379 uint16 nR = (uint16)(fR * 32.0f); 01380 uint16 nG = (uint16)(fR * 64.0f); 01381 uint16 nB = (uint16)(fR * 32.0f); 01382 01383 rTC[j].Color565 = nR + (nG << 5) + (nB << 11); 01384 } 01385 } 01386 } 01387 else 01388 { 01389 if (factor != 1.0f) 01390 { 01391 for (uint32 i = 0; i < Patchs.size(); ++i) 01392 { 01393 vector<CTileColor> &rTC = Patchs[i].TileColors; 01394 for (uint32 j = 0; j < rTC.size(); ++j) 01395 { 01396 float fR = (rTC[j].Color565 & 31) / 32.0f; 01397 float fG = ((rTC[j].Color565 >> 5) & 63) / 64.0f; 01398 float fB = ((rTC[j].Color565 >> 11) & 31) / 32.0f; 01399 01400 fR *= factor; 01401 fG *= factor; 01402 fB *= factor; 01403 01404 if (fR > 0.99f) fR = 0.99f; 01405 if (fG > 0.99f) fG = 0.99f; 01406 if (fB > 0.99f) fB = 0.99f; 01407 01408 uint16 nR = (uint16)(fR * 32.0f); 01409 uint16 nG = (uint16)(fG * 64.0f); 01410 uint16 nB = (uint16)(fB * 32.0f); 01411 01412 rTC[j].Color565 = nR + (nG << 5) + (nB << 11); 01413 } 01414 } 01415 } 01416 } 01417 } |
|
Debug purpose only : setup the colors of the patch of this zone so that it shows which tiles have vegetable disabled, or are above, below water. User provides a table with 4 colors for each state : color 0 = above water color 1 = underwater color 2 = intersect water color 3 = vegetable disabled Definition at line 1532 of file 3d/zone.cpp. References uint.
|
|
Definition at line 868 of file 3d/zone.cpp. References NL3D::CPatch::unbind(). Referenced by release().
00869 { 00870 /* 00871 Remind: the old version with CPatch::unbindFrom*() doesn't work because of CZone::release(). This function 00872 first erase the zone from loadedZones... 00873 Not matter here. We use CPatch::unbind() which should do all the good job correctly (unbind pa from ohters 00874 , and unbind others from pa at same time). 00875 */ 00876 00877 pa.unbind(); 00878 } |
|
Definition at line 590 of file src/3d/zone.h. |
|
Definition at line 593 of file src/3d/zone.h. |
|
Definition at line 591 of file src/3d/zone.h. |
|
Definition at line 579 of file src/3d/zone.h. Referenced by clipPatchs(), compile(), getPatchBSphere(), and preRender(). |
|
Definition at line 581 of file src/3d/zone.h. Referenced by build(), clip(), NL3D::CPatch::release(), and serial(). |
|
Definition at line 580 of file src/3d/zone.h. Referenced by build(), changePatchTextureAndColor(), clip(), clipPatchs(), isPatchRenderClipped(), preRender(), NL3D::CPatch::release(), resetRenderFarAndDeleteVBFV(), and serial(). |
|
List of PointLights that may influences Patchs and objects walking on them. Definition at line 586 of file src/3d/zone.h. Referenced by NL3D::CLandscape::addZone(), NL3D::CPatch::appendTileLightInfluences(), build(), and NL3D::CPatch::getCurrentTileTLIColors(). |
|
Definition at line 570 of file src/3d/zone.h. |
|
Definition at line 572 of file src/3d/zone.h. Referenced by build(). |
|
Definition at line 595 of file src/3d/zone.h. Referenced by clip(), CZone(), preRender(), and release(). |
|
Definition at line 562 of file src/3d/zone.h. Referenced by averageTesselationVertices(), build(), changePatchTextureAndColor(), clip(), compile(), compiled(), CZone(), excludePatchFromRefineAll(), preRender(), refineAll(), refreshTesselationGeometry(), release(), and ~CZone(). |
|
|
Definition at line 568 of file src/3d/zone.h. Referenced by build(). |
|
Definition at line 564 of file src/3d/zone.h. Referenced by applyHeightField(), build(), computeBBScaleBias(), getPatchBias(), retrieve(), and serial(). |
|
Definition at line 577 of file src/3d/zone.h. Referenced by build(), buildBindInfo(), compile(), debugBinds(), getPatchConnect(), rebindBorder(), retrieve(), and serial(). |
|
Definition at line 576 of file src/3d/zone.h. Referenced by build(). |
|
Definition at line 565 of file src/3d/zone.h. Referenced by applyHeightField(), build(), computeBBScaleBias(), getPatchScale(), retrieve(), and serial(). |
|
Definition at line 563 of file src/3d/zone.h. Referenced by build(), clip(), computeBBScaleBias(), getZoneBB(), and serial(). |
|
Definition at line 561 of file src/3d/zone.h. Referenced by build(). |