urho3d/urho3d

Potential bug in Ray::HitDistance - unreliable results in `outNormal` and `outUV`

ChrisDenham opened this issue · 1 comments

I think I may have found a bug in at least two of the Ray::HitDistance functions in Urho3D.

The bug is that they appear to return the normal of the last intersected triangle rather the nearest one.
In addition, what also looks wrong to me is that the barycentre used to interpolate the returned UV coordinate may not necessarily be calculated for the same triangle for which the UV coordinate is interpolated.

Of course, if there is only one ray intersection with the mesh, the result is reliable, but generally speaking the function appears to be assuming that the last intersection found is also the nearest, and thus the resultant normal and UV coord are potentially dependent on the ordering of the triangles in the mesh. Please correct me if I'm wrong here.

I think I can see how to fix it simply by only assigning to outNormal, outUV & outBary at the point of assigning nearestIndices = indices. However I'm a bit hesitant to submit that change as a PR in case I've misunderstood something here and wanted to check with the masters of Urho before doing that. :-)

https://github.com/urho3d/Urho3D/blob/928b5b1b068c4e525d4d8274033d3633eabacf7f/Source/Urho3D/Math/Ray.cpp#L287-L369

Ah, looks like I might have hit same issue as #2702 (stale)