diff --git a/examples/osgdem/osgdem.cpp b/examples/osgdem/osgdem.cpp index 1e4cf3fa4..33d967003 100644 --- a/examples/osgdem/osgdem.cpp +++ b/examples/osgdem/osgdem.cpp @@ -33,6 +33,25 @@ #include +class GraphicsContext { + public: + GraphicsContext() + { + rs = new Producer::RenderSurface; + rs->setWindowRectangle(0,0,1,1); + rs->useBorder(false); + rs->useConfigEventThread(false); + rs->realize(); + std::cout<<"Realized window"< rs; +}; char *SanitizeSRS( const char *pszUserInput ) @@ -93,6 +112,16 @@ int main( int argc, char **argv ) dataset->setDestinationExtents(osg::BoundingBox(x,y,0.0f,x+w,y+h,0.0f)); } + while (arguments.read("--HEIGHT_FIELD")) + { + dataset->setGeometryType(osgTerrain::DataSet::HEIGHT_FIELD); + } + + while (arguments.read("--POLYGONAL")) + { + dataset->setGeometryType(osgTerrain::DataSet::POLYGONAL); + } + while (arguments.read("--LOD")) { dataset->setDatabaseType(osgTerrain::DataSet::LOD_DATABASE); @@ -294,11 +323,16 @@ int main( int argc, char **argv ) return 1; } - dataset->loadSources(); + // generate the database + { + GraphicsContext context; - dataset->createDestination((unsigned int)numLevels); - - dataset->writeDestination(); + dataset->loadSources(); + + dataset->createDestination((unsigned int)numLevels); + + dataset->writeDestination(); + } return 0; } diff --git a/include/osgTerrain/DataSet b/include/osgTerrain/DataSet index eae1cc998..f182fd8a1 100644 --- a/include/osgTerrain/DataSet +++ b/include/osgTerrain/DataSet @@ -693,6 +693,10 @@ class DataSet : public osg::Referenced osg::Node* createScene(); + osg::ShapeDrawable* createDrawableHeightField(); + + osg::Geometry* createDrawablePolygonal(); + void empty(); diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index aaff8cd9f..7e994df65 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -1692,34 +1692,80 @@ void DataSet::DestinationTile::optimizeResolution() } osg::Node* DataSet::DestinationTile::createScene() +{ + osg::Geode* geode = new osg::Geode; + + bool imagePresent = _imagery.valid() && _imagery->_image.valid(); + + if (_dataSet->getGeometryType()==HEIGHT_FIELD) + { + osg::ShapeDrawable* shapeDrawable = createDrawableHeightField(); + + if (shapeDrawable) + { + geode->addDrawable(shapeDrawable); + + if (!imagePresent) + { + shapeDrawable->setColor(_dataSet->getDefaultColor()); + } + } + } + else + { + osg::Geometry* geometry = createDrawablePolygonal(); + + if (geometry) + { + geode->addDrawable(geometry); + + if (!imagePresent) + { + osg::Vec4Array* colours = new osg::Vec4Array(1); + (*colours)[0] = _dataSet->getDefaultColor(); + + geometry->setColorArray(colours); + geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + } + } + } + + if (imagePresent) + { + std::string imageName(_name+".rgb"); + _imagery->_image->setFileName(imageName.c_str()); + + //std::cout<<"Writing out imagery to "<_image,_imagery->_image->getFileName().c_str()); + + osg::StateSet* stateset = geode->getOrCreateStateSet(); + osg::Texture2D* texture = new osg::Texture2D(_imagery->_image.get()); + texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP); + texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP); + stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); + } + + return geode; + + +} + +osg::ShapeDrawable* DataSet::DestinationTile::createDrawableHeightField() { bool heightFieldPresent = _terrain.valid() && _terrain->_heightField.valid(); - bool imagePresent = _imagery.valid() && _imagery->_image.valid(); - if (!heightFieldPresent && !imagePresent) - { - std::cout<<"**** No terrain or imagery to build tile from, will need to create some fallback ****"<_heightField.get(); - geode = new osg::Geode; + osg::ShapeDrawable* shapeDrawable = new osg::ShapeDrawable(hf); + hf->setSkirtHeight(shapeDrawable->getBound().radius()*0.01f); - shapeDrawable = new osg::ShapeDrawable(hf); - geode->addDrawable(shapeDrawable); - - hf->setSkirtHeight(geode->getBound().radius()*0.01f); - + return shapeDrawable; } else { @@ -1731,35 +1777,39 @@ osg::Node* DataSet::DestinationTile::createScene() hf->setXInterval(_extents.xMax()-_extents.xMin()); hf->setYInterval(_extents.yMax()-_extents.yMin()); - geode = new osg::Geode; osg::ShapeDrawable* shapeDrawable = new osg::ShapeDrawable(hf); - geode->addDrawable(shapeDrawable); - hf->setSkirtHeight(geode->getBound().radius()*0.01f); - } - - if (imagePresent) - { - std::string imageName(_name+".rgb"); - std::cout<<"Writing out imagery to "<_image->setFileName(imageName.c_str()); - //osgDB::writeImageFile(*_imagery->_image,_imagery->_image->getFileName().c_str()); - - osg::StateSet* stateset = geode->getOrCreateStateSet(); - osg::Texture2D* texture = new osg::Texture2D(_imagery->_image.get()); - texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP); - texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP); - stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); - } - else if (shapeDrawable) - { - shapeDrawable->setColor(_dataSet->getDefaultColor()); - } + hf->setSkirtHeight(shapeDrawable->getBound().radius()*0.01f); - return geode; + return shapeDrawable; + } +} + +osg::Geometry* DataSet::DestinationTile::createDrawablePolygonal() +{ + std::cout<<"--------- DataSet::DestinationTile::createSceneGeometry() ------------- "<_heightField.valid(); + + if (!heightFieldPresent) + { + std::cout<<"--- Have terrain build tile ----"<_heightField.get(); + + osg::Geometry* geometry = new osg::Geometry; + + return geometry; + + } + else + { + std::cout<<"**** No terrain to build tile from use flat terrain fallback ****"<