From dd77c81557102a98c086ff47d6b41171cf759613 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Tue, 30 Jul 2024 23:21:10 +0100 Subject: [PATCH] Fix: castRenderingRay doesnt hit terrain --- apps/openmw/mwrender/renderingmanager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index eefdd64528..07288c278b 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1061,9 +1061,15 @@ namespace MWRender auto test = [&](const osgUtil::LineSegmentIntersector::Intersection& intersection) { PtrHolder* ptrHolder = nullptr; std::vector refnumMarkers; + bool hitNonObjectWorld = false; for (osg::NodePath::const_iterator it = intersection.nodePath.begin(); it != intersection.nodePath.end(); ++it) { + // Terrain doesnt contain any user data ptrs or flags, so we have to check the name + // TODO: better solution for this that could also be used for water and other world pieces with flags + if (!hitNonObjectWorld) + hitNonObjectWorld = (*it)->getName() == std::string_view("Terrain Root"); + osg::UserDataContainer* userDataContainer = (*it)->getUserDataContainer(); if (!userDataContainer) continue; @@ -1109,7 +1115,7 @@ namespace MWRender vertexCounter += refnumMarkers[i]->mNumVertices; } - if (!result.mHitObject.isEmpty() || result.mHitRefnum.isSet()) + if (!result.mHitObject.isEmpty() || result.mHitRefnum.isSet() || hitNonObjectWorld) { result.mHit = true; result.mHitPointWorld = intersection.getWorldIntersectPoint();