diff --git a/examples/osgmultitexturecontrol/CMakeLists.txt b/examples/osgmultitexturecontrol/CMakeLists.txt index c3a3483f1..8d346bac8 100644 --- a/examples/osgmultitexturecontrol/CMakeLists.txt +++ b/examples/osgmultitexturecontrol/CMakeLists.txt @@ -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 ) diff --git a/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp b/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp index 05ade529d..049dca698 100644 --- a/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp +++ b/examples/osgmultitexturecontrol/osgmultitexturecontrol.cpp @@ -38,6 +38,8 @@ #include #include +#include + #include #include @@ -196,6 +198,15 @@ int main( int argc, char **argv ) return 1; } + osgTerrain::TerrainSystem* terrain = findTopMostNodeOfType(rootnode); + if (!terrain) + { + terrain = new osgTerrain::TerrainSystem; + terrain->addChild(rootnode); + + rootnode = terrain; + } + osg::CoordinateSystemNode* csn = findTopMostNodeOfType(rootnode); unsigned int numLayers = 1; diff --git a/include/osgTerrain/Terrain b/include/osgTerrain/Terrain index 340c3a6c3..fa7a43ec1 100644 --- a/include/osgTerrain/Terrain +++ b/include/osgTerrain/Terrain @@ -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 (layerrhs.layer) return false; + if (xrhs.x) return false; + return y > Layers; + + TerrainSystem* _terrainSystem; + + bool _hasBeenTraversal; + + TileID _tileID; + osg::ref_ptr _terrainTechnique; osg::ref_ptr _locator; @@ -125,8 +171,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group bool _requiresNormals; bool _treatBoundariesToValidDataAsDefaultValue; - - osg::ref_ptr _operationQueue; }; } diff --git a/include/osgTerrain/TerrainSystem b/include/osgTerrain/TerrainSystem new file mode 100644 index 000000000..9e32c4c96 --- /dev/null +++ b/include/osgTerrain/TerrainSystem @@ -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 +#include + +#include + +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; + + typedef std::list< osg::observer_ptr > TerrainList; + TerrainList _incomingTerrain; + + +}; + +} + +#endif diff --git a/include/osgTerrain/TileSystem b/include/osgTerrain/TileSystem index bf5b0da36..44b127a18 100644 --- a/include/osgTerrain/TileSystem +++ b/include/osgTerrain/TileSystem @@ -14,13 +14,13 @@ #ifndef OSGTERRAIN_TILESYSTEM #define OSGTERRAIN_TILESYSTEM 1 -#include +#include + #include #include 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; - int _layer; - int _x; - int _y; + typedef std::map< TileID, osg::observer_ptr > TileMap; + + TileMap _tileMap; }; } diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 0c00cc673..67164ec5e 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -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); diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index eb5a50130..74c8c15f4 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -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 diff --git a/src/osgPlugins/ive/Terrain.cpp b/src/osgPlugins/ive/Terrain.cpp index 0cf3bafc0..c2472ead1 100644 --- a/src/osgPlugins/ive/Terrain.cpp +++ b/src/osgPlugins/ive/Terrain.cpp @@ -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()); diff --git a/src/osgTerrain/CMakeLists.txt b/src/osgTerrain/CMakeLists.txt index 95f7b850b..1b9657202 100644 --- a/src/osgTerrain/CMakeLists.txt +++ b/src/osgTerrain/CMakeLists.txt @@ -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 diff --git a/src/osgTerrain/Terrain.cpp b/src/osgTerrain/Terrain.cpp index d0a58aa90..d475985d4 100644 --- a/src/osgTerrain/Terrain.cpp +++ b/src/osgTerrain/Terrain.cpp @@ -12,12 +12,16 @@ */ #include +#include + #include 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(*itr); + if (ts) + { + osg::notify(osg::NOTICE)<<"Assigning terrain system "<(getCullCallback()); diff --git a/src/osgTerrain/TerrainSystem.cpp b/src/osgTerrain/TerrainSystem.cpp new file mode 100644 index 000000000..536318c04 --- /dev/null +++ b/src/osgTerrain/TerrainSystem.cpp @@ -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 + +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); +} diff --git a/src/osgTerrain/TileSystem.cpp b/src/osgTerrain/TileSystem.cpp index 177478bdc..9af2334be 100644 --- a/src/osgTerrain/TileSystem.cpp +++ b/src/osgTerrain/TileSystem.cpp @@ -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() -{ -} -