From a61c0aaee1a1473cc45951fb91deb26a42bd91d1 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH] Do not load height data to the qued tree since we do not need it now --- components/terrain/quadtreenode.cpp | 9 +++------ components/terrain/quadtreenode.hpp | 4 ++-- components/terrain/quadtreeworld.cpp | 25 ++++++++++++------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/components/terrain/quadtreenode.cpp b/components/terrain/quadtreenode.cpp index 10f46c0eb..b92c37313 100644 --- a/components/terrain/quadtreenode.cpp +++ b/components/terrain/quadtreenode.cpp @@ -108,14 +108,11 @@ void QuadTreeNode::initNeighbours() getChild(i)->initNeighbours(); } -void QuadTreeNode::traverse(ViewData* vd, osg::NodeVisitor* nv, const osg::Vec3f& viewPoint, bool visible, float maxDist) +void QuadTreeNode::traverse(ViewData* vd, const osg::Vec3f& viewPoint, float maxDist) { if (!hasValidBounds()) return; - if (nv && nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR) - visible = visible && !static_cast(nv)->isCulled(mBoundingBox); - float dist = distance(viewPoint); if (dist > maxDist) return; @@ -123,11 +120,11 @@ void QuadTreeNode::traverse(ViewData* vd, osg::NodeVisitor* nv, const osg::Vec3f bool stopTraversal = (mLodCallback->isSufficientDetail(this, dist)) || !getNumChildren(); if (stopTraversal) - vd->add(this, visible); + vd->add(this, true); else { for (unsigned int i=0; itraverse(vd, nv, viewPoint, visible, maxDist); + getChild(i)->traverse(vd, viewPoint, maxDist); } } diff --git a/components/terrain/quadtreenode.hpp b/components/terrain/quadtreenode.hpp index 96b08842f..391c2b75f 100644 --- a/components/terrain/quadtreenode.hpp +++ b/components/terrain/quadtreenode.hpp @@ -92,8 +92,8 @@ namespace Terrain const osg::Vec2f& getCenter() const; /// Optimized version of traverse() that doesn't incur the overhead of NodeVisitor double-dispatch or fetching the various variables. - /// Note this doesn't do any culling for non-cull visitors (e.g. intersections) so it shouldn't be used for those. - void traverse(ViewData* vd, osg::NodeVisitor* nv, const osg::Vec3f& viewPoint, bool visible, float maxDist); + /// Note this doesn't do any culling. + void traverse(ViewData* vd, const osg::Vec3f& viewPoint, float maxDist); /// Traverse to a specific node and add only that node. void traverseTo(ViewData* vd, float size, const osg::Vec2f& center); diff --git a/components/terrain/quadtreeworld.cpp b/components/terrain/quadtreeworld.cpp index 6fc41b04a..bd81c8637 100644 --- a/components/terrain/quadtreeworld.cpp +++ b/components/terrain/quadtreeworld.cpp @@ -188,15 +188,14 @@ public: if (node->getSize() <= mMinSize) { - // We arrived at a leaf - float minZ,maxZ; - if (mStorage->getMinMaxHeights(size, center, minZ, maxZ)) - { - float cellWorldSize = mStorage->getCellWorldSize(); - osg::BoundingBox boundingBox(osg::Vec3f((center.x()-halfSize)*cellWorldSize, (center.y()-halfSize)*cellWorldSize, minZ), - osg::Vec3f((center.x()+halfSize)*cellWorldSize, (center.y()+halfSize)*cellWorldSize, maxZ)); - node->setBoundingBox(boundingBox); - } + // We arrived at a leaf. + // Since the tree is used for LOD level selection instead of culling, we do not need to load an actual height data here. + float minZ = -std::numeric_limits::max(); + float maxZ = std::numeric_limits::max(); + float cellWorldSize = mStorage->getCellWorldSize(); + osg::BoundingBox boundingBox(osg::Vec3f((center.x()-halfSize)*cellWorldSize, (center.y()-halfSize)*cellWorldSize, minZ), + osg::Vec3f((center.x()+halfSize)*cellWorldSize, (center.y()+halfSize)*cellWorldSize, maxZ)); + node->setBoundingBox(boundingBox); return node; } else @@ -360,7 +359,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) mRootNode->traverseTo(vd, 1, osg::Vec2f(x+0.5,y+0.5)); } else - mRootNode->traverse(vd, &nv, cv->getViewPoint(), true, mViewDistance); + mRootNode->traverse(vd, cv->getViewPoint(), mViewDistance); } else { @@ -376,9 +375,9 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv) mRootNode->intersect(vd, terrainIntersector); } } - else if (isCullVisitor) + + if (isCullVisitor) { - // view point is the same, but must still update visible status in case the camera has rotated for (unsigned int i=0; igetNumEntries(); ++i) { ViewData::Entry& entry = vd->getEntry(i); @@ -471,7 +470,7 @@ void QuadTreeWorld::preload(View *view, const osg::Vec3f &viewPoint, std::atomic ViewData* vd = static_cast(view); vd->setViewPoint(viewPoint); - mRootNode->traverse(vd, nullptr, viewPoint, false, mViewDistance); + mRootNode->traverse(vd, viewPoint, mViewDistance); for (unsigned int i=0; igetNumEntries() && !abort; ++i) {