Refactored the way that the DatabasePager passes the Terrain decorator node onto the TerrainTile.
The DatabasePager now passes the Terrain pointer into the ReaderWriter's via osgDB::Options object, rather than pushing a NodePath containing the Terrain onto NodeVisitor. This change means that the DatabasePager nolonger needs to observer the whole NodePath and will be lighter and quicker for it. The change also means that ReadFileCallback can now run custom NodeVisitor's on the scene graph without having to worry about TerrainTile's constructing scene graphs prior to the Terrain being assigned. Also changed is the NodeVisitor::DatabaseRequestHandler which now requires a NodePath to the node that you wish to add to rather than just the pointer to the node you wish to add to. This is more robust when handling scenes with multiple parental paths, whereas previously errors could have occurred due to the default of picking the first available parental path. This change means that subclasses of DatabasePager will need to be updated to use this new function entry point.
This commit is contained in:
@@ -23,8 +23,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
// forward declare osgTerrrain::Terrain to enable declaration of asTerrain() method.
|
||||
namespace osgTerrain {
|
||||
class Terrain;
|
||||
}
|
||||
|
||||
namespace osg {
|
||||
|
||||
// forcing declare classes to enable declaration of as*() methods.
|
||||
class NodeVisitor;
|
||||
class Group;
|
||||
class Transform;
|
||||
@@ -114,6 +121,15 @@ class OSG_EXPORT Node : public Object
|
||||
* Equivalent to dynamic_cast<const Geode*>(this).*/
|
||||
virtual const Geode* asGeode() const { return 0; }
|
||||
|
||||
/** Convert 'this' into a Transform pointer if Node is a Terrain, otherwise return 0.
|
||||
* Equivalent to dynamic_cast<Terrrain*>(this).*/
|
||||
virtual osgTerrain::Terrain* asTerrain() { return 0; }
|
||||
|
||||
/** convert 'const this' into a const Terrain pointer if Node is a Terrain, otherwise return 0.
|
||||
* Equivalent to dynamic_cast<const Terrain*>(this).*/
|
||||
virtual const osgTerrain::Terrain* asTerrain() const { return 0; }
|
||||
|
||||
|
||||
/** Visitor Pattern : calls the apply method of a NodeVisitor with this node's type.*/
|
||||
virtual void accept(NodeVisitor& nv);
|
||||
/** Traverse upwards : calls parents' accept method with NodeVisitor.*/
|
||||
|
||||
@@ -280,7 +280,7 @@ class OSG_EXPORT NodeVisitor : public virtual Referenced
|
||||
DatabaseRequestHandler():
|
||||
Referenced(true) {}
|
||||
|
||||
virtual void requestNodeFile(const std::string& fileName,osg::Group* group, float priority, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& databaseRequest, const osg::Referenced* options=0) = 0;
|
||||
virtual void requestNodeFile(const std::string& fileName, osg::NodePath& nodePath, float priority, const FrameStamp* framestamp, osg::ref_ptr<osg::Referenced>& databaseRequest, const osg::Referenced* options=0) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~DatabaseRequestHandler() {}
|
||||
|
||||
@@ -70,7 +70,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
|
||||
|
||||
/** Add a request to load a node file to end the the database request list.*/
|
||||
virtual void requestNodeFile(const std::string& fileName,osg::Group* group,
|
||||
virtual void requestNodeFile(const std::string& fileName, osg::NodePath& nodePath,
|
||||
float priority, const osg::FrameStamp* framestamp,
|
||||
osg::ref_ptr<osg::Referenced>& databaseRequest,
|
||||
const osg::Referenced* options);
|
||||
@@ -316,9 +316,12 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
|
||||
double _timestampLastRequest;
|
||||
float _priorityLastRequest;
|
||||
unsigned int _numOfRequests;
|
||||
osg::ObserverNodePath _observerNodePath;
|
||||
osg::ref_ptr<osg::Node> _loadedModel;
|
||||
osg::ref_ptr<Options> _loadOptions;
|
||||
|
||||
osg::observer_ptr<osg::Node> _terrain;
|
||||
osg::observer_ptr<osg::Group> _group;
|
||||
|
||||
osg::ref_ptr<osg::Node> _loadedModel;
|
||||
osg::ref_ptr<Options> _loadOptions;
|
||||
|
||||
osg::observer_ptr<osgUtil::IncrementalCompileOperation::CompileSet> _compileSet;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <osg/PrimitiveSet>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/StreamOperator>
|
||||
#include <osgDB/Options>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define OSGDB_OPTIONS 1
|
||||
|
||||
#include <osgDB/Callbacks>
|
||||
#include <osg/ObserverNodePath>
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
@@ -227,7 +228,6 @@ class OSGDB_EXPORT Options : public osg::Object
|
||||
/** Get the callback to use inform the DatabasePager whether a file is located on local or remote file system.*/
|
||||
FileLocationCallback* getFileLocationCallback() const { return _fileLocationCallback.get(); }
|
||||
|
||||
|
||||
/** Set the FileCache that is used to manage local storage of files downloaded from the internet.*/
|
||||
void setFileCache(FileCache* fileCache) { _fileCache = fileCache; }
|
||||
|
||||
@@ -235,6 +235,13 @@ class OSGDB_EXPORT Options : public osg::Object
|
||||
FileCache* getFileCache() const { return _fileCache.get(); }
|
||||
|
||||
|
||||
/** Set the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
|
||||
void setTerrain(osg::observer_ptr<osg::Node>& terrain) { _terrain = terrain; }
|
||||
|
||||
/** Get the terrain observer_ptr, use to decorate any osgTerrain subgraphs.*/
|
||||
const osg::observer_ptr<osg::Node>& getTerrain() const { return _terrain; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Options() {}
|
||||
@@ -257,6 +264,8 @@ class OSGDB_EXPORT Options : public osg::Object
|
||||
osg::ref_ptr<FileLocationCallback> _fileLocationCallback;
|
||||
|
||||
osg::ref_ptr<FileCache> _fileCache;
|
||||
|
||||
osg::observer_ptr<osg::Node> _terrain;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,11 @@ class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode
|
||||
META_Node(osgTerrain, Terrain);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
virtual osgTerrain::Terrain* asTerrain() { return this; }
|
||||
virtual const osgTerrain::Terrain* asTerrain() const { return this; }
|
||||
|
||||
|
||||
/** Set the sample ratio hint that TerrainTile should use when building geometry.
|
||||
* Defaults to 1.0, which means use all original sample points.*/
|
||||
void setSampleRatio(float ratio);
|
||||
|
||||
Reference in New Issue
Block a user