diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index 0179d274f..c5242d055 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -37,7 +37,12 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::readNode(const std::string& fil if (txpNode->loadArchive()) { TXPArchive* archive = txpNode->getArchive(); - if (archive) archive->setId(_archiveId++); + if (archive) + { + int id = _archiveId++; + archive->setId(id); + getArchive(id,osgDB::getFilePath(fileName)); + } return txpNode.get(); } else @@ -137,11 +142,14 @@ TXPArchive *ReaderWriterTXP::getArchive(int id, const std::string& dir) return NULL; } + /* + // We load the models on demand if (archive->loadModels() == false) { ReaderWriterTXPERROR("getArchive()") << "failed to load models from archive: \"" << archiveName << "\"" << std::endl; return NULL; } + */ if (archive->loadLightAttributes() == false) { diff --git a/src/osgPlugins/txp/ReaderWriterTXP.h b/src/osgPlugins/txp/ReaderWriterTXP.h index ee1f714ae..771967ec6 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.h +++ b/src/osgPlugins/txp/ReaderWriterTXP.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __READERWRITER_TXP_H_ #define __READERWRITER_TXP_H_ diff --git a/src/osgPlugins/txp/TXPArchive.cpp b/src/osgPlugins/txp/TXPArchive.cpp index 0407ce91e..2475cb33a 100644 --- a/src/osgPlugins/txp/TXPArchive.cpp +++ b/src/osgPlugins/txp/TXPArchive.cpp @@ -82,11 +82,28 @@ bool TXPArchive::openFile(const std::string& archiveName) header->GetExtents(_swExtents,_neExtents); } + /* + int numTextures; + texTable.GetNumTextures(numTextures); + _textures.resize(numTextures); + */ + + int numModel; + modelTable.GetNumModels(numModel); + _models.resize(numModel); + return true; } +bool TXPArchive::loadMaterial(int ix) +{ + return false; +} + bool TXPArchive::loadMaterials() { + osg::notify(osg::NOTICE) << "txp:: Loading materials ..." << std::endl; + trpgrImageHelper image_helper(this->GetEndian(),getDir(),materialTable,texTable); int numTextures; @@ -341,53 +358,68 @@ bool TXPArchive::loadMaterials() _gstates[i] = osg_state_set; } } + + osg::notify(osg::NOTICE) << "txp:: ... done." << std::endl; + return true; +} + +bool TXPArchive::loadModel(int ix) +{ + trpgModel *mod = modelTable.GetModelRef(ix); + int type; + mod->GetType(type); + + // Only dealing with external models currently + if (type == trpgModel::External) + { + char name[1024]; + mod->GetName(name,1023); + + // Load the model. It's probably not TerraPage + osg::Node *osg_model = osgDB::readNodeFile(name); + if (!osg_model) + { + osg::notify(osg::WARN) << "TrPageArchive::LoadModels() error: " + << "failed to load model: " + << name << std::endl; + } + // Do this even if it's NULL + _models[ix] = osg_model; + } +/* + else + { + trpgMemReadBuffer buf(GetEndian()); + mod->Read(buf); + Group *osg_model = parse->ParseScene(buf, m_gstates , m_models); + m_models.push_back(osg_model); + } +*/ return true; } bool TXPArchive::loadModels() { + osg::notify(osg::NOTICE) << "txp:: Loading models ..." << std::endl; + int numModel; modelTable.GetNumModels(numModel); + _models.resize(numModel); // Iterate over the models for (int i=0; i< numModel; i++) { - trpgModel *mod = modelTable.GetModelRef(i); - int type; - mod->GetType(type); - - // Only dealing with external models currently - if (type == trpgModel::External) - { - char name[1024]; - mod->GetName(name,1023); - - // Load the model. It's probably not TerraPage - osg::Node *osg_model = osgDB::readNodeFile(name); - if (!osg_model) - { - osg::notify(osg::WARN) << "TrPageArchive::LoadModels() error: " - << "failed to load model: " - << name << std::endl; - } - // Do this even if it's NULL - _models.push_back(osg_model); - } - /* - else - { - trpgMemReadBuffer buf(GetEndian()); - mod->Read(buf); - Group *osg_model = parse->ParseScene(buf, m_gstates , m_models); - m_models.push_back(osg_model); - } - */ + loadModel(i); } + + osg::notify(osg::NOTICE) << "txp:: ... done." << std::endl; return true; } bool TXPArchive::loadLightAttributes() { + osg::notify(osg::NOTICE) << "txp:: Loading light attributes ..." << std::endl; + int num; lightTable.GetNumLightAttrs(num); for ( int attr_num = 0; attr_num < num; attr_num++ ) @@ -484,6 +516,8 @@ bool TXPArchive::loadLightAttributes() addLightAttribute(osgLight, stateSet, osg::Vec3(normal.x,normal.y,normal.z)); } + + osg::notify(osg::NOTICE) << "txp:: ... done." << std::endl; return true; } @@ -557,7 +591,7 @@ osg::Group* TXPArchive::getTileContent(int x, int y, int lod) trpgMemReadBuffer buf(GetEndian()); if (!ReadTile(x,y,lod,buf)) { - return new osg::Group; + return new osg::Group; } osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models); diff --git a/src/osgPlugins/txp/TXPArchive.h b/src/osgPlugins/txp/TXPArchive.h index 4ebca3e0c..c85741fc8 100644 --- a/src/osgPlugins/txp/TXPArchive.h +++ b/src/osgPlugins/txp/TXPArchive.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __TXPARCHIVE_H_ #define __TXPARCHIVE_H_ @@ -35,9 +68,11 @@ namespace txp // Load the materials from the archve bool loadMaterials(); + bool loadMaterial(int ix); // Load the models from the archive bool loadModels(); + bool loadModel(int ix); // Load the light attribs from the archive bool loadLightAttributes(); @@ -79,7 +114,7 @@ namespace txp osg::Group* getTileContent(int x, int y, int lod); - + protected: diff --git a/src/osgPlugins/txp/TXPNode.cpp b/src/osgPlugins/txp/TXPNode.cpp index 808e9c8f8..f31f94fe2 100644 --- a/src/osgPlugins/txp/TXPNode.cpp +++ b/src/osgPlugins/txp/TXPNode.cpp @@ -103,7 +103,7 @@ bool TXPNode::loadArchive() return false; } - /* + /* if (_archive->loadMaterials() == false) { TXPNodeERROR("loadArchive()") << "failed to load materials from archive: \"" << _archiveName << "\"" << std::endl; @@ -121,7 +121,7 @@ bool TXPNode::loadArchive() TXPNodeERROR("loadArchive()") << "failed to load light attributes from archive: \"" << _archiveName << "\"" << std::endl; return false; } - */ + */ _archive->getOrigin(_originX,_originY); _archive->getExtents(_extents); diff --git a/src/osgPlugins/txp/TXPNode.h b/src/osgPlugins/txp/TXPNode.h index fe8dda3fc..00547ced3 100644 --- a/src/osgPlugins/txp/TXPNode.h +++ b/src/osgPlugins/txp/TXPNode.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __TXPNODE_H_ #define __TXPNODE_H_ diff --git a/src/osgPlugins/txp/TXPPageManager.h b/src/osgPlugins/txp/TXPPageManager.h index 3f89307a7..cc4d3a47e 100644 --- a/src/osgPlugins/txp/TXPPageManager.h +++ b/src/osgPlugins/txp/TXPPageManager.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __TXPPAGEMANAGER_H_ #define __TXPPAGEMANAGER_H_ diff --git a/src/osgPlugins/txp/TXPParser.cpp b/src/osgPlugins/txp/TXPParser.cpp index ac01a2be0..b211d9062 100644 --- a/src/osgPlugins/txp/TXPParser.cpp +++ b/src/osgPlugins/txp/TXPParser.cpp @@ -17,11 +17,14 @@ #include #include #include +#include #include "TXPParser.h" #include "TXPArchive.h" using namespace txp; +static osg::ApplicationUsageProxy TXP_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_TXP_DEFAULT_MAX_ANISOTROPY \" []\"","1.0 | 2.0 | 4.0 | 8.0 | 16.0"); + TXPParser::TXPParser(): _archive(0), _currentTop(0), @@ -30,7 +33,8 @@ _underBillboardSubgraph(false), _numBillboardLevels(0), _underLayerSubgraph(false), _numLayerLevels(0), -_layerGeode(0) +_layerGeode(0), +_defaultMaxAnisotropy(1.0f) { AddCallback(TRPG_GEOMETRY,new geomRead(this)); AddCallback(TRPG_GROUP,new groupRead(this)); @@ -40,6 +44,12 @@ _layerGeode(0) AddCallback(TRPG_LIGHT,new lightRead(this)); AddCallback(TRPG_LAYER,new layerRead(this)); AddCallback(TRPGTILEHEADER,new tileHeaderRead(this)); + + if (getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY")) + { + _defaultMaxAnisotropy = atof(getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY")); + } + } TXPParser::~TXPParser() @@ -350,7 +360,7 @@ void TXPParser::loadLocalMaterials() osg_texture->setWrap(osg::Texture2D::WRAP_T, wrap_t == trpgTextureEnv::Repeat ? osg::Texture2D::REPEAT: osg::Texture2D::CLAMP ); // by default is anisotropic filtering. - osg_texture->setMaxAnisotropy(4.0f); + osg_texture->setMaxAnisotropy(_defaultMaxAnisotropy); } else { @@ -430,6 +440,11 @@ void TXPParser::loadLocalMaterials() } } +bool TXPParser::requestModel(int ix) +{ + return _archive->loadModel(ix); +} + //---------------------------------------------------------------------------- // // LOD Reader Class @@ -522,6 +537,12 @@ void *modelRefRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) { osg_Model = (*modelList)[modelID].get(); + if (osg_Model==NULL) + { + _parse->requestModel(modelID); + osg_Model = (*modelList)[modelID].get(); + } + // Create the SCS and position the model if (osg_Model) { diff --git a/src/osgPlugins/txp/TXPParser.h b/src/osgPlugins/txp/TXPParser.h index 19dfc5c63..71fd920b4 100644 --- a/src/osgPlugins/txp/TXPParser.h +++ b/src/osgPlugins/txp/TXPParser.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __TXPPARSER_H_ #define __TXPPARSER_H_ @@ -90,6 +123,9 @@ namespace txp // Return the current model list std::vector >* getModels() { return _models; } + // Request a model to be load + bool requestModel(int ix); + // Return a reference to the tile header (after a tile has been read) inline trpgTileHeader *getTileHeaderRef() { return &_tileHeader; } @@ -129,6 +165,11 @@ namespace txp // Returns the current layer geode inline osg::Geode* getLayerGeode() const { return _layerGeode; } + // default value to use when setting up textures. + void setMaxAnisotropy(float anisotropy) { _defaultMaxAnisotropy = anisotropy; } + float getMaxAnisotropy() const { return _defaultMaxAnisotropy; } + + protected: virtual ~TXPParser(); @@ -188,6 +229,9 @@ namespace txp // Our Layer Geode osg::Geode* _layerGeode; + + // default value to use when setting up textures. + float _defaultMaxAnisotropy; // TEMP osg::Geode* createBoundingBox(int x,int y, int lod); diff --git a/src/osgPlugins/txp/TXPSeamLOD.h b/src/osgPlugins/txp/TXPSeamLOD.h index d57c2f6b4..a42c81590 100644 --- a/src/osgPlugins/txp/TXPSeamLOD.h +++ b/src/osgPlugins/txp/TXPSeamLOD.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef TXPSeamLOD_H #define TXPSeamLOD_H diff --git a/src/osgPlugins/txp/TXPTileNode.h b/src/osgPlugins/txp/TXPTileNode.h index 26835014a..f0ea0cf8b 100644 --- a/src/osgPlugins/txp/TXPTileNode.h +++ b/src/osgPlugins/txp/TXPTileNode.h @@ -1,3 +1,36 @@ +/* ************************************************************************** +* December 2003 +* +* This TerraPage loader was re-written in a fashion to use PagedLOD +* to manage paging entirely, also includes a version of Terrex's smart mesh +* adapted to work with PagedLOD. The essential code by Boris Bralo is still present, +* slight modified. +* nick at terrex dot com +* +* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield + *****************************************************************************/ + +/* ************************************************************************** + * OpenSceneGraph loader for Terrapage format database + * by Boris Bralo 2002 + * + * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh + * + * This loader is based on/modified from Terrain Experts Performer Loader, + * and was ported to SGL by Bryan Walsh / bryanw at earthlink dot net + * + * That loader is redistributed under the terms listed on Terrain Experts + * website (www.terrex.com/www/pages/technology/technologypage.htm) + * + * "TerraPage is provided as an Open Source format for use by anyone... + * We supply the TerraPage C++ source code free of charge. Anyone + * can use it and redistribute it as needed (including our competitors). + * We do, however, ask that you keep the TERREX copyrights intact." + * + * Copyright Terrain Experts Inc. 1999. + * All Rights Reserved. + * + *****************************************************************************/ #ifndef __TXPTILENODE_H_ #define __TXPTILENODE_H_