Remove Terrain simplifier - now redundant
This commit is contained in:
@@ -27,7 +27,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <osg/LOD>
|
#include <osg/LOD>
|
||||||
#include <osgUtil/Simplifier>
|
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
@@ -52,9 +51,6 @@
|
|||||||
typedef std::list<SGLightBin> SGLightListBin;
|
typedef std::list<SGLightBin> SGLightListBin;
|
||||||
typedef std::list<SGDirectionalLightBin> SGDirectionalLightListBin;
|
typedef std::list<SGDirectionalLightBin> SGDirectionalLightListBin;
|
||||||
|
|
||||||
#define SG_SIMPLIFIER_RATIO (0.001)
|
|
||||||
#define SG_SIMPLIFIER_MAX_LENGTH (1000.0)
|
|
||||||
#define SG_SIMPLIFIER_MAX_ERROR (2000.0)
|
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
|
|
||||||
// QuadTreeBuilder is used by Random Objects Generator
|
// QuadTreeBuilder is used by Random Objects Generator
|
||||||
@@ -124,11 +120,6 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
osg::Node* node = loadTerrain();
|
|
||||||
if (node) {
|
|
||||||
group->addChild(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::LOD* lightLOD = generateLightingTileObjects(matTris, matcache);
|
osg::LOD* lightLOD = generateLightingTileObjects(matTris, matcache);
|
||||||
if (lightLOD) {
|
if (lightLOD) {
|
||||||
group->addChild(lightLOD);
|
group->addChild(lightLOD);
|
||||||
@@ -241,79 +232,6 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Load terrain if required
|
|
||||||
// todo - this is the same code as when we load a btg from the .STG - can we combine?
|
|
||||||
osg::Node* loadTerrain()
|
|
||||||
{
|
|
||||||
if (! _loadterrain)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
SGBinObject tile;
|
|
||||||
if (!tile.read_bin(_path))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
SGMaterialLibPtr matlib;
|
|
||||||
SGMaterialCache* matcache = 0;
|
|
||||||
bool useVBOs = false;
|
|
||||||
bool simplifyNear = false;
|
|
||||||
double ratio = SG_SIMPLIFIER_RATIO;
|
|
||||||
double maxLength = SG_SIMPLIFIER_MAX_LENGTH;
|
|
||||||
double maxError = SG_SIMPLIFIER_MAX_ERROR;
|
|
||||||
|
|
||||||
if (_options) {
|
|
||||||
matlib = _options->getMaterialLib();
|
|
||||||
useVBOs = (_options->getPluginStringData("SimGear::USE_VBOS") == "ON");
|
|
||||||
SGPropertyNode* propertyNode = _options->getPropertyNode().get();
|
|
||||||
simplifyNear = propertyNode->getBoolValue("/sim/rendering/terrain/simplifier/enabled-near", simplifyNear);
|
|
||||||
ratio = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/ratio", ratio);
|
|
||||||
maxLength = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/max-length", maxLength);
|
|
||||||
maxError = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/max-error", maxError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PSADRO TODO : we can do this in terragear
|
|
||||||
// - why not add a bitmask of flags to the btg so we can precompute this?
|
|
||||||
// and only do it if it hasn't been done already
|
|
||||||
SGVec3d center = tile.get_gbs_center();
|
|
||||||
SGGeod geodPos = SGGeod::fromCart(center);
|
|
||||||
SGQuatd hlOr = SGQuatd::fromLonLat(geodPos)*SGQuatd::fromEulerDeg(0, 0, 180);
|
|
||||||
|
|
||||||
// Generate a materials cache
|
|
||||||
if (matlib) {
|
|
||||||
matcache = matlib->generateMatCache(geodPos, _options);
|
|
||||||
}
|
|
||||||
|
|
||||||
// rotate the tiles so that the bounding boxes get nearly axis aligned.
|
|
||||||
// this will help the collision tree's bounding boxes a bit ...
|
|
||||||
std::vector<SGVec3d> nodes = tile.get_wgs84_nodes();
|
|
||||||
for (unsigned i = 0; i < nodes.size(); ++i) {
|
|
||||||
nodes[i] = hlOr.transform(nodes[i]);
|
|
||||||
}
|
|
||||||
tile.set_wgs84_nodes(nodes);
|
|
||||||
|
|
||||||
SGQuatf hlOrf(hlOr[0], hlOr[1], hlOr[2], hlOr[3]);
|
|
||||||
std::vector<SGVec3f> normals = tile.get_normals();
|
|
||||||
for (unsigned i = 0; i < normals.size(); ++i) {
|
|
||||||
normals[i] = hlOrf.transform(normals[i]);
|
|
||||||
}
|
|
||||||
tile.set_normals(normals);
|
|
||||||
|
|
||||||
osg::ref_ptr<SGTileGeometryBin> tileGeometryBin = new SGTileGeometryBin;
|
|
||||||
|
|
||||||
if (!tileGeometryBin->insertSurfaceGeometry(tile, matcache)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::Node* node = tileGeometryBin->getSurfaceGeometry(matcache, useVBOs);
|
|
||||||
if (node && simplifyNear) {
|
|
||||||
osgUtil::Simplifier simplifier(ratio, maxError, maxLength);
|
|
||||||
node->accept(simplifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
float min_dist_to_seg_squared( const SGVec3f p, const SGVec3d& a, const SGVec3d& b )
|
float min_dist_to_seg_squared( const SGVec3f p, const SGVec3d& a, const SGVec3d& b )
|
||||||
{
|
{
|
||||||
const float l2 = distSqr(a, b);
|
const float l2 = distSqr(a, b);
|
||||||
@@ -1110,7 +1028,6 @@ public:
|
|||||||
/// 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;
|
||||||
string _path;
|
string _path;
|
||||||
bool _loadterrain;
|
|
||||||
osg::ref_ptr<osg::Node> _rootNode;
|
osg::ref_ptr<osg::Node> _rootNode;
|
||||||
SGVec3d _gbs_center;
|
SGVec3d _gbs_center;
|
||||||
bool _randomSurfaceLightsComputed;
|
bool _randomSurfaceLightsComputed;
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
SGMaterialLibPtr matlib;
|
SGMaterialLibPtr matlib;
|
||||||
osg::ref_ptr<SGMaterialCache> matcache;
|
osg::ref_ptr<SGMaterialCache> matcache;
|
||||||
bool useVBOs = false;
|
bool useVBOs = false;
|
||||||
bool simplifyDistant = false;
|
|
||||||
bool simplifyNear = false;
|
|
||||||
double ratio = SG_SIMPLIFIER_RATIO;
|
|
||||||
double maxLength = SG_SIMPLIFIER_MAX_LENGTH;
|
|
||||||
double maxError = SG_SIMPLIFIER_MAX_ERROR;
|
|
||||||
double object_range = SG_OBJECT_RANGE_ROUGH;
|
double object_range = SG_OBJECT_RANGE_ROUGH;
|
||||||
double tile_min_expiry = SG_TILE_MIN_EXPIRY;
|
double tile_min_expiry = SG_TILE_MIN_EXPIRY;
|
||||||
bool usePhotoscenery = false;
|
bool usePhotoscenery = false;
|
||||||
@@ -69,13 +64,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
useVBOs = (options->getPluginStringData("SimGear::USE_VBOS") == "ON");
|
useVBOs = (options->getPluginStringData("SimGear::USE_VBOS") == "ON");
|
||||||
SGPropertyNode* propertyNode = options->getPropertyNode().get();
|
SGPropertyNode* propertyNode = options->getPropertyNode().get();
|
||||||
|
|
||||||
// We control whether we simplify the nearby terrain and distant terrain separatey.
|
|
||||||
// However, we don't allow only simplifying the near terrain!
|
|
||||||
simplifyNear = propertyNode->getBoolValue("/sim/rendering/terrain/simplifier/enabled-near", simplifyNear);
|
|
||||||
simplifyDistant = simplifyNear || propertyNode->getBoolValue("/sim/rendering/terrain/simplifier/enabled-far", simplifyDistant);
|
|
||||||
ratio = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/ratio", ratio);
|
|
||||||
maxLength = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/max-length", maxLength);
|
|
||||||
maxError = propertyNode->getDoubleValue("/sim/rendering/terrain/simplifier/max-error", maxError);
|
|
||||||
object_range = propertyNode->getDoubleValue("/sim/rendering/static-lod/rough", object_range);
|
object_range = propertyNode->getDoubleValue("/sim/rendering/static-lod/rough", object_range);
|
||||||
tile_min_expiry= propertyNode->getDoubleValue("/sim/rendering/plod-minimum-expiry-time-secs", tile_min_expiry);
|
tile_min_expiry= propertyNode->getDoubleValue("/sim/rendering/plod-minimum-expiry-time-secs", tile_min_expiry);
|
||||||
usePhotoscenery = propertyNode->getBoolValue("/sim/rendering/photoscenery/enabled", usePhotoscenery);
|
usePhotoscenery = propertyNode->getBoolValue("/sim/rendering/photoscenery/enabled", usePhotoscenery);
|
||||||
@@ -150,11 +138,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node && simplifyDistant) {
|
|
||||||
osgUtil::Simplifier simplifier(ratio, maxError, maxLength);
|
|
||||||
node->accept(simplifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The toplevel transform for that tile.
|
// The toplevel transform for that tile.
|
||||||
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
osg::MatrixTransform* transform = new osg::MatrixTransform;
|
||||||
transform->setName(path);
|
transform->setName(path);
|
||||||
@@ -172,18 +155,10 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
pagedLOD->setCenterMode(osg::PagedLOD::USE_BOUNDING_SPHERE_CENTER);
|
pagedLOD->setCenterMode(osg::PagedLOD::USE_BOUNDING_SPHERE_CENTER);
|
||||||
pagedLOD->setName("pagedObjectLOD");
|
pagedLOD->setName("pagedObjectLOD");
|
||||||
|
|
||||||
if (simplifyNear == simplifyDistant) {
|
osg::Group* terrainGroup = new osg::Group;
|
||||||
// Same terrain type is used for both near and far distances,
|
terrainGroup->setName("BTGTerrainGroup");
|
||||||
// so add it to the main group.
|
terrainGroup->addChild(node);
|
||||||
osg::Group* terrainGroup = new osg::Group;
|
transform->addChild(terrainGroup);
|
||||||
terrainGroup->setName("BTGTerrainGroup");
|
|
||||||
terrainGroup->addChild(node);
|
|
||||||
transform->addChild(terrainGroup);
|
|
||||||
} else if (simplifyDistant) {
|
|
||||||
// Simplified terrain is only used in the distance, the
|
|
||||||
// call-back below will re-generate the closer version
|
|
||||||
pagedLOD->addChild(node, 2*object_range + SG_TILE_RADIUS, FLT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::ref_ptr<SGReaderWriterOptions> opt;
|
osg::ref_ptr<SGReaderWriterOptions> opt;
|
||||||
opt = SGReaderWriterOptions::copyOrCreate(options);
|
opt = SGReaderWriterOptions::copyOrCreate(options);
|
||||||
@@ -191,7 +166,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
|||||||
// we just need to know about the read file callback that itself holds the data
|
// we just need to know about the read file callback that itself holds the data
|
||||||
tileDetailsCallback->_options = opt;
|
tileDetailsCallback->_options = opt;
|
||||||
tileDetailsCallback->_path = std::string(path);
|
tileDetailsCallback->_path = std::string(path);
|
||||||
tileDetailsCallback->_loadterrain = ! (simplifyNear == simplifyDistant);
|
|
||||||
tileDetailsCallback->_gbs_center = center;
|
tileDetailsCallback->_gbs_center = center;
|
||||||
tileDetailsCallback->_rootNode = node;
|
tileDetailsCallback->_rootNode = node;
|
||||||
tileDetailsCallback->_randomSurfaceLightsComputed = false;
|
tileDetailsCallback->_randomSurfaceLightsComputed = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user