scenery: put stg loaded models under a common lod node.

This commit is contained in:
Mathias Froehlich 2012-10-27 08:22:45 +02:00
parent 8ebc0f2b24
commit a7f64cf7aa

View File

@ -25,6 +25,7 @@
#include "ReaderWriterSTG.hxx" #include "ReaderWriterSTG.hxx"
#include <osg/LOD>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <osg/ProxyNode> #include <osg/ProxyNode>
#include <osgUtil/LineSegmentIntersector> #include <osgUtil/LineSegmentIntersector>
@ -288,8 +289,8 @@ struct ReaderWriterSTG::_ModelBin {
osg::ref_ptr<SGReaderWriterOptions> options; osg::ref_ptr<SGReaderWriterOptions> options;
options = SGReaderWriterOptions::copyOrCreate(opt); options = SGReaderWriterOptions::copyOrCreate(opt);
osg::ref_ptr<osg::Group> group = new osg::Group; osg::ref_ptr<osg::Group> terrainGroup = new osg::Group;
group->setDataVariance(osg::Object::STATIC); terrainGroup->setDataVariance(osg::Object::STATIC);
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) {
@ -300,14 +301,14 @@ struct ReaderWriterSTG::_ModelBin {
<< i->_token << " '" << i->_name << "'"); << i->_token << " '" << i->_name << "'");
continue; continue;
} }
group->addChild(node.get()); terrainGroup->addChild(node.get());
} }
} else { } else {
SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile"); SG_LOG(SG_TERRAIN, SG_INFO, " Generating ocean tile");
osg::Node* node = SGOceanTile(bucket, options->getMaterialLib()); osg::Node* node = SGOceanTile(bucket, options->getMaterialLib());
if (node) { if (node) {
group->addChild(node); terrainGroup->addChild(node);
} else { } else {
SG_LOG( SG_TERRAIN, SG_ALERT, SG_LOG( SG_TERRAIN, SG_ALERT,
"Warning: failed to generate ocean tile!" ); "Warning: failed to generate ocean tile!" );
@ -317,15 +318,18 @@ struct ReaderWriterSTG::_ModelBin {
for (std::list<_ObjectStatic>::iterator i = _objectStaticList.begin(); i != _objectStaticList.end(); ++i) { for (std::list<_ObjectStatic>::iterator i = _objectStaticList.begin(); i != _objectStaticList.end(); ++i) {
if (!i->_agl) if (!i->_agl)
continue; continue;
i->_elev += elevation(*group, 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;
i->_elev += elevation(*group, SGGeod::fromDeg(i->_lon, i->_lat)); i->_elev += elevation(*terrainGroup, SGGeod::fromDeg(i->_lon, i->_lat));
} }
osg::ref_ptr<osg::Group> modelGroup = new osg::Group;
modelGroup->setDataVariance(osg::Object::STATIC);
for (std::list<_ObjectStatic>::iterator i = _objectStaticList.begin(); i != _objectStaticList.end(); ++i) { for (std::list<_ObjectStatic>::iterator i = _objectStaticList.begin(); i != _objectStaticList.end(); ++i) {
osg::ref_ptr<osg::Node> node; osg::ref_ptr<osg::Node> node;
if (i->_proxy) { if (i->_proxy) {
@ -355,16 +359,23 @@ struct ReaderWriterSTG::_ModelBin {
matrixTransform = new osg::MatrixTransform(matrix); matrixTransform = new osg::MatrixTransform(matrix);
matrixTransform->setDataVariance(osg::Object::STATIC); matrixTransform->setDataVariance(osg::Object::STATIC);
matrixTransform->addChild(node.get()); matrixTransform->addChild(node.get());
group->addChild(matrixTransform); modelGroup->addChild(matrixTransform);
} }
simgear::AirportSignBuilder signBuilder(options->getMaterialLib(), bucket.get_center()); simgear::AirportSignBuilder signBuilder(options->getMaterialLib(), bucket.get_center());
for (std::list<_Sign>::iterator i = _signList.begin(); i != _signList.end(); ++i) for (std::list<_Sign>::iterator i = _signList.begin(); i != _signList.end(); ++i)
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()); modelGroup->addChild(signBuilder.getSignsGroup());
return group.release(); osg::LOD* lod = new osg::LOD;
lod->setDataVariance(osg::Object::STATIC);
if (terrainGroup->getNumChildren())
lod->addChild(terrainGroup.get(), 0, std::numeric_limits<float>::max());
if (modelGroup->getNumChildren())
lod->addChild(modelGroup.get(), 0, 30000);
return lod;
} }
bool _foundBase; bool _foundBase;