Changeset 252 for experimental


Ignore:
Timestamp:
Feb 21, 2011, 6:35:43 PM (14 years ago)
Author:
Torben Dannhauer
Message:

Pseudoloader works!

Next step: learn how to perform mdifications in the pseudoloader.

Location:
experimental/TerrainTest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • experimental/TerrainTest/ModificationVisitor.cpp

    r251 r252  
    11#include "ModificationVisitor.h"
    22
    3 ModificationVisitor::ModificationVisitor()
     3ModificationVisitor::ModificationVisitor(std::string extensionToSet) : _extensionToSet(extensionToSet)
    44{
    55        setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
     
    88void ModificationVisitor::apply( osg::Node& node )
    99{
    10         OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found" << std::endl;
     10        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: Node found: " << node.className() << std::endl;
    1111        traverse( node );
    1212}
     
    1414void ModificationVisitor::apply( osg::PagedLOD& pNode )
    1515{
    16         OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found" << std::endl;
     16        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD found: " << pNode.className() << std::endl;
     17
     18        for( unsigned int i=0;i<pNode.getNumFileNames();i++)
     19        {
     20                //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child #" << i << std::endl;
     21                if(pNode.getFileName(i)!="")
     22                {
     23                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name pre: " << pNode.getFileName(i) << std::endl;
     24                        pNode.setFileName(i, pNode.getFileName(i)+_extensionToSet );
     25                        //OSG_NOTIFY( osg::ALWAYS ) << "ModVisitor: pagedLOD Child Name post: " << newFileName << std::endl;
     26                }
     27        }
     28
    1729        traverse( pNode );
    1830}
  • experimental/TerrainTest/ModificationVisitor.h

    r251 r252  
    88{
    99public:
    10         ModificationVisitor();
     10        ModificationVisitor(std::string extensionToSet);
    1111        virtual void apply( osg::Node& node );
    1212        virtual void apply( osg::PagedLOD& pNode );
     13
     14private:
     15        std::string _extensionToSet;
    1316};
  • experimental/TerrainTest/ReaderWriterTerrainMod.cpp

    r251 r252  
    44{
    55        supportsExtension( "terrainmod", "Terrain modification pseudo loader");
     6
     7        std::string extensionToAdd = ".terrainmod";
    68}
    7 
    8 //ReaderWriterTerrainMod::~ReaderWriterTerrainMod()
    9 //{
    10 //}
    119
    1210ReaderWriterTerrainMod::ReadResult ReaderWriterTerrainMod::readNode( const std::string& file, const osgDB::ReaderWriter::Options* options) const
    1311{
     12        // Check if its a valid file for this pseudo loader
    1413        std::string ext = osgDB::getLowerCaseFileExtension( file );
    1514        if( !acceptsExtension(ext) )
    1615                return ReadResult::FILE_NOT_HANDLED;
    1716
    18         std::string fileName = osgDB::findDataFile( file, options );
     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 );
    1922        if( fileName.empty() )
    2023                return ReadResult::FILE_NOT_FOUND;
    2124
    22         // Strip the pseudo-loader extension
    23     std::string realName = osgDB::getNameLessExtension( fileName );
    24 
    2525        // Load real file
    26         osg::Node *node = osgDB::readNodeFile( realName, options );
     26        osg::Node *node = osgDB::readNodeFile( fileName, options );
    2727    if( !node )
    2828    {
    2929        // propagate the read failure upwards
    30         OSG_WARN << "Subfile \"" << realName << "\" could not be loaded" << std::endl;
     30        OSG_WARN << "Subfile \"" << fileName << "\" could not be loaded" << std::endl;
    3131        return ReadResult::FILE_NOT_HANDLED;
    3232    }
    3333
    34         // Modify Node
    35         OSG_NOTIFY( osg::ALWAYS ) << "Doing modification in pseudoloader!" << std::endl;
    36 
    3734        // Traverse through loaded graph, check for PagedLOD and modify all filenames of external references
    38         ModificationVisitor modVisitor;
     35        ModificationVisitor modVisitor(extensionToAdd);
    3936        node->accept( modVisitor );
    40 
    41         std::string extensionToAdd = ".terrainmod";
    42 
    4337
    4438        return node;
    4539}
    4640
    47 
    4841// Add ourself to the Registry to instantiate the reader/writer.
    4942REGISTER_OSGPLUGIN(terrainmod, ReaderWriterTerrainMod)
Note: See TracChangeset for help on using the changeset viewer.