Merge branch 'fix/render-raycast-doesnt-hit-terrain' into 'master'

Fix: castRenderingRay doesnt hit terrain

Closes #7912

See merge request OpenMW/openmw!4286
pull/3236/head
psi29a 5 months ago
commit e7fc20d279

@ -1051,6 +1051,7 @@ namespace MWRender
RenderingManager::RayResult getIntersectionResult(osgUtil::LineSegmentIntersector* intersector,
const osg::ref_ptr<osgUtil::IntersectionVisitor>& visitor, std::span<const MWWorld::Ptr> ignoreList = {})
{
constexpr auto nonObjectWorldMask = Mask_Terrain | Mask_Water;
RenderingManager::RayResult result;
result.mHit = false;
result.mRatio = 0;
@ -1061,9 +1062,14 @@ namespace MWRender
auto test = [&](const osgUtil::LineSegmentIntersector::Intersection& intersection) {
PtrHolder* ptrHolder = nullptr;
std::vector<RefnumMarker*> refnumMarkers;
bool hitNonObjectWorld = false;
for (osg::NodePath::const_iterator it = intersection.nodePath.begin(); it != intersection.nodePath.end();
++it)
{
const auto& nodeMask = (*it)->getNodeMask();
if (!hitNonObjectWorld)
hitNonObjectWorld = nodeMask & nonObjectWorldMask;
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();

Loading…
Cancel
Save