Show
Ignore:
Timestamp:
12/09/10 13:16:11 (3 years ago)
Author:
robert
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgterrain/osgterrain.cpp

    r11306 r11992  
    191191 
    192192    // load the nodes from the commandline arguments. 
    193     osg::Node* rootnode = osgDB::readNodeFiles(arguments); 
     193    osg::ref_ptr<osg::Node> rootnode = osgDB::readNodeFiles(arguments); 
    194194 
    195195    if (!rootnode) 
     
    199199    } 
    200200 
    201     osgTerrain::Terrain* terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode); 
     201    osg::ref_ptr<osgTerrain::Terrain> terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode); 
    202202    if (!terrain) 
    203203    { 
     204        // no Terrain node present insert one above the loaded model. 
    204205        terrain = new osgTerrain::Terrain; 
    205         terrain->addChild(rootnode); 
    206  
    207         rootnode = terrain; 
     206 
     207        // if CoordinateSystemNode is present copy it's contents into the Terrain, and discard it. 
     208        osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode);; 
     209        if (csn) 
     210        { 
     211            terrain->set(*csn); 
     212            for(unsigned int i=0; i<csn->getNumChildren();++i) 
     213            { 
     214                terrain->addChild(csn->getChild(i)); 
     215            } 
     216        } 
     217        else 
     218        { 
     219            terrain->addChild(rootnode.get()); 
     220        } 
     221 
     222        rootnode = terrain.get(); 
    208223    } 
    209224 
     
    216231 
    217232    // add a viewport to the viewer and attach the scene graph. 
    218     viewer.setSceneData( rootnode ); 
     233    viewer.setSceneData( rootnode.get() ); 
    219234 
    220235