Introduce TerrainSystem node which decorates a complete terrain model made up of Terrain tiles.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SET(TARGET_SRC osgmultitexturecontrol.cpp )
|
||||
SET(TARGET_ADDED_LIBRARIES osgFX )
|
||||
SET(TARGET_ADDED_LIBRARIES osgFX osgTerrain)
|
||||
|
||||
#### end var setup ###
|
||||
SETUP_EXAMPLE(osgmultitexturecontrol )
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <osgGA/TerrainManipulator>
|
||||
|
||||
#include <osgTerrain/TerrainSystem>
|
||||
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osgViewer/Viewer>
|
||||
|
||||
@@ -196,6 +198,15 @@ int main( int argc, char **argv )
|
||||
return 1;
|
||||
}
|
||||
|
||||
osgTerrain::TerrainSystem* terrain = findTopMostNodeOfType<osgTerrain::TerrainSystem>(rootnode);
|
||||
if (!terrain)
|
||||
{
|
||||
terrain = new osgTerrain::TerrainSystem;
|
||||
terrain->addChild(rootnode);
|
||||
|
||||
rootnode = terrain;
|
||||
}
|
||||
|
||||
osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode);
|
||||
|
||||
unsigned int numLayers = 1;
|
||||
|
||||
@@ -23,6 +23,37 @@
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
class TerrainSystem;
|
||||
|
||||
class TileID
|
||||
{
|
||||
public:
|
||||
|
||||
TileID():
|
||||
layer(-1),
|
||||
x(-1),
|
||||
y(-1) {}
|
||||
|
||||
TileID(int in_layer, int in_x, int in_y):
|
||||
layer(in_layer),
|
||||
x(in_x),
|
||||
y(in_y) {}
|
||||
|
||||
bool operator < (const TileID& rhs) const
|
||||
{
|
||||
if (layer<rhs.layer) return true;
|
||||
if (layer>rhs.layer) return false;
|
||||
if (x<rhs.x) return true;
|
||||
if (x>rhs.x) return false;
|
||||
return y<rhs.y;
|
||||
}
|
||||
|
||||
int layer;
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
|
||||
/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
|
||||
* This allows TerrainTechnique's to be plugged in at runtime.*/
|
||||
class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
@@ -41,8 +72,25 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
/** Call init on any attached TerrainTechnique.*/
|
||||
void init();
|
||||
|
||||
|
||||
/** Set the TerrainSystem that this Terrain tile is a member of.*/
|
||||
void setTerrainSystem(TerrainSystem* ts) { _terrainSystem = ts; }
|
||||
|
||||
/** Get the TerrainSystem that this Terrain tile is a member of.*/
|
||||
TerrainSystem* getTerrainSystem() { return _terrainSystem; }
|
||||
|
||||
/** Get the const TerrainSystem that this Terrain tile is a member of.*/
|
||||
const TerrainSystem* getTerrainSystem() const { return _terrainSystem; }
|
||||
|
||||
|
||||
void setTileID(const TileID& tileID) { _tileID = tileID; }
|
||||
|
||||
const TileID& getTileID() const { return _tileID; }
|
||||
|
||||
|
||||
|
||||
/** Set the TerrainTechnique*/
|
||||
void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique);
|
||||
void setTerrainTechnique(TerrainTechnique* TerrainTechnique);
|
||||
|
||||
/** Get the TerrainTechnique*/
|
||||
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
|
||||
@@ -98,15 +146,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
bool getTreatBoundariesToValidDataAsDefaultValue() const { return _treatBoundariesToValidDataAsDefaultValue; }
|
||||
|
||||
|
||||
/** Set an OperationQueue to do an data initialization and update work.*/
|
||||
void setOperationQueue(osg::OperationQueue* operations) { _operationQueue = operations; }
|
||||
|
||||
/** Get the OperationsQueue if one is attached, return NULL otherwise.*/
|
||||
osg::OperationQueue* getOperationQueue() { return _operationQueue.get(); }
|
||||
|
||||
/** Get the const OperationsQueue if one is attached, return NULL otherwise.*/
|
||||
const osg::OperationQueue* getOperationsQueue() const { return _operationQueue.get(); }
|
||||
|
||||
/** Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers.*/
|
||||
virtual osg::BoundingSphere computeBound() const;
|
||||
|
||||
@@ -116,6 +155,13 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Layer> > Layers;
|
||||
|
||||
|
||||
TerrainSystem* _terrainSystem;
|
||||
|
||||
bool _hasBeenTraversal;
|
||||
|
||||
TileID _tileID;
|
||||
|
||||
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
||||
osg::ref_ptr<Locator> _locator;
|
||||
|
||||
@@ -125,8 +171,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
|
||||
bool _requiresNormals;
|
||||
bool _treatBoundariesToValidDataAsDefaultValue;
|
||||
|
||||
osg::ref_ptr<osg::OperationQueue> _operationQueue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
67
include/osgTerrain/TerrainSystem
Normal file
67
include/osgTerrain/TerrainSystem
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGTERRAINSYSTEM
|
||||
#define OSGTERRAINSYSTEM 1
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
/** TerrainSystem provides a framework for loosely coupling height field data with height rendering algorithms.
|
||||
* This allows TerrainTechnique's to be plugged in at runtime.*/
|
||||
class OSGTERRAIN_EXPORT TerrainSystem : public osg::Group
|
||||
{
|
||||
public:
|
||||
|
||||
TerrainSystem();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
TerrainSystem(const TerrainSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osgTerrain, TerrainSystem);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
/** Set the TerrainTechnique that is used as the prototype for all Terrain below the TerrainSystem. */
|
||||
void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique);
|
||||
|
||||
/** Get the TerrainTechnique*/
|
||||
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
|
||||
|
||||
/** Get the const TerrainTechnique*/
|
||||
const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TerrainSystem();
|
||||
|
||||
friend class TerrainManager;
|
||||
|
||||
void registerPotentialMember(Terrain* terrain);
|
||||
|
||||
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
||||
|
||||
typedef std::list< osg::observer_ptr<Terrain> > TerrainList;
|
||||
TerrainList _incomingTerrain;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,13 +14,13 @@
|
||||
#ifndef OSGTERRAIN_TILESYSTEM
|
||||
#define OSGTERRAIN_TILESYSTEM 1
|
||||
|
||||
#include <osgTerrain/Export>
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
|
||||
/** TileSystem provides the mechanism for computing the position in space of tiles.*/
|
||||
class OSGTERRAIN_EXPORT TileSystem : public osg::Object
|
||||
{
|
||||
@@ -35,26 +35,10 @@ class OSGTERRAIN_EXPORT TileSystem : public osg::Object
|
||||
protected:
|
||||
|
||||
virtual ~TileSystem();
|
||||
};
|
||||
|
||||
class OSGTERRAIN_EXPORT TileID : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
TileID();
|
||||
|
||||
TileID(const TileID&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgTerrain, TileID);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TileID();
|
||||
|
||||
osg::observer_ptr<TileSystem> _tileSystem;
|
||||
int _layer;
|
||||
int _x;
|
||||
int _y;
|
||||
typedef std::map< TileID, osg::observer_ptr<Terrain> > TileMap;
|
||||
|
||||
TileMap _tileMap;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -732,6 +732,22 @@ void DatabasePager::run()
|
||||
_changeAutoUnRef, _valueAutoUnRef,
|
||||
_changeAnisotropy, _valueAnisotropy,
|
||||
_drawablePolicy, this);
|
||||
|
||||
// push the soon to be parent on the nodepath of the NodeVisitor so that
|
||||
// during traversal one can test for where it'll be in the overall scene graph
|
||||
osg::NodePathList nodePathList = databaseRequest->_groupForAddingLoadedSubgraph->getParentalNodePaths();
|
||||
if (!nodePathList.empty())
|
||||
{
|
||||
osg::NodePath& nodePath = nodePathList.front();
|
||||
for(osg::NodePath::iterator nitr = nodePath.begin();
|
||||
nitr != nodePath.end();
|
||||
++nitr)
|
||||
{
|
||||
frov.pushOntoNodePath(*nitr);
|
||||
}
|
||||
}
|
||||
|
||||
frov.pushOntoNodePath(databaseRequest->_groupForAddingLoadedSubgraph.get());
|
||||
|
||||
databaseRequest->_loadedModel->accept(frov);
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@
|
||||
#define VERSION_0023 23
|
||||
#define VERSION_0024 24
|
||||
#define VERSION_0025 25
|
||||
#define VERSION_0026 26
|
||||
|
||||
#define VERSION VERSION_0025
|
||||
#define VERSION VERSION_0026
|
||||
|
||||
/* The BYTE_SEX tag is used to check the endian
|
||||
of the IVE file being read in. The IVE format
|
||||
|
||||
@@ -31,6 +31,13 @@ void Terrain::write(DataOutputStream* out)
|
||||
else
|
||||
throw Exception("Terrain::write(): Could not cast this osgTerrain::Terrain to an osg::Group.");
|
||||
|
||||
if (out->getVersion() >= VERSION_0026)
|
||||
{
|
||||
out->writeInt(getTileID().layer);
|
||||
out->writeInt(getTileID().x);
|
||||
out->writeInt(getTileID().y);
|
||||
}
|
||||
|
||||
if (out->getVersion() >= VERSION_0023)
|
||||
{
|
||||
out->writeLocator(getLocator());
|
||||
@@ -77,6 +84,14 @@ void Terrain::read(DataInputStream* in)
|
||||
else
|
||||
throw Exception("Terrain::read(): Could not cast this osgTerrain::Terrain to an osg::Group.");
|
||||
|
||||
if (in->getVersion() >= VERSION_0026)
|
||||
{
|
||||
int layer = in->readInt();
|
||||
int x = in->readInt();
|
||||
int y = in->readInt();
|
||||
setTileID(osgTerrain::TileID(layer,x,y));
|
||||
}
|
||||
|
||||
if (in->getVersion() >= VERSION_0023)
|
||||
{
|
||||
setLocator(in->readLocator());
|
||||
|
||||
@@ -12,6 +12,7 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/Layer
|
||||
${HEADER_PATH}/Terrain
|
||||
${HEADER_PATH}/TerrainTechnique
|
||||
${HEADER_PATH}/TerrainSystem
|
||||
${HEADER_PATH}/TileSystem
|
||||
${HEADER_PATH}/GeometryTechnique
|
||||
${HEADER_PATH}/ValidDataOperator
|
||||
@@ -26,6 +27,7 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
Locator.cpp
|
||||
Terrain.cpp
|
||||
TerrainTechnique.cpp
|
||||
TerrainSystem.cpp
|
||||
TileSystem.cpp
|
||||
GeometryTechnique.cpp
|
||||
Version.cpp
|
||||
|
||||
@@ -12,12 +12,16 @@
|
||||
*/
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
#include <osgTerrain/TerrainSystem>
|
||||
|
||||
#include <osg/ClusterCullingCallback>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgTerrain;
|
||||
|
||||
Terrain::Terrain():
|
||||
_terrainSystem(0),
|
||||
_hasBeenTraversal(false),
|
||||
_requiresNormals(true),
|
||||
_treatBoundariesToValidDataAsDefaultValue(false)
|
||||
{
|
||||
@@ -27,6 +31,8 @@ Terrain::Terrain():
|
||||
|
||||
Terrain::Terrain(const Terrain& terrain,const osg::CopyOp& copyop):
|
||||
Group(terrain,copyop),
|
||||
_terrainSystem(0),
|
||||
_hasBeenTraversal(false),
|
||||
_elevationLayer(terrain._elevationLayer),
|
||||
_colorLayers(terrain._colorLayers),
|
||||
_requiresNormals(terrain._requiresNormals),
|
||||
@@ -43,6 +49,30 @@ Terrain::~Terrain()
|
||||
|
||||
void Terrain::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
if (!_hasBeenTraversal)
|
||||
{
|
||||
if (!_terrainSystem)
|
||||
{
|
||||
osg::NodePath& nodePath = nv.getNodePath();
|
||||
if (!nodePath.empty())
|
||||
{
|
||||
for(osg::NodePath::reverse_iterator itr = nodePath.rbegin();
|
||||
itr != nodePath.rend() && !_terrainSystem;
|
||||
++itr)
|
||||
{
|
||||
osgTerrain::TerrainSystem* ts = dynamic_cast<TerrainSystem*>(*itr);
|
||||
if (ts)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Assigning terrain system "<<ts<<std::endl;
|
||||
_terrainSystem = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_hasBeenTraversal = true;
|
||||
}
|
||||
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
||||
{
|
||||
osg::ClusterCullingCallback* ccc = dynamic_cast<osg::ClusterCullingCallback*>(getCullCallback());
|
||||
|
||||
34
src/osgTerrain/TerrainSystem.cpp
Normal file
34
src/osgTerrain/TerrainSystem.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgTerrain/TerrainSystem>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgTerrain;
|
||||
|
||||
TerrainSystem::TerrainSystem()
|
||||
{
|
||||
}
|
||||
|
||||
TerrainSystem::~TerrainSystem()
|
||||
{
|
||||
}
|
||||
|
||||
TerrainSystem::TerrainSystem(const TerrainSystem& ts, const osg::CopyOp& copyop)
|
||||
{
|
||||
}
|
||||
|
||||
void TerrainSystem::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
Group::traverse(nv);
|
||||
}
|
||||
@@ -27,25 +27,3 @@ TileSystem::TileSystem(const TileSystem& tileSystem,const osg::CopyOp& copyop):
|
||||
TileSystem::~TileSystem()
|
||||
{
|
||||
}
|
||||
|
||||
TileID::TileID():
|
||||
_tileSystem(0),
|
||||
_layer(-1),
|
||||
_x(-1),
|
||||
_y(-1)
|
||||
{
|
||||
}
|
||||
|
||||
TileID::TileID(const TileID& tileID,const osg::CopyOp& copyop):
|
||||
osg::Object(tileID),
|
||||
_tileSystem(tileID._tileSystem),
|
||||
_layer(tileID._layer),
|
||||
_x(tileID._x),
|
||||
_y(tileID._y)
|
||||
{
|
||||
}
|
||||
|
||||
TileID::~TileID()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user