1 | #include "ReaderWriterTerrainMod.h" |
---|
2 | |
---|
3 | ReaderWriterTerrainMod::ReaderWriterTerrainMod() |
---|
4 | { |
---|
5 | supportsExtension( "terrainmod", "Terrain modification pseudo loader"); |
---|
6 | |
---|
7 | extensionToAdd = ".terrainmod"; |
---|
8 | } |
---|
9 | |
---|
10 | ReaderWriterTerrainMod::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. |
---|
43 | REGISTER_OSGPLUGIN(terrainmod, ReaderWriterTerrainMod) |
---|