From dd77c81557102a98c086ff47d6b41171cf759613 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Tue, 30 Jul 2024 23:21:10 +0100 Subject: [PATCH 1/2] 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(); From 1b3509d0add709a52ec942eaba1233aa907a0bb6 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Wed, 31 Jul 2024 00:30:06 +0100 Subject: [PATCH 2/2] Use nodeMask... lets ignore the previous attempt --- apps/openmw/mwrender/renderingmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 07288c278b..7048f7c933 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1051,6 +1051,7 @@ namespace MWRender RenderingManager::RayResult getIntersectionResult(osgUtil::LineSegmentIntersector* intersector, const osg::ref_ptr& visitor, std::span ignoreList = {}) { + constexpr auto nonObjectWorldMask = Mask_Terrain | Mask_Water; RenderingManager::RayResult result; result.mHit = false; result.mRatio = 0; @@ -1065,10 +1066,9 @@ namespace MWRender 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 + const auto& nodeMask = (*it)->getNodeMask(); if (!hitNonObjectWorld) - hitNonObjectWorld = (*it)->getName() == std::string_view("Terrain Root"); + hitNonObjectWorld = nodeMask & nonObjectWorldMask; osg::UserDataContainer* userDataContainer = (*it)->getUserDataContainer(); if (!userDataContainer)