Fix for OBJECT_BUILDING_MESH_DETAILED
This commit is contained in:
@@ -81,7 +81,7 @@ static SGBucket bucketIndexFromFileName(const std::string& fileName)
|
|||||||
ss >> index;
|
ss >> index;
|
||||||
if (ss.fail())
|
if (ss.fail())
|
||||||
return SGBucket();
|
return SGBucket();
|
||||||
|
|
||||||
return SGBucket(index);
|
return SGBucket(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,19 +195,19 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
signBuilder.addSign(SGGeod::fromDegM(i->_lon, i->_lat, i->_elev), i->_hdg, i->_name, i->_size);
|
signBuilder.addSign(SGGeod::fromDegM(i->_lon, i->_lat, i->_elev), i->_hdg, i->_name, i->_size);
|
||||||
if (signBuilder.getSignsGroup())
|
if (signBuilder.getSignsGroup())
|
||||||
group->addChild(signBuilder.getSignsGroup());
|
group->addChild(signBuilder.getSignsGroup());
|
||||||
|
|
||||||
return group.release();
|
return group.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
mt _seed;
|
mt _seed;
|
||||||
std::list<_ObjectStatic> _objectStaticList;
|
std::list<_ObjectStatic> _objectStaticList;
|
||||||
std::list<_Sign> _signList;
|
std::list<_Sign> _signList;
|
||||||
|
|
||||||
/// The original options to use for this bunch of models
|
/// The original options to use for this bunch of models
|
||||||
osg::ref_ptr<SGReaderWriterOptions> _options;
|
osg::ref_ptr<SGReaderWriterOptions> _options;
|
||||||
SGBucket _bucket;
|
SGBucket _bucket;
|
||||||
};
|
};
|
||||||
|
|
||||||
_ModelBin() :
|
_ModelBin() :
|
||||||
_object_range_bare(SG_OBJECT_RANGE_BARE),
|
_object_range_bare(SG_OBJECT_RANGE_BARE),
|
||||||
_object_range_rough(SG_OBJECT_RANGE_ROUGH),
|
_object_range_rough(SG_OBJECT_RANGE_ROUGH),
|
||||||
@@ -225,14 +225,14 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
SGPath path = filePath;
|
SGPath path = filePath;
|
||||||
path.append(".."); path.append(".."); path.append("..");
|
path.append(".."); path.append(".."); path.append("..");
|
||||||
sharedOptions->getDatabasePathList().push_back(path.local8BitStr());
|
sharedOptions->getDatabasePathList().push_back(path.local8BitStr());
|
||||||
|
|
||||||
// ensure Models directory synced via TerraSync is searched before the copy in
|
// ensure Models directory synced via TerraSync is searched before the copy in
|
||||||
// FG_ROOT, so that updated models can be used.
|
// FG_ROOT, so that updated models can be used.
|
||||||
std::string terrasync_root = options->getPluginStringData("SimGear::TERRASYNC_ROOT");
|
std::string terrasync_root = options->getPluginStringData("SimGear::TERRASYNC_ROOT");
|
||||||
if (!terrasync_root.empty()) {
|
if (!terrasync_root.empty()) {
|
||||||
sharedOptions->getDatabasePathList().push_back(terrasync_root);
|
sharedOptions->getDatabasePathList().push_back(terrasync_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string fg_root = options->getPluginStringData("SimGear::FG_ROOT");
|
std::string fg_root = options->getPluginStringData("SimGear::FG_ROOT");
|
||||||
sharedOptions->getDatabasePathList().push_back(fg_root);
|
sharedOptions->getDatabasePathList().push_back(fg_root);
|
||||||
|
|
||||||
@@ -271,26 +271,26 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
{
|
{
|
||||||
SGVec3d start = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, 10000));
|
SGVec3d start = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, 10000));
|
||||||
SGVec3d end = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, -1000));
|
SGVec3d end = SGVec3d::fromGeod(SGGeod::fromGeodM(geod, -1000));
|
||||||
|
|
||||||
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector;
|
osg::ref_ptr<osgUtil::LineSegmentIntersector> intersector;
|
||||||
intersector = new osgUtil::LineSegmentIntersector(toOsg(start), toOsg(end));
|
intersector = new osgUtil::LineSegmentIntersector(toOsg(start), toOsg(end));
|
||||||
osgUtil::IntersectionVisitor visitor(intersector.get());
|
osgUtil::IntersectionVisitor visitor(intersector.get());
|
||||||
group.accept(visitor);
|
group.accept(visitor);
|
||||||
|
|
||||||
if (!intersector->containsIntersections())
|
if (!intersector->containsIntersections())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
SGVec3d cart = toSG(intersector->getFirstIntersection().getWorldIntersectPoint());
|
SGVec3d cart = toSG(intersector->getFirstIntersection().getWorldIntersectPoint());
|
||||||
return SGGeod::fromCart(cart).getElevationM();
|
return SGGeod::fromCart(cart).getElevationM();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read(const std::string& absoluteFileName, const osgDB::Options* options)
|
bool read(const std::string& absoluteFileName, const osgDB::Options* options)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Determine object ranges
|
// Determine object ranges. Mesh size needs to be accounted for.
|
||||||
_object_range_bare = atof(options->getPluginStringData("SimGear::BARE_LOD_RANGE").c_str());
|
_object_range_bare = 2000.0f + atof(options->getPluginStringData("SimGear::LOD_RANGE_BARE").c_str());
|
||||||
_object_range_rough = atof(options->getPluginStringData("SimGear::ROUGH_LOD_RANGE").c_str());
|
_object_range_rough = 2000.0f + atof(options->getPluginStringData("SimGear::LOD_RANGE_ROUGH").c_str());
|
||||||
_object_range_detailed = atof(options->getPluginStringData("SimGear::DETAILED_LOD_RANGE").c_str());
|
_object_range_detailed = 2000.0f + atof(options->getPluginStringData("SimGear::LOD_RANGE_DETAILED").c_str());
|
||||||
_building_mesh_enabled = (options->getPluginStringData("SimGear::RENDER_BUILDING_MESH") == "true");
|
_building_mesh_enabled = (options->getPluginStringData("SimGear::RENDER_BUILDING_MESH") == "true");
|
||||||
|
|
||||||
if (absoluteFileName.empty())
|
if (absoluteFileName.empty())
|
||||||
@@ -301,7 +301,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
SG_LOG(SG_TERRAIN, SG_INFO, "Loading stg file " << absoluteFileName);
|
SG_LOG(SG_TERRAIN, SG_INFO, "Loading stg file " << absoluteFileName);
|
||||||
|
|
||||||
std::string filePath = osgDB::getFilePath(absoluteFileName);
|
std::string filePath = osgDB::getFilePath(absoluteFileName);
|
||||||
|
|
||||||
// Bucket provides a consistent seed
|
// Bucket provides a consistent seed
|
||||||
@@ -314,7 +314,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
bool onlyAirports = options->getPluginStringData("SimGear::FG_ONLY_AIRPORTS") == "ON";
|
bool onlyAirports = options->getPluginStringData("SimGear::FG_ONLY_AIRPORTS") == "ON";
|
||||||
// do only load terrain btg files
|
// do only load terrain btg files
|
||||||
bool onlyTerrain = options->getPluginStringData("SimGear::FG_ONLY_TERRAIN") == "ON";
|
bool onlyTerrain = options->getPluginStringData("SimGear::FG_ONLY_TERRAIN") == "ON";
|
||||||
|
|
||||||
while (!stream.eof()) {
|
while (!stream.eof()) {
|
||||||
// read a line
|
// read a line
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -324,21 +324,21 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
std::string::size_type hash_pos = line.find('#');
|
std::string::size_type hash_pos = line.find('#');
|
||||||
if (hash_pos != std::string::npos)
|
if (hash_pos != std::string::npos)
|
||||||
line.resize(hash_pos);
|
line.resize(hash_pos);
|
||||||
|
|
||||||
// and process further
|
// and process further
|
||||||
std::stringstream in(line);
|
std::stringstream in(line);
|
||||||
|
|
||||||
std::string token;
|
std::string token;
|
||||||
in >> token;
|
in >> token;
|
||||||
|
|
||||||
// No comment
|
// No comment
|
||||||
if (token.empty())
|
if (token.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Then there is always a name
|
// Then there is always a name
|
||||||
std::string name;
|
std::string name;
|
||||||
in >> name;
|
in >> name;
|
||||||
|
|
||||||
SGPath path = filePath;
|
SGPath path = filePath;
|
||||||
path.append(name);
|
path.append(name);
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
obj._options = staticOptions(filePath, options);
|
obj._options = staticOptions(filePath, options);
|
||||||
_objectList.push_back(obj);
|
_objectList.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (token == "OBJECT") {
|
} else if (token == "OBJECT") {
|
||||||
if (!onlyAirports || isAirportBtg(name)) {
|
if (!onlyAirports || isAirportBtg(name)) {
|
||||||
_Object obj;
|
_Object obj;
|
||||||
@@ -364,7 +364,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
obj._options = staticOptions(filePath, options);
|
obj._options = staticOptions(filePath, options);
|
||||||
_objectList.push_back(obj);
|
_objectList.push_back(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!onlyTerrain) {
|
} else if (!onlyTerrain) {
|
||||||
// Load non-terrain objects
|
// Load non-terrain objects
|
||||||
|
|
||||||
@@ -454,10 +454,10 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
<< ": Unknown token '" << token << "'" );
|
<< ": Unknown token '" << token << "'" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
|
osg::Node* load(const SGBucket& bucket, const osgDB::Options* opt)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<SGReaderWriterOptions> options;
|
osg::ref_ptr<SGReaderWriterOptions> options;
|
||||||
@@ -466,7 +466,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
osg::ref_ptr<osg::Group> terrainGroup = new osg::Group;
|
osg::ref_ptr<osg::Group> terrainGroup = new osg::Group;
|
||||||
terrainGroup->setDataVariance(osg::Object::STATIC);
|
terrainGroup->setDataVariance(osg::Object::STATIC);
|
||||||
terrainGroup->setName("terrain");
|
terrainGroup->setName("terrain");
|
||||||
|
|
||||||
if (_foundBase) {
|
if (_foundBase) {
|
||||||
for (std::list<_Object>::iterator i = _objectList.begin(); i != _objectList.end(); ++i) {
|
for (std::list<_Object>::iterator i = _objectList.begin(); i != _objectList.end(); ++i) {
|
||||||
osg::ref_ptr<osg::Node> node;
|
osg::ref_ptr<osg::Node> node;
|
||||||
@@ -480,7 +480,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile: " << bucket.gen_base_path() << "/" << bucket.gen_index_str());
|
SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile: " << bucket.gen_base_path() << "/" << bucket.gen_index_str());
|
||||||
|
|
||||||
osg::Node* node = SGOceanTile(bucket, options->getMaterialLib());
|
osg::Node* node = SGOceanTile(bucket, options->getMaterialLib());
|
||||||
if (node) {
|
if (node) {
|
||||||
node->setName("SGOceanTile");
|
node->setName("SGOceanTile");
|
||||||
@@ -496,7 +496,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
continue;
|
continue;
|
||||||
i->_elev += elevation(*terrainGroup, SGGeod::fromDeg(i->_lon, i->_lat));
|
i->_elev += elevation(*terrainGroup, SGGeod::fromDeg(i->_lon, i->_lat));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::list<_Sign>::iterator i = _signList.begin(); i != _signList.end(); ++i) {
|
for (std::list<_Sign>::iterator i = _signList.begin(); i != _signList.end(); ++i) {
|
||||||
if (!i->_agl)
|
if (!i->_agl)
|
||||||
continue;
|
continue;
|
||||||
@@ -510,7 +510,7 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
osg::PagedLOD* pagedLOD = new osg::PagedLOD;
|
osg::PagedLOD* pagedLOD = new osg::PagedLOD;
|
||||||
pagedLOD->setCenterMode(osg::PagedLOD::USE_BOUNDING_SPHERE_CENTER);
|
pagedLOD->setCenterMode(osg::PagedLOD::USE_BOUNDING_SPHERE_CENTER);
|
||||||
pagedLOD->setName("pagedObjectLOD");
|
pagedLOD->setName("pagedObjectLOD");
|
||||||
|
|
||||||
// This should be visible in any case.
|
// This should be visible in any case.
|
||||||
// If this is replaced by some lower level of detail, the parent LOD node handles this.
|
// If this is replaced by some lower level of detail, the parent LOD node handles this.
|
||||||
pagedLOD->addChild(terrainGroup, 0, std::numeric_limits<float>::max());
|
pagedLOD->addChild(terrainGroup, 0, std::numeric_limits<float>::max());
|
||||||
@@ -524,16 +524,16 @@ struct ReaderWriterSTG::_ModelBin {
|
|||||||
osg::ref_ptr<osgDB::Options> callbackOptions = new osgDB::Options;
|
osg::ref_ptr<osgDB::Options> callbackOptions = new osgDB::Options;
|
||||||
callbackOptions->setReadFileCallback(readFileCallback.get());
|
callbackOptions->setReadFileCallback(readFileCallback.get());
|
||||||
pagedLOD->setDatabaseOptions(callbackOptions.get());
|
pagedLOD->setDatabaseOptions(callbackOptions.get());
|
||||||
|
|
||||||
pagedLOD->setFileName(pagedLOD->getNumChildren(), "Dummy name - use the stored data in the read file callback");
|
pagedLOD->setFileName(pagedLOD->getNumChildren(), "Dummy name - use the stored data in the read file callback");
|
||||||
|
|
||||||
// Objects may end up displayed up to 2x the object range.
|
// Objects may end up displayed up to 2x the object range.
|
||||||
pagedLOD->setRange(pagedLOD->getNumChildren(), 0, 2.0 * _object_range_rough + SG_TILE_RADIUS);
|
pagedLOD->setRange(pagedLOD->getNumChildren(), 0, 2.0 * _object_range_rough + SG_TILE_RADIUS);
|
||||||
|
|
||||||
return pagedLOD;
|
return pagedLOD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double _object_range_bare;
|
double _object_range_bare;
|
||||||
double _object_range_rough;
|
double _object_range_rough;
|
||||||
double _object_range_detailed;
|
double _object_range_detailed;
|
||||||
@@ -576,11 +576,11 @@ ReaderWriterSTG::readNode(const std::string& fileName, const osgDB::Options* opt
|
|||||||
// For stg meta files, we need options for the search path.
|
// For stg meta files, we need options for the search path.
|
||||||
if (!options)
|
if (!options)
|
||||||
return ReadResult::FILE_NOT_FOUND;
|
return ReadResult::FILE_NOT_FOUND;
|
||||||
|
|
||||||
SG_LOG(SG_TERRAIN, SG_INFO, "Loading tile " << fileName);
|
SG_LOG(SG_TERRAIN, SG_INFO, "Loading tile " << fileName);
|
||||||
|
|
||||||
std::string basePath = bucket.gen_base_path();
|
std::string basePath = bucket.gen_base_path();
|
||||||
|
|
||||||
// Stop scanning once an object base is found
|
// Stop scanning once an object base is found
|
||||||
// This is considered a meta file, so apply the scenery path search
|
// This is considered a meta file, so apply the scenery path search
|
||||||
const osgDB::FilePathList& filePathList = options->getDatabasePathList();
|
const osgDB::FilePathList& filePathList = options->getDatabasePathList();
|
||||||
@@ -591,7 +591,7 @@ ReaderWriterSTG::readNode(const std::string& fileName, const osgDB::Options* opt
|
|||||||
objects.append(basePath);
|
objects.append(basePath);
|
||||||
objects.append(fileName);
|
objects.append(fileName);
|
||||||
modelBin.read(objects.local8BitStr(), options);
|
modelBin.read(objects.local8BitStr(), options);
|
||||||
|
|
||||||
SGPath terrain(*i);
|
SGPath terrain(*i);
|
||||||
terrain.append("Terrain");
|
terrain.append("Terrain");
|
||||||
terrain.append(basePath);
|
terrain.append(basePath);
|
||||||
|
|||||||
Reference in New Issue
Block a user