Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Rendering: a kd-tree for every mesh, so the rays cast each frame don't test every triangle of Vivec

Alan Saunders4345bc5a2ab8
diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp
index 3c95966..cc8d3ae 100644
--- a/apps/openmw/mwrender/objectpaging.cpp
+++ b/apps/openmw/mwrender/objectpaging.cpp
@@ -3,6 +3,7 @@
#include <unordered_map>
#include <vector>
+#include <osg/KdTree>
#include <osg/LOD>
#include <osg/Material>
#include <osg/MatrixTransform>
@@ -945,6 +946,11 @@ namespace MWRender
optimizer.optimize(mergeGroup, options);
+ // Isowind: kd-trees for the merged meshes, as SceneManager builds for each model, so the rays cast through
+ // the scene each frame (the top-down cursor's pick reaches this far) stay cheap
+ osg::ref_ptr<osg::KdTreeBuilder> kdTreeBuilder = new osg::KdTreeBuilder;
+ mergeGroup->accept(*kdTreeBuilder);
+
group->addChild(mergeGroup);
if (mDebugBatches)
diff --git a/components/resource/scenemanager.cpp b/components/resource/scenemanager.cpp
index e0f26ad..fd9def8 100644
--- a/components/resource/scenemanager.cpp
+++ b/components/resource/scenemanager.cpp
@@ -7,6 +7,7 @@
#include <osg/Capability>
#include <osg/ColorMaski>
#include <osg/Group>
+#include <osg/KdTree>
#include <osg/Node>
#include <osg/UserDataContainer>
@@ -1007,6 +1008,13 @@ namespace Resource
else
shareState(loaded);
+ // Isowind: a kd-tree for every mesh, so each ray cast through the scene (the top-down camera's search for
+ // what hides the player, several a frame, and the cursor's pick) tests a handful of a big mesh's
+ // triangles rather than all of them: Vivec's cantons have tens of thousands, and a frame there went by
+ // their count.
+ osg::ref_ptr<osg::KdTreeBuilder> kdTreeBuilder = new osg::KdTreeBuilder;
+ loaded->accept(*kdTreeBuilder);
+
if (compile && mIncrementalCompileOperation)
mIncrementalCompileOperation->add(loaded);
else
diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp
index 9f414ea..ad5eb9c 100644
--- a/components/terrain/chunkmanager.cpp
+++ b/components/terrain/chunkmanager.cpp
@@ -1,5 +1,6 @@
#include "chunkmanager.hpp"
+#include <osg/KdTree>
#include <osg/Material>
#include <osg/Texture2D>
@@ -255,6 +256,11 @@ namespace Terrain
geometry->addPrimitiveSet(mBufferCache.getIndexBuffer(numVerts, lodFlags));
+ // Isowind: a kd-tree, as SceneManager builds for each model, so the rays cast through the scene each frame (the
+ // top-down cursor's pick) test a few of the chunk's triangles rather than all of them
+ osg::ref_ptr<osg::KdTreeBuilder> kdTreeBuilder = new osg::KdTreeBuilder;
+ kdTreeBuilder->apply(*geometry);
+
bool useCompositeMap = chunkSize >= mCompositeMapLevel;
unsigned int numUvSets = useCompositeMap ? 1 : 2;