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