source: experimental/TerrainTest/ReaderWriterTerrainMod.cpp @ 260

Last change on this file since 260 was 255, checked in by Torben Dannhauer, 14 years ago
File size: 1.5 KB
RevLine 
[250]1#include "ReaderWriterTerrainMod.h"
2
3ReaderWriterTerrainMod::ReaderWriterTerrainMod()
4{
5        supportsExtension( "terrainmod", "Terrain modification pseudo loader");
[252]6
[253]7        extensionToAdd = ".terrainmod";
[250]8}
9
10ReaderWriterTerrainMod::ReadResult ReaderWriterTerrainMod::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const
11{
[252]12        // Check if its a valid file for this pseudo loader
[250]13        std::string ext = osgDB::getLowerCaseFileExtension( file );
14        if( !acceptsExtension(ext) )
15                return ReadResult::FILE_NOT_HANDLED;
16
[252]17        // Strip the pseudo-loader extension
18    std::string realName = osgDB::getNameLessExtension( file );
19
20        // check if stripped file exists
21        std::string fileName = osgDB::findDataFile( realName, options );
[250]22        if( fileName.empty() )
23                return ReadResult::FILE_NOT_FOUND;
24
25        // Load real file
[252]26        osg::Node *node = osgDB::readNodeFile( fileName, options );
[250]27    if( !node )
28    {
29        // propagate the read failure upwards
[252]30        OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl;
[250]31        return ReadResult::FILE_NOT_HANDLED;
32    }
33
[251]34        // Traverse through loaded graph, check for PagedLOD and modify all filenames of external references
[253]35        // This ensures ensures that higher LODs are loaded via terrainmod pseudo loader as well.
[252]36        ModificationVisitor modVisitor(extensionToAdd);
[251]37        node->accept( modVisitor );
38
[250]39        return node;
40}
41
42// Add ourself to the Registry to instantiate the reader/writer.
43REGISTER_OSGPLUGIN(terrainmod, ReaderWriterTerrainMod)
Note: See TracBrowser for help on using the repository browser.