VPB: Initial commit

Not for LTS
This commit is contained in:
Scott Giese 2020-06-28 11:30:33 -05:00
parent 3fccee6e38
commit 6d8e9e5bbc
6 changed files with 95 additions and 14 deletions

View File

@ -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;

View File

@ -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.
*/

View File

@ -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 = "";
}

View File

@ -22,7 +22,7 @@
#ifdef HAVE_CONFIG_H
# include <simgear_config.h>
#endif
#include <algorithm>
#include "ReaderWriterSTG.hxx"
#include <osg/LOD>
@ -53,6 +53,8 @@
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/tgdb/SGBuildingBin.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
#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<std::string, bool> tile_map;
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
{
osg::ref_ptr<SGReaderWriterOptions> 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<osg::Node> 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)

View File

@ -48,7 +48,8 @@ SGSceneFeatures::SGSceneFeatures() :
_pointSpriteLights(true),
_triangleDirectionalLights(true),
_distanceAttenuationLights(true),
_textureFilter(1)
_textureFilter(1),
_VPBActive(false)
{
}

View File

@ -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