diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index c97a0510b..797652470 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -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 rootnode = osgDB::readNodeFiles(arguments); if (!rootnode) { @@ -198,13 +198,28 @@ int main(int argc, char** argv) return 1; } - osgTerrain::Terrain* terrain = findTopMostNodeOfType(rootnode); + osg::ref_ptr terrain = findTopMostNodeOfType(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(rootnode);; + if (csn) + { + terrain->set(*csn); + for(unsigned int i=0; igetNumChildren();++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