1
/***************************************************************************
2
OgrePagingLandScapeSceneManager.cpp - description
4
begin : Mon May 12 2003
5
copyright : (C) 2003-2006 by Jose A Milan && Tuan Kuranes
6
email : spoke2@supercable.es && tuan.kuranes@free.fr
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU Lesser General Public License as *
13
* published by the Free Software Foundation; either version 2 of the *
14
* License, or (at your option) any later version. *
16
***************************************************************************/
18
#include "OgrePagingLandScapePrecompiledHeaders.h"
23
#include "OgreSceneManager.h"
24
#include "OgreVector2.h"
25
#include "OgreVector3.h"
26
#include "OgreColourValue.h"
27
#include "OgreMovableObject.h"
28
#include "OgreAxisAlignedBox.h"
29
#include "OgreCamera.h"
30
#include "OgreStringConverter.h"
31
#include "OgreSceneNode.h"
32
#include "OgreSimpleRenderable.h"
34
#include "OgrePagingLandScapeOptions.h"
35
#include "OgrePagingLandScapeCamera.h"
36
#include "OgrePagingLandScapeData2DManager.h"
37
#include "OgrePagingLandScapeRenderableManager.h"
38
#include "OgrePagingLandScapeTextureCoordMan.h"
39
#include "OgrePagingLandScapeRenderable.h"
40
#include "OgrePagingLandScapeTextureManager.h"
41
#include "OgrePagingLandScapeTexture.h"
42
#include "OgrePagingLandScapePageManager.h"
43
#include "OgrePagingLandScapeTile.h"
44
#include "OgrePagingLandScapeTileInfo.h"
45
#include "OgrePagingLandScapeTileManager.h"
46
#include "OgrePagingLandScapeRenderable.h"
47
#include "OgrePagingLandScapeRenderableManager.h"
48
#include "OgrePagingLandScapeAABSQ.h"
49
#include "OgrePagingLandScapeRaySceneQuery.h"
50
#include "OgrePagingLandScapeCamera.h"
51
#include "OgrePagingLandScapeMeshDecal.h"
53
#include "OgrePagingLandScapeListenerManager.h"
55
#include "OgrePagingLandScapeSceneManager.h"
57
#include "OgrePagingLandScapeHorizon.h"
62
//-----------------------------------------------------------------------
63
const String PagingLandScapeSceneManagerFactory::FACTORY_TYPE_NAME = "PagingLandScapeSceneManager";
64
//-----------------------------------------------------------------------
65
void PagingLandScapeSceneManagerFactory::initMetaData(void) const
67
mMetaData.typeName = FACTORY_TYPE_NAME;
68
mMetaData.description = "Scene manager organising the scene on the basis of an octree, and paging heightmap when needed.";
69
mMetaData.sceneTypeMask = ST_EXTERIOR_REAL_FAR; // support all types
70
mMetaData.worldGeometrySupported = true;
72
//-----------------------------------------------------------------------
73
SceneManager* PagingLandScapeSceneManagerFactory::createInstance(
74
const String& instanceName)
76
return new PagingLandScapeSceneManager(instanceName);
78
//-----------------------------------------------------------------------
79
void PagingLandScapeSceneManagerFactory::destroyInstance(SceneManager* instance)
83
//-----------------------------------------------------------------------
84
PagingLandScapeSceneManager::PagingLandScapeSceneManager(const String& name) :
85
PagingLandScapeOctreeSceneManager(name),
89
mRenderableManager (0),
94
mNeedOptionsUpdate (false),
96
mWorldGeomIsSetup (false),
98
mWorldGeomIsInit (false),
102
mBrushCenter (Vector3::ZERO),
103
mBrushArray (0), mCraterArray(0),
104
mBrushArrayHeight (0),
105
mBrushArrayWidth (0),
108
textureFormatChanged (false)
110
//showBoundingBoxes(true);
111
//setDisplaySceneNodes(true);
113
mMeshDecalFactory = new PagingLandScapeMeshDecalFactory;
114
if( !(Root::getSingleton().hasMovableObjectFactory("PagingLandScapeMeshDecal")) )
115
Root::getSingleton().addMovableObjectFactory( mMeshDecalFactory );
117
//-------------------------------------------------------------------------
118
const String& PagingLandScapeSceneManager::getTypeName(void) const
120
return PagingLandScapeSceneManagerFactory::FACTORY_TYPE_NAME;
122
//-----------------------------------------------------------------------
123
void PagingLandScapeSceneManager::PagingLandScapeOctreeResize()
125
const Ogre::Real x = mOptions->maxScaledX;
126
assert (mData2DManager);
127
const Ogre::Real y = mData2DManager->getMaxHeight () * 4;
128
const Ogre::Real z = mOptions->maxScaledZ;
129
PagingLandScapeOctreeSceneManager::resize(AxisAlignedBox(-x , 0, -z, x, y, z));
131
//-----------------------------------------------------------------------
132
void PagingLandScapeSceneManager::WorldDimensionChange()
134
PagingLandScapeOctreeResize();
136
assert (mPageManager);
137
assert (mData2DManager);
138
assert (mTextureManager);
139
mPageManager->WorldDimensionChange();
140
mData2DManager->WorldDimensionChange();
141
mTextureManager->WorldDimensionChange();
143
//-------------------------------------------------------------------------
144
void PagingLandScapeSceneManager::shutdown(void)
151
delete mData2DManager;
153
delete mTextureManager;
157
Root::getSingleton().removeFrameListener (mPageManager);
161
delete mListenerManager;
162
mListenerManager = 0;
165
delete mRenderableManager;
166
mRenderableManager = 0;
168
delete mIndexesManager;
170
delete mTexCoordManager;
171
mTexCoordManager = 0;
173
delete[] mCraterArray;
176
Root::getSingleton().removeMovableObjectFactory( mMeshDecalFactory );
177
delete mMeshDecalFactory;
179
//-----------------------------------------------------------------------
180
PagingLandScapeSceneManager::~PagingLandScapeSceneManager()
184
//-------------------------------------------------------------------------
185
void PagingLandScapeSceneManager::setWorldGeometry(DataStreamPtr& stream, const String& typeName)
187
if (!mListenerManager)
188
mListenerManager = new PagingLandScapeListenerManager(this);
189
// Clear out any existing world resources (if not default)
190
if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() !=
191
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
193
ResourceGroupManager::getSingleton().clearResourceGroup(
194
ResourceGroupManager::getSingleton().getWorldResourceGroupName());
197
if (mWorldGeomIsSetup)
200
mOptions = new PagingLandScapeOptions(this);
202
// Load the configuration file
203
if (!stream.isNull ())
205
if (mOptions->load(stream))
208
// Check if we need to set the camera
209
if (!mOptions->primaryCamera && !mCameras.empty ())
211
PagingLandScapeCamera* c = static_cast <PagingLandScapeCamera*> (mCameras.begin()->second);
212
mOptions->setPrimaryCamera (c);
215
//-----------------------------------------------------------------------
216
void PagingLandScapeSceneManager::setWorldGeometry(const String& filename)
218
if (filename.empty())
221
DataStreamPtr myStream;
223
DataStreamPtr myStream (0);
226
setWorldGeometry (myStream);
230
// try to open in the current folder first
232
fs.open(filename.c_str(), std::ios::in | std::ios::binary);
236
DataStreamPtr myStream (OGRE_NEW FileStreamDataStream (filename, &fs, false));
237
setWorldGeometry (myStream);
241
// otherwise try resource system
242
DataStreamPtr myStream (ResourceGroupManager::getSingleton().openResource(filename));
243
setWorldGeometry (myStream);
245
//-----------------------------------------------------------------------
246
void PagingLandScapeSceneManager::InitScene ()
248
// Only initialized once
249
// not to loose use listeners
250
if (!mListenerManager)
251
mListenerManager = new PagingLandScapeListenerManager(this);
253
mTileManager = new PagingLandScapeTileManager(this);
255
mData2DManager = new PagingLandScapeData2DManager(this, mOptions); //
256
if (!mTextureManager)
257
mTextureManager = new PagingLandScapeTextureManager(this);
258
if (!mIndexesManager)
259
mIndexesManager = new PagingLandScapeIndexBufferManager(this);
260
if (!mTexCoordManager)
261
mTexCoordManager = new PagingLandScapeTextureCoordinatesManager(this);
262
if (!mRenderableManager)
263
mRenderableManager = new PagingLandScapeRenderableManager(this);
268
mPageManager = new PagingLandScapePageManager(this);
269
Root::getSingleton().addFrameListener(mPageManager);
271
mPageManager->setWorldGeometryRenderQueue (static_cast<Ogre::RenderQueueGroupID>(SceneManager::getWorldGeometryRenderQueue()));
272
mData2DManager->setPageManager(this);
275
//-----------------------------------------------------------------------
276
void PagingLandScapeSceneManager::loadScene()
278
if (!mWorldGeomIsSetup)
280
// listen to frames to update queues independently of cam numbers.
281
// cannot do that if remove is called in same frame before it removes it
283
//Root::getSingleton().addFrameListener(mPageManager);
284
mPageManager->setEnabled (true);
286
mTileManager->load();
287
mData2DManager->load();
288
mTextureManager->load();
289
mIndexesManager->load();
290
mTexCoordManager->load();
291
if (mOptions->VisMap)
294
mHorizon = new PagingLandScapeHorizon(mOptions);
296
mPageManager->load();
297
mRenderableManager->load();
299
// reset camera paging
300
// register existing camera in node
301
CameraList::iterator i = mCameras.begin();
302
for (; i != mCameras.end(); ++i)
304
// Notify occlusion system
305
PagingLandScapeCamera *c = static_cast <PagingLandScapeCamera *> (i->second);
309
PagingLandScapeOctreeResize();
313
mWorldGeomIsSetup = true;
318
//-----------------------------------------------------------------------
319
void PagingLandScapeSceneManager::clearScene(void)
321
//SceneManager::getRenderQueue()->clear();
322
PagingLandScapeSceneManager::resetScene();
324
PagingLandScapeOctreeSceneManager::clearScene();
326
//-----------------------------------------------------------------------
327
void PagingLandScapeSceneManager::resetScene(void)
329
if (mWorldGeomIsSetup)
331
//Root::getSingleton().removeFrameListener (mPageManager);
332
mPageManager->setEnabled (false);
333
// clear the Managers
334
mPageManager->clear();
335
mTextureManager->clear();
336
mData2DManager->clear();
343
mRenderableManager->clear();
344
mTileManager->clear();
346
// unload cached map info
347
mOptions->clearTileInfo();
349
// clear hardware buffer caches
350
//mIndexesManager->clear(); //don't clear to keep index buffer if tilesize
351
//mTexCoordManager->clear(); //don't clear to keep index buffer if tilesize
353
mWorldGeomIsSetup = false;
354
mWorldGeomIsInit = false;
356
//PagingLandScapeOctreeSceneManager::clearScene();
359
//-----------------------------------------------------------------------
360
void PagingLandScapeSceneManager::_updateSceneGraph(Camera * cam)
362
// entry into here could come before setWorldGeometry
363
// got called which could be disastrous
365
assert(mPageManager);
366
if (cam == mOptions->primaryCamera && isRenderQueueToBeProcessed(mPageManager->getPageRenderQueue()))
368
if (mWorldGeomIsInit)
370
mPageManager->updatePaging (static_cast<PagingLandScapeCamera *> (cam));
374
if (mWorldGeomIsSetup)
376
mOptions->calculateCFactor ();
377
assert (mPageManager);
378
if (mOptions->BigImage)
380
assert (mTextureManager);
382
mTextureManager->setMapMaterial();
383
mPageManager->setMapMaterial();
385
mWorldGeomIsInit = true;
386
mPageManager->updatePaging (static_cast<PagingLandScapeCamera *> (cam));
391
PagingLandScapeOctreeSceneManager::_updateSceneGraph(cam);
394
AxisAlignedBoxSceneQuery* PagingLandScapeSceneManager::createAABBQuery( const AxisAlignedBox& box,
397
PagingLandScapeAxisAlignedBoxSceneQuery* q = new PagingLandScapeAxisAlignedBoxSceneQuery(this);
399
q->setQueryMask(mask);
403
//----------------------------------------------------------------------------
404
RaySceneQuery* PagingLandScapeSceneManager::createRayQuery(const Ray& ray, unsigned long mask)
406
PagingLandScapeRaySceneQuery* q = new PagingLandScapeRaySceneQuery(this);
408
q->setQueryMask(mask);
411
//-------------------------------------------------------------------------
412
bool PagingLandScapeSceneManager::intersectSegment(const Ogre::Vector3 & raybegin,
413
const Ogre::Vector3 & rayend,
414
Ogre::Vector3 * rayresult)
416
return intersectSegmentTerrain (raybegin, rayend, rayresult);
418
//-------------------------------------------------------------------------
419
bool PagingLandScapeSceneManager::intersectSegmentTerrain (const Ogre::Vector3 & raybegin,
420
const Ogre::Vector3 & raydir,
421
Ogre::Vector3 * rayresult)
423
Ogre::Vector3 raystart (raybegin);
424
assert (mPageManager && mData2DManager);
426
const Ogre::Real maxHeight = mData2DManager->getMaxHeight ();
428
if (raystart.y > maxHeight)
430
// find an new ray start that is under highest terrain height
431
// so that we do not test intersection between terrain and ray
432
// on ray part where Y > maxHeight
434
// First check if not parallel to terrain
435
if (Math::Abs(raydir.y) < std::numeric_limits<Real>::epsilon())
438
*rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
441
// now ray should begin at a pertinent place.
442
const Ogre::Real t = -(raystart.y-maxHeight)/raydir.y;
443
raystart += raydir*t;
444
if (raystart.y <= mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
446
*rayresult = raystart;
451
PagingLandScapeTile * t = mPageManager->getTile (raystart.x, raystart.z, false);
454
// we're outside LandScape
455
#ifndef _STRICT_LandScape
456
// if you want to be able to intersect from a point outside the canvas
457
//const int pageSize = mOptions->PageSize - 1;
458
const Ogre::Real W = mOptions->maxScaledX;
459
const Ogre::Real H = mOptions->maxScaledZ;
460
const Ogre::Real maxHeight = mData2DManager->getMaxHeight ();
462
if (W != 0 && H != 0) {
463
// while ray is outside but raydir going inside
464
while ((raystart.y < 0.0f && raydir.y > 0.0f) ||
465
(raystart.y > maxHeight && raydir.y < 0.0f) ||
467
(raystart.x < -W && raydir.x > 0.0f) ||
468
(raystart.x > W && raydir.x < 0.0f) ||
470
(raystart.z < -H && raydir.z > 0.0f) ||
471
(raystart.z > H && raydir.z < 0.0f))
475
if (raystart.y < 0.0f || raystart.y >= maxHeight ||
476
raystart.x < -W || raystart.x > W ||
477
raystart.z < -H || raystart.z > H)
479
*rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
482
t = mPageManager->getTile (raystart.x, raystart.z, false);
485
#else //_STRICT_LandScape
486
// if you don't want to be able to intersect from a point outside the canvas
487
*rayresult = Ogre::Vector3(-1.0f, -1.0f, -1.0f);
489
#endif //_STRICT_LandScape
496
// if (raydir.x == 0.0f && raydir.z == 0.0f)
498
// if (raystart.y <= mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
500
// *rayresult = raystart;
508
// const Ogre::Vector3 rayDirScaled (
509
// raydir.x * mOptions->scale.x,
510
// raydir.y * mOptions->scale.y,
511
// raydir.z * mOptions->scale.z);
513
if (raystart.y >= mData2DManager->getInterpolatedWorldHeight(raystart.x, raystart.z))
515
impact = t->intersectSegmentFromAbove(raystart, raydir, rayresult);
519
impact = t->intersectSegmentFromBelow(raystart, raydir, rayresult);
525
//-------------------------------------------------------------------------
526
void PagingLandScapeSceneManager::resizeCrater ()
528
const int radius = mBrushSize;
529
const unsigned int diameter = static_cast <unsigned int> (radius) * 2;
531
mBrushArrayHeight = diameter;
532
mBrushArrayWidth = diameter;
534
delete [] mCraterArray;
535
const unsigned int array_size = diameter * diameter;
536
mCraterArray = new Real[array_size];
537
memset (mCraterArray, 0, array_size * sizeof(Real));
539
// Calculate the minimum X value
540
// make sure it is still on the height map
541
const int Zmin = -radius;
542
const int Zmax = radius;
544
const int Xmin = -radius;
545
const int Xmax = radius;
547
// (goes through each X value)
548
unsigned int array_indx = 0;
549
const int radiussquare = radius * radius;
550
//const Ogre::Real scaler = mOptions->scale.y;// / radius;
551
const Ogre::Real scaler = 1.0 / radius;
552
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
554
const Ogre::Real Precalc = radiussquare - (Zcurr * Zcurr);
557
// Determine the minimum and maximum X value for that
558
// line in the circle (that Z value)
559
//const int Xmax = static_cast<int> (Math::Sqrt(Precalc));
560
//const int Xmin = - Xmax;
562
unsigned int curr_indx = array_indx;// + Xmin + radius;
563
// For each of those Z values, calculate the new Y value
564
for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
566
assert (curr_indx < array_size);
567
// Calculate the new theoretical height for the current point on the circle
568
const Ogre::Real val = static_cast <Real> (Xcurr * Xcurr);
569
const Ogre::Real diffPrecalc = Precalc - val;
570
mCraterArray[curr_indx] = std::min(static_cast <Real> (1.0),
571
std::max(static_cast <Real> (0.0),
572
Math::Sqrt (diffPrecalc)* scaler)) ;
574
} // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
575
} // if (Precalc > 1.0f)
576
array_indx += diameter;
577
//array_indx += diameter;
578
} // for (int Zcurr = Zmin; Zcurr < radius; Zcurr++)
579
mBrushArray = mCraterArray;
581
//-----------------------------------------------------------------------
582
void PagingLandScapeSceneManager::paint (const Ogre::Vector3 &impact)
584
if (mOptions->textureModifiable)
586
const int X = static_cast<int> (impact.x / mOptions->scale.x);
587
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
589
//const int pageSize = mOptions->PageSize - 1;
591
const int W = static_cast<int> (mOptions->maxUnScaledX);
592
const int H = static_cast<int> (mOptions->maxUnScaledZ);
594
if (X < -W || X > W || Z < -H || Z > H)
597
const int brushW = static_cast<int> (mBrushArrayWidth);
598
// Calculate the minimum X value
599
// make sure it is still on the height map
600
unsigned int xshift = 0;
601
int Xmin = static_cast<int> (-brushW * 0.5f) ;
604
//assert (Xmin + X + W > 0);
605
xshift = static_cast <unsigned int> (abs (Xmin + X + W));
608
// Calculate the maximum X value
609
// make sure it is still on the height map
610
int Xmax = static_cast<int> (brushW * 0.5f) ;
613
const int brushH = static_cast<int> (mBrushArrayHeight);
614
// Calculate the minimum Z value
615
// make sure it is still on the height map
616
unsigned int zshift = 0;
617
int Zmin = - static_cast<int> (brushH * 0.5) ;
620
//assert (Zmin + Z + H > 0);
621
zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
624
// Calculate the maximum Z value
625
// make sure it is still on the height map
626
int Zmax = static_cast<int> (brushH * 0.5);
630
// Main loop to draw the circle on the height map
631
// (goes through each X value)
632
unsigned int array_indx = zshift*brushW;
633
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
635
// For each of those Z values, calculate the new Y value
636
unsigned int curr_indx = array_indx + xshift;
637
for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
639
// get results by page index ?
640
const Ogre::Real h = mBrushArray[curr_indx];
641
// Make sure we do it for something.
644
assert (h >= 0.0f && h <= 1.0f);
645
const Ogre::Real bushForce = std::min(static_cast <Real> (1.0), h*mBrushScale);
646
if (bushForce - 0.005f > 0)
648
const Ogre::Vector3 currpoint (X + Xcurr, static_cast <Real> (0.0), Z + Zcurr);
649
assert (mPageManager&& mData2DManager && mTextureManager);
650
PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);
651
if (t && t->isLoaded ())
653
mImpactInfo = t->getInfo ();
654
// check page boundaries to modify any page, tile neighbour
655
// tells any tile modified to update at next frame
656
assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);
657
mTextureManager->paint (currpoint, bushForce, mImpactInfo);
658
}// if (t && t->isLoaded ())
662
} // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
663
array_indx += brushW;
664
} // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
666
}//-----------------------------------------------------------------------
667
void PagingLandScapeSceneManager::setHeight (const Ogre::Vector3 &impact)
669
if (mOptions->Deformable)
671
const int X = static_cast<int> (impact.x / mOptions->scale.x);
672
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
674
//const int pageSize = mOptions->PageSize - 1;
676
const int W = static_cast<int> (mOptions->maxUnScaledX);
677
const int H = static_cast<int> (mOptions->maxUnScaledZ);
679
if (X < -W || X > W || Z < -H || Z > H)
682
const int brushW = static_cast<int> (mBrushArrayWidth);
683
// Calculate the minimum X value
684
// make sure it is still on the height map
685
unsigned int xshift = 0;
686
int Xmin = static_cast<int> (-brushW * 0.5f);
689
//assert (Xmin + X + W > 0);
690
xshift = static_cast <unsigned int> (abs (Xmin + X + W));
693
// Calculate the maximum X value
694
// make sure it is still on the height map
695
int Xmax = static_cast<int> (brushW * 0.5f) ;
698
const int brushH = static_cast<int> (mBrushArrayHeight);
699
// Calculate the minimum Z value
700
// make sure it is still on the height map
701
unsigned int zshift = 0;
702
int Zmin = static_cast<int> (- brushH * 0.5f) ;
705
//assert (Zmin + Z + H > 0);
706
zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
709
// Calculate the maximum Z value
710
// make sure it is still on the height map
711
int Zmax = static_cast<int> (brushH * 0.5f) ;
715
const Ogre::Real Hscale = mOptions->scale.y * mBrushScale;
716
// Main loop to draw the circle on the height map
717
// (goes through each X value)
718
unsigned int array_indx = zshift*brushW;
719
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
721
// For each of those Z values, calculate the new Y value
722
unsigned int curr_indx = array_indx + xshift;
723
for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
725
// get results by page index ?
726
const Ogre::Real h = - mBrushArray[curr_indx] * mBrushScale * Hscale;
727
// Make sure we do it for something.
730
const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
731
assert (mPageManager&& mData2DManager && mTextureManager);
732
PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);
733
if (t && t->isLoaded ())
735
mImpactInfo = t->getInfo ();
736
// check page boundaries to modify any page, tile neighbour
737
// tells any tile modified to update at next frame
738
assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);
739
if (mData2DManager->setHeight (currpoint, h, mImpactInfo))
740
mTextureManager->deformHeight (currpoint, mImpactInfo);
741
} // if (t && t->isLoaded ())
744
} // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
745
array_indx += brushW;
746
} // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
747
} // if (mOptions->Deformable)
749
//-----------------------------------------------------------------------
750
void PagingLandScapeSceneManager::deformHeight (const Ogre::Vector3 &impact)
752
if (mOptions->Deformable)
754
const int X = static_cast<int> (impact.x / mOptions->scale.x);
755
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
757
//const int pageSize = mOptions->PageSize - 1;
759
const int W = static_cast<int> (mOptions->maxUnScaledX);
760
const int H = static_cast<int> (mOptions->maxUnScaledZ);
762
if (X < -W || X > W || Z < -H || Z > H)
765
const int brushW = static_cast<int> (mBrushArrayWidth);
766
// Calculate the minimum X value
767
// make sure it is still on the height map
768
unsigned int xshift = 0;
769
int Xmin = static_cast<int> (-brushW * 0.5f);
772
//assert (Xmin + X + W > 0);
773
xshift = static_cast <unsigned int> (abs (Xmin + X + W));
776
// Calculate the maximum X value
777
// make sure it is still on the height map
778
int Xmax = static_cast<int> (brushW * 0.5f) ;
781
const int brushH = static_cast<int> (mBrushArrayHeight);
782
// Calculate the minimum Z value
783
// make sure it is still on the height map
784
unsigned int zshift = 0;
785
int Zmin = static_cast<int> (- brushH * 0.5f) ;
788
//assert (Zmin + Z + H > 0);
789
zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
792
// Calculate the maximum Z value
793
// make sure it is still on the height map
794
int Zmax = static_cast<int> (brushH * 0.5f) ;
798
const Ogre::Real Hscale = mOptions->scale.y * mBrushScale;
800
// Main loop to draw the circle on the height map
801
// (goes through each X value)
802
unsigned int array_indx = zshift*brushW;
803
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
805
// For each of those Z values, calculate the new Y value
806
unsigned int curr_indx = array_indx + xshift;
807
for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
809
// get results by page index ?
810
const Ogre::Real h = - mBrushArray[curr_indx] * Hscale;
811
// Make sure we do it for something.
814
const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
815
assert (mPageManager&& mData2DManager && mTextureManager);
816
PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);
817
if (t && t->isLoaded ())
819
mImpactInfo = t->getInfo ();
820
// check page boundaries to modify any page, tile neighbour
821
// tells any tile modified to update at next frame
822
assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);
823
if (mData2DManager->deformHeight (currpoint, h, mImpactInfo))
824
mTextureManager->deformHeight (currpoint, mImpactInfo);
825
} // if (t && t->isLoaded ())
828
} // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
829
array_indx += brushW;
830
} // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
831
} // if (mOptions->Deformable)
833
//-----------------------------------------------------------------------
834
void PagingLandScapeSceneManager::getAreaHeight (const Ogre::Vector3 &impact)
836
const int X = static_cast<int> (impact.x / mOptions->scale.x);
837
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
839
//const int pageSize = mOptions->PageSize - 1;
841
const int W = static_cast<int> (mOptions->maxUnScaledX);
842
const int H = static_cast<int> (mOptions->maxUnScaledZ);
844
if (X < -W || X > W || Z < -H || Z > H)
847
const int brushW = static_cast<int> (mBrushArrayWidth);
848
// Calculate the minimum X value
849
// make sure it is still on the height map
850
unsigned int xshift = 0;
851
int Xmin = static_cast<int> (-brushW * 0.5f);
854
//assert (Xmin + X + W > 0);
855
xshift = static_cast <unsigned int> (abs (Xmin + X + W));
858
// Calculate the maximum X value
859
// make sure it is still on the height map
860
int Xmax = static_cast<int> (brushW * 0.5f) ;
863
const int brushH = static_cast<int> (mBrushArrayHeight);
864
// Calculate the minimum Z value
865
// make sure it is still on the height map
866
unsigned int zshift = 0;
867
int Zmin = static_cast<int> (- brushH * 0.5f) ;
870
//assert (Zmin + Z + H > 0);
871
zshift = static_cast <unsigned int> (abs (Zmin + Z + H));
874
// Calculate the maximum Z value
875
// make sure it is still on the height map
876
int Zmax = static_cast<int> (brushH * 0.5f) ;
880
const unsigned int pSize = mOptions->PageSize - 1;
881
const Ogre::Real Hscale = 1 / (mOptions->scale.y * mBrushScale);
882
// Main loop to draw the circle on the height map
883
// (goes through each X value)
884
unsigned int array_indx = zshift*brushW;
885
for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
887
// For each of those Z values, calculate the new Y value
888
unsigned int curr_indx = array_indx + xshift;
889
for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
891
const Ogre::Vector3 currpoint (X + Xcurr, 0.0f, Z + Zcurr);
892
assert (mPageManager&& mData2DManager && mTextureManager);
893
PagingLandScapeTile * t = mPageManager->getTileUnscaled (currpoint.x, currpoint.z, false);
894
if (t && t->isLoaded ())
896
mImpactInfo = t->getInfo ();
897
// check page boundaries to modify any page, tile neighbour
898
// tells any tile modified to update at next frame
899
assert (curr_indx < mBrushArrayWidth*mBrushArrayHeight);
901
// adjust x and z to be local to page
902
const unsigned int x = static_cast<unsigned int> (currpoint.x
903
- mImpactInfo->mPageX * pSize
905
const unsigned int z = static_cast<unsigned int> (currpoint.z
906
- mImpactInfo->mPageZ * pSize
908
mBrushArray[curr_indx] = mData2DManager->getHeight(mImpactInfo->mPageX,
916
} // if (t && t->isLoaded ())
919
} // for (int Xcurr = Xmin; Xcurr < Xmax; Xcurr++)
920
array_indx += brushW;
921
} // for (int Zcurr = Zmin; Zcurr < Zmax; Zcurr++)
923
//-----------------------------------------------------------------------
924
bool PagingLandScapeSceneManager::setOption(const String& strKey, const void* pValue)
927
if (StringUtil::endsWith(strKey, "listener", true))
929
if (mListenerManager->setOption (strKey, pValue))
933
if (StringUtil::startsWith(strKey, "pause", true))
935
mPageManager->setEnabled( ! *(const_cast < bool * > (static_cast < const bool * >(pValue))));
938
// deformation and painting
939
if (strKey == "BrushArray")
941
mBrushArray = const_cast <Ogre::Real * > (static_cast < const Ogre::Real * >(pValue));
944
if (strKey == "BrushArrayHeight")
946
mBrushArrayHeight = * static_cast < const unsigned int * > (pValue);
949
if (strKey == "BrushArrayWidth")
951
mBrushArrayWidth = * static_cast < const unsigned int * > (pValue);
954
if (strKey == "BrushScale")
956
mBrushScale = * static_cast < const Ogre::Real * > (pValue) ;
959
if (strKey == "BrushSize")
961
mBrushSize = * static_cast < const unsigned int * > (pValue);
965
if (strKey == "setHeightCenter")
967
mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
968
setHeight (mBrushCenter);
972
if (strKey == "DeformationCenter")
974
mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
975
deformHeight (mBrushCenter);
979
if (strKey == "fillBrushArray")
981
mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
982
getAreaHeight (mBrushCenter);
985
if (strKey == "PaintCenter")
987
mBrushCenter = * static_cast < const Ogre::Vector3 * > (pValue);
991
if (strKey == "setPaintChannelValues")
993
mTextureManager->setPaintChannelValues (
994
static_cast < const std::vector<Real> *>
1000
if (strKey == "renderTextureModeToBaseTextures")
1002
const String alternateMaterial = *static_cast < const String * > (pValue);
1003
renderBaseTextures(alternateMaterial);
1007
if (strKey == "LoadMap")
1009
const String textureFormatName(mOptions->getCurrentTextureFormat ());
1011
PagingLandScapeSceneManager::resetScene();
1012
PagingLandScapeSceneManager::loadScene ();
1014
textureFormatChanged = false;
1019
if (strKey == "CurrentMap")
1021
const String CurrentMapName = *static_cast < const String * > (pValue);
1022
mOptions->setCurrentMapName (CurrentMapName);
1025
if (strKey == "InsertNewMap")
1027
const String CurrentMapName = *static_cast < const String * > (pValue);
1028
mOptions->insertMap(CurrentMapName);
1031
// TextureFormat changes
1032
if (strKey == "CurrentTextureFormat")
1034
// Override File TextureFormat
1035
mOptions->setTextureFormat (*static_cast < const String * > (pValue));
1036
textureFormatChanged = true;
1039
// TextureFormat changes
1040
if (strKey == "InsertTextureFormat")
1042
// Override File TextureFormat
1043
mOptions->insertTextureFormat (*static_cast < const String * > (pValue));
1046
if (strKey == "PageUpdate")
1048
const Vector2 page = *static_cast < const Vector2 * > (pValue);
1050
// Reload Data. ALso must reload pages that depend on this
1051
mData2DManager->reload (page.x, page.y);
1052
mTextureManager->reload(page.x, page.y);
1055
mData2DManager->reload (page.x-1, page.y);
1056
mTextureManager->reload(page.x-1, page.y);
1060
mTextureManager->reload(page.x, page.y-1);
1061
mData2DManager->reload (page.x, page.y-1);
1063
if (page.x > 0 && page.y > 0)
1065
mData2DManager->reload (page.x-1, page.y-1);
1066
mTextureManager->reload(page.x-1, page.y-1);
1070
//mPageManager::getSingleton().getPage(page.x, page.y)->reload();
1073
if (strKey == "LoadNow")
1075
assert (mPageManager);
1076
if (mOptions->max_preload_pages*mOptions->max_preload_pages >= mOptions->NumPages)
1078
// Configuration file is telling us to pre-load all pages at startup.
1079
for (unsigned int pageY = 0; pageY < mOptions->world_height; pageY++)
1081
for (unsigned int pageX = 0; pageX < mOptions->world_width; pageX++)
1083
PagingLandScapePage * const p = mPageManager->getPage(pageX, pageY);
1085
mPageManager->addLoadedPage(p);
1089
if (mOptions->primaryCamera)
1090
mPageManager->loadNow (mOptions->primaryCamera);
1094
PagingLandScapeCamera *cam = const_cast <PagingLandScapeCamera *> (static_cast < const PagingLandScapeCamera * > (pValue));
1095
mPageManager->loadNow (cam);
1098
if (strKey == "ResetScene")
1100
if( * static_cast < const bool * > (pValue) )
1101
PagingLandScapeSceneManager::resetScene();
1105
if (mOptions->setOption(strKey, pValue) == true)
1109
if (PagingLandScapeOctreeSceneManager::setOption (strKey, pValue) == true)
1118
//-----------------------------------------------------------------------
1119
bool PagingLandScapeSceneManager::getOption(const String& strKey, void* pDestValue)
1121
if (strKey == "h" || strKey == "getHeightAt")
1123
Ogre::Vector3 *p = static_cast < Ogre::Vector3 * > (pDestValue);
1124
p->y = getHeightAt (p->x, p->z);
1127
if (strKey == "s" || strKey == "getSlopeAt")
1129
Ogre::Vector3 *p = static_cast < Ogre::Vector3 * > (pDestValue);
1130
p->y = getSlopeAt (p->x, p->z);
1133
if (StringUtil::startsWith(strKey, "pause", true))
1135
* (static_cast < bool * > (pDestValue)) = !mPageManager->isEnabled();
1139
// heightfield data an pos info
1140
if (strKey == "MapBoundaries")
1142
AxisAlignedBox *box = static_cast < AxisAlignedBox * > (pDestValue);
1144
box->setExtents(-mOptions->maxScaledX,
1146
-mOptions->maxScaledZ,
1147
mOptions->maxScaledX,
1149
mOptions->maxScaledZ);
1153
if (strKey == "GlobalToPage")
1155
Ogre::Vector3 *pos = static_cast < Ogre::Vector3 * > (pDestValue);
1156
mPageManager->getGlobalToPage (pos->x, pos->z);
1159
if (strKey == "getAreaSize")
1161
Ogre::Vector3 *vertices_array = static_cast < Ogre::Vector3 * > (pDestValue);
1163
mPageManager->getGlobalToPage (vertices_array[0].x, vertices_array[0].z);
1164
mPageManager->getGlobalToPage (vertices_array[1].x, vertices_array[1].z);
1165
mPageManager->getGlobalToPage (vertices_array[2].x, vertices_array[2].z);
1166
mPageManager->getGlobalToPage (vertices_array[3].x, vertices_array[3].z);
1168
// define an area an get number of point in it.
1169
const Ogre::Real maxx = std::max (vertices_array[0].x,
1170
std::max (vertices_array[1].x,
1171
std::max (vertices_array[2].x,
1172
vertices_array[3].x)));
1173
const Ogre::Real minx = std::min (vertices_array[0].x,
1174
std::min (vertices_array[1].x,
1175
std::min (vertices_array[2].x,
1176
vertices_array[3].x)));
1178
const Ogre::Real maxz = std::max (vertices_array[0].z,
1179
std::max (vertices_array[1].z,
1180
std::max (vertices_array[2].z,
1181
vertices_array[3].z)));
1182
const Ogre::Real minz = std::min (vertices_array[0].z,
1183
std::min (vertices_array[1].z,
1184
std::min (vertices_array[2].z,
1185
vertices_array[3].z)));
1187
const unsigned int xpoints = static_cast<unsigned int> (maxx - minx);
1188
const unsigned int zpoints = static_cast<unsigned int> (maxz - minz);
1189
vertices_array[4].x = zpoints * xpoints;
1195
if (strKey == "VisibilityMaterial")
1199
* static_cast < MaterialPtr * > (pDestValue) = mHorizon->getVisibilityMaterial();
1205
// TextureFormat info
1206
if (strKey == "NextTextureFormat")
1208
* static_cast < String * > (pDestValue) = mTextureManager->getNextTextureFormat();
1211
if (strKey == "CurrentTextureFormat")
1213
* static_cast < String * > (pDestValue) = mTextureManager->getCurrentTextureFormat();
1219
if (strKey == "NextMap")
1221
* static_cast < String * > (pDestValue) = mOptions->getNextMapName();
1224
if (strKey == "PreviousMap")
1226
* static_cast < String * > (pDestValue) = mOptions->getPreviousMapName();
1229
if (strKey == "CurrentMap")
1231
* static_cast < String * > (pDestValue) = mOptions->getCurrentMapName();
1234
if (strKey == "CurrentMapFileName")
1236
* static_cast < String * > (pDestValue) = mOptions->LandScape_filename;
1242
if (strKey == "CurrentCameraPageX")
1245
* static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraPageX();
1248
if (strKey == "CurrentCameraPageZ")
1251
* static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraPageZ();
1257
if (strKey == "LoadedPages")
1260
* static_cast < int * > (pDestValue) = mPageManager->getLoadedPageSize();
1264
if (strKey == "UnloadedPages")
1267
* static_cast < int * > (pDestValue) = mPageManager->getUnloadedPagesSize();
1271
if (strKey == "MaxNumTiles")
1274
* static_cast < int * > (pDestValue) = mTileManager->numTiles();
1277
if (strKey == "TileFree")
1280
* static_cast < int * > (pDestValue) = (int)mTileManager->numFree();
1283
if (strKey == "CurrentCameraTileX")
1286
* static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraTileX();
1289
if (strKey == "CurrentCameraTileZ")
1292
* static_cast < int * > (pDestValue) = mPageManager->getCurrentCameraTileZ();
1297
if (strKey == "MaxNumRenderables")
1299
if (mRenderableManager)
1300
* static_cast < int * > (pDestValue) = mRenderableManager->numRenderables();
1303
if (strKey == "RenderableFree")
1305
if (mRenderableManager)
1306
* static_cast < int * > (pDestValue) = (int)mRenderableManager->numFree();
1309
if (strKey == "RenderableLoading")
1311
if (mRenderableManager)
1312
* static_cast < int * > (pDestValue) = (int)mRenderableManager->numLoading();
1315
if (strKey == "VisibleRenderables")
1317
if (mRenderableManager)
1318
* static_cast < unsigned int * > (pDestValue) = mRenderableManager->numVisibles();
1320
* static_cast < unsigned int * > (pDestValue) = 0;
1325
if (strKey == "Impact")
1327
* static_cast < Ogre::Vector3 * > (pDestValue) = mImpact;
1330
if (strKey == "ImpactPageX")
1333
* static_cast < int * > (pDestValue) = mImpactInfo->mPageX;
1336
if (strKey == "ImpactPageZ")
1339
* static_cast < int * > (pDestValue) = mImpactInfo->mPageZ;
1342
if (strKey == "ImpactTileX")
1345
* static_cast < int * > (pDestValue) = mImpactInfo->mTileZ;
1348
if (strKey == "ImpactTileZ")
1351
* static_cast < int * > (pDestValue) = mImpactInfo->mTileZ;
1354
if (strKey == "numModifiedTile")
1356
if (mRenderableManager)
1357
* static_cast < int * > (pDestValue) = mRenderableManager->numRenderables();
1360
if (strKey == "BrushSize")
1362
* static_cast < int * > (pDestValue) = mBrushSize;
1365
if (strKey == "BrushScale")
1367
* static_cast <Ogre::Real * > (pDestValue) = mBrushScale;
1372
if (strKey == "currentColors")
1377
//added for Vertex data retrieval
1378
if (strKey == "PageGetTileVertexData_2")
1381
* This is the optimized, yet a bit fuzzy implementation of the getVertexDataPatch
1382
* Usage: Pass in a std::vector<void*> Pointer to the getOption call containing at least 5 Elements
1383
* [0](Ogre::unsigned int*) = X Index of the Page to retrieve data from
1384
* [1](Ogre::unsigned int*) = Z Index of the Page to retrieve data from
1385
* [2](Ogre::unsigned int*) = X Index of the Tile within the Page to retrieve data from
1386
* [3](Ogre::unsigned int*) = Z Index of the Tile within the Page to retrieve data from
1387
* [4](Ogre::unsigned int*) = LodLevel to get the data at (note that level 0 means highest detail)
1388
* The getData call will then append 3 entries to the end of the vector. In Detail(in order)
1389
* [End-2](Ogre::unsigned int*) = Number of vertices returned
1390
* [End-1] (Ogre::Vector3*) = The actual vertices, this is a array containing as many elements as returned in [End-2]
1391
* [End] (Ogre::IndexData*) = The index data for the terrain polygons at the queried LodLevel
1392
* @remark note that the caller is in charge of deleting the vector array, vertices array and indice array.
1394
unsigned int requestPageX = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[0]);
1395
unsigned int requestPageZ = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[1]);
1396
unsigned int requestTileX = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[2]);
1397
unsigned int requestTileZ = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[3]);
1398
unsigned int requestLodLevel = *static_cast<unsigned int *>((*static_cast<std::vector<void*>*>(pDestValue))[4]);
1399
PagingLandScapePage* page = mPageManager->getPage(requestPageX,requestPageZ);
1402
PagingLandScapeTile* tile = page->getTile(requestTileX,requestTileZ);
1405
PagingLandScapeRenderable* rend = tile->getRenderable();
1408
Vector3* tempPointer; //This will hold the vertexData and needs to be deleted by the caller
1409
unsigned int* numPtr = new unsigned int;
1410
*numPtr = rend->getVertexCount();
1411
(*static_cast<std::vector<void*>*>(pDestValue)).push_back(numPtr);
1412
tempPointer = new Ogre::Vector3[*numPtr];
1413
//warning! make sure that the allocated space for the vertices is big enough!
1414
rend->getRawVertexData(tempPointer);
1415
(*static_cast<std::vector<void*>*>(pDestValue)).push_back(tempPointer);
1416
(*static_cast<std::vector<void*>*>(pDestValue)).push_back(rend->getRawIndexData(requestLodLevel));
1423
if (strKey == "getMaterialPageName")
1429
Vector3 **pos = static_cast < Ogre::Vector3 ** > (pDestValue);
1430
mPageManager->getGlobalToPage ((*pos)->x, (*pos)->z);
1433
Ogre::PagingLandScapeTexture* texture_ptr =
1434
mTextureManager->getTexture((*pos)->x, (*pos)->z, false);
1436
// check for valid texture
1440
String* name_ptr = const_cast<String*>(&texture_ptr->getMaterialName());
1442
// convert void pointer to a string**
1443
String** target_ptr = static_cast<String**>(pDestValue);
1445
// save name at target position
1446
*target_ptr = name_ptr;
1453
if (mOptions && mOptions->getOption(strKey, pDestValue) == false)
1455
return PagingLandScapeOctreeSceneManager::getOption (strKey, pDestValue);
1460
//-----------------------------------------------------------------------
1461
bool PagingLandScapeSceneManager::hasOption(const String& strKey) const
1463
if (strKey == "AddNewHeight")
1467
if (strKey == "RemoveNewHeight")
1471
if (strKey == "CurrentCameraPageX")
1475
if (strKey == "CurrentCameraPageZ")
1479
if (strKey == "MaxNumTiles")
1483
if (strKey == "TileFree")
1487
if (strKey == "MaxNumRenderables")
1491
if (strKey == "RenderableFree")
1495
if (strKey == "RenderableLoading")
1499
if (strKey == "PagePreloadQueue")
1503
if (strKey == "PageLoadQueue")
1507
if (strKey == "PageUnloadQueue")
1511
if (strKey == "PagePostUnloadQueue")
1515
//added for Vertex data retrieval
1516
if (strKey == "PageGetTileVertexData")
1521
if (mOptions && mOptions->hasOption(strKey) == false)
1523
return PagingLandScapeOctreeSceneManager::hasOption (strKey);
1528
//-----------------------------------------------------------------------
1529
bool PagingLandScapeSceneManager::getOptionValues(const String & key, StringVector &refValueList)
1531
// if (key == "CurrentCameraPageX")
1533
// refValueList.push_back(MemoryDataStreamPtr());
1536
// if (key == "CurrentCameraPageZ")
1538
// refValueList.push_back(MemoryDataStreamPtr());
1541
// if (key == "MaxNumTiles")
1543
// refValueList.push_back(MemoryDataStreamPtr());
1546
// if (key == "TileFree")
1548
// refValueList.push_back(MemoryDataStreamPtr());
1551
// if (key == "MaxNumRenderables")
1553
// refValueList.push_back(MemoryDataStreamPtr());
1556
// if (key == "RenderableFree")
1558
// refValueList.push_back(MemoryDataStreamPtr());
1561
// if (key == "RenderableLoading")
1563
// refValueList.push_back(MemoryDataStreamPtr());
1566
// if (key == "PagePreloadQueue")
1568
// refValueList.push_back(MemoryDataStreamPtr());
1571
// if (key == "PageLoadQueue")
1573
// refValueList.push_back(MemoryDataStreamPtr());
1576
// if (key == "PageUnloadQueue")
1578
// refValueList.push_back(MemoryDataStreamPtr());
1581
// if (key == "PagePostUnloadQueue")
1583
// refValueList.push_back(MemoryDataStreamPtr());
1587
if (mOptions->getOptionValues(key, refValueList) == false)
1589
return PagingLandScapeOctreeSceneManager::getOptionValues (key, refValueList);
1594
//-----------------------------------------------------------------------
1595
bool PagingLandScapeSceneManager::getOptionKeys(StringVector &refKeys)
1598
refKeys.push_back("AddNewHeight");
1599
refKeys.push_back("RemoveNewHeight");
1600
refKeys.push_back("CurrentCameraPageX");
1601
refKeys.push_back("CurrentCameraPageZ");
1602
refKeys.push_back("MaxNumTiles");
1603
refKeys.push_back("TileFree");
1604
refKeys.push_back("MaxNumRenderables");
1605
refKeys.push_back("RenderableFree");
1606
refKeys.push_back("RenderableLoading");
1607
refKeys.push_back("PagePreloadQueue");
1608
refKeys.push_back("PageLoadQueue");
1609
refKeys.push_back("PageUnloadQueue");
1610
refKeys.push_back("PagePostUnloadQueue");
1611
mOptions->getOptionKeys(refKeys);
1612
return PagingLandScapeOctreeSceneManager::getOptionKeys (refKeys);
1614
//-------------------------------------------------------------------------
1615
void PagingLandScapeSceneManager::setWorldGeometryRenderQueue (uint8 qid)
1617
PagingLandScapeOctreeSceneManager::setWorldGeometryRenderQueue(qid);
1619
mPageManager->setWorldGeometryRenderQueue (qid);
1621
//-----------------------------------------------------------------------
1622
Camera * PagingLandScapeSceneManager::createCamera(const String &name)
1624
if (mCameras.find(name) != mCameras.end())
1627
Exception::ERR_DUPLICATE_ITEM,
1628
"A camera with the name " + name + " already exists",
1629
"PagingLandScapeSceneManager::createCamera");
1632
Camera * c = new PagingLandScapeCamera(name, this);
1633
mCameras.insert(CameraList::value_type(name, c));
1634
PagingLandScapeOctreeSceneManager::addCamera (c);
1635
// Check if we need to set the primaryCamera
1636
if (mOptions && !mOptions->primaryCamera)
1638
mOptions->setPrimaryCamera (static_cast <PagingLandScapeCamera*> (c));
1641
c->setNearClipDistance( 1 );
1642
// Infinite far plane?
1643
if (Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
1645
c->setFarClipDistance(0);
1650
getOption( "VisibleDistance", &tmp);
1651
c->setFarClipDistance( tmp );
1654
// create visible bounds aab map entry
1655
mCamVisibleObjectsMap[c] = VisibleObjectsBoundsInfo();
1659
//-----------------------------------------------------------------------
1660
void PagingLandScapeSceneManager::destroyCamera(Camera *cam)
1662
if (mOptions->primaryCamera && cam->getName() == mOptions->primaryCamera->getName())
1664
mOptions->setPrimaryCamera (0);
1666
PagingLandScapeOctreeSceneManager::destroyCamera(cam);
1668
//-----------------------------------------------------------------------
1669
void PagingLandScapeSceneManager::destroyCamera(const String& name)
1671
if (mOptions->primaryCamera && name == mOptions->primaryCamera->getName())
1673
mOptions->setPrimaryCamera (0);
1675
PagingLandScapeOctreeSceneManager::destroyCamera(name);
1677
//-----------------------------------------------------------------------
1678
void PagingLandScapeSceneManager::destroyAllCameras(void)
1680
mOptions->setPrimaryCamera (0);
1681
PagingLandScapeOctreeSceneManager::destroyAllCameras();
1683
//-----------------------------------------------------------------------
1684
void _OgrePagingLandScapeExport PagingLandScapeSceneManager::getWorldSize(Real *worldSizeX,Ogre::Real *worldSizeZ)
1686
*worldSizeX = mOptions->maxScaledX * 2.0f;
1687
*worldSizeZ = mOptions->maxScaledZ * 2.0f;
1688
// *worldSizeX = (float)mOptions->world_width * mOptions->scale.x;
1689
// *worldSizeZ = (float)mOptions->world_height * mOptions->scale.z;
1691
//-----------------------------------------------------------------------
1692
float _OgrePagingLandScapeExport PagingLandScapeSceneManager::getMaxSlope(Vector3 location1, Ogre::Vector3 location2, float maxSlopeIn)
1694
return mData2DManager->getMaxSlope(location1, location2, maxSlopeIn);
1696
//-----------------------------------------------------------------------
1697
void PagingLandScapeSceneManager::renderBaseTextures(const String& alternateMatName)
1700
//only currently works for PLSplattingShaderLit mode
1701
//because I can't figure out how to elegantly handle all texture modes (yet)
1702
if(mOptions->textureFormat != "PLSplattingShaderLit" || alternateMatName != "PLSplattingShaderUnlit")
1705
Exception::ERR_NOT_IMPLEMENTED,
1706
"Only currently supports PLSplattingShaderLit texture mode and alternate material SplattingShader",
1707
"PagingLandScapeSceneManager::renderBaseTextures");
1710
PagingLandScapeTexture* t = NULL;
1713
RenderTexture *renderTexture;
1715
texture = TextureManager::getSingleton ().createManual("PLRTTBaseTexture",
1716
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
1724
renderTexture = texture->getBuffer()->getRenderTarget();
1725
renderTexture->setAutoUpdated(false);
1726
rttCam = createCamera("PLRTTBaseTextureCam");
1727
rttCam->setNearClipDistance(1.0f);
1728
rttCam->setFarClipDistance(0);
1729
rttCam->setPosition(Vector3(0,0,2));
1730
rttCam->lookAt(Vector3(0,0,0));
1731
Viewport* const v = renderTexture->addViewport(rttCam);
1732
v->setClearEveryFrame(true);
1733
v->setBackgroundColour(ColourValue(0.0f, 0.0f, 0.0f, 0.0f));
1735
//addSpecialCaseRenderQueue(Ogre::RENDER_QUEUE_6);
1736
//setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_INCLUDE);
1738
Rectangle2D* rect = new Rectangle2D(true);
1739
rect->setBoundingBox(AxisAlignedBox(-100000.0*Vector3::UNIT_SCALE, 100000.0*Vector3::UNIT_SCALE));
1740
rect->setCorners(-1, 1, 1, -1);
1741
rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
1742
SceneNode* node = getRootSceneNode()->createChildSceneNode("PLBaseTextureRectNode");
1743
rect->setVisible(true);
1744
node->attachObject(rect);
1747
MaterialPtr material;
1748
MaterialPtr alternateMaterial;
1749
//this->setAmbientLight(ColourValue::White);
1751
for(uint x = 0; x < mOptions->world_width; ++x)
1753
for(uint z = 0; z < mOptions->world_height; ++z)
1755
t = mTextureManager->getTexture(x, z);
1759
textureName = mOptions->LandScape_filename + ".Base." + StringConverter::toString(z) + "." + StringConverter::toString(x) + ".png";
1760
matName = t->getMaterialName();
1762
//if an alternate material name is specified, we'll use the texture units from our original material
1763
//and the passes from our new material
1764
if(alternateMatName != "")
1766
alternateMaterial = MaterialManager::getSingleton().getByName(alternateMatName + "_Clone");
1767
if(alternateMaterial.isNull())
1769
alternateMaterial = MaterialManager::getSingleton().getByName(alternateMatName);
1770
if(alternateMaterial.isNull())
1773
Exception::ERR_ITEM_NOT_FOUND,
1774
"Could not find alternate material " + alternateMatName,
1775
"PagingLandScapeSceneManager::renderBaseTextures");
1777
alternateMaterial = alternateMaterial->clone(alternateMatName + "_Clone");
1779
matName = alternateMaterial->getName();
1780
material = t->getMaterial();
1782
//we know that pass 2 of PLSplattingShaderLitDecompress has our coverage and
1783
//splatting textures in specific texture units
1784
//I think if we want this to be completely generic we'll have to load the original
1785
//texture mode's material, iterate through and find the "Coverage" and "Splatting" references from it,
1786
//and do the same for alternate material, and attempt to hook them up the same
1787
for(uint i = 0; i < 5; ++i)
1789
alternateMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(i)->setTextureName(material->getTechnique(0)->getPass(1)->getTextureUnitState(i)->getTextureName());
1793
//assign the material to the rectangle
1794
rect->setMaterial(matName);
1795
_updateSceneGraph(rttCam);
1796
renderTexture->update();
1797
renderTexture->writeContentsToFile("../../../Media/paginglandscape2/terrains/" + mOptions->LandScape_filename + "/" + textureName);
1798
TexturePtr texture = TextureManager::getSingleton().getByName(textureName);
1799
if(!texture.isNull())
1802
if(mOptions->VertexCompression)
1804
MaterialManager::getSingleton().remove(material->getHandle());
1809
TextureManager::getSingleton().remove(texture->getHandle());
1810
destroyCamera("PLRTTBaseTextureCam");
1811
node->detachObject(rect);
1812
destroySceneNode("PLBaseTextureRectNode");