1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 22:20:33 +00:00

alternate debug chunks (#3127)

* quadtreeworld.cpp

* chunkmanager.cpp

* chunkmanager.hpp

* quadtreeworld.hpp

* chunkmanager.cpp

* quadtreeworld.cpp

* quadtreeworld.cpp

* quadtreeworld.cpp [ci skip]

* quadtreeworld.hpp

* quadtreeworld.cpp

* quadtreeworld.cpp

* quadtreeworld.cpp

* chunkmanager.cpp

* chunkmanager.cpp
This commit is contained in:
Bo Svensson 2021-09-27 19:25:39 +00:00 committed by GitHub
parent 782e0710af
commit 3f68ddd8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 26 deletions

View File

@ -3,9 +3,7 @@
#include <sstream>
#include <osg/Texture2D>
#include <osg/ClusterCullingCallback>
#include <osg/Material>
#include <osg/MatrixTransform>
#include <osgUtil/IncrementalCompileOperation>
@ -13,14 +11,12 @@
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/lightmanager.hpp>
#include <components/settings/settings.hpp>
#include "terraindrawable.hpp"
#include "material.hpp"
#include "storage.hpp"
#include "texturemanager.hpp"
#include "compositemaprenderer.hpp"
#include <components/misc/constants.hpp>
namespace Terrain
{
@ -35,7 +31,6 @@ ChunkManager::ChunkManager(Storage *storage, Resource::SceneManager *sceneMgr, T
, mCompositeMapSize(512)
, mCompositeMapLevel(1.f)
, mMaxCompGeometrySize(1.f)
, mDebugChunks(Settings::Manager::getBool("debug chunks", "Terrain"))
{
mMultiPassRoot = new osg::StateSet;
mMultiPassRoot->setRenderingHint(osg::StateSet::OPAQUE_BIN);
@ -238,19 +233,6 @@ osg::ref_ptr<osg::Node> ChunkManager::createChunk(float chunkSize, const osg::Ve
}
geometry->setNodeMask(mNodeMask);
if (mDebugChunks)
{
osg::ref_ptr<osg::Group> result(new osg::Group);
result->addChild(geometry);
auto chunkBorder = CellBorder::createBorderGeometry(chunkCenter.x() - chunkSize / 2.f, chunkCenter.y() - chunkSize / 2.f, chunkSize, mStorage, mSceneManager, getNodeMask(), 5.f, { 1, 0, 0, 0 });
osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 };
osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform(osg::Matrixf::translate(-center*Constants::CellSizeInUnits));
trans->setDataVariance(osg::Object::STATIC);
trans->addChild(chunkBorder);
result->addChild(trans);
return result;
}
return geometry;
}

View File

@ -72,7 +72,6 @@ namespace Terrain
unsigned int mCompositeMapSize;
float mCompositeMapLevel;
float mMaxCompGeometrySize;
bool mDebugChunks = false;
};
}

View File

@ -11,6 +11,7 @@
#include <components/sceneutil/mwshadowtechnique.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include <components/loadinglistener/reporter.hpp>
#include <components/resource/resourcesystem.hpp>
#include "quadtreenode.hpp"
#include "storage.hpp"
@ -244,6 +245,26 @@ private:
osg::ref_ptr<RootNode> mRootNode;
};
class DebugChunkManager : public QuadTreeWorld::ChunkManager
{
public:
DebugChunkManager(Resource::SceneManager* sceneManager, Storage* storage, unsigned int nodeMask) : mSceneManager(sceneManager), mStorage(storage), mNodeMask(nodeMask) {}
osg::ref_ptr<osg::Node> getChunk(float size, const osg::Vec2f& chunkCenter, unsigned char lod, unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile)
{
osg::Vec3f center = { chunkCenter.x(), chunkCenter.y(), 0 };
auto chunkBorder = CellBorder::createBorderGeometry(center.x() - size / 2.f, center.y() - size / 2.f, size, mStorage, mSceneManager, mNodeMask, 5.f, { 1, 0, 0, 0 });
osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform(osg::Matrixf::translate(-center*Constants::CellSizeInUnits));
trans->setDataVariance(osg::Object::STATIC);
trans->addChild(chunkBorder);
return trans;
}
unsigned int getNodeMask() { return mNodeMask; }
private:
Resource::SceneManager* mSceneManager;
Storage* mStorage;
unsigned int mNodeMask;
};
QuadTreeWorld::QuadTreeWorld(osg::Group *parent, osg::Group *compileRoot, Resource::ResourceSystem *resourceSystem, Storage *storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask, int compMapResolution, float compMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize)
: TerrainGrid(parent, compileRoot, resourceSystem, storage, nodeMask, preCompileMask, borderMask)
, mViewDataMap(new ViewDataMap)
@ -258,6 +279,12 @@ QuadTreeWorld::QuadTreeWorld(osg::Group *parent, osg::Group *compileRoot, Resour
mChunkManager->setCompositeMapLevel(compMapLevel);
mChunkManager->setMaxCompositeGeometrySize(maxCompGeometrySize);
mChunkManagers.push_back(mChunkManager.get());
if (mDebugTerrainChunks)
{
mDebugChunkManager = std::unique_ptr<DebugChunkManager>(new DebugChunkManager(mResourceSystem->getSceneManager(), mStorage, borderMask));
addChunkManager(mDebugChunkManager.get());
}
}
QuadTreeWorld::~QuadTreeWorld()
@ -352,7 +379,7 @@ void loadRenderingNode(ViewData::Entry& entry, ViewData* vd, int vertexLodMod, f
}
}
void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld, bool debugTerrainChunk)
void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil::CullVisitor* cv, float cellworldsize, bool outofworld)
{
if (!(cv->getTraversalMask() & callback->getCullMask()))
return;
@ -368,11 +395,7 @@ void updateWaterCullingView(HeightCullCallback* callback, ViewData* vd, osgUtil:
for (unsigned int i=0; i<vd->getNumEntries(); ++i)
{
ViewData::Entry& entry = vd->getEntry(i);
osg::BoundingBox bb;
if(debugTerrainChunk)
bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0)->asGroup()->getChild(0))->getWaterBoundingBox();
else
bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox();
osg::BoundingBox bb = static_cast<TerrainDrawable*>(entry.mRenderingNode->asGroup()->getChild(0))->getWaterBoundingBox();
if (!bb.valid())
continue;
osg::Vec3f ofs (entry.mNode->getCenter().x()*cellworldsize, entry.mNode->getCenter().y()*cellworldsize, 0.f);
@ -448,7 +471,7 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
}
if (mHeightCullCallback && isCullVisitor)
updateWaterCullingView(mHeightCullCallback, vd, static_cast<osgUtil::CullVisitor*>(&nv), mStorage->getCellWorldSize(), !isGridEmpty(), mDebugTerrainChunks);
updateWaterCullingView(mHeightCullCallback, vd, static_cast<osgUtil::CullVisitor*>(&nv), mStorage->getCellWorldSize(), !isGridEmpty());
vd->markUnchanged();

View File

@ -5,6 +5,7 @@
#include "terraingrid.hpp"
#include <mutex>
#include <memory>
namespace osg
{
@ -15,6 +16,7 @@ namespace Terrain
{
class RootNode;
class ViewDataMap;
class DebugChunkManager;
/// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD.
class QuadTreeWorld : public TerrainGrid // note: derived from TerrainGrid is only to render default cells (see loadCell)
@ -73,6 +75,7 @@ namespace Terrain
float mViewDistance;
float mMinSize;
bool mDebugTerrainChunks;
std::unique_ptr<DebugChunkManager> mDebugChunkManager;
};
}