Added handling of CoordinateSystemNode when they decorate a loaded model, copying the contents of the CoordinateSystemNode across to the Terrain node

This commit is contained in:
Robert Osfield
2010-12-09 12:16:11 +00:00
parent 067695bec4
commit 8707758429

View File

@@ -190,7 +190,7 @@ int main(int argc, char** argv)
}
// load the nodes from the commandline arguments.
osg::Node* rootnode = osgDB::readNodeFiles(arguments);
osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFiles(arguments);
if (!rootnode)
{
@@ -198,13 +198,28 @@ int main(int argc, char** argv)
return 1;
}
osgTerrain::Terrain* terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode);
osg::ref_ptr<osgTerrain::Terrain> terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode);
if (!terrain)
{
// no Terrain node present insert one above the loaded model.
terrain = new osgTerrain::Terrain;
terrain->addChild(rootnode);
rootnode = terrain;
// if CoordinateSystemNode is present copy it's contents into the Terrain, and discard it.
osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode);;
if (csn)
{
terrain->set(*csn);
for(unsigned int i=0; i<csn->getNumChildren();++i)
{
terrain->addChild(csn->getChild(i));
}
}
else
{
terrain->addChild(rootnode.get());
}
rootnode = terrain.get();
}
terrain->setSampleRatio(sampleRatio);
@@ -215,7 +230,7 @@ int main(int argc, char** argv)
viewer.addEventHandler(new TerrainHandler(terrain));
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData( rootnode );
viewer.setSceneData( rootnode.get() );
// run the viewers main loop