From 3b1eb4a7f7c3bd459d4bc48ed740e95d9dba03d2 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sun, 17 Jan 2021 14:26:35 +0000 Subject: [PATCH] Remove Terrain simplifier - now redundant --- simgear/scene/tgdb/SGTileDetailsCallback.hxx | 83 -------------------- simgear/scene/tgdb/obj.cxx | 34 +------- 2 files changed, 4 insertions(+), 113 deletions(-) diff --git a/simgear/scene/tgdb/SGTileDetailsCallback.hxx b/simgear/scene/tgdb/SGTileDetailsCallback.hxx index 13b88beb..78ce8864 100644 --- a/simgear/scene/tgdb/SGTileDetailsCallback.hxx +++ b/simgear/scene/tgdb/SGTileDetailsCallback.hxx @@ -27,7 +27,6 @@ #endif #include -#include #include @@ -52,9 +51,6 @@ typedef std::list SGLightListBin; typedef std::list SGDirectionalLightListBin; -#define SG_SIMPLIFIER_RATIO (0.001) -#define SG_SIMPLIFIER_MAX_LENGTH (1000.0) -#define SG_SIMPLIFIER_MAX_ERROR (2000.0) using namespace simgear; // QuadTreeBuilder is used by Random Objects Generator @@ -124,11 +120,6 @@ public: } #endif - osg::Node* node = loadTerrain(); - if (node) { - group->addChild(node); - } - osg::LOD* lightLOD = generateLightingTileObjects(matTris, matcache); if (lightLOD) { group->addChild(lightLOD); @@ -241,79 +232,6 @@ public: 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 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 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 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 ) { const float l2 = distSqr(a, b); @@ -1110,7 +1028,6 @@ public: /// The original options to use for this bunch of models osg::ref_ptr _options; string _path; - bool _loadterrain; osg::ref_ptr _rootNode; SGVec3d _gbs_center; bool _randomSurfaceLightsComputed; diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index 6305b23b..095cb7a6 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -55,11 +55,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options SGMaterialLibPtr matlib; osg::ref_ptr matcache; 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 tile_min_expiry = SG_TILE_MIN_EXPIRY; bool usePhotoscenery = false; @@ -69,13 +64,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options useVBOs = (options->getPluginStringData("SimGear::USE_VBOS") == "ON"); 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); tile_min_expiry= propertyNode->getDoubleValue("/sim/rendering/plod-minimum-expiry-time-secs", tile_min_expiry); 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. osg::MatrixTransform* transform = new osg::MatrixTransform; 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->setName("pagedObjectLOD"); - if (simplifyNear == simplifyDistant) { - // Same terrain type is used for both near and far distances, - // so add it to the main group. - osg::Group* terrainGroup = new osg::Group; - 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::Group* terrainGroup = new osg::Group; + terrainGroup->setName("BTGTerrainGroup"); + terrainGroup->addChild(node); + transform->addChild(terrainGroup); osg::ref_ptr opt; 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 tileDetailsCallback->_options = opt; tileDetailsCallback->_path = std::string(path); - tileDetailsCallback->_loadterrain = ! (simplifyNear == simplifyDistant); tileDetailsCallback->_gbs_center = center; tileDetailsCallback->_rootNode = node; tileDetailsCallback->_randomSurfaceLightsComputed = false;