| 192 | | // load the nodes from the commandline arguments. |
| 193 | | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
| 194 | | |
| 195 | | if (!rootnode) |
| 196 | | { |
| 197 | | osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
| 198 | | return 1; |
| 199 | | } |
| 200 | | |
| 201 | | osgTerrain::Terrain* terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode); |
| 202 | | if (!terrain) |
| 203 | | { |
| 204 | | terrain = new osgTerrain::Terrain; |
| 205 | | terrain->addChild(rootnode); |
| 206 | | |
| 207 | | rootnode = terrain; |
| 208 | | } |
| 209 | | |
| 210 | | osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode); |
| 211 | | |
| 212 | | unsigned int numLayers = 1; |
| 213 | | osgFX::MultiTextureControl* mtc = findTopMostNodeOfType<osgFX::MultiTextureControl>(rootnode); |
| 214 | | if (mtc) |
| 215 | | { |
| 216 | | numLayers = mtc->getNumTextureWeights(); |
| 217 | | } |
| 218 | | |
| 219 | | if (numLayers<2) |
| 220 | | { |
| 221 | | osg::notify(osg::NOTICE)<<"Warning: scene must have MultiTextureControl node with at least 2 texture units defined."<<std::endl; |
| 222 | | return 1; |
| 223 | | } |
| 224 | | |
| 225 | | double maxElevationTransition = 1e6; |
| 226 | | ElevationLayerBlendingCallback::Elevations elevations; |
| 227 | | for(unsigned int i=0; i<numLayers; ++i) |
| 228 | | { |
| 229 | | elevations.push_back(maxElevationTransition); |
| 230 | | maxElevationTransition /= 2.0; |
| 231 | | } |
| 232 | | |
| 233 | | ElevationLayerBlendingCallback* elbc = new ElevationLayerBlendingCallback(mtc, elevations); |
| 234 | | |
| 235 | | // assign to the most appropriate node (the CoordinateSystemNode is best as it provides the elevation on the globe.) |
| 236 | | if (csn) csn->setCullCallback(elbc); |
| 237 | | else if (mtc) mtc->setCullCallback(elbc); |
| 238 | | else rootnode->setCullCallback(elbc); |
| 292 | | // add a viewport to the viewer and attach the scene graph. |
| 293 | | viewer.setSceneData( rootnode ); |
| | 246 | // set up the scene graph |
| | 247 | { |
| | 248 | // load the nodes from the commandline arguments. |
| | 249 | osg::Node* rootnode = osgDB::readNodeFiles(arguments); |
| | 250 | |
| | 251 | if (!rootnode) |
| | 252 | { |
| | 253 | osg::notify(osg::NOTICE)<<"Warning: no valid data loaded, please specify a database on the command line."<<std::endl; |
| | 254 | return 1; |
| | 255 | } |
| | 256 | |
| | 257 | osgTerrain::Terrain* terrain = findTopMostNodeOfType<osgTerrain::Terrain>(rootnode); |
| | 258 | if (!terrain) |
| | 259 | { |
| | 260 | terrain = new osgTerrain::Terrain; |
| | 261 | terrain->addChild(rootnode); |
| | 262 | |
| | 263 | rootnode = terrain; |
| | 264 | } |
| | 265 | |
| | 266 | osg::CoordinateSystemNode* csn = findTopMostNodeOfType<osg::CoordinateSystemNode>(rootnode); |
| | 267 | |
| | 268 | unsigned int numLayers = 1; |
| | 269 | osgFX::MultiTextureControl* mtc = findTopMostNodeOfType<osgFX::MultiTextureControl>(rootnode); |
| | 270 | if (mtc) |
| | 271 | { |
| | 272 | numLayers = mtc->getNumTextureWeights(); |
| | 273 | } |
| | 274 | |
| | 275 | if (numLayers<2) |
| | 276 | { |
| | 277 | osg::notify(osg::NOTICE)<<"Warning: scene must have MultiTextureControl node with at least 2 texture units defined."<<std::endl; |
| | 278 | return 1; |
| | 279 | } |
| | 280 | |
| | 281 | double maxElevationTransition = 1e6; |
| | 282 | ElevationLayerBlendingCallback::Elevations elevations; |
| | 283 | for(unsigned int i=0; i<numLayers; ++i) |
| | 284 | { |
| | 285 | elevations.push_back(maxElevationTransition); |
| | 286 | maxElevationTransition /= 2.0; |
| | 287 | } |
| | 288 | |
| | 289 | ElevationLayerBlendingCallback* elbc = new ElevationLayerBlendingCallback(mtc, elevations); |
| | 290 | |
| | 291 | // assign to the most appropriate node (the CoordinateSystemNode is best as it provides the elevation on the globe.) |
| | 292 | if (csn) csn->setCullCallback(elbc); |
| | 293 | else if (mtc) mtc->setCullCallback(elbc); |
| | 294 | else rootnode->setCullCallback(elbc); |
| | 295 | |
| | 296 | // add a viewport to the viewer and attach the scene graph. |
| | 297 | viewer.setSceneData( rootnode ); |
| | 298 | } |