diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index 47ab6ef3f..9cdcd87e5 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -49,21 +49,25 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::local_readNode(const std::strin txpNode->setOptions(options->getOptionString()); } - if (txpNode->loadArchive()) - { - TXPArchive* archive = txpNode->getArchive(); - if (archive) - { - if (options && options->getOptionString().find("loadMaterialsToStateSet")!=std::string::npos) - { - archive->SetMaterialAttributesToStateSetVar(true); - } - int id = _archiveId++; - archive->setId(id); -// txpNode->setArchive(getArchive(id,osgDB::getFilePath(fileName))); - getArchive(id,osgDB::getFilePath(fileName)); + //modified by Brad Anderegg on May-27-08 + //calling getArchive will create a new TXPArchive if the specified one does not exist + //we will set our osgdb loader options on the archive and set the appropriate archive on + //the txpNode. + int id = ++_archiveId; + TXPArchive* archive = getArchive(id,osgDB::getFilePath(fileName)); + + if (archive != NULL) + { + archive->setId(id); + + if (options && options->getOptionString().find("loadMaterialsToStateSet")!=std::string::npos) + { + archive->SetMaterialAttributesToStateSetVar(true); } + + txpNode->loadArchive(archive); + return txpNode.get(); } else diff --git a/src/osgPlugins/txp/TXPIO.cpp b/src/osgPlugins/txp/TXPIO.cpp index e32d52e5d..3e7988dd2 100644 --- a/src/osgPlugins/txp/TXPIO.cpp +++ b/src/osgPlugins/txp/TXPIO.cpp @@ -36,7 +36,11 @@ bool TXPNode_readLocalData(osg::Object &obj, osgDB::Input &fr) if (fr.matchSequence("databaseName %s")) { txpNode.setArchiveName(fr[1].getStr()); - txpNode.loadArchive(); + + //modified by Brad Anderegg on May-27-08 + //this function now takes the archive to load as a parameter + //passing in NULL will have the same effect as before. + txpNode.loadArchive(NULL); fr += 2; itrAdvanced = true; @@ -49,8 +53,8 @@ bool TXPNode_readLocalData(osg::Object &obj, osgDB::Input &fr) class Dump2Osg : public osg::NodeVisitor { public: - Dump2Osg( osgDB::Output &fw ) : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ), _fw( fw ) - {} + Dump2Osg( osgDB::Output &fw ) : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ), _fw( fw ) + {} virtual void apply(osg::Node& node) { @@ -65,10 +69,10 @@ bool TXPNode_writeLocalData(const osg::Object &obj, osgDB::Output &fw) { const txp::TXPNode &txpNode = static_cast(obj); - if ( !txpNode.getOptions().empty() ) - fw.indent() << "databaseOptions \"" << txpNode.getOptions() << "\"" << std::endl; - if ( !txpNode.getArchiveName().empty() ) - fw.indent() << "databaseName \"" << txpNode.getArchiveName() << "\"" << std::endl; + if ( !txpNode.getOptions().empty() ) + fw.indent() << "databaseOptions \"" << txpNode.getOptions() << "\"" << std::endl; + if ( !txpNode.getArchiveName().empty() ) + fw.indent() << "databaseName \"" << txpNode.getArchiveName() << "\"" << std::endl; osg::Group* grp = const_cast(txpNode.asGroup()); diff --git a/src/osgPlugins/txp/TXPNode.cpp b/src/osgPlugins/txp/TXPNode.cpp index 0f458c50f..a80e70b9e 100644 --- a/src/osgPlugins/txp/TXPNode.cpp +++ b/src/osgPlugins/txp/TXPNode.cpp @@ -26,7 +26,7 @@ class RetestCallback : public osg::NodeCallback public: RetestCallback() { - timer = osg::Timer::instance(); // get static timer + timer = osg::Timer::instance(); // get static timer prevTime = 0; // should this be instantiated with current time? } @@ -38,7 +38,7 @@ public: (n = (osg::Group *) pLOD->getChild(0)) && (n->getNumChildren() == 0)) { - osg::Timer_t curTime = timer->tick(); + osg::Timer_t curTime = timer->tick(); if ((prevTime + 2.0/timer->getSecondsPerTick() ) < curTime) { prevTime = curTime; @@ -64,7 +64,7 @@ _originX(0.0), _originY(0.0) { setNumChildrenRequiringUpdateTraversal(1); - setCullingActive(false); + setCullingActive(false); } TXPNode::TXPNode(const TXPNode& txpNode,const osg::CopyOp& copyop): @@ -179,40 +179,32 @@ const std::string& TXPNode::getArchiveName() const return _archiveName; } -bool TXPNode::loadArchive() +bool TXPNode::loadArchive(TXPArchive* archive) { - if (_archive.get()) - { - TXPNodeERROR("loadArchive()") << "archive already open" << std::endl; - return false; - } + //if (_archive.get()) + //{ + // TXPNodeERROR("loadArchive()") << "archive already open" << std::endl; + // return false; + //} - _archive = new TXPArchive; - if (_archive->openFile(_archiveName) == false) - { - TXPNodeERROR("loadArchive()") << "failed to load archive: \"" << _archiveName << "\"" << std::endl; - return false; - } - /* - if (_archive->loadMaterials() == false) - { - TXPNodeERROR("loadArchive()") << "failed to load materials from archive: \"" << _archiveName << "\"" << std::endl; - return false; - } - - if (_archive->loadModels() == false) - { - TXPNodeERROR("loadArchive()") << "failed to load models from archive: \"" << _archiveName << "\"" << std::endl; - return false; - } - - if (_archive->loadLightAttributes() == false) - { - TXPNodeERROR("loadArchive()") << "failed to load light attributes from archive: \"" << _archiveName << "\"" << std::endl; - return false; - } - */ + //modified by Brad Anderegg on May-27-08 + //if NULL is passed in we will create a new archive and open the database + //otherwise we will use the archive provided which should have already been loaded + //by ReaderWriterTXP::getArchive(). See line 57-77 of ReaderWriterTXP.cpp. + if(archive == NULL) + { + _archive = new TXPArchive; + if (_archive->openFile(_archiveName) == false) + { + TXPNodeERROR("loadArchive()") << "failed to load archive: \"" << _archiveName << "\"" << std::endl; + return false; + } + } + else + { + _archive = archive; + } _archive->getOrigin(_originX,_originY); _archive->getExtents(_extents); diff --git a/src/osgPlugins/txp/TXPNode.h b/src/osgPlugins/txp/TXPNode.h index 322f4b00a..ba73a65f8 100644 --- a/src/osgPlugins/txp/TXPNode.h +++ b/src/osgPlugins/txp/TXPNode.h @@ -65,14 +65,18 @@ public: const std::string& getOptions() const; const std::string& getArchiveName() const; - bool loadArchive(); + //modified by Brad Anderegg on May-27-08 + //because the TXPArchives are kept in an std::map and referenced later + //we do not want to create a new one, so we pass it in. + //If NULL is passed into loadArchive it will do the same thing it used to. + bool loadArchive(TXPArchive*); TXPArchive* getArchive(); - void setArchive( TXPArchive* archive ) - { - _archive = archive; - } + void setArchive( TXPArchive* archive ) + { + _archive = archive; + } virtual osg::BoundingSphere computeBound() const; @@ -86,18 +90,18 @@ protected: // Create a page lod for lod 0 with givin grid location (x,y) osg::Node* addPagedLODTile(int x, int y); - std::string _archiveName; - std::string _options; + std::string _archiveName; + std::string _options; - osg::ref_ptr _archive; - osg::ref_ptr _pageManager; + osg::ref_ptr _archive; + osg::ref_ptr _pageManager; - double _originX; - double _originY; - osg::BoundingBox _extents; + double _originX; + double _originY; + osg::BoundingBox _extents; - std::vector _nodesToAdd; - std::vector _nodesToRemove; + std::vector _nodesToAdd; + std::vector _nodesToRemove; }; diff --git a/src/osgPlugins/txp/TXPPagedLOD.cpp b/src/osgPlugins/txp/TXPPagedLOD.cpp index dd0bb7297..e126ab79d 100644 --- a/src/osgPlugins/txp/TXPPagedLOD.cpp +++ b/src/osgPlugins/txp/TXPPagedLOD.cpp @@ -24,7 +24,9 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) { TileMapper* tileMapper = dynamic_cast(nv.getUserData()); - bool forceUseOfFirstChild = tileMapper ? (tileMapper->isNodeBlackListed(this)) : false; + //Modified by Brad Anderegg (May-27-08) because the black listing process appears to make tiles switch lods + //when they clearly shouldnt, in the worst cases a tile will page out that is right in front of you. + bool forceUseOfFirstChild = /*tileMapper ? (tileMapper->isNodeBlackListed(this)) :*/ false; double timeStamp = nv.getFrameStamp()?nv.getFrameStamp()->getReferenceTime():0.0; bool updateTimeStamp = nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR; @@ -40,19 +42,19 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) int lastChildTraversed = -1; bool needToLoadChild = false; - + unsigned maxRangeSize = _rangeList.size(); if (maxRangeSize!=0 && forceUseOfFirstChild) - maxRangeSize=1; - + maxRangeSize=1; + for(unsigned int i=0;iaccept(nv); lastChildTraversed = (int)i; @@ -63,38 +65,43 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) } } } - + if (needToLoadChild) { unsigned int numChildren = _children.size(); - + //std::cout<<"PagedLOD::traverse() - falling back "<0 && ((int)numChildren-1)!=lastChildTraversed) { //std::cout<<" to child "<accept(nv); } - + // now request the loading of the next unload child. if (nv.getDatabaseRequestHandler() && numChildren<_perRangeDataList.size()) { // compute priority from where abouts in the required range the distance falls. float priority = (_rangeList[numChildren].second-distance)/(_rangeList[numChildren].second-_rangeList[numChildren].first); - + // modify the priority according to the child's priority offset and scale. priority = _perRangeDataList[numChildren]._priorityOffset + priority * _perRangeDataList[numChildren]._priorityScale; //std::cout<<" requesting child "<<_fileNameList[numChildren]<<" priotity = "<requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp(),_perRangeDataList[numChildren]._databaseRequest); + nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename, + this, + priority, + nv.getFrameStamp(), + _perRangeDataList[numChildren]._databaseRequest); } - - + + } - - + + break; } default: @@ -109,10 +116,10 @@ osg::BoundingSphere TXPPagedLOD::computeBound() const // If this is not done, then externally referenced models will disappear // when the tile they are attached to leaves the view volume. osg::BoundingSphere result = osg::Group::computeBound(); - + if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f) { - float tempRadius = osg::maximum( _radius, result.radius() ); + float tempRadius = osg::maximum( _radius, result.radius() ); result = osg::BoundingSphere(_userDefinedCenter,tempRadius); } return result; diff --git a/src/osgPlugins/txp/TXPParser.cpp b/src/osgPlugins/txp/TXPParser.cpp index 1e58b3509..19ed0ce36 100644 --- a/src/osgPlugins/txp/TXPParser.cpp +++ b/src/osgPlugins/txp/TXPParser.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include "TXPParser.h" #include "TXPArchive.h" @@ -150,8 +152,22 @@ osg::Group *TXPParser::parseScene( } _tileGroups.clear(); - LayerVisitor lv; - _root->accept(lv); + try + { + LayerVisitor lv; + _root->accept(lv); + + //modified by Brad Anderegg May-27-08 + //running the optimizer on the terrain fixes some major preformance issues, unfortunately the texture atlas builder seems to get messed up + //on some of the textures (usually around buildings) and the tri stripper seems to occasionally crash and also mess up the indices on certain buildings. + osgUtil::Optimizer opt; + opt.optimize(_root.get(), (osgUtil::Optimizer::ALL_OPTIMIZATIONS ^ osgUtil::Optimizer::TEXTURE_ATLAS_BUILDER) ^ osgUtil::Optimizer::TRISTRIP_GEOMETRY); + } + catch (...) + { + osg::notify(osg::NOTICE) << "txp::TXPParser::parseScene(): exception thrown in the osg::Optimizer" << std::endl; + } + return _root.get(); } @@ -1433,10 +1449,11 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) if (geometry.valid() && top) { - // added this set use display list off since terrapage will - // be creating and deleting these geometry leaves on the fly - // so we don't want to be creating short lived display lists either. - geometry->setUseDisplayList(false); + + //modifed by Brad Anderegg on May-27-08 + //using display lists actually increases our framerate by + //a fair amount, on certain laptops it increased by as much as 1000% + geometry->setUseDisplayList(true); geometry->setVertexArray(vertices.get()); if (normals.valid())