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
Line 
1#include "ReaderWriterTerrainMod.h"
2
3ReaderWriterTerrainMod::ReaderWriterTerrainMod()
4{
5        supportsExtension( "terrainmod", "Terrain modification pseudo loader");
6
7        extensionToAdd = ".terrainmod";
8}
9
10ReaderWriterTerrainMod::ReadResult ReaderWriterTerrainMod::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const
11{
12        // Check if its a valid file for this pseudo loader
13        std::string ext = osgDB::getLowerCaseFileExtension( file );
14        if( !acceptsExtension(ext) )
15                return ReadResult::FILE_NOT_HANDLED;
16
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 );
22        if( fileName.empty() )
23                return ReadResult::FILE_NOT_FOUND;
24
25        // Load real file
26        osg::Node *node = osgDB::readNodeFile( fileName, options );
27    if( !node )
28    {
29        // propagate the read failure upwards
30        OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl;
31        return ReadResult::FILE_NOT_HANDLED;
32    }
33
34        // Traverse through loaded graph, check for PagedLOD and modify all filenames of external references
35        // This ensures ensures that higher LODs are loaded via terrainmod pseudo loader as well.
36        ModificationVisitor modVisitor(extensionToAdd);
37        node->accept( modVisitor );
38
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.