Groundwork for adding support for polygonal tiles
This commit is contained in:
parent
aa52005b87
commit
cad1e2a075
@ -33,6 +33,25 @@
|
||||
|
||||
#include <ogr_spatialref.h>
|
||||
|
||||
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"<<std::endl;
|
||||
}
|
||||
|
||||
virtual ~GraphicsContext()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Producer::ref_ptr<Producer::RenderSurface> 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;
|
||||
}
|
||||
|
@ -693,6 +693,10 @@ class DataSet : public osg::Referenced
|
||||
|
||||
osg::Node* createScene();
|
||||
|
||||
osg::ShapeDrawable* createDrawableHeightField();
|
||||
|
||||
osg::Geometry* createDrawablePolygonal();
|
||||
|
||||
void empty();
|
||||
|
||||
|
||||
|
@ -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 "<<imageName<<std::endl;
|
||||
//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);
|
||||
}
|
||||
|
||||
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 ****"<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
osg::Geode* geode = 0;
|
||||
osg::ShapeDrawable* shapeDrawable = 0;
|
||||
|
||||
if (heightFieldPresent)
|
||||
{
|
||||
std::cout<<"--- Have terrain build tile ----"<<std::endl;
|
||||
|
||||
osg::HeightField* hf = _terrain->_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 "<<imageName<<std::endl;
|
||||
_imagery->_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() ------------- "<<std::endl;
|
||||
|
||||
|
||||
bool heightFieldPresent = _terrain.valid() && _terrain->_heightField.valid();
|
||||
|
||||
if (!heightFieldPresent)
|
||||
{
|
||||
std::cout<<"--- Have terrain build tile ----"<<std::endl;
|
||||
|
||||
osg::HeightField* grid = _terrain->_heightField.get();
|
||||
|
||||
osg::Geometry* geometry = new osg::Geometry;
|
||||
|
||||
return geometry;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"**** No terrain to build tile from use flat terrain fallback ****"<<std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DataSet::DestinationTile::readFrom(CompositeSource* sourceGraph)
|
||||
@ -2147,7 +2197,7 @@ DataSet::DataSet()
|
||||
|
||||
_defaultColor.set(0.5f,0.5f,1.0f,1.0f);
|
||||
_databaseType = PagedLOD_DATABASE;
|
||||
_geometryType = POLYGONAL;
|
||||
_geometryType = HEIGHT_FIELD;
|
||||
_textureType = COMPRESSED_TEXTURE;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user