From 6d8e9e5bbcdbbeb8254a85693d31df5482f1d869 Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 28 Jun 2020 11:30:33 -0500 Subject: [PATCH] VPB: Initial commit Not for LTS --- simgear/bucket/newbucket.cxx | 45 +++++++++++++++++++++++++ simgear/bucket/newbucket.hxx | 6 ++++ simgear/scene/dem/SGDemTile_gdal.cxx | 4 +++ simgear/scene/tgdb/ReaderWriterSTG.cxx | 46 ++++++++++++++++++-------- simgear/scene/util/SGSceneFeatures.cxx | 3 +- simgear/scene/util/SGSceneFeatures.hxx | 5 +++ 6 files changed, 95 insertions(+), 14 deletions(-) diff --git a/simgear/bucket/newbucket.cxx b/simgear/bucket/newbucket.cxx index 41b6534c..27fcc504 100644 --- a/simgear/bucket/newbucket.cxx +++ b/simgear/bucket/newbucket.cxx @@ -184,6 +184,51 @@ void SGBucket::innerSet( double dlon, double dlat ) } } +std::string SGBucket::gen_vpb_base() const { + // long int index; + int top_lon, top_lat, main_lon, main_lat; + char hem, pole; + char raw_path[256]; + + top_lon = lon / 10; + main_lon = lon; + if ((lon < 0) && (top_lon * 10 != lon)) { + top_lon -= 1; + } + top_lon *= 10; + if (top_lon >= 0) { + hem = 'E'; + } + else { + hem = 'W'; + top_lon *= -1; + } + if (main_lon < 0) { + main_lon *= -1; + } + + top_lat = lat / 10; + main_lat = lat; + if ((lat < 0) && (top_lat * 10 != lat)) { + top_lat -= 1; + } + top_lat *= 10; + if (top_lat >= 0) { + pole = 'N'; + } + else { + pole = 'S'; + top_lat *= -1; + } + if (main_lat < 0) { + main_lat *= -1; + } + + ::snprintf(raw_path, 256, "WS_%c%d%c%2d", hem, main_lon, pole, main_lat); + + return raw_path; +} + // Build the path name for this bucket std::string SGBucket::gen_base_path() const { // long int index; diff --git a/simgear/bucket/newbucket.hxx b/simgear/bucket/newbucket.hxx index e31c9935..5f96593a 100644 --- a/simgear/bucket/newbucket.hxx +++ b/simgear/bucket/newbucket.hxx @@ -195,6 +195,12 @@ public: */ std::string gen_base_path() const; + /** + * Build the base path name for this bucket. + * @return base path in string form + */ + std::string gen_vpb_base() const; + /** * @return the center lon of a tile. */ diff --git a/simgear/scene/dem/SGDemTile_gdal.cxx b/simgear/scene/dem/SGDemTile_gdal.cxx index d187fc86..08f808df 100644 --- a/simgear/scene/dem/SGDemTile_gdal.cxx +++ b/simgear/scene/dem/SGDemTile_gdal.cxx @@ -172,7 +172,11 @@ GDALDatasetH SGDemTile::createTile( char **papszSrcFiles, const char *pszFilenam && (pszMethod == NULL || EQUALN(pszMethod,"GCP_",4)) ) { pszThisSourceSRS = GDALGetGCPProjection( hSrcDS ); } else if( pszMethod != NULL && EQUAL(pszMethod,"RPC") ) { +#ifndef SRS_WKT_WGS84 + pszThisSourceSRS = SRS_WKT_WGS84_LAT_LONG; +#else pszThisSourceSRS = SRS_WKT_WGS84; +#endif } else { pszThisSourceSRS = ""; } diff --git a/simgear/scene/tgdb/ReaderWriterSTG.cxx b/simgear/scene/tgdb/ReaderWriterSTG.cxx index 332c157a..c04228bf 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.cxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.cxx @@ -22,7 +22,7 @@ #ifdef HAVE_CONFIG_H # include #endif - +#include #include "ReaderWriterSTG.hxx" #include @@ -53,6 +53,8 @@ #include #include +#include + #include "SGOceanTile.hxx" #define BUILDING_ROUGH "OBJECT_BUILDING_MESH_ROUGH" @@ -376,6 +378,8 @@ struct ReaderWriterSTG::_ModelBin { int bucket = atoi(absoluteFileName.file_base().c_str()); mt_init(&seed, bucket); + bool vpb_active = SGSceneFeatures::instance()->getVPBActive(); + // do only load airport btg files. bool onlyAirports = options->getPluginStringData("SimGear::FG_ONLY_AIRPORTS") == "ON"; // do only load terrain btg files @@ -409,18 +413,19 @@ struct ReaderWriterSTG::_ModelBin { path.append(name); if (token == "OBJECT_BASE") { - // Load only once (first found) - SG_LOG( SG_TERRAIN, SG_BULK, " " << token << " " << name ); - _foundBase = true; - if (!onlyAirports || isAirportBtg(name)) { - _Object obj; - obj._errorLocation = absoluteFileName; - obj._token = token; - obj._name = path.utf8Str(); - obj._options = staticOptions(filePath, options); - _objectList.push_back(obj); + if (!vpb_active) { + // Load only once (first found) + SG_LOG( SG_TERRAIN, SG_BULK, " " << token << " " << name ); + _foundBase = true; + if (!onlyAirports || isAirportBtg(name)) { + _Object obj; + obj._errorLocation = absoluteFileName; + obj._token = token; + obj._name = path.utf8Str(); + obj._options = staticOptions(filePath, options); + _objectList.push_back(obj); + } } - } else if (token == "OBJECT") { if (!onlyAirports || isAirportBtg(name)) { _Object obj; @@ -430,7 +435,6 @@ struct ReaderWriterSTG::_ModelBin { obj._options = staticOptions(filePath, options); _objectList.push_back(obj); } - } else if (!onlyTerrain) { // Load non-terrain objects @@ -566,6 +570,8 @@ struct ReaderWriterSTG::_ModelBin { return true; } + std::map tile_map; + osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt) { osg::ref_ptr options; @@ -575,6 +581,19 @@ struct ReaderWriterSTG::_ModelBin { terrainGroup->setDataVariance(osg::Object::STATIC); terrainGroup->setName("terrain"); + bool vpb_active = SGSceneFeatures::instance()->getVPBActive(); + if (vpb_active) { + std::string filename = "vpb/" + bucket.gen_vpb_base() + ".osgb"; + //std::string filename = "vpb/*.osgb"; + if (tile_map.count(filename) == 0) { + auto vpb_node = osgDB::readRefNodeFile(filename, options); + terrainGroup->addChild(vpb_node); + tile_map[filename] = true; + SG_LOG(SG_TERRAIN, SG_INFO, "Loading: " << filename); + } + } + + if (!vpb_active) { if (_foundBase) { for (auto stgObject : _objectList) { osg::ref_ptr node; @@ -599,6 +618,7 @@ struct ReaderWriterSTG::_ModelBin { "Warning: failed to generate ocean tile!" ); } } + } for (std::list<_ObjectStatic>::iterator i = _objectStaticList.begin(); i != _objectStaticList.end(); ++i) { if (!i->_agl) diff --git a/simgear/scene/util/SGSceneFeatures.cxx b/simgear/scene/util/SGSceneFeatures.cxx index 3d0527ab..c26cfeef 100644 --- a/simgear/scene/util/SGSceneFeatures.cxx +++ b/simgear/scene/util/SGSceneFeatures.cxx @@ -48,7 +48,8 @@ SGSceneFeatures::SGSceneFeatures() : _pointSpriteLights(true), _triangleDirectionalLights(true), _distanceAttenuationLights(true), - _textureFilter(1) + _textureFilter(1), + _VPBActive(false) { } diff --git a/simgear/scene/util/SGSceneFeatures.hxx b/simgear/scene/util/SGSceneFeatures.hxx index 9be4e99a..128cb33a 100644 --- a/simgear/scene/util/SGSceneFeatures.hxx +++ b/simgear/scene/util/SGSceneFeatures.hxx @@ -39,6 +39,7 @@ public: UseDXT3Compression, UseDXT5Compression }; + int getMaxTextureSize() const { return _MaxTextureSize; } void setMaxTextureSize(const int maxTextureSize) { _MaxTextureSize = maxTextureSize; } @@ -60,6 +61,9 @@ public: // modify the texture compression on the texture parameter void applyTextureCompression(osg::Texture* texture) const; + bool getVPBActive() const { return _VPBActive; } + void setVPBActive(const bool val) { _VPBActive = val; } + void setEnablePointSpriteLights(bool enable) { _pointSpriteLights = enable; @@ -145,6 +149,7 @@ private: bool _triangleDirectionalLights; bool _distanceAttenuationLights; int _textureFilter; + bool _VPBActive; }; #endif