Rearranged the traversal and initialization of TerrainTechnique
This commit is contained in:
@@ -131,7 +131,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if (!terrain) return 0;
|
||||
|
||||
return 0;
|
||||
// return 0;
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData(terrain.get());
|
||||
|
||||
@@ -30,16 +30,15 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
GeometryTechnique(const GeometryTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual void initialize();
|
||||
virtual void init();
|
||||
|
||||
virtual void update(osgUtil::UpdateVisitor* nv);
|
||||
|
||||
virtual void cull(osgUtil::CullVisitor* nv);
|
||||
|
||||
virtual void cleanSceneGraph() {}
|
||||
virtual void cleanSceneGraph();
|
||||
|
||||
/** Dirty so that cached data structurese are updated.*/
|
||||
virtual void dirty() { _dirty = true; }
|
||||
virtual void dirty();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -47,7 +46,6 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
|
||||
|
||||
osg::ref_ptr<osg::Geode> _geode;
|
||||
osg::ref_ptr<osg::Geometry> _geometry;
|
||||
bool _dirty;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
|
||||
TerrainNode* getTerrainNode() { return _terrainNode; }
|
||||
const TerrainNode* getTerrainNode() const { return _terrainNode; }
|
||||
|
||||
virtual void initialize();
|
||||
virtual void init();
|
||||
|
||||
virtual void update(osgUtil::UpdateVisitor* nv);
|
||||
|
||||
@@ -48,6 +48,9 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
|
||||
/** Clean scene graph from any terrain technique specific nodes.*/
|
||||
virtual void cleanSceneGraph();
|
||||
|
||||
/** Traverse the terain subgraph.*/
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
/** Dirty so that cached data structurese are updated.*/
|
||||
virtual void dirty();
|
||||
|
||||
@@ -57,7 +60,8 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
|
||||
|
||||
friend class osgTerrain::TerrainNode;
|
||||
|
||||
TerrainNode* _terrainNode;
|
||||
TerrainNode* _terrainNode;
|
||||
bool _dirty;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -28,14 +28,15 @@ GeometryTechnique::~GeometryTechnique()
|
||||
{
|
||||
}
|
||||
|
||||
void GeometryTechnique::initialize()
|
||||
void GeometryTechnique::init()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Doing initalize"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<"Doing init()"<<std::endl;
|
||||
|
||||
_geode = new osg::Geode;
|
||||
_geometry = new osg::Geometry;
|
||||
_geode->addDrawable(_geometry.get());
|
||||
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,3 +55,13 @@ void GeometryTechnique::cull(osgUtil::CullVisitor* nv)
|
||||
_geode->accept(*nv);
|
||||
}
|
||||
}
|
||||
|
||||
void GeometryTechnique::cleanSceneGraph()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Cleaning scene graph"<<std::endl;
|
||||
}
|
||||
|
||||
void GeometryTechnique::dirty()
|
||||
{
|
||||
TerrainTechnique::dirty();
|
||||
}
|
||||
|
||||
@@ -38,29 +38,14 @@ TerrainNode::~TerrainNode()
|
||||
|
||||
void TerrainNode::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
// if app traversal update the frame count.
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||
if (_terrainTechnique.valid())
|
||||
{
|
||||
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
|
||||
if (getTerrainTechnique() && uv)
|
||||
{
|
||||
getTerrainTechnique()->update(uv);
|
||||
return;
|
||||
}
|
||||
|
||||
_terrainTechnique->traverse(nv);
|
||||
}
|
||||
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
||||
else
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
||||
if (getTerrainTechnique() && cv)
|
||||
{
|
||||
getTerrainTechnique()->cull(cv);
|
||||
return;
|
||||
}
|
||||
osg::Group::traverse(nv);
|
||||
}
|
||||
|
||||
// otherwise fallback to the Group::traverse()
|
||||
Group::traverse(nv);
|
||||
}
|
||||
|
||||
void TerrainNode::setTerrainTechnique(osgTerrain::TerrainTechnique* terrainTechnique)
|
||||
|
||||
@@ -12,17 +12,20 @@
|
||||
*/
|
||||
|
||||
#include <osgTerrain/TerrainTechnique>
|
||||
#include <osgTerrain/TerrainNode>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
TerrainTechnique::TerrainTechnique():
|
||||
_terrainNode(0)
|
||||
_terrainNode(0),
|
||||
_dirty(true)
|
||||
{
|
||||
}
|
||||
|
||||
TerrainTechnique::TerrainTechnique(const TerrainTechnique& TerrainTechnique,const osg::CopyOp& copyop):
|
||||
osg::Object(TerrainTechnique,copyop),
|
||||
_terrainNode(0)
|
||||
_terrainNode(0),
|
||||
_dirty(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,9 +33,11 @@ TerrainTechnique::~TerrainTechnique()
|
||||
{
|
||||
}
|
||||
|
||||
void TerrainTechnique::initialize()
|
||||
void TerrainTechnique::init()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<className()<<"::initialize(..) not implementated yet"<<std::endl;
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
void TerrainTechnique::update(osgUtil::UpdateVisitor*)
|
||||
@@ -52,5 +57,37 @@ void TerrainTechnique::cleanSceneGraph()
|
||||
|
||||
void TerrainTechnique::dirty()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<className()<<"::dirty(..) not implementated yet"<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<className()<<"::dirty(..) not implementated yet"<<std::endl;
|
||||
_dirty = true;
|
||||
}
|
||||
|
||||
void TerrainTechnique::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
if (!_terrainNode) return;
|
||||
|
||||
// if app traversal update the frame count.
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
if (_dirty) init();
|
||||
|
||||
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
|
||||
if (uv)
|
||||
{
|
||||
update(uv);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
||||
if (cv)
|
||||
{
|
||||
cull(cv);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise fallback to the Group::traverse()
|
||||
_terrainNode->osg::Group::traverse(nv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user