[365] | 1 | #include "ReaderWriterDist.h" |
---|
| 2 | #include <osg/KdTree> |
---|
| 3 | |
---|
| 4 | ReaderWriterDist::ReaderWriterDist() |
---|
| 5 | { |
---|
| 6 | supportsExtension( "dist", "distortion set loader"); |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | extensionToAdd = ".dist"; |
---|
| 10 | } |
---|
| 11 | |
---|
| 12 | ReaderWriterDist::ReadResult ReaderWriterDist::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const |
---|
| 13 | { |
---|
| 14 | // Check if its a valid file for this pseudo loader |
---|
| 15 | std::string ext = osgDB::getLowerCaseFileExtension( file ); |
---|
| 16 | if( !acceptsExtension(ext) ) |
---|
| 17 | return ReadResult::FILE_NOT_HANDLED; |
---|
| 18 | |
---|
| 19 | // Strip the pseudo-loader extension |
---|
| 20 | std::string realName = osgDB::getNameLessExtension( file ); |
---|
| 21 | |
---|
| 22 | // check if stripped file exists |
---|
| 23 | std::string fileName = osgDB::findDataFile( realName, options ); |
---|
| 24 | if( fileName.empty() ) |
---|
| 25 | return ReadResult::FILE_NOT_FOUND; |
---|
| 26 | |
---|
| 27 | // If options are available: Save it'S original KdTree Hint. |
---|
| 28 | Options::BuildKdTreesHint originalHint = Options::NO_PREFERENCE; |
---|
| 29 | if(options) |
---|
| 30 | { |
---|
| 31 | originalHint = options->getBuildKdTreesHint(); |
---|
| 32 | const_cast<osgDB::ReaderWriter::Options*>(options)->setBuildKdTreesHint(Options::DO_NOT_BUILD_KDTREES); |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | // Load real file |
---|
| 36 | osg::Node *node = osgDB::readNodeFile( fileName, options ); |
---|
| 37 | if( !node ) |
---|
| 38 | { |
---|
| 39 | // propagate the read failure upwards |
---|
| 40 | OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl; |
---|
| 41 | return ReadResult::FILE_NOT_HANDLED; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | return node; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | // Add ourself to the Registry to instantiate the reader/writer. |
---|
| 48 | REGISTER_OSGPLUGIN(dist, ReaderWriterDist) |
---|